blob: 75976877a3cecbb9642726379eadb1bb92d5a538 [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"
davidben6cd57dd2014-12-12 19:23:579#include "base/callback.h"
[email protected]3b63f8f42011-03-28 01:54:1510#include "base/memory/ref_counted.h"
davidben6cd57dd2014-12-12 19:23:5711#include "base/memory/weak_ptr.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;
[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
[email protected]89f23a32012-10-24 22:31:2421namespace content {
22
davidben78fee7d2014-12-03 19:41:5123// This class handles the approval and selection of a certificate for SSL client
davidben6cd57dd2014-12-12 19:23:5724// authentication by the user. Should only be used on the IO thread. If the
25// SSLClientAuthHandler is destroyed before the certificate is selected, the
26// selection is canceled and the callback never called.
27class SSLClientAuthHandler {
davidben78fee7d2014-12-03 19:41:5128 public:
davidben5b6618d2014-12-08 20:41:3929 using CertificateCallback = base::Callback<void(net::X509Certificate*)>;
30
[email protected]1ccb6992013-10-30 04:46:2031 SSLClientAuthHandler(scoped_ptr<net::ClientCertStore> client_cert_store,
32 net::URLRequest* request,
davidben5b6618d2014-12-08 20:41:3933 net::SSLCertRequestInfo* cert_request_info,
34 const CertificateCallback& callback);
davidben6cd57dd2014-12-12 19:23:5735 ~SSLClientAuthHandler();
[email protected]ce2b62262009-06-27 05:11:4136
[email protected]c99c442e2011-08-24 11:37:3037 // Selects a certificate and resumes the URL request with that certificate.
[email protected]ce2b62262009-06-27 05:11:4138 void SelectCertificate();
39
[email protected]ce2b62262009-06-27 05:11:4140 private:
davidben6cd57dd2014-12-12 19:23:5741 class Core;
davidben78fee7d2014-12-03 19:41:5142
davidben6cd57dd2014-12-12 19:23:5743 // Called when |core_| is done retrieving the cert list.
[email protected]1ccb6992013-10-30 04:46:2044 void DidGetClientCerts();
45
davidben21d28492015-01-31 18:34:3946 // Called when the user has selected a cert. If the user chose to continue
47 // with no certificate, |cert| is NULL.
davidben6cd57dd2014-12-12 19:23:5748 void CertificateSelected(net::X509Certificate* cert);
davidben78fee7d2014-12-03 19:41:5149
davidben6cd57dd2014-12-12 19:23:5750 // A reference-counted core so the ClientCertStore may outlive
51 // SSLClientAuthHandler if the handler is destroyed while an operation on the
52 // ClientCertStore is in progress.
53 scoped_refptr<Core> core_;
[email protected]c61769052011-05-18 18:38:3554
[email protected]6981d9632010-11-30 21:34:0255 // The net::URLRequest that triggered this client auth.
[email protected]edfe7fab2010-11-28 13:11:5256 net::URLRequest* request_;
[email protected]ce2b62262009-06-27 05:11:4157
[email protected]ce2b62262009-06-27 05:11:4158 // The certs to choose from.
59 scoped_refptr<net::SSLCertRequestInfo> cert_request_info_;
60
davidben5b6618d2014-12-08 20:41:3961 // The callback to call when the certificate is selected.
62 CertificateCallback callback_;
63
davidben6cd57dd2014-12-12 19:23:5764 base::WeakPtrFactory<SSLClientAuthHandler> weak_factory_;
65
[email protected]ce2b62262009-06-27 05:11:4166 DISALLOW_COPY_AND_ASSIGN(SSLClientAuthHandler);
67};
68
[email protected]89f23a32012-10-24 22:31:2469} // namespace content
70
[email protected]74b962a2011-06-03 21:22:5471#endif // CONTENT_BROWSER_SSL_SSL_CLIENT_AUTH_HANDLER_H_