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. | |
254 static const unsigned int kTrusted = CERTDB_TRUSTED_CA | CERTDB_TRUSTED; | |
255 const bool has_no_trust_flags = | |
256 (nsstrust.sslFlags & kTrusted) == 0 && | |
257 (nsstrust.emailFlags & kTrusted) == 0 && | |
258 (nsstrust.objectSigningFlags & kTrusted) == 0; | |
259 | |
260 unsigned int flags = SEC_GET_TRUST_FLAGS(&nsstrust, trustSSL); | |
261 if (flags & CERTDB_TERMINAL_RECORD) { | |
wtc
2011/09/21 21:49:21
Also the CERTDB_TERMINAL_RECORD bit needs to be te
| |
262 // In a terminal trust record, three bits may be set: CERTDB_VALID_CA, | |
263 // CERTDB_TRUSTED_CA, and CERTDB_TRUSTED. The CERTDB_VALID_CA bit is | |
264 // irrelevant to distrust, so we don't test that bit. | |
265 return has_no_trust_flags; | |
wtc
2011/09/21 19:01:13
The boolean expression has_no_trust_flags is wrong
| |
266 } | |
267 | |
268 // Self-signed certificates that don't have any trust bits set are untrusted. | |
269 // Other certificates that don't have any trust bits set may still be trusted | |
270 // if they chain up to a trust anchor. | |
271 if (CERT_CompareName(&cert->os_cert_handle()->issuer, | |
272 &cert->os_cert_handle()->subject) == SECEqual) { | |
273 return has_no_trust_flags; | |
274 } | |
275 | |
276 return false; | |
277 } | |
278 | |
239 bool CertDatabase::SetCertTrust(const X509Certificate* cert, | 279 bool CertDatabase::SetCertTrust(const X509Certificate* cert, |
240 CertType type, | 280 CertType type, |
241 TrustBits trust_bits) { | 281 TrustBits trust_bits) { |
242 bool success = psm::SetCertTrust(cert, type, trust_bits); | 282 bool success = psm::SetCertTrust(cert, type, trust_bits); |
243 if (success) | 283 if (success) |
244 CertDatabase::NotifyObserversOfCertTrustChanged(cert); | 284 CertDatabase::NotifyObserversOfCertTrustChanged(cert); |
245 | 285 |
246 return success; | 286 return success; |
247 } | 287 } |
248 | 288 |
(...skipping 19 matching lines...) Expand all Loading... | |
268 } | 308 } |
269 return true; | 309 return true; |
270 } | 310 } |
271 | 311 |
272 bool CertDatabase::IsReadOnly(const X509Certificate* cert) const { | 312 bool CertDatabase::IsReadOnly(const X509Certificate* cert) const { |
273 PK11SlotInfo* slot = cert->os_cert_handle()->slot; | 313 PK11SlotInfo* slot = cert->os_cert_handle()->slot; |
274 return slot && PK11_IsReadOnly(slot); | 314 return slot && PK11_IsReadOnly(slot); |
275 } | 315 } |
276 | 316 |
277 } // namespace net | 317 } // namespace net |
OLD | NEW |