Index: build/chrome/cackey.js ================================================================== --- build/chrome/cackey.js +++ build/chrome/cackey.js @@ -79,11 +79,11 @@ for (idx = 0; idx < message.certificates.length; idx++) { certificates.push( { certificate: message.certificates[idx], - supportedHashes: ['SHA1', 'SHA256', 'MD5_SHA1'] + supportedHashes: ['SHA1', 'SHA256', 'SHA512', 'MD5_SHA1'] } ); } chromeCallback(certificates, @@ -485,10 +485,29 @@ function cackeySignMessage(signRequest, chromeCallback) { var callbackId; var command; var certificateId; var digest, digestHeader; + var promiseHandle = null, promiseResolve, promiseReject; + + if (!chromeCallback) { + /* + * If no callback supplied, arrange for a promise to be returned instead + */ + promiseHandle = new Promise(function(resolve, reject) { + promiseResolve = resolve; + promiseReject = reject; + }); + + chromeCallback = function(payload) { + if (!payload) { + promiseReject(new Error("Signing payload is empty or not supplied")); + } else { + promiseResolve(payload); + } + }; + } /* * Prefix the digest with the ASN.1 header required of it */ switch (signRequest.hash) { @@ -496,19 +515,23 @@ digestHeader = new Uint8Array([0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14]); break; case "SHA256": digestHeader = new Uint8Array([0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20]); break; + case "SHA512": + digestHeader = new Uint8Array([0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x05, 0x00, 0x04, 0x40]); + break; case "MD5_SHA1": + case "RAW": digestHeader = new Uint8Array(); break; default: console.error("[cackey] Asked to sign a message with a hash we do not support: " + signRequest.hash); chromeCallback(); - return; + return(promiseHandle); } digest = new Uint8Array(digestHeader.length + signRequest.digest.byteLength); digest.set(digestHeader, 0); digest.set(new Uint8Array(signRequest.digest), digestHeader.length); @@ -545,11 +568,11 @@ if (goog.DEBUG) { console.log("[cackey] Thrown."); } }, chromeCallback); - return; + return(promiseHandle); } /* * Unititalizes the CACKey PCSC connection */