Diff

Differences From Artifact [3317412933]:

To Artifact [039bbe7def]:


    26     26   		explicit CACKeyInstance(PP_Instance instance, pp::Core *core) : pp::Instance(instance) {
    27     27   			std::thread(&CACKeyInstance::pcscNaClInitWrapper, this, core).detach();
    28     28   		}
    29     29   
    30     30   		virtual ~CACKeyInstance() {}
    31     31   
    32     32   		virtual void HandleMessageThread(pp::VarDictionary *message) {
    33         -			int numCertificates, i;
    34         -			struct cackey_certificate *certificates;
           33  +			cackey_chrome_returnType signRet;
           34  +			char *pinPrompt;
           35  +			const char *pin;
           36  +			unsigned char buffer[8192];
           37  +			struct cackey_certificate *certificates, incomingCertificateCACKey;
    35     38   			pp::VarDictionary *reply;
    36     39   			pp::VarArray certificatesPPArray;
    37         -			pp::VarArrayBuffer *certificateContents;
    38         -			pp::Var command, incomingCertificateContents;
           40  +			pp::VarArrayBuffer *certificateContents, *incomingCertificateContents, *incomingData, *outgoingData;
           41  +			pp::Var command;
           42  +			const pp::Var *messageAsVar = NULL, *outgoingDataAsVar = NULL;
           43  +			int numCertificates, i;
           44  +			unsigned long outgoingDataLength;
    39     45   
    40     46   			/*
    41     47   			 * Extract the command
    42     48   			 */
    43     49   			command = message->Get("command");
    44     50   
    45     51   			/*
................................................................................
    68     74   
    69     75   				reply->Set("status", "success");
    70     76   				reply->Set("certificates", certificatesPPArray);
    71     77   			} else if (command.AsString() == "sign") {
    72     78   				if (!message->HasKey("certificate")) {
    73     79   					reply->Set("status", "error");
    74     80   					reply->Set("error", "Certificate not supplied");
    75         -				} else {
    76         -					incomingCertificateContents = message->Get("certificate");
    77         -
           81  +				} else if (!message->HasKey("data")) {
    78     82   					reply->Set("status", "error");
    79         -					reply->Set("error", "This function is not yet implemented");
           83  +					reply->Set("error", "Data not supplied");
           84  +				} else {
           85  +					incomingCertificateContents = new pp::VarArrayBuffer(message->Get("certificate"));
           86  +					incomingData = new pp::VarArrayBuffer(message->Get("data"));
           87  +
           88  +					if (message->HasKey("pin")) {
           89  +						pin = message->Get("pin").AsString().c_str();
           90  +					} else {
           91  +						pin = NULL;
           92  +					}
           93  +
           94  +					incomingCertificateCACKey.certificate = incomingCertificateContents->Map();					
           95  +					incomingCertificateCACKey.certificate_len = incomingCertificateContents->ByteLength();					
           96  +
           97  +					outgoingDataLength = sizeof(buffer);
           98  +
           99  +					signRet = cackey_chrome_signMessage(&incomingCertificateCACKey,
          100  +						incomingData->Map(), incomingData->ByteLength(),
          101  +						buffer, &outgoingDataLength,
          102  +						&pinPrompt, pin
          103  +					);
          104  +
          105  +					incomingCertificateContents->Unmap();
          106  +					incomingData->Unmap();
          107  +
          108  +					delete incomingCertificateContents;
          109  +					delete incomingData;
          110  +
          111  +					switch (signRet) {
          112  +						case CACKEY_CHROME_OK:
          113  +							outgoingData = new pp::VarArrayBuffer(outgoingDataLength);
          114  +
          115  +							memcpy(outgoingData->Map(), buffer, outgoingDataLength);
          116  +
          117  +							outgoingData->Unmap();
          118  +
          119  +							outgoingDataAsVar = new pp::Var(outgoingData->pp_var());
          120  +
          121  +							delete outgoingData;
          122  +
          123  +							reply->Set("status", "success");
          124  +							reply->Set("signedData", outgoingDataAsVar);
          125  +
          126  +							delete outgoingDataAsVar;
          127  +
          128  +							break;
          129  +						case CACKEY_CHROME_ERROR:
          130  +							reply->Set("status", "error");
          131  +							reply->Set("error", "Unable to sign data");
          132  +							break;
          133  +						case CACKEY_CHROME_NEEDLOGIN:
          134  +						case CACKEY_CHROME_NEEDPROTECTEDLOGIN:
          135  +							messageAsVar = new pp::Var(message->pp_var());
          136  +
          137  +							reply->Set("status", "retry");
          138  +							reply->Set("originalrequest", messageAsVar);
          139  +
          140  +							delete messageAsVar;
          141  +
          142  +							break;
          143  +					}
    80    144   				}
    81    145   			} else {
    82    146   				reply->Set("status", "error");
    83    147   				reply->Set("error", "Invalid command");
    84    148   			}
    85    149   
    86    150   			/*