| 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 CONTENT_BROWSER_SSL_SSL_CLIENT_AUTH_HANDLER_H_ | 5 #ifndef CONTENT_BROWSER_SSL_SSL_CLIENT_AUTH_HANDLER_H_ |
| 6 #define CONTENT_BROWSER_SSL_SSL_CLIENT_AUTH_HANDLER_H_ | 6 #define CONTENT_BROWSER_SSL_SSL_CLIENT_AUTH_HANDLER_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
| 14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "net/ssl/ssl_cert_request_info.h" | 15 #include "net/ssl/ssl_cert_request_info.h" |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 class ClientCertStore; | 18 class ClientCertStore; |
| 19 class SSLPrivateKey; |
| 19 class URLRequest; | 20 class URLRequest; |
| 20 class X509Certificate; | 21 class X509Certificate; |
| 21 } // namespace net | 22 } // namespace net |
| 22 | 23 |
| 23 namespace content { | 24 namespace content { |
| 24 | 25 |
| 25 // This class handles the approval and selection of a certificate for SSL client | 26 // This class handles the approval and selection of a certificate for SSL client |
| 26 // authentication by the user. Should only be used on the IO thread. If the | 27 // authentication by the user. Should only be used on the IO thread. If the |
| 27 // SSLClientAuthHandler is destroyed before the certificate is selected, the | 28 // SSLClientAuthHandler is destroyed before the certificate is selected, the |
| 28 // selection is canceled and the delegate never called. | 29 // selection is canceled and the delegate never called. |
| 29 class SSLClientAuthHandler { | 30 class SSLClientAuthHandler { |
| 30 public: | 31 public: |
| 31 // Delegate interface for SSLClientAuthHandler. Method implementations may | 32 // Delegate interface for SSLClientAuthHandler. Method implementations may |
| 32 // delete the handler when called. | 33 // delete the handler when called. |
| 33 class CONTENT_EXPORT Delegate { | 34 class CONTENT_EXPORT Delegate { |
| 34 public: | 35 public: |
| 35 Delegate() {} | 36 Delegate() {} |
| 36 | 37 |
| 37 // Called to continue the request with |cert|. |cert| may be nullptr. | 38 // Called to continue the request with |cert| and |pkey|. |cert| and |pkey| |
| 38 virtual void ContinueWithCertificate(net::X509Certificate* cert) = 0; | 39 // may be nullptr. |
| 40 virtual void ContinueWithCertificate(net::X509Certificate* cert, |
| 41 net::SSLPrivateKey* pkey) = 0; |
| 39 | 42 |
| 40 // Called to cancel the certificate selection and abort the request. | 43 // Called to cancel the certificate selection and abort the request. |
| 41 virtual void CancelCertificateSelection() = 0; | 44 virtual void CancelCertificateSelection() = 0; |
| 42 | 45 |
| 43 protected: | 46 protected: |
| 44 virtual ~Delegate() {} | 47 virtual ~Delegate() {} |
| 45 | 48 |
| 46 private: | 49 private: |
| 47 DISALLOW_COPY_AND_ASSIGN(Delegate); | 50 DISALLOW_COPY_AND_ASSIGN(Delegate); |
| 48 }; | 51 }; |
| 49 | 52 |
| 50 // Creates a new SSLClientAuthHandler. The caller ensures that the handler | 53 // Creates a new SSLClientAuthHandler. The caller ensures that the handler |
| 51 // does not outlive |request| or |delegate|. | 54 // does not outlive |request| or |delegate|. |
| 52 SSLClientAuthHandler(scoped_ptr<net::ClientCertStore> client_cert_store, | 55 SSLClientAuthHandler(scoped_ptr<net::ClientCertStore> client_cert_store, |
| 53 net::URLRequest* request, | 56 net::URLRequest* request, |
| 54 net::SSLCertRequestInfo* cert_request_info, | 57 net::SSLCertRequestInfo* cert_request_info, |
| 55 Delegate* delegate); | 58 Delegate* delegate); |
| 56 ~SSLClientAuthHandler(); | 59 ~SSLClientAuthHandler(); |
| 57 | 60 |
| 58 // Selects a certificate and resumes the URL request with that certificate. | 61 // Selects a certificate and resumes the URL request with that certificate. |
| 59 void SelectCertificate(); | 62 void SelectCertificate(); |
| 60 | 63 |
| 61 // Called to continue the request associated with |handler| using |cert|. This | 64 // Called to continue the request associated with |handler| using |cert|. This |
| 62 // is static to avoid deleting |handler| while it is on the stack. | 65 // is static to avoid deleting |handler| while it is on the stack. |
| 63 static void ContinueWithCertificate( | 66 static void ContinueWithCertificate( |
| 64 const base::WeakPtr<SSLClientAuthHandler>& handler, | 67 const base::WeakPtr<SSLClientAuthHandler>& handler, |
| 65 net::X509Certificate* cert); | 68 net::X509Certificate* cert, |
| 69 net::SSLPrivateKey* pkey); |
| 66 | 70 |
| 67 // Called to abort the request associated with |handler|. This is static to | 71 // Called to abort the request associated with |handler|. This is static to |
| 68 // avoid deleting |handler| while it is on the stack. | 72 // avoid deleting |handler| while it is on the stack. |
| 69 static void CancelCertificateSelection( | 73 static void CancelCertificateSelection( |
| 70 const base::WeakPtr<SSLClientAuthHandler>& handler); | 74 const base::WeakPtr<SSLClientAuthHandler>& handler); |
| 71 | 75 |
| 72 private: | 76 private: |
| 73 class Core; | 77 class Core; |
| 74 | 78 |
| 75 // Called when |core_| is done retrieving the cert list. | 79 // Called when |core_| is done retrieving the cert list. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 90 Delegate* delegate_; | 94 Delegate* delegate_; |
| 91 | 95 |
| 92 base::WeakPtrFactory<SSLClientAuthHandler> weak_factory_; | 96 base::WeakPtrFactory<SSLClientAuthHandler> weak_factory_; |
| 93 | 97 |
| 94 DISALLOW_COPY_AND_ASSIGN(SSLClientAuthHandler); | 98 DISALLOW_COPY_AND_ASSIGN(SSLClientAuthHandler); |
| 95 }; | 99 }; |
| 96 | 100 |
| 97 } // namespace content | 101 } // namespace content |
| 98 | 102 |
| 99 #endif // CONTENT_BROWSER_SSL_SSL_CLIENT_AUTH_HANDLER_H_ | 103 #endif // CONTENT_BROWSER_SSL_SSL_CLIENT_AUTH_HANDLER_H_ |
| OLD | NEW |