Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes the format of the signature to allow for later extensions. #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,31 +158,36 @@ function validateSignature(content, signature, pageOptions, pubkey) {
});
}

// Returns when first promise returns true
function promise_any(promises) {
return new Promise((resolve,reject) => {
Promise.all(promises.map(promise => promise.then(value => {
if (value)
resolve(value);
return value;
}).catch( error => {
reject(error);
}))).then(values => {
if (values.every(x => x == false))
resolve(false)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, this resolves promises with false. So it is only supported for promises that return boolean values…

})
})
}

function validateSignatures(content, options, pubKey, method) {
let last = Promise.resolve(false);
for (let signature of options.signatures) {
let promise = null;
return promise_any(options.signatures.map(signature => {
if (signature.allowedmethods.includes(method.toLowerCase())) {
if (signature.type == 'pgp') {
promise = validateSignature(content, signature.signature, options, pubKey);
return validateSignature(content, signature.signature, options, pubKey);
} else if (signature.type == 'pgpMinimized') {
if (matchVersions(signature.version, '1.0.0')) {
const signedContent = minimize_1_0(content);
promise = validateSignature(signedContent, signature.signature, options, pubKey);
return validateSignature(signedContent, signature.signature, options, pubKey);
}
}
}
// Chain promises returning when the first one is true
if (promise) {
last = last.then(verified => {
if (verified)
return verified;
else
return promise;
})
}
}
return last;
return Promise.resolve(false);
}))
}

function processPage(rawContent, legacySignature, url, tabId, method) {
Expand Down