0000: 2f 2a 0a 20 2a 20 43 41 43 4b 65 79 20 43 68 72 /*. * CACKey Chr
0010: 6f 6d 65 4f 53 20 63 68 72 6f 6d 65 2e 63 65 72 omeOS chrome.cer
0020: 74 69 66 69 63 61 74 65 50 72 6f 76 69 64 65 72 tificateProvider
0030: 20 49 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 0a Implementation.
0040: 20 2a 2f 0a 0a 66 75 6e 63 74 69 6f 6e 20 6f 6e */..function on
0050: 43 65 72 74 69 66 69 63 61 74 65 73 52 65 6a 65 CertificatesReje
0060: 63 74 65 64 28 72 65 6a 65 63 74 65 64 43 65 72 cted(rejectedCer
0070: 74 73 29 20 7b 0a 09 2f 2f 20 49 66 20 63 65 72 ts) {..// If cer
0080: 74 69 66 69 63 61 74 65 73 20 77 65 72 65 20 72 tificates were r
0090: 65 6a 65 63 74 65 64 20 62 79 20 74 68 65 20 41 ejected by the A
00a0: 50 49 2c 20 6c 6f 67 20 61 6e 20 65 72 72 6f 72 PI, log an error
00b0: 2c 20 66 6f 72 20 65 78 61 6d 70 6c 65 2e 0a 09 , for example...
00c0: 63 6f 6e 73 6f 6c 65 2e 65 72 72 6f 72 28 72 65 console.error(re
00d0: 6a 65 63 74 65 64 43 65 72 74 73 2e 6c 65 6e 67 jectedCerts.leng
00e0: 74 68 20 2b 20 27 20 63 65 72 74 69 66 69 63 61 th + ' certifica
00f0: 74 65 73 20 77 65 72 65 20 72 65 6a 65 63 74 65 tes were rejecte
0100: 64 2e 27 29 3b 0a 09 72 65 74 75 72 6e 3b 0a 7d d.');..return;.}
0110: 0a 0a 2f 2a 0a 20 2a 20 48 61 6e 64 6c 65 20 66 ../*. * Handle f
0120: 6f 72 20 74 68 65 20 43 41 43 4b 65 79 20 4e 61 or the CACKey Na
0130: 43 6c 20 54 61 72 67 65 74 0a 20 2a 2f 0a 76 61 Cl Target. */.va
0140: 72 20 63 61 63 6b 65 79 48 61 6e 64 6c 65 20 3d r cackeyHandle =
0150: 20 6e 75 6c 6c 3b 0a 0a 2f 2a 0a 20 2a 20 48 61 null;../*. * Ha
0160: 6e 64 6c 65 20 61 6e 64 20 49 44 20 66 6f 72 20 ndle and ID for
0170: 6f 75 74 73 74 61 6e 64 69 6e 67 20 63 61 6c 6c outstanding call
0180: 62 61 63 6b 73 0a 20 2a 2f 0a 76 61 72 20 63 61 backs. */.var ca
0190: 63 6b 65 79 4f 75 74 73 74 61 6e 64 69 6e 67 43 ckeyOutstandingC
01a0: 61 6c 6c 62 61 63 6b 73 20 3d 20 7b 7d 0a 76 61 allbacks = {}.va
01b0: 72 20 63 61 63 6b 65 79 4f 75 74 73 74 61 6e 64 r cackeyOutstand
01c0: 69 6e 67 43 61 6c 6c 62 61 63 6b 43 6f 75 6e 74 ingCallbackCount
01d0: 65 72 20 3d 20 2d 31 3b 0a 0a 2f 2a 0a 20 2a 20 er = -1;../*. *
01e0: 43 6f 6d 6d 75 6e 69 63 61 74 69 6f 6e 20 77 69 Communication wi
01f0: 74 68 20 74 68 65 20 50 49 4e 20 65 6e 74 72 79 th the PIN entry
0200: 20 77 69 6e 64 6f 77 0a 20 2a 2f 0a 76 61 72 20 window. */.var
0210: 70 69 6e 57 69 6e 64 6f 77 50 49 4e 56 61 6c 75 pinWindowPINValu
0220: 65 20 3d 20 22 22 3b 0a 76 61 72 20 70 69 6e 57 e = "";.var pinW
0230: 69 6e 64 6f 77 50 72 65 76 69 6f 75 73 48 61 6e indowPreviousHan
0240: 64 6c 65 20 3d 20 6e 75 6c 6c 3b 0a 0a 2f 2a 0a dle = null;../*.
0250: 20 2a 20 4d 65 73 73 61 67 65 73 20 74 68 61 74 * Messages that
0260: 20 6d 61 79 20 6e 65 65 64 20 74 6f 20 62 65 20 may need to be
0270: 72 65 74 72 69 65 64 20 61 66 74 65 72 20 67 65 retried after ge
0280: 74 74 69 6e 67 20 61 20 50 49 4e 0a 20 2a 2f 0a tting a PIN. */.
0290: 76 61 72 20 63 61 63 6b 65 79 4d 65 73 73 61 67 var cackeyMessag
02a0: 65 73 54 6f 52 65 74 72 79 20 3d 20 5b 5d 3b 0a esToRetry = [];.
02b0: 0a 2f 2a 0a 20 2a 20 53 74 6f 72 65 64 20 50 49 ./*. * Stored PI
02c0: 4e 20 66 6f 72 20 61 20 67 69 76 65 6e 20 63 65 N for a given ce
02d0: 72 74 69 66 69 63 61 74 65 0a 20 2a 2f 0a 76 61 rtificate. */.va
02e0: 72 20 63 61 63 6b 65 79 43 65 72 74 69 66 69 63 r cackeyCertific
02f0: 61 74 65 54 6f 50 49 4e 4d 61 70 20 3d 20 7b 7d ateToPINMap = {}
0300: 3b 0a 0a 2f 2a 0a 20 2a 20 43 6f 6d 70 75 74 65 ;../*. * Compute
0310: 20 61 20 74 65 78 74 2d 62 61 73 65 64 20 68 61 a text-based ha
0320: 6e 64 6c 65 20 66 6f 72 20 61 20 63 65 72 74 69 ndle for a certi
0330: 66 69 63 61 74 65 20 74 6f 20 62 65 20 68 61 73 ficate to be has
0340: 68 65 64 20 62 79 0a 20 2a 2f 0a 66 75 6e 63 74 hed by. */.funct
0350: 69 6f 6e 20 63 61 63 6b 65 79 43 65 72 74 69 66 ion cackeyCertif
0360: 69 63 61 74 65 54 6f 50 49 4e 49 44 28 63 65 72 icateToPINID(cer
0370: 74 69 66 69 63 61 74 65 29 20 7b 0a 09 76 61 72 tificate) {..var
0380: 20 69 64 3b 0a 09 76 61 72 20 63 65 72 74 69 66 id;..var certif
0390: 69 63 61 74 65 41 72 72 61 79 3b 0a 0a 09 69 64 icateArray;...id
03a0: 20 3d 20 22 22 3b 0a 0a 09 63 65 72 74 69 66 69 = "";...certifi
03b0: 63 61 74 65 41 72 72 61 79 20 3d 20 6e 65 77 20 cateArray = new
03c0: 55 69 6e 74 38 41 72 72 61 79 28 63 65 72 74 69 Uint8Array(certi
03d0: 66 69 63 61 74 65 29 3b 0a 0a 09 63 65 72 74 69 ficate);...certi
03e0: 66 69 63 61 74 65 41 72 72 61 79 2e 6d 61 70 28 ficateArray.map(
03f0: 0a 09 09 66 75 6e 63 74 69 6f 6e 28 62 79 74 65 ...function(byte
0400: 29 20 7b 0a 09 09 09 69 64 20 2b 3d 20 28 22 30 ) {....id += ("0
0410: 22 20 2b 20 62 79 74 65 2e 74 6f 53 74 72 69 6e " + byte.toStrin
0420: 67 28 31 36 29 29 2e 73 6c 69 63 65 28 2d 32 29 g(16)).slice(-2)
0430: 3b 0a 09 09 7d 0a 09 29 3b 0a 0a 09 64 65 6c 65 ;...}..);...dele
0440: 74 65 20 63 65 72 74 69 66 69 63 61 74 65 41 72 te certificateAr
0450: 72 61 79 3b 0a 0a 09 72 65 74 75 72 6e 28 69 64 ray;...return(id
0460: 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 48 61 6e 64 );.}../*. * Hand
0470: 6c 65 20 61 20 72 65 73 70 6f 6e 73 65 20 66 72 le a response fr
0480: 6f 6d 20 74 68 65 20 4e 61 43 6c 20 73 69 64 65 om the NaCl side
0490: 20 72 65 67 61 72 64 69 6e 67 20 63 65 72 74 69 regarding certi
04a0: 66 69 63 61 74 65 73 20 61 76 61 69 6c 61 62 6c ficates availabl
04b0: 65 0a 20 2a 2f 0a 66 75 6e 63 74 69 6f 6e 20 63 e. */.function c
04c0: 61 63 6b 65 79 4d 65 73 73 61 67 65 49 6e 63 6f ackeyMessageInco
04d0: 6d 69 6e 67 4c 69 73 74 43 65 72 74 69 66 69 63 mingListCertific
04e0: 61 74 65 73 28 6d 65 73 73 61 67 65 2c 20 63 68 ates(message, ch
04f0: 72 6f 6d 65 43 61 6c 6c 62 61 63 6b 29 20 7b 0a romeCallback) {.
0500: 09 76 61 72 20 69 64 78 3b 0a 09 76 61 72 20 63 .var idx;..var c
0510: 65 72 74 69 66 69 63 61 74 65 73 20 3d 20 5b 5d ertificates = []
0520: 3b 0a 0a 09 66 6f 72 20 28 69 64 78 20 3d 20 30 ;...for (idx = 0
0530: 3b 20 69 64 78 20 3c 20 6d 65 73 73 61 67 65 2e ; idx < message.
0540: 63 65 72 74 69 66 69 63 61 74 65 73 2e 6c 65 6e certificates.len
0550: 67 74 68 3b 20 69 64 78 2b 2b 29 20 7b 0a 09 09 gth; idx++) {...
0560: 63 65 72 74 69 66 69 63 61 74 65 73 2e 70 75 73 certificates.pus
0570: 68 28 0a 09 09 09 7b 0a 09 09 09 09 63 65 72 74 h(....{.....cert
0580: 69 66 69 63 61 74 65 3a 20 6d 65 73 73 61 67 65 ificate: message
0590: 2e 63 65 72 74 69 66 69 63 61 74 65 73 5b 69 64 .certificates[id
05a0: 78 5d 2c 0a 09 09 09 09 73 75 70 70 6f 72 74 65 x],.....supporte
05b0: 64 48 61 73 68 65 73 3a 20 5b 27 53 48 41 31 27 dHashes: ['SHA1'
05c0: 2c 20 27 53 48 41 32 35 36 27 5d 0a 09 09 09 7d , 'SHA256']....}
05d0: 0a 09 09 29 3b 0a 09 7d 0a 0a 09 63 68 72 6f 6d ...);..}...chrom
05e0: 65 43 61 6c 6c 62 61 63 6b 28 63 65 72 74 69 66 eCallback(certif
05f0: 69 63 61 74 65 73 2c 0a 09 09 66 75 6e 63 74 69 icates,...functi
0600: 6f 6e 28 72 65 6a 65 63 74 65 64 43 65 72 74 73 on(rejectedCerts
0610: 29 20 7b 0a 09 09 09 69 66 20 28 63 68 72 6f 6d ) {....if (chrom
0620: 65 2e 72 75 6e 74 69 6d 65 2e 6c 61 73 74 45 72 e.runtime.lastEr
0630: 72 6f 72 29 20 7b 0a 09 09 09 09 72 65 74 75 72 ror) {.....retur
0640: 6e 3b 0a 09 09 09 7d 0a 0a 09 09 09 69 66 20 28 n;....}.....if (
0650: 72 65 6a 65 63 74 65 64 43 65 72 74 73 2e 6c 65 rejectedCerts.le
0660: 6e 67 74 68 20 21 3d 3d 20 30 29 20 7b 0a 09 09 ngth !== 0) {...
0670: 09 09 6f 6e 43 65 72 74 69 66 69 63 61 74 65 73 ..onCertificates
0680: 52 65 6a 65 63 74 65 64 28 72 65 6a 65 63 74 65 Rejected(rejecte
0690: 64 43 65 72 74 73 29 3b 0a 09 09 09 7d 0a 0a 09 dCerts);....}...
06a0: 09 09 72 65 74 75 72 6e 3b 0a 09 09 7d 0a 09 29 ..return;...}..)
06b0: 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 48 61 6e 64 6c ;.}../*. * Handl
06c0: 65 20 61 20 72 65 73 70 6f 6e 73 65 20 66 72 6f e a response fro
06d0: 6d 20 74 68 65 20 4e 61 43 6c 20 73 69 64 65 20 m the NaCl side
06e0: 72 65 67 61 72 64 69 6e 67 20 73 69 67 6e 69 6e regarding signin
06f0: 67 20 61 20 6d 65 73 73 61 67 65 0a 20 2a 2f 0a g a message. */.
0700: 66 75 6e 63 74 69 6f 6e 20 63 61 63 6b 65 79 4d function cackeyM
0710: 65 73 73 61 67 65 49 6e 63 6f 6d 69 6e 67 53 69 essageIncomingSi
0720: 67 6e 4d 65 73 73 61 67 65 28 6d 65 73 73 61 67 gnMessage(messag
0730: 65 2c 20 63 68 72 6f 6d 65 43 61 6c 6c 62 61 63 e, chromeCallbac
0740: 6b 29 20 7b 0a 09 76 61 72 20 70 61 79 6c 6f 61 k) {..var payloa
0750: 64 3b 0a 0a 09 70 61 79 6c 6f 61 64 20 3d 20 6d d;...payload = m
0760: 65 73 73 61 67 65 2e 73 69 67 6e 65 64 44 61 74 essage.signedDat
0770: 61 3b 0a 0a 09 63 68 72 6f 6d 65 43 61 6c 6c 62 a;...chromeCallb
0780: 61 63 6b 28 70 61 79 6c 6f 61 64 29 3b 0a 7d 0a ack(payload);.}.
0790: 0a 2f 2a 0a 20 2a 20 48 61 6e 64 6c 65 20 61 6e ./*. * Handle an
07a0: 20 69 6e 63 6f 6d 69 6e 67 20 6d 65 73 73 61 67 incoming messag
07b0: 65 20 66 72 6f 6d 20 74 68 65 20 4e 61 43 6c 20 e from the NaCl
07c0: 73 69 64 65 20 61 6e 64 20 70 61 73 73 20 69 74 side and pass it
07d0: 20 6f 66 66 20 74 6f 0a 20 2a 20 6f 6e 65 20 6f off to. * one o
07e0: 66 20 74 68 65 20 68 61 6e 64 6c 65 72 73 20 61 f the handlers a
07f0: 62 6f 76 65 20 66 6f 72 20 61 63 74 75 61 6c 20 bove for actual
0800: 66 6f 72 6d 61 74 74 69 6e 67 20 61 6e 64 20 70 formatting and p
0810: 61 73 73 69 6e 67 20 74 6f 0a 20 2a 20 74 68 65 assing to. * the
0820: 20 63 61 6c 6c 62 61 63 6b 0a 20 2a 0a 20 2a 20 callback. *. *
0830: 49 66 20 61 6e 20 65 72 72 6f 72 20 6f 63 63 75 If an error occu
0840: 72 65 64 2c 20 69 6e 76 6f 6b 65 20 74 68 65 20 red, invoke the
0850: 63 61 6c 6c 62 61 63 6b 20 77 69 74 68 20 6e 6f callback with no
0860: 20 61 72 67 75 6d 65 6e 74 73 2e 0a 20 2a 2f 0a arguments.. */.
0870: 66 75 6e 63 74 69 6f 6e 20 63 61 63 6b 65 79 4d function cackeyM
0880: 65 73 73 61 67 65 49 6e 63 6f 6d 69 6e 67 28 6d essageIncoming(m
0890: 65 73 73 61 67 65 45 76 65 6e 74 29 20 7b 0a 09 essageEvent) {..
08a0: 76 61 72 20 6e 65 78 74 46 75 6e 63 74 69 6f 6e var nextFunction
08b0: 20 3d 20 6e 75 6c 6c 3b 0a 09 76 61 72 20 63 68 = null;..var ch
08c0: 72 6f 6d 65 43 61 6c 6c 62 61 63 6b 20 3d 20 6e romeCallback = n
08d0: 75 6c 6c 3b 0a 0a 09 69 66 20 28 6d 65 73 73 61 ull;...if (messa
08e0: 67 65 45 76 65 6e 74 2e 64 61 74 61 2e 74 61 72 geEvent.data.tar
08f0: 67 65 74 20 21 3d 20 22 63 61 63 6b 65 79 22 29 get != "cackey")
0900: 20 7b 0a 09 09 72 65 74 75 72 6e 3b 0a 09 7d 0a {...return;..}.
0910: 0a 09 69 66 20 28 47 6f 6f 67 6c 65 53 6d 61 72 ..if (GoogleSmar
0920: 74 43 61 72 64 2e 49 53 5f 44 45 42 55 47 5f 42 tCard.IS_DEBUG_B
0930: 55 49 4c 44 29 20 7b 0a 09 09 63 6f 6e 73 6f 6c UILD) {...consol
0940: 65 2e 6c 6f 67 28 22 53 54 41 52 54 20 4d 45 53 e.log("START MES
0950: 53 41 47 45 22 29 3b 0a 09 09 63 6f 6e 73 6f 6c SAGE");...consol
0960: 65 2e 6c 6f 67 28 6d 65 73 73 61 67 65 45 76 65 e.log(messageEve
0970: 6e 74 2e 64 61 74 61 29 3b 0a 09 09 63 6f 6e 73 nt.data);...cons
0980: 6f 6c 65 2e 6c 6f 67 28 22 45 4e 44 20 4d 45 53 ole.log("END MES
0990: 53 41 47 45 22 29 3b 0a 09 7d 0a 0a 09 2f 2a 0a SAGE");..}.../*.
09a0: 09 20 2a 20 49 66 20 77 65 20 66 61 69 6c 65 64 . * If we failed
09b0: 20 66 6f 72 20 73 6f 6d 65 20 72 65 61 73 6f 6e for some reason
09c0: 20 61 6e 64 20 77 65 20 68 61 76 65 20 61 20 63 and we have a c
09d0: 65 72 74 69 66 69 63 61 74 65 20 69 6e 20 74 68 ertificate in th
09e0: 65 20 6f 72 69 67 69 6e 61 6c 0a 09 20 2a 20 72 e original.. * r
09f0: 65 71 75 65 73 74 20 74 68 65 6e 20 66 6f 72 67 equest then forg
0a00: 65 74 20 61 6e 79 20 50 49 4e 20 61 73 73 6f 63 et any PIN assoc
0a10: 69 61 74 65 64 20 77 69 74 68 20 74 68 61 74 20 iated with that
0a20: 63 65 72 74 69 66 69 63 61 74 65 0a 09 20 2a 2f certificate.. */
0a30: 0a 09 69 66 20 28 6d 65 73 73 61 67 65 45 76 65 ..if (messageEve
0a40: 6e 74 2e 64 61 74 61 2e 73 74 61 74 75 73 20 21 nt.data.status !
0a50: 3d 20 22 73 75 63 63 65 73 73 22 29 20 7b 0a 09 = "success") {..
0a60: 09 69 66 20 28 6d 65 73 73 61 67 65 45 76 65 6e .if (messageEven
0a70: 74 2e 64 61 74 61 2e 6f 72 69 67 69 6e 61 6c 72 t.data.originalr
0a80: 65 71 75 65 73 74 29 20 7b 0a 09 09 09 69 66 20 equest) {....if
0a90: 28 6d 65 73 73 61 67 65 45 76 65 6e 74 2e 64 61 (messageEvent.da
0aa0: 74 61 2e 6f 72 69 67 69 6e 61 6c 72 65 71 75 65 ta.originalreque
0ab0: 73 74 2e 63 65 72 74 69 66 69 63 61 74 65 29 20 st.certificate)
0ac0: 7b 0a 09 09 09 09 64 65 6c 65 74 65 20 63 61 63 {.....delete cac
0ad0: 6b 65 79 43 65 72 74 69 66 69 63 61 74 65 54 6f keyCertificateTo
0ae0: 50 49 4e 4d 61 70 5b 63 61 63 6b 65 79 43 65 72 PINMap[cackeyCer
0af0: 74 69 66 69 63 61 74 65 54 6f 50 49 4e 49 44 28 tificateToPINID(
0b00: 6d 65 73 73 61 67 65 45 76 65 6e 74 2e 64 61 74 messageEvent.dat
0b10: 61 2e 6f 72 69 67 69 6e 61 6c 72 65 71 75 65 73 a.originalreques
0b20: 74 2e 63 65 72 74 69 66 69 63 61 74 65 29 5d 3b t.certificate)];
0b30: 0a 09 09 09 7d 0a 09 09 7d 0a 09 7d 0a 0a 09 69 ....}...}..}...i
0b40: 66 20 28 6d 65 73 73 61 67 65 45 76 65 6e 74 2e f (messageEvent.
0b50: 64 61 74 61 2e 69 64 20 3d 3d 20 6e 75 6c 6c 29 data.id == null)
0b60: 20 7b 0a 09 09 72 65 74 75 72 6e 3b 0a 09 7d 0a {...return;..}.
0b70: 0a 09 63 68 72 6f 6d 65 43 61 6c 6c 62 61 63 6b ..chromeCallback
0b80: 20 3d 20 63 61 63 6b 65 79 4f 75 74 73 74 61 6e = cackeyOutstan
0b90: 64 69 6e 67 43 61 6c 6c 62 61 63 6b 73 5b 6d 65 dingCallbacks[me
0ba0: 73 73 61 67 65 45 76 65 6e 74 2e 64 61 74 61 2e ssageEvent.data.
0bb0: 69 64 5d 3b 0a 0a 09 69 66 20 28 63 68 72 6f 6d id];...if (chrom
0bc0: 65 43 61 6c 6c 62 61 63 6b 20 3d 3d 20 6e 75 6c eCallback == nul
0bd0: 6c 29 20 7b 0a 09 09 63 6f 6e 73 6f 6c 65 2e 65 l) {...console.e
0be0: 72 72 6f 72 28 22 5b 63 61 63 6b 65 79 5d 20 44 rror("[cackey] D
0bf0: 69 73 63 61 72 64 69 6e 67 20 6f 75 74 64 61 74 iscarding outdat
0c00: 65 64 20 6d 65 73 73 61 67 65 22 29 3b 0a 0a 09 ed message");...
0c10: 09 72 65 74 75 72 6e 3b 0a 09 7d 0a 0a 09 73 77 .return;..}...sw
0c20: 69 74 63 68 20 28 6d 65 73 73 61 67 65 45 76 65 itch (messageEve
0c30: 6e 74 2e 64 61 74 61 2e 73 74 61 74 75 73 29 20 nt.data.status)
0c40: 7b 0a 09 09 63 61 73 65 20 22 65 72 72 6f 72 22 {...case "error"
0c50: 3a 0a 09 09 09 63 6f 6e 73 6f 6c 65 2e 65 72 72 :....console.err
0c60: 6f 72 28 22 5b 63 61 63 6b 65 79 5d 20 46 61 69 or("[cackey] Fai
0c70: 6c 65 64 20 74 6f 20 65 78 65 63 75 74 65 20 63 led to execute c
0c80: 6f 6d 6d 61 6e 64 20 27 22 20 2b 20 6d 65 73 73 ommand '" + mess
0c90: 61 67 65 45 76 65 6e 74 2e 64 61 74 61 2e 63 6f ageEvent.data.co
0ca0: 6d 6d 61 6e 64 20 2b 20 22 27 3a 20 22 20 2b 20 mmand + "': " +
0cb0: 6d 65 73 73 61 67 65 45 76 65 6e 74 2e 64 61 74 messageEvent.dat
0cc0: 61 2e 65 72 72 6f 72 29 3b 0a 0a 09 09 09 63 68 a.error);.....ch
0cd0: 72 6f 6d 65 43 61 6c 6c 62 61 63 6b 28 29 3b 0a romeCallback();.
0ce0: 0a 09 09 09 62 72 65 61 6b 3b 0a 09 09 63 61 73 ....break;...cas
0cf0: 65 20 22 72 65 74 72 79 22 3a 0a 09 09 09 2f 2a e "retry":..../*
0d00: 0a 09 09 09 20 2a 20 41 64 64 20 74 68 65 20 6e .... * Add the n
0d10: 65 77 20 72 65 71 75 65 73 74 20 74 6f 20 74 68 ew request to th
0d20: 65 20 71 75 65 75 65 20 6f 66 20 65 76 65 6e 74 e queue of event
0d30: 73 20 74 6f 20 70 72 6f 63 65 73 73 20 77 68 65 s to process whe
0d40: 6e 20 74 68 65 20 50 49 4e 0a 09 09 09 20 2a 20 n the PIN.... *
0d50: 70 72 6f 6d 70 74 20 69 73 20 74 65 72 6d 69 6e prompt is termin
0d60: 61 74 65 64 2e 0a 09 09 09 20 2a 2f 0a 09 09 09 ated..... */....
0d70: 63 61 63 6b 65 79 4d 65 73 73 61 67 65 73 54 6f cackeyMessagesTo
0d80: 52 65 74 72 79 2e 70 75 73 68 28 6d 65 73 73 61 Retry.push(messa
0d90: 67 65 45 76 65 6e 74 29 3b 0a 0a 09 09 09 69 66 geEvent);.....if
0da0: 20 28 70 69 6e 57 69 6e 64 6f 77 50 72 65 76 69 (pinWindowPrevi
0db0: 6f 75 73 48 61 6e 64 6c 65 29 20 7b 0a 09 09 09 ousHandle) {....
0dc0: 09 2f 2a 0a 09 09 09 09 20 2a 20 41 6e 20 65 78 ./*..... * An ex
0dd0: 69 73 74 69 6e 67 20 50 49 4e 20 65 6e 74 72 79 isting PIN entry
0de0: 20 69 73 20 69 6e 20 70 72 6f 67 72 65 73 73 0a is in progress.
0df0: 09 09 09 09 20 2a 20 4a 75 73 74 20 61 64 64 20 .... * Just add
0e00: 74 68 65 20 72 65 71 75 65 73 74 20 74 6f 20 74 the request to t
0e10: 68 65 20 71 75 65 75 65 20 28 61 62 6f 76 65 29 he queue (above)
0e20: 20 61 6e 64 20 77 61 69 74 0a 09 09 09 09 20 2a and wait..... *
0e30: 2f 0a 0a 09 09 09 09 72 65 74 75 72 6e 3b 0a 09 /......return;..
0e40: 09 09 7d 0a 0a 09 09 09 2f 2a 0a 09 09 09 20 2a ..}...../*.... *
0e50: 20 53 65 74 20 74 68 65 20 68 61 6e 64 6c 65 20 Set the handle
0e60: 74 6f 20 61 6e 20 69 6e 76 61 6c 69 64 20 28 62 to an invalid (b
0e70: 75 74 20 6e 6f 6e 2d 6e 75 6c 6c 29 20 76 61 6c ut non-null) val
0e80: 75 65 20 75 6e 74 69 6c 20 74 68 65 20 77 69 6e ue until the win
0e90: 64 6f 77 0a 09 09 09 20 2a 20 69 73 20 63 72 65 dow.... * is cre
0ea0: 61 74 65 64 20 69 6e 20 63 61 73 65 20 77 65 20 ated in case we
0eb0: 61 72 65 20 69 6e 76 6f 6b 65 64 20 61 67 61 69 are invoked agai
0ec0: 6e 20 73 6f 6f 6e 2e 0a 09 09 09 20 2a 2f 0a 09 n soon..... */..
0ed0: 09 09 70 69 6e 57 69 6e 64 6f 77 50 72 65 76 69 ..pinWindowPrevi
0ee0: 6f 75 73 48 61 6e 64 6c 65 20 3d 20 22 69 6e 76 ousHandle = "inv
0ef0: 61 6c 69 64 22 3b 0a 0a 09 09 09 63 68 72 6f 6d alid";.....chrom
0f00: 65 2e 61 70 70 2e 77 69 6e 64 6f 77 2e 63 72 65 e.app.window.cre
0f10: 61 74 65 28 22 70 69 6e 2e 68 74 6d 6c 22 2c 20 ate("pin.html",
0f20: 7b 0a 09 09 09 09 22 69 64 22 3a 20 22 63 61 63 {....."id": "cac
0f30: 6b 65 79 50 49 4e 45 6e 74 72 79 22 2c 0a 09 09 keyPINEntry",...
0f40: 09 09 22 72 65 73 69 7a 61 62 6c 65 22 3a 20 66 .."resizable": f
0f50: 61 6c 73 65 2c 0a 09 09 09 09 22 61 6c 77 61 79 alse,....."alway
0f60: 73 4f 6e 54 6f 70 22 3a 20 74 72 75 65 2c 0a 09 sOnTop": true,..
0f70: 09 09 09 22 66 6f 63 75 73 65 64 22 3a 20 74 72 ..."focused": tr
0f80: 75 65 2c 0a 09 09 09 09 22 76 69 73 69 62 6c 65 ue,....."visible
0f90: 4f 6e 41 6c 6c 57 6f 72 6b 73 70 61 63 65 73 22 OnAllWorkspaces"
0fa0: 3a 20 74 72 75 65 2c 0a 09 09 09 09 22 69 6e 6e : true,....."inn
0fb0: 65 72 42 6f 75 6e 64 73 22 3a 20 7b 0a 09 09 09 erBounds": {....
0fc0: 09 09 22 77 69 64 74 68 22 3a 20 33 35 30 2c 0a .."width": 350,.
0fd0: 09 09 09 09 09 22 6d 69 6e 57 69 64 74 68 22 3a ....."minWidth":
0fe0: 20 33 35 30 2c 0a 09 09 09 09 09 22 68 65 69 67 350,......"heig
0ff0: 68 74 22 3a 20 31 33 35 2c 0a 09 09 09 09 09 22 ht": 135,......"
1000: 6d 69 6e 48 65 69 67 68 74 22 3a 20 31 33 35 0a minHeight": 135.
1010: 09 09 09 09 7d 0a 09 09 09 7d 2c 20 66 75 6e 63 ....}....}, func
1020: 74 69 6f 6e 28 70 69 6e 57 69 6e 64 6f 77 29 20 tion(pinWindow)
1030: 7b 0a 09 09 09 09 2f 2a 0a 09 09 09 09 20 2a 20 {...../*..... *
1040: 53 65 74 20 74 68 65 20 50 49 4e 20 76 61 6c 75 Set the PIN valu
1050: 65 20 74 6f 20 62 6c 61 6e 6b 0a 09 09 09 09 20 e to blank.....
1060: 2a 2f 0a 09 09 09 09 70 69 6e 57 69 6e 64 6f 77 */.....pinWindow
1070: 50 49 4e 56 61 6c 75 65 20 3d 20 22 22 3b 0a 0a PINValue = "";..
1080: 09 09 09 09 69 66 20 28 21 70 69 6e 57 69 6e 64 ....if (!pinWind
1090: 6f 77 29 20 7b 0a 09 09 09 09 09 63 6f 6e 73 6f ow) {......conso
10a0: 6c 65 2e 65 72 72 6f 72 28 22 5b 63 61 63 6b 65 le.error("[cacke
10b0: 79 5d 20 4e 6f 20 77 69 6e 64 6f 77 20 77 61 73 y] No window was
10c0: 20 70 72 6f 76 69 64 65 64 20 66 6f 72 20 50 49 provided for PI
10d0: 4e 20 65 6e 74 72 79 2c 20 74 68 69 73 20 77 69 N entry, this wi
10e0: 6c 6c 20 6e 6f 74 20 67 6f 20 77 65 6c 6c 2e 22 ll not go well."
10f0: 29 3b 0a 0a 09 09 09 09 09 72 65 74 75 72 6e 3b );.......return;
1100: 0a 09 09 09 09 7d 0a 0a 09 09 09 09 70 69 6e 57 .....}......pinW
1110: 69 6e 64 6f 77 50 72 65 76 69 6f 75 73 48 61 6e indowPreviousHan
1120: 64 6c 65 20 3d 20 70 69 6e 57 69 6e 64 6f 77 3b dle = pinWindow;
1130: 0a 0a 09 09 09 09 70 69 6e 57 69 6e 64 6f 77 2e ......pinWindow.
1140: 64 72 61 77 41 74 74 65 6e 74 69 6f 6e 28 29 3b drawAttention();
1150: 0a 09 09 09 09 70 69 6e 57 69 6e 64 6f 77 2e 66 .....pinWindow.f
1160: 6f 63 75 73 28 29 3b 0a 0a 09 09 09 09 2f 2a 0a ocus();....../*.
1170: 09 09 09 09 20 2a 20 52 65 67 69 73 74 65 72 20 .... * Register
1180: 61 20 68 61 6e 64 6c 65 72 20 74 6f 20 68 61 6e a handler to han
1190: 64 6c 65 20 74 68 65 20 77 69 6e 64 6f 77 20 62 dle the window b
11a0: 65 69 6e 67 20 63 6c 6f 73 65 64 20 77 69 74 68 eing closed with
11b0: 6f 75 74 0a 09 09 09 09 20 2a 20 68 61 76 69 6e out..... * havin
11c0: 67 20 73 65 6e 74 20 61 6e 79 74 68 69 6e 67 0a g sent anything.
11d0: 09 09 09 09 20 2a 2f 0a 09 09 09 09 70 69 6e 57 .... */.....pinW
11e0: 69 6e 64 6f 77 2e 6f 6e 43 6c 6f 73 65 64 2e 61 indow.onClosed.a
11f0: 64 64 4c 69 73 74 65 6e 65 72 28 66 75 6e 63 74 ddListener(funct
1200: 69 6f 6e 28 29 20 7b 0a 09 09 09 09 09 76 61 72 ion() {......var
1210: 20 6d 65 73 73 61 67 65 49 64 78 3b 0a 0a 09 09 messageIdx;....
1220: 09 09 09 70 69 6e 57 69 6e 64 6f 77 50 72 65 76 ...pinWindowPrev
1230: 69 6f 75 73 48 61 6e 64 6c 65 20 3d 20 6e 75 6c iousHandle = nul
1240: 6c 3b 0a 0a 09 09 09 09 09 66 6f 72 20 28 6d 65 l;.......for (me
1250: 73 73 61 67 65 49 64 78 20 3d 20 30 3b 20 6d 65 ssageIdx = 0; me
1260: 73 73 61 67 65 49 64 78 20 3c 20 63 61 63 6b 65 ssageIdx < cacke
1270: 79 4d 65 73 73 61 67 65 73 54 6f 52 65 74 72 79 yMessagesToRetry
1280: 2e 6c 65 6e 67 74 68 3b 20 6d 65 73 73 61 67 65 .length; message
1290: 49 64 78 2b 2b 29 20 7b 0a 09 09 09 09 09 09 76 Idx++) {.......v
12a0: 61 72 20 74 6d 70 4d 65 73 73 61 67 65 45 76 65 ar tmpMessageEve
12b0: 6e 74 3b 0a 0a 09 09 09 09 09 09 74 6d 70 4d 65 nt;........tmpMe
12c0: 73 73 61 67 65 45 76 65 6e 74 20 3d 20 63 61 63 ssageEvent = cac
12d0: 6b 65 79 4d 65 73 73 61 67 65 73 54 6f 52 65 74 keyMessagesToRet
12e0: 72 79 5b 6d 65 73 73 61 67 65 49 64 78 5d 3b 0a ry[messageIdx];.
12f0: 0a 09 09 09 09 09 09 69 66 20 28 70 69 6e 57 69 .......if (pinWi
1300: 6e 64 6f 77 50 49 4e 56 61 6c 75 65 20 3d 3d 20 ndowPINValue ==
1310: 22 22 29 20 7b 0a 09 09 09 09 09 09 09 69 66 20 "") {........if
1320: 28 47 6f 6f 67 6c 65 53 6d 61 72 74 43 61 72 64 (GoogleSmartCard
1330: 2e 49 53 5f 44 45 42 55 47 5f 42 55 49 4c 44 29 .IS_DEBUG_BUILD)
1340: 20 7b 0a 09 09 09 09 09 09 09 09 63 6f 6e 73 6f {.........conso
1350: 6c 65 2e 6c 6f 67 28 22 5b 63 61 63 6b 65 79 5d le.log("[cackey]
1360: 20 54 68 65 20 50 49 4e 20 64 69 61 6c 6f 67 20 The PIN dialog
1370: 77 61 73 20 63 6c 6f 73 65 64 20 77 69 74 68 6f was closed witho
1380: 75 74 20 67 61 74 68 65 72 69 6e 67 20 61 20 50 ut gathering a P
1390: 49 4e 2c 20 74 72 65 61 74 69 6e 67 20 69 74 20 IN, treating it
13a0: 61 73 20 61 20 66 61 69 6c 75 72 65 2e 22 29 3b as a failure.");
13b0: 0a 09 09 09 09 09 09 09 7d 0a 0a 09 09 09 09 09 ........}.......
13c0: 09 09 74 6d 70 4d 65 73 73 61 67 65 45 76 65 6e ..tmpMessageEven
13d0: 74 2e 64 61 74 61 2e 73 74 61 74 75 73 20 3d 20 t.data.status =
13e0: 22 65 72 72 6f 72 22 3b 0a 09 09 09 09 09 09 09 "error";........
13f0: 74 6d 70 4d 65 73 73 61 67 65 45 76 65 6e 74 2e tmpMessageEvent.
1400: 64 61 74 61 2e 65 72 72 6f 72 20 3d 20 22 50 49 data.error = "PI
1410: 4e 20 77 69 6e 64 6f 77 20 63 6c 6f 73 65 64 20 N window closed
1420: 77 69 74 68 6f 75 74 20 61 20 50 49 4e 20 62 65 without a PIN be
1430: 69 6e 67 20 70 72 6f 76 69 64 65 64 22 3b 0a 0a ing provided";..
1440: 09 09 09 09 09 09 09 63 61 63 6b 65 79 4d 65 73 .......cackeyMes
1450: 73 61 67 65 49 6e 63 6f 6d 69 6e 67 28 74 6d 70 sageIncoming(tmp
1460: 4d 65 73 73 61 67 65 45 76 65 6e 74 29 3b 0a 09 MessageEvent);..
1470: 09 09 09 09 09 7d 20 65 6c 73 65 20 7b 0a 09 09 .....} else {...
1480: 09 09 09 09 09 74 6d 70 4d 65 73 73 61 67 65 45 .....tmpMessageE
1490: 76 65 6e 74 2e 64 61 74 61 2e 6f 72 69 67 69 6e vent.data.origin
14a0: 61 6c 72 65 71 75 65 73 74 2e 70 69 6e 20 3d 20 alrequest.pin =
14b0: 70 69 6e 57 69 6e 64 6f 77 50 49 4e 56 61 6c 75 pinWindowPINValu
14c0: 65 3b 0a 0a 09 09 09 09 09 09 09 63 61 63 6b 65 e;.........cacke
14d0: 79 43 65 72 74 69 66 69 63 61 74 65 54 6f 50 49 yCertificateToPI
14e0: 4e 4d 61 70 5b 63 61 63 6b 65 79 43 65 72 74 69 NMap[cackeyCerti
14f0: 66 69 63 61 74 65 54 6f 50 49 4e 49 44 28 74 6d ficateToPINID(tm
1500: 70 4d 65 73 73 61 67 65 45 76 65 6e 74 2e 64 61 pMessageEvent.da
1510: 74 61 2e 6f 72 69 67 69 6e 61 6c 72 65 71 75 65 ta.originalreque
1520: 73 74 2e 63 65 72 74 69 66 69 63 61 74 65 29 5d st.certificate)]
1530: 20 3d 20 70 69 6e 57 69 6e 64 6f 77 50 49 4e 56 = pinWindowPINV
1540: 61 6c 75 65 3b 0a 0a 09 09 09 09 09 09 09 63 61 alue;.........ca
1550: 63 6b 65 79 48 61 6e 64 6c 65 2e 70 6f 73 74 4d ckeyHandle.postM
1560: 65 73 73 61 67 65 28 74 6d 70 4d 65 73 73 61 67 essage(tmpMessag
1570: 65 45 76 65 6e 74 2e 64 61 74 61 2e 6f 72 69 67 eEvent.data.orig
1580: 69 6e 61 6c 72 65 71 75 65 73 74 29 3b 0a 09 09 inalrequest);...
1590: 09 09 09 09 7d 0a 09 09 09 09 09 7d 0a 0a 0a 09 ....}......}....
15a0: 09 09 09 09 2f 2a 0a 09 09 09 09 09 20 2a 20 44 ..../*...... * D
15b0: 65 6c 65 74 65 20 74 68 65 20 65 78 69 73 74 69 elete the existi
15c0: 6e 67 20 68 61 6e 64 6c 65 20 61 6e 64 20 63 72 ng handle and cr
15d0: 65 61 74 65 20 61 20 6e 65 77 20 6f 6e 65 0a 09 eate a new one..
15e0: 09 09 09 09 20 2a 2f 0a 09 09 09 09 09 64 65 6c .... */......del
15f0: 65 74 65 20 63 61 63 6b 65 79 4d 65 73 73 61 67 ete cackeyMessag
1600: 65 73 54 6f 52 65 74 72 79 3b 0a 0a 09 09 09 09 esToRetry;......
1610: 09 63 61 63 6b 65 79 4d 65 73 73 61 67 65 73 54 .cackeyMessagesT
1620: 6f 52 65 74 72 79 20 3d 20 5b 5d 3b 0a 0a 09 09 oRetry = [];....
1630: 09 09 09 2f 2a 0a 09 09 09 09 09 20 2a 20 57 65 .../*...... * We
1640: 20 61 72 65 20 64 6f 6e 65 20 66 65 74 63 68 69 are done fetchi
1650: 6e 67 20 74 68 65 20 75 73 65 72 20 50 49 4e 2c ng the user PIN,
1660: 20 63 6c 65 61 72 20 74 68 65 20 76 61 6c 75 65 clear the value
1670: 0a 09 09 09 09 09 20 2a 2f 0a 09 09 09 09 09 70 ...... */......p
1680: 69 6e 57 69 6e 64 6f 77 50 49 4e 56 61 6c 75 65 inWindowPINValue
1690: 20 3d 20 22 22 3b 0a 0a 09 09 09 09 09 72 65 74 = "";.......ret
16a0: 75 72 6e 3b 0a 09 09 09 09 7d 29 0a 0a 09 09 09 urn;.....}).....
16b0: 09 2f 2a 0a 09 09 09 09 20 2a 20 50 61 73 73 20 ./*..... * Pass
16c0: 74 68 69 73 20 6d 65 73 73 61 67 65 20 6f 66 66 this message off
16d0: 20 74 6f 20 74 68 65 20 6f 74 68 65 72 20 77 69 to the other wi
16e0: 6e 64 6f 77 20 73 6f 20 74 68 61 74 20 69 74 20 ndow so that it
16f0: 6d 61 79 20 72 65 73 75 62 6d 69 74 20 74 68 65 may resubmit the
1700: 20 72 65 71 75 65 73 74 2e 0a 09 09 09 09 20 2a request...... *
1710: 2f 0a 09 09 09 09 70 69 6e 57 69 6e 64 6f 77 2e /.....pinWindow.
1720: 63 6f 6e 74 65 6e 74 57 69 6e 64 6f 77 2e 70 61 contentWindow.pa
1730: 72 65 6e 74 57 69 6e 64 6f 77 20 3d 20 77 69 6e rentWindow = win
1740: 64 6f 77 3b 0a 09 09 09 09 70 69 6e 57 69 6e 64 dow;.....pinWind
1750: 6f 77 2e 63 6f 6e 74 65 6e 74 57 69 6e 64 6f 77 ow.contentWindow
1760: 2e 6d 65 73 73 61 67 65 45 76 65 6e 74 20 3d 20 .messageEvent =
1770: 6d 65 73 73 61 67 65 45 76 65 6e 74 3b 0a 0a 09 messageEvent;...
1780: 09 09 09 72 65 74 75 72 6e 3b 0a 09 09 09 7d 29 ...return;....})
1790: 3b 0a 0a 09 09 09 2f 2a 0a 09 09 09 20 2a 20 57 ;...../*.... * W
17a0: 65 20 72 65 74 75 72 6e 20 68 65 72 65 20 69 6e e return here in
17b0: 73 74 65 61 64 20 6f 66 20 62 72 65 61 6b 20 74 stead of break t
17c0: 6f 20 61 76 6f 69 64 20 64 65 6c 65 74 69 6e 67 o avoid deleting
17d0: 20 74 68 65 20 63 61 6c 6c 62 61 63 6b 0a 09 09 the callback...
17e0: 09 20 2a 20 65 6e 74 72 79 2e 0a 09 09 09 20 2a . * entry..... *
17f0: 2f 0a 09 09 09 72 65 74 75 72 6e 3b 0a 09 09 63 /....return;...c
1800: 61 73 65 20 22 73 75 63 63 65 73 73 22 3a 0a 09 ase "success":..
1810: 09 09 73 77 69 74 63 68 20 28 6d 65 73 73 61 67 ..switch (messag
1820: 65 45 76 65 6e 74 2e 64 61 74 61 2e 63 6f 6d 6d eEvent.data.comm
1830: 61 6e 64 29 20 7b 0a 09 09 09 09 63 61 73 65 20 and) {.....case
1840: 22 6c 69 73 74 63 65 72 74 69 66 69 63 61 74 65 "listcertificate
1850: 73 22 3a 0a 09 09 09 09 09 6e 65 78 74 46 75 6e s":......nextFun
1860: 63 74 69 6f 6e 20 3d 20 63 61 63 6b 65 79 4d 65 ction = cackeyMe
1870: 73 73 61 67 65 49 6e 63 6f 6d 69 6e 67 4c 69 73 ssageIncomingLis
1880: 74 43 65 72 74 69 66 69 63 61 74 65 73 3b 0a 0a tCertificates;..
1890: 09 09 09 09 09 62 72 65 61 6b 3b 0a 09 09 09 09 .....break;.....
18a0: 63 61 73 65 20 22 73 69 67 6e 22 3a 0a 09 09 09 case "sign":....
18b0: 09 09 6e 65 78 74 46 75 6e 63 74 69 6f 6e 20 3d ..nextFunction =
18c0: 20 63 61 63 6b 65 79 4d 65 73 73 61 67 65 49 6e cackeyMessageIn
18d0: 63 6f 6d 69 6e 67 53 69 67 6e 4d 65 73 73 61 67 comingSignMessag
18e0: 65 3b 0a 0a 09 09 09 09 09 62 72 65 61 6b 3b 0a e;.......break;.
18f0: 09 09 09 7d 0a 0a 09 09 09 62 72 65 61 6b 3b 0a ...}.....break;.
1900: 09 7d 0a 0a 09 69 66 20 28 6e 65 78 74 46 75 6e .}...if (nextFun
1910: 63 74 69 6f 6e 20 21 3d 20 6e 75 6c 6c 29 20 7b ction != null) {
1920: 0a 09 09 6e 65 78 74 46 75 6e 63 74 69 6f 6e 28 ...nextFunction(
1930: 6d 65 73 73 61 67 65 45 76 65 6e 74 2e 64 61 74 messageEvent.dat
1940: 61 2c 20 63 68 72 6f 6d 65 43 61 6c 6c 62 61 63 a, chromeCallbac
1950: 6b 29 3b 0a 09 7d 0a 0a 09 64 65 6c 65 74 65 20 k);..}...delete
1960: 63 61 63 6b 65 79 4f 75 74 73 74 61 6e 64 69 6e cackeyOutstandin
1970: 67 43 61 6c 6c 62 61 63 6b 73 5b 6d 65 73 73 61 gCallbacks[messa
1980: 67 65 45 76 65 6e 74 2e 64 61 74 61 2e 69 64 5d geEvent.data.id]
1990: 3b 0a 0a 09 72 65 74 75 72 6e 3b 0a 7d 0a 0a 2f ;...return;.}../
19a0: 2a 0a 20 2a 20 48 61 6e 64 6c 65 72 20 66 6f 72 *. * Handler for
19b0: 20 6d 65 73 73 61 67 65 73 20 66 72 6f 6d 20 43 messages from C
19c0: 68 72 6f 6d 65 20 72 65 6c 61 74 65 64 20 74 6f hrome related to
19d0: 20 6c 69 73 74 69 6e 67 20 63 65 72 74 69 66 69 listing certifi
19e0: 63 61 74 65 73 0a 20 2a 2f 0a 66 75 6e 63 74 69 cates. */.functi
19f0: 6f 6e 20 63 61 63 6b 65 79 4c 69 73 74 43 65 72 on cackeyListCer
1a00: 74 69 66 69 63 61 74 65 73 28 63 68 72 6f 6d 65 tificates(chrome
1a10: 43 61 6c 6c 62 61 63 6b 29 20 7b 0a 09 76 61 72 Callback) {..var
1a20: 20 63 61 6c 6c 62 61 63 6b 49 64 3b 0a 0a 09 69 callbackId;...i
1a30: 66 20 28 47 6f 6f 67 6c 65 53 6d 61 72 74 43 61 f (GoogleSmartCa
1a40: 72 64 2e 49 53 5f 44 45 42 55 47 5f 42 55 49 4c rd.IS_DEBUG_BUIL
1a50: 44 29 20 7b 0a 09 09 63 6f 6e 73 6f 6c 65 2e 6c D) {...console.l
1a60: 6f 67 28 22 5b 63 61 63 6b 65 79 5d 20 41 73 6b og("[cackey] Ask
1a70: 65 64 20 74 6f 20 70 72 6f 76 69 64 65 20 61 20 ed to provide a
1a80: 6c 69 73 74 20 6f 66 20 63 65 72 74 69 66 69 63 list of certific
1a90: 61 74 65 73 20 2d 2d 20 74 68 72 6f 77 69 6e 67 ates -- throwing
1aa0: 20 74 68 61 74 20 72 65 71 75 65 73 74 20 6f 76 that request ov
1ab0: 65 72 20 74 6f 20 74 68 65 20 4e 61 43 6c 20 73 er to the NaCl s
1ac0: 69 64 65 2e 2e 2e 20 22 29 3b 0a 09 7d 0a 0a 09 ide... ");..}...
1ad0: 63 61 6c 6c 62 61 63 6b 49 64 20 3d 20 63 61 63 callbackId = cac
1ae0: 6b 65 79 4f 75 74 73 74 61 6e 64 69 6e 67 43 61 keyOutstandingCa
1af0: 6c 6c 62 61 63 6b 43 6f 75 6e 74 65 72 20 2b 20 llbackCounter +
1b00: 31 3b 0a 0a 09 63 61 63 6b 65 79 48 61 6e 64 6c 1;...cackeyHandl
1b10: 65 2e 70 6f 73 74 4d 65 73 73 61 67 65 28 0a 09 e.postMessage(..
1b20: 09 7b 0a 09 09 09 27 74 61 72 67 65 74 27 3a 20 .{....'target':
1b30: 22 63 61 63 6b 65 79 22 2c 0a 09 09 09 27 63 6f "cackey",....'co
1b40: 6d 6d 61 6e 64 27 3a 20 22 6c 69 73 74 63 65 72 mmand': "listcer
1b50: 74 69 66 69 63 61 74 65 73 22 2c 0a 09 09 09 27 tificates",....'
1b60: 69 64 27 3a 20 63 61 6c 6c 62 61 63 6b 49 64 0a id': callbackId.
1b70: 09 09 7d 0a 09 29 3b 0a 0a 09 63 61 63 6b 65 79 ..}..);...cackey
1b80: 4f 75 74 73 74 61 6e 64 69 6e 67 43 61 6c 6c 62 OutstandingCallb
1b90: 61 63 6b 43 6f 75 6e 74 65 72 20 3d 20 63 61 6c ackCounter = cal
1ba0: 6c 62 61 63 6b 49 64 3b 0a 09 63 61 63 6b 65 79 lbackId;..cackey
1bb0: 4f 75 74 73 74 61 6e 64 69 6e 67 43 61 6c 6c 62 OutstandingCallb
1bc0: 61 63 6b 73 5b 63 61 6c 6c 62 61 63 6b 49 64 5d acks[callbackId]
1bd0: 20 3d 20 63 68 72 6f 6d 65 43 61 6c 6c 62 61 63 = chromeCallbac
1be0: 6b 3b 0a 0a 09 69 66 20 28 47 6f 6f 67 6c 65 53 k;...if (GoogleS
1bf0: 6d 61 72 74 43 61 72 64 2e 49 53 5f 44 45 42 55 martCard.IS_DEBU
1c00: 47 5f 42 55 49 4c 44 29 20 7b 0a 09 09 63 6f 6e G_BUILD) {...con
1c10: 73 6f 6c 65 2e 6c 6f 67 28 22 5b 63 61 63 6b 65 sole.log("[cacke
1c20: 79 5d 20 54 68 72 6f 77 6e 2e 22 29 3b 0a 09 7d y] Thrown.");..}
1c30: 0a 0a 09 72 65 74 75 72 6e 3b 0a 7d 0a 0a 2f 2a ...return;.}../*
1c40: 0a 20 2a 20 48 61 6e 64 6c 65 72 20 66 6f 72 20 . * Handler for
1c50: 6d 65 73 73 61 67 65 73 20 66 72 6f 6d 20 43 68 messages from Ch
1c60: 72 6f 6d 65 20 72 65 6c 61 74 65 64 20 74 6f 20 rome related to
1c70: 73 69 67 6e 69 6e 67 20 61 20 68 61 73 68 20 6f signing a hash o
1c80: 66 20 73 6f 6d 65 20 73 6f 72 74 0a 20 2a 2f 0a f some sort. */.
1c90: 66 75 6e 63 74 69 6f 6e 20 63 61 63 6b 65 79 53 function cackeyS
1ca0: 69 67 6e 4d 65 73 73 61 67 65 28 73 69 67 6e 52 ignMessage(signR
1cb0: 65 71 75 65 73 74 2c 20 63 68 72 6f 6d 65 43 61 equest, chromeCa
1cc0: 6c 6c 62 61 63 6b 29 20 7b 0a 09 76 61 72 20 63 llback) {..var c
1cd0: 61 6c 6c 62 61 63 6b 49 64 3b 0a 09 76 61 72 20 allbackId;..var
1ce0: 63 6f 6d 6d 61 6e 64 3b 0a 09 76 61 72 20 63 65 command;..var ce
1cf0: 72 74 69 66 69 63 61 74 65 49 64 3b 0a 09 76 61 rtificateId;..va
1d00: 72 20 64 69 67 65 73 74 2c 20 64 69 67 65 73 74 r digest, digest
1d10: 48 65 61 64 65 72 3b 0a 0a 09 2f 2a 0a 09 20 2a Header;.../*.. *
1d20: 20 50 72 65 66 69 78 20 74 68 65 20 64 69 67 65 Prefix the dige
1d30: 73 74 20 77 69 74 68 20 74 68 65 20 41 53 4e 2e st with the ASN.
1d40: 31 20 68 65 61 64 65 72 20 72 65 71 75 69 72 65 1 header require
1d50: 64 20 6f 66 20 69 74 0a 09 20 2a 2f 0a 09 73 77 d of it.. */..sw
1d60: 69 74 63 68 20 28 73 69 67 6e 52 65 71 75 65 73 itch (signReques
1d70: 74 2e 68 61 73 68 29 20 7b 0a 09 09 63 61 73 65 t.hash) {...case
1d80: 20 22 53 48 41 2d 31 22 3a 0a 09 09 09 64 69 67 "SHA-1":....dig
1d90: 65 73 74 48 65 61 64 65 72 20 3d 20 6e 65 77 20 estHeader = new
1da0: 55 69 6e 74 38 41 72 72 61 79 28 5b 30 78 33 30 Uint8Array([0x30
1db0: 2c 20 30 78 32 31 2c 20 30 78 33 30 2c 20 30 78 , 0x21, 0x30, 0x
1dc0: 30 39 2c 20 30 78 30 36 2c 20 30 78 30 35 2c 20 09, 0x06, 0x05,
1dd0: 30 78 32 62 2c 20 30 78 30 65 2c 20 30 78 30 33 0x2b, 0x0e, 0x03
1de0: 2c 20 30 78 30 32 2c 20 30 78 31 61 2c 20 30 78 , 0x02, 0x1a, 0x
1df0: 30 35 2c 20 30 78 30 30 2c 20 30 78 30 34 2c 20 05, 0x00, 0x04,
1e00: 30 78 31 34 5d 29 3b 0a 09 09 09 62 72 65 61 6b 0x14]);....break
1e10: 3b 0a 09 09 63 61 73 65 20 22 53 48 41 2d 32 35 ;...case "SHA-25
1e20: 36 22 3a 0a 09 09 09 64 69 67 65 73 74 48 65 61 6":....digestHea
1e30: 64 65 72 20 3d 20 6e 65 77 20 55 69 6e 74 38 41 der = new Uint8A
1e40: 72 72 61 79 28 5b 30 78 33 30 2c 20 30 78 33 31 rray([0x30, 0x31
1e50: 2c 20 30 78 33 30 2c 20 30 78 30 64 2c 20 30 78 , 0x30, 0x0d, 0x
1e60: 30 36 2c 20 30 78 30 39 2c 20 30 78 36 30 2c 20 06, 0x09, 0x60,
1e70: 30 78 38 36 2c 20 30 78 34 38 2c 20 30 78 30 31 0x86, 0x48, 0x01
1e80: 2c 20 30 78 36 35 2c 20 30 78 30 33 2c 20 30 78 , 0x65, 0x03, 0x
1e90: 30 34 2c 20 30 78 30 32 2c 20 30 78 30 31 2c 20 04, 0x02, 0x01,
1ea0: 30 78 30 35 2c 20 30 78 30 30 2c 20 30 78 30 34 0x05, 0x00, 0x04
1eb0: 2c 20 30 78 32 30 5d 29 3b 0a 09 09 09 62 72 65 , 0x20]);....bre
1ec0: 61 6b 3b 0a 09 09 63 61 73 65 20 22 4d 44 35 5f ak;...case "MD5_
1ed0: 53 48 41 31 22 3a 0a 09 09 09 64 69 67 65 73 74 SHA1":....digest
1ee0: 48 65 61 64 65 72 20 3d 20 6e 65 77 20 55 69 6e Header = new Uin
1ef0: 74 38 41 72 72 61 79 28 29 3b 0a 09 09 09 62 72 t8Array();....br
1f00: 65 61 6b 3b 0a 09 09 64 65 66 61 75 6c 74 3a 0a eak;...default:.
1f10: 09 09 09 63 6f 6e 73 6f 6c 65 2e 65 72 72 6f 72 ...console.error
1f20: 28 22 5b 63 61 63 6b 65 79 5d 20 41 73 6b 65 64 ("[cackey] Asked
1f30: 20 74 6f 20 73 69 67 6e 20 61 20 6d 65 73 73 61 to sign a messa
1f40: 67 65 20 77 69 74 68 20 61 20 68 61 73 68 20 77 ge with a hash w
1f50: 65 20 64 6f 20 6e 6f 74 20 73 75 70 70 6f 72 74 e do not support
1f60: 3a 20 22 20 2b 20 73 69 67 6e 52 65 71 75 65 73 : " + signReques
1f70: 74 2e 68 61 73 68 29 3b 0a 0a 09 09 09 63 68 72 t.hash);.....chr
1f80: 6f 6d 65 43 61 6c 6c 62 61 63 6b 28 29 3b 0a 0a omeCallback();..
1f90: 09 09 09 72 65 74 75 72 6e 3b 0a 09 7d 0a 0a 09 ...return;..}...
1fa0: 64 69 67 65 73 74 20 3d 20 6e 65 77 20 55 69 6e digest = new Uin
1fb0: 74 38 41 72 72 61 79 28 64 69 67 65 73 74 48 65 t8Array(digestHe
1fc0: 61 64 65 72 2e 6c 65 6e 67 74 68 20 2b 20 73 69 ader.length + si
1fd0: 67 6e 52 65 71 75 65 73 74 2e 64 69 67 65 73 74 gnRequest.digest
1fe0: 2e 62 79 74 65 4c 65 6e 67 74 68 29 3b 0a 09 64 .byteLength);..d
1ff0: 69 67 65 73 74 2e 73 65 74 28 64 69 67 65 73 74 igest.set(digest
2000: 48 65 61 64 65 72 2c 20 30 29 3b 0a 09 64 69 67 Header, 0);..dig
2010: 65 73 74 2e 73 65 74 28 6e 65 77 20 55 69 6e 74 est.set(new Uint
2020: 38 41 72 72 61 79 28 73 69 67 6e 52 65 71 75 65 8Array(signReque
2030: 73 74 2e 64 69 67 65 73 74 29 2c 20 64 69 67 65 st.digest), dige
2040: 73 74 48 65 61 64 65 72 2e 6c 65 6e 67 74 68 29 stHeader.length)
2050: 3b 0a 0a 09 64 65 6c 65 74 65 20 64 69 67 65 73 ;...delete diges
2060: 74 48 65 61 64 65 72 3b 0a 0a 09 69 66 20 28 47 tHeader;...if (G
2070: 6f 6f 67 6c 65 53 6d 61 72 74 43 61 72 64 2e 49 oogleSmartCard.I
2080: 53 5f 44 45 42 55 47 5f 42 55 49 4c 44 29 20 7b S_DEBUG_BUILD) {
2090: 0a 09 09 63 6f 6e 73 6f 6c 65 2e 6c 6f 67 28 22 ...console.log("
20a0: 5b 63 61 63 6b 65 79 5d 20 41 73 6b 65 64 20 74 [cackey] Asked t
20b0: 6f 20 73 69 67 6e 20 61 20 6d 65 73 73 61 67 65 o sign a message
20c0: 20 2d 2d 20 74 68 72 6f 77 69 6e 67 20 74 68 61 -- throwing tha
20d0: 74 20 72 65 71 75 65 73 74 20 6f 76 65 72 20 74 t request over t
20e0: 6f 20 74 68 65 20 4e 61 43 6c 20 73 69 64 65 2e o the NaCl side.
20f0: 2e 2e 20 22 29 3b 0a 09 7d 0a 0a 09 63 61 6c 6c .. ");..}...call
2100: 62 61 63 6b 49 64 20 3d 20 63 61 63 6b 65 79 4f backId = cackeyO
2110: 75 74 73 74 61 6e 64 69 6e 67 43 61 6c 6c 62 61 utstandingCallba
2120: 63 6b 43 6f 75 6e 74 65 72 20 2b 20 31 3b 0a 0a ckCounter + 1;..
2130: 09 63 6f 6d 6d 61 6e 64 20 3d 20 7b 0a 09 09 27 .command = {...'
2140: 74 61 72 67 65 74 27 3a 20 22 63 61 63 6b 65 79 target': "cackey
2150: 22 2c 0a 09 09 27 63 6f 6d 6d 61 6e 64 27 3a 20 ",...'command':
2160: 22 73 69 67 6e 22 2c 0a 09 09 27 69 64 27 3a 20 "sign",...'id':
2170: 63 61 6c 6c 62 61 63 6b 49 64 2c 0a 09 09 27 63 callbackId,...'c
2180: 65 72 74 69 66 69 63 61 74 65 27 3a 20 73 69 67 ertificate': sig
2190: 6e 52 65 71 75 65 73 74 2e 63 65 72 74 69 66 69 nRequest.certifi
21a0: 63 61 74 65 2c 0a 09 09 27 64 61 74 61 27 3a 20 cate,...'data':
21b0: 64 69 67 65 73 74 2e 62 75 66 66 65 72 0a 09 7d digest.buffer..}
21c0: 3b 0a 0a 09 63 65 72 74 69 66 69 63 61 74 65 49 ;...certificateI
21d0: 64 20 3d 20 63 61 63 6b 65 79 43 65 72 74 69 66 d = cackeyCertif
21e0: 69 63 61 74 65 54 6f 50 49 4e 49 44 28 63 6f 6d icateToPINID(com
21f0: 6d 61 6e 64 2e 63 65 72 74 69 66 69 63 61 74 65 mand.certificate
2200: 29 3b 0a 0a 09 69 66 20 28 63 61 63 6b 65 79 43 );...if (cackeyC
2210: 65 72 74 69 66 69 63 61 74 65 54 6f 50 49 4e 4d ertificateToPINM
2220: 61 70 5b 63 65 72 74 69 66 69 63 61 74 65 49 64 ap[certificateId
2230: 5d 29 20 7b 0a 09 09 63 6f 6d 6d 61 6e 64 2e 70 ]) {...command.p
2240: 69 6e 20 3d 20 63 61 63 6b 65 79 43 65 72 74 69 in = cackeyCerti
2250: 66 69 63 61 74 65 54 6f 50 49 4e 4d 61 70 5b 63 ficateToPINMap[c
2260: 65 72 74 69 66 69 63 61 74 65 49 64 5d 3b 0a 09 ertificateId];..
2270: 7d 0a 0a 09 63 61 63 6b 65 79 48 61 6e 64 6c 65 }...cackeyHandle
2280: 2e 70 6f 73 74 4d 65 73 73 61 67 65 28 63 6f 6d .postMessage(com
2290: 6d 61 6e 64 29 3b 0a 0a 09 63 61 63 6b 65 79 4f mand);...cackeyO
22a0: 75 74 73 74 61 6e 64 69 6e 67 43 61 6c 6c 62 61 utstandingCallba
22b0: 63 6b 43 6f 75 6e 74 65 72 20 3d 20 63 61 6c 6c ckCounter = call
22c0: 62 61 63 6b 49 64 3b 0a 09 63 61 63 6b 65 79 4f backId;..cackeyO
22d0: 75 74 73 74 61 6e 64 69 6e 67 43 61 6c 6c 62 61 utstandingCallba
22e0: 63 6b 73 5b 63 61 6c 6c 62 61 63 6b 49 64 5d 20 cks[callbackId]
22f0: 3d 20 63 68 72 6f 6d 65 43 61 6c 6c 62 61 63 6b = chromeCallback
2300: 3b 0a 0a 09 69 66 20 28 47 6f 6f 67 6c 65 53 6d ;...if (GoogleSm
2310: 61 72 74 43 61 72 64 2e 49 53 5f 44 45 42 55 47 artCard.IS_DEBUG
2320: 5f 42 55 49 4c 44 29 20 7b 0a 09 09 63 6f 6e 73 _BUILD) {...cons
2330: 6f 6c 65 2e 6c 6f 67 28 22 5b 63 61 63 6b 65 79 ole.log("[cackey
2340: 5d 20 54 68 72 6f 77 6e 2e 22 29 3b 0a 09 7d 0a ] Thrown.");..}.
2350: 0a 09 72 65 74 75 72 6e 3b 0a 7d 0a 0a 2f 2a 0a ..return;.}../*.
2360: 20 2a 20 46 69 6e 69 73 68 20 70 65 72 66 6f 72 * Finish perfor
2370: 6d 69 6e 67 20 69 6e 69 74 69 61 6c 69 7a 61 74 ming initializat
2380: 69 6f 6e 20 74 68 61 74 20 6d 75 73 74 20 77 61 ion that must wa
2390: 69 74 20 75 6e 74 69 6c 20 77 65 20 68 61 76 65 it until we have
23a0: 20 6c 6f 61 64 65 64 20 74 68 65 20 43 41 43 4b loaded the CACK
23b0: 65 79 20 6d 6f 64 75 6c 65 0a 20 2a 2f 0a 66 75 ey module. */.fu
23c0: 6e 63 74 69 6f 6e 20 63 61 63 6b 65 79 49 6e 69 nction cackeyIni
23d0: 74 4c 6f 61 64 65 64 28 6d 65 73 73 61 67 65 45 tLoaded(messageE
23e0: 76 65 6e 74 29 20 7b 0a 09 63 6f 6e 73 6f 6c 65 vent) {..console
23f0: 2e 6c 6f 67 28 22 5b 63 61 63 6b 65 79 5d 20 4c .log("[cackey] L
2400: 6f 61 64 65 64 20 43 41 43 4b 65 79 20 50 4e 61 oaded CACKey PNa
2410: 43 6c 20 4d 6f 64 75 6c 65 22 29 3b 0a 0a 09 2f Cl Module");.../
2420: 2a 20 52 65 67 69 73 74 65 72 20 6c 69 73 74 65 * Register liste
2430: 6e 65 72 73 20 77 69 74 68 20 43 68 72 6f 6d 65 ners with Chrome
2440: 20 2a 2f 0a 09 69 66 20 28 63 68 72 6f 6d 65 2e */..if (chrome.
2450: 63 65 72 74 69 66 69 63 61 74 65 50 72 6f 76 69 certificateProvi
2460: 64 65 72 29 20 7b 0a 09 09 63 68 72 6f 6d 65 2e der) {...chrome.
2470: 63 65 72 74 69 66 69 63 61 74 65 50 72 6f 76 69 certificateProvi
2480: 64 65 72 2e 6f 6e 43 65 72 74 69 66 69 63 61 74 der.onCertificat
2490: 65 73 52 65 71 75 65 73 74 65 64 2e 61 64 64 4c esRequested.addL
24a0: 69 73 74 65 6e 65 72 28 63 61 63 6b 65 79 4c 69 istener(cackeyLi
24b0: 73 74 43 65 72 74 69 66 69 63 61 74 65 73 29 3b stCertificates);
24c0: 0a 09 09 63 68 72 6f 6d 65 2e 63 65 72 74 69 66 ...chrome.certif
24d0: 69 63 61 74 65 50 72 6f 76 69 64 65 72 2e 6f 6e icateProvider.on
24e0: 53 69 67 6e 44 69 67 65 73 74 52 65 71 75 65 73 SignDigestReques
24f0: 74 65 64 2e 61 64 64 4c 69 73 74 65 6e 65 72 28 ted.addListener(
2500: 63 61 63 6b 65 79 53 69 67 6e 4d 65 73 73 61 67 cackeySignMessag
2510: 65 29 3b 0a 09 7d 0a 0a 09 2f 2a 0a 09 20 2a 20 e);..}.../*.. *
2520: 49 6e 69 74 69 61 6c 69 7a 65 20 43 41 43 4b 65 Initialize CACKe
2530: 79 20 77 69 74 68 20 74 68 65 20 63 6f 72 72 65 y with the corre
2540: 63 74 20 68 61 6e 64 6c 65 20 74 6f 20 74 61 6c ct handle to tal
2550: 6b 20 74 6f 20 74 68 65 20 47 6f 6f 67 6c 65 20 k to the Google
2560: 53 6d 61 72 74 63 61 72 64 20 4d 61 6e 61 67 65 Smartcard Manage
2570: 72 20 41 70 70 0a 09 20 2a 2f 0a 09 63 61 63 6b r App.. */..cack
2580: 65 79 48 61 6e 64 6c 65 2e 70 6f 73 74 4d 65 73 eyHandle.postMes
2590: 73 61 67 65 28 0a 09 09 7b 0a 09 09 09 22 74 61 sage(...{...."ta
25a0: 72 67 65 74 22 3a 20 22 63 61 63 6b 65 79 22 2c rget": "cackey",
25b0: 0a 09 09 09 22 63 6f 6d 6d 61 6e 64 22 3a 20 22 ...."command": "
25c0: 69 6e 69 74 22 2c 0a 09 09 09 22 73 6d 61 72 74 init",...."smart
25d0: 63 61 72 64 4d 61 6e 61 67 65 72 41 70 70 49 64 cardManagerAppId
25e0: 22 3a 20 22 6b 68 70 66 65 61 61 6e 6a 6e 67 6d ": "khpfeaanjngm
25f0: 63 6e 70 6c 62 64 6c 70 65 67 69 69 66 67 70 66 cnplbdlpegiifgpf
2600: 67 64 63 6f 22 0a 09 09 7d 0a 09 29 3b 0a 0a 09 gdco"...}..);...
2610: 2f 2a 0a 09 20 2a 20 53 74 61 72 74 20 74 68 65 /*.. * Start the
2620: 20 47 6f 6f 67 6c 65 20 50 43 53 43 20 49 6e 74 Google PCSC Int
2630: 65 72 66 61 63 65 0a 09 20 2a 2f 0a 09 6e 65 77 erface.. */..new
2640: 20 47 6f 6f 67 6c 65 53 6d 61 72 74 43 61 72 64 GoogleSmartCard
2650: 2e 50 63 73 63 4e 61 63 6c 28 63 61 63 6b 65 79 .PcscNacl(cackey
2660: 48 61 6e 64 6c 65 29 3b 0a 0a 09 72 65 74 75 72 Handle);...retur
2670: 6e 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 49 6e 69 74 n;.}../*. * Init
2680: 69 61 6c 69 7a 65 20 43 41 43 4b 65 79 20 61 6e ialize CACKey an
2690: 64 20 74 68 65 20 50 43 53 43 20 6c 69 62 72 61 d the PCSC libra
26a0: 72 79 20 66 72 6f 6d 20 47 6f 6f 67 6c 65 0a 20 ry from Google.
26b0: 2a 2f 0a 66 75 6e 63 74 69 6f 6e 20 63 61 63 6b */.function cack
26c0: 65 79 49 6e 69 74 28 29 20 7b 0a 09 76 61 72 20 eyInit() {..var
26d0: 65 6c 65 6d 65 6e 74 45 6d 62 65 64 3b 0a 0a 09 elementEmbed;...
26e0: 2f 2a 20 4c 6f 67 20 74 68 61 74 20 77 65 20 61 /* Log that we a
26f0: 72 65 20 6f 70 65 72 61 74 69 6f 6e 61 6c 20 2a re operational *
2700: 2f 0a 09 63 6f 6e 73 6f 6c 65 2e 6c 6f 67 28 22 /..console.log("
2710: 5b 63 61 63 6b 65 79 5d 20 63 61 63 6b 65 79 49 [cackey] cackeyI
2720: 6e 69 74 28 29 3a 20 43 61 6c 6c 65 64 2e 22 29 nit(): Called.")
2730: 3b 0a 0a 09 2f 2a 0a 09 20 2a 20 43 72 65 61 74 ;.../*.. * Creat
2740: 65 20 61 20 68 61 6e 64 6c 65 72 20 66 6f 72 20 e a handler for
2750: 73 74 61 72 74 69 6e 67 20 74 68 65 20 61 70 70 starting the app
2760: 6c 69 63 61 74 69 6f 6e 20 55 49 0a 09 20 2a 2f lication UI.. */
2770: 0a 09 63 68 72 6f 6d 65 2e 61 70 70 2e 72 75 6e ..chrome.app.run
2780: 74 69 6d 65 2e 6f 6e 4c 61 75 6e 63 68 65 64 2e time.onLaunched.
2790: 61 64 64 4c 69 73 74 65 6e 65 72 28 66 75 6e 63 addListener(func
27a0: 74 69 6f 6e 28 29 20 7b 0a 09 09 63 68 72 6f 6d tion() {...chrom
27b0: 65 2e 61 70 70 2e 77 69 6e 64 6f 77 2e 63 72 65 e.app.window.cre
27c0: 61 74 65 28 27 75 69 2e 68 74 6d 6c 27 2c 20 7b ate('ui.html', {
27d0: 0a 09 09 09 22 69 64 22 3a 20 22 63 61 63 6b 65 ...."id": "cacke
27e0: 79 55 49 22 2c 0a 09 09 09 22 66 6f 63 75 73 65 yUI",...."focuse
27f0: 64 22 3a 20 74 72 75 65 2c 0a 09 09 09 22 69 6e d": true,...."in
2800: 6e 65 72 42 6f 75 6e 64 73 22 3a 20 7b 0a 09 09 nerBounds": {...
2810: 09 09 22 77 69 64 74 68 22 3a 20 33 35 30 2c 0a .."width": 350,.
2820: 09 09 09 09 22 6d 69 6e 57 69 64 74 68 22 3a 20 ...."minWidth":
2830: 33 35 30 2c 0a 09 09 09 09 22 68 65 69 67 68 74 350,....."height
2840: 22 3a 20 31 33 35 2c 0a 09 09 09 09 22 6d 69 6e ": 135,....."min
2850: 48 65 69 67 68 74 22 3a 20 31 33 35 0a 09 09 09 Height": 135....
2860: 7d 0a 09 09 7d 29 3b 0a 09 7d 29 3b 0a 0a 09 2f }...});..});.../
2870: 2a 20 56 65 72 69 66 79 20 74 68 61 74 20 77 65 * Verify that we
2880: 20 63 61 6e 20 72 65 67 69 73 74 65 72 20 63 61 can register ca
2890: 6c 6c 62 61 63 6b 73 20 2a 2f 0a 09 69 66 20 28 llbacks */..if (
28a0: 21 63 68 72 6f 6d 65 2e 63 65 72 74 69 66 69 63 !chrome.certific
28b0: 61 74 65 50 72 6f 76 69 64 65 72 29 20 7b 0a 09 ateProvider) {..
28c0: 09 69 66 20 28 21 47 6f 6f 67 6c 65 53 6d 61 72 .if (!GoogleSmar
28d0: 74 43 61 72 64 2e 49 53 5f 44 45 42 55 47 5f 42 tCard.IS_DEBUG_B
28e0: 55 49 4c 44 29 20 7b 0a 09 09 09 63 6f 6e 73 6f UILD) {....conso
28f0: 6c 65 2e 65 72 72 6f 72 28 22 5b 63 61 63 6b 65 le.error("[cacke
2900: 79 5d 20 54 68 69 73 20 65 78 74 65 6e 73 69 6f y] This extensio
2910: 6e 20 6f 6e 6c 79 20 77 6f 72 6b 73 20 6f 6e 20 n only works on
2920: 43 68 72 6f 6d 65 4f 53 21 22 29 3b 0a 0a 09 09 ChromeOS!");....
2930: 09 72 65 74 75 72 6e 3b 0a 09 09 7d 20 65 6c 73 .return;...} els
2940: 65 20 7b 0a 09 09 09 63 6f 6e 73 6f 6c 65 2e 6c e {....console.l
2950: 6f 67 28 22 5b 63 61 63 6b 65 79 5d 20 54 68 69 og("[cackey] Thi
2960: 73 20 65 78 74 65 6e 73 69 6f 6e 20 6f 6e 6c 79 s extension only
2970: 20 77 6f 72 6b 73 20 6f 6e 20 43 68 72 6f 6d 65 works on Chrome
2980: 4f 53 2c 20 62 75 74 20 79 6f 75 20 61 70 70 65 OS, but you appe
2990: 61 72 20 74 6f 20 62 65 20 64 65 62 75 67 67 69 ar to be debuggi
29a0: 6e 67 20 69 74 20 2d 2d 20 74 72 79 69 6e 67 20 ng it -- trying
29b0: 61 6e 79 77 61 79 2e 22 29 3b 0a 09 09 7d 0a 09 anyway.");...}..
29c0: 7d 0a 0a 09 69 66 20 28 63 61 63 6b 65 79 48 61 }...if (cackeyHa
29d0: 6e 64 6c 65 20 21 3d 20 6e 75 6c 6c 29 20 7b 0a ndle != null) {.
29e0: 09 09 63 6f 6e 73 6f 6c 65 2e 6c 6f 67 28 22 5b ..console.log("[
29f0: 63 61 63 6b 65 79 5d 20 63 61 63 6b 65 79 49 6e cackey] cackeyIn
2a00: 69 74 28 29 3a 20 41 6c 72 65 61 64 79 20 69 6e it(): Already in
2a10: 69 74 69 61 6c 69 7a 65 64 2e 20 20 52 65 74 75 itialized. Retu
2a20: 72 6e 69 6e 67 2e 22 29 3b 0a 0a 09 09 72 65 74 rning.");....ret
2a30: 75 72 6e 3b 0a 09 7d 0a 0a 09 65 6c 65 6d 65 6e urn;..}...elemen
2a40: 74 45 6d 62 65 64 20 3d 20 64 6f 63 75 6d 65 6e tEmbed = documen
2a50: 74 2e 63 72 65 61 74 65 45 6c 65 6d 65 6e 74 28 t.createElement(
2a60: 27 65 6d 62 65 64 27 29 3b 0a 09 65 6c 65 6d 65 'embed');..eleme
2a70: 6e 74 45 6d 62 65 64 2e 74 79 70 65 20 3d 20 22 ntEmbed.type = "
2a80: 61 70 70 6c 69 63 61 74 69 6f 6e 2f 78 2d 70 6e application/x-pn
2a90: 61 63 6c 22 3b 0a 09 65 6c 65 6d 65 6e 74 45 6d acl";..elementEm
2aa0: 62 65 64 2e 77 69 64 74 68 20 3d 20 30 3b 0a 09 bed.width = 0;..
2ab0: 65 6c 65 6d 65 6e 74 45 6d 62 65 64 2e 68 65 69 elementEmbed.hei
2ac0: 67 68 74 20 3d 20 30 3b 0a 09 65 6c 65 6d 65 6e ght = 0;..elemen
2ad0: 74 45 6d 62 65 64 2e 73 72 63 20 3d 20 22 63 61 tEmbed.src = "ca
2ae0: 63 6b 65 79 2e 6e 6d 66 22 3b 0a 09 65 6c 65 6d ckey.nmf";..elem
2af0: 65 6e 74 45 6d 62 65 64 2e 69 64 20 3d 20 22 63 entEmbed.id = "c
2b00: 61 63 6b 65 79 4d 6f 64 75 6c 65 22 3b 0a 09 65 ackeyModule";..e
2b10: 6c 65 6d 65 6e 74 45 6d 62 65 64 2e 61 64 64 45 lementEmbed.addE
2b20: 76 65 6e 74 4c 69 73 74 65 6e 65 72 28 27 65 72 ventListener('er
2b30: 72 6f 72 27 2c 20 66 75 6e 63 74 69 6f 6e 28 6d ror', function(m
2b40: 65 73 73 61 67 65 45 76 65 6e 74 29 20 7b 20 63 essageEvent) { c
2b50: 6f 6e 73 6f 6c 65 2e 65 72 72 6f 72 28 22 45 72 onsole.error("Er
2b60: 72 6f 72 20 6c 6f 61 64 69 6e 67 20 43 41 43 4b ror loading CACK
2b70: 65 79 20 50 4e 61 43 6c 20 4d 6f 64 75 6c 65 3a ey PNaCl Module:
2b80: 20 22 20 2b 20 6d 65 73 73 61 67 65 45 76 65 6e " + messageEven
2b90: 74 2e 64 61 74 61 29 3b 20 7d 2c 20 74 72 75 65 t.data); }, true
2ba0: 29 3b 0a 09 65 6c 65 6d 65 6e 74 45 6d 62 65 64 );..elementEmbed
2bb0: 2e 61 64 64 45 76 65 6e 74 4c 69 73 74 65 6e 65 .addEventListene
2bc0: 72 28 27 6c 6f 61 64 27 2c 20 63 61 63 6b 65 79 r('load', cackey
2bd0: 49 6e 69 74 4c 6f 61 64 65 64 2c 20 74 72 75 65 InitLoaded, true
2be0: 29 3b 0a 09 65 6c 65 6d 65 6e 74 45 6d 62 65 64 );..elementEmbed
2bf0: 2e 61 64 64 45 76 65 6e 74 4c 69 73 74 65 6e 65 .addEventListene
2c00: 72 28 27 6d 65 73 73 61 67 65 27 2c 20 63 61 63 r('message', cac
2c10: 6b 65 79 4d 65 73 73 61 67 65 49 6e 63 6f 6d 69 keyMessageIncomi
2c20: 6e 67 2c 20 74 72 75 65 29 3b 0a 0a 09 63 61 63 ng, true);...cac
2c30: 6b 65 79 48 61 6e 64 6c 65 20 3d 20 65 6c 65 6d keyHandle = elem
2c40: 65 6e 74 45 6d 62 65 64 3b 0a 0a 09 64 6f 63 75 entEmbed;...docu
2c50: 6d 65 6e 74 2e 62 6f 64 79 2e 61 70 70 65 6e 64 ment.body.append
2c60: 43 68 69 6c 64 28 63 61 63 6b 65 79 48 61 6e 64 Child(cackeyHand
2c70: 6c 65 29 0a 0a 09 63 6f 6e 73 6f 6c 65 2e 6c 6f le)...console.lo
2c80: 67 28 22 5b 63 61 63 6b 65 79 5d 20 63 61 63 6b g("[cackey] cack
2c90: 65 79 49 6e 69 74 28 29 3a 20 43 6f 6d 70 6c 65 eyInit(): Comple
2ca0: 74 65 64 2e 20 20 52 65 74 75 72 6e 69 6e 67 2e ted. Returning.
2cb0: 22 29 3b 0a 7d 0a 0a 2f 2a 20 49 6e 69 74 69 61 ");.}../* Initia
2cc0: 6c 69 7a 65 20 43 41 43 4b 65 79 20 2a 2f 0a 63 lize CACKey */.c
2cd0: 61 63 6b 65 79 49 6e 69 74 28 29 3b 0a ackeyInit();.