Check-in [16b40cb47e]
Overview
SHA1:16b40cb47e9e13b9fa704089a920df2dce0c0df7
Date: 2016-02-15 06:39:29
User: rkeene
Comment:ChromeOS: Restructured initialization so that the Google PCSC Smartcard Manager App ID can be found at runtime
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2016-02-15
06:43
[c53eda4523] ChromeOS: Fixed race with specifying the Google Smartcard Manager App ID (user: rkeene, tags: trunk)
06:39
[16b40cb47e] ChromeOS: Restructured initialization so that the Google PCSC Smartcard Manager App ID can be found at runtime (user: rkeene, tags: trunk)
06:20
[b97c4963e4] ChromeOS: Pass PIN prompt back to the user (unused for now) (user: rkeene, tags: trunk)
Changes

Modified build/chrome/build-deps from [5999de848a] to [2732a78124].

   234    234   		cat << \_EOF_ > "${instdir}/include/PCSC/pcsc-nacl.h"
   235    235   #ifndef PCSC_NACL_H
   236    236   #define PCSC_NACL_H 1
   237    237   #ifdef __cplusplus
   238    238   #include <ppapi/cpp/core.h>
   239    239   #include <ppapi/cpp/instance.h>
   240    240   
   241         -void pcscNaClInit(pp::Instance *instance, pp::Core *core);
          241  +void pcscNaClInit(pp::Instance *instance, pp::Core *core, const char *smartcardManagerAppId, const char *clientId);
   242    242   bool pcscNaClHandleMessage(const pp::Var &message);
   243    243   
   244    244   #endif
   245    245   #endif
   246    246   _EOF_
   247    247   
   248    248   		# Copy out JavaScript files for later use
