Diff

Differences From Artifact [3c60365638]:

To Artifact [d291048f9c]:


    77     77   		return;
    78     78   	}
    79     79   
    80     80   	for (idx = 0; idx < message.certificates.length; idx++) {
    81     81   		certificates.push(
    82     82   			{
    83     83   				certificate: message.certificates[idx],
    84         -				supportedHashes: ['SHA1', 'SHA256', 'MD5_SHA1']
           84  +				supportedHashes: ['SHA1', 'SHA256', 'SHA512', 'MD5_SHA1']
    85     85   			}
    86     86   		);
    87     87   	}
    88     88   
    89     89   	chromeCallback(certificates,
    90     90   		function(rejectedCerts) {
    91     91   			if (chrome.runtime.lastError) {
................................................................................
   483    483    * Handler for messages from Chrome related to signing a hash of some sort
   484    484    */
   485    485   function cackeySignMessage(signRequest, chromeCallback) {
   486    486   	var callbackId;
   487    487   	var command;
   488    488   	var certificateId;
   489    489   	var digest, digestHeader;
          490  +	var promiseHandle = null, promiseResolve, promiseReject;
          491  +
          492  +	if (!chromeCallback) {
          493  +		/*
          494  +		 * If no callback supplied, arrange for a promise to be returned instead
          495  +		 */
          496  +		promiseHandle = new Promise(function(resolve, reject) {
          497  +			promiseResolve = resolve;
          498  +			promiseReject = reject;
          499  +		});
          500  +
          501  +		chromeCallback = function(payload) {
          502  +			if (!payload) {
          503  +				promiseReject(new Error("Signing payload is empty or not supplied"));
          504  +			} else {
          505  +				promiseResolve(payload);
          506  +			}
          507  +		};
          508  +	}
   490    509   
   491    510   	/*
   492    511   	 * Prefix the digest with the ASN.1 header required of it
   493    512   	 */
   494    513   	switch (signRequest.hash) {
   495    514   		case "SHA1":
   496    515   			digestHeader = new Uint8Array([0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14]);
   497    516   			break;
   498    517   		case "SHA256":
   499    518   			digestHeader = new Uint8Array([0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20]);
   500    519   			break;
          520  +		case "SHA512":
          521  +			digestHeader = new Uint8Array([0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x05, 0x00, 0x04, 0x40]);
          522  +			break;
   501    523   		case "MD5_SHA1":
          524  +		case "RAW":
   502    525   			digestHeader = new Uint8Array();
   503    526   			break;
   504    527   		default:
   505    528   			console.error("[cackey] Asked to sign a message with a hash we do not support: " + signRequest.hash);
   506    529   
   507    530   			chromeCallback();
   508    531   
   509         -			return;
          532  +			return(promiseHandle);
   510    533   	}
   511    534   
   512    535   	digest = new Uint8Array(digestHeader.length + signRequest.digest.byteLength);
   513    536   	digest.set(digestHeader, 0);
   514    537   	digest.set(new Uint8Array(signRequest.digest), digestHeader.length);
   515    538   
   516    539   	delete digestHeader;
................................................................................
   543    566   		cackeyOutstandingCallbacks[callbackId] = chromeCallback;
   544    567   
   545    568   		if (goog.DEBUG) {
   546    569   			console.log("[cackey] Thrown.");
   547    570   		}
   548    571   	}, chromeCallback);
   549    572   
   550         -	return;
          573  +	return(promiseHandle);
   551    574   }
   552    575   
   553    576   /*
   554    577    * Unititalizes the CACKey PCSC connection
   555    578    */
   556    579   function cackeyUninitPCSC() {
   557    580   	console.log("[cackey] cackeyUninitPCSC() called");