mirror of https://github.com/xwiki-labs/cryptpad
add signing keys to user object at login and register time
This commit is contained in:
parent
8129b8cdc1
commit
0a6373852e
|
@ -127,11 +127,17 @@ define([
|
||||||
var passwd = $passwd.val();
|
var passwd = $passwd.val();
|
||||||
Login.loginOrRegister(uname, passwd, false, function (err, result) {
|
Login.loginOrRegister(uname, passwd, false, function (err, result) {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
|
var proxy = result.proxy;
|
||||||
|
|
||||||
// successful validation and user already exists
|
// successful validation and user already exists
|
||||||
// set user hash in localStorage and redirect to drive
|
// set user hash in localStorage and redirect to drive
|
||||||
if (result.proxy && !result.proxy.login_name) {
|
if (proxy && !proxy.login_name) {
|
||||||
result.proxy.login_name = result.userName;
|
proxy.login_name = result.userName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
proxy.edPrivate = result.edPrivate;
|
||||||
|
proxy.edPublic = result.edPublic;
|
||||||
|
|
||||||
Cryptpad.whenRealtimeSyncs(result.realtime, function () {
|
Cryptpad.whenRealtimeSyncs(result.realtime, function () {
|
||||||
Cryptpad.login(result.userHash, result.userName, function () {
|
Cryptpad.login(result.userHash, result.userName, function () {
|
||||||
document.location.href = '/drive/';
|
document.location.href = '/drive/';
|
||||||
|
|
|
@ -11,6 +11,7 @@ define([
|
||||||
Cred: Cred,
|
Cred: Cred,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var Nacl = window.nacl;
|
||||||
var allocateBytes = function (bytes) {
|
var allocateBytes = function (bytes) {
|
||||||
var dispense = Cred.dispenser(bytes);
|
var dispense = Cred.dispenser(bytes);
|
||||||
|
|
||||||
|
@ -25,6 +26,12 @@ define([
|
||||||
// 32 more for a signing key
|
// 32 more for a signing key
|
||||||
var edSeed = opt.edSeed = dispense(32);
|
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);
|
var keys = opt.keys = Crypto.createEditCryptor(null, encryptionSeed);
|
||||||
|
|
||||||
// 24 bytes of base64
|
// 24 bytes of base64
|
||||||
|
@ -98,6 +105,10 @@ define([
|
||||||
res.userHash = opt.userHash;
|
res.userHash = opt.userHash;
|
||||||
res.userName = uname;
|
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
|
// they tried to just log in but there's no such user
|
||||||
if (!isRegister && isProxyEmpty(rt.proxy)) {
|
if (!isRegister && isProxyEmpty(rt.proxy)) {
|
||||||
rt.network.disconnect(); // clean up after yourself
|
rt.network.disconnect(); // clean up after yourself
|
||||||
|
|
|
@ -71,12 +71,17 @@ define([
|
||||||
var passwd = $passwd.val();
|
var passwd = $passwd.val();
|
||||||
Login.loginOrRegister(uname, passwd, false, function (err, result) {
|
Login.loginOrRegister(uname, passwd, false, function (err, result) {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
|
var proxy = result.proxy;
|
||||||
|
|
||||||
// successful validation and user already exists
|
// successful validation and user already exists
|
||||||
// set user hash in localStorage and redirect to drive
|
// 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;
|
result.proxy.login_name = result.userName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
proxy.edPrivate = result.edPrivate;
|
||||||
|
proxy.edPublic = result.edPublic;
|
||||||
|
|
||||||
Cryptpad.whenRealtimeSyncs(result.realtime, function() {
|
Cryptpad.whenRealtimeSyncs(result.realtime, function() {
|
||||||
Cryptpad.login(result.userHash, result.userName, function () {
|
Cryptpad.login(result.userHash, result.userName, function () {
|
||||||
if (sessionStorage.redirectTo) {
|
if (sessionStorage.redirectTo) {
|
||||||
|
|
|
@ -63,6 +63,11 @@ define([
|
||||||
|
|
||||||
var logMeIn = function (result) {
|
var logMeIn = function (result) {
|
||||||
localStorage.User_hash = result.userHash;
|
localStorage.User_hash = result.userHash;
|
||||||
|
|
||||||
|
var proxy = result.proxy;
|
||||||
|
proxy.edPublic = result.edPublic;
|
||||||
|
proxy.edPrivate = result.edPrivate;
|
||||||
|
|
||||||
Cryptpad.whenRealtimeSyncs(result.realtime, function () {
|
Cryptpad.whenRealtimeSyncs(result.realtime, function () {
|
||||||
Cryptpad.login(result.userHash, result.userName, function () {
|
Cryptpad.login(result.userHash, result.userName, function () {
|
||||||
if (sessionStorage.redirectTo) {
|
if (sessionStorage.redirectTo) {
|
||||||
|
|
Loading…
Reference in New Issue