| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 CHROME_BROWSER_CHROMEOS_POLICY_POLICY_CERT_VERIFIER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_POLICY_CERT_VERIFIER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_POLICY_POLICY_CERT_VERIFIER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_POLICY_POLICY_CERT_VERIFIER_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/weak_ptr.h" |
| 16 #include "net/base/completion_callback.h" |
| 15 #include "net/cert/cert_trust_anchor_provider.h" | 17 #include "net/cert/cert_trust_anchor_provider.h" |
| 16 #include "net/cert/cert_verifier.h" | 18 #include "net/cert/cert_verifier.h" |
| 17 | 19 |
| 18 namespace net { | 20 namespace net { |
| 21 class CertVerifyResult; |
| 19 class X509Certificate; | 22 class X509Certificate; |
| 20 typedef std::vector<scoped_refptr<X509Certificate> > CertificateList; | 23 typedef std::vector<scoped_refptr<X509Certificate> > CertificateList; |
| 21 } | 24 } |
| 22 | 25 |
| 23 namespace policy { | 26 namespace policy { |
| 24 | 27 |
| 25 // Wraps a MultiThreadedCertVerifier to make it use the additional trust anchors | 28 // Wraps a MultiThreadedCertVerifier to make it use the additional trust anchors |
| 26 // configured by the ONC user policy. | 29 // configured by the ONC user policy. |
| 27 class PolicyCertVerifier : public net::CertVerifier, | 30 class PolicyCertVerifier : public net::CertVerifier, |
| 28 public net::CertTrustAnchorProvider { | 31 public net::CertTrustAnchorProvider { |
| 29 public: | 32 public: |
| 30 // This object must be created on the UI thread. It's member functions and | 33 // This object must be created on the UI thread. |anchor_used_callback| is |
| 31 // destructor must be called on the IO thread. |anchor_used_callback| is | 34 // called on the UI thread everytime a certificate from the additional trust |
| 32 // called on the IO thread everytime a certificate from the additional trust | 35 // anchors (set with SetTrustAnchors) is used. These notifications are stopped |
| 33 // anchors (set with SetTrustAnchors) is used. | 36 // once UnsetTrustAnchorUsedCallback is called. |
| 34 explicit PolicyCertVerifier(const base::Closure& anchor_used_callback); | 37 explicit PolicyCertVerifier(const base::Closure& anchor_used_callback); |
| 35 virtual ~PolicyCertVerifier(); | 38 virtual ~PolicyCertVerifier(); |
| 36 | 39 |
| 37 void InitializeOnIOThread(); | 40 void InitializeOnIOThread(); |
| 38 | 41 |
| 42 // To be called on the UI thread. Unsets |anchor_used_callback| from the |
| 43 // constructor. Until this is called, that callback is run for usages of |
| 44 // additional trust anchors. |
| 45 void UnsetTrustAnchorUsedCallback(); |
| 46 |
| 47 // To be called on the IO thread. Sets the additional trust anchors. |
| 39 void SetTrustAnchors(const net::CertificateList& trust_anchors); | 48 void SetTrustAnchors(const net::CertificateList& trust_anchors); |
| 40 | 49 |
| 41 // CertVerifier: | 50 // CertVerifier: |
| 42 // Note: |callback| can be null. | 51 // Note: |callback| can be null. |
| 43 virtual int Verify(net::X509Certificate* cert, | 52 virtual int Verify(net::X509Certificate* cert, |
| 44 const std::string& hostname, | 53 const std::string& hostname, |
| 45 int flags, | 54 int flags, |
| 46 net::CRLSet* crl_set, | 55 net::CRLSet* crl_set, |
| 47 net::CertVerifyResult* verify_result, | 56 net::CertVerifyResult* verify_result, |
| 48 const net::CompletionCallback& callback, | 57 const net::CompletionCallback& callback, |
| 49 RequestHandle* out_req, | 58 RequestHandle* out_req, |
| 50 const net::BoundNetLog& net_log) OVERRIDE; | 59 const net::BoundNetLog& net_log) OVERRIDE; |
| 51 | 60 |
| 52 virtual void CancelRequest(RequestHandle req) OVERRIDE; | 61 virtual void CancelRequest(RequestHandle req) OVERRIDE; |
| 53 | 62 |
| 54 // CertTrustAnchorProvider: | 63 // CertTrustAnchorProvider: |
| 55 virtual const net::CertificateList& GetAdditionalTrustAnchors() OVERRIDE; | 64 virtual const net::CertificateList& GetAdditionalTrustAnchors() OVERRIDE; |
| 56 | 65 |
| 57 private: | 66 private: |
| 67 void NotifyOnUI(); |
| 68 |
| 69 static void MaybeSignalAnchorUse( |
| 70 int error, |
| 71 const net::CertVerifyResult& verify_result, |
| 72 const base::WeakPtr<PolicyCertVerifier>& weak_ptr); |
| 73 |
| 74 static void CompleteAndSignalAnchorUse( |
| 75 const net::CompletionCallback& completion_callback, |
| 76 const net::CertVerifyResult* verify_result, |
| 77 const base::WeakPtr<PolicyCertVerifier>& weak_ptr, |
| 78 int error); |
| 79 |
| 80 // Access on IO thread. |
| 58 net::CertificateList trust_anchors_; | 81 net::CertificateList trust_anchors_; |
| 82 |
| 83 // Access on IO thread. |
| 84 scoped_ptr<CertVerifier> delegate_; |
| 85 |
| 86 // Access on UI thread. |
| 59 base::Closure anchor_used_callback_; | 87 base::Closure anchor_used_callback_; |
| 60 scoped_ptr<CertVerifier> delegate_; | 88 |
| 89 // Must be constructed, modified, and invalidated on the UI thread. |
| 90 base::WeakPtrFactory<PolicyCertVerifier> weak_ptr_factory_; |
| 91 |
| 92 // Must be constructed and dereferenced on the UI thread. This WeakPtr has to |
| 93 // be used for callbacks from the IO thread to the UI thread. |
| 94 base::WeakPtr<PolicyCertVerifier> weak_ptr_; |
| 61 | 95 |
| 62 DISALLOW_COPY_AND_ASSIGN(PolicyCertVerifier); | 96 DISALLOW_COPY_AND_ASSIGN(PolicyCertVerifier); |
| 63 }; | 97 }; |
| 64 | 98 |
| 65 } // namespace policy | 99 } // namespace policy |
| 66 | 100 |
| 67 #endif // CHROME_BROWSER_CHROMEOS_POLICY_POLICY_CERT_VERIFIER_H_ | 101 #endif // CHROME_BROWSER_CHROMEOS_POLICY_POLICY_CERT_VERIFIER_H_ |
| OLD | NEW |