︙ | | | ︙ | |
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
}
if (messageEvent.data.command == "init" && messageEvent.data.status == "success") {
if (GoogleSmartCard.IS_DEBUG_BUILD) {
console.log("[cackey] Initialization completed, resending any queued messages");
}
cackeyInitPCSCCompleted();
}
if (messageEvent.data.id == null) {
return;
}
chromeCallback = cackeyOutstandingCallbacks[messageEvent.data.id];
|
|
|
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
}
if (messageEvent.data.command == "init" && messageEvent.data.status == "success") {
if (GoogleSmartCard.IS_DEBUG_BUILD) {
console.log("[cackey] Initialization completed, resending any queued messages");
}
cackeyInitPCSCCompleted("success");
}
if (messageEvent.data.id == null) {
return;
}
chromeCallback = cackeyOutstandingCallbacks[messageEvent.data.id];
|
︙ | | | ︙ | |
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
/*
* Register a handler to handle the window being closed without
* having sent anything
*/
pinWindow.onClosed.addListener(function() {
var messageIdx;
pinWindowPreviousHandle = null;
for (messageIdx = 0; messageIdx < cackeyMessagesToRetry.length; messageIdx++) {
var tmpMessageEvent;
tmpMessageEvent = cackeyMessagesToRetry[messageIdx];
|
>
|
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
|
/*
* Register a handler to handle the window being closed without
* having sent anything
*/
pinWindow.onClosed.addListener(function() {
var messageIdx;
var chromeCallback;
pinWindowPreviousHandle = null;
for (messageIdx = 0; messageIdx < cackeyMessagesToRetry.length; messageIdx++) {
var tmpMessageEvent;
tmpMessageEvent = cackeyMessagesToRetry[messageIdx];
|
︙ | | | ︙ | |
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
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;
cackeyInitPCSC(function() {
cackeyHandle.postMessage(tmpMessageEvent.data.originalrequest);
});
}
}
/*
* Delete the existing handle and create a new one
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
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;
chromeCallback = null;
if (tmpMessageEvent.data.id) {
if (cackeyOutstandingCallbacks) {
chromeCallback = cackeyOutstandingCallbacks[tmpMessageEvent.data.id];
}
}
cackeyInitPCSC(function() {
cackeyHandle.postMessage(tmpMessageEvent.data.originalrequest);
}, function() {
if (chromeCallback) {
chromeCallback();
}
if (tmpMessageEvent.data.id && cackeyOutstandingCallbacks[tmpMessageEvent.data.id]) {
delete cackeyOutstandingCallbacks[tmpMessageEvent.data.id];
}
});
}
}
/*
* Delete the existing handle and create a new one
|
︙ | | | ︙ | |
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
|
cackeyOutstandingCallbackCounter = callbackId;
cackeyOutstandingCallbacks[callbackId] = chromeCallback;
if (GoogleSmartCard.IS_DEBUG_BUILD) {
console.log("[cackey] Thrown.");
}
});
return;
}
/*
* Handler for messages from Chrome related to signing a hash of some sort
*/
|
|
|
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
|
cackeyOutstandingCallbackCounter = callbackId;
cackeyOutstandingCallbacks[callbackId] = chromeCallback;
if (GoogleSmartCard.IS_DEBUG_BUILD) {
console.log("[cackey] Thrown.");
}
}, chromeCallback);
return;
}
/*
* Handler for messages from Chrome related to signing a hash of some sort
*/
|
︙ | | | ︙ | |
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
|
cackeyOutstandingCallbackCounter = callbackId;
cackeyOutstandingCallbacks[callbackId] = chromeCallback;
if (GoogleSmartCard.IS_DEBUG_BUILD) {
console.log("[cackey] Thrown.");
}
});
return;
}
/*
* Unititalizes the CACKey PCSC connection
*/
|
|
|
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
|
cackeyOutstandingCallbackCounter = callbackId;
cackeyOutstandingCallbacks[callbackId] = chromeCallback;
if (GoogleSmartCard.IS_DEBUG_BUILD) {
console.log("[cackey] Thrown.");
}
}, chromeCallback);
return;
}
/*
* Unititalizes the CACKey PCSC connection
*/
|
︙ | | | ︙ | |
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
|
* not working.
*/
setTimeout(cackeyInit, 30000);
return;
}
function cackeyInitPCSCCompleted() {
var idx;
cackeyPCSCHandleUsable = true;
for (idx = 0; idx < cackeyCallbackAfterInit.length; idx++) {
if (!cackeyCallbackAfterInit[idx]) {
continue;
}
cackeyCallbackAfterInit[idx]();
}
delete cackeyCallbackAfterInit;
cackeyCallbackAfterInit = [];
return;
}
/*
* Initialize the PCSC connection
*/
function cackeyInitPCSC(callbackAfterInit) {
/*
* Start the Google PCSC Interface
*/
console.log("[cackey] cackeyInitPCSC() called");
/*
* Queue this callback to be completed when initialization is complete
*/
if (callbackAfterInit) {
cackeyCallbackAfterInit.push(callbackAfterInit);
}
/*
* No additional work is required
*/
if (cackeyPCSCHandle) {
console.log("[cackey] PCSC handle is already valid, nothing to do.");
if (cackeyPCSCHandleUsable) {
cackeyInitPCSCCompleted();
}
return;
}
/*
* Sanely initialize this
|
|
>
>
>
>
|
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
|
|
|
|
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
|
* not working.
*/
setTimeout(cackeyInit, 30000);
return;
}
function cackeyInitPCSCCompleted(state) {
var idx;
console.log("[cackey] Connection completed (state = \"" + state + "\"), sending queued events: " + cackeyCallbackAfterInit.length);
switch (state) {
case "success":
cackeyPCSCHandleUsable = true;
break;
case "failure":
cackeyPCSCHandleUsable = false;
break;
}
for (idx = 0; idx < cackeyCallbackAfterInit.length; idx++) {
if (!cackeyCallbackAfterInit[idx]) {
continue;
}
switch (state) {
case "success":
(cackeyCallbackAfterInit[idx].successCallback)();
break;
case "failure":
(cackeyCallbackAfterInit[idx].failureCallback)();
break;
}
}
delete cackeyCallbackAfterInit;
cackeyCallbackAfterInit = [];
console.log("[cackey] All queued events processed");
return;
}
/*
* Initialize the PCSC connection
*/
function cackeyInitPCSC(callbackAfterInit, callbackInitFailed) {
/*
* Start the Google PCSC Interface
*/
console.log("[cackey] cackeyInitPCSC() called");
/*
* Queue this callback to be completed when initialization is complete
*/
if (callbackAfterInit) {
cackeyCallbackAfterInit.push({"successCallback": callbackAfterInit, "failureCallback": callbackInitFailed});
}
/*
* No additional work is required
*/
if (cackeyPCSCHandle) {
console.log("[cackey] PCSC handle is already valid, nothing to do.");
if (cackeyPCSCHandleUsable) {
cackeyInitPCSCCompleted("success");
}
return;
}
/*
* Sanely initialize this
|
︙ | | | ︙ | |
689
690
691
692
693
694
695
696
697
698
699
700
701
702
|
/*
* Register a handler for dealing with the PCSC port being disconnected
*/
oldOnPortDisconnectedFunction = GoogleSmartCard.Pcsc.prototype.onPortDisconnected_;
GoogleSmartCard.Pcsc.prototype.onPortDisconnected_ = function() {
oldOnPortDisconnectedFunction.apply(this);
cackeyRestart();
return;
};
/*
|
>
>
|
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
|
/*
* Register a handler for dealing with the PCSC port being disconnected
*/
oldOnPortDisconnectedFunction = GoogleSmartCard.Pcsc.prototype.onPortDisconnected_;
GoogleSmartCard.Pcsc.prototype.onPortDisconnected_ = function() {
oldOnPortDisconnectedFunction.apply(this);
cackeyInitPCSCCompleted("failure");
cackeyRestart();
return;
};
/*
|
︙ | | | ︙ | |