................................................................................
   308    308   
   309    309   #include "pcsc_nacl_global.h"
   310    310   #include "dom_requests_manager.h"
   311    311   #include "pcsc_nacl.h"
   312    312   
   313    313   static DomRequestsManager *pcscNaClDRM = NULL;
   314    314   
   315         -void pcscNaClInit(pp::Instance *instance, pp::Core *core) {
          315  +void pcscNaClInit(pp::Instance *instance, pp::Core *core, const char *smartcardManagerAppId, const char *clientId) {
   316    316   	DomRequestsManager::PpDelegateImpl *drmDelegateImpl;
   317    317   	PcscNacl *pcsc_nacl;
          318  +
          319  +	if (smartcardManagerAppId == NULL) {
          320  +		smartcardManagerAppId = "khpfeaanjngmcnplbdlpegiifgpfgdco";
          321  +	}
          322  +
          323  +	if (clientId == NULL) {
          324  +		clientId = "UNKNOWN";
          325  +	}
   318    326   
   319    327   	drmDelegateImpl = new DomRequestsManager::PpDelegateImpl(instance, core);
   320    328   
   321    329   	pcscNaClDRM = new DomRequestsManager("pcsc-nacl", drmDelegateImpl);
   322    330   
   323         -	pcsc_nacl = new PcscNacl(pcscNaClDRM, "khpfeaanjngmcnplbdlpegiifgpfgdco", "CACKey");
          331  +	pcsc_nacl = new PcscNacl(pcscNaClDRM, smartcardManagerAppId, clientId);
   324    332   
   325    333   	if (!pcsc_nacl->Initialize()) {
   326    334   		return;
   327    335   	}
   328    336   
   329    337   	SetPcscNaclGlobalInstance(pcsc_nacl);
   330    338   

Modified build/chrome/cackey-chrome-init.cc from [7e38a33c28] to [7c0a1742a0].

    15     15   #include <ppapi/cpp/var_array_buffer.h>
    16     16   
    17     17   #include "pcsc-nacl.h"
    18     18   #include "cackey-chrome.h"
    19     19   
    20     20   class CACKeyInstance : public pp::Instance {
    21     21   	private:
    22         -		void pcscNaClInitWrapper(pp::Core *core) {
    23         -			pcscNaClInit(this, core);
    24         -		}
           22  +		pp::Core *corePointer;
    25     23   	public:
    26     24   		explicit CACKeyInstance(PP_Instance instance, pp::Core *core) : pp::Instance(instance) {
    27         -			std::thread(&CACKeyInstance::pcscNaClInitWrapper, this, core).detach();
           25  +			corePointer = core;
    28     26   		}
    29     27   
    30     28   		virtual ~CACKeyInstance() {}
    31     29   
    32     30   		virtual void HandleMessageThread(pp::VarDictionary *message) {
    33     31   			cackey_chrome_returnType signRet;
    34     32   			char *pinPrompt;
    35     33   			const char *pin;
           34  +			const char *smartcardManagerAppId = NULL;
    36     35   			unsigned char buffer[8192];
    37     36   			struct cackey_certificate *certificates, incomingCertificateCACKey;
    38     37   			pp::VarDictionary *reply;
    39     38   			pp::VarArray certificatesPPArray;
    40     39   			pp::VarArrayBuffer *certificateContents, *incomingCertificateContents, *incomingData, *outgoingData;
    41     40   			pp::Var command;
    42     41   			const pp::Var *messageAsVar = NULL, *outgoingDataAsVar = NULL;
................................................................................
    49     48   			command = message->Get("command");
    50     49   
    51     50   			/*
    52     51   			 * Do the thing we are being asked to do
    53     52   			 */
    54     53   			reply = new pp::VarDictionary();
    55     54   
    56         -			if (command.AsString() == "listcertificates") {
           55  +			if (command.AsString() == "init") {
           56  +				if (message->HasKey("smartcardManagerAppId")) {
           57  +					smartcardManagerAppId = message->Get("smartcardManagerAppId").AsString().c_str();
           58  +				}
           59  +
           60  +				pcscNaClInit(this, corePointer, smartcardManagerAppId, "CACKey");
           61  +
           62  +				reply->Set("status", "success");
           63  +			} else if (command.AsString() == "listcertificates") {
    57     64   				numCertificates = cackey_chrome_listCertificates(&certificates);
    58     65   
    59     66   				certificatesPPArray.SetLength(numCertificates);
    60     67   
    61     68   				for (i = 0; i < numCertificates; i++) {
    62     69   					certificateContents = new pp::VarArrayBuffer(certificates[i].certificate_len);
    63     70   

Modified build/chrome/cackey.js from [f054a4b4b3] to [95eeb58033].

    86     86   	if (messageEvent.data.target != "cackey") {
    87     87   		return;
    88     88   	}
    89     89   
    90     90   	console.log("START MESSAGE");
    91     91   	console.log(messageEvent.data);
    92     92   	console.log("END MESSAGE");
           93  +
           94  +	if (messageEvent.data.id == null) {
           95  +		return;
           96  +	}
    93     97   
    94     98   	chromeCallback = cackeyOutstandingCallbacks[messageEvent.data.id];
    95     99   
    96    100   	if (chromeCallback == null) {
    97    101   		console.log("[cackey] Discarding outdated message");
    98    102   
    99    103   		return;
................................................................................
   291    295   	console.log("[cackey] Loaded CACKey PNaCl Module");
   292    296   
   293    297   	/* Register listeners with Chrome */
   294    298   	if (chrome.certificateProvider) {
   295    299   		chrome.certificateProvider.onCertificatesRequested.addListener(cackeyListCertificates);
   296    300   		chrome.certificateProvider.onSignDigestRequested.addListener(cackeySignMessage);
   297    301   	}
          302  +
          303  +	/*
          304  +	 * Initialize CACKey with the correct handle to talk to the Google Smartcard Manager App
          305  +	 */
          306  +	cackeyHandle.postMessage(
          307  +		{
          308  +			"target": "cackey",
          309  +			"command": "init"
          310  +		}
          311  +	);
          312  +
          313  +	/*
          314  +	 * Start the Google PCSC Interface
          315  +	 */
          316  +	new GoogleSmartCard.PcscNacl(cackeyHandle);
          317  +
   298    318   
   299    319   	return;
   300    320   }
   301    321   
   302    322   /*
   303    323    * Initialize CACKey and the PCSC library from Google
   304    324    */
................................................................................
   333    353   	elementEmbed.id = "cackeyModule";
   334    354   	elementEmbed.addEventListener('error', function(messageEvent) { console.error("Error loading CACKey PNaCl Module: " + messageEvent.data); }, true);
   335    355   	elementEmbed.addEventListener('load', cackeyInitLoaded, true);
   336    356   	elementEmbed.addEventListener('message', cackeyMessageIncoming, true);
   337    357   
   338    358   	cackeyHandle = elementEmbed;
   339    359   
   340         -	/*
   341         -	 * Start the Google PCSC Interface
   342         -	 */
   343         -	new GoogleSmartCard.PcscNacl(cackeyHandle);
   344         -
   345    360   	document.body.appendChild(cackeyHandle)
   346    361   
   347    362   	console.log("[cackey] cackeyInit(): Completed.  Returning.");
   348    363   }
   349    364   
   350    365   /* Initialize CACKey */
   351    366   cackeyInit();