Skip to content

Commit

Permalink
Regenerate certificates with sensible lifetimes and add script
Browse files Browse the repository at this point in the history
  • Loading branch information
jarhodes314 committed Nov 15, 2023
1 parent e2e1bb1 commit 0153108
Show file tree
Hide file tree
Showing 19 changed files with 156 additions and 133 deletions.
54 changes: 29 additions & 25 deletions crates/common/axum_tls/src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,27 +194,27 @@ mod tests {
}

fn copy_test_file_to(test_file: &str, path: impl AsRef<Path>) -> io::Result<u64> {
std::fs::copy(format!("./src/test_data/{test_file}"), path)
std::fs::copy(format!("./test_data/{test_file}"), path)
}
}

#[test]
fn load_pkey_fails_when_given_x509_certificate() {
assert_eq!(
load_pkey(Utf8Path::new("./src/test_data/ec.crt"))
load_pkey(Utf8Path::new("./test_data/ec.crt"))
.unwrap_err()
.to_string(),
"expected private key in \"./src/test_data/ec.crt\", found an X509 certificate"
"expected private key in \"./test_data/ec.crt\", found an X509 certificate"
);
}

#[test]
fn load_pkey_fails_when_given_certificate_revocation_list() {
assert_eq!(
load_pkey(Utf8Path::new("./src/test_data/demo.crl"))
load_pkey(Utf8Path::new("./test_data/demo.crl"))
.unwrap_err()
.to_string(),
"expected private key in \"./src/test_data/demo.crl\", found a CRL"
"expected private key in \"./test_data/demo.crl\", found a CRL"
);
}

