Diff

Differences From Artifact [3273b79cbc]:

To Artifact [6f10afa9df]:


32
33
34
35
36
37
38

39
40
41
42
43
44
45
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46







+







 */
var cackeyMessagesToRetry = [];

/*
 * Stored PIN for a given certificate
 */
var cackeyCertificateToPINMap = {};
var cackeyCertificateToPINMapLastUsedRunner = false;

/*
 * Callbacks to perform after PCSC comes online
 */
cackeyCallbackAfterInit = [];

/*
105
106
107
108
109
110
111















































112
113
114
115
116
117
118
106
107
108
109
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








	payload = message.signedData;

	chromeCallback(payload);

	return;
}

/*
 * Update the time a PIN was last used for a certificate
 */
function cackeyCertificateToPINMapUpdateLastUsed(id) {
	if (id != null) {
		cackeyCertificateToPINMap[id].lastUsed = (new Date()).getTime();
	}

	if (!cackeyCertificateToPINMapLastUsedRunner) {
		cackeyCertificateToPINMapLastUsedRunner = true;

		setTimeout(function() {
			var currentTime;
			var certificates, certificate;
			var idx;

			currentTime = (new Date()).getTime();

			certificates = Object.keys(cackeyCertificateToPINMap);

			console.log("Looking for PINs to clear");

			for (idx = 0; idx < certificates.length; idx++) {
				certificate = certificates[idx];

				if ((cackeyCertificateToPINMap[certificate].lastUsed + 900000) > currentTime) {
					continue;
				}

				console.log("Deleteting " + certificate);

				delete cackeyCertificateToPINMap[certificate];
			}

			certificates = Object.keys(cackeyCertificateToPINMap);

			cackeyCertificateToPINMapLastUsedRunner = false;

			if (certificates.length == 0) {
				return;
			}

			cackeyCertificateToPINMapUpdateLastUsed(null);
		}, 900000);
	}
}

/*
 * Handle an incoming message from the NaCl side and pass it off to
 * one of the handlers above for actual formatting and passing to
 * the callback
 *
 * If an error occured, invoke the callback with no arguments.
244
245
246
247
248
249
250
251




252
253
254
255
256
257
258
292
293
294
295
296
297
298

299
300
301
302
303
304
305
306
307
308
309







-
+
+
+
+







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

							cackeyMessageIncoming(tmpMessageEvent);
						} else {
							tmpMessageEvent.data.originalrequest.pin = pinWindowPINValue;

							cackeyCertificateToPINMap[cackeyCertificateToPINID(tmpMessageEvent.data.originalrequest.certificate)] = pinWindowPINValue;
							cackeyCertificateToPINMap[cackeyCertificateToPINID(tmpMessageEvent.data.originalrequest.certificate)] = {}
							cackeyCertificateToPINMap[cackeyCertificateToPINID(tmpMessageEvent.data.originalrequest.certificate)].pin = pinWindowPINValue;

							cackeyCertificateToPINMapUpdateLastUsed(cackeyCertificateToPINID(tmpMessageEvent.data.originalrequest.certificate));

							chromeCallback = null;
							if (tmpMessageEvent.data.id) {
								if (cackeyOutstandingCallbacks) {
									chromeCallback = cackeyOutstandingCallbacks[tmpMessageEvent.data.id];
								}
							}
405
406
407
408
409
410
411
412
413




414
415
416
417
418
419
420
456
457
458
459
460
461
462


463
464
465
466
467
468
469
470
471
472
473







-
-
+
+
+
+







		'id': callbackId,
		'certificate': signRequest.certificate,
		'data': digest.buffer
	};

	certificateId = cackeyCertificateToPINID(command.certificate);

	if (cackeyCertificateToPINMap[certificateId]) {
		command.pin = cackeyCertificateToPINMap[certificateId];
	if (cackeyCertificateToPINMap[certificateId] && cackeyCertificateToPINMap[certificateId].pin) {
		command.pin = cackeyCertificateToPINMap[certificateId].pin;

		cackeyCertificateToPINMapUpdateLastUsed(certificateId);
	}

	cackeyInitPCSC(function() {
		cackeyHandle.postMessage(command);

		cackeyOutstandingCallbackCounter = callbackId;
		cackeyOutstandingCallbacks[callbackId] = chromeCallback;