Check-in [b276afc558]
Overview
SHA1:b276afc558cd3c8caebca6cadabf5e9fad37c3ea
Date: 2016-02-29 16:50:34
User: rkeene
Comment:ChromeOS: Updated to call a failure callback if PCSC connection fails
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2016-02-29
22:22
[50743e141d] Removed "import", does not work because the required module does not export (user: rkeene, tags: trunk)
16:50
[b276afc558] ChromeOS: Updated to call a failure callback if PCSC connection fails (user: rkeene, tags: trunk)
04:32
[30263e48a3] ChromeOS: Release 5 (user: rkeene, tags: trunk)
Changes

Modified build/chrome/cackey.js from [42af92888f] to [6bb2c4f501].

   144    144   	}
   145    145   
   146    146   	if (messageEvent.data.command == "init" && messageEvent.data.status == "success") {
   147    147   		if (GoogleSmartCard.IS_DEBUG_BUILD) {
   148    148   			console.log("[cackey] Initialization completed, resending any queued messages");
   149    149   		}
   150    150   
   151         -		cackeyInitPCSCCompleted();
          151  +		cackeyInitPCSCCompleted("success");
   152    152   	}
   153    153   
   154    154   	if (messageEvent.data.id == null) {
   155    155   		return;
   156    156   	}
   157    157   
   158    158   	chromeCallback = cackeyOutstandingCallbacks[messageEvent.data.id];
................................................................................
   223    223   
   224    224   				/*
   225    225   				 * Register a handler to handle the window being closed without
   226    226   				 * having sent anything
   227    227   				 */
   228    228   				pinWindow.onClosed.addListener(function() {
   229    229   					var messageIdx;
          230  +					var chromeCallback;
   230    231   
   231    232   					pinWindowPreviousHandle = null;
   232    233   
   233    234   					for (messageIdx = 0; messageIdx < cackeyMessagesToRetry.length; messageIdx++) {
   234    235   						var tmpMessageEvent;
   235    236   
   236    237   						tmpMessageEvent = cackeyMessagesToRetry[messageIdx];
................................................................................
   244    245   							tmpMessageEvent.data.error = "PIN window closed without a PIN being provided";
   245    246   
   246    247   							cackeyMessageIncoming(tmpMessageEvent);
   247    248   						} else {
   248    249   							tmpMessageEvent.data.originalrequest.pin = pinWindowPINValue;
   249    250   
   250    251   							cackeyCertificateToPINMap[cackeyCertificateToPINID(tmpMessageEvent.data.originalrequest.certificate)] = pinWindowPINValue;
          252  +
          253  +							chromeCallback = null;
          254  +							if (tmpMessageEvent.data.id) {
          255  +								if (cackeyOutstandingCallbacks) {
          256  +									chromeCallback = cackeyOutstandingCallbacks[tmpMessageEvent.data.id];
          257  +								}
          258  +							}
   251    259   
   252    260   							cackeyInitPCSC(function() {
   253    261   								cackeyHandle.postMessage(tmpMessageEvent.data.originalrequest);
          262  +							}, function() {
          263  +								if (chromeCallback) {
          264  +									chromeCallback();
          265  +								}
          266  +
          267  +								if (tmpMessageEvent.data.id && cackeyOutstandingCallbacks[tmpMessageEvent.data.id]) {
          268  +									delete cackeyOutstandingCallbacks[tmpMessageEvent.data.id];
          269  +								}
   254    270   							});
   255    271   						}
   256    272   					}
   257    273   
   258    274   
   259    275   					/*
   260    276   					 * Delete the existing handle and create a new one
................................................................................
   332    348   
   333    349   		cackeyOutstandingCallbackCounter = callbackId;
   334    350   		cackeyOutstandingCallbacks[callbackId] = chromeCallback;
   335    351   
   336    352   		if (GoogleSmartCard.IS_DEBUG_BUILD) {
   337    353   			console.log("[cackey] Thrown.");
   338    354   		}
   339         -	});
          355  +	}, chromeCallback);
   340    356   
   341    357   	return;
   342    358   }
   343    359   
   344    360   /*
   345    361    * Handler for messages from Chrome related to signing a hash of some sort
   346    362    */
................................................................................
   402    418   
   403    419   		cackeyOutstandingCallbackCounter = callbackId;
   404    420   		cackeyOutstandingCallbacks[callbackId] = chromeCallback;
   405    421   
   406    422   		if (GoogleSmartCard.IS_DEBUG_BUILD) {
   407    423   			console.log("[cackey] Thrown.");
   408    424   		}
   409         -	});
          425  +	}, chromeCallback);
   410    426   
   411    427   	return;
   412    428   }
   413    429   
   414    430   /*
   415    431    * Unititalizes the CACKey PCSC connection
   416    432    */
