Packagenet.tynril.crypto.srp6
Classpublic class SRP6
InheritanceSRP6 Inheritance Object

This is an ActionScript 3 implementation of the SRP-6a system, which allows a secure exchange of password between a host and a client without a trusted third-party.

This strong authentication protocol is developed by Tom Wu of the Stanford University. All credits for designing and specifying this protocol goes to him.

The SRP-6a protocol is quite simple, and works like that:
  1. The client sends a username and the 'A' token to the server;
  2. The server sends a salt and the 'B' token to the client;
  3. The user types his/her password on the client-side
  4. Both sides are performing checks on those values;
  5. The client sends a proof of key-match to the server;
  6. The server sends a proof of key-match to the client.

The whole details about the protocol are described on the official SRP page on the Stanford University website: http://srp.stanford.edu/design.html

This library was initially written by Samuel Lorétan, and is released under the Lesser GNU General Public License.



Public Properties
 PropertyDefined By
  status : uint
[read-only] Get the current status of this instance.
SRP6
Public Methods
 MethodDefined By
  
Creates a new instance of the SRP6 algorithm.
SRP6
  
Step 1: Compute the client token 'A' to be sent to the server along with the username.
SRP6
  
computeKeyProof(username:String, password:String):String
Step 3: Computes the key proof to be sent to the server, using all previously set data and the password given by the user.
SRP6
  
dispose():void
Dispose of the SRP6 object, freeing any memory it is using.
SRP6
  
initialize(modulus:String = null, generator:String = null, multiplier:String = null, hash:IHash = null, prng:Class = null, radix:uint = 16):void
Step 0: Initialize this SRP6 instance with the given arithmetic constants, or with the default constants.
SRP6
  
receiveSaltAndServerToken(salt:String, serverToken:String):Boolean
Step 2: Received the salt s and the B token from the server.
SRP6
  
validateServerProof(proof:String):Boolean
Step 4: Validate the proof sent by the server.
SRP6
Public Constants
 ConstantDefined By
  STATUS_AUTHENTICATED : uint = 0x05
[static] The proof of session key sent by the server is matching our expectation, the session is valid and the server can be trusted.
SRP6
  STATUS_ERROR : uint = 0xFF
[static] Something went wrong during the calculation.
SRP6
  STATUS_HANDSHAKED : uint = 0x03
[static] The salt and 'B' token were received from the server.
SRP6
  STATUS_IDENTIFIED : uint = 0x02
[static] The user has identified himself to the server by sending his or her username and 'A' token.
SRP6
  STATUS_INITIALIZED : uint = 0x01
[static] The protocol was initialized and is ready to be used, starting with the step one, computeClientToken.
SRP6
  STATUS_PROOF_SENT : uint = 0x04
[static] The proof of session key 'M' was sent to the server.
SRP6
  STATUS_UNINITIALIZED : uint = 0x00
[static] Initial status of the authentication protocol.
SRP6
Property Detail
statusproperty
status:uint  [read-only]

Get the current status of this instance.


Implementation
    public function get status():uint
Constructor Detail
SRP6()Constructor
public function SRP6()

Creates a new instance of the SRP6 algorithm. This instance will need to be initialized by calling the initialize method before usage. A single instance can be used multiple times, if disposeed correctly.

Method Detail
computeClientToken()method
public function computeClientToken():String

Step 1: Compute the client token 'A' to be sent to the server along with the username.

Changes the status of this SRP6 object to STATUS_IDENTIFIED.

Returns
String — A radix representation of the client token.
computeKeyProof()method 
public function computeKeyProof(username:String, password:String):String

Step 3: Computes the key proof to be sent to the server, using all previously set data and the password given by the user.

Changes the status of this SRP6 object to STATUS_PROOF_SENT.

Parameters

username:String — Username as entered by the user.
 
password:String — Password as entered by the user.

Returns
String — A radix representation of the key proof.
dispose()method 
public function dispose():void

Dispose of the SRP6 object, freeing any memory it is using.

initialize()method 
public function initialize(modulus:String = null, generator:String = null, multiplier:String = null, hash:IHash = null, prng:Class = null, radix:uint = 16):void

Step 0: Initialize this SRP6 instance with the given arithmetic constants, or with the default constants.

Changes the status of this SRP6 object to STATUS_INITIALIZED.

Parameters

modulus:String (default = null) — (N) A large safe prime (N = 2q+1 where 1 is prime) All arithmetics is done modulo N.
 
generator:String (default = null) — (g) A generator modulo N.
 
multiplier:String (default = null) — (k) Multiplier parameter (k = H(N, g) in SRP-6a, k = 3 for legacy SRP-6).
 
hash:IHash (default = null) — (H) The hash function to be used during authentication. Defaults to SHA1.
 
prng:Class (default = null) — The pseudo-random generator to be used during authentication. Defaults to ARC4.
 
radix:uint (default = 16) — All token and values will be returned as a string representing the number with the given radix. Hexadecimal by default.

receiveSaltAndServerToken()method 
public function receiveSaltAndServerToken(salt:String, serverToken:String):Boolean

Step 2: Received the salt s and the B token from the server.

Changes the status of this SRP6 object to STATUS_HANDSHAKED.

Parameters

salt:String — The salt received from the server, represented as a radix string.
 
serverToken:String — The B token as received from the server, represented as a radix string.

Returns
Booleantrue if the value received were valid, false otherwise.
validateServerProof()method 
public function validateServerProof(proof:String):Boolean

Step 4: Validate the proof sent by the server.

Changes the status of this SRP6 object to STATUS_AUTHENTICATED if everything is fine, or to STATUS_ERROR if the proof was invalid.

Parameters

proof:String — The radix representation of the proof sent by the server.

Returns
Booleantrue if the proof was okay, false otherwise.
Constant Detail
STATUS_AUTHENTICATEDConstant
public static const STATUS_AUTHENTICATED:uint = 0x05

The proof of session key sent by the server is matching our expectation, the session is valid and the server can be trusted. This status is set once validateServerProof was called. This is the final status, no more step is required.

STATUS_ERRORConstant 
public static const STATUS_ERROR:uint = 0xFF

Something went wrong during the calculation.

It can be one of the following case (depending on the previous state):

STATUS_HANDSHAKEDConstant 
public static const STATUS_HANDSHAKED:uint = 0x03

The salt and 'B' token were received from the server. This status is set once receiveSaltAndServerToken was called. The protocol is ready for the next step, computeKeyProof.

STATUS_IDENTIFIEDConstant 
public static const STATUS_IDENTIFIED:uint = 0x02

The user has identified himself to the server by sending his or her username and 'A' token. This status is set once computeClientToken was called. The protocol is ready for the next step, receiveSaltAndServerToken.

STATUS_INITIALIZEDConstant 
public static const STATUS_INITIALIZED:uint = 0x01

The protocol was initialized and is ready to be used, starting with the step one, computeClientToken.

STATUS_PROOF_SENTConstant 
public static const STATUS_PROOF_SENT:uint = 0x04

The proof of session key 'M' was sent to the server. This status is set once computeKeyProof was called. The protocol is ready for the next and final step, validateServerProof.

STATUS_UNINITIALIZEDConstant 
public static const STATUS_UNINITIALIZED:uint = 0x00

Initial status of the authentication protocol. The initialize method must be called.