Index: build/chrome/cackey-chrome-init.cc ================================================================== --- build/chrome/cackey-chrome-init.cc +++ build/chrome/cackey-chrome-init.cc @@ -10,23 +10,17 @@ #include #include #include #include -#include - #include "pcsc-nacl.h" #include "cackey-chrome.h" class CACKeyInstance : public pp::Instance { private: void pcscNaClInitWrapper(pp::Core *core) { - fprintf(stderr, "Calling pcscNaClInit(%p, %p)\n", this, core); - pcscNaClInit(this, core); - - fprintf(stderr, "pcscNaClInit terminated\n"); } public: explicit CACKeyInstance(PP_Instance instance, pp::Core *core) : pp::Instance(instance) { std::thread(&CACKeyInstance::pcscNaClInitWrapper, this, core).detach(); } @@ -37,25 +31,25 @@ int numCertificates, i; struct cackey_certificate *certificates; pp::VarDictionary *reply; pp::VarArray certificatesPPArray; pp::VarArrayBuffer *certificateContents; - pp::Var command; + pp::Var command, incomingCertificateContents; /* * Extract the command */ command = message->Get("command"); /* * Do the thing we are being asked to do */ + reply = new pp::VarDictionary(); + if (command.AsString() == "listcertificates") { numCertificates = cackey_chrome_listCertificates(&certificates); - reply = new pp::VarDictionary(); - certificatesPPArray.SetLength(numCertificates); for (i = 0; i < numCertificates; i++) { certificateContents = new pp::VarArrayBuffer(certificates[i].certificate_len); @@ -62,21 +56,29 @@ memcpy(certificateContents->Map(), certificates[i].certificate, certificates[i].certificate_len); certificateContents->Unmap(); certificatesPPArray.Set(i, *certificateContents); + + delete certificateContents; } + + cackey_chrome_freeCertificates(certificates, numCertificates); reply->Set("status", "success"); reply->Set("certificates", certificatesPPArray); } else if (command.AsString() == "sign") { - reply = new pp::VarDictionary(); - - reply->Set("status", "success"); - } else { - reply = new pp::VarDictionary(); + if (!message->HasKey("certificate")) { + reply->Set("status", "error"); + reply->Set("error", "Certificate not supplied"); + } else { + incomingCertificateContents = message->Get("certificate"); + reply->Set("status", "error"); + reply->Set("error", "This function is not yet implemented"); + } + } else { reply->Set("status", "error"); reply->Set("error", "Invalid command"); } /* @@ -88,10 +90,12 @@ /* * Send the reply back to the requestor, hopefully they are waiting for this message */ PostMessage(*reply); + + delete reply; delete message; return; }