Skip to content

Commit

Permalink
follow up feedback from Richard
Browse files Browse the repository at this point in the history
  • Loading branch information
suhasHere committed Apr 24, 2021
1 parent f0533d9 commit eb8cc4a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 22 deletions.
12 changes: 6 additions & 6 deletions lib/hpke/include/hpke/certificate.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ struct Certificate

using ParsedName = std::map<int, std::string>;

// Certificate Status
enum struct Status
// Certificate Expiration Status
enum struct ExpirationStatus
{
expired,
inactive,
active
inactive, // now < notBefore
active, // notBefore < now < notAfter
expired, // notAfter < now
};

explicit Certificate(const bytes& der);
Expand All @@ -53,7 +53,7 @@ struct Certificate
ParsedName issuer() const;
ParsedName subject() const;
bool is_ca() const;
Status status() const;
ExpirationStatus expiration_status() const;

std::optional<bytes> subject_key_id() const;
std::optional<bytes> authority_key_id() const;
Expand Down
14 changes: 7 additions & 7 deletions lib/hpke/src/certificate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,20 +234,20 @@ struct Certificate::ParsedCertificate
return make_typed_unique<EVP_PKEY>(X509_get_pubkey(x509.get()));
}

Certificate::Status status() const
Certificate::ExpirationStatus expiration_status() const
{
auto* not_before = X509_get_notBefore(x509.get());
auto* not_after = X509_get_notAfter(x509.get());

if (X509_cmp_current_time(not_before) > 0) {
return Certificate::Status::inactive;
return Certificate::ExpirationStatus::inactive;
}

if (X509_cmp_current_time(not_after) < 0) {
return Certificate::Status::expired;
return Certificate::ExpirationStatus::expired;
}

return Certificate::Status::active;
return Certificate::ExpirationStatus::active;
}

bytes raw() const
Expand Down Expand Up @@ -383,10 +383,10 @@ Certificate::is_ca() const
return parsed_cert->is_ca;
}

Certificate::Status
Certificate::status() const
Certificate::ExpirationStatus
Certificate::expiration_status() const
{
return parsed_cert->status();
return parsed_cert->expiration_status();
}

std::optional<bytes>
Expand Down
11 changes: 3 additions & 8 deletions lib/hpke/test/certificate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ TEST_CASE("Certificate Known-Answer depth 2")
CHECK_FALSE(issuing.valid_from(leaf));
CHECK_FALSE(root.valid_from(issuing));
CHECK_FALSE(root.valid_from(leaf));
auto status = root.status();
REQUIRE(status == Certificate::Status::expired);
}

TEST_CASE("Certificate Known-Answer depth 2 with SKID/ADID")
Expand Down Expand Up @@ -489,8 +487,7 @@ TEST_CASE("Test Certificate notBefore status")
"4d134de11eca367f9d967d6eae14192454770a2fc278963602");

auto root = Certificate{ root_der };
auto status = root.status();
REQUIRE(status == Certificate::Status::inactive);
REQUIRE(root.expiration_status() == Certificate::ExpirationStatus::inactive);
}

TEST_CASE("Test Certificate notAfter status")
Expand All @@ -509,8 +506,7 @@ TEST_CASE("Test Certificate notAfter status")
"e4e7d2b0606050b2e0edcfc8d6390b373e21f08116910b");

auto root = Certificate{ root_der };
auto status = root.status();
REQUIRE(status == Certificate::Status::expired);
REQUIRE(root.expiration_status() == Certificate::ExpirationStatus::expired);
}

TEST_CASE("Test Certificate active status")
Expand All @@ -530,6 +526,5 @@ TEST_CASE("Test Certificate active status")
"16a821444907e84cd4fb88167f1c3a4d4911f8260dafb21b05");

auto root = Certificate{ root_der };
auto status = root.status();
REQUIRE(status == Certificate::Status::active);
REQUIRE(root.expiration_status() == Certificate::ExpirationStatus::active);
}
1 change: 0 additions & 1 deletion scripts/cert-gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
)

var (

notBefore = time.Now().Add(-2 * 24 * time.Hour)
notAfter = time.Now().Add(99 * 365 * 24 * time.Hour)

Expand Down

0 comments on commit eb8cc4a

Please sign in to comment.