Hex Artifact Content

Artifact 3317412933c48f9d1e9a3054910c8ace99aaee67:


0000: 2f 2a 0a 20 2a 20 47 6f 6f 67 6c 65 27 73 20 50  /*. * Google's P
0010: 43 53 43 20 6c 69 62 72 61 72 79 20 72 65 71 75  CSC library requ
0020: 69 72 65 73 20 75 73 20 74 6f 20 77 72 69 74 65  ires us to write
0030: 20 6f 75 72 20 6d 6f 64 75 6c 65 20 69 6e 20 43   our module in C
0040: 2b 2b 20 74 6f 20 69 6e 69 74 69 61 6c 69 7a 65  ++ to initialize
0050: 0a 20 2a 20 69 74 2e 20 20 54 68 69 73 20 63 6f  . * it.  This co
0060: 6d 70 6f 6e 65 6e 74 20 68 61 6e 64 6c 65 73 20  mponent handles 
0070: 74 68 65 20 69 6e 69 74 69 61 6c 69 7a 61 74 69  the initializati
0080: 6f 6e 20 6f 66 20 6f 75 72 20 6d 6f 64 75 6c 65  on of our module
0090: 20 61 6e 64 20 68 61 6e 64 6c 65 73 0a 20 2a 20   and handles. * 
00a0: 69 6e 63 6f 6d 69 6e 67 20 6d 65 73 73 61 67 65  incoming message
00b0: 73 2c 20 70 61 73 73 69 6e 67 20 74 68 65 6d 20  s, passing them 
00c0: 65 69 74 68 65 72 20 74 6f 20 6f 75 72 20 6c 69  either to our li
00d0: 62 72 61 72 79 20 28 63 61 63 6b 65 79 2d 63 68  brary (cackey-ch
00e0: 72 6f 6d 65 29 20 6f 72 0a 20 2a 20 74 6f 20 74  rome) or. * to t
00f0: 68 65 20 50 43 53 43 2d 4e 61 43 6c 20 6c 69 62  he PCSC-NaCl lib
0100: 72 61 72 79 20 66 72 6f 6d 20 47 6f 6f 67 6c 65  rary from Google
0110: 20 61 73 20 61 70 70 72 6f 70 72 69 61 74 65 2e   as appropriate.
0120: 0a 20 2a 2f 0a 0a 23 69 6e 63 6c 75 64 65 20 3c  . */..#include <
0130: 74 68 72 65 61 64 3e 0a 23 69 6e 63 6c 75 64 65  thread>.#include
0140: 20 3c 70 70 61 70 69 2f 63 70 70 2f 69 6e 73 74   <ppapi/cpp/inst
0150: 61 6e 63 65 2e 68 3e 0a 23 69 6e 63 6c 75 64 65  ance.h>.#include
0160: 20 3c 70 70 61 70 69 2f 63 70 70 2f 6d 6f 64 75   <ppapi/cpp/modu
0170: 6c 65 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c  le.h>.#include <
0180: 70 70 61 70 69 2f 63 70 70 2f 63 6f 72 65 2e 68  ppapi/cpp/core.h
0190: 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 70 70 61 70  >.#include <ppap
01a0: 69 2f 63 70 70 2f 76 61 72 2e 68 3e 0a 23 69 6e  i/cpp/var.h>.#in
01b0: 63 6c 75 64 65 20 3c 70 70 61 70 69 2f 63 70 70  clude <ppapi/cpp
01c0: 2f 76 61 72 5f 64 69 63 74 69 6f 6e 61 72 79 2e  /var_dictionary.
01d0: 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 70 70 61  h>.#include <ppa
01e0: 70 69 2f 63 70 70 2f 76 61 72 5f 61 72 72 61 79  pi/cpp/var_array
01f0: 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 70 70  .h>.#include <pp
0200: 61 70 69 2f 63 70 70 2f 76 61 72 5f 61 72 72 61  api/cpp/var_arra
0210: 79 5f 62 75 66 66 65 72 2e 68 3e 0a 0a 23 69 6e  y_buffer.h>..#in
0220: 63 6c 75 64 65 20 22 70 63 73 63 2d 6e 61 63 6c  clude "pcsc-nacl
0230: 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20 22 63 61  .h".#include "ca
0240: 63 6b 65 79 2d 63 68 72 6f 6d 65 2e 68 22 0a 0a  ckey-chrome.h"..
0250: 63 6c 61 73 73 20 43 41 43 4b 65 79 49 6e 73 74  class CACKeyInst
0260: 61 6e 63 65 20 3a 20 70 75 62 6c 69 63 20 70 70  ance : public pp
0270: 3a 3a 49 6e 73 74 61 6e 63 65 20 7b 0a 09 70 72  ::Instance {..pr
0280: 69 76 61 74 65 3a 0a 09 09 76 6f 69 64 20 70 63  ivate:...void pc
0290: 73 63 4e 61 43 6c 49 6e 69 74 57 72 61 70 70 65  scNaClInitWrappe
02a0: 72 28 70 70 3a 3a 43 6f 72 65 20 2a 63 6f 72 65  r(pp::Core *core
02b0: 29 20 7b 0a 09 09 09 70 63 73 63 4e 61 43 6c 49  ) {....pcscNaClI
02c0: 6e 69 74 28 74 68 69 73 2c 20 63 6f 72 65 29 3b  nit(this, core);
02d0: 0a 09 09 7d 0a 09 70 75 62 6c 69 63 3a 0a 09 09  ...}..public:...
02e0: 65 78 70 6c 69 63 69 74 20 43 41 43 4b 65 79 49  explicit CACKeyI
02f0: 6e 73 74 61 6e 63 65 28 50 50 5f 49 6e 73 74 61  nstance(PP_Insta
0300: 6e 63 65 20 69 6e 73 74 61 6e 63 65 2c 20 70 70  nce instance, pp
0310: 3a 3a 43 6f 72 65 20 2a 63 6f 72 65 29 20 3a 20  ::Core *core) : 
0320: 70 70 3a 3a 49 6e 73 74 61 6e 63 65 28 69 6e 73  pp::Instance(ins
0330: 74 61 6e 63 65 29 20 7b 0a 09 09 09 73 74 64 3a  tance) {....std:
0340: 3a 74 68 72 65 61 64 28 26 43 41 43 4b 65 79 49  :thread(&CACKeyI
0350: 6e 73 74 61 6e 63 65 3a 3a 70 63 73 63 4e 61 43  nstance::pcscNaC
0360: 6c 49 6e 69 74 57 72 61 70 70 65 72 2c 20 74 68  lInitWrapper, th
0370: 69 73 2c 20 63 6f 72 65 29 2e 64 65 74 61 63 68  is, core).detach
0380: 28 29 3b 0a 09 09 7d 0a 0a 09 09 76 69 72 74 75  ();...}....virtu
0390: 61 6c 20 7e 43 41 43 4b 65 79 49 6e 73 74 61 6e  al ~CACKeyInstan
03a0: 63 65 28 29 20 7b 7d 0a 0a 09 09 76 69 72 74 75  ce() {}....virtu
03b0: 61 6c 20 76 6f 69 64 20 48 61 6e 64 6c 65 4d 65  al void HandleMe
03c0: 73 73 61 67 65 54 68 72 65 61 64 28 70 70 3a 3a  ssageThread(pp::
03d0: 56 61 72 44 69 63 74 69 6f 6e 61 72 79 20 2a 6d  VarDictionary *m
03e0: 65 73 73 61 67 65 29 20 7b 0a 09 09 09 69 6e 74  essage) {....int
03f0: 20 6e 75 6d 43 65 72 74 69 66 69 63 61 74 65 73   numCertificates
0400: 2c 20 69 3b 0a 09 09 09 73 74 72 75 63 74 20 63  , i;....struct c
0410: 61 63 6b 65 79 5f 63 65 72 74 69 66 69 63 61 74  ackey_certificat
0420: 65 20 2a 63 65 72 74 69 66 69 63 61 74 65 73 3b  e *certificates;
0430: 0a 09 09 09 70 70 3a 3a 56 61 72 44 69 63 74 69  ....pp::VarDicti
0440: 6f 6e 61 72 79 20 2a 72 65 70 6c 79 3b 0a 09 09  onary *reply;...
0450: 09 70 70 3a 3a 56 61 72 41 72 72 61 79 20 63 65  .pp::VarArray ce
0460: 72 74 69 66 69 63 61 74 65 73 50 50 41 72 72 61  rtificatesPPArra
0470: 79 3b 0a 09 09 09 70 70 3a 3a 56 61 72 41 72 72  y;....pp::VarArr
0480: 61 79 42 75 66 66 65 72 20 2a 63 65 72 74 69 66  ayBuffer *certif
0490: 69 63 61 74 65 43 6f 6e 74 65 6e 74 73 3b 0a 09  icateContents;..
04a0: 09 09 70 70 3a 3a 56 61 72 20 63 6f 6d 6d 61 6e  ..pp::Var comman
04b0: 64 2c 20 69 6e 63 6f 6d 69 6e 67 43 65 72 74 69  d, incomingCerti
04c0: 66 69 63 61 74 65 43 6f 6e 74 65 6e 74 73 3b 0a  ficateContents;.
04d0: 0a 09 09 09 2f 2a 0a 09 09 09 20 2a 20 45 78 74  ..../*.... * Ext
04e0: 72 61 63 74 20 74 68 65 20 63 6f 6d 6d 61 6e 64  ract the command
04f0: 0a 09 09 09 20 2a 2f 0a 09 09 09 63 6f 6d 6d 61  .... */....comma
0500: 6e 64 20 3d 20 6d 65 73 73 61 67 65 2d 3e 47 65  nd = message->Ge
0510: 74 28 22 63 6f 6d 6d 61 6e 64 22 29 3b 0a 0a 09  t("command");...
0520: 09 09 2f 2a 0a 09 09 09 20 2a 20 44 6f 20 74 68  ../*.... * Do th
0530: 65 20 74 68 69 6e 67 20 77 65 20 61 72 65 20 62  e thing we are b
0540: 65 69 6e 67 20 61 73 6b 65 64 20 74 6f 20 64 6f  eing asked to do
0550: 0a 09 09 09 20 2a 2f 0a 09 09 09 72 65 70 6c 79  .... */....reply
0560: 20 3d 20 6e 65 77 20 70 70 3a 3a 56 61 72 44 69   = new pp::VarDi
0570: 63 74 69 6f 6e 61 72 79 28 29 3b 0a 0a 09 09 09  ctionary();.....
0580: 69 66 20 28 63 6f 6d 6d 61 6e 64 2e 41 73 53 74  if (command.AsSt
0590: 72 69 6e 67 28 29 20 3d 3d 20 22 6c 69 73 74 63  ring() == "listc
05a0: 65 72 74 69 66 69 63 61 74 65 73 22 29 20 7b 0a  ertificates") {.
05b0: 09 09 09 09 6e 75 6d 43 65 72 74 69 66 69 63 61  ....numCertifica
05c0: 74 65 73 20 3d 20 63 61 63 6b 65 79 5f 63 68 72  tes = cackey_chr
05d0: 6f 6d 65 5f 6c 69 73 74 43 65 72 74 69 66 69 63  ome_listCertific
05e0: 61 74 65 73 28 26 63 65 72 74 69 66 69 63 61 74  ates(&certificat
05f0: 65 73 29 3b 0a 0a 09 09 09 09 63 65 72 74 69 66  es);......certif
0600: 69 63 61 74 65 73 50 50 41 72 72 61 79 2e 53 65  icatesPPArray.Se
0610: 74 4c 65 6e 67 74 68 28 6e 75 6d 43 65 72 74 69  tLength(numCerti
0620: 66 69 63 61 74 65 73 29 3b 0a 0a 09 09 09 09 66  ficates);......f
0630: 6f 72 20 28 69 20 3d 20 30 3b 20 69 20 3c 20 6e  or (i = 0; i < n
0640: 75 6d 43 65 72 74 69 66 69 63 61 74 65 73 3b 20  umCertificates; 
0650: 69 2b 2b 29 20 7b 0a 09 09 09 09 09 63 65 72 74  i++) {......cert
0660: 69 66 69 63 61 74 65 43 6f 6e 74 65 6e 74 73 20  ificateContents 
0670: 3d 20 6e 65 77 20 70 70 3a 3a 56 61 72 41 72 72  = new pp::VarArr
0680: 61 79 42 75 66 66 65 72 28 63 65 72 74 69 66 69  ayBuffer(certifi
0690: 63 61 74 65 73 5b 69 5d 2e 63 65 72 74 69 66 69  cates[i].certifi
06a0: 63 61 74 65 5f 6c 65 6e 29 3b 0a 0a 09 09 09 09  cate_len);......
06b0: 09 6d 65 6d 63 70 79 28 63 65 72 74 69 66 69 63  .memcpy(certific
06c0: 61 74 65 43 6f 6e 74 65 6e 74 73 2d 3e 4d 61 70  ateContents->Map
06d0: 28 29 2c 20 63 65 72 74 69 66 69 63 61 74 65 73  (), certificates
06e0: 5b 69 5d 2e 63 65 72 74 69 66 69 63 61 74 65 2c  [i].certificate,
06f0: 20 63 65 72 74 69 66 69 63 61 74 65 73 5b 69 5d   certificates[i]
0700: 2e 63 65 72 74 69 66 69 63 61 74 65 5f 6c 65 6e  .certificate_len
0710: 29 3b 0a 0a 09 09 09 09 09 63 65 72 74 69 66 69  );.......certifi
0720: 63 61 74 65 43 6f 6e 74 65 6e 74 73 2d 3e 55 6e  cateContents->Un
0730: 6d 61 70 28 29 3b 0a 0a 09 09 09 09 09 63 65 72  map();.......cer
0740: 74 69 66 69 63 61 74 65 73 50 50 41 72 72 61 79  tificatesPPArray
0750: 2e 53 65 74 28 69 2c 20 2a 63 65 72 74 69 66 69  .Set(i, *certifi
0760: 63 61 74 65 43 6f 6e 74 65 6e 74 73 29 3b 0a 0a  cateContents);..
0770: 09 09 09 09 09 64 65 6c 65 74 65 20 63 65 72 74  .....delete cert
0780: 69 66 69 63 61 74 65 43 6f 6e 74 65 6e 74 73 3b  ificateContents;
0790: 0a 09 09 09 09 7d 0a 0a 09 09 09 09 63 61 63 6b  .....}......cack
07a0: 65 79 5f 63 68 72 6f 6d 65 5f 66 72 65 65 43 65  ey_chrome_freeCe
07b0: 72 74 69 66 69 63 61 74 65 73 28 63 65 72 74 69  rtificates(certi
07c0: 66 69 63 61 74 65 73 2c 20 6e 75 6d 43 65 72 74  ficates, numCert
07d0: 69 66 69 63 61 74 65 73 29 3b 0a 0a 09 09 09 09  ificates);......
07e0: 72 65 70 6c 79 2d 3e 53 65 74 28 22 73 74 61 74  reply->Set("stat
07f0: 75 73 22 2c 20 22 73 75 63 63 65 73 73 22 29 3b  us", "success");
0800: 0a 09 09 09 09 72 65 70 6c 79 2d 3e 53 65 74 28  .....reply->Set(
0810: 22 63 65 72 74 69 66 69 63 61 74 65 73 22 2c 20  "certificates", 
0820: 63 65 72 74 69 66 69 63 61 74 65 73 50 50 41 72  certificatesPPAr
0830: 72 61 79 29 3b 0a 09 09 09 7d 20 65 6c 73 65 20  ray);....} else 
0840: 69 66 20 28 63 6f 6d 6d 61 6e 64 2e 41 73 53 74  if (command.AsSt
0850: 72 69 6e 67 28 29 20 3d 3d 20 22 73 69 67 6e 22  ring() == "sign"
0860: 29 20 7b 0a 09 09 09 09 69 66 20 28 21 6d 65 73  ) {.....if (!mes
0870: 73 61 67 65 2d 3e 48 61 73 4b 65 79 28 22 63 65  sage->HasKey("ce
0880: 72 74 69 66 69 63 61 74 65 22 29 29 20 7b 0a 09  rtificate")) {..
0890: 09 09 09 09 72 65 70 6c 79 2d 3e 53 65 74 28 22  ....reply->Set("
08a0: 73 74 61 74 75 73 22 2c 20 22 65 72 72 6f 72 22  status", "error"
08b0: 29 3b 0a 09 09 09 09 09 72 65 70 6c 79 2d 3e 53  );......reply->S
08c0: 65 74 28 22 65 72 72 6f 72 22 2c 20 22 43 65 72  et("error", "Cer
08d0: 74 69 66 69 63 61 74 65 20 6e 6f 74 20 73 75 70  tificate not sup
08e0: 70 6c 69 65 64 22 29 3b 0a 09 09 09 09 7d 20 65  plied");.....} e
08f0: 6c 73 65 20 7b 0a 09 09 09 09 09 69 6e 63 6f 6d  lse {......incom
0900: 69 6e 67 43 65 72 74 69 66 69 63 61 74 65 43 6f  ingCertificateCo
0910: 6e 74 65 6e 74 73 20 3d 20 6d 65 73 73 61 67 65  ntents = message
0920: 2d 3e 47 65 74 28 22 63 65 72 74 69 66 69 63 61  ->Get("certifica
0930: 74 65 22 29 3b 0a 0a 09 09 09 09 09 72 65 70 6c  te");.......repl
0940: 79 2d 3e 53 65 74 28 22 73 74 61 74 75 73 22 2c  y->Set("status",
0950: 20 22 65 72 72 6f 72 22 29 3b 0a 09 09 09 09 09   "error");......
0960: 72 65 70 6c 79 2d 3e 53 65 74 28 22 65 72 72 6f  reply->Set("erro
0970: 72 22 2c 20 22 54 68 69 73 20 66 75 6e 63 74 69  r", "This functi
0980: 6f 6e 20 69 73 20 6e 6f 74 20 79 65 74 20 69 6d  on is not yet im
0990: 70 6c 65 6d 65 6e 74 65 64 22 29 3b 0a 09 09 09  plemented");....
09a0: 09 7d 0a 09 09 09 7d 20 65 6c 73 65 20 7b 0a 09  .}....} else {..
09b0: 09 09 09 72 65 70 6c 79 2d 3e 53 65 74 28 22 73  ...reply->Set("s
09c0: 74 61 74 75 73 22 2c 20 22 65 72 72 6f 72 22 29  tatus", "error")
09d0: 3b 0a 09 09 09 09 72 65 70 6c 79 2d 3e 53 65 74  ;.....reply->Set
09e0: 28 22 65 72 72 6f 72 22 2c 20 22 49 6e 76 61 6c  ("error", "Inval
09f0: 69 64 20 63 6f 6d 6d 61 6e 64 22 29 3b 0a 09 09  id command");...
0a00: 09 7d 0a 0a 09 09 09 2f 2a 0a 09 09 09 20 2a 20  .}...../*.... * 
0a10: 49 66 20 61 20 6d 65 73 73 61 67 65 20 49 44 20  If a message ID 
0a20: 77 61 73 20 73 65 6e 74 20 69 6e 20 74 68 65 20  was sent in the 
0a30: 72 65 71 75 65 73 74 2c 20 69 6e 63 6c 75 64 65  request, include
0a40: 20 69 74 20 69 6e 20 74 68 65 20 72 65 70 6c 79   it in the reply
0a50: 0a 09 09 09 20 2a 2f 0a 09 09 09 69 66 20 28 6d  .... */....if (m
0a60: 65 73 73 61 67 65 2d 3e 48 61 73 4b 65 79 28 22  essage->HasKey("
0a70: 69 64 22 29 29 20 7b 0a 09 09 09 09 72 65 70 6c  id")) {.....repl
0a80: 79 2d 3e 53 65 74 28 22 69 64 22 2c 20 6d 65 73  y->Set("id", mes
0a90: 73 61 67 65 2d 3e 47 65 74 28 22 69 64 22 29 29  sage->Get("id"))
0aa0: 3b 0a 09 09 09 7d 0a 0a 09 09 09 2f 2a 0a 09 09  ;....}...../*...
0ab0: 09 20 2a 20 49 6e 64 69 63 61 74 65 20 77 68 6f  . * Indicate who
0ac0: 20 6f 75 72 20 6d 65 73 73 61 67 65 20 69 73 20   our message is 
0ad0: 66 6f 72 0a 09 09 09 20 2a 2f 0a 09 09 09 72 65  for.... */....re
0ae0: 70 6c 79 2d 3e 53 65 74 28 22 74 61 72 67 65 74  ply->Set("target
0af0: 22 2c 20 22 63 61 63 6b 65 79 22 29 3b 0a 09 09  ", "cackey");...
0b00: 09 72 65 70 6c 79 2d 3e 53 65 74 28 22 63 6f 6d  .reply->Set("com
0b10: 6d 61 6e 64 22 2c 20 63 6f 6d 6d 61 6e 64 29 3b  mand", command);
0b20: 0a 0a 09 09 09 2f 2a 0a 09 09 09 20 2a 20 53 65  ...../*.... * Se
0b30: 6e 64 20 74 68 65 20 72 65 70 6c 79 20 62 61 63  nd the reply bac
0b40: 6b 20 74 6f 20 74 68 65 20 72 65 71 75 65 73 74  k to the request
0b50: 6f 72 2c 20 68 6f 70 65 66 75 6c 6c 79 20 74 68  or, hopefully th
0b60: 65 79 20 61 72 65 20 77 61 69 74 69 6e 67 20 66  ey are waiting f
0b70: 6f 72 20 74 68 69 73 20 6d 65 73 73 61 67 65 0a  or this message.
0b80: 09 09 09 20 2a 2f 0a 09 09 09 50 6f 73 74 4d 65  ... */....PostMe
0b90: 73 73 61 67 65 28 2a 72 65 70 6c 79 29 3b 0a 0a  ssage(*reply);..
0ba0: 09 09 09 64 65 6c 65 74 65 20 72 65 70 6c 79 3b  ...delete reply;
0bb0: 0a 0a 09 09 09 64 65 6c 65 74 65 20 6d 65 73 73  .....delete mess
0bc0: 61 67 65 3b 0a 0a 09 09 09 72 65 74 75 72 6e 3b  age;.....return;
0bd0: 0a 09 09 7d 0a 0a 09 09 76 69 72 74 75 61 6c 20  ...}....virtual 
0be0: 76 6f 69 64 20 48 61 6e 64 6c 65 4d 65 73 73 61  void HandleMessa
0bf0: 67 65 28 63 6f 6e 73 74 20 70 70 3a 3a 56 61 72  ge(const pp::Var
0c00: 26 20 6d 65 73 73 61 67 65 50 6c 61 69 6e 29 20  & messagePlain) 
0c10: 7b 0a 09 09 09 70 70 3a 3a 56 61 72 44 69 63 74  {....pp::VarDict
0c20: 69 6f 6e 61 72 79 20 2a 6d 65 73 73 61 67 65 3b  ionary *message;
0c30: 0a 09 09 09 70 70 3a 3a 56 61 72 20 74 61 72 67  ....pp::Var targ
0c40: 65 74 3b 0a 0a 09 09 09 2f 2a 0a 09 09 09 20 2a  et;...../*.... *
0c50: 20 54 68 65 20 69 6e 63 6f 6d 69 6e 67 20 6d 65   The incoming me
0c60: 73 73 61 67 65 20 6d 75 73 74 20 62 65 20 61 20  ssage must be a 
0c70: 64 69 63 74 69 6f 6e 61 72 79 0a 09 09 09 20 2a  dictionary.... *
0c80: 2f 0a 09 09 09 69 66 20 28 21 6d 65 73 73 61 67  /....if (!messag
0c90: 65 50 6c 61 69 6e 2e 69 73 5f 64 69 63 74 69 6f  ePlain.is_dictio
0ca0: 6e 61 72 79 28 29 29 20 7b 0a 09 09 09 09 70 63  nary()) {.....pc
0cb0: 73 63 4e 61 43 6c 48 61 6e 64 6c 65 4d 65 73 73  scNaClHandleMess
0cc0: 61 67 65 28 6d 65 73 73 61 67 65 50 6c 61 69 6e  age(messagePlain
0cd0: 29 3b 0a 0a 09 09 09 09 72 65 74 75 72 6e 3b 0a  );......return;.
0ce0: 09 09 09 7d 0a 0a 09 09 09 2f 2a 0a 09 09 09 20  ...}...../*.... 
0cf0: 2a 20 50 72 6f 63 65 73 73 20 74 68 65 20 61 70  * Process the ap
0d00: 70 72 6f 70 72 69 61 74 65 20 63 6f 6d 6d 61 6e  propriate comman
0d10: 64 20 66 72 6f 6d 20 74 68 65 20 69 6e 63 6f 6d  d from the incom
0d20: 69 6e 67 20 6d 65 73 73 61 67 65 0a 09 09 09 20  ing message.... 
0d30: 2a 2f 0a 09 09 09 6d 65 73 73 61 67 65 20 3d 20  */....message = 
0d40: 6e 65 77 20 70 70 3a 3a 56 61 72 44 69 63 74 69  new pp::VarDicti
0d50: 6f 6e 61 72 79 28 6d 65 73 73 61 67 65 50 6c 61  onary(messagePla
0d60: 69 6e 29 3b 0a 0a 09 09 09 2f 2a 0a 09 09 09 20  in);...../*.... 
0d70: 2a 20 56 65 72 69 66 79 20 74 68 61 74 20 74 68  * Verify that th
0d80: 69 73 20 6d 65 73 73 61 67 65 20 69 73 20 64 65  is message is de
0d90: 73 74 69 6e 65 64 20 66 6f 72 20 75 73 0a 09 09  stined for us...
0da0: 09 20 2a 2f 0a 09 09 09 69 66 20 28 21 6d 65 73  . */....if (!mes
0db0: 73 61 67 65 2d 3e 48 61 73 4b 65 79 28 22 74 61  sage->HasKey("ta
0dc0: 72 67 65 74 22 29 29 20 7b 0a 09 09 09 09 64 65  rget")) {.....de
0dd0: 6c 65 74 65 20 6d 65 73 73 61 67 65 3b 0a 0a 09  lete message;...
0de0: 09 09 09 2f 2a 20 57 65 20 64 6f 6e 27 74 20 68  .../* We don't h
0df0: 61 6e 64 6c 65 20 74 68 69 73 20 6d 65 73 73 61  andle this messa
0e00: 67 65 2c 20 73 65 65 20 69 66 20 50 43 53 43 2d  ge, see if PCSC-
0e10: 4e 61 43 6c 20 64 6f 65 73 20 2a 2f 0a 09 09 09  NaCl does */....
0e20: 09 70 63 73 63 4e 61 43 6c 48 61 6e 64 6c 65 4d  .pcscNaClHandleM
0e30: 65 73 73 61 67 65 28 6d 65 73 73 61 67 65 50 6c  essage(messagePl
0e40: 61 69 6e 29 3b 0a 0a 09 09 09 09 72 65 74 75 72  ain);......retur
0e50: 6e 3b 0a 09 09 09 7d 0a 0a 09 09 09 74 61 72 67  n;....}.....targ
0e60: 65 74 20 3d 20 6d 65 73 73 61 67 65 2d 3e 47 65  et = message->Ge
0e70: 74 28 22 74 61 72 67 65 74 22 29 3b 0a 09 09 09  t("target");....
0e80: 69 66 20 28 74 61 72 67 65 74 2e 41 73 53 74 72  if (target.AsStr
0e90: 69 6e 67 28 29 20 21 3d 20 22 63 61 63 6b 65 79  ing() != "cackey
0ea0: 22 29 20 7b 0a 09 09 09 09 64 65 6c 65 74 65 20  ") {.....delete 
0eb0: 6d 65 73 73 61 67 65 3b 0a 0a 09 09 09 09 2f 2a  message;....../*
0ec0: 20 57 65 20 64 6f 6e 27 74 20 68 61 6e 64 6c 65   We don't handle
0ed0: 20 74 68 69 73 20 6d 65 73 73 61 67 65 2c 20 73   this message, s
0ee0: 65 65 20 69 66 20 50 43 53 43 2d 4e 61 43 6c 20  ee if PCSC-NaCl 
0ef0: 64 6f 65 73 20 2a 2f 0a 09 09 09 09 70 63 73 63  does */.....pcsc
0f00: 4e 61 43 6c 48 61 6e 64 6c 65 4d 65 73 73 61 67  NaClHandleMessag
0f10: 65 28 6d 65 73 73 61 67 65 50 6c 61 69 6e 29 3b  e(messagePlain);
0f20: 0a 0a 09 09 09 09 72 65 74 75 72 6e 3b 0a 09 09  ......return;...
0f30: 09 7d 0a 0a 09 09 09 2f 2a 0a 09 09 09 20 2a 20  .}...../*.... * 
0f40: 44 65 74 65 72 6d 69 6e 65 20 77 68 61 74 20 77  Determine what w
0f50: 65 20 61 72 65 20 62 65 69 6e 67 20 61 73 6b 65  e are being aske
0f60: 64 20 74 6f 20 64 6f 0a 09 09 09 20 2a 2f 0a 09  d to do.... */..
0f70: 09 09 69 66 20 28 21 6d 65 73 73 61 67 65 2d 3e  ..if (!message->
0f80: 48 61 73 4b 65 79 28 22 63 6f 6d 6d 61 6e 64 22  HasKey("command"
0f90: 29 29 20 7b 0a 09 09 09 09 64 65 6c 65 74 65 20  )) {.....delete 
0fa0: 6d 65 73 73 61 67 65 3b 0a 0a 09 09 09 09 2f 2a  message;....../*
0fb0: 20 57 65 20 64 6f 6e 27 74 20 68 61 6e 64 6c 65   We don't handle
0fc0: 20 74 68 69 73 20 6d 65 73 73 61 67 65 2c 20 73   this message, s
0fd0: 65 65 20 69 66 20 50 43 53 43 2d 4e 61 43 6c 20  ee if PCSC-NaCl 
0fe0: 64 6f 65 73 20 2a 2f 0a 09 09 09 09 70 63 73 63  does */.....pcsc
0ff0: 4e 61 43 6c 48 61 6e 64 6c 65 4d 65 73 73 61 67  NaClHandleMessag
1000: 65 28 6d 65 73 73 61 67 65 50 6c 61 69 6e 29 3b  e(messagePlain);
1010: 0a 0a 09 09 09 09 72 65 74 75 72 6e 3b 0a 09 09  ......return;...
1020: 09 7d 0a 0a 09 09 09 2f 2a 0a 09 09 09 20 2a 20  .}...../*.... * 
1030: 50 72 6f 63 65 73 73 20 74 68 65 20 72 65 71 75  Process the requ
1040: 65 73 74 20 69 6e 20 61 6e 6f 74 68 65 72 20 74  est in another t
1050: 68 72 65 61 64 0a 09 09 09 20 2a 2f 0a 09 09 09  hread.... */....
1060: 73 74 64 3a 3a 74 68 72 65 61 64 28 26 43 41 43  std::thread(&CAC
1070: 4b 65 79 49 6e 73 74 61 6e 63 65 3a 3a 48 61 6e  KeyInstance::Han
1080: 64 6c 65 4d 65 73 73 61 67 65 54 68 72 65 61 64  dleMessageThread
1090: 2c 20 74 68 69 73 2c 20 6d 65 73 73 61 67 65 29  , this, message)
10a0: 2e 64 65 74 61 63 68 28 29 3b 0a 0a 09 09 09 72  .detach();.....r
10b0: 65 74 75 72 6e 3b 0a 09 09 7d 0a 7d 3b 0a 0a 63  eturn;...}.};..c
10c0: 6c 61 73 73 20 43 41 43 4b 65 79 4d 6f 64 75 6c  lass CACKeyModul
10d0: 65 20 3a 20 70 75 62 6c 69 63 20 70 70 3a 3a 4d  e : public pp::M
10e0: 6f 64 75 6c 65 20 7b 0a 09 70 75 62 6c 69 63 3a  odule {..public:
10f0: 0a 09 09 43 41 43 4b 65 79 4d 6f 64 75 6c 65 28  ...CACKeyModule(
1100: 29 20 3a 20 70 70 3a 3a 4d 6f 64 75 6c 65 28 29  ) : pp::Module()
1110: 20 7b 7d 0a 09 09 76 69 72 74 75 61 6c 20 7e 43   {}...virtual ~C
1120: 41 43 4b 65 79 4d 6f 64 75 6c 65 28 29 20 7b 7d  ACKeyModule() {}
1130: 0a 0a 09 09 76 69 72 74 75 61 6c 20 70 70 3a 3a  ....virtual pp::
1140: 49 6e 73 74 61 6e 63 65 20 2a 43 72 65 61 74 65  Instance *Create
1150: 49 6e 73 74 61 6e 63 65 28 50 50 5f 49 6e 73 74  Instance(PP_Inst
1160: 61 6e 63 65 20 69 6e 73 74 61 6e 63 65 29 20 7b  ance instance) {
1170: 0a 09 09 09 72 65 74 75 72 6e 28 6e 65 77 20 43  ....return(new C
1180: 41 43 4b 65 79 49 6e 73 74 61 6e 63 65 28 69 6e  ACKeyInstance(in
1190: 73 74 61 6e 63 65 2c 20 63 6f 72 65 28 29 29 29  stance, core()))
11a0: 3b 0a 09 09 7d 0a 7d 3b 0a 0a 6e 61 6d 65 73 70  ;...}.};..namesp
11b0: 61 63 65 20 70 70 20 7b 0a 09 4d 6f 64 75 6c 65  ace pp {..Module
11c0: 20 2a 43 72 65 61 74 65 4d 6f 64 75 6c 65 28 29   *CreateModule()
11d0: 20 7b 0a 09 09 72 65 74 75 72 6e 28 6e 65 77 20   {...return(new 
11e0: 43 41 43 4b 65 79 4d 6f 64 75 6c 65 28 29 29 3b  CACKeyModule());
11f0: 0a 09 7d 0a 7d 0a                                ..}.}.