summaryrefslogtreecommitdiff
path: root/lib/srp.js
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2012-08-21 17:14:06 +0200
committerAzul <azul@riseup.net>2012-08-21 17:14:29 +0200
commitd5e30a95e09bab18a55f9aad1572b6ae3e16e482 (patch)
treef2e6646a800788d8ea8ea8b531d075844d12360e /lib/srp.js
parent79610eaf3c0628c8b84da3a4bbf8a6598e1a03cb (diff)
moved on with refactoring
* srp_register now is part of srp.js * moved server specific stuff into plainXHR (such as fetching the seed from the server) * fixed tests
Diffstat (limited to 'lib/srp.js')
-rw-r--r--lib/srp.js59
1 files changed, 38 insertions, 21 deletions
diff --git a/lib/srp.js b/lib/srp.js
index b54d6b7..0482a06 100644
--- a/lib/srp.js
+++ b/lib/srp.js
@@ -3,43 +3,60 @@ function SRP(remote, session)
var srp = this;
session = session || new this.Session();
remote = remote || new this.Remote();
+ remote.onError = remote.onError || this.error;
+ session.onError = session.onError || this.error;
+ this.remote = remote;
+ this.session = session;
// Start the login process by identifying the user
this.identify = function()
{
remote.handshake(session, receive_salts);
+
+ // Receive login salts from the server, start calculations
+ function receive_salts(response)
+ {
+ // B = 0 will make the algorithm always succeed
+ // -> refuse such a server answer
+ if(response.B == 0) {
+ srp.error("Server send random number 0 - this is not allowed");
+ } else {
+ session.calculations(response.s, response.B);
+ remote.authenticate(session, confirm_authentication)
+ }
+ };
+
+ // Receive M2 from the server and verify it
+ // If an error occurs, raise it as an alert.
+ function confirm_authentication(response)
+ {
+ if (session.validate(response.M))
+ srp.success();
+ else
+ srp.error("Server key does not match");
+ };
};
- // Receive login salts from the server, start calculations
- function receive_salts(response)
+ // Initiate the registration process
+ this.register = function()
{
- // B = 0 will make the algorithm always succeed
- // -> refuse such a server answer
- if(response.B == 0) {
- srp.error("Server send random number 0 - this is not allowed");
- } else {
- session.calculations(response.s, response.B);
- remote.authenticate(session, confirm_authentication)
- }
+ remote.register(session, srp.registered_user);
};
- // Receive M2 from the server and verify it
- // If an error occurs, raise it as an alert.
- function confirm_authentication(response)
+ // The user has been registered successfully, now login
+ this.registered_user = function(response)
{
- if (session.validate(response.M))
- srp.success();
- else
- alertErrorMessage("Server key does not match");
- };
+ if(response.ok)
+ {
+ srp.identify();
+ }
+ };
// Minimal error handling - set remote.onError to sth better to overwrite.
this.error = function(text)
{
alert(text);
};
- remote.onError = remote.onError || this.error;
- session.onError = session.onError || this.error;
// This function is called when authentication is successful.
// Developers can set this to other functions in specific implementations
@@ -55,5 +72,5 @@ function SRP(remote, session)
alert("Login successful.");
}
};
-
};
+