Skip to content

Commit

Permalink
nixos/tests/acme: Fix fullchain validation (#346023)
Browse files Browse the repository at this point in the history
  • Loading branch information
flokli authored Oct 3, 2024
2 parents 77a6708 + b275888 commit 3398bb1
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions nixos/tests/acme.nix
Original file line number Diff line number Diff line change
Expand Up @@ -471,14 +471,18 @@ in {
# Ensure cert comes before chain in fullchain.pem
def check_fullchain(node, cert_name):
subject_data = node.succeed(
f"openssl crl2pkcs7 -nocrl -certfile /var/lib/acme/{cert_name}/fullchain.pem"
" | openssl pkcs7 -print_certs -noout"
cert_file = f"/var/lib/acme/{cert_name}/fullchain.pem"
num_certs = node.succeed(f"grep -o 'END CERTIFICATE' {cert_file}")
assert len(num_certs.strip().split("\n")) > 1, "Insufficient certs in fullchain.pem"
first_cert_data = node.succeed(
f"grep -m1 -B50 'END CERTIFICATE' {cert_file}"
" | openssl x509 -noout -text"
)
for line in subject_data.lower().split("\n"):
if "subject" in line:
print(f"First subject in fullchain.pem: {line}")
assert cert_name.lower() in line
for line in first_cert_data.lower().split("\n"):
if "dns:" in line:
print(f"First DNSName in fullchain.pem: {line}")
assert cert_name.lower() in line, f"{cert_name} not found in {line}"
return
assert False
Expand Down

0 comments on commit 3398bb1

Please sign in to comment.