Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
didDocumentSignaturePath
) => {
const didDocument = fs.readFileSync(didDocumentPath);
const didDocumentJson = JSON.parse(didDocument);
const didDocumentSignature = fs
.readFileSync(didDocumentSignaturePath)
.toString();
const signedArmor = didDocumentSignature;
const pubkey = didDocumentJson.publicKey[0].publicKeyPem;
options = {
message: openpgp.message.fromBinary(didDocument), // CleartextMessage or Message object
signature: await openpgp.signature.readArmored(signedArmor), // parse detached signature
publicKeys: (await openpgp.key.readArmored(pubkey)).keys // for verification
};
const verified = await openpgp.verify(options);
validity = verified.signatures[0].valid; // true
// console.log(verified.signatures[0])
if (validity) {
// console.log("signed by key id " + verified.signatures[0].keyid.toHex());
const didParts = didDocumentJson.id.split(":");
const fingerprint = didParts[didParts.length - 1];
const signatureMathesFingerprint =
fingerprint.substring(24).toLowerCase() ===
verified.signatures[0].keyid.toHex();
// console.log(signatureMathesFingerprint);
return signatureMathesFingerprint;
}
export const verifyPGP = async (fileName : string, pubKey : string, detachedSig : string) => {
const readableStream = fs.createReadStream(fileName)
const options = {
message: await openpgp.message.fromBinary(readableStream), // CleartextMessage or Message object
signature: await openpgp.signature.readArmored(detachedSig), // parse detached signature
publicKeys: (await openpgp.key.readArmored(pubKey)).keys // for verification
};
let verified = await verify(options) as any
await openpgp.stream.readToEnd(verified.data);
let validity = await verified.signatures[0].verified;
return validity
}
const attemptVerify = async (rawPublicKeys: string) => {
try {
const publicKeys = openpgp.key.readArmored(rawPublicKeys).keys;
const verifyOptions = {
message: openpgp.message.fromText(deterministicString),
signature: openpgp.signature.readArmored(signature),
publicKeys: publicKeys
};
const verifiedMessage = await openpgp.verify(verifyOptions);
return verifiedMessage.signatures.length >= 1;
} catch (e) {
return false;
}
}
const attemptVerify = async (rawPublicKeys: string) => {
try {
const publicKeys = (await openpgp.key.readArmored(rawPublicKeys)).keys;
const verifyOptions = {
message: openpgp.message.fromText(deterministicString),
signature: await openpgp.signature.readArmored(signature),
publicKeys: publicKeys
};
const verifiedMessage = await openpgp.verify(verifyOptions);
return verifiedMessage.signatures.length >= 1;
} catch (e) {
return false;
}
};
const attemptVerify = (rawPublicKeys) => __awaiter(this, void 0, void 0, function* () {
try {
const publicKeys = openpgp.key.readArmored(rawPublicKeys).keys;
const verifyOptions = {
message: openpgp.message.fromText(deterministicSignature),
signature: openpgp.signature.readArmored(signature),
publicKeys: publicKeys
};
const verifiedMessage = yield openpgp.verify(verifyOptions);
return verifiedMessage.signatures.length >= 1;
}
catch (e) {
return false;
}
});
let rawPublicKeys = yield this.trustStore.getOrFetchCachedPublicKeys('keybase.io.' + identity.keybaseUser, fetchPub);
const attemptVerify = async (rawPublicKeys: string) => {
try {
const publicKeys = openpgp.key.readArmored(rawPublicKeys).keys;
const verifyOptions = {
message: openpgp.message.fromText(deterministicString),
signature: openpgp.signature.readArmored(signature),
publicKeys: publicKeys
};
const verifiedMessage = await openpgp.verify(verifyOptions);
return verifiedMessage.signatures.length >= 1;
} catch (e) {
return false;
}
}
const attemptVerify = (rawPublicKeys) => __awaiter(this, void 0, void 0, function* () {
try {
const publicKeys = openpgp.key.readArmored(rawPublicKeys).keys;
const verifyOptions = {
message: openpgp.message.fromText(deterministicSignature),
signature: openpgp.signature.readArmored(signature),
publicKeys: publicKeys
};
const verifiedMessage = yield openpgp.verify(verifyOptions);
return verifiedMessage.signatures.length >= 1;
}
catch (e) {
return false;
}
});
let urlHashObj = crypto.createHash('sha512');
function processPage(rawContent, signature, url, tabId) {
const content = new Minimize({ spare:true, conditionals: true, empty: true, quotes: true }).parse(rawContent)
.replace(/^\s*]*>/i, '');
const shouldCheck = getPubkey(patterns, url);
if (shouldCheck) {
try {
const pubkey = patterns[shouldCheck];
const options = {
message: openpgp.message.fromBinary(openpgp.util.str2Uint8Array(content)),
signature: openpgp.signature.readArmored(signature),
publicKeys: openpgp.key.readArmored(pubkey).keys,
};
openpgp.verify(options).then((verified) => {
const signatureData = (verified.signatures[0].valid) ? goodSignature : badSignature;
updateBrowserAction(signatureData, tabId);
statusCache[url] = signatureData;
});
} catch (e) {
updateBrowserAction(badSignature, tabId);
statusCache[url] = badSignature;
}
} else {
updateBrowserAction(neutralSignature, tabId);
}
}