Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: net/base/test_root_certs.h

Issue 4646001: Implement LoadTemporaryRoot for Windows (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/net/base
Patch Set: Rebase to trunk with OpenSSL fixes from joth Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef NET_BASE_TEST_ROOT_CERTS_H_
6 #define NET_BASE_TEST_ROOT_CERTS_H_
7 #pragma once
8
9 #include "base/singleton.h"
10 #include "build/build_config.h"
11
12 #if defined(OS_WIN)
13 #include <windows.h>
14 #include <wincrypt.h>
15 #elif defined(OS_MACOSX)
16 #include <CoreFoundation/CFArray.h>
17 #include <Security/SecTrust.h>
18 #include "base/mac/scoped_cftyperef.h"
19 #elif defined(USE_NSS)
20 #include <list>
21 #endif
22
23 class FilePath;
24
25 namespace net {
26
27 class X509Certificate;
28
29 // TestRootCerts is a helper class for unit tests that is used to
30 // artificially mark a certificate as trusted, independent of the local
31 // machine configuration.
32 class TestRootCerts {
33 public:
34 // Obtains the Singleton instance to the trusted certificates.
35 static TestRootCerts* GetInstance();
36
37 // Marks |certificate| as trusted for X509Certificate::Verify(). Returns
38 // false if the certificate could not be marked trusted.
39 bool Add(X509Certificate* certificate);
40
41 // Reads a single certificate from |file| and marks it as trusted. Returns
42 // false if an error is encountered, such as being unable to read |file|
43 // or more than one certificate existing in |file|.
44 bool AddFromFile(const FilePath& file);
45
46 // Clears the trusted status of any certificates that were previously
47 // marked trusted via Add().
48 void Clear();
49
50 // Returns true if there are no certificates that have been marked trusted.
51 bool IsEmpty() const;
52
53 #if defined(OS_MACOSX)
54 CFArrayRef temporary_roots() const { return temporary_roots_; }
55
56 // Modifies the root certificates of |trust_ref| to include the
57 // certificates stored in |temporary_roots_|. If IsEmpty() is true, this
58 // does not modify |trust_ref|.
59 OSStatus FixupSecTrustRef(SecTrustRef trust_ref) const;
60 #elif defined(OS_WIN)
61 HCERTSTORE temporary_roots() const { return temporary_roots_; }
62
63 // Overrides any trust failures in |chain_context| that were caused by an
64 // untrusted CA certificate that was previously added. In order to more
65 // closely match the behaviour of CryptoAPI, intermediate CA certificates
66 // are also allowed to be trust anchors, as described in RFC 3280, in
67 // addition to root (self-signed) certificates. If IsEmpty() is true,
68 // |chain_context| is not modified.
69 void FixupChainContext(PCERT_CHAIN_CONTEXT chain_context) const;
70 #endif
71
72 private:
73 friend struct DefaultSingletonTraits<TestRootCerts>;
74
75 TestRootCerts();
76 ~TestRootCerts();
77
78 #if defined(OS_MACOSX)
79 base::mac::ScopedCFTypeRef<CFMutableArrayRef> temporary_roots_;
80 #elif defined(OS_WIN)
81 HCERTSTORE temporary_roots_;
82 #elif defined(USE_NSS)
83 // It is necessary to maintain a cache of the original certificate trust
84 // settings, in order to restore them when Clear() is called.
85 class TrustEntry;
86 std::list<TrustEntry*> trust_cache_;
87 #endif
88
89 #if defined(OS_WIN) || defined(USE_OPENSSL)
90 // True if there are no temporarily trusted root certificates.
91 bool empty_;
92 #endif
93
94 DISALLOW_COPY_AND_ASSIGN(TestRootCerts);
95 };
96
97 } // namespace net
98
99 #endif // NET_BASE_TEST_ROOT_CERTS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698