blob: 019ffaf744f87b2cfb6c38635ec81a4bc0094f60 [file] [log] [blame]
[email protected]3b63f8f42011-03-28 01:54:151// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]ce2b62262009-06-27 05:11:412// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]74b962a2011-06-03 21:22:545#ifndef CONTENT_BROWSER_SSL_SSL_CLIENT_AUTH_HANDLER_H_
6#define CONTENT_BROWSER_SSL_SSL_CLIENT_AUTH_HANDLER_H_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]ce2b62262009-06-27 05:11:418
9#include "base/basictypes.h"
[email protected]3b63f8f42011-03-28 01:54:1510#include "base/memory/ref_counted.h"
[email protected]8d128d62011-09-13 22:11:5711#include "content/common/content_export.h"
[email protected]c38831a12011-10-28 12:44:4912#include "content/public/browser/browser_thread.h"
[email protected]6c2381d2011-10-19 02:52:5313#include "content/public/browser/notification_observer.h"
14#include "content/public/browser/notification_registrar.h"
[email protected]ce2b62262009-06-27 05:11:4115#include "net/base/ssl_cert_request_info.h"
16
17namespace net {
[email protected]fe4fb432011-10-20 22:43:4218class HttpNetworkSession;
[email protected]ce2b62262009-06-27 05:11:4119class URLRequest;
[email protected]edfe7fab2010-11-28 13:11:5220class X509Certificate;
21} // namespace net
[email protected]ce2b62262009-06-27 05:11:4122
23// This class handles the approval and selection of a certificate for SSL client
24// authentication by the user.
25// It is self-owned and deletes itself when the UI reports the user selection or
[email protected]6981d9632010-11-30 21:34:0226// when the net::URLRequest is cancelled.
[email protected]8d128d62011-09-13 22:11:5727class CONTENT_EXPORT SSLClientAuthHandler
[email protected]1f18184a2010-07-21 19:34:4928 : public base::RefCountedThreadSafe<SSLClientAuthHandler,
[email protected]9a7e1502010-10-08 04:03:5029 BrowserThread::DeleteOnIOThread> {
[email protected]ce2b62262009-06-27 05:11:4130 public:
[email protected]edfe7fab2010-11-28 13:11:5231 SSLClientAuthHandler(net::URLRequest* request,
[email protected]0d3dc8e22009-11-03 02:27:0132 net::SSLCertRequestInfo* cert_request_info);
[email protected]ce2b62262009-06-27 05:11:4133
[email protected]c99c442e2011-08-24 11:37:3034 // Selects a certificate and resumes the URL request with that certificate.
[email protected]ce2b62262009-06-27 05:11:4135 // Should only be called on the IO thread.
36 void SelectCertificate();
37
38 // Invoked when the request associated with this handler is cancelled.
39 // Should only be called on the IO thread.
40 void OnRequestCancelled();
41
[email protected]b1f184942010-03-04 01:46:5742 // Calls DoCertificateSelected on the I/O thread.
43 // Called on the UI thread after the user has made a selection (which may
44 // be long after DoSelectCertificate returns, if the UI is modeless/async.)
45 void CertificateSelected(net::X509Certificate* cert);
46
[email protected]d39dbf12011-04-18 23:37:3147 // Like CertificateSelected, but does not send SSL_CLIENT_AUTH_CERT_SELECTED
48 // notification. Used to avoid notification re-spamming when other
49 // certificate selectors act on a notification matching the same host.
[email protected]f2455422011-07-21 02:56:5850 virtual void CertificateSelectedNoNotify(net::X509Certificate* cert);
[email protected]d39dbf12011-04-18 23:37:3151
[email protected]1f18184a2010-07-21 19:34:4952 // Returns the SSLCertRequestInfo for this handler.
53 net::SSLCertRequestInfo* cert_request_info() { return cert_request_info_; }
54
[email protected]fe4fb432011-10-20 22:43:4255 // Returns the session the URL request is associated with.
56 const net::HttpNetworkSession* http_network_session() const {
57 return http_network_session_;
58 }
59
[email protected]f2455422011-07-21 02:56:5860 protected:
61 virtual ~SSLClientAuthHandler();
62
[email protected]ce2b62262009-06-27 05:11:4163 private:
[email protected]8d128d62011-09-13 22:11:5764 friend class base::RefCountedThreadSafe<SSLClientAuthHandler,
65 BrowserThread::DeleteOnIOThread>;
[email protected]092b04e2010-10-12 23:23:4466 friend class BrowserThread;
[email protected]1f18184a2010-07-21 19:34:4967 friend class DeleteTask<SSLClientAuthHandler>;
[email protected]e6e6ba42009-11-07 01:56:1968
[email protected]ce2b62262009-06-27 05:11:4169 // Notifies that the user has selected a cert.
70 // Called on the IO thread.
[email protected]3e1fc8e2010-02-18 22:45:0571 void DoCertificateSelected(net::X509Certificate* cert);
[email protected]ce2b62262009-06-27 05:11:4172
[email protected]c99c442e2011-08-24 11:37:3073 // Selects a client certificate on the UI thread.
74 void DoSelectCertificate(int render_process_host_id,
75 int render_view_host_id);
[email protected]c61769052011-05-18 18:38:3576
[email protected]6981d9632010-11-30 21:34:0277 // The net::URLRequest that triggered this client auth.
[email protected]edfe7fab2010-11-28 13:11:5278 net::URLRequest* request_;
[email protected]ce2b62262009-06-27 05:11:4179
[email protected]fe4fb432011-10-20 22:43:4280 // The HttpNetworkSession |request_| is associated with.
81 const net::HttpNetworkSession* http_network_session_;
82
[email protected]ce2b62262009-06-27 05:11:4183 // The certs to choose from.
84 scoped_refptr<net::SSLCertRequestInfo> cert_request_info_;
85
[email protected]ce2b62262009-06-27 05:11:4186 DISALLOW_COPY_AND_ASSIGN(SSLClientAuthHandler);
87};
88
[email protected]6c2381d2011-10-19 02:52:5389class CONTENT_EXPORT SSLClientAuthObserver
90 : public content::NotificationObserver {
[email protected]d39dbf12011-04-18 23:37:3191 public:
92 SSLClientAuthObserver(net::SSLCertRequestInfo* cert_request_info,
93 SSLClientAuthHandler* handler);
94 virtual ~SSLClientAuthObserver();
95
96 // UI should implement this to close the dialog.
97 virtual void OnCertSelectedByNotification() = 0;
98
[email protected]6c2381d2011-10-19 02:52:5399 // content::NotificationObserver implementation:
[email protected]432115822011-07-10 15:52:27100 virtual void Observe(int type,
[email protected]6c2381d2011-10-19 02:52:53101 const content::NotificationSource& source,
102 const content::NotificationDetails& details);
[email protected]d39dbf12011-04-18 23:37:31103
104 // Begins observing notifications from other SSLClientAuthHandler instances.
105 // If another instance chooses a cert for a matching SSLCertRequestInfo, we
106 // will also use the same cert and OnCertSelectedByNotification will be called
107 // so that the cert selection UI can be closed.
108 void StartObserving();
109
110 // Stops observing notifications. We will no longer act on client auth
111 // notifications.
112 void StopObserving();
113
114 private:
115 scoped_refptr<net::SSLCertRequestInfo> cert_request_info_;
116
117 scoped_refptr<SSLClientAuthHandler> handler_;
118
[email protected]6c2381d2011-10-19 02:52:53119 content::NotificationRegistrar notification_registrar_;
[email protected]d39dbf12011-04-18 23:37:31120
121 DISALLOW_COPY_AND_ASSIGN(SSLClientAuthObserver);
122};
123
[email protected]74b962a2011-06-03 21:22:54124#endif // CONTENT_BROWSER_SSL_SSL_CLIENT_AUTH_HANDLER_H_