Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Commit

Permalink
Initial import.
Browse files Browse the repository at this point in the history
  • Loading branch information
lamikae committed Mar 5, 2012
0 parents commit 0e67e69
Show file tree
Hide file tree
Showing 9 changed files with 1,036 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.gem
.bundle
Gemfile.lock
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source "http://rubygems.org"
gemspec
74 changes: 74 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
This is a pure Ruby implementation of the Secure Remote Password protocol (SRP-6a). SRP is a cryptographically strong authentication protocol for password-based, mutual authentication over an insecure network connection.

Unlike other common challenge-response autentication protocols, such as Kereros and SSL, SRP does not rely on an external infrastructure of trusted key servers or certificate management. Instead, SRP server applications use verification keys derived from each user's password to determine the authenticity of a network connection.

SRP provides mutual-authentication in that successful authentication requires both sides of the connection to have knowledge of the user's password. If the client side lacks the user's password or the server side lacks the proper verification key, the authentication will fail.


References

* [http://srp.stanford.edu/](http://srp.stanford.edu/)
* [http://srp.stanford.edu/demo/demo.html](http://srp.stanford.edu/demo/demo.html)

Usage example
=============


username = "user"
password = "password"

require 'srp'
prime_length = 1024


# The salt and verifier should be stored on the server database.

@auth = SRP::Verifier.new(prime_length).generate_userauth(username, password)
# @auth is a hash containing :username, :verifier and :salt


# ~~~ Begin Authentication ~~~

client = SRP::Client.new(1024)
A = client.start_authentication()


# Client => Server: username, A

# Server retrieves user's verifier and salt from the database.
v = @auth[:verifier]
salt = @auth[:salt]

# Server generates challenge for the client.
verifier = SRP::Verifier.new(1024)
session = srp.get_challenge_and_proof(username, v, salt, A)

# Server sends the challenge containing salt and B to client.
client_response = session[:challenge]

# Server has to remember proof to authenticate the client response.
session[:proof] # should be stored to database if server is stateless


# Server => Client: salt, B

client_M = client.process_challenge(username, password, salt, B)


# Client => Server: M

verifier.verify_session(session[:proof], client_M) # should be true

# At this point, the client and server should have a common session key
# that is secure (i.e. not known to an outside party). To finish
# authentication, they must prove to each other that their keys are
# identical.

server_H_AMK = verifier.H_AMK


# Server => Client: HAMK

client.H_AMK == server_H_AMK


7 changes: 7 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new

task :default => :spec
task :test => :spec
Loading

0 comments on commit 0e67e69

Please sign in to comment.