Diff

Differences From Artifact [3317412933]:

To Artifact [039bbe7def]:


26
27
28
29
30
31
32

33


34
35
36
37
38



39
40
41
42
43
44
45
		explicit CACKeyInstance(PP_Instance instance, pp::Core *core) : pp::Instance(instance) {
			std::thread(&CACKeyInstance::pcscNaClInitWrapper, this, core).detach();
		}

		virtual ~CACKeyInstance() {}

		virtual void HandleMessageThread(pp::VarDictionary *message) {

			int numCertificates, i;


			struct cackey_certificate *certificates;
			pp::VarDictionary *reply;
			pp::VarArray certificatesPPArray;
			pp::VarArrayBuffer *certificateContents;
			pp::Var command, incomingCertificateContents;




			/*
			 * Extract the command
			 */
			command = message->Get("command");

			/*







>
|
>
>
|


|
|
>
>
>







26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
		explicit CACKeyInstance(PP_Instance instance, pp::Core *core) : pp::Instance(instance) {
			std::thread(&CACKeyInstance::pcscNaClInitWrapper, this, core).detach();
		}

		virtual ~CACKeyInstance() {}

		virtual void HandleMessageThread(pp::VarDictionary *message) {
			cackey_chrome_returnType signRet;
			char *pinPrompt;
			const char *pin;
			unsigned char buffer[8192];
			struct cackey_certificate *certificates, incomingCertificateCACKey;
			pp::VarDictionary *reply;
			pp::VarArray certificatesPPArray;
			pp::VarArrayBuffer *certificateContents, *incomingCertificateContents, *incomingData, *outgoingData;
			pp::Var command;
			const pp::Var *messageAsVar = NULL, *outgoingDataAsVar = NULL;
			int numCertificates, i;
			unsigned long outgoingDataLength;

			/*
			 * Extract the command
			 */
			command = message->Get("command");

			/*
68
69
70
71
72
73
74



75




















76

77






















78
79












80
81
82
83
84
85
86

				reply->Set("status", "success");
				reply->Set("certificates", certificatesPPArray);
			} else if (command.AsString() == "sign") {
				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");
			}

			/*







>
>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
>
>
>
>
>
>
>
>
>
>
>
>







74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150

				reply->Set("status", "success");
				reply->Set("certificates", certificatesPPArray);
			} else if (command.AsString() == "sign") {
				if (!message->HasKey("certificate")) {
					reply->Set("status", "error");
					reply->Set("error", "Certificate not supplied");
				} else if (!message->HasKey("data")) {
					reply->Set("status", "error");
					reply->Set("error", "Data not supplied");
				} else {
					incomingCertificateContents = new pp::VarArrayBuffer(message->Get("certificate"));
					incomingData = new pp::VarArrayBuffer(message->Get("data"));

					if (message->HasKey("pin")) {
						pin = message->Get("pin").AsString().c_str();
					} else {
						pin = NULL;
					}

					incomingCertificateCACKey.certificate = incomingCertificateContents->Map();					
					incomingCertificateCACKey.certificate_len = incomingCertificateContents->ByteLength();					

					outgoingDataLength = sizeof(buffer);

					signRet = cackey_chrome_signMessage(&incomingCertificateCACKey,
						incomingData->Map(), incomingData->ByteLength(),
						buffer, &outgoingDataLength,
						&pinPrompt, pin
					);

					incomingCertificateContents->Unmap();
					incomingData->Unmap();

					delete incomingCertificateContents;
					delete incomingData;

					switch (signRet) {
						case CACKEY_CHROME_OK:
							outgoingData = new pp::VarArrayBuffer(outgoingDataLength);

							memcpy(outgoingData->Map(), buffer, outgoingDataLength);

							outgoingData->Unmap();

							outgoingDataAsVar = new pp::Var(outgoingData->pp_var());

							delete outgoingData;

							reply->Set("status", "success");
							reply->Set("signedData", outgoingDataAsVar);

							delete outgoingDataAsVar;

							break;
						case CACKEY_CHROME_ERROR:
							reply->Set("status", "error");
							reply->Set("error", "Unable to sign data");
							break;
						case CACKEY_CHROME_NEEDLOGIN:
						case CACKEY_CHROME_NEEDPROTECTEDLOGIN:
							messageAsVar = new pp::Var(message->pp_var());

							reply->Set("status", "retry");
							reply->Set("originalrequest", messageAsVar);

							delete messageAsVar;

							break;
					}
				}
			} else {
				reply->Set("status", "error");
				reply->Set("error", "Invalid command");
			}

			/*