Overview
| Comment: | ChromeOS: Started working on providing working callbacks for calls into NaCl |
|---|---|
| Downloads: | Tarball | ZIP archive | SQL archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA1: |
b356505dc257c15531d29c1fafbd2ced |
| User & Date: | rkeene on 2016-02-12 05:10:48 |
| Other Links: | manifest | tags |
Context
|
2016-02-12
| ||
| 05:26 | ChromeOS: Restructed the JavaScript portion of CACKey check-in: 2900ebd791 user: rkeene tags: trunk | |
| 05:10 | ChromeOS: Started working on providing working callbacks for calls into NaCl check-in: b356505dc2 user: rkeene tags: trunk | |
| 05:10 | ChromeOS: Updated to include the command we are replying to in the reply check-in: e3aaea539b user: rkeene tags: trunk | |
Changes
Modified build/chrome/cackey.js from [0b72bd3c23] to [11ec47cfa2].
| ︙ | ︙ | |||
296 297 298 299 300 301 302 |
function onCertificatesRejected(rejectedCerts) {
// If certificates were rejected by the API, log an error, for example.
console.error(rejectedCerts.length + ' certificates were rejected.');
return;
}
| < | < < | < < < < | < < < < < < < < < < < < < < | < < | < < < < < < < < < | < < | < < | < > | | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > < | > | > < | | > > > | > | > | > > > | | 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
function onCertificatesRejected(rejectedCerts) {
// If certificates were rejected by the API, log an error, for example.
console.error(rejectedCerts.length + ' certificates were rejected.');
return;
}
/*
* Handle for the CACKey NaCl Target
*/
var cackeyHandle = null;
var cackeyOutstandingCallback = null
var cackeyOutstandingCallbackId = -1;
function cackeyMessageIncomingListCertificates(message, chromeCallback) {
var idx;
var certificates = [];
for (idx = 0; idx < message.certificates.length; idx++) {
certificates.push(
{
certificate: message.certificates[idx],
supportedHashes: ['SHA1', 'SHA256']
}
);
}
chromeCallback(certificates,
function(rejectedCerts) {
if (chrome.runtime.lastError) {
return;
}
if (rejectedCerts.length !== 0) {
onCertificatesRejected(rejectedCerts);
}
return;
}
);
}
function cackeyMessageIncomingSignMessage(message, chromeCallback) {
var payload;
payload = message.signedData;
chromeCallback(payload);
}
function cackeyMessageIncoming(messageEvent) {
var nextFunction = null;
if (messageEvent.data.target != "cackey") {
return;
}
console.log("START MESSAGE");
console.log(messageEvent.data);
console.log("END MESSAGE");
if (messageEvent.data.id != cackeyOutstandingCallbackId || cackeyOutstandingCallback == null) {
console.log("[cackey] Discarding outdated message");
return;
}
if (messageEvent.data.status != "success") {
console.error("[cackey] Failed to execute command '" + messageEvent.data.command + "': " + messageEvent.data.error);
cackeyOutstandingCallback();
} else {
switch (messageEvent.data.command) {
case "listcertificates":
nextFunction = cackeyMessageIncomingListCertificates;
break;
case "sign":
nextFunction = cackeyMessageIncomingSignMessage;
break;
}
}
if (nextFunction != null) {
nextFunction(messageEvent.data, cackeyOutstandingCallback);
}
cackeyOutstandingCallback = null;
return;
}
/*
* Finish performing initialization that must wait until we have loaded the CACKey module
*/
function cackeyInitLoaded(messageEvent) {
console.log("[cackey] Loaded CACKey PNaCl Module");
/* Register listeners with Chrome */
if (chrome.certificateProvider) {
chrome.certificateProvider.onCertificatesRequested.addListener(cackeyListCertificates);
chrome.certificateProvider.onSignDigestRequested.addListener(cackeySignMessage);
}
return;
}
function cackeyInit() {
var elementEmbed;
/* Log that we are operational */
console.log("[cackey] cackeyInit(): Called.");
/* Verify that we can register callbacks */
if (!chrome.certificateProvider) {
if (!GoogleSmartCard.IS_DEBUG_BUILD) {
console.error("[cackey] This extension only works on ChromeOS!");
return;
} else {
console.log("[cackey] This extension only works on ChromeOS, but you appear to be debugging it -- trying anyway.");
}
}
if (cackeyHandle != null) {
console.log("[cackey] cackeyInit(): Already initialized. Returning.");
return;
}
elementEmbed = document.createElement('embed');
elementEmbed.type = "application/x-pnacl";
elementEmbed.width = 0;
elementEmbed.height = 0;
elementEmbed.src = "cackey.nmf";
elementEmbed.id = "cackeyModule";
elementEmbed.addEventListener('error', function(messageEvent) { console.error("Error loading CACKey PNaCl Module: " + messageEvent.data); }, true);
elementEmbed.addEventListener('load', cackeyInitLoaded, true);
elementEmbed.addEventListener('message', cackeyMessageIncoming, true);
cackeyHandle = elementEmbed;
/*
* Start the Google PCSC Interface
*/
new GoogleSmartCard.PcscNacl(cackeyHandle);
document.body.appendChild(cackeyHandle)
console.log("[cackey] cackeyInit(): Completed. Returning.");
}
function cackeyListCertificates(chromeCallback) {
var callbackId;
console.log("[cackey] Asked to provide a list of certificates -- throwing that request over to the NaCl side... ");
callbackId = cackeyOutstandingCallbackId + 1;
cackeyHandle.postMessage(
{
'target': "cackey",
'command': "listcertificates",
'id': callbackId
}
);
cackeyOutstandingCallbackId = callbackId;
cackeyOutstandingCallback = chromeCallback;
console.log("[cackey] Thrown.");
return;
}
function cackeySignMessage(signRequest, chromeCallback) {
var callbackId;
console.log("[cackey] Asked to sign a message -- throwing that request over to the NaCl side... ");
callbackId = cackeyOutstandingCallbackId + 1;
cackeyHandle.postMessage(
{
'target': "cackey",
'command': "sign",
'id': callbackId,
'certificate': signRequest.certificate,
'data': signRequest.digest /* XXX:TODO: This needs to be prefixed based on the signRequest.hash */
}
);
cackeyOutstandingCallbackId = callbackId;
cackeyOutstandingCallback = chromeCallback;
console.log("[cackey] Thrown.");
return;
}
/* Initialize CACKey */
cackeyInit();
|