lib/clarion/app.rb in clarion-0.1.0 vs lib/clarion/app.rb in clarion-0.2.0

- old
+ new

@@ -125,15 +125,17 @@ end @reg_id = SecureRandom.urlsafe_base64(12) registrator = Registrator.new(u2f, counter) @app_id, @requests = registrator.request - session[:regs] ||= {} - session[:regs][@reg_id] = { + session[:regis] ||= [] + session[:regis] << { + id: @reg_id, challenges: @requests.map(&:challenge), key: public_key.to_der, } + session[:regis].shift(session[:regis].size - 4) if session[:regis].size > 4 @callback = params[:callback] @state = params[:state] @name = params[:name] @comment = params[:comment] @@ -148,12 +150,12 @@ content_type :json unless data[:reg_id] && data[:response] halt 400, '{"error": "Missing params"}' end - session[:regs] ||= {} - reg = session[:regs][data[:reg_id]] + session[:regis] ||= [] + reg = session[:regis].find { |_| _[:id] == data[:reg_id] } unless reg && reg[:challenges] && reg[:key] halt 400, '{"error": "Invalid :reg"}' end public_key = begin @@ -162,11 +164,12 @@ halt 400, '{"error": "Invalid public key"}' end registrator = Registrator.new(u2f, counter) key = registrator.register!(reg[:challenges], data[:response]) + key.name = data[:name] - session[:regs].delete(data[:reg_id]) + session[:regis].reject! { |_| _[:id] == data[:reg_id] } {ok: true, encrypted_key: key.to_encrypted_json(public_key, :all)}.to_json end post '/ui/verify/:id' do