Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix using expired cert in tests #3435

Merged
merged 1 commit into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 33 additions & 33 deletions src/AppInstallerCLITests/Certificates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,76 +13,76 @@ using namespace AppInstaller::Certificates;
TEST_CASE("Certificates_NoPinningSucceeds", "[certificates]")
{
PinningDetails expected;
expected.LoadCertificate(IDX_CERTIFICATE_STORE_ROOT_1).SetPinning(PinningVerificationType::None);
expected.LoadCertificate(IDX_CERTIFICATE_STORE_ROOT_2).SetPinning(PinningVerificationType::None);

PinningDetails actual;
actual.LoadCertificate(IDX_CERTIFICATE_STORE_LEAF_1);
actual.LoadCertificate(IDX_CERTIFICATE_STORE_LEAF_2);

REQUIRE(expected.Validate(actual.GetCertificate()));
}

TEST_CASE("Certificates_PublicKeyMismatch", "[certificates]")
{
PinningDetails expected;
expected.LoadCertificate(IDX_CERTIFICATE_STORE_ROOT_1).SetPinning(PinningVerificationType::PublicKey);
expected.LoadCertificate(IDX_CERTIFICATE_STORE_ROOT_2).SetPinning(PinningVerificationType::PublicKey);

PinningDetails actual;
actual.LoadCertificate(IDX_CERTIFICATE_STORE_LEAF_1);
actual.LoadCertificate(IDX_CERTIFICATE_STORE_LEAF_2);

REQUIRE(!expected.Validate(actual.GetCertificate()));
}

TEST_CASE("Certificates_PublicKeyMatch", "[certificates]")
{
PinningDetails expected;
expected.LoadCertificate(IDX_CERTIFICATE_STORE_ROOT_1).SetPinning(PinningVerificationType::PublicKey);
expected.LoadCertificate(IDX_CERTIFICATE_STORE_ROOT_2).SetPinning(PinningVerificationType::PublicKey);

PinningDetails actual;
actual.LoadCertificate(IDX_CERTIFICATE_STORE_ROOT_1);
actual.LoadCertificate(IDX_CERTIFICATE_STORE_ROOT_2);

REQUIRE(expected.Validate(actual.GetCertificate()));
}

TEST_CASE("Certificates_SubjectMismatch", "[certificates]")
{
PinningDetails expected;
expected.LoadCertificate(IDX_CERTIFICATE_STORE_ROOT_1).SetPinning(PinningVerificationType::Subject);
expected.LoadCertificate(IDX_CERTIFICATE_STORE_ROOT_2).SetPinning(PinningVerificationType::Subject);

PinningDetails actual;
actual.LoadCertificate(IDX_CERTIFICATE_STORE_INTERMEDIATE_1);
actual.LoadCertificate(IDX_CERTIFICATE_STORE_INTERMEDIATE_2);

REQUIRE(!expected.Validate(actual.GetCertificate()));
}

TEST_CASE("Certificates_SubjectMatch", "[certificates]")
{
PinningDetails expected;
expected.LoadCertificate(IDX_CERTIFICATE_STORE_INTERMEDIATE_1).SetPinning(PinningVerificationType::Subject);
expected.LoadCertificate(IDX_CERTIFICATE_STORE_INTERMEDIATE_2).SetPinning(PinningVerificationType::Subject);

PinningDetails actual;
actual.LoadCertificate(IDX_CERTIFICATE_STORE_INTERMEDIATE_1);
actual.LoadCertificate(IDX_CERTIFICATE_STORE_INTERMEDIATE_2);

REQUIRE(expected.Validate(actual.GetCertificate()));
}

TEST_CASE("Certificates_IssuerMismatch", "[certificates]")
{
PinningDetails expected;
expected.LoadCertificate(IDX_CERTIFICATE_STORE_INTERMEDIATE_1).SetPinning(PinningVerificationType::Issuer);
expected.LoadCertificate(IDX_CERTIFICATE_STORE_INTERMEDIATE_2).SetPinning(PinningVerificationType::Issuer);

PinningDetails actual;
actual.LoadCertificate(IDX_CERTIFICATE_STORE_LEAF_1);
actual.LoadCertificate(IDX_CERTIFICATE_STORE_LEAF_2);

REQUIRE(!expected.Validate(actual.GetCertificate()));
}

TEST_CASE("Certificates_IssuerMatch", "[certificates]")
{
PinningDetails expected;
expected.LoadCertificate(IDX_CERTIFICATE_STORE_LEAF_1).SetPinning(PinningVerificationType::Issuer);
expected.LoadCertificate(IDX_CERTIFICATE_STORE_LEAF_2).SetPinning(PinningVerificationType::Issuer);

PinningDetails actual;
actual.LoadCertificate(IDX_CERTIFICATE_STORE_LEAF_1);
actual.LoadCertificate(IDX_CERTIFICATE_STORE_LEAF_2);

REQUIRE(expected.Validate(actual.GetCertificate()));
}
Expand All @@ -91,15 +91,15 @@ TEST_CASE("Certificates_ChainLengthDiffers", "[certificates]")
{
PinningChain chain;
auto chainElement = chain.Root();
chainElement->LoadCertificate(IDX_CERTIFICATE_STORE_ROOT_1).SetPinning(PinningVerificationType::PublicKey);
chainElement->LoadCertificate(IDX_CERTIFICATE_STORE_ROOT_2).SetPinning(PinningVerificationType::PublicKey);
chainElement = chainElement.Next();
chainElement->LoadCertificate(IDX_CERTIFICATE_STORE_LEAF_1).SetPinning(PinningVerificationType::Subject | PinningVerificationType::Issuer);
chainElement->LoadCertificate(IDX_CERTIFICATE_STORE_LEAF_2).SetPinning(PinningVerificationType::Subject | PinningVerificationType::Issuer);

PinningConfiguration config;
config.AddChain(chain);

PinningDetails details;
details.LoadCertificate(IDX_CERTIFICATE_STORE_LEAF_1);
details.LoadCertificate(IDX_CERTIFICATE_STORE_LEAF_2);

REQUIRE(!config.Validate(details.GetCertificate()));
}
Expand All @@ -112,7 +112,7 @@ TEST_CASE("Certificates_EmptyChainRejects", "[certificates]")
config.AddChain(chain);

PinningDetails details;
details.LoadCertificate(IDX_CERTIFICATE_STORE_LEAF_1);
details.LoadCertificate(IDX_CERTIFICATE_STORE_LEAF_2);

REQUIRE(!config.Validate(details.GetCertificate()));
}
Expand All @@ -121,17 +121,17 @@ TEST_CASE("Certificates_ChainOrderDiffers", "[certificates]")
{
PinningChain chain;
auto chainElement = chain.Root();
chainElement->LoadCertificate(IDX_CERTIFICATE_STORE_ROOT_1).SetPinning(PinningVerificationType::PublicKey);
chainElement->LoadCertificate(IDX_CERTIFICATE_STORE_ROOT_2).SetPinning(PinningVerificationType::PublicKey);
chainElement = chainElement.Next();
chainElement->LoadCertificate(IDX_CERTIFICATE_STORE_LEAF_1).SetPinning(PinningVerificationType::Subject | PinningVerificationType::Issuer);
chainElement->LoadCertificate(IDX_CERTIFICATE_STORE_LEAF_2).SetPinning(PinningVerificationType::Subject | PinningVerificationType::Issuer);
chainElement = chainElement.Next();
chainElement->LoadCertificate(IDX_CERTIFICATE_STORE_INTERMEDIATE_1).SetPinning(PinningVerificationType::Subject | PinningVerificationType::Issuer);
chainElement->LoadCertificate(IDX_CERTIFICATE_STORE_INTERMEDIATE_2).SetPinning(PinningVerificationType::Subject | PinningVerificationType::Issuer);

PinningConfiguration config;
config.AddChain(chain);

PinningDetails details;
details.LoadCertificate(IDX_CERTIFICATE_STORE_LEAF_1);
details.LoadCertificate(IDX_CERTIFICATE_STORE_LEAF_2);

REQUIRE(!config.Validate(details.GetCertificate()));
}
Expand All @@ -140,17 +140,17 @@ TEST_CASE("Certificates_StoreChain_BuiltInTest", "[certificates]")
{
PinningChain chain;
auto chainElement = chain.Root();
chainElement->LoadCertificate(IDX_CERTIFICATE_STORE_ROOT_1).SetPinning(PinningVerificationType::PublicKey);
chainElement->LoadCertificate(IDX_CERTIFICATE_STORE_ROOT_2).SetPinning(PinningVerificationType::PublicKey);
chainElement = chainElement.Next();
chainElement->LoadCertificate(IDX_CERTIFICATE_STORE_INTERMEDIATE_1).SetPinning(PinningVerificationType::Subject | PinningVerificationType::Issuer);
chainElement->LoadCertificate(IDX_CERTIFICATE_STORE_INTERMEDIATE_2).SetPinning(PinningVerificationType::Subject | PinningVerificationType::Issuer);
chainElement = chainElement.Next();
chainElement->LoadCertificate(IDX_CERTIFICATE_STORE_LEAF_1).SetPinning(PinningVerificationType::Subject | PinningVerificationType::Issuer);
chainElement->LoadCertificate(IDX_CERTIFICATE_STORE_LEAF_2).SetPinning(PinningVerificationType::Subject | PinningVerificationType::Issuer);

PinningConfiguration config;
config.AddChain(chain);

PinningDetails details;
details.LoadCertificate(IDX_CERTIFICATE_STORE_LEAF_1);
details.LoadCertificate(IDX_CERTIFICATE_STORE_LEAF_2);

REQUIRE(config.Validate(details.GetCertificate()));
}
Expand All @@ -159,27 +159,27 @@ TEST_CASE("Certificates_MultipleChains_Success", "[certificates]")
{
PinningChain chainOutOfOrder;
auto chainElement = chainOutOfOrder.Root();
chainElement->LoadCertificate(IDX_CERTIFICATE_STORE_ROOT_1).SetPinning(PinningVerificationType::PublicKey);
chainElement->LoadCertificate(IDX_CERTIFICATE_STORE_ROOT_2).SetPinning(PinningVerificationType::PublicKey);
chainElement = chainElement.Next();
chainElement->LoadCertificate(IDX_CERTIFICATE_STORE_LEAF_1).SetPinning(PinningVerificationType::Subject | PinningVerificationType::Issuer);
chainElement->LoadCertificate(IDX_CERTIFICATE_STORE_LEAF_2).SetPinning(PinningVerificationType::Subject | PinningVerificationType::Issuer);
chainElement = chainElement.Next();
chainElement->LoadCertificate(IDX_CERTIFICATE_STORE_INTERMEDIATE_1).SetPinning(PinningVerificationType::Subject | PinningVerificationType::Issuer);
chainElement->LoadCertificate(IDX_CERTIFICATE_STORE_INTERMEDIATE_2).SetPinning(PinningVerificationType::Subject | PinningVerificationType::Issuer);

PinningConfiguration config;
config.AddChain(chainOutOfOrder);

PinningChain chain;
chainElement = chain.Root();
chainElement->LoadCertificate(IDX_CERTIFICATE_STORE_ROOT_1).SetPinning(PinningVerificationType::PublicKey);
chainElement->LoadCertificate(IDX_CERTIFICATE_STORE_ROOT_2).SetPinning(PinningVerificationType::PublicKey);
chainElement = chainElement.Next();
chainElement->LoadCertificate(IDX_CERTIFICATE_STORE_INTERMEDIATE_1).SetPinning(PinningVerificationType::Subject | PinningVerificationType::Issuer);
chainElement->LoadCertificate(IDX_CERTIFICATE_STORE_INTERMEDIATE_2).SetPinning(PinningVerificationType::Subject | PinningVerificationType::Issuer);
chainElement = chainElement.Next();
chainElement->LoadCertificate(IDX_CERTIFICATE_STORE_LEAF_1).SetPinning(PinningVerificationType::Subject | PinningVerificationType::Issuer);
chainElement->LoadCertificate(IDX_CERTIFICATE_STORE_LEAF_2).SetPinning(PinningVerificationType::Subject | PinningVerificationType::Issuer);

config.AddChain(chain);

PinningDetails details;
details.LoadCertificate(IDX_CERTIFICATE_STORE_LEAF_1);
details.LoadCertificate(IDX_CERTIFICATE_STORE_LEAF_2);

REQUIRE(config.Validate(details.GetCertificate()));
}
6 changes: 3 additions & 3 deletions src/AppInstallerCLITests/GroupPolicy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,11 @@ TEST_CASE("GroupPolicy_Sources", "[groupPolicy]")
auto additionalSourcesKey = RegCreateVolatileSubKey(policiesKey.get(), AdditionalSourcesPolicyKeyName);

PinningDetails rootCert;
rootCert.LoadCertificate(IDX_CERTIFICATE_STORE_ROOT_1);
rootCert.LoadCertificate(IDX_CERTIFICATE_STORE_ROOT_2);
PinningDetails intermediateCert;
intermediateCert.LoadCertificate(IDX_CERTIFICATE_STORE_INTERMEDIATE_1);
intermediateCert.LoadCertificate(IDX_CERTIFICATE_STORE_INTERMEDIATE_2);
PinningDetails leafCert;
leafCert.LoadCertificate(IDX_CERTIFICATE_STORE_LEAF_1);
leafCert.LoadCertificate(IDX_CERTIFICATE_STORE_LEAF_2);

auto getBytesString = [](const PinningDetails& details)
{
Expand Down
6 changes: 3 additions & 3 deletions src/AppInstallerCLITests/HttpClientHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ TEST_CASE("HttpClientHelper_PinningConfiguration", "[RestSource]")
// Create the Store chain config
PinningChain chain;
auto chainElement = chain.Root();
chainElement->LoadCertificate(IDX_CERTIFICATE_STORE_ROOT_1).SetPinning(PinningVerificationType::PublicKey);
chainElement->LoadCertificate(IDX_CERTIFICATE_STORE_ROOT_2).SetPinning(PinningVerificationType::PublicKey);
chainElement = chainElement.Next();
chainElement->LoadCertificate(IDX_CERTIFICATE_STORE_INTERMEDIATE_1).SetPinning(PinningVerificationType::Subject | PinningVerificationType::Issuer);
chainElement->LoadCertificate(IDX_CERTIFICATE_STORE_INTERMEDIATE_2).SetPinning(PinningVerificationType::Subject | PinningVerificationType::Issuer);
chainElement = chainElement.Next();
chainElement->LoadCertificate(IDX_CERTIFICATE_STORE_LEAF_1).SetPinning(PinningVerificationType::Subject | PinningVerificationType::Issuer);
chainElement->LoadCertificate(IDX_CERTIFICATE_STORE_LEAF_2).SetPinning(PinningVerificationType::Subject | PinningVerificationType::Issuer);

PinningConfiguration config;
config.AddChain(chain);
Expand Down