| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/x509_certificate.h" | 5 #include "net/base/x509_certificate.h" |
| 6 | 6 |
| 7 #if defined(USE_NSS) | 7 #if defined(OS_MACOSX) |
| 8 #include <Security/Security.h> |
| 9 #elif defined(USE_NSS) |
| 8 #include <cert.h> | 10 #include <cert.h> |
| 9 #endif | 11 #endif |
| 10 | 12 |
| 11 #include "base/histogram.h" | 13 #include "base/histogram.h" |
| 12 #include "base/logging.h" | 14 #include "base/logging.h" |
| 13 #include "base/time.h" | 15 #include "base/time.h" |
| 14 | 16 |
| 15 namespace net { | 17 namespace net { |
| 16 | 18 |
| 17 namespace { | 19 namespace { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 return a->derCert.len == b->derCert.len && | 51 return a->derCert.len == b->derCert.len && |
| 50 memcmp(a->derCert.data, b->derCert.data, a->derCert.len) == 0; | 52 memcmp(a->derCert.data, b->derCert.data, a->derCert.len) == 0; |
| 51 #else | 53 #else |
| 52 // TODO(snej): not implemented | 54 // TODO(snej): not implemented |
| 53 UNREACHED(); | 55 UNREACHED(); |
| 54 return false; | 56 return false; |
| 55 #endif | 57 #endif |
| 56 } | 58 } |
| 57 | 59 |
| 58 bool X509Certificate::FingerprintLessThan::operator()( | 60 bool X509Certificate::FingerprintLessThan::operator()( |
| 59 const Fingerprint& lhs, | 61 const SHA1Fingerprint& lhs, |
| 60 const Fingerprint& rhs) const { | 62 const SHA1Fingerprint& rhs) const { |
| 61 for (size_t i = 0; i < sizeof(lhs.data); ++i) { | 63 for (size_t i = 0; i < sizeof(lhs.data); ++i) { |
| 62 if (lhs.data[i] < rhs.data[i]) | 64 if (lhs.data[i] < rhs.data[i]) |
| 63 return true; | 65 return true; |
| 64 if (lhs.data[i] > rhs.data[i]) | 66 if (lhs.data[i] > rhs.data[i]) |
| 65 return false; | 67 return false; |
| 66 } | 68 } |
| 67 return false; | 69 return false; |
| 68 } | 70 } |
| 69 | 71 |
| 70 bool X509Certificate::LessThan::operator()(X509Certificate* lhs, | 72 bool X509Certificate::LessThan::operator()(X509Certificate* lhs, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 X509Certificate* X509Certificate::Cache::Find(const Fingerprint& fingerprint) { | 116 X509Certificate* X509Certificate::Cache::Find(const Fingerprint& fingerprint) { |
| 115 AutoLock lock(lock_); | 117 AutoLock lock(lock_); |
| 116 | 118 |
| 117 CertMap::iterator pos(cache_.find(fingerprint)); | 119 CertMap::iterator pos(cache_.find(fingerprint)); |
| 118 if (pos == cache_.end()) | 120 if (pos == cache_.end()) |
| 119 return NULL; | 121 return NULL; |
| 120 | 122 |
| 121 return pos->second; | 123 return pos->second; |
| 122 }; | 124 }; |
| 123 | 125 |
| 124 X509Certificate::Policy::Judgment X509Certificate::Policy::Check( | |
| 125 X509Certificate* cert) const { | |
| 126 // It shouldn't matter which set we check first, but we check denied first | |
| 127 // in case something strange has happened. | |
| 128 | |
| 129 if (denied_.find(cert->fingerprint()) != denied_.end()) { | |
| 130 // DCHECK that the order didn't matter. | |
| 131 DCHECK(allowed_.find(cert->fingerprint()) == allowed_.end()); | |
| 132 return DENIED; | |
| 133 } | |
| 134 | |
| 135 if (allowed_.find(cert->fingerprint()) != allowed_.end()) { | |
| 136 // DCHECK that the order didn't matter. | |
| 137 DCHECK(denied_.find(cert->fingerprint()) == denied_.end()); | |
| 138 return ALLOWED; | |
| 139 } | |
| 140 | |
| 141 // We don't have a policy for this cert. | |
| 142 return UNKNOWN; | |
| 143 } | |
| 144 | |
| 145 void X509Certificate::Policy::Allow(X509Certificate* cert) { | |
| 146 // Put the cert in the allowed set and (maybe) remove it from the denied set. | |
| 147 denied_.erase(cert->fingerprint()); | |
| 148 allowed_.insert(cert->fingerprint()); | |
| 149 } | |
| 150 | |
| 151 void X509Certificate::Policy::Deny(X509Certificate* cert) { | |
| 152 // Put the cert in the denied set and (maybe) remove it from the allowed set. | |
| 153 allowed_.erase(cert->fingerprint()); | |
| 154 denied_.insert(cert->fingerprint()); | |
| 155 } | |
| 156 | |
| 157 bool X509Certificate::Policy::HasAllowedCert() const { | |
| 158 return !allowed_.empty(); | |
| 159 } | |
| 160 | |
| 161 bool X509Certificate::Policy::HasDeniedCert() const { | |
| 162 return !denied_.empty(); | |
| 163 } | |
| 164 | |
| 165 // static | 126 // static |
| 166 X509Certificate* X509Certificate::CreateFromHandle( | 127 X509Certificate* X509Certificate::CreateFromHandle( |
| 167 OSCertHandle cert_handle, | 128 OSCertHandle cert_handle, |
| 168 Source source, | 129 Source source, |
| 169 const OSCertHandles& intermediates) { | 130 const OSCertHandles& intermediates) { |
| 170 DCHECK(cert_handle); | 131 DCHECK(cert_handle); |
| 171 DCHECK(source != SOURCE_UNUSED); | 132 DCHECK(source != SOURCE_UNUSED); |
| 172 | 133 |
| 173 // Check if we already have this certificate in memory. | 134 // Check if we already have this certificate in memory. |
| 174 X509Certificate::Cache* cache = X509Certificate::Cache::GetInstance(); | 135 X509Certificate::Cache* cache = X509Certificate::Cache::GetInstance(); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 | 224 |
| 264 bool X509Certificate::HasIntermediateCertificates(const OSCertHandles& certs) { | 225 bool X509Certificate::HasIntermediateCertificates(const OSCertHandles& certs) { |
| 265 for (size_t i = 0; i < certs.size(); ++i) { | 226 for (size_t i = 0; i < certs.size(); ++i) { |
| 266 if (!HasIntermediateCertificate(certs[i])) | 227 if (!HasIntermediateCertificate(certs[i])) |
| 267 return false; | 228 return false; |
| 268 } | 229 } |
| 269 return true; | 230 return true; |
| 270 } | 231 } |
| 271 | 232 |
| 272 } // namespace net | 233 } // namespace net |
| OLD | NEW |