Merge branch 'msg' of github.com:xwiki-labs/cryptpad into msg
This commit is contained in:
commit
852b2eaf1d
@ -54,7 +54,7 @@ Version 1
|
|||||||
if (!hash) { return; }
|
if (!hash) { return; }
|
||||||
var parsed = {};
|
var parsed = {};
|
||||||
var hashArr = fixDuplicateSlashes(hash).split('/');
|
var hashArr = fixDuplicateSlashes(hash).split('/');
|
||||||
if (['media', 'file', 'user'].indexOf(type) === -1) {
|
if (['media', 'file', 'user', 'invite'].indexOf(type) === -1) {
|
||||||
parsed.type = 'pad';
|
parsed.type = 'pad';
|
||||||
if (hash.slice(0,1) !== '/' && hash.length >= 56) {
|
if (hash.slice(0,1) !== '/' && hash.length >= 56) {
|
||||||
// Old hash
|
// Old hash
|
||||||
@ -93,6 +93,16 @@ Version 1
|
|||||||
}
|
}
|
||||||
return parsed;
|
return parsed;
|
||||||
}
|
}
|
||||||
|
if (['invite'].indexOf(type) !== -1) {
|
||||||
|
parsed.type = 'invite';
|
||||||
|
if (hashArr[1] && hashArr[1] === '1') {
|
||||||
|
parsed.version = 1;
|
||||||
|
parsed.channel = hashArr[2];
|
||||||
|
parsed.pubkey = hashArr[3].replace(/-/g, '/');
|
||||||
|
return parsed;
|
||||||
|
}
|
||||||
|
return parsed;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
var parsePadUrl = Hash.parsePadUrl = function (href) {
|
var parsePadUrl = Hash.parsePadUrl = function (href) {
|
||||||
@ -320,5 +330,11 @@ Version 1
|
|||||||
return hash;
|
return hash;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Hash.createInviteUrl = function (curvePublic, channel) {
|
||||||
|
channel = channel || Hash.createChannelId();
|
||||||
|
return window.location.origin + '/invite/#/1/' + channel +
|
||||||
|
'/' + curvePublic.replace(/\//g, '-') + '/';
|
||||||
|
};
|
||||||
|
|
||||||
return Hash;
|
return Hash;
|
||||||
});
|
});
|
||||||
|
|||||||
@ -108,6 +108,7 @@ define([
|
|||||||
common.findWeaker = Hash.findWeaker;
|
common.findWeaker = Hash.findWeaker;
|
||||||
common.findStronger = Hash.findStronger;
|
common.findStronger = Hash.findStronger;
|
||||||
common.serializeHash = Hash.serializeHash;
|
common.serializeHash = Hash.serializeHash;
|
||||||
|
common.createInviteUrl = Hash.createInviteUrl;
|
||||||
|
|
||||||
// Messaging
|
// Messaging
|
||||||
common.addDirectMessageHandler = Messaging.addDirectMessageHandler;
|
common.addDirectMessageHandler = Messaging.addDirectMessageHandler;
|
||||||
|
|||||||
47
www/common/curve-put.js
Normal file
47
www/common/curve-put.js
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
define([
|
||||||
|
'/common/curve.js',
|
||||||
|
'/bower_components/chainpad-listmap/chainpad-listmap.js',
|
||||||
|
], function (Curve, Listmap) {
|
||||||
|
var Edit = {};
|
||||||
|
|
||||||
|
Edit.create = function (network, channel, theirs, mine, cb) {
|
||||||
|
try {
|
||||||
|
var encryptor = Curve.createEncryptor(theirs, mine);
|
||||||
|
var lm = Listmap.create({
|
||||||
|
network: network,
|
||||||
|
data: {},
|
||||||
|
channel: channel,
|
||||||
|
readOnly: false,
|
||||||
|
validateKey: undefined,
|
||||||
|
crypto: encryptor,
|
||||||
|
userName: 'lol',
|
||||||
|
logLevel: 1,
|
||||||
|
});
|
||||||
|
|
||||||
|
var done = function () {
|
||||||
|
// TODO make this abort and disconnect the session after the
|
||||||
|
// user has finished making changes to the object, and they
|
||||||
|
// have propagated.
|
||||||
|
};
|
||||||
|
|
||||||
|
lm.proxy
|
||||||
|
.on('create', function () {
|
||||||
|
console.log('created');
|
||||||
|
})
|
||||||
|
.on('ready', function () {
|
||||||
|
console.log('ready');
|
||||||
|
cb(lm, done);
|
||||||
|
})
|
||||||
|
.on('disconnect', function () {
|
||||||
|
console.log('disconnected');
|
||||||
|
})
|
||||||
|
.on('change', [], function (o, n, p) {
|
||||||
|
console.log(o, n, p);
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return Edit;
|
||||||
|
});
|
||||||
@ -2,35 +2,36 @@ define([
|
|||||||
'/bower_components/tweetnacl/nacl-fast.min.js',
|
'/bower_components/tweetnacl/nacl-fast.min.js',
|
||||||
], function () {
|
], function () {
|
||||||
var Nacl = window.nacl;
|
var Nacl = window.nacl;
|
||||||
|
|
||||||
var Curve = {};
|
var Curve = {};
|
||||||
|
|
||||||
// nacl.box(message, nonce, theirPublicKey, mySecretKey)
|
// nacl.box(message, nonce, theirPublicKey, mySecretKey)
|
||||||
Curve.encrypt = function (message, theirPub, mySecret) {
|
Curve.encrypt = function (message, theirPub, mySecret) {
|
||||||
var buffer = Nacl.util.decodeUTF8(message);
|
var buffer = Nacl.util.decodeUTF8(message);
|
||||||
|
|
||||||
var nonce = Nacl.randomBytes(24);
|
var nonce = Nacl.randomBytes(24);
|
||||||
|
|
||||||
var box = Nacl.box(buffer, nonce, theirPub, mySecret);
|
var box = Nacl.box(buffer, nonce, theirPub, mySecret);
|
||||||
|
return Nacl.util.encodeBase64(nonce) + '|' + Nacl.util.encodeBase64(box);
|
||||||
return [Nacl.util.encodeBase64(nonce), Nacl.util.encodeBase64(box)].join('|');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// nacl.box.open(box, nonce, theirPublicKey, mySecretKey)
|
// nacl.box.open(box, nonce, theirPublicKey, mySecretKey)
|
||||||
Curve.decrypt = function (packed, theirPub, mySecret) {
|
Curve.decrypt = function (packed, theirPub, mySecret) {
|
||||||
var unpacked = packed.split('|');
|
var unpacked = packed.split('|');
|
||||||
var nonce = Nacl.util.decodeBase64(unpacked[0]);
|
var nonce = Nacl.util.decodeBase64(unpacked[0]);
|
||||||
|
|
||||||
var box = Nacl.util.decodeBase64(unpacked[1]);
|
var box = Nacl.util.decodeBase64(unpacked[1]);
|
||||||
|
|
||||||
var message = Nacl.box.open(box, nonce, theirPub, mySecret);
|
var message = Nacl.box.open(box, nonce, theirPub, mySecret);
|
||||||
|
|
||||||
return Nacl.util.encodeUTF8(message);
|
return Nacl.util.encodeUTF8(message);
|
||||||
};
|
};
|
||||||
|
|
||||||
Curve.createEncryptor = function () {
|
Curve.createEncryptor = function (theirPublic, mySecret) {
|
||||||
console.log("PEWPEW");
|
var theirs = Nacl.util.decodeBase64(theirPublic);
|
||||||
throw new Error("E_NOT_IMPL");
|
var mine = Nacl.util.decodeBase64(mySecret);
|
||||||
|
return {
|
||||||
|
encrypt: function (msg) {
|
||||||
|
return Curve.encrypt(msg, theirs, mine);
|
||||||
|
},
|
||||||
|
decrypt: function (packed) {
|
||||||
|
return Curve.decrypt(packed, theirs, mine);
|
||||||
|
}
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
return Curve;
|
return Curve;
|
||||||
|
|||||||
@ -7,52 +7,49 @@ define([
|
|||||||
], function ($, Cryptpad, Listmap, Curve) {
|
], function ($, Cryptpad, Listmap, Curve) {
|
||||||
var APP = window.APP = {};
|
var APP = window.APP = {};
|
||||||
|
|
||||||
var Nacl = window.nacl;
|
|
||||||
|
|
||||||
var alice = Nacl.box.keyPair();
|
|
||||||
var bob = Nacl.box.keyPair();
|
|
||||||
|
|
||||||
var packed = Curve.encrypt('pewpew', bob.publicKey, alice.secretKey);
|
|
||||||
console.log(packed);
|
|
||||||
|
|
||||||
var message = Curve.decrypt(packed, alice.publicKey, bob.secretKey);
|
|
||||||
|
|
||||||
console.log(message);
|
|
||||||
|
|
||||||
Cryptpad.removeLoadingScreen();
|
|
||||||
Cryptpad.alert(message);
|
|
||||||
|
|
||||||
return {};
|
|
||||||
|
|
||||||
//var Messages = Cryptpad.Messages;
|
//var Messages = Cryptpad.Messages;
|
||||||
var onReady = function () {
|
|
||||||
|
|
||||||
if (!APP.initialized) {
|
|
||||||
APP.initialized = true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var onInit = function () {};
|
var onInit = function () {};
|
||||||
|
|
||||||
var onDisconnect = function () {};
|
var onDisconnect = function () {};
|
||||||
var onChange = function () {};
|
var onChange = function () {};
|
||||||
|
|
||||||
var andThen = function (profileHash) {
|
var andThen = function () {
|
||||||
var secret = Cryptpad.getSecrets('profile', profileHash);
|
var hash = window.location.hash.slice(1);
|
||||||
var readOnly = APP.readOnly = secret.keys && !secret.keys.editKeyStr;
|
|
||||||
|
var info = Cryptpad.parseTypeHash('invite', hash);
|
||||||
|
console.log(info);
|
||||||
|
|
||||||
|
if (!info.pubkey) {
|
||||||
|
Cryptpad.removeLoadingScreen();
|
||||||
|
Cryptpad.alert('invalid invite');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var proxy = Cryptpad.getProxy();
|
||||||
|
var mySecret = proxy.curvePrivate;
|
||||||
|
|
||||||
|
var encryptor = Curve.createEncryptor(info.pubkey, mySecret);
|
||||||
|
|
||||||
|
Cryptpad.removeLoadingScreen();
|
||||||
|
var message = 'hello!';
|
||||||
|
Cryptpad.alert(message);
|
||||||
|
|
||||||
var listmapConfig = {
|
var listmapConfig = {
|
||||||
data: {},
|
data: {},
|
||||||
websocketURL: Cryptpad.getWebsocketURL(),
|
network: Cryptpad.getNetwork(),
|
||||||
channel: secret.channel,
|
channel: info.channel,
|
||||||
readOnly: readOnly,
|
readOnly: false, //undefined,
|
||||||
validateKey: secret.keys.validateKey || undefined,
|
validateKey: undefined,
|
||||||
crypto: Crypto.createEncryptor(secret.keys),
|
crypto: encryptor,
|
||||||
userName: 'profile',
|
userName: 'profile',
|
||||||
logLevel: 1,
|
logLevel: 1,
|
||||||
};
|
};
|
||||||
var lm = APP.lm = Listmap.create(listmapConfig);
|
var lm = APP.lm = Listmap.create(listmapConfig);
|
||||||
lm.proxy.on('create', onInit)
|
lm.proxy.on('create', onInit)
|
||||||
.on('ready', onReady)
|
.on('ready', function () {
|
||||||
|
APP.initialized = true;
|
||||||
|
console.log(JSON.stringify(lm.proxy));
|
||||||
|
})
|
||||||
.on('disconnect', onDisconnect)
|
.on('disconnect', onDisconnect)
|
||||||
.on('change', [], onChange);
|
.on('change', [], onChange);
|
||||||
};
|
};
|
||||||
@ -84,11 +81,7 @@ define([
|
|||||||
|
|
||||||
Cryptpad.ready(function () {
|
Cryptpad.ready(function () {
|
||||||
Cryptpad.reportAppUsage();
|
Cryptpad.reportAppUsage();
|
||||||
|
andThen();
|
||||||
if (window.location.hash) {
|
|
||||||
return void andThen(window.location.hash.slice(1));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user