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

OSSL Memory leak mitigation #675

Merged
merged 1 commit into from
Jan 4, 2019
Merged
Changes from all commits
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
16 changes: 12 additions & 4 deletions sea/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
var parse = require('./parse');
var u;


var knownKeys = {};
var keyForPair = pair => {
if (knownKeys[pair]) return knownKeys[pair];
const jwk = S.jwk(pair);
knownKeys[pair] = (shim.ossl || shim.subtle).importKey("jwk", jwk, S.ecdsa.pair, false, ["verify"]);
return knownKeys[pair];
};

SEA.verify = SEA.verify || (async (data, pair, cb, opt) => { try {
const json = parse(data)
if(false === pair){ // don't verify!
Expand All @@ -18,9 +27,8 @@
opt = opt || {};
// SEA.I // verify is free! Requires no user permission.
if(json === data){ throw "No signature on data." }
const pub = pair.pub || pair
const jwk = S.jwk(pub)
const key = await (shim.ossl || shim.subtle).importKey('jwk', jwk, S.ecdsa.pair, false, ['verify'])
const pub = pair.pub || pair;
const key = await keyForPair(pub);
const hash = await sha256hash(json.m)
var buf; var sig; var check; try{
buf = shim.Buffer.from(json.s, opt.encode || 'base64') // NEW DEFAULT!
Expand All @@ -46,4 +54,4 @@
}});

module.exports = SEA.verify;