blob: 6774287975f5f1a903937888821eef970b8a6aa4 [file] [log] [blame]
[email protected]f7867172012-07-11 07:04:071// Copyright (c) 2012 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]ce2b62262009-06-27 05:11:417
8#include "base/basictypes.h"
[email protected]3b63f8f42011-03-28 01:54:159#include "base/memory/ref_counted.h"
davidben78fee7d2014-12-03 19:41:5110#include "base/sequenced_task_runner_helpers.h"
11#include "content/common/content_export.h"
[email protected]c38831a12011-10-28 12:44:4912#include "content/public/browser/browser_thread.h"
[email protected]536fd0b2013-03-14 17:41:5713#include "net/ssl/ssl_cert_request_info.h"
[email protected]ce2b62262009-06-27 05:11:4114
15namespace net {
[email protected]1ccb6992013-10-30 04:46:2016class ClientCertStore;
davidben78fee7d2014-12-03 19:41:5117class HttpNetworkSession;
[email protected]ce2b62262009-06-27 05:11:4118class URLRequest;
[email protected]edfe7fab2010-11-28 13:11:5219class X509Certificate;
20} // namespace net
[email protected]ce2b62262009-06-27 05:11:4121
[email protected]89f23a32012-10-24 22:31:2422namespace content {
23
davidben78fee7d2014-12-03 19:41:5124class ResourceContext;
robliaoe9651b352014-11-26 18:01:5025
davidben78fee7d2014-12-03 19:41:5126// This class handles the approval and selection of a certificate for SSL client
27// authentication by the user.
28// It is self-owned and deletes itself when the UI reports the user selection or
29// when the net::URLRequest is cancelled.
30class CONTENT_EXPORT SSLClientAuthHandler
31 : public base::RefCountedThreadSafe<
32 SSLClientAuthHandler, BrowserThread::DeleteOnIOThread> {
33 public:
davidben5b6618d2014-12-08 20:41:3934 using CertificateCallback = base::Callback<void(net::X509Certificate*)>;
35
[email protected]1ccb6992013-10-30 04:46:2036 SSLClientAuthHandler(scoped_ptr<net::ClientCertStore> client_cert_store,
37 net::URLRequest* request,
davidben5b6618d2014-12-08 20:41:3938 net::SSLCertRequestInfo* cert_request_info,
39 const CertificateCallback& callback);
[email protected]ce2b62262009-06-27 05:11:4140
[email protected]c99c442e2011-08-24 11:37:3041 // Selects a certificate and resumes the URL request with that certificate.
davidben78fee7d2014-12-03 19:41:5142 // Should only be called on the IO thread.
[email protected]ce2b62262009-06-27 05:11:4143 void SelectCertificate();
44
davidben78fee7d2014-12-03 19:41:5145 // Invoked when the request associated with this handler is cancelled.
46 // Should only be called on the IO thread.
47 void OnRequestCancelled();
48
49 // Calls DoCertificateSelected on the I/O thread.
50 // Called on the UI thread after the user has made a selection (which may
51 // be long after DoSelectCertificate returns, if the UI is modeless/async.)
52 void CertificateSelected(net::X509Certificate* cert);
53
54 protected:
55 virtual ~SSLClientAuthHandler();
56
[email protected]ce2b62262009-06-27 05:11:4157 private:
davidben78fee7d2014-12-03 19:41:5158 friend class base::RefCountedThreadSafe<
59 SSLClientAuthHandler, BrowserThread::DeleteOnIOThread>;
60 friend class BrowserThread;
61 friend class base::DeleteHelper<SSLClientAuthHandler>;
62
[email protected]1ccb6992013-10-30 04:46:2063 // Called when ClientCertStore is done retrieving the cert list.
64 void DidGetClientCerts();
65
davidben78fee7d2014-12-03 19:41:5166 // Notifies that the user has selected a cert.
67 // Called on the IO thread.
68 void DoCertificateSelected(net::X509Certificate* cert);
69
70 // Selects a client certificate on the UI thread.
71 void DoSelectCertificate(int render_process_host_id,
72 int render_frame_host_id);
[email protected]c61769052011-05-18 18:38:3573
[email protected]6981d9632010-11-30 21:34:0274 // The net::URLRequest that triggered this client auth.
[email protected]edfe7fab2010-11-28 13:11:5275 net::URLRequest* request_;
[email protected]ce2b62262009-06-27 05:11:4176
[email protected]ce2b62262009-06-27 05:11:4177 // The certs to choose from.
78 scoped_refptr<net::SSLCertRequestInfo> cert_request_info_;
79
[email protected]1ccb6992013-10-30 04:46:2080 scoped_ptr<net::ClientCertStore> client_cert_store_;
81
davidben5b6618d2014-12-08 20:41:3982 // The callback to call when the certificate is selected.
83 CertificateCallback callback_;
84
[email protected]ce2b62262009-06-27 05:11:4185 DISALLOW_COPY_AND_ASSIGN(SSLClientAuthHandler);
86};
87
[email protected]89f23a32012-10-24 22:31:2488} // namespace content
89
[email protected]74b962a2011-06-03 21:22:5490#endif // CONTENT_BROWSER_SSL_SSL_CLIENT_AUTH_HANDLER_H_