Diff

Differences From Artifact [3ee1c2da74]:

To Artifact [c88468545b]:


110
111
112
113
114
115
116

117
118
119




120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138

139
140
141
142
143
144
145
110
111
112
113
114
115
116
117



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139

140
141
142
143
144
145
146
147







+
-
-
-
+
+
+
+


















-
+







	var nextFunction = null;
	var chromeCallback = null;

	if (messageEvent.data.target != "cackey") {
		return;
	}

	if (!GoogleSmartCard.IS_DEBUG_BUILD) {
	console.log("START MESSAGE");
	console.log(messageEvent.data);
	console.log("END MESSAGE");
		console.log("START MESSAGE");
		console.log(messageEvent.data);
		console.log("END MESSAGE");
	}

	/*
	 * If we failed for some reason and we have a certificate in the original
	 * request then forget any PIN associated with that certificate
	 */
	if (messageEvent.data.status != "success") {
		if (messageEvent.data.originalrequest.certificate) {
			delete cackeyCertificateToPINMap[cackeyCertificateToPINID(messageEvent.data.originalrequest.certificate)];
		}
	}

	if (messageEvent.data.id == null) {
		return;
	}

	chromeCallback = cackeyOutstandingCallbacks[messageEvent.data.id];

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

		return;
	}

	switch (messageEvent.data.status) {
		case "error":
			console.error("[cackey] Failed to execute command '" + messageEvent.data.command + "': " + messageEvent.data.error);
184
185
186
187
188
189
190
191

192
193
194
195
196
197
198
186
187
188
189
190
191
192

193
194
195
196
197
198
199
200







-
+







			}, function(pinWindow) {
				/*
				 * Set the PIN value to blank
				 */
				pinWindowPINValue = "";

				if (!pinWindow) {
					console.log("[cackey] No window was provided for PIN entry, this will not go well.");
					console.error("[cackey] No window was provided for PIN entry, this will not go well.");

					return;
				}

				pinWindowPreviousHandle = pinWindow;

				pinWindow.drawAttention();
209
210
211
212
213
214
215

216


217
218
219
220
221
222
223
211
212
213
214
215
216
217
218

219
220
221
222
223
224
225
226
227







+
-
+
+








					for (messageIdx = 0; messageIdx < cackeyMessagesToRetry.length; messageIdx++) {
						var tmpMessageEvent;

						tmpMessageEvent = cackeyMessagesToRetry[messageIdx];

						if (pinWindowPINValue == "") {
							if (!GoogleSmartCard.IS_DEBUG_BUILD) {
							console.log("[cackey] The PIN dialog was closed without gathering a PIN, treating it as a failure.");
								console.log("[cackey] The PIN dialog was closed without gathering a PIN, treating it as a failure.");
							}

							tmpMessageEvent.data.status = "error";
							tmpMessageEvent.data.error = "PIN window closed without a PIN being provided";

							cackeyMessageIncoming(tmpMessageEvent);
						} else {
							tmpMessageEvent.data.originalrequest.pin = pinWindowPINValue;
284
285
286
287
288
289
290

291


292
293
294
295
296
297
298
299
300
301
302
303
304
305

306


307
308
309
310
311
312
313
288
289
290
291
292
293
294
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







+
-
+
+














+
-
+
+








/*
 * Handler for messages from Chrome related to listing certificates
 */
function cackeyListCertificates(chromeCallback) {
	var callbackId;

	if (!GoogleSmartCard.IS_DEBUG_BUILD) {
	console.log("[cackey] Asked to provide a list of certificates -- throwing that request over to the NaCl side... ");
		console.log("[cackey] Asked to provide a list of certificates -- throwing that request over to the NaCl side... ");
	}

	callbackId = cackeyOutstandingCallbackCounter + 1;

	cackeyHandle.postMessage(
		{
			'target': "cackey",
			'command': "listcertificates",
			'id': callbackId
		}
	);

	cackeyOutstandingCallbackCounter = callbackId;
	cackeyOutstandingCallbacks[callbackId] = chromeCallback;

	if (!GoogleSmartCard.IS_DEBUG_BUILD) {
	console.log("[cackey] Thrown.");
		console.log("[cackey] Thrown.");
	}

	return;
}

/*
 * Handler for messages from Chrome related to signing a hash of some sort
 */
340
341
342
343
344
345
346

347


348
349
350
351
352
353
354
348
349
350
351
352
353
354
355

356
357
358
359
360
361
362
363
364







+
-
+
+








	digest = new Uint8Array(digestHeader.length + signRequest.digest.byteLength);
	digest.set(digestHeader, 0);
	digest.set(new Uint8Array(signRequest.digest), digestHeader.length);

	delete digestHeader;

	if (!GoogleSmartCard.IS_DEBUG_BUILD) {
	console.log("[cackey] Asked to sign a message -- throwing that request over to the NaCl side... ");
		console.log("[cackey] Asked to sign a message -- throwing that request over to the NaCl side... ");
	}

	callbackId = cackeyOutstandingCallbackCounter + 1;

	command = {
		'target': "cackey",
		'command': "sign",
		'id': callbackId,
363
364
365
366
367
368
369

370


371
372
373
374
375
376
377
373
374
375
376
377
378
379
380

381
382
383
384
385
386
387
388
389







+
-
+
+







	}

	cackeyHandle.postMessage(command);

	cackeyOutstandingCallbackCounter = callbackId;
	cackeyOutstandingCallbacks[callbackId] = chromeCallback;

	if (!GoogleSmartCard.IS_DEBUG_BUILD) {
	console.log("[cackey] Thrown.");
		console.log("[cackey] Thrown.");
	}

	return;
}

/*
 * Finish performing initialization that must wait until we have loaded the CACKey module
 */
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
407
408
409
410
411
412
413

414
415
416
417
418
419
420







-







		}
	);

	/*
	 * Start the Google PCSC Interface
	 */
	new GoogleSmartCard.PcscNacl(cackeyHandle);


	return;
}

/*
 * Initialize CACKey and the PCSC library from Google
 */