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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
...
308
309
310
311
312
313
314
315
316
317








318
319
320
321
322
323
324
325
326
327
328
329
330
		cat << \_EOF_ > "${instdir}/include/PCSC/pcsc-nacl.h"
#ifndef PCSC_NACL_H
#define PCSC_NACL_H 1
#ifdef __cplusplus
#include <ppapi/cpp/core.h>
#include <ppapi/cpp/instance.h>

void pcscNaClInit(pp::Instance *instance, pp::Core *core);
bool pcscNaClHandleMessage(const pp::Var &message);

#endif
#endif
_EOF_

		# Copy out JavaScript files for later use
................................................................................

#include "pcsc_nacl_global.h"
#include "dom_requests_manager.h"
#include "pcsc_nacl.h"

static DomRequestsManager *pcscNaClDRM = NULL;

void pcscNaClInit(pp::Instance *instance, pp::Core *core) {
	DomRequestsManager::PpDelegateImpl *drmDelegateImpl;
	PcscNacl *pcsc_nacl;









	drmDelegateImpl = new DomRequestsManager::PpDelegateImpl(instance, core);

	pcscNaClDRM = new DomRequestsManager("pcsc-nacl", drmDelegateImpl);

	pcsc_nacl = new PcscNacl(pcscNaClDRM, "khpfeaanjngmcnplbdlpegiifgpfgdco", "CACKey");

	if (!pcsc_nacl->Initialize()) {
		return;
	}

	SetPcscNaclGlobalInstance(pcsc_nacl);








|







 







|


>
>
>
>
>
>
>
>





|







234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
...
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
		cat << \_EOF_ > "${instdir}/include/PCSC/pcsc-nacl.h"
#ifndef PCSC_NACL_H
#define PCSC_NACL_H 1
#ifdef __cplusplus
#include <ppapi/cpp/core.h>
#include <ppapi/cpp/instance.h>

void pcscNaClInit(pp::Instance *instance, pp::Core *core, const char *smartcardManagerAppId, const char *clientId);
bool pcscNaClHandleMessage(const pp::Var &message);

#endif
#endif
_EOF_

		# Copy out JavaScript files for later use
................................................................................

#include "pcsc_nacl_global.h"
#include "dom_requests_manager.h"
#include "pcsc_nacl.h"

static DomRequestsManager *pcscNaClDRM = NULL;

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, smartcardManagerAppId, clientId);

	if (!pcsc_nacl->Initialize()) {
		return;
	}

	SetPcscNaclGlobalInstance(pcsc_nacl);

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

15
16
17
18
19
20
21
22
23
24
25
26
27

28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
..
49
50
51
52
53
54
55








56
57
58
59
60
61
62
63
#include <ppapi/cpp/var_array_buffer.h>

#include "pcsc-nacl.h"
#include "cackey-chrome.h"

class CACKeyInstance : public pp::Instance {
	private:
		void pcscNaClInitWrapper(pp::Core *core) {
			pcscNaClInit(this, core);
		}
	public:
		explicit CACKeyInstance(PP_Instance instance, pp::Core *core) : pp::Instance(instance) {
			std::thread(&CACKeyInstance::pcscNaClInitWrapper, this, core).detach();

		}

		virtual ~CACKeyInstance() {}

		virtual void HandleMessageThread(pp::VarDictionary *message) {
			cackey_chrome_returnType signRet;
			char *pinPrompt;
			const char *pin;

			unsigned char buffer[8192];
			struct cackey_certificate *certificates, incomingCertificateCACKey;
			pp::VarDictionary *reply;
			pp::VarArray certificatesPPArray;
			pp::VarArrayBuffer *certificateContents, *incomingCertificateContents, *incomingData, *outgoingData;
			pp::Var command;
			const pp::Var *messageAsVar = NULL, *outgoingDataAsVar = NULL;
................................................................................
			command = message->Get("command");

			/*
			 * Do the thing we are being asked to do
			 */
			reply = new pp::VarDictionary();









			if (command.AsString() == "listcertificates") {
				numCertificates = cackey_chrome_listCertificates(&certificates);

				certificatesPPArray.SetLength(numCertificates);

				for (i = 0; i < numCertificates; i++) {
					certificateContents = new pp::VarArrayBuffer(certificates[i].certificate_len);








|
<
<


<
>








>







 







>
>
>
>
>
>
>
>
|







15
16
17
18
19
20
21
22


23
24

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
..
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <ppapi/cpp/var_array_buffer.h>

#include "pcsc-nacl.h"
#include "cackey-chrome.h"

class CACKeyInstance : public pp::Instance {
	private:
		pp::Core *corePointer;


	public:
		explicit CACKeyInstance(PP_Instance instance, pp::Core *core) : pp::Instance(instance) {

			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;
			pp::Var command;
			const pp::Var *messageAsVar = NULL, *outgoingDataAsVar = NULL;
................................................................................
			command = message->Get("command");

			/*
			 * Do the thing we are being asked to do
			 */
			reply = new pp::VarDictionary();

			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++) {
					certificateContents = new pp::VarArrayBuffer(certificates[i].certificate_len);

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

86
87
88
89
90
91
92




93
94
95
96
97
98
99
...
291
292
293
294
295
296
297
















298
299
300
301
302
303
304
...
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
	if (messageEvent.data.target != "cackey") {
		return;
	}

	console.log("START MESSAGE");
	console.log(messageEvent.data);
	console.log("END MESSAGE");





	chromeCallback = cackeyOutstandingCallbacks[messageEvent.data.id];

	if (chromeCallback == null) {
		console.log("[cackey] Discarding outdated message");

		return;
................................................................................
	console.log("[cackey] Loaded CACKey PNaCl Module");

	/* Register listeners with Chrome */
	if (chrome.certificateProvider) {
		chrome.certificateProvider.onCertificatesRequested.addListener(cackeyListCertificates);
		chrome.certificateProvider.onSignDigestRequested.addListener(cackeySignMessage);
	}

















	return;
}

/*
 * Initialize CACKey and the PCSC library from Google
 */
................................................................................
	elementEmbed.id = "cackeyModule";
	elementEmbed.addEventListener('error', function(messageEvent) { console.error("Error loading CACKey PNaCl Module: " + messageEvent.data); }, true);
	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();







>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







<
<
<
<
<







86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
...
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
...
353
354
355
356
357
358
359





360
361
362
363
364
365
366
	if (messageEvent.data.target != "cackey") {
		return;
	}

	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");

		return;
................................................................................
	console.log("[cackey] Loaded CACKey PNaCl Module");

	/* 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;
}

/*
 * Initialize CACKey and the PCSC library from Google
 */
................................................................................
	elementEmbed.id = "cackeyModule";
	elementEmbed.addEventListener('error', function(messageEvent) { console.error("Error loading CACKey PNaCl Module: " + messageEvent.data); }, true);
	elementEmbed.addEventListener('load', cackeyInitLoaded, true);
	elementEmbed.addEventListener('message', cackeyMessageIncoming, true);

	cackeyHandle = elementEmbed;






	document.body.appendChild(cackeyHandle)

	console.log("[cackey] cackeyInit(): Completed.  Returning.");
}

/* Initialize CACKey */
cackeyInit();