From a41d7f306aa1dbcae17643cc9c3b457632ee8909 Mon Sep 17 00:00:00 2001 From: Azul <azul@riseup.net> Date: Mon, 19 Nov 2012 17:49:18 +0100 Subject: removed the SRP class - using just a plain srp object now --- src/srp.js | 92 ------------------------------------------------------ src/srp_session.js | 5 ++- 2 files changed, 2 insertions(+), 95 deletions(-) (limited to 'src') diff --git a/src/srp.js b/src/srp.js index 5b76a88..e57b7e9 100644 --- a/src/srp.js +++ b/src/srp.js @@ -16,95 +16,3 @@ var srp = (function(){ } }()); - -function SRP(remote, session) -{ - var srp = this; - session = session || new this.Session(); - session.onError = session.onError || this.error; - this.remote = remote; - this.session = session; - - // Start the login process by identifying the user - this.identify = function(success, error) - { - store_callbacks(success, error); - remote.handshake(session) - .success(receive_salts) - .error(srp.error); - - // 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) - .success(confirm_authentication) - .error(srp.error); - } - } - - // 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"); - }; - }; - - // Initiate the registration process - this.register = function(success, error) - { - store_callbacks(success, error); - remote.register(session) - .success(srp.registered_user) - .error(srp.error); - }; - - // The user has been registered successfully, now login - this.registered_user = function(response) - { - // TODO: This can go if response has an error code - if(response.errors) { - srp.error(response.errors) - } - else { - srp.identify(); - } - }; - - // 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() - { - alert("Login successful."); - }; - - // Minimal error handling - set remote.onError to sth better to overwrite. - this.error = function(text) - { - alert(text); - }; - - function store_callbacks(success, error) { - if (typeof success == "function") { - srp.success = success; - } - if (typeof error == "function") { - srp.error = error; - } - } -}; - diff --git a/src/srp_session.js b/src/srp_session.js index 8f45a44..7f1232f 100644 --- a/src/srp_session.js +++ b/src/srp_session.js @@ -1,4 +1,4 @@ -SRP.prototype.Session = function(login, password) { +srp.Session = function(login, password) { // Variables session will be used in the SRP protocol var Nstr = "eeaf0ab9adb38dd69c33f80afa8fc5e86072618775ff3c0b9ea2314c9c256576d674df7496ea81d3383b4813d692c6e0e0d5d8e250b98be48e495c1d6089dad15dc7d7b46154d6b6ce8ef4ad69b15d4982559b297bcf1885c529f566660e57ec68edbc3c05726cc02fd4cbf4976eaa9afd5138fe8376435b9fc61d2fc0eb06e3"; @@ -154,6 +154,5 @@ SRP.prototype.Session = function(login, password) { } return str; } +}; - -} -- cgit v1.2.3