summaryrefslogtreecommitdiff
path: root/javascript/srp_register.js
diff options
context:
space:
mode:
authorausiv4 <ausiv4@eb105b4a-77de-11de-a249-6bf219df57d5>2009-08-07 03:38:03 +0000
committerausiv4 <ausiv4@eb105b4a-77de-11de-a249-6bf219df57d5>2009-08-07 03:38:03 +0000
commit29e50956daeadaa6786b7cf34ab96387e5295bb6 (patch)
treeb8f352d908cb580280fa7901997f90fffccee5b2 /javascript/srp_register.js
parent0ce2f0f249e0b0868056d3ce00a2db5ebe270605 (diff)
This update separates the register functionality from the login library. The login script is now .3 kb smaller, but there is a new 1.1 kb
register file. I think that registrations are rare enough relative to logins that this should be a worthwhile tradeoff. This also prepares a framework for importing an update file, which will allow existing installations to upgrade from less secure authentication protocols, so some of the overhead in srp.js that was added here will help reduce the size as we add the update functionality.
Diffstat (limited to 'javascript/srp_register.js')
-rw-r--r--javascript/srp_register.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/javascript/srp_register.js b/javascript/srp_register.js
new file mode 100644
index 0000000..31b8ab8
--- /dev/null
+++ b/javascript/srp_register.js
@@ -0,0 +1,52 @@
+function SRP_REGISTER()
+{
+ var that;
+
+ // Initiate the registration process
+ SRP.prototype.register = function()
+ {
+ that = this;
+ var handshake_url = this.geturl() + this.paths("register/salt/");
+ var params = "I="+this.getI();
+ this.ajaxRequest(handshake_url, params, this.register_receive_salt);
+ };
+
+ // Receive the salt for registration
+ SRP.prototype.register_receive_salt = function()
+ {
+ var xhr = that.getxhr();
+ if(xhr.readyState == 4 && xhr.status == 200) {
+ if(xhr.responseXML.getElementsByTagName("salt").length > 0)
+ {
+ var s = that.innerxml(xhr.responseXML.getElementsByTagName("salt")[0]);
+ var x = that.calcX(s);
+ var v = that.getg().modPow(x, that.getN());
+ that.register_send_verifier(v.toString(16));
+ }
+ else if(xhr.responseXML.getElementsByTagName("error").length > 0)
+ {
+ that.error_message(that.innerxml(xhr.responseXML.getElementsByTagName("error")[0]));
+ }
+ }
+ };
+ // Send the verifier to the server
+ SRP.prototype.register_send_verifier = function(v)
+ {
+ var params = "v="+v;
+ var auth_url = that.geturl() + that.paths("register/user/");
+ that.ajaxRequest(auth_url, params, that.register_user);
+ };
+
+ // The user has been registered successfully, now login
+ SRP.prototype.register_user = function()
+ {
+ var xhr = that.getxhr();
+ if(xhr.readyState == 4 && xhr.status == 200) {
+ if(xhr.responseXML.getElementsByTagName("ok").length > 0)
+ {
+ that.identify();
+ }
+ }
+ };
+};
+SRP_REGISTER();