................................................................................
   497    513   	 * not working.
   498    514   	 */
   499    515   	setTimeout(cackeyInit, 30000);
   500    516   
   501    517   	return;
   502    518   }
   503    519   
   504         -function cackeyInitPCSCCompleted() {
          520  +function cackeyInitPCSCCompleted(state) {
   505    521   	var idx;
   506    522   
   507         -	cackeyPCSCHandleUsable = true;
          523  +	console.log("[cackey] Connection completed (state = \"" + state + "\"), sending queued events: " + cackeyCallbackAfterInit.length);
          524  +
          525  +	switch (state) {
          526  +		case "success":
          527  +			cackeyPCSCHandleUsable = true;
          528  +
          529  +			break;
          530  +		case "failure":
          531  +			cackeyPCSCHandleUsable = false;
          532  +
          533  +			break;
          534  +	}
   508    535   
   509    536   	for (idx = 0; idx < cackeyCallbackAfterInit.length; idx++) {
   510    537   		if (!cackeyCallbackAfterInit[idx]) {
   511    538   			continue;
   512    539   		}
   513    540   
   514         -		cackeyCallbackAfterInit[idx]();
          541  +		switch (state) {
          542  +			case "success":
          543  +				(cackeyCallbackAfterInit[idx].successCallback)();
          544  +
          545  +				break;
          546  +			case "failure":
          547  +				(cackeyCallbackAfterInit[idx].failureCallback)();
          548  +
          549  +				break;
          550  +		}
   515    551   	}
   516    552   
   517    553   	delete cackeyCallbackAfterInit;
   518    554   
   519    555   	cackeyCallbackAfterInit = [];
          556  +
          557  +	console.log("[cackey] All queued events processed");
   520    558   
   521    559   	return;
   522    560   }
   523    561   
   524    562   /*
   525    563    * Initialize the PCSC connection
   526    564    */
   527         -function cackeyInitPCSC(callbackAfterInit) {
          565  +function cackeyInitPCSC(callbackAfterInit, callbackInitFailed) {
   528    566   	/*
   529    567   	 * Start the Google PCSC Interface
   530    568   	 */
   531    569   
   532    570   	console.log("[cackey] cackeyInitPCSC() called");
   533    571   
   534    572   	/*
   535    573   	 * Queue this callback to be completed when initialization is complete
   536    574   	 */
   537    575   	if (callbackAfterInit) {
   538         -		cackeyCallbackAfterInit.push(callbackAfterInit);
          576  +		cackeyCallbackAfterInit.push({"successCallback": callbackAfterInit, "failureCallback": callbackInitFailed});
   539    577   	}
   540    578   
   541    579   	/*
   542    580   	 * No additional work is required
   543    581   	 */
   544    582   
   545    583   	if (cackeyPCSCHandle) {
   546    584   		console.log("[cackey] PCSC handle is already valid, nothing to do.");
   547    585   
   548    586   		if (cackeyPCSCHandleUsable) {
   549         -			cackeyInitPCSCCompleted();
          587  +			cackeyInitPCSCCompleted("success");
   550    588   		}
   551    589   
   552    590   		return;
   553    591   	}
   554    592   
   555    593   	/*
   556    594   	 * Sanely initialize this
................................................................................
   689    727   
   690    728   	/*
   691    729   	 * Register a handler for dealing with the PCSC port being disconnected
   692    730   	 */
   693    731   	oldOnPortDisconnectedFunction = GoogleSmartCard.Pcsc.prototype.onPortDisconnected_;
   694    732   	GoogleSmartCard.Pcsc.prototype.onPortDisconnected_ = function() {
   695    733   		oldOnPortDisconnectedFunction.apply(this);
          734  +
          735  +		cackeyInitPCSCCompleted("failure");
   696    736   
   697    737   		cackeyRestart();
   698    738   
   699    739   		return;
   700    740   	};
   701    741   
   702    742   	/*

Modified build/chrome/ui.js from [02acf47905] to [213cbbd233].

    42     42   	if (globalCerts == null) {
    43     43   		htmlObject.innerHTML = "<i>Updating...</i>";
    44     44   	} else {
    45     45   		displayCerts(htmlObject, globalCerts);
    46     46   	}
    47     47   
    48     48   	parentWindow.cackeyListCertificates(function(certs) {
           49  +		/*
           50  +		 * If there is an error then we are invoked with no certs
           51  +		 * parameter at all, fake one.
           52  +		 */
           53  +		if (!certs) {
           54  +			certs = [];
           55  +		}
           56  +
    49     57   		globalCerts = certs;
    50     58   
    51     59   		displayCerts(htmlObject, certs);
    52     60   	});
    53     61   
    54     62   	return;
    55     63   }
    56     64   
    57     65   setTimeout(function() {
    58     66   	updateCertificates(document.getElementById('certificates'));
    59     67   }, 1);