#include "components/enterprise/client_certificates/core/certificate_store.h"
#include <memory>
#include <string>
#include "base/containers/span.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/memory/weak_ptr.h"
#include "base/pickle.h"
#include "base/task/thread_pool.h"
#include "components/enterprise/client_certificates/core/private_key.h"
#include "components/enterprise/client_certificates/core/private_key_factory.h"
#include "components/enterprise/client_certificates/proto/client_certificates_database.pb.h"
#include "components/leveldb_proto/public/proto_database_provider.h"
#include "components/leveldb_proto/public/shared_proto_database_client_list.h"
#include "net/cert/x509_certificate.h"
namespace client_certificates {
namespace {
const base::FilePath::StringPieceType kClientCertsDbPath = …);
void OnIdentityFetched(
base::OnceCallback<void(
StoreErrorOr<std::unique_ptr<client_certificates_pb::ClientIdentity>>)>
callback,
bool success,
std::unique_ptr<client_certificates_pb::ClientIdentity> identity) { … }
void OnKeyLoaded(
const std::string& identity_name,
scoped_refptr<net::X509Certificate> certificate,
base::OnceCallback<void(StoreErrorOr<std::optional<ClientIdentity>>)>
callback,
scoped_refptr<PrivateKey> private_key) { … }
void OnCertificateCommitted(
base::OnceCallback<void(std::optional<StoreError>)> callback,
bool success) { … }
void SetCertificate(client_certificates_pb::ClientIdentity& proto_identity,
net::X509Certificate& certificate) { … }
}
class CertificateStoreImpl : public CertificateStore { … };
CertificateStore::CertificateStore() = default;
CertificateStore::~CertificateStore() = default;
std::unique_ptr<CertificateStore> CertificateStore::Create(
const base::FilePath& profile_dir,
leveldb_proto::ProtoDatabaseProvider* database_provider,
std::unique_ptr<PrivateKeyFactory> key_factory) { … }
std::unique_ptr<CertificateStore> CertificateStore::CreateForTesting(
std::unique_ptr<leveldb_proto::ProtoDatabase<
client_certificates_pb::ClientIdentity>> database,
std::unique_ptr<PrivateKeyFactory> key_factory) { … }
CertificateStoreImpl::CertificateStoreImpl(
std::unique_ptr<leveldb_proto::ProtoDatabase<
client_certificates_pb::ClientIdentity>> database,
std::unique_ptr<PrivateKeyFactory> key_factory)
: … { … }
CertificateStoreImpl::~CertificateStoreImpl() = default;
void CertificateStoreImpl::CreatePrivateKey(
const std::string& identity_name,
base::OnceCallback<void(StoreErrorOr<scoped_refptr<PrivateKey>>)>
callback) { … }
void CertificateStoreImpl::CommitCertificate(
const std::string& identity_name,
scoped_refptr<net::X509Certificate> certificate,
base::OnceCallback<void(std::optional<StoreError>)> callback) { … }
void CertificateStoreImpl::CommitIdentity(
const std::string& temporary_identity_name,
const std::string& final_identity_name,
scoped_refptr<net::X509Certificate> certificate,
base::OnceCallback<void(std::optional<StoreError>)> callback) { … }
void CertificateStoreImpl::GetIdentity(
const std::string& identity_name,
base::OnceCallback<void(StoreErrorOr<std::optional<ClientIdentity>>)>
callback) { … }
void CertificateStoreImpl::InitializeDatabase() { … }
void CertificateStoreImpl::OnDatabaseInitialized(
leveldb_proto::Enums::InitStatus status) { … }
void CertificateStoreImpl::WaitForInitializationAndGetIdentityProto(
const std::string& identity_name,
base::OnceCallback<void(
StoreErrorOr<std::unique_ptr<client_certificates_pb::ClientIdentity>>)>
callback) { … }
void CertificateStoreImpl::GetIdentityProto(
const std::string& identity_name,
base::OnceCallback<void(
StoreErrorOr<std::unique_ptr<client_certificates_pb::ClientIdentity>>)>
callback) { … }
void CertificateStoreImpl::CreatePrivateKeyInner(
const std::string& identity_name,
base::OnceCallback<void(StoreErrorOr<scoped_refptr<PrivateKey>>)> callback,
StoreErrorOr<std::unique_ptr<client_certificates_pb::ClientIdentity>>
proto_identity) { … }
void CertificateStoreImpl::OnPrivateKeyCreated(
const std::string& identity_name,
base::OnceCallback<void(StoreErrorOr<scoped_refptr<PrivateKey>>)> callback,
scoped_refptr<PrivateKey> private_key) { … }
void CertificateStoreImpl::OnPrivateKeySaved(
scoped_refptr<PrivateKey> private_key,
base::OnceCallback<void(StoreErrorOr<scoped_refptr<PrivateKey>>)> callback,
bool save_success) { … }
void CertificateStoreImpl::CommitCertificateInner(
const std::string& identity_name,
scoped_refptr<net::X509Certificate> certificate,
base::OnceCallback<void(std::optional<StoreError>)> callback,
StoreErrorOr<std::unique_ptr<client_certificates_pb::ClientIdentity>>
proto_identity) { … }
void CertificateStoreImpl::CommitIdentityInner(
const std::string& temporary_identity_name,
const std::string& final_identity_name,
scoped_refptr<net::X509Certificate> certificate,
base::OnceCallback<void(std::optional<StoreError>)> callback,
StoreErrorOr<std::unique_ptr<client_certificates_pb::ClientIdentity>>
proto_identity) { … }
void CertificateStoreImpl::GetIdentityInner(
const std::string& identity_name,
base::OnceCallback<void(StoreErrorOr<std::optional<ClientIdentity>>)>
callback,
StoreErrorOr<std::unique_ptr<client_certificates_pb::ClientIdentity>>
proto_identity) { … }
}