summaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
Diffstat (limited to 'example')
-rw-r--r--example/http-srp.rb12
-rw-r--r--example/models/user.rb11
-rw-r--r--example/views/signup.erb2
3 files changed, 13 insertions, 12 deletions
diff --git a/example/http-srp.rb b/example/http-srp.rb
index 2e50cc8..ed07896 100644
--- a/example/http-srp.rb
+++ b/example/http-srp.rb
@@ -2,9 +2,9 @@ require 'sinatra'
require 'pp'
require 'json'
+require '../lib/srp'
require 'models/user'
require 'models/log'
-require '../lib/srp'
get '/' do
@user = User.current
@@ -24,7 +24,7 @@ post '/register/salt/' do
{ :salt => @user.salt.to_s(16) }.to_json
end
-post '/register/user/' do
+post '/register/user' do
User.current.verifier = params.delete('v').hex
content_type :json
{ :ok => true }.to_json
@@ -35,19 +35,19 @@ get '/login' do
erb :login
end
-post '/handshake/' do
+post '/handshake' do
@user = User.current
Log.log(:handshake, params)
- @handshake = @user.initialize_auth(params)
+ @handshake = @user.handshake(params)
Log.log(:init_auth, @handshake)
content_type :json
@handshake.to_json
end
-post '/authenticate/' do
+post '/authenticate' do
@user = User.current
Log.log(:authenticate, params)
- @auth = @user.authenticate(params)
+ @auth = @user.validate(params)
Log.log(:confirm_authentication, @auth)
content_type :json
@auth.to_json
diff --git a/example/models/user.rb b/example/models/user.rb
index 91bbffc..81104f4 100644
--- a/example/models/user.rb
+++ b/example/models/user.rb
@@ -1,5 +1,7 @@
class User
+ include SRP::Authentication
+
def self.current
@current
end
@@ -22,14 +24,13 @@ class User
User.current = self
end
- def initialize_auth(params)
- self.srp = SRP::Server.new(self.salt, self.verifier)
- bb, u = self.srp.initialize_auth(params.delete('A').hex)
+ def handshake(params)
+ bb, u = initialize_auth(params.delete('A').hex)
return {:s => self.salt.to_s(16), :B => bb.to_s(16)}
end
- def authenticate(params)
- if m2 = self.srp.authenticate(params.delete('M').hex)
+ def validate(params)
+ if m2 = authenticate(params.delete('M').hex)
self.active = true
return {:M => m2.to_s(16)}
else
diff --git a/example/views/signup.erb b/example/views/signup.erb
index 6e1bbf3..2b26820 100644
--- a/example/views/signup.erb
+++ b/example/views/signup.erb
@@ -1,6 +1,6 @@
<h2>1. Signup</h2>
-<form class="form-horizontal" action="/signup" method="POST">
+<form class="form-horizontal" action="/register/user" method="POST">
<legend>Signup to test secure remote passwords</legend>
<div class="control-group">
<label class="control-label" for="login">Login</label>