diff options
| author | Azul <azul@riseup.net> | 2012-11-19 17:36:49 +0100 | 
|---|---|---|
| committer | Azul <azul@riseup.net> | 2012-11-19 17:36:49 +0100 | 
| commit | 2e365cba5263ec50f10fb074c054ef19adb8f7b0 (patch) | |
| tree | 2f0a7aba3ab7a5da123de781357ef71a9be7f91d /src | |
| parent | 49bfe6ab74229ba4da5342382b87dcd6fca239fa (diff) | |
first step at cleaning up the srp
Diffstat (limited to 'src')
| -rw-r--r-- | src/jqueryRest.js | 50 | ||||
| -rw-r--r-- | src/srp.js | 19 | 
2 files changed, 69 insertions, 0 deletions
diff --git a/src/jqueryRest.js b/src/jqueryRest.js index a7928d5..29f737c 100644 --- a/src/jqueryRest.js +++ b/src/jqueryRest.js @@ -35,3 +35,53 @@ jqueryRest = function() {      authenticate: authenticate    };  }; + +srp.remote = (function(){ + +  function signup(){ +    jqueryRest().register(srp.session) +    .success(srp.signedUp) +    .error(srp.error) +  }; + +  function login(){ +    jqueryRest().handshake(srp.session) +    .success(receiveSalts) +    .error(srp.error) +  }; + +  function receiveSalts(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  +    { +      srp.session.calculations(response.salt, response.B); +      jqueryRest().authenticate(srp.session) +      .success(confirmAuthentication) +      .error(srp.error); +    } +  }; + +  // Receive M2 from the server and verify it +  // If an error occurs, raise it as an alert. +  function confirmAuthentication(response) +  { +    if (srp.session.validate(response.M2)) +      srp.loggedIn(); +    else +      srp.error("Server key does not match"); +  }; + + +  return { +    signup: signup, +    login: login +  } + +}()); @@ -1,3 +1,22 @@ +var srp = (function(){ + +  function signup() +  { +    this.remote.signup(); +  }; + +  function login() +  { +    this.remote.login(); +  }; + +  return { +    signup: signup, +    login: login +  } +}()); + +  function SRP(remote, session)  {    var srp = this;  | 
