Chromium Code Reviews| Index: net/base/cert_database_nss.cc |
| diff --git a/net/base/cert_database_nss.cc b/net/base/cert_database_nss.cc |
| index e198e3504be82298c9b3354b0ae08e81be425a1f..4c112126063ae870bbd0eb1d1287948b4f32ca4f 100644 |
| --- a/net/base/cert_database_nss.cc |
| +++ b/net/base/cert_database_nss.cc |
| @@ -21,6 +21,12 @@ |
| #include "net/third_party/mozilla_security_manager/nsNSSCertTrust.h" |
| #include "net/third_party/mozilla_security_manager/nsPKCS12Blob.h" |
| +// In NSS 3.13, CERTDB_VALID_PEER was renamed CERTDB_TERMINAL_RECORD. So we use |
| +// the new name of the macro. |
| +#if !defined(CERTDB_TERMINAL_RECORD) |
| +#define CERTDB_TERMINAL_RECORD CERTDB_VALID_PEER |
| +#endif |
| + |
| // PSM = Mozilla's Personal Security Manager. |
| namespace psm = mozilla_security_manager; |
| @@ -236,6 +242,42 @@ CertDatabase::TrustBits CertDatabase::GetCertTrust(const X509Certificate* cert, |
| } |
| } |
| +bool CertDatabase::IsUntrusted(const X509Certificate* cert) const { |
| + CERTCertTrust nsstrust; |
|
wtc
2011/09/21 22:40:43
The CERTCertTrust structure contains three trust r
|
| + SECStatus rv = CERT_GetCertTrust(cert->os_cert_handle(), &nsstrust); |
| + if (rv != SECSuccess) { |
| + LOG(ERROR) << "CERT_GetCertTrust failed with error " << PORT_GetError(); |
| + return false; |
| + } |
| + |
| + // Handle explicitly distrusted certificates. |
| + static const unsigned int kTrusted = CERTDB_TRUSTED_CA | CERTDB_TRUSTED; |
| + const bool has_no_trust_flags = |
| + (nsstrust.sslFlags & kTrusted) == 0 && |
| + (nsstrust.emailFlags & kTrusted) == 0 && |
| + (nsstrust.objectSigningFlags & kTrusted) == 0; |
| + const bool is_terminal_record = |
| + (nsstrust.sslFlags & CERTDB_TERMINAL_RECORD) || |
| + (nsstrust.emailFlags & CERTDB_TERMINAL_RECORD) || |
| + (nsstrust.objectSigningFlags & CERTDB_TERMINAL_RECORD); |
| + |
| + // In a terminal trust record, three bits may be set: CERTDB_VALID_CA, |
| + // CERTDB_TRUSTED_CA, and CERTDB_TRUSTED. The CERTDB_VALID_CA bit is |
| + // irrelevant to distrust, so we don't test that bit. |
| + if (is_terminal_record && has_no_trust_flags) |
| + return true; |
| + |
| + // Self-signed certificates that don't have any trust bits set are untrusted. |
| + // Other certificates that don't have any trust bits set may still be trusted |
| + // if they chain up to a trust anchor. |
| + if (CERT_CompareName(&cert->os_cert_handle()->issuer, |
| + &cert->os_cert_handle()->subject) == SECEqual) { |
| + return has_no_trust_flags; |
| + } |
| + |
| + return false; |
| +} |
| + |
| bool CertDatabase::SetCertTrust(const X509Certificate* cert, |
| CertType type, |
| TrustBits trust_bits) { |