[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | ce2b6226 | 2009-06-27 05:11:41 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 74b962a | 2011-06-03 21:22:54 | [diff] [blame^] | 5 | #ifndef CONTENT_BROWSER_SSL_SSL_CLIENT_AUTH_HANDLER_H_ |
6 | #define CONTENT_BROWSER_SSL_SSL_CLIENT_AUTH_HANDLER_H_ | ||||
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | ce2b6226 | 2009-06-27 05:11:41 | [diff] [blame] | 8 | |
9 | #include "base/basictypes.h" | ||||
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 10 | #include "base/memory/ref_counted.h" |
[email protected] | 5f945a0e | 2011-03-01 17:47:53 | [diff] [blame] | 11 | #include "content/browser/browser_thread.h" |
[email protected] | d39dbf1 | 2011-04-18 23:37:31 | [diff] [blame] | 12 | #include "content/common/notification_observer.h" |
13 | #include "content/common/notification_registrar.h" | ||||
[email protected] | ce2b6226 | 2009-06-27 05:11:41 | [diff] [blame] | 14 | #include "net/base/ssl_cert_request_info.h" |
15 | |||||
16 | namespace net { | ||||
[email protected] | ce2b6226 | 2009-06-27 05:11:41 | [diff] [blame] | 17 | class URLRequest; |
[email protected] | edfe7fab | 2010-11-28 13:11:52 | [diff] [blame] | 18 | class X509Certificate; |
19 | } // namespace net | ||||
[email protected] | ce2b6226 | 2009-06-27 05:11:41 | [diff] [blame] | 20 | |
21 | // This class handles the approval and selection of a certificate for SSL client | ||||
22 | // authentication by the user. | ||||
23 | // It is self-owned and deletes itself when the UI reports the user selection or | ||||
[email protected] | 6981d963 | 2010-11-30 21:34:02 | [diff] [blame] | 24 | // when the net::URLRequest is cancelled. |
[email protected] | 11f485728 | 2009-11-13 19:56:17 | [diff] [blame] | 25 | class SSLClientAuthHandler |
[email protected] | 1f18184a | 2010-07-21 19:34:49 | [diff] [blame] | 26 | : public base::RefCountedThreadSafe<SSLClientAuthHandler, |
[email protected] | 9a7e150 | 2010-10-08 04:03:50 | [diff] [blame] | 27 | BrowserThread::DeleteOnIOThread> { |
[email protected] | ce2b6226 | 2009-06-27 05:11:41 | [diff] [blame] | 28 | public: |
[email protected] | edfe7fab | 2010-11-28 13:11:52 | [diff] [blame] | 29 | SSLClientAuthHandler(net::URLRequest* request, |
[email protected] | 0d3dc8e2 | 2009-11-03 02:27:01 | [diff] [blame] | 30 | net::SSLCertRequestInfo* cert_request_info); |
[email protected] | ce2b6226 | 2009-06-27 05:11:41 | [diff] [blame] | 31 | |
32 | // Asks the user to select a certificate and resumes the URL request with that | ||||
33 | // certificate. | ||||
34 | // Should only be called on the IO thread. | ||||
35 | void SelectCertificate(); | ||||
36 | |||||
37 | // Invoked when the request associated with this handler is cancelled. | ||||
38 | // Should only be called on the IO thread. | ||||
39 | void OnRequestCancelled(); | ||||
40 | |||||
[email protected] | b1f18494 | 2010-03-04 01:46:57 | [diff] [blame] | 41 | // Calls DoCertificateSelected on the I/O thread. |
42 | // Called on the UI thread after the user has made a selection (which may | ||||
43 | // be long after DoSelectCertificate returns, if the UI is modeless/async.) | ||||
44 | void CertificateSelected(net::X509Certificate* cert); | ||||
45 | |||||
[email protected] | d39dbf1 | 2011-04-18 23:37:31 | [diff] [blame] | 46 | // Like CertificateSelected, but does not send SSL_CLIENT_AUTH_CERT_SELECTED |
47 | // notification. Used to avoid notification re-spamming when other | ||||
48 | // certificate selectors act on a notification matching the same host. | ||||
49 | void CertificateSelectedNoNotify(net::X509Certificate* cert); | ||||
50 | |||||
[email protected] | 1f18184a | 2010-07-21 19:34:49 | [diff] [blame] | 51 | // Returns the SSLCertRequestInfo for this handler. |
52 | net::SSLCertRequestInfo* cert_request_info() { return cert_request_info_; } | ||||
53 | |||||
[email protected] | ce2b6226 | 2009-06-27 05:11:41 | [diff] [blame] | 54 | private: |
[email protected] | 092b04e | 2010-10-12 23:23:44 | [diff] [blame] | 55 | friend class BrowserThread; |
[email protected] | 1f18184a | 2010-07-21 19:34:49 | [diff] [blame] | 56 | friend class DeleteTask<SSLClientAuthHandler>; |
[email protected] | e6e6ba4 | 2009-11-07 01:56:19 | [diff] [blame] | 57 | |
[email protected] | 02d08e0 | 2010-10-08 17:50:46 | [diff] [blame] | 58 | virtual ~SSLClientAuthHandler(); |
[email protected] | e6e6ba4 | 2009-11-07 01:56:19 | [diff] [blame] | 59 | |
[email protected] | ce2b6226 | 2009-06-27 05:11:41 | [diff] [blame] | 60 | // Notifies that the user has selected a cert. |
61 | // Called on the IO thread. | ||||
[email protected] | 3e1fc8e | 2010-02-18 22:45:05 | [diff] [blame] | 62 | void DoCertificateSelected(net::X509Certificate* cert); |
[email protected] | ce2b6226 | 2009-06-27 05:11:41 | [diff] [blame] | 63 | |
[email protected] | c6176905 | 2011-05-18 18:38:35 | [diff] [blame] | 64 | // Calls the SSL helper on the UI thread. |
65 | void ShowClientCertificateRequestDialog(int render_process_host_id, | ||||
66 | int render_view_host_id); | ||||
67 | |||||
[email protected] | 6981d963 | 2010-11-30 21:34:02 | [diff] [blame] | 68 | // The net::URLRequest that triggered this client auth. |
[email protected] | edfe7fab | 2010-11-28 13:11:52 | [diff] [blame] | 69 | net::URLRequest* request_; |
[email protected] | ce2b6226 | 2009-06-27 05:11:41 | [diff] [blame] | 70 | |
71 | // The certs to choose from. | ||||
72 | scoped_refptr<net::SSLCertRequestInfo> cert_request_info_; | ||||
73 | |||||
[email protected] | ce2b6226 | 2009-06-27 05:11:41 | [diff] [blame] | 74 | DISALLOW_COPY_AND_ASSIGN(SSLClientAuthHandler); |
75 | }; | ||||
76 | |||||
[email protected] | d39dbf1 | 2011-04-18 23:37:31 | [diff] [blame] | 77 | class SSLClientAuthObserver : public NotificationObserver { |
78 | public: | ||||
79 | SSLClientAuthObserver(net::SSLCertRequestInfo* cert_request_info, | ||||
80 | SSLClientAuthHandler* handler); | ||||
81 | virtual ~SSLClientAuthObserver(); | ||||
82 | |||||
83 | // UI should implement this to close the dialog. | ||||
84 | virtual void OnCertSelectedByNotification() = 0; | ||||
85 | |||||
86 | // NotificationObserver implementation: | ||||
87 | virtual void Observe(NotificationType type, | ||||
88 | const NotificationSource& source, | ||||
89 | const NotificationDetails& details); | ||||
90 | |||||
91 | // Begins observing notifications from other SSLClientAuthHandler instances. | ||||
92 | // If another instance chooses a cert for a matching SSLCertRequestInfo, we | ||||
93 | // will also use the same cert and OnCertSelectedByNotification will be called | ||||
94 | // so that the cert selection UI can be closed. | ||||
95 | void StartObserving(); | ||||
96 | |||||
97 | // Stops observing notifications. We will no longer act on client auth | ||||
98 | // notifications. | ||||
99 | void StopObserving(); | ||||
100 | |||||
101 | private: | ||||
102 | scoped_refptr<net::SSLCertRequestInfo> cert_request_info_; | ||||
103 | |||||
104 | scoped_refptr<SSLClientAuthHandler> handler_; | ||||
105 | |||||
106 | NotificationRegistrar notification_registrar_; | ||||
107 | |||||
108 | DISALLOW_COPY_AND_ASSIGN(SSLClientAuthObserver); | ||||
109 | }; | ||||
110 | |||||
[email protected] | 74b962a | 2011-06-03 21:22:54 | [diff] [blame^] | 111 | #endif // CONTENT_BROWSER_SSL_SSL_CLIENT_AUTH_HANDLER_H_ |