Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/base/cert_database.h" | 5 #include "net/base/cert_database.h" |
| 6 | 6 |
| 7 #include <cert.h> | 7 #include <cert.h> |
| 8 #include <certdb.h> | 8 #include <certdb.h> |
| 9 #include <keyhi.h> | 9 #include <keyhi.h> |
| 10 #include <pk11pub.h> | 10 #include <pk11pub.h> |
| 11 #include <secmod.h> | 11 #include <secmod.h> |
| 12 | 12 |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "crypto/nss_util.h" | 15 #include "crypto/nss_util.h" |
| 16 #include "crypto/nss_util_internal.h" | 16 #include "crypto/nss_util_internal.h" |
| 17 #include "net/base/crypto_module.h" | 17 #include "net/base/crypto_module.h" |
| 18 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
| 19 #include "net/base/x509_certificate.h" | 19 #include "net/base/x509_certificate.h" |
| 20 #include "net/third_party/mozilla_security_manager/nsNSSCertificateDB.h" | 20 #include "net/third_party/mozilla_security_manager/nsNSSCertificateDB.h" |
| 21 #include "net/third_party/mozilla_security_manager/nsNSSCertTrust.h" | 21 #include "net/third_party/mozilla_security_manager/nsNSSCertTrust.h" |
| 22 #include "net/third_party/mozilla_security_manager/nsPKCS12Blob.h" | 22 #include "net/third_party/mozilla_security_manager/nsPKCS12Blob.h" |
| 23 | 23 |
| 24 // In NSS 3.13, CERTDB_VALID_PEER was renamed CERTDB_TERMINAL_RECORD. So we use | |
| 25 // the new name of the macro. | |
| 26 #if !defined(CERTDB_TERMINAL_RECORD) | |
| 27 #define CERTDB_TERMINAL_RECORD CERTDB_VALID_PEER | |
| 28 #endif | |
| 29 | |
| 24 // PSM = Mozilla's Personal Security Manager. | 30 // PSM = Mozilla's Personal Security Manager. |
| 25 namespace psm = mozilla_security_manager; | 31 namespace psm = mozilla_security_manager; |
| 26 | 32 |
| 27 namespace net { | 33 namespace net { |
| 28 | 34 |
| 29 CertDatabase::CertDatabase() { | 35 CertDatabase::CertDatabase() { |
| 30 crypto::EnsureNSSInit(); | 36 crypto::EnsureNSSInit(); |
| 31 psm::EnsurePKCS12Init(); | 37 psm::EnsurePKCS12Init(); |
| 32 } | 38 } |
| 33 | 39 |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 trust.HasTrustedCA(PR_FALSE, PR_FALSE, PR_TRUE) * TRUSTED_OBJ_SIGN; | 235 trust.HasTrustedCA(PR_FALSE, PR_FALSE, PR_TRUE) * TRUSTED_OBJ_SIGN; |
| 230 case SERVER_CERT: | 236 case SERVER_CERT: |
| 231 return trust.HasTrustedPeer(PR_TRUE, PR_FALSE, PR_FALSE) * TRUSTED_SSL + | 237 return trust.HasTrustedPeer(PR_TRUE, PR_FALSE, PR_FALSE) * TRUSTED_SSL + |
| 232 trust.HasTrustedPeer(PR_FALSE, PR_TRUE, PR_FALSE) * TRUSTED_EMAIL + | 238 trust.HasTrustedPeer(PR_FALSE, PR_TRUE, PR_FALSE) * TRUSTED_EMAIL + |
| 233 trust.HasTrustedPeer(PR_FALSE, PR_FALSE, PR_TRUE) * TRUSTED_OBJ_SIGN; | 239 trust.HasTrustedPeer(PR_FALSE, PR_FALSE, PR_TRUE) * TRUSTED_OBJ_SIGN; |
| 234 default: | 240 default: |
| 235 return UNTRUSTED; | 241 return UNTRUSTED; |
| 236 } | 242 } |
| 237 } | 243 } |
| 238 | 244 |
| 245 bool CertDatabase::IsUntrusted(const X509Certificate* cert) const { | |
| 246 CERTCertTrust nsstrust; | |
| 247 SECStatus rv = CERT_GetCertTrust(cert->os_cert_handle(), &nsstrust); | |
| 248 if (rv != SECSuccess) { | |
| 249 LOG(ERROR) << "CERT_GetCertTrust failed with error " << PORT_GetError(); | |
| 250 return false; | |
| 251 } | |
| 252 | |
| 253 // handle explicitly distrusted certificates. | |
|
wtc
2011/09/21 17:05:33
Nit: capitalize "handle".
| |
| 254 unsigned int flags = SEC_GET_TRUST_FLAGS(&nsstrust, trustSSL); | |
| 255 static const unsigned int kTrusted = CERTDB_TRUSTED_CA | CERTDB_TRUSTED; | |
| 256 if ((flags & CERTDB_TERMINAL_RECORD) && (flags & kTrusted) == 0) { | |
| 257 // In a terminal trust record, three bits may be set: CERTDB_VALID_CA, | |
| 258 // CERTDB_TRUSTED_CA, and CERTDB_TRUSTED. The CERTDB_VALID_CA bit is | |
| 259 // irrelevant to distrust, so we don't test that bit. | |
| 260 return true; | |
| 261 } | |
|
wtc
2011/09/21 17:05:33
IMPORTANT: Did you omit the checking of distrust f
agl
2011/09/21 17:53:53
I did deliberately omit the tests for email and co
| |
| 262 | |
| 263 // Self-signed certificates that don't have any trust bits set are untrusted. | |
| 264 // Other certificates that don't have any trust bits set may still be trusted | |
| 265 // if they chain up to a trust anchor. | |
| 266 if (CERT_CompareName(&cert->os_cert_handle()->issuer, | |
| 267 &cert->os_cert_handle()->subject) == SECEqual) { | |
| 268 return (nsstrust.sslFlags & kTrusted) == 0 && | |
| 269 (nsstrust.emailFlags & kTrusted) == 0 && | |
| 270 (nsstrust.objectSigningFlags & kTrusted) == 0; | |
| 271 } | |
| 272 | |
| 273 return false; | |
| 274 } | |
| 275 | |
| 239 bool CertDatabase::SetCertTrust(const X509Certificate* cert, | 276 bool CertDatabase::SetCertTrust(const X509Certificate* cert, |
| 240 CertType type, | 277 CertType type, |
| 241 unsigned int trusted) { | 278 unsigned int trusted) { |
| 242 bool success = psm::SetCertTrust(cert, type, trusted); | 279 bool success = psm::SetCertTrust(cert, type, trusted); |
| 243 if (success) | 280 if (success) |
| 244 CertDatabase::NotifyObserversOfCertTrustChanged(cert); | 281 CertDatabase::NotifyObserversOfCertTrustChanged(cert); |
| 245 | 282 |
| 246 return success; | 283 return success; |
| 247 } | 284 } |
| 248 | 285 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 268 } | 305 } |
| 269 return true; | 306 return true; |
| 270 } | 307 } |
| 271 | 308 |
| 272 bool CertDatabase::IsReadOnly(const X509Certificate* cert) const { | 309 bool CertDatabase::IsReadOnly(const X509Certificate* cert) const { |
| 273 PK11SlotInfo* slot = cert->os_cert_handle()->slot; | 310 PK11SlotInfo* slot = cert->os_cert_handle()->slot; |
| 274 return slot && PK11_IsReadOnly(slot); | 311 return slot && PK11_IsReadOnly(slot); |
| 275 } | 312 } |
| 276 | 313 |
| 277 } // namespace net | 314 } // namespace net |
| OLD | NEW |