blob: 0b2e9cb8b52784c1a18506b0630e9180e38e5e12 [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]5f945a0e2011-03-01 17:47:5311#include "content/browser/browser_thread.h"
[email protected]d39dbf12011-04-18 23:37:3112#include "content/common/notification_observer.h"
13#include "content/common/notification_registrar.h"
[email protected]ce2b62262009-06-27 05:11:4114#include "net/base/ssl_cert_request_info.h"
15
16namespace net {
[email protected]ce2b62262009-06-27 05:11:4117class URLRequest;
[email protected]edfe7fab2010-11-28 13:11:5218class X509Certificate;
19} // namespace net
[email protected]ce2b62262009-06-27 05:11:4120
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]6981d9632010-11-30 21:34:0224// when the net::URLRequest is cancelled.
[email protected]11f4857282009-11-13 19:56:1725class SSLClientAuthHandler
[email protected]1f18184a2010-07-21 19:34:4926 : public base::RefCountedThreadSafe<SSLClientAuthHandler,
[email protected]9a7e1502010-10-08 04:03:5027 BrowserThread::DeleteOnIOThread> {
[email protected]ce2b62262009-06-27 05:11:4128 public:
[email protected]edfe7fab2010-11-28 13:11:5229 SSLClientAuthHandler(net::URLRequest* request,
[email protected]0d3dc8e22009-11-03 02:27:0130 net::SSLCertRequestInfo* cert_request_info);
[email protected]ce2b62262009-06-27 05:11:4131
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]b1f184942010-03-04 01:46:5741 // 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]d39dbf12011-04-18 23:37:3146 // 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]1f18184a2010-07-21 19:34:4951 // Returns the SSLCertRequestInfo for this handler.
52 net::SSLCertRequestInfo* cert_request_info() { return cert_request_info_; }
53
[email protected]ce2b62262009-06-27 05:11:4154 private:
[email protected]092b04e2010-10-12 23:23:4455 friend class BrowserThread;
[email protected]1f18184a2010-07-21 19:34:4956 friend class DeleteTask<SSLClientAuthHandler>;
[email protected]e6e6ba42009-11-07 01:56:1957
[email protected]02d08e02010-10-08 17:50:4658 virtual ~SSLClientAuthHandler();
[email protected]e6e6ba42009-11-07 01:56:1959
[email protected]ce2b62262009-06-27 05:11:4160 // Notifies that the user has selected a cert.
61 // Called on the IO thread.
[email protected]3e1fc8e2010-02-18 22:45:0562 void DoCertificateSelected(net::X509Certificate* cert);
[email protected]ce2b62262009-06-27 05:11:4163
[email protected]c61769052011-05-18 18:38:3564 // 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]6981d9632010-11-30 21:34:0268 // The net::URLRequest that triggered this client auth.
[email protected]edfe7fab2010-11-28 13:11:5269 net::URLRequest* request_;
[email protected]ce2b62262009-06-27 05:11:4170
71 // The certs to choose from.
72 scoped_refptr<net::SSLCertRequestInfo> cert_request_info_;
73
[email protected]ce2b62262009-06-27 05:11:4174 DISALLOW_COPY_AND_ASSIGN(SSLClientAuthHandler);
75};
76
[email protected]d39dbf12011-04-18 23:37:3177class 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]74b962a2011-06-03 21:22:54111#endif // CONTENT_BROWSER_SSL_SSL_CLIENT_AUTH_HANDLER_H_