Expand All @@ -223,56 +223,56 @@ mod tests {

#[tokio::test]
async fn alg_ed25519_pkcs8() {
let key = include_str!("test_data/ed25519.key");
let cert = include_str!("./test_data/ed25519.crt");
let key = test_data("ed25519.key");
let cert = test_data("ed25519.crt");

let (config, cert) = config_from_pem(key, cert).unwrap();
let (config, cert) = config_from_pem(&key, &cert).unwrap();

assert_matches!(parse_key_to_item(key), Item::PKCS8Key(_));
assert_matches!(parse_key_to_item(&key), Item::PKCS8Key(_));
assert_server_works_with(config, cert).await;
}

#[tokio::test]
async fn alg_ec() {
let key = include_str!("test_data/ec.key");
let cert = include_str!("./test_data/ec.crt");
let key = test_data("ec.key");
let cert = test_data("ec.crt");

let (config, cert) = config_from_pem(key, cert).unwrap();
let (config, cert) = config_from_pem(&key, &cert).unwrap();

assert_matches!(parse_key_to_item(key), Item::ECKey(_));
assert_matches!(parse_key_to_item(&key), Item::ECKey(_));
assert_server_works_with(config, cert).await;
}

#[tokio::test]
async fn alg_ec_pkcs8() {
let key = include_str!("test_data/ec.pkcs8.key");
let cert = include_str!("./test_data/ec.crt");
let key = test_data("ec.pkcs8.key");
let cert = test_data("ec.crt");

let (config, cert) = config_from_pem(key, cert).unwrap();
let (config, cert) = config_from_pem(&key, &cert).unwrap();

assert_matches!(parse_key_to_item(key), Item::PKCS8Key(_));
assert_matches!(parse_key_to_item(&key), Item::PKCS8Key(_));
assert_server_works_with(config, cert).await;
}

#[tokio::test]
async fn alg_rsa_pkcs8() {
let key = include_str!("./test_data/rsa.pkcs8.key");
let cert = include_str!("./test_data/rsa.crt");
let key = test_data("rsa.pkcs8.key");
let cert = test_data("rsa.crt");

let (config, cert) = config_from_pem(key, cert).unwrap();
let (config, cert) = config_from_pem(&key, &cert).unwrap();

assert_matches!(parse_key_to_item(key), Item::PKCS8Key(_));
assert_matches!(parse_key_to_item(&key), Item::PKCS8Key(_));
assert_server_works_with(config, cert).await;
}

#[tokio::test]
async fn alg_rsa_pkcs1() {
let key = include_str!("./test_data/rsa.pkcs1.key");
let cert = include_str!("./test_data/rsa.crt");
let key = test_data("rsa.pkcs1.key");
let cert = test_data("rsa.crt");

let (config, cert) = config_from_pem(key, cert).unwrap();
let (config, cert) = config_from_pem(&key, &cert).unwrap();

assert_matches!(parse_key_to_item(key), Item::RSAKey(_));
assert_matches!(parse_key_to_item(&key), Item::RSAKey(_));
assert_server_works_with(config, cert).await;
}

Expand All @@ -282,6 +282,10 @@ mod tests {
.unwrap()
}

fn test_data(file_name: &str) -> String {
std::fs::read_to_string(format!("./test_data/{file_name}")).with_context(|| format!("opening file {file_name} from test_data")).unwrap()
}

fn config_from_pem(
key: &str,
cert: &str,
Expand Down
11 changes: 0 additions & 11 deletions crates/common/axum_tls/src/test_data/ec.crt

This file was deleted.

5 changes: 0 additions & 5 deletions crates/common/axum_tls/src/test_data/ec.key

This file was deleted.

6 changes: 0 additions & 6 deletions crates/common/axum_tls/src/test_data/ec.pkcs8.key

This file was deleted.

9 changes: 0 additions & 9 deletions crates/common/axum_tls/src/test_data/ed25519.crt

This file was deleted.

3 changes: 0 additions & 3 deletions crates/common/axum_tls/src/test_data/ed25519.key

This file was deleted.

19 changes: 0 additions & 19 deletions crates/common/axum_tls/src/test_data/rsa.crt

This file was deleted.

27 changes: 0 additions & 27 deletions crates/common/axum_tls/src/test_data/rsa.pkcs1.key

This file was deleted.

28 changes: 0 additions & 28 deletions crates/common/axum_tls/src/test_data/rsa.pkcs8.key

This file was deleted.

19 changes: 19 additions & 0 deletions crates/common/axum_tls/test_data/_regenerate_certs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

# This script generates the certificates required for the "unit"
# tests in axum_tls using openssl

days=365000
args=("-days" "$days" "-noenc" \
-subj "/CN=localhost" \
-addext "subjectAltName=DNS:localhost,DNS:*.localhost" \
-addext "basicConstraints=critical,CA:false")

set -eux

openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 -keyout ec.pkcs8.key -out ec.crt "${args[@]}"
openssl req -x509 -newkey rsa -keyout rsa.pkcs8.key -out rsa.crt "${args[@]}"
openssl req -x509 -newkey ed25519 -keyout ed25519.key -out ed25519.crt "${args[@]}"

openssl ec -in ec.pkcs8.key -out ec.key
openssl pkey -in rsa.pkcs8.key -out rsa.pkcs1.key -traditional
File renamed without changes.
11 changes: 11 additions & 0 deletions crates/common/axum_tls/test_data/ec.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-----BEGIN CERTIFICATE-----
MIIBnzCCAUWgAwIBAgIUSTUtJUfUdERMKBwsfdRv9IbvQicwCgYIKoZIzj0EAwIw
FDESMBAGA1UEAwwJbG9jYWxob3N0MCAXDTIzMTExNDE2MDUwOVoYDzMwMjMwMzE3
MTYwNTA5WjAUMRIwEAYDVQQDDAlsb2NhbGhvc3QwWTATBgcqhkjOPQIBBggqhkjO
PQMBBwNCAAR2SVEPD34AAxFuk0xYm60p7hA7+1SW+sFHazBRg32ifFd0o2Mn+Tf+
voYflBi3v4lhr361RoWB8QfmaGN05vv+o3MwcTAdBgNVHQ4EFgQUAb4jQ7RQ/xyg
cZM+We8ik29/oxswHwYDVR0jBBgwFoAUAb4jQ7RQ/xygcZM+We8ik29/oxswIQYD
VR0RBBowGIIJbG9jYWxob3N0ggsqLmxvY2FsaG9zdDAMBgNVHRMBAf8EAjAAMAoG
CCqGSM49BAMCA0gAMEUCIA6QrxoDHQJqoly7d8VN0sj0eDvfFpbbZdSnzBd6R8AP
AiEAm/PAH3IPGuHRBIpdC0rNR8F/l3WcN9I9984qKZdG5rs=
-----END CERTIFICATE-----
5 changes: 5 additions & 0 deletions crates/common/axum_tls/test_data/ec.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-----BEGIN EC PRIVATE KEY-----
MHcCAQEEIBX2Z/NKGEX14QbH4kb5GXom0pqSPfX0mxdWbLb86apEoAoGCCqGSM49
AwEHoUQDQgAEdklRDw9+AAMRbpNMWJutKe4QO/tUlvrBR2swUYN9onxXdKNjJ/k3
/r6GH5QYt7+JYa9+tUaFgfEH5mhjdOb7/g==
-----END EC PRIVATE KEY-----
5 changes: 5 additions & 0 deletions crates/common/axum_tls/test_data/ec.pkcs8.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgFfZn80oYRfXhBsfi
RvkZeibSmpI99fSbF1ZstvzpqkShRANCAAR2SVEPD34AAxFuk0xYm60p7hA7+1SW
+sFHazBRg32ifFd0o2Mn+Tf+voYflBi3v4lhr361RoWB8QfmaGN05vv+
-----END PRIVATE KEY-----
10 changes: 10 additions & 0 deletions crates/common/axum_tls/test_data/ed25519.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-----BEGIN CERTIFICATE-----
MIIBXzCCARGgAwIBAgIUMTdemw1ehDhI74y1G3RVggvgS+kwBQYDK2VwMBQxEjAQ
BgNVBAMMCWxvY2FsaG9zdDAgFw0yMzExMTQxNjA1MTBaGA8zMDIzMDMxNzE2MDUx
MFowFDESMBAGA1UEAwwJbG9jYWxob3N0MCowBQYDK2VwAyEA/UW75ceWTm5/gUFx
s8E8V9hwunGiS3POOaOFRL1fsomjczBxMB0GA1UdDgQWBBT0bcj2U4AWeGQY6SNU
0VXdEcnjUDAfBgNVHSMEGDAWgBT0bcj2U4AWeGQY6SNU0VXdEcnjUDAhBgNVHREE
GjAYgglsb2NhbGhvc3SCCyoubG9jYWxob3N0MAwGA1UdEwEB/wQCMAAwBQYDK2Vw
A0EAw0W+9MuZ/yVpjgdBEYtDbgU41ESa4WwSwN9mLHcTtBrcFKhmHRe7zxoV50SB
hl/lsQ2UVNAAKA1xb5teTSN4AA==
-----END CERTIFICATE-----
3 changes: 3 additions & 0 deletions crates/common/axum_tls/test_data/ed25519.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEIHk0JP05MzYNxrJz86L9EZfdP9Etbo0qpFWfWGsHMqJz
-----END PRIVATE KEY-----
19 changes: 19 additions & 0 deletions crates/common/axum_tls/test_data/rsa.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-----BEGIN CERTIFICATE-----
MIIDKzCCAhOgAwIBAgIUYJV5nCxWPleHI2VvUR0N/PXW2AEwDQYJKoZIhvcNAQEL
BQAwFDESMBAGA1UEAwwJbG9jYWxob3N0MCAXDTIzMTExNDE2MDUxMFoYDzMwMjMw
MzE3MTYwNTEwWjAUMRIwEAYDVQQDDAlsb2NhbGhvc3QwggEiMA0GCSqGSIb3DQEB
AQUAA4IBDwAwggEKAoIBAQCl4CGc5yQkcZ8zU5oeovsITD+J/oJiNQjsXAwNHZM4
3vy4rrRlVCAHULMAecKfNwuUocETZVgU/XPKrTXhuNO+v0GmIF/bbCBk8oLRpzFI
ywCgaOzybzUzeF//80neA3O2Tiplb/Y5NzK/ECvn0oZLqHrdBJcsFmskpbBn7Fep
MVz4g5b7bHNim3f5PKwODRrMLTSpqKkVNmYsBTGfdRnrRM3X0EBmt3f9Zm1Vk2uI
F9AamjvvIB1JbSR9HSGP3kJqKOQoeyWvwa001JqwK25DRGZiOQcMxkZOpE5j03IL
6lfDFwsmGOC7cFWaN3O6XO/GdtSMU0Rq1Kr+d43TVdxNAgMBAAGjczBxMB0GA1Ud
DgQWBBRNCvr3snQQYV1CeBoefp97nOcq+jAfBgNVHSMEGDAWgBRNCvr3snQQYV1C
eBoefp97nOcq+jAhBgNVHREEGjAYgglsb2NhbGhvc3SCCyoubG9jYWxob3N0MAwG
A1UdEwEB/wQCMAAwDQYJKoZIhvcNAQELBQADggEBAB6mrO8ZbhKGR98m0NyzE2vK
PeQ8yasnUbLOf538afIlXNCEvKLQuQbYf2GlbT4fxWfimixf/iKkABYyTLGlTFMP
sM7+ZEhtALTO++S4eJJNF4+ZNE0WsBYQ5ZCv46AAYROipRYkUlVO6XGnggTBPeez
eQGImkni393b498P0qqH/PvFhwgH/T62N5kgKwhGcDuldYwmCqUYpvzWvFmUiC+x
BbrhE70ZSLsKQjglFT4Vx8bgqPQLRUgaku6SXBNcWhRf5vvED9PGBycZ3jOsLQc3
9q9piK+zSS/5AEwkTpljDg08n6AkfT8ODpHfa2XsoDf/qiVb7iTAMD+In+fIPy8=
-----END CERTIFICATE-----
27 changes: 27 additions & 0 deletions crates/common/axum_tls/test_data/rsa.pkcs1.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEApeAhnOckJHGfM1OaHqL7CEw/if6CYjUI7FwMDR2TON78uK60
ZVQgB1CzAHnCnzcLlKHBE2V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cym+k3+gGv+Zfv0Z/pp9E65dg3p1ujv2c/r9WHdTUP2bC4C0aMhZlJORkJvfN
TxhS1DOKqri+My82R3raIQKBgQDAOq7+YOI5CQ56GKJ2kRcS76KeGWT7WEHSacId
HrEtkpkNfNXhwYJlwASu10HrJfyTudtstcqEjTaQeOMmCT3ns0wPp7R+l7oQYjNO
EDwqHDPlb2oeq+yJfIqvE5bo8MlSam634jvdXGn8KCMcI13RB5EwwlvBGcnAhD/W
4QgsfQKBgBHpjB1XubP4SbjWQe64zES2cjWMskbCe+lBgVXs5CC42w1VoX5m3BdP
akWTNbMQqo/lB+htUJKrLQqdFCKUVeXG7GAk7xo0zynKSP8HyJLjmGBNzB1CTg1j
UCUPiJtM1ymPwQ18y9GEREjISg2ZDm4WIxBMzFI4PrNplUp9Uc7W
-----END RSA PRIVATE KEY-----
28 changes: 28 additions & 0 deletions crates/common/axum_tls/test_data/rsa.pkcs8.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCl4CGc5yQkcZ8z
U5oeovsITD+J/oJiNQjsXAwNHZM43vy4rrRlVCAHULMAecKfNwuUocETZVgU/XPK
rTXhuNO+v0GmIF/bbCBk8oLRpzFIywCgaOzybzUzeF//80neA3O2Tiplb/Y5NzK/
ECvn0oZLqHrdBJcsFmskpbBn7FepMVz4g5b7bHNim3f5PKwODRrMLTSpqKkVNmYs
BTGfdRnrRM3X0EBmt3f9Zm1Vk2uIF9AamjvvIB1JbSR9HSGP3kJqKOQoeyWvwa00
1JqwK25DRGZiOQcMxkZOpE5j03IL6lfDFwsmGOC7cFWaN3O6XO/GdtSMU0Rq1Kr+
d43TVdxNAgMBAAECggEABQsL1yVaVWt2y5y7jievl9QHEPJ0PHASkKFjX/tsCEem
ct3/fZWdAvY2CnNErhOd0tc1JdE1ung3PJEDzeaaWcR6WM/HhuF9vaUcC1BB96kk
F1f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