Add a new hash version for the file viewer

This commit is contained in:
yflory 2017-04-25 17:19:13 +02:00
parent 5194677443
commit d985b144cc
5 changed files with 42 additions and 22 deletions

1
.gitignore vendored
View File

@ -12,3 +12,4 @@ www/scratch
data
npm-debug.log
pins/
blob/

View File

@ -82,6 +82,8 @@ var mainPages = config.mainPages || ['index', 'privacy', 'terms', 'about', 'cont
var mainPagePattern = new RegExp('^\/(' + mainPages.join('|') + ').html$');
app.get(mainPagePattern, Express.static(__dirname + '/customize.dist'));
app.use("/blob", Express.static(__dirname + '/blob'));
app.use("/customize", Express.static(__dirname + '/customize'));
app.use("/customize", Express.static(__dirname + '/customize.dist'));
app.use(/^\/[^\/]*$/, Express.static('customize'));

View File

@ -23,13 +23,16 @@ define([
return chanKey + keys;
}
if (!keys.editKeyStr) { return; }
return '/1/edit/' + hexToBase64(chanKey) + '/' + Crypto.b64RemoveSlashes(keys.editKeyStr);
return '/1/edit/' + hexToBase64(chanKey) + '/'+Crypto.b64RemoveSlashes(keys.editKeyStr)+'/';
};
var getViewHashFromKeys = Hash.getViewHashFromKeys = function (chanKey, keys) {
if (typeof keys === 'string') {
return;
}
return '/1/view/' + hexToBase64(chanKey) + '/' + Crypto.b64RemoveSlashes(keys.viewKeyStr);
return '/1/view/' + hexToBase64(chanKey) + '/'+Crypto.b64RemoveSlashes(keys.viewKeyStr)+'/';
};
var getFileHashFromKey = Hash.getFileHashFromKey = function (fileKey, cryptKey, type) {
return '/2/' + hexToBase64(fileKey) + '/' + Crypto.b64RemoveSlashes(cryptKey) + '/' + Crypto.base64RemoveSlashes(type);
};
var parsePadUrl = Hash.parsePadUrl = function (href) {
@ -119,7 +122,9 @@ define([
}
} else if (version === "2") {
// version 2 hashes are to be used for encrypted blobs
// TODO
var fileId = secret.file = hashArray[2].replace(/-/g, '/');
var key = secret.key = hashArray[3].replace(/-/g, '/');
var type = secret.type = hashArray[4].replace(/-/g, '/');
}
}
}
@ -150,7 +155,7 @@ define([
var channelId = Util.hexToBase64(createChannelId());
// 18 byte encryption key
var key = Crypto.b64RemoveSlashes(Crypto.rand64(18));
return '/1/edit/' + [channelId, key].join('/');
return '/1/edit/' + [channelId, key].join('/') + '/';
};
/*
@ -159,8 +164,8 @@ Version 0
Version 1
/code/#/1/edit/3Ujt4F2Sjnjbis6CoYWpoQ/usn4+9CqVja8Q7RZOGTfRgqI
Version 2
/file/<fileId>/#/2/<cryptKey>/<contentType>
/file/<fileId>/#/2/ajExFODrFH4lVBwxxsrOKw/pdf
/file/#/2/<fileId>/<cryptKey>/<contentType>
/file/#/2/K6xWU-LT9BJHCQcDCT-DcQ/ajExFODrFH4lVBwxxsrOKw/image-png
*/
var parseHash = Hash.parseHash = function (hash) {
var parsed = {};
@ -177,7 +182,14 @@ Version 2
parsed.mode = hashArr[2];
parsed.channel = hashArr[3];
parsed.key = hashArr[4];
parsed.present = hashArr[5] && hashArr[5] === 'present';
parsed.present = typeof(hashArr[5]) === "string" && hashArr[5] === 'present';
return parsed;
}
if (hashArr[1] && hashArr[1] === '2') {
parsed.version = 2;
parsed.file = hashArr[2].replace(/-/g, '/');
parsed.key = hashArr[3].replace(/-/g, '/');
parsed.type = hashArr[4].replace(/-/g, '/');
return parsed;
}
return;

View File

@ -514,7 +514,7 @@ define([
if (p.type !== parsed.type) { return pad; }
var shouldUpdate = p.hash === parsed.hash;
var shouldUpdate = p.hash.replace(/\/$/, '') === parsed.hash.replace(/\/$/, '');
// Version 1 : we have up to 4 differents hash for 1 pad, keep the strongest :
// Edit > Edit (present) > View > View (present)

View File

@ -20,25 +20,30 @@ define([
var andThen = function () {
var $bar = $iframe.find('.toolbar-container');
var secret = Cryptpad.getSecrets();
var readOnly = secret.keys && !secret.keys.editKeyStr;
if (!secret.keys) {
secret.keys = secret.key;
}
if (secret.keys) { throw new Error("You need a hash"); } // TODO
var cryptKey = secret.key;
var fileId = secret.file;
var hexFileName = Cryptpad.base64ToHex(fileId);
var type = secret.type;
// Test hash:
// #/2/K6xWU-LT9BJHCQcDCT-DcQ/TBo77200c0e-FdldQFcnQx4Y/image-png
var $mt = $iframe.find('#encryptedFile');
$mt.attr('src', './assets/image.png-encrypted');
$mt.attr('data-crypto-key', 'TBo77200c0e/FdldQFcnQx4Y');
$mt.attr('data-type', 'image/png');
$mt.attr('src', '/blob/' + hexFileName.slice(0,2) + '/' + hexFileName);
$mt.attr('data-crypto-key', cryptKey);
$mt.attr('data-type', type);
require(['/common/media-tag.js'], function (MediaTag) {
MediaTag($mt[0]);
Cryptpad.removeLoadingScreen();
var configTb = {
displayed: ['useradmin', 'newpad'],
ifrw: ifrw,
common: Cryptpad
};
toolbar = Toolbar.create($bar, null, null, null, null, configTb);
var configTb = {
displayed: ['useradmin', 'newpad'],
ifrw: ifrw,
common: Cryptpad
};
Toolbar.create($bar, null, null, null, null, configTb);
});
};