Index: build/chrome/build-deps ================================================================== --- build/chrome/build-deps +++ build/chrome/build-deps @@ -236,11 +236,11 @@ #define PCSC_NACL_H 1 #ifdef __cplusplus #include #include -void pcscNaClInit(pp::Instance *instance, pp::Core *core); +void pcscNaClInit(pp::Instance *instance, pp::Core *core, const char *smartcardManagerAppId, const char *clientId); bool pcscNaClHandleMessage(const pp::Var &message); #endif #endif _EOF_ @@ -310,19 +310,27 @@ #include "dom_requests_manager.h" #include "pcsc_nacl.h" static DomRequestsManager *pcscNaClDRM = NULL; -void pcscNaClInit(pp::Instance *instance, pp::Core *core) { +void pcscNaClInit(pp::Instance *instance, pp::Core *core, const char *smartcardManagerAppId, const char *clientId) { DomRequestsManager::PpDelegateImpl *drmDelegateImpl; PcscNacl *pcsc_nacl; + + if (smartcardManagerAppId == NULL) { + smartcardManagerAppId = "khpfeaanjngmcnplbdlpegiifgpfgdco"; + } + + if (clientId == NULL) { + clientId = "UNKNOWN"; + } drmDelegateImpl = new DomRequestsManager::PpDelegateImpl(instance, core); pcscNaClDRM = new DomRequestsManager("pcsc-nacl", drmDelegateImpl); - pcsc_nacl = new PcscNacl(pcscNaClDRM, "khpfeaanjngmcnplbdlpegiifgpfgdco", "CACKey"); + pcsc_nacl = new PcscNacl(pcscNaClDRM, smartcardManagerAppId, clientId); if (!pcsc_nacl->Initialize()) { return; } Index: build/chrome/cackey-chrome-init.cc ================================================================== --- build/chrome/cackey-chrome-init.cc +++ build/chrome/cackey-chrome-init.cc @@ -17,24 +17,23 @@ #include "pcsc-nacl.h" #include "cackey-chrome.h" class CACKeyInstance : public pp::Instance { private: - void pcscNaClInitWrapper(pp::Core *core) { - pcscNaClInit(this, core); - } + pp::Core *corePointer; public: explicit CACKeyInstance(PP_Instance instance, pp::Core *core) : pp::Instance(instance) { - std::thread(&CACKeyInstance::pcscNaClInitWrapper, this, core).detach(); + corePointer = core; } virtual ~CACKeyInstance() {} virtual void HandleMessageThread(pp::VarDictionary *message) { cackey_chrome_returnType signRet; char *pinPrompt; const char *pin; + const char *smartcardManagerAppId = NULL; unsigned char buffer[8192]; struct cackey_certificate *certificates, incomingCertificateCACKey; pp::VarDictionary *reply; pp::VarArray certificatesPPArray; pp::VarArrayBuffer *certificateContents, *incomingCertificateContents, *incomingData, *outgoingData; @@ -51,11 +50,19 @@ /* * Do the thing we are being asked to do */ reply = new pp::VarDictionary(); - if (command.AsString() == "listcertificates") { + if (command.AsString() == "init") { + if (message->HasKey("smartcardManagerAppId")) { + smartcardManagerAppId = message->Get("smartcardManagerAppId").AsString().c_str(); + } + + pcscNaClInit(this, corePointer, smartcardManagerAppId, "CACKey"); + + reply->Set("status", "success"); + } else if (command.AsString() == "listcertificates") { numCertificates = cackey_chrome_listCertificates(&certificates); certificatesPPArray.SetLength(numCertificates); for (i = 0; i < numCertificates; i++) { Index: build/chrome/cackey.js ================================================================== --- build/chrome/cackey.js +++ build/chrome/cackey.js @@ -88,10 +88,14 @@ } console.log("START MESSAGE"); console.log(messageEvent.data); console.log("END MESSAGE"); + + if (messageEvent.data.id == null) { + return; + } chromeCallback = cackeyOutstandingCallbacks[messageEvent.data.id]; if (chromeCallback == null) { console.log("[cackey] Discarding outdated message"); @@ -293,10 +297,26 @@ /* Register listeners with Chrome */ if (chrome.certificateProvider) { chrome.certificateProvider.onCertificatesRequested.addListener(cackeyListCertificates); chrome.certificateProvider.onSignDigestRequested.addListener(cackeySignMessage); } + + /* + * Initialize CACKey with the correct handle to talk to the Google Smartcard Manager App + */ + cackeyHandle.postMessage( + { + "target": "cackey", + "command": "init" + } + ); + + /* + * Start the Google PCSC Interface + */ + new GoogleSmartCard.PcscNacl(cackeyHandle); + return; } /* @@ -335,17 +355,12 @@ elementEmbed.addEventListener('load', cackeyInitLoaded, true); elementEmbed.addEventListener('message', cackeyMessageIncoming, true); cackeyHandle = elementEmbed; - /* - * Start the Google PCSC Interface - */ - new GoogleSmartCard.PcscNacl(cackeyHandle); - document.body.appendChild(cackeyHandle) console.log("[cackey] cackeyInit(): Completed. Returning."); } /* Initialize CACKey */ cackeyInit();