From 3565d0c362646d681cbac605924fcf7984b05a92 Mon Sep 17 00:00:00 2001 From: Zaran Date: Thu, 19 May 2011 18:31:47 +0200 Subject: Client-side user registration. Send a registration request on connect: * if the user is already registered, set the rsa key from the information sent by the server component. * if not, display the registration form. The forms contains a link to generate a new rsa public/private key (and encrypt the private with the user's password). --- webclient/lib/alias.js | 95 ++++++++++++++++++-------------------------------- 1 file changed, 34 insertions(+), 61 deletions(-) (limited to 'webclient/lib/alias.js') diff --git a/webclient/lib/alias.js b/webclient/lib/alias.js index 4adac04..c19d025 100644 --- a/webclient/lib/alias.js +++ b/webclient/lib/alias.js @@ -17,55 +17,6 @@ var Alias = { */ connection: null, - form: { - render: function(form){ - var result = $('
'); - - if ( form.find('title').length !== 0 ){ - result.append('

' + form.find('title') + '

'); - } - - if ( form.find('instructions').length !== 0 ){ - result.append('

' - + form.find('instructions') + '

'); - } - - form.find('field').each(function(index){ - var type = $(this).attr("type"); - var name = $(this).attr("var"); - var required = $(this).find('required').length !== 0; - - if ( $(this).find('desc').length !== 0 ){ - result.append('

' - + $(this).find('desc').text() - + '

'); - } - - if ( $(this).attr('label') !== undefined ){ - result.append(''); - } - - switch(type){ - case("text-single"): - var input = $(''); - input.attr('type', 'text'); - input.attr('name', name); - input.attr('id', 'form-' + name); - - if ( $(this).find('value').length !== 0 ){ - input.attr('value', $(this).find('value').text()); - } - result.append(input); - result.append('
'); - } - }); - return result; - } - }, - /** * Send registration request to the component */ @@ -80,22 +31,48 @@ var Alias = { */ onRegister: function(iq) { var form = $(iq).find('query x'); - if ($(iq).find('query > registered').length !== 0){ + if ($(iq).find('registered').length !== 0){ // user is registered, get the info from the form - this.pubkey = form.find('field[var="pubkey"] > value'); - this.salt = form.find('field[var="pubkey"] > value'); - var privkey = form.find('field[var="pubkey"] > value'); - var salt = form.find('field[var="salt"] > value'); - this.privkey = sjcl.decrypt(Alias.connection.pass, privkey, {salt: salt}); + var pubkey = form.find('field[var="pubkey"] > value').text(); + var privkey = form.find('field[var="privkey"] > value').text(); + privkey = sjcl.decrypt(Alias.connection.pass, privkey); + pubkey = JSON.parse(pubkey); + privkey = JSON.parse(privkey); + var rsa = new RSAKey(); + rsa.setPublic(pubkey.n, pubkey.e); + rsa.setPrivate(pubkey.n, pubkey.e, privkey.d); + this.rsa = rsa; } else{ $('#register').empty(); - var instructions = $(iq).find('query > instructions'); + var instructions = $(iq).find('instructions'); if ( instructions.length !== 0 ){ $('#register').append('

' + instructions.text() + '

'); } - var result = Alias.form.render(form); + var result = form.xmppForm('render'); + $('#register').append('

Generate

'); + $('#generate').click(function(){ + var rsa = new RSAKey(); + rsa.generate(1024, "10001"); + var pubkey = {n: rsa.n.toString(16), e: rsa.e.toString(16)}; + var privkey = {d: rsa.d.toString(16)}; + privkey = sjcl.encrypt(Alias.connection.pass, JSON.stringify(privkey)); + $("#form-pubkey").val(JSON.stringify(pubkey)); + $("#form-privkey").val(privkey); + }); $('#register').append(result); + $('#register').append(''); + $('#register-button').click(function(){ + var pubkey = $('