Skip to content

Commit

Permalink
Bug 1334976, use a new attribute in the builtins root CA list, to dis…
Browse files Browse the repository at this point in the history
…tinguish between Mozilla policy CAs and other CAs, code changes, r=rrelyea
  • Loading branch information
kaie committed Feb 9, 2017
1 parent 93ac86e commit 22ffa92
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 1 deletion.
28 changes: 28 additions & 0 deletions cmd/addbuiltin/addbuiltin.c
Expand Up @@ -31,6 +31,29 @@ dumpbytes(unsigned char *buf, int len)
printf("\n");
}

int
hasPositiveTrust(unsigned int trust)
{
if (trust & CERTDB_TRUSTED) {
if (trust & CERTDB_TRUSTED_CA) {
return PR_TRUE;
} else {
return PR_FALSE;
}
} else {
if (trust & CERTDB_TRUSTED_CA) {
return PR_TRUE;
} else if (trust & CERTDB_VALID_CA) {
return PR_TRUE;
} else if (trust & CERTDB_TERMINAL_RECORD) {
return PR_FALSE;
} else {
return PR_FALSE;
}
}
return PR_FALSE;
}

char *
getTrustString(unsigned int trust)
{
Expand Down Expand Up @@ -202,6 +225,11 @@ ConvertCertificate(SECItem *sdder, char *nickname, CERTCertTrust *trust,
printf("CKA_VALUE MULTILINE_OCTAL\n");
dumpbytes(sdder->data, sdder->len);
printf("END\n");
if (hasPositiveTrust(trust->sslFlags) ||
hasPositiveTrust(trust->emailFlags) ||
hasPositiveTrust(trust->objectSigningFlags)) {
printf("CKA_NSS_MOZILLA_CA_POLICY CK_BBOOL CK_TRUE\n");
}
}

if ((trust->sslFlags | trust->emailFlags | trust->objectSigningFlags) ==
Expand Down
32 changes: 31 additions & 1 deletion cmd/lib/secutil.c
Expand Up @@ -32,7 +32,7 @@
#include "certt.h"
#include "certdb.h"

/* #include "secmod.h" */
#include "secmod.h"
#include "pk11func.h"
#include "secoid.h"

Expand Down Expand Up @@ -3229,6 +3229,8 @@ SEC_PrintCertificateAndTrust(CERTCertificate *cert,
SECStatus rv;
SECItem data;
CERTCertTrust certTrust;
PK11SlotList *slotList;
const char *moz_policy_ca_info = NULL;

data.data = cert->derCert.data;
data.len = cert->derCert.len;
Expand All @@ -3238,6 +3240,34 @@ SEC_PrintCertificateAndTrust(CERTCertificate *cert,
if (rv) {
return (SECFailure);
}

slotList = PK11_GetAllSlotsForCert(cert, NULL);
if (slotList) {
PK11SlotListElement *se = PK11_GetFirstSafe(slotList);
for ( ; se; se = PK11_GetNextSafe(slotList, se, PR_FALSE)) {
CK_OBJECT_HANDLE handle = PK11_FindCertInSlot(se->slot, cert, NULL);
if (handle != CK_INVALID_HANDLE) {
PORT_SetError(0);
if (PK11_HasAttributeSet(se->slot, handle,
CKA_NSS_MOZILLA_CA_POLICY, PR_FALSE)) {
moz_policy_ca_info = "true (attribute present)";
} else {
if (PORT_GetError() != 0) {
moz_policy_ca_info = "false (attribute missing)";
} else {
moz_policy_ca_info = "false (attribute present)";
}
}
}
}
PK11_FreeSlotList(slotList);
}

if (moz_policy_ca_info) {
SECU_Indent(stdout, 1);
printf("Mozilla-CA-Policy: %s\n", moz_policy_ca_info);
}

if (trust) {
SECU_PrintTrustFlags(stdout, trust,
"Certificate Trust Flags", 1);
Expand Down
6 changes: 6 additions & 0 deletions lib/nss/nss.def
Expand Up @@ -1097,3 +1097,9 @@ PK11_VerifyWithMechanism;
;+ local:
;+ *;
;+};
;+NSS_3.30 { # NSS 3.30 release
;+ global:
PK11_HasAttributeSet;
;+ local:
;+ *;
;+};
2 changes: 2 additions & 0 deletions lib/util/pkcs11n.h
Expand Up @@ -93,6 +93,8 @@
#define CKA_NSS_JPAKE_X2 (CKA_NSS + 32)
#define CKA_NSS_JPAKE_X2S (CKA_NSS + 33)

#define CKA_NSS_MOZILLA_CA_POLICY (CKA_NSS + 34)

/*
* Trust attributes:
*
Expand Down

0 comments on commit 22ffa92

Please sign in to comment.