add signing keys to user object at login and register time

This commit is contained in:
ansuz 2017-03-15 18:57:13 +01:00
parent 8129b8cdc1
commit 0a6373852e
4 changed files with 30 additions and 3 deletions

View File

@ -127,11 +127,17 @@ define([
var passwd = $passwd.val();
Login.loginOrRegister(uname, passwd, false, function (err, result) {
if (!err) {
var proxy = result.proxy;
// successful validation and user already exists
// set user hash in localStorage and redirect to drive
if (result.proxy && !result.proxy.login_name) {
result.proxy.login_name = result.userName;
if (proxy && !proxy.login_name) {
proxy.login_name = result.userName;
}
proxy.edPrivate = result.edPrivate;
proxy.edPublic = result.edPublic;
Cryptpad.whenRealtimeSyncs(result.realtime, function () {
Cryptpad.login(result.userHash, result.userName, function () {
document.location.href = '/drive/';

View File

@ -11,6 +11,7 @@ define([
Cred: Cred,
};
var Nacl = window.nacl;
var allocateBytes = function (bytes) {
var dispense = Cred.dispenser(bytes);
@ -25,6 +26,12 @@ define([
// 32 more for a signing key
var edSeed = opt.edSeed = dispense(32);
// derive a private key from the ed seed
var signingKeypair = Nacl.sign.keyPair.fromSeed(new Uint8Array(edSeed));
opt.edPrivate = Nacl.util.encodeBase64(signingKeypair.secretKey);
opt.edPublic = Nacl.util.encodeBase64(signingKeypair.publicKey);
var keys = opt.keys = Crypto.createEditCryptor(null, encryptionSeed);
// 24 bytes of base64
@ -98,6 +105,10 @@ define([
res.userHash = opt.userHash;
res.userName = uname;
// export their signing key
res.edPrivate = opt.edPrivate;
res.edPublic = opt.edPublic;
// they tried to just log in but there's no such user
if (!isRegister && isProxyEmpty(rt.proxy)) {
rt.network.disconnect(); // clean up after yourself

View File

@ -71,12 +71,17 @@ define([
var passwd = $passwd.val();
Login.loginOrRegister(uname, passwd, false, function (err, result) {
if (!err) {
var proxy = result.proxy;
// successful validation and user already exists
// set user hash in localStorage and redirect to drive
if (result.proxy && !result.proxy.login_name) {
if (!proxy.login_name) {
result.proxy.login_name = result.userName;
}
proxy.edPrivate = result.edPrivate;
proxy.edPublic = result.edPublic;
Cryptpad.whenRealtimeSyncs(result.realtime, function() {
Cryptpad.login(result.userHash, result.userName, function () {
if (sessionStorage.redirectTo) {

View File

@ -63,6 +63,11 @@ define([
var logMeIn = function (result) {
localStorage.User_hash = result.userHash;
var proxy = result.proxy;
proxy.edPublic = result.edPublic;
proxy.edPrivate = result.edPrivate;
Cryptpad.whenRealtimeSyncs(result.realtime, function () {
Cryptpad.login(result.userHash, result.userName, function () {
if (sessionStorage.redirectTo) {