Add support for ownerKey in the hash (version 1 and 2)

pull/1/head
yflory 5 years ago
parent 8ccafbc821
commit d4d07f3332

@ -254,6 +254,32 @@ define([
!secret.hashData.present); !secret.hashData.present);
}, "test support for trailing slashes in version 1 hash failed to parse"); }, "test support for trailing slashes in version 1 hash failed to parse");
// test support for ownerKey
assert(function (cb) {
var secret = Hash.parsePadUrl('/pad/#/1/edit/3Ujt4F2Sjnjbis6CoYWpoQ/usn4+9CqVja8Q7RZOGTfRgqI/present/uPmJDtDJ9okhdIyQ-8zphYlpaAonJDOC6MAcYY6iBwWBQr+XmrQ9uGY9WkApJTfEfAu5QcqaDCw1Ul+JXKcYkA/embed');
return cb(secret.hashData.version === 1 &&
secret.hashData.mode === "edit" &&
secret.hashData.channel === "3Ujt4F2Sjnjbis6CoYWpoQ" &&
secret.hashData.key === "usn4+9CqVja8Q7RZOGTfRgqI" &&
secret.hashData.ownerKey === "uPmJDtDJ9okhdIyQ-8zphYlpaAonJDOC6MAcYY6iBwWBQr+XmrQ9uGY9WkApJTfEfAu5QcqaDCw1Ul+JXKcYkA" &&
secret.hashData.embed &&
secret.hashData.present);
}, "test support for owner key in version 1 hash failed to parse");
assert(function (cb) {
var parsed = Hash.parsePadUrl('/pad/#/2/pad/edit/oRE0oLCtEXusRDyin7GyLGcS/p/uPmJDtDJ9okhdIyQ-8zphYlpaAonJDOC6MAcYY6iBwWBQr+XmrQ9uGY9WkApJTfEfAu5QcqaDCw1Ul+JXKcYkA/embed');
var secret = Hash.getSecrets('pad', parsed.hash);
return cb(parsed.hashData.version === 2 &&
parsed.hashData.mode === "edit" &&
parsed.hashData.type === "pad" &&
parsed.hashData.key === "oRE0oLCtEXusRDyin7GyLGcS" &&
secret.channel === "d8d51b4aea863f3f050f47f8ad261753" &&
window.nacl.util.encodeBase64(secret.keys.cryptKey) === "0Ts1M6VVEozErV2Nx/LTv6Im5SCD7io2LlhasyyBPQo=" &&
secret.keys.validateKey === "f5A1FM9Gp55tnOcM75RyHD1oxBG9ZPh9WDA7qe2Fvps=" &&
parsed.hashData.ownerKey === "uPmJDtDJ9okhdIyQ-8zphYlpaAonJDOC6MAcYY6iBwWBQr+XmrQ9uGY9WkApJTfEfAu5QcqaDCw1Ul+JXKcYkA" &&
parsed.hashData.embed &&
parsed.hashData.password);
}, "test support for owner key in version 2 hash failed to parse");
assert(function (cb) { assert(function (cb) {
var secret = Hash.parsePadUrl('/invite/#/2/invite/edit/oRE0oLCtEXusRDyin7GyLGcS/p/'); var secret = Hash.parsePadUrl('/invite/#/2/invite/edit/oRE0oLCtEXusRDyin7GyLGcS/p/');
var hd = secret.hashData; var hd = secret.hashData;

@ -158,9 +158,17 @@ Version 1
options = hashArr.slice(5); options = hashArr.slice(5);
parsed.present = options.indexOf('present') !== -1; parsed.present = options.indexOf('present') !== -1;
parsed.embed = options.indexOf('embed') !== -1; parsed.embed = options.indexOf('embed') !== -1;
// Check if we have an ownerKey for this pad
hashArr.some(function (data) {
if (data.length === 86) { // XXX 88 characters - 2 trailing "="...
parsed.ownerKey = data;
return true;
}
});
parsed.getHash = function (opts) { parsed.getHash = function (opts) {
var hash = hashArr.slice(0, 5).join('/') + '/'; var hash = hashArr.slice(0, 5).join('/') + '/';
if (parsed.ownerKey) { hash += parsed.ownerKey + '/'; }
if (opts.embed) { hash += 'embed/'; } if (opts.embed) { hash += 'embed/'; }
if (opts.present) { hash += 'present/'; } if (opts.present) { hash += 'present/'; }
return hash; return hash;
@ -177,9 +185,17 @@ Version 1
parsed.password = options.indexOf('p') !== -1; parsed.password = options.indexOf('p') !== -1;
parsed.present = options.indexOf('present') !== -1; parsed.present = options.indexOf('present') !== -1;
parsed.embed = options.indexOf('embed') !== -1; parsed.embed = options.indexOf('embed') !== -1;
// Check if we have a ownerKey for this pad
hashArr.some(function (data) {
if (data.length === 86) { // XXX 88 characters - 2 trailing "="...
parsed.ownerKey = data;
return true;
}
});
parsed.getHash = function (opts) { parsed.getHash = function (opts) {
var hash = hashArr.slice(0, 5).join('/') + '/'; var hash = hashArr.slice(0, 5).join('/') + '/';
if (parsed.ownerKey) { hash += parsed.ownerKey + '/'; }
if (parsed.password) { hash += 'p/'; } if (parsed.password) { hash += 'p/'; }
if (opts.embed) { hash += 'embed/'; } if (opts.embed) { hash += 'embed/'; }
if (opts.present) { hash += 'present/'; } if (opts.present) { hash += 'present/'; }

Loading…
Cancel
Save