| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_TEST_ROOT_CERTS_H_ | 5 #ifndef NET_BASE_TEST_ROOT_CERTS_H_ |
| 6 #define NET_BASE_TEST_ROOT_CERTS_H_ | 6 #define NET_BASE_TEST_ROOT_CERTS_H_ |
| 7 | 7 |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 11 #include "net/base/net_export.h" | 11 #include "net/base/net_export.h" |
| 12 | 12 |
| 13 #if defined(USE_NSS) || defined(OS_IOS) | 13 #if defined(USE_NSS) || defined(OS_IOS) |
| 14 #include <list> | 14 #include <list> |
| 15 #elif defined(OS_WIN) | 15 #elif defined(OS_WIN) |
| 16 #include <windows.h> | 16 #include <windows.h> |
| 17 #include <wincrypt.h> | 17 #include <wincrypt.h> |
| 18 #elif defined(OS_MACOSX) | 18 #elif defined(OS_MACOSX) |
| 19 #include <CoreFoundation/CFArray.h> | 19 #include <CoreFoundation/CFArray.h> |
| 20 #include <Security/SecTrust.h> | 20 #include <Security/SecTrust.h> |
| 21 #include "base/mac/scoped_cftyperef.h" | 21 #include "base/mac/scoped_cftyperef.h" |
| 22 #endif | 22 #endif |
| 23 | 23 |
| 24 namespace base { |
| 24 class FilePath; | 25 class FilePath; |
| 26 } |
| 25 | 27 |
| 26 namespace net { | 28 namespace net { |
| 27 | 29 |
| 28 class X509Certificate; | 30 class X509Certificate; |
| 29 | 31 |
| 30 // TestRootCerts is a helper class for unit tests that is used to | 32 // TestRootCerts is a helper class for unit tests that is used to |
| 31 // artificially mark a certificate as trusted, independent of the local | 33 // artificially mark a certificate as trusted, independent of the local |
| 32 // machine configuration. | 34 // machine configuration. |
| 33 class NET_EXPORT_PRIVATE TestRootCerts { | 35 class NET_EXPORT_PRIVATE TestRootCerts { |
| 34 public: | 36 public: |
| 35 // Obtains the Singleton instance to the trusted certificates. | 37 // Obtains the Singleton instance to the trusted certificates. |
| 36 static TestRootCerts* GetInstance(); | 38 static TestRootCerts* GetInstance(); |
| 37 | 39 |
| 38 // Returns true if an instance exists, without forcing an initialization. | 40 // Returns true if an instance exists, without forcing an initialization. |
| 39 static bool HasInstance(); | 41 static bool HasInstance(); |
| 40 | 42 |
| 41 // Marks |certificate| as trusted for X509Certificate::Verify(). Returns | 43 // Marks |certificate| as trusted for X509Certificate::Verify(). Returns |
| 42 // false if the certificate could not be marked trusted. | 44 // false if the certificate could not be marked trusted. |
| 43 bool Add(X509Certificate* certificate); | 45 bool Add(X509Certificate* certificate); |
| 44 | 46 |
| 45 // Reads a single certificate from |file| and marks it as trusted. Returns | 47 // Reads a single certificate from |file| and marks it as trusted. Returns |
| 46 // false if an error is encountered, such as being unable to read |file| | 48 // false if an error is encountered, such as being unable to read |file| |
| 47 // or more than one certificate existing in |file|. | 49 // or more than one certificate existing in |file|. |
| 48 bool AddFromFile(const FilePath& file); | 50 bool AddFromFile(const base::FilePath& file); |
| 49 | 51 |
| 50 // Clears the trusted status of any certificates that were previously | 52 // Clears the trusted status of any certificates that were previously |
| 51 // marked trusted via Add(). | 53 // marked trusted via Add(). |
| 52 void Clear(); | 54 void Clear(); |
| 53 | 55 |
| 54 // Returns true if there are no certificates that have been marked trusted. | 56 // Returns true if there are no certificates that have been marked trusted. |
| 55 bool IsEmpty() const; | 57 bool IsEmpty() const; |
| 56 | 58 |
| 57 #if defined(OS_MACOSX) && !defined(OS_IOS) | 59 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 58 CFArrayRef temporary_roots() const { return temporary_roots_; } | 60 CFArrayRef temporary_roots() const { return temporary_roots_; } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 118 |
| 117 private: | 119 private: |
| 118 scoped_refptr<X509Certificate> cert_; | 120 scoped_refptr<X509Certificate> cert_; |
| 119 | 121 |
| 120 DISALLOW_COPY_AND_ASSIGN(ScopedTestRoot); | 122 DISALLOW_COPY_AND_ASSIGN(ScopedTestRoot); |
| 121 }; | 123 }; |
| 122 | 124 |
| 123 } // namespace net | 125 } // namespace net |
| 124 | 126 |
| 125 #endif // NET_BASE_TEST_ROOT_CERTS_H_ | 127 #endif // NET_BASE_TEST_ROOT_CERTS_H_ |
| OLD | NEW |