update to use new style crypto module

pull/1/head
ansuz 9 years ago
parent f94c06abc0
commit 849683d586

@ -10,18 +10,20 @@ define([
'/bower_components/textpatcher/TextPatcher.amd.js', '/bower_components/textpatcher/TextPatcher.amd.js',
'json.sortify', 'json.sortify',
'/bower_components/chainpad-json-validator/json-ot.js', '/bower_components/chainpad-json-validator/json-ot.js',
'/common/cryptpad-common.js',
'/bower_components/fabric.js/dist/fabric.min.js', '/bower_components/fabric.js/dist/fabric.min.js',
'/bower_components/jquery/dist/jquery.min.js', '/bower_components/jquery/dist/jquery.min.js',
'/bower_components/file-saver/FileSaver.min.js', '/bower_components/file-saver/FileSaver.min.js',
'/customize/pad.js' '/customize/pad.js'
], function (Config, Realtime, Messages, Crypto, TextPatcher, JSONSortify, JsonOT) { ], function (Config, Realtime, Messages, Crypto, TextPatcher, JSONSortify, JsonOT, Cryptpad) {
var saveAs = window.saveAs; var saveAs = window.saveAs;
var module = window.APP = { }; var module = window.APP = { };
var $ = module.$ = window.jQuery; var $ = module.$ = window.jQuery;
var Fabric = module.Fabric = window.fabric; var Fabric = module.Fabric = window.fabric;
var secret = Cryptpad.getSecrets();
/*
var key; var key;
var channel = ''; var channel = '';
if (!/#/.test(window.location.href)) { if (!/#/.test(window.location.href)) {
@ -30,7 +32,7 @@ define([
var hash = window.location.hash.slice(1); var hash = window.location.hash.slice(1);
channel = hash.slice(0, 32); channel = hash.slice(0, 32);
key = hash.slice(32); key = hash.slice(32);
} }*/
/* Initialize Fabric */ /* Initialize Fabric */
var canvas = module.canvas = new Fabric.Canvas('canvas'); var canvas = module.canvas = new Fabric.Canvas('canvas');
@ -78,14 +80,14 @@ define([
// TODO initialState ? // TODO initialState ?
websocketURL: Config.websocketURL, websocketURL: Config.websocketURL,
//userName: Crypto.rand64(8), //userName: Crypto.rand64(8),
channel: channel, channel: secret.channel,
cryptKey: key, //cryptKey: key,
crypto: Crypto, crypto: Crypto.createEncryptor(secret.key),
transformFunction: JsonOT.validate, transformFunction: JsonOT.validate,
}; };
var onInit = config.onInit = function (info) { var onInit = config.onInit = function (info) {
window.location.hash = info.channel + key; window.location.hash = info.channel + secret.key;
$(window).on('hashchange', function() { $(window).on('hashchange', function() {
window.location.reload(); window.location.reload();
}); });

@ -8,10 +8,11 @@ define([
'/common/toolbar.js', '/common/toolbar.js',
'json.sortify', 'json.sortify',
'/bower_components/chainpad-json-validator/json-ot.js', '/bower_components/chainpad-json-validator/json-ot.js',
'/common/cryptpad-common.js',
'/bower_components/file-saver/FileSaver.min.js', '/bower_components/file-saver/FileSaver.min.js',
'/bower_components/jquery/dist/jquery.min.js', '/bower_components/jquery/dist/jquery.min.js',
'/customize/pad.js' '/customize/pad.js'
], function (Config, /*RTCode,*/ Messages, Crypto, Realtime, TextPatcher, Toolbar, JSONSortify, JsonOT) { ], function (Config, /*RTCode,*/ Messages, Crypto, Realtime, TextPatcher, Toolbar, JSONSortify, JsonOT, Cryptpad) {
var $ = window.jQuery; var $ = window.jQuery;
var saveAs = window.saveAs; var saveAs = window.saveAs;
var module = window.APP = {}; var module = window.APP = {};
@ -24,6 +25,8 @@ define([
var userName = Crypto.rand64(8), var userName = Crypto.rand64(8),
toolbar; toolbar;
var secret = Cryptpad.getSecrets();
/*
var key; var key;
var channel = ''; var channel = '';
var hash = false; var hash = false;
@ -33,7 +36,7 @@ define([
hash = window.location.hash.slice(1); hash = window.location.hash.slice(1);
channel = hash.slice(0, 32); channel = hash.slice(0, 32);
key = hash.slice(32); key = hash.slice(32);
} }*/
var andThen = function (CMeditor) { var andThen = function (CMeditor) {
var $pad = $('#pad-iframe'); var $pad = $('#pad-iframe');
@ -90,9 +93,9 @@ define([
//initialState: Messages.codeInitialState, //initialState: Messages.codeInitialState,
userName: userName, userName: userName,
websocketURL: Config.websocketURL, websocketURL: Config.websocketURL,
channel: channel, channel: secret.channel,
cryptKey: key, //cryptKey: key,
crypto: Crypto, crypto: Crypto.createEncryptor(secret.key),
setMyID: setMyID, setMyID: setMyID,
transformFunction: JsonOT.validate transformFunction: JsonOT.validate
}; };
@ -152,7 +155,7 @@ define([
createChangeName('cryptpad-changeName', $bar); createChangeName('cryptpad-changeName', $bar);
$bar.find('#cryptpad-saveContent').click(exportText); $bar.find('#cryptpad-saveContent').click(exportText);
window.location.hash = info.channel + key; window.location.hash = info.channel + secret.key;
}; };
var updateUserList = function(shjson) { var updateUserList = function(shjson) {

@ -7,21 +7,13 @@ define([
'json.sortify', 'json.sortify',
'/form/ula.js', '/form/ula.js',
'/bower_components/chainpad-json-validator/json-ot.js', '/bower_components/chainpad-json-validator/json-ot.js',
'/common/cryptpad-common.js',
'/bower_components/jquery/dist/jquery.min.js', '/bower_components/jquery/dist/jquery.min.js',
'/customize/pad.js' '/customize/pad.js'
], function (Config, Realtime, Crypto, TextPatcher, Sortify, Formula, JsonOT) { ], function (Config, Realtime, Crypto, TextPatcher, Sortify, Formula, JsonOT, Cryptpad) {
var $ = window.jQuery; var $ = window.jQuery;
var key; var secret = Cryptpad.getSecrets();
var channel = '';
var hash = false;
if (!/#/.test(window.location.href)) {
key = Crypto.genKey();
} else {
hash = window.location.hash.slice(1);
channel = hash.slice(0,32);
key = hash.slice(32);
}
var module = window.APP = { var module = window.APP = {
TextPatcher: TextPatcher, TextPatcher: TextPatcher,
@ -125,9 +117,8 @@ define([
initialState: Sortify(Map) || '{}', initialState: Sortify(Map) || '{}',
websocketURL: Config.websocketURL, websocketURL: Config.websocketURL,
userName: Crypto.rand64(8), userName: Crypto.rand64(8),
channel: channel, channel: secret.channel,
cryptKey: key, crypto: Crypto.createEncryptor(secret.key),
crypto: Crypto,
transformFunction: JsonOT.validate transformFunction: JsonOT.validate
}; };
@ -142,7 +133,7 @@ define([
var onInit = config.onInit = function (info) { var onInit = config.onInit = function (info) {
var realtime = module.realtime = info.realtime; var realtime = module.realtime = info.realtime;
window.location.hash = info.channel + key; window.location.hash = info.channel + secret.key;
// create your patcher // create your patcher
module.patchText = TextPatcher.create({ module.patchText = TextPatcher.create({

@ -3,44 +3,23 @@ define([
'/bower_components/chainpad-netflux/chainpad-netflux.js', '/bower_components/chainpad-netflux/chainpad-netflux.js',
'/bower_components/chainpad-crypto/crypto.js', '/bower_components/chainpad-crypto/crypto.js',
'/bower_components/textpatcher/TextPatcher.amd.js', '/bower_components/textpatcher/TextPatcher.amd.js',
'/common/cryptpad-common.js',
'/bower_components/jquery/dist/jquery.min.js' '/bower_components/jquery/dist/jquery.min.js'
], function (Config, Realtime, Crypto, TextPatcher) { ], function (Config, Realtime, Crypto, TextPatcher, Cryptpad) {
var $ = window.jQuery; var $ = window.jQuery;
var key; var secret = Cryptpad.getSecrets();
var channel = '';
if (window.location.href.indexOf('#') === -1) {
key = Crypto.genKey();
//window.location.href = window.location.href + '#' + Crypto.genKey();
//return;
} else {
var hash = window.location.hash.substr(1);
channel = hash.substr(0,32);
key = hash.substr(32);
}
var $textarea = $('textarea'), var $textarea = $('textarea'),
$run = $('#run'); $run = $('#run');
var module = {}; var module = {};
/*
onRemote
onInit
onReady
onAbort
transformFunction
*/
var userName = Crypto.rand64(8);
var config = { var config = {
initialState: '', initialState: '',
websocketURL: Config.websocketURL, websocketURL: Config.websocketURL,
userName: userName, channel: secret.channel,
channel: channel, crypto: Crypto.createEncryptor(secret.key),
cryptKey: key,
crypto: Crypto,
}; };
var initializing = true; var initializing = true;
@ -50,7 +29,7 @@ define([
setEditable(false); setEditable(false);
var onInit = config.onInit = function (info) { var onInit = config.onInit = function (info) {
window.location.hash = info.channel + key; window.location.hash = info.channel + secret.key;
$(window).on('hashchange', function() { window.location.reload(); }); $(window).on('hashchange', function() { window.location.reload(); });
}; };

@ -13,9 +13,9 @@ define([
var config = { var config = {
websocketURL: Config.websocketURL, websocketURL: Config.websocketURL,
channel: secret.channel, channel: secret.channel,
cryptKey: secret.key, //cryptKey: secret.key,
data: {}, data: {},
crypto: Crypto crypto: Crypto.createEncryptor(secret.key)
}; };
var module = window.APP = {}; var module = window.APP = {};

@ -209,8 +209,6 @@ define([
var applyHjson = function (shjson) { var applyHjson = function (shjson) {
var userDocStateDom = hjsonToDom(JSON.parse(shjson)); var userDocStateDom = hjsonToDom(JSON.parse(shjson));
// we *might* be able to remove this now
// changes to hyperscript fixed this bug *maybe* --ansuz
userDocStateDom.setAttribute("contenteditable", "true"); // lol wtf userDocStateDom.setAttribute("contenteditable", "true"); // lol wtf
var patch = (DD).diff(inner, userDocStateDom); var patch = (DD).diff(inner, userDocStateDom);
(DD).apply(inner, patch); (DD).apply(inner, patch);
@ -238,14 +236,24 @@ define([
// method which allows us to get the id of the user // method which allows us to get the id of the user
setMyID: setMyID, setMyID: setMyID,
// Crypto object to avoid loading it twice in Cryptpad // Pass in encrypt and decrypt methods
crypto: Crypto, crypto: Crypto.createEncryptor(secret.key),
// really basic operational transform // really basic operational transform
transformFunction : JsonOT.validate, transformFunction : JsonOT.validate,
// cryptpad debug logging (default is 1) // cryptpad debug logging (default is 1)
// logLevel: 0, // logLevel: 0,
validateContent: function (content) {
try {
JSON.parse(content);
return true;
} catch (e) {
console.log("Failed to parse, rejecting patch");
return false;
}
}
}; };
var updateUserList = function(shjson) { var updateUserList = function(shjson) {

@ -4,28 +4,20 @@ define([
'/bower_components/chainpad-crypto/crypto.js', '/bower_components/chainpad-crypto/crypto.js',
'/bower_components/marked/marked.min.js', '/bower_components/marked/marked.min.js',
'/bower_components/hyperjson/hyperjson.js', '/bower_components/hyperjson/hyperjson.js',
'/common/cryptpad-common.js',
//'/common/convert.js', //'/common/convert.js',
'/bower_components/jquery/dist/jquery.min.js', '/bower_components/jquery/dist/jquery.min.js',
'/bower_components/diff-dom/diffDOM.js', '/bower_components/diff-dom/diffDOM.js',
'/customize/pad.js' '/customize/pad.js'
], function (Config, Realtime, Crypto, Marked, Hyperjson) { ], function (Config, Realtime, Crypto, Marked, Hyperjson, Cryptpad) {
var $ = window.jQuery; var $ = window.jQuery;
var DiffDom = window.diffDOM; var DiffDom = window.diffDOM;
var key; var secret = Cryptpad.getSecrets();
var channel = '';
var hash = false;
if (!/#/.test(window.location.href)) {
key = Crypto.genKey();
} else {
hash = window.location.hash.slice(1);
channel = hash.slice(0, 32);
key = hash.slice(32);
}
// set markdown rendering options :: strip html to prevent XSS // set markdown rendering options :: strip html to prevent XSS
Marked.setOptions({ Marked.setOptions({
//sanitize: true sanitize: true
}); });
var module = window.APP = { }; var module = window.APP = { };
@ -34,9 +26,9 @@ define([
var config = { var config = {
websocketURL: Config.websocketURL, websocketURL: Config.websocketURL,
channel: channel, channel: secret.channel,
cryptKey: key, //cryptKey: secret.key,
crypto: Crypto crypto: Crypto.createEncryptor(secret.key)
}; };
var draw = window.draw = (function () { var draw = window.draw = (function () {
@ -70,7 +62,7 @@ define([
var initializing = true; var initializing = true;
var onInit = config.onInit = function (info) { var onInit = config.onInit = function (info) {
window.location.hash = info.channel + key; window.location.hash = info.channel + secret.key;
module.realtime = info.realtime; module.realtime = info.realtime;
}; };

@ -3,9 +3,10 @@ define([
'/bower_components/chainpad-netflux/chainpad-netflux.js', '/bower_components/chainpad-netflux/chainpad-netflux.js',
'/bower_components/chainpad-crypto/crypto.js', '/bower_components/chainpad-crypto/crypto.js',
'/bower_components/textpatcher/TextPatcher.amd.js', '/bower_components/textpatcher/TextPatcher.amd.js',
'/common/cryptpad-common.js',
'/bower_components/jquery/dist/jquery.min.js', '/bower_components/jquery/dist/jquery.min.js',
'/customize/pad.js' '/customize/pad.js'
], function (Config, Realtime, Crypto, TextPatcher) { ], function (Config, Realtime, Crypto, TextPatcher, Cryptpad) {
// TODO consider adding support for less.js // TODO consider adding support for less.js
var $ = window.jQuery; var $ = window.jQuery;
@ -14,21 +15,11 @@ define([
var module = window.APP = {}; var module = window.APP = {};
var key; var secret = Cryptpad.getSecrets();
var channel = '';
if (!/#/.test(window.location.href)) {
key = Crypto.genKey();
} else {
var hash = window.location.hash.slice(1);
channel = hash.slice(0, 32);
key = hash.slice(32);
}
var config = { var config = {
websocketURL: Config.websocketURL, websocketURL: Config.websocketURL,
channel: channel, channel: secret.channel,
cryptKey: key, crypto: Crypto.createEncryptor(secret.key),
crypto: Crypto,
}; };
var userName = module.userName = config.userName = Crypto.rand64(8); var userName = module.userName = config.userName = Crypto.rand64(8);
@ -49,7 +40,7 @@ define([
var initializing = true; var initializing = true;
var onInit = config.onInit = function (info) { var onInit = config.onInit = function (info) {
window.location.hash = info.channel + key; window.location.hash = info.channel + secret.key;
var realtime = module.realtime = info.realtime; var realtime = module.realtime = info.realtime;
module.patchText = TextPatcher.create({ module.patchText = TextPatcher.create({
realtime: realtime, realtime: realtime,

@ -3,20 +3,13 @@ define([
'/bower_components/chainpad-netflux/chainpad-netflux.js', '/bower_components/chainpad-netflux/chainpad-netflux.js',
'/bower_components/chainpad-crypto/crypto.js', '/bower_components/chainpad-crypto/crypto.js',
'/bower_components/textpatcher/TextPatcher.amd.js', '/bower_components/textpatcher/TextPatcher.amd.js',
'/common/cryptpad-common.js',
'/bower_components/jquery/dist/jquery.min.js', '/bower_components/jquery/dist/jquery.min.js',
'/customize/pad.js' '/customize/pad.js'
], function (Config, Realtime, Crypto, TextPatcher) { ], function (Config, Realtime, Crypto, TextPatcher, Cryptpad) {
var $ = window.jQuery; var $ = window.jQuery;
var key; var secret = Cryptpad.getSecrets();
var channel = '';
if (window.location.href.indexOf('#') === -1) {
key = Crypto.genKey();
} else {
var hash = window.location.hash.substr(1);
channel = hash.substr(0, 32);
key = hash.substr(32);
}
var module = window.APP = { var module = window.APP = {
TextPatcher: TextPatcher TextPatcher: TextPatcher
@ -29,12 +22,9 @@ define([
var config = module.config = { var config = module.config = {
initialState: '', initialState: '',
textarea: $textarea[0],
websocketURL: Config.websocketURL, websocketURL: Config.websocketURL,
userName: userName, channel: secret.channel,
channel: channel, crypto: Crypto.createEncryptor(secret.key),
cryptKey: key,
crypto: Crypto,
}; };
var setEditable = function (bool) { $textarea.attr('disabled', !bool); }; var setEditable = function (bool) { $textarea.attr('disabled', !bool); };
@ -43,7 +33,7 @@ define([
setEditable(false); setEditable(false);
var onInit = config.onInit = function (info) { var onInit = config.onInit = function (info) {
window.location.hash = info.channel + key; window.location.hash = info.channel + secret.key;
$(window).on('hashchange', function() { $(window).on('hashchange', function() {
window.location.reload(); window.location.reload();
}); });

Loading…
Cancel
Save