1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_ENTERPRISE_SIGNALS_CLIENT_CERTIFICATE_FETCHER_H_
#define CHROME_BROWSER_ENTERPRISE_SIGNALS_CLIENT_CERTIFICATE_FETCHER_H_
#include <memory>
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "net/base/host_port_pair.h"
#include "net/cert/x509_certificate.h"
#include "net/ssl/client_cert_identity.h"
#include "url/gurl.h"
class Profile;
namespace content {
class BrowserContext;
}
namespace net {
class ClientCertStore;
class SSLCertRequestInfo;
} // namespace net
namespace enterprise_signals {
// Class that wraps a ProfileNetworkContextService instance to allow easier
// mocking of that instance in unit tests.
class ProfileNetworkContextServiceWrapper {
public:
virtual ~ProfileNetworkContextServiceWrapper() = default;
virtual std::unique_ptr<net::ClientCertStore> CreateClientCertStore() = 0;
virtual void FlushCachedClientCertIfNeeded(
const net::HostPortPair& host,
const scoped_refptr<net::X509Certificate>& certificate) = 0;
};
class ClientCertificateFetcher {
public:
ClientCertificateFetcher(std::unique_ptr<ProfileNetworkContextServiceWrapper>
profile_network_context_service_wrapper,
Profile* profile);
~ClientCertificateFetcher();
static std::unique_ptr<ClientCertificateFetcher> Create(
content::BrowserContext* browser_context);
using FetchAutoSelectedCertificateForUrlCallback =
base::OnceCallback<void(std::unique_ptr<net::ClientCertIdentity>)>;
void FetchAutoSelectedCertificateForUrl(
const GURL& url,
FetchAutoSelectedCertificateForUrlCallback callback);
private:
void OnGetClientCertsComplete(const GURL& url,
net::ClientCertIdentityList client_certs);
std::unique_ptr<ProfileNetworkContextServiceWrapper>
profile_network_context_service_wrapper_;
std::unique_ptr<net::ClientCertStore> client_cert_store_;
raw_ptr<Profile> profile_;
FetchAutoSelectedCertificateForUrlCallback fetch_callback_;
scoped_refptr<net::SSLCertRequestInfo> cert_request_info_;
base::WeakPtrFactory<ClientCertificateFetcher> weak_ptr_factory_{this};
};
} // namespace enterprise_signals
#endif // CHROME_BROWSER_ENTERPRISE_SIGNALS_CLIENT_CERTIFICATE_FETCHER_H_
|