#include "net/cert/cert_verify_proc_builtin.h"
#include <optional>
#include <string_view>
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/numerics/safe_conversions.h"
#include "base/ranges/algorithm.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "components/network_time/time_tracker/time_tracker.h"
#include "net/base/features.h"
#include "net/base/net_errors.h"
#include "net/base/test_completion_callback.h"
#include "net/cert/cert_verify_proc.h"
#include "net/cert/crl_set.h"
#include "net/cert/do_nothing_ct_verifier.h"
#include "net/cert/ev_root_ca_metadata.h"
#include "net/cert/internal/system_trust_store.h"
#include "net/cert/sct_status_flags.h"
#include "net/cert/time_conversions.h"
#include "net/cert/x509_util.h"
#include "net/cert_net/cert_net_fetcher_url_request.h"
#include "net/http/transport_security_state.h"
#include "net/log/net_log_with_source.h"
#include "net/log/test_net_log.h"
#include "net/test/cert_builder.h"
#include "net/test/cert_test_util.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "net/test/embedded_test_server/request_handler_util.h"
#include "net/test/gtest_util.h"
#include "net/test/revocation_builder.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_builder.h"
#include "net/url_request/url_request_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/boringssl/src/pki/trust_store.h"
#include "third_party/boringssl/src/pki/trust_store_collection.h"
#include "third_party/boringssl/src/pki/trust_store_in_memory.h"
#if BUILDFLAG(CHROME_ROOT_STORE_SUPPORTED)
#include "base/version_info/version_info.h"
#endif
IsError;
IsOk;
_;
namespace net {
namespace {
std::unique_ptr<test_server::HttpResponse> HangRequestAndCallback(
base::OnceClosure callback,
const test_server::HttpRequest& request) { … }
void FailTest(const std::string& message) { … }
std::unique_ptr<test_server::HttpResponse> FailRequestAndFailTest(
const std::string& message,
scoped_refptr<base::TaskRunner> main_task_runner,
const test_server::HttpRequest& request) { … }
std::unique_ptr<test_server::HttpResponse> ServeResponse(
HttpStatusCode status_code,
const std::string& content_type,
const std::string& content,
const test_server::HttpRequest& request) { … }
std::string MakeRandomHexString(size_t num_bytes) { … }
static std::string MakeRandomPath(std::string_view suffix) { … }
int VerifyOnWorkerThread(const scoped_refptr<CertVerifyProc>& verify_proc,
scoped_refptr<X509Certificate> cert,
const std::string& hostname,
const std::string& ocsp_response,
const std::string& sct_list,
int flags,
CertVerifyResult* verify_result,
NetLogSource* out_source) { … }
class MockSystemTrustStore : public SystemTrustStore { … };
class BlockingTrustStore : public bssl::TrustStore { … };
class MockCTVerifier : public CTVerifier { … };
class MockCTPolicyEnforcer : public CTPolicyEnforcer { … };
}
class CertVerifyProcBuiltinTest : public ::testing::Test { … };
TEST_F(CertVerifyProcBuiltinTest, ShouldBypassHSTS) { … }
TEST_F(CertVerifyProcBuiltinTest, SimpleSuccess) { … }
TEST_F(CertVerifyProcBuiltinTest, CallsCtVerifierAndReturnsSctStatus) { … }
#if defined(PLATFORM_USES_CHROMIUM_EV_METADATA)
TEST_F(CertVerifyProcBuiltinTest, EVCertStatusMaintainedForCompliantCert) { … }
#endif
TEST_F(CertVerifyProcBuiltinTest, DistrustedIntermediate) { … }
TEST_F(CertVerifyProcBuiltinTest, AddedRootWithConstraints) { … }
TEST_F(CertVerifyProcBuiltinTest, AddedRootWithConstraintsNotEnforced) { … }
TEST_F(CertVerifyProcBuiltinTest, AddedRootWithOutsideDNSConstraints) { … }
TEST_F(CertVerifyProcBuiltinTest,
AddedRootWithOutsideDNSConstraintsNotMatched) { … }
TEST_F(CertVerifyProcBuiltinTest, AddedRootWithOutsideCIDRConstraints) { … }
TEST_F(CertVerifyProcBuiltinTest,
AddedRootWithOutsideCIDRConstraintsNotMatched) { … }
TEST_F(CertVerifyProcBuiltinTest, AddedRootWithBadTime) { … }
TEST_F(CertVerifyProcBuiltinTest, AddedRootWithBadTimeButNotEnforced) { … }
TEST_F(CertVerifyProcBuiltinTest, TimeTracker) { … }
TEST_F(CertVerifyProcBuiltinTest, TimeTrackerFailureIsRetriedWithSystemTime) { … }
TEST_F(CertVerifyProcBuiltinTest, CRLNotCheckedForKnownRoots) { … }
TEST_F(CertVerifyProcBuiltinTest, RevocationCheckDeadlineCRL) { … }
TEST_F(CertVerifyProcBuiltinTest, RevocationCheckDeadlineOCSP) { … }
#if defined(PLATFORM_USES_CHROMIUM_EV_METADATA)
TEST_F(CertVerifyProcBuiltinTest, EVNoOCSPRevocationChecks) { … }
#endif
#if BUILDFLAG(CHROME_ROOT_STORE_SUPPORTED)
scoped_refptr<ct::SignedCertificateTimestamp> MakeSct(base::Time t,
std::string_view log_id) { … }
TEST_F(CertVerifyProcBuiltinTest,
ChromeRootStoreConstraintSctConstraintsWithCtDisabled) { … }
TEST_F(CertVerifyProcBuiltinTest, ChromeRootStoreConstraintSctNotAfter) { … }
TEST_F(CertVerifyProcBuiltinTest,
ChromeRootStoreConstraintSctNotAfterLogUnknown) { … }
TEST_F(
CertVerifyProcBuiltinTest,
ChromeRootStoreConstraintSctNotAfterFromDisqualifiedLogBeforeDisqualification) { … }
TEST_F(
CertVerifyProcBuiltinTest,
ChromeRootStoreConstraintSctNotAfterFromDisqualifiedLogAfterDisqualification) { … }
TEST_F(CertVerifyProcBuiltinTest,
ChromeRootStoreConstraintSctNotAfterFromFutureDisqualifiedLog) { … }
TEST_F(CertVerifyProcBuiltinTest, ChromeRootStoreConstraintSctAllAfter) { … }
std::string CurVersionString() { … }
std::string NextVersionString() { … }
std::string PrevVersionString() { … }
TEST_F(CertVerifyProcBuiltinTest, ChromeRootStoreConstraintMinVersion) { … }
TEST_F(CertVerifyProcBuiltinTest, ChromeRootStoreConstraintMaxVersion) { … }
TEST_F(CertVerifyProcBuiltinTest, ChromeRootStoreConstraintMinAndMaxVersion) { … }
TEST_F(CertVerifyProcBuiltinTest,
ChromeRootStoreConstraintMultipleConstraints) { … }
TEST_F(CertVerifyProcBuiltinTest,
ChromeRootStoreConstraintNotEnforcedIfAnchorLocallyTrusted) { … }
TEST_F(CertVerifyProcBuiltinTest,
ChromeRootStoreConstraintNotEnforcedIfAnchorAdditionallyTrusted) { … }
#endif
TEST_F(CertVerifyProcBuiltinTest, DeadlineExceededDuringSyncGetIssuers) { … }
namespace {
std::string UnknownSignatureAlgorithmTLV() { … }
std::string InvalidSignatureAlgorithmTLV() { … }
}
TEST_F(CertVerifyProcBuiltinTest, UnknownSignatureAlgorithmTarget) { … }
TEST_F(CertVerifyProcBuiltinTest,
UnparsableMismatchedTBSSignatureAlgorithmTarget) { … }
TEST_F(CertVerifyProcBuiltinTest, UnknownSignatureAlgorithmIntermediate) { … }
TEST_F(CertVerifyProcBuiltinTest,
UnparsableMismatchedTBSSignatureAlgorithmIntermediate) { … }
TEST_F(CertVerifyProcBuiltinTest, UnknownSignatureAlgorithmRoot) { … }
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_UnparsableMismatchedTBSSignatureAlgorithmRoot …
#else
#define MAYBE_UnparsableMismatchedTBSSignatureAlgorithmRoot …
#endif
TEST_F(CertVerifyProcBuiltinTest,
MAYBE_UnparsableMismatchedTBSSignatureAlgorithmRoot) { … }
TEST_F(CertVerifyProcBuiltinTest, IterationLimit) { … }
}