@@ -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();