diff options
author | Azul <azul@riseup.net> | 2013-03-20 12:51:56 +0100 |
---|---|---|
committer | Azul <azul@riseup.net> | 2013-03-20 12:51:56 +0100 |
commit | 3328b20621265b0c50ed395ea890b267ab89109b (patch) | |
tree | 5afee96076bd922653231af818e98d5147457dff /src/srp.js | |
parent | 527eb51ad4b943bde7e2ba411f5772611a80463c (diff) | |
parent | d29d1146865d36e9d9789d3936e7a9163511be0a (diff) |
Merge branch 'release/0.3.0'
Diffstat (limited to 'src/srp.js')
-rw-r--r-- | src/srp.js | 86 |
1 files changed, 12 insertions, 74 deletions
@@ -1,86 +1,24 @@ -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; +var srp = (function(){ - // Start the login process by identifying the user - this.identify = function(success, error) + function signup() { - store_callbacks(success, error); - 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 - could not login."); - } - else if(! response.salt || response.salt === 0) { - srp.error("Server failed to send salt - could not login."); - } - else - { - session.calculations(response.salt, 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.M2)) - srp.success(); - else - srp.error("Server key does not match"); - }; + srp.remote.signup(); }; - // Initiate the registration process - this.register = function(success, error) - { - store_callbacks(success, error); - remote.register(session, srp.registered_user); - }; - - // The user has been registered successfully, now login - this.registered_user = function(response) - { - if(response.errors) { - srp.error(response.errors) - } - else { - srp.identify(); - } - }; - - // Minimal error handling - set remote.onError to sth better to overwrite. - this.error = function(text) + function login() { - alert(text); + srp.remote.login(); }; - // This function is called when authentication is successful. - // It's a dummy. Please hand the real thing to the call to identify. - this.success = function() + function update(submitEvent) { - alert("Login successful."); + srp.remote.update(submitEvent); }; - function store_callbacks(success, error) { - if (typeof success == "function") { - srp.success = success; - } - if (typeof error == "function") { - srp.error = error; - } + return { + signup: signup, + update: update, + login: login } -}; +}()); |