summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2012-11-19 17:49:18 +0100
committerAzul <azul@riseup.net>2012-11-19 17:49:18 +0100
commita41d7f306aa1dbcae17643cc9c3b457632ee8909 (patch)
treed7aa8ef9b1a2c187793d01af668e0943a1093da5
parent2e365cba5263ec50f10fb074c054ef19adb8f7b0 (diff)
removed the SRP class - using just a plain srp object now
-rw-r--r--spec/login_spec.js95
-rw-r--r--spec/session_spec.js1
-rw-r--r--spec/signup_spec.js34
-rw-r--r--src/srp.js92
-rw-r--r--src/srp_session.js5
5 files changed, 9 insertions, 218 deletions
diff --git a/spec/login_spec.js b/spec/login_spec.js
index 7bb11f6..da343a5 100644
--- a/spec/login_spec.js
+++ b/spec/login_spec.js
@@ -1,96 +1,3 @@
-describe("Login", function() {
-
- it("has an identify function", function() {
- var srp = new SRP(jqueryRest());
- expect(typeof srp.identify).toBe('function');
- });
-
- describe("(Compatibility with py-srp)", function (){
- // these need to be the same as in the spec runner:
- var login = "testuser";
- var password = "password";
- // a valid auth attempt for the user / password given in the spec runner:
- var a = 'a5cccf937ea1bf72df5cf8099442552f5664da6780a75436d5a59bc77a8a9993';
- var A = 'e67d222244564ccd2e37471f226b999a4e987f3d494c7d80e0d36169efd6c6c6d857a96924c25fc165e5e9b0212a31c30701ec376dc32e36be00bbcd6d2104789d368af984e26fc094374f90ee5746478f14cec45c7e131a3cbce15fe79e98894213dac4e63c3f73f644fe25aa8707bc58859dfd1b36972e4e34169db2622899';
- // just for the sake of having a complete set of test vars:
- var b = '6aa5c88d1877af9907ccefad31083e1102a7121dc04706f681f66c8680fb7f05';
- var B = 'd56a80aaafdf9f70598b5d1184f122f326a333fafd37ab76d6f7fba4a9c4ee59545be056335150bd64f04880bc8e76949469379fe9de17cf6f36f3ee11713d05f63050486bc73c545163169999ff01b55c0ca4e90d8856a6e3d3a6ffc70b70d993a5308a37a5c2399874344e083e72b3c9afa083d312dfe9096ea9a65023f135';
- var salt = '628365a0';
- var K = 'db6ec0bdab81742315861a828323ff492721bdcd114077a4124bc425e4bf328b';
- var M = '640e51d5ac5461591c31811221261f0e0eae7c08ce43c85e9556adbd94ed8c26';
- var M2 = '49e48f8ac8c4da0e8a7374f73eeedbee2266e123d23fc1be1568523fc9c24b1e';
- var V = '6f5fb78184161f4191babaf1a700ff70e4d261054d002466d05f2ec2b45fc8807dbd7ce25dc3c882331eb8bf72a22caf2868e3438477be7ab151d3281d00aa1a9fc5cb6a725abd99e11882f77d52b56b83f95c0ba0b8fbbf4ee1fbb445c35adb5d1aaa48ba761c4a4417f6bb821fb61956c919e47740b316b960653303fe7190';
- var A_, callback;
-
-
- beforeEach(function() {
- this.srp = new SRP(jqueryRest());
-
- specHelper.setupFakeXHR.apply(this);
-
- A_ = this.srp.session.calculateAndSetA(a)
- });
-
- afterEach(function() {
- this.xhr.restore();
- });
-
- it("calculates the same A", function(){
- expect(A_).toBe(A);
- });
-
- it("calculates the same verifier", function(){
- expect(this.srp.session.getV().toString(16)).toBe(V);
- });
-
- it("calculates the same key", function(){
- this.srp.session.calculations(salt, B);
- expect(this.srp.session.key()).toBe(K);
- });
-
- it("authenticates successfully", function(){
- var success = sinon.spy();
- this.srp.identify(success);
-
- this.expectRequest('sessions.json', 'login=' +login+ '&A=' +A, 'POST');
- this.respondJSON({salt: salt, B: B});
- this.expectRequest('sessions/'+login+'.json', 'client_auth='+M, 'PUT');
- this.respondJSON({M2: M2});
-
- expect(success).toHaveBeenCalled();
- });
-
- it("reports errors during handshake", function(){
- this.srp.error = sinon.spy();
- var error = {login: "something went wrong on the server side"};
- this.srp.identify();
-
- this.expectRequest('sessions.json', 'login=' +login+ '&A=' +A, 'POST');
- this.respondJSON(error, 422);
- //this.expectNoMoreRequests();
-
- expect(this.srp.error).toHaveBeenCalled;
- var args = this.srp.error.args[0];
- expect($.parseJSON(args[0].responseText)).toEqual(error);
- });
-
- it("rejects B = 0", function(){
- var success = sinon.spy();
- var error = sinon.spy();
- this.srp.identify(success, error);
-
- this.expectRequest('sessions.json', 'login=' +login+ '&A=' +A, 'POST');
- this.respondJSON({salt: salt, B: 0});
- // aborting if B=0
- expect(this.requests).toEqual([]);
- expect(error).toHaveBeenCalledWith("Server send random number 0 - could not login.");
- expect(success).not.toHaveBeenCalled();
- });
- });
-
-
-});
-
describe("Login with srp var", function() {
describe("(Compatibility with py-srp)", function (){
@@ -112,8 +19,6 @@ describe("Login with srp var", function() {
beforeEach(function() {
- srp.session = new SRP().session;
-
specHelper.setupFakeXHR.apply(this);
A_ = srp.session.calculateAndSetA(a)
diff --git a/spec/session_spec.js b/spec/session_spec.js
index b7f16f0..643a717 100644
--- a/spec/session_spec.js
+++ b/spec/session_spec.js
@@ -15,7 +15,6 @@ describe("Session", function() {
var session;
beforeEach(function() {
- var srp = new SRP(jqueryRest());
session = new srp.Session(compare.username, compare.password);
});
diff --git a/spec/signup_spec.js b/spec/signup_spec.js
index fcb5930..41af179 100644
--- a/spec/signup_spec.js
+++ b/spec/signup_spec.js
@@ -1,38 +1,19 @@
-describe("Signup", function() {
-
- beforeEach(function() {
- this.srp = new SRP(jqueryRest());
- specHelper.setupFakeXHR.apply(this);
- });
-
- afterEach(function() {
- this.xhr.restore();
- });
-
- it("has a register function", function() {
- expect(typeof this.srp.register).toBe('function');
+describe("Loading SRP", function() {
+ it("provides a signup function", function() {
+ expect(typeof srp.signup).toBe('function');
});
- it("calculates the right x", function(){
- expect(this.srp.session.calcX("7686acb8").toString(16)).toBe('84d6bb567ddf584b1d8c8728289644d45dbfbb02deedd05c0f64db96740f0398');
+ it("provides session which calculates the right x", function(){
+ srp.session = new srp.Session();
+ expect(srp.session.calcX("7686acb8").toString(16)).toBe('84d6bb567ddf584b1d8c8728289644d45dbfbb02deedd05c0f64db96740f0398');
});
-
- it("identifies after successful registration (INTEGRATION)", function(){
- var callback = sinon.spy();
- this.srp.identify = callback;
- this.srp.session.getSalt = function() {return "4c78c3f8"};
- this.srp.register();
- this.expectRequest('users.json', "user[login]=testuser&user[password_salt]=4c78c3f8&user[password_verifier]=474c26aa42d11f20544a00f7bf9711c4b5cf7aab95ed448df82b95521b96668e7480b16efce81c861870302560ddf6604c67df54f1d04b99d5bb9d0f02c6051ada5dc9d594f0d4314e12f876cfca3dcd99fc9c98c2e6a5e04298b11061fb8549a22cde0564e91514080df79bca1c38c682214d65d590f66b3719f954b078b83c", 'POST')
- this.respondJSON({password_salt: "4c78c3f8", login: "testuser", ok: "true"});
- expect(callback).toHaveBeenCalled();
- });
-
});
describe("Signup with srp var", function() {
beforeEach(function() {
specHelper.setupFakeXHR.apply(this);
+ srp.session = new srp.Session();
});
afterEach(function() {
@@ -42,7 +23,6 @@ describe("Signup with srp var", function() {
it("identifies after successful registration (INTEGRATION)", function(){
var callback = sinon.spy();
srp.signedUp = callback;
- srp.session = new SRP().session
srp.session.getSalt = function() {return "4c78c3f8"};
srp.signup();
this.expectRequest('users.json', "user[login]=testuser&user[password_salt]=4c78c3f8&user[password_verifier]=474c26aa42d11f20544a00f7bf9711c4b5cf7aab95ed448df82b95521b96668e7480b16efce81c861870302560ddf6604c67df54f1d04b99d5bb9d0f02c6051ada5dc9d594f0d4314e12f876cfca3dcd99fc9c98c2e6a5e04298b11061fb8549a22cde0564e91514080df79bca1c38c682214d65d590f66b3719f954b078b83c", 'POST')
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;
}
+};
-
-}