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 #ifndef NET_BASE_X509_CERTIFICATE_H_ | 5 #ifndef NET_BASE_X509_CERTIFICATE_H_ |
6 #define NET_BASE_X509_CERTIFICATE_H_ | 6 #define NET_BASE_X509_CERTIFICATE_H_ |
7 | 7 |
8 #include <map> | |
8 #include <set> | 9 #include <set> |
9 #include <string> | 10 #include <string> |
10 #include <vector> | 11 #include <vector> |
11 | 12 |
13 #include "base/singleton.h" | |
wtc
2008/09/23 21:39:55
Nit: list "base/singleton.h" in alphabetical order
| |
12 #include "base/ref_counted.h" | 14 #include "base/ref_counted.h" |
13 #include "base/time.h" | 15 #include "base/time.h" |
14 | 16 |
15 #if defined(OS_WIN) | 17 #if defined(OS_WIN) |
16 #include <windows.h> | 18 #include <windows.h> |
17 #include <wincrypt.h> | 19 #include <wincrypt.h> |
18 #elif defined(OS_MACOSX) | 20 #elif defined(OS_MACOSX) |
19 #include <Security/Security.h> | 21 #include <Security/Security.h> |
20 #endif | 22 #endif |
21 | 23 |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 bool HasExpired() const; | 161 bool HasExpired() const; |
160 | 162 |
161 // Returns true if the certificate is an extended-validation (EV) | 163 // Returns true if the certificate is an extended-validation (EV) |
162 // certificate. | 164 // certificate. |
163 bool IsEV(int cert_status) const; | 165 bool IsEV(int cert_status) const; |
164 | 166 |
165 OSCertHandle os_cert_handle() const { return cert_handle_; } | 167 OSCertHandle os_cert_handle() const { return cert_handle_; } |
166 | 168 |
167 private: | 169 private: |
168 // A cache of X509Certificate objects. | 170 // A cache of X509Certificate objects. |
169 class Cache; | 171 class Cache { |
172 public: | |
173 static Cache* GetInstance(); | |
174 void Insert(X509Certificate* cert); | |
175 void Remove(X509Certificate* cert); | |
176 X509Certificate* Find(const Fingerprint& fingerprint); | |
177 | |
178 private: | |
179 typedef std::map<Fingerprint, X509Certificate*, FingerprintLessThan> | |
180 CertMap; | |
181 | |
182 // Obtain an instance of X509Certificate::Cache via GetInstance(). | |
183 Cache() { } | |
184 friend struct DefaultSingletonTraits<Cache>; | |
185 | |
186 // You must acquire this lock before using any private data of this object. | |
187 // You must not block while holding this lock. | |
188 Lock lock_; | |
189 | |
190 // The certificate cache. You must acquire |lock_| before using |cache_|. | |
191 CertMap cache_; | |
192 | |
193 DISALLOW_COPY_AND_ASSIGN(Cache); | |
194 }; | |
170 | 195 |
171 // Construct an X509Certificate from a handle to the certificate object | 196 // Construct an X509Certificate from a handle to the certificate object |
172 // in the underlying crypto library. | 197 // in the underlying crypto library. |
173 explicit X509Certificate(OSCertHandle cert_handle); | 198 explicit X509Certificate(OSCertHandle cert_handle); |
174 | 199 |
175 friend class base::RefCountedThreadSafe<X509Certificate>; | 200 friend class base::RefCountedThreadSafe<X509Certificate>; |
176 ~X509Certificate(); | 201 ~X509Certificate(); |
177 | 202 |
178 // Common object initialization code. Called by the constructors only. | 203 // Common object initialization code. Called by the constructors only. |
179 void Initialize(); | 204 void Initialize(); |
180 | 205 |
181 #if defined(OS_WIN) | |
182 // Helper function to parse a principal from a WinInet description of that | |
183 // principal. | |
184 static void ParsePrincipal(const std::string& description, | |
185 Principal* principal); | |
186 #endif | |
187 | |
188 // The subject of the certificate. | 206 // The subject of the certificate. |
189 Principal subject_; | 207 Principal subject_; |
190 | 208 |
191 // The issuer of the certificate. | 209 // The issuer of the certificate. |
192 Principal issuer_; | 210 Principal issuer_; |
193 | 211 |
194 // This certificate is not valid before |valid_start_| | 212 // This certificate is not valid before |valid_start_| |
195 Time valid_start_; | 213 Time valid_start_; |
196 | 214 |
197 // This certificate is not valid after |valid_expiry_| | 215 // This certificate is not valid after |valid_expiry_| |
198 Time valid_expiry_; | 216 Time valid_expiry_; |
199 | 217 |
200 // The fingerprint of this certificate. | 218 // The fingerprint of this certificate. |
201 Fingerprint fingerprint_; | 219 Fingerprint fingerprint_; |
202 | 220 |
203 // A handle to the certificate object in the underlying crypto library. | 221 // A handle to the certificate object in the underlying crypto library. |
204 OSCertHandle cert_handle_; | 222 OSCertHandle cert_handle_; |
205 | 223 |
206 DISALLOW_COPY_AND_ASSIGN(X509Certificate); | 224 DISALLOW_COPY_AND_ASSIGN(X509Certificate); |
207 }; | 225 }; |
208 | 226 |
209 } // namespace net | 227 } // namespace net |
210 | 228 |
211 #endif // NET_BASE_X509_CERTIFICATE_H_ | 229 #endif // NET_BASE_X509_CERTIFICATE_H_ |
212 | 230 |
OLD | NEW |