comparison cinst/mozilla.c @ 524:a097dd86cb4d

merged.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 29 Apr 2014 15:26:43 +0200
parents 48d7b956bd98
children f115da3645d5
comparison
equal deleted inserted replaced
523:ca583ffe728a 524:a097dd86cb4d
379 cn_str = x509_parse_subject(secitemp->data, secitemp->len, CERT_OID_CN); 379 cn_str = x509_parse_subject(secitemp->data, secitemp->len, CERT_OID_CN);
380 o_str = x509_parse_subject(secitemp->data, secitemp->len, CERT_OID_O); 380 o_str = x509_parse_subject(secitemp->data, secitemp->len, CERT_OID_O);
381 if (!cn_str || !o_str) 381 if (!cn_str || !o_str)
382 { 382 {
383 DEBUGPRINTF("FATAL: Could not parse certificate!"); 383 DEBUGPRINTF("FATAL: Could not parse certificate!");
384 DEBUGPRINTF("data len: %u \n", secitemp->len);
385 exit(ERR_INVALID_CERT); 384 exit(ERR_INVALID_CERT);
386 } 385 }
387 name_len = strlen(cn_str) + strlen(o_str) + 4; 386 name_len = strlen(cn_str) + strlen(o_str) + 4;
388 name = (char *)xmalloc(name_len); 387 name = (char *)xmalloc(name_len);
389 snprintf(name, name_len, "%s - %s", cn_str, o_str); 388 snprintf(name, name_len, "%s - %s", cn_str, o_str);
437 CERTCertificate *cert = NULL; 436 CERTCertificate *cert = NULL;
438 bool success = false; 437 bool success = false;
439 char *cert_name = nss_cert_name(dercert); 438 char *cert_name = nss_cert_name(dercert);
440 439
441 DEBUGPRINTF("INSTALLING cert: '%s' to: %s\n", cert_name, pdir); 440 DEBUGPRINTF("INSTALLING cert: '%s' to: %s\n", cert_name, pdir);
442 if (NSS_Initialize(pdir, "", "", "secmod.db", 0) == SECSuccess) 441 pk11slot = PK11_GetInternalKeySlot();
443 { 442 cert = CERT_DecodeCertFromPackage((char *)dercert->data,
444 pk11slot = PK11_GetInternalKeySlot(); 443 (int)dercert->len);
445 cert = CERT_DecodeCertFromPackage((char *)dercert->data, 444 trust = (CERTCertTrust *)xmalloc(sizeof(CERTCertTrust));
446 (int)dercert->len); 445 CERT_DecodeTrustString(trust, "C");
447 trust = (CERTCertTrust *)xmalloc(sizeof(CERTCertTrust)); 446 if ((PK11_ImportCert(pk11slot, cert, CK_INVALID_HANDLE,
448 CERT_DecodeTrustString(trust, "C"); 447 cert_name, PR_FALSE)
449 if ((PK11_ImportCert(pk11slot, cert, CK_INVALID_HANDLE, 448 == SECSuccess) &&
450 cert_name, PR_FALSE) 449 (CERT_ChangeCertTrust(CERT_GetDefaultCertDB(), cert, trust)
451 == SECSuccess) && 450 == SECSuccess))
452 (CERT_ChangeCertTrust(CERT_GetDefaultCertDB(), cert, trust) 451 {
453 == SECSuccess)) 452 success = true;
454 {
455 success = true;
456 }
457 else
458 {
459 DEBUGPRINTF("Failed to install certificate '%s' to '%s'!\n", cert_name, pdir);
460 }
461 CERT_DestroyCertificate (cert);
462 free(trust);
463 PK11_FreeSlot(pk11slot);
464 NSS_Shutdown();
465 } 453 }
466 else 454 else
467 { 455 {
468 DEBUGPRINTF("Could not open nss certificate store in %s!\n", pdir); 456 DEBUGPRINTF("Failed to install certificate '%s' to '%s'!\n", cert_name, pdir);
469 } 457 ERRORPRINTF("Error installing certificate err: %i\n", PORT_GetError());
458 }
459 CERT_DestroyCertificate (cert);
460 free(trust);
461 PK11_FreeSlot(pk11slot);
470 462
471 free(cert_name); 463 free(cert_name);
472 return success; 464 return success;
473 } 465 }
474 466
543 */ 535 */
544 bool 536 bool
545 apply_to_certs_and_profiles(bool fn(char *, SECItem *), 537 apply_to_certs_and_profiles(bool fn(char *, SECItem *),
546 seciteml_t **certs, char **pdirs) 538 seciteml_t **certs, char **pdirs)
547 { 539 {
548 SECItem *cert;
549 bool success = true; 540 bool success = true;
550 541
551 while ((cert = seciteml_pop(certs)) != NULL) 542 for (int i=0; pdirs[i] != NULL; i++)
552 { 543 {
553 for (int i=0; pdirs[i] != NULL; i++) 544 seciteml_t *iter = *certs;
554 { 545 if (NSS_Initialize(pdirs[i], "", "", "secmod.db", 0) != SECSuccess)
546 {
547 DEBUGPRINTF("Could not open nss certificate store in %s!\n", pdirs[i]);
548 continue;
549 }
550
551 while (iter != NULL && iter->item != NULL)
552 {
553 SECItem *cert = iter->item;
555 if (! (*fn)(pdirs[i], cert)) 554 if (! (*fn)(pdirs[i], cert))
556 success = false; 555 success = false;
557 } 556 iter = iter->next;
558 free(cert->data); 557 }
559 free(cert); 558 NSS_Shutdown();
560 } 559 }
561 560
562 return success; 561 return success;
563 } 562 }
564 563

http://wald.intevation.org/projects/trustbridge/