From d4d07f33326b1a63ee0f648eca2f62a1b5cda498 Mon Sep 17 00:00:00 2001 From: yflory Date: Thu, 9 Jan 2020 11:20:35 +0100 Subject: [PATCH] Add support for ownerKey in the hash (version 1 and 2) --- www/assert/main.js | 26 ++++++++++++++++++++++++++ www/common/common-hash.js | 16 ++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/www/assert/main.js b/www/assert/main.js index cdde441f0..ceff9f58b 100644 --- a/www/assert/main.js +++ b/www/assert/main.js @@ -254,6 +254,32 @@ define([ !secret.hashData.present); }, "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) { var secret = Hash.parsePadUrl('/invite/#/2/invite/edit/oRE0oLCtEXusRDyin7GyLGcS/p/'); var hd = secret.hashData; diff --git a/www/common/common-hash.js b/www/common/common-hash.js index 4ed1193e3..c26a097e4 100644 --- a/www/common/common-hash.js +++ b/www/common/common-hash.js @@ -158,9 +158,17 @@ Version 1 options = hashArr.slice(5); parsed.present = options.indexOf('present') !== -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) { var hash = hashArr.slice(0, 5).join('/') + '/'; + if (parsed.ownerKey) { hash += parsed.ownerKey + '/'; } if (opts.embed) { hash += 'embed/'; } if (opts.present) { hash += 'present/'; } return hash; @@ -177,9 +185,17 @@ Version 1 parsed.password = options.indexOf('p') !== -1; parsed.present = options.indexOf('present') !== -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) { var hash = hashArr.slice(0, 5).join('/') + '/'; + if (parsed.ownerKey) { hash += parsed.ownerKey + '/'; } if (parsed.password) { hash += 'p/'; } if (opts.embed) { hash += 'embed/'; } if (opts.present) { hash += 'present/'; }