|
|
@ -1,4 +1,4 @@ |
|
|
|
use crate::crypto::{HashFunction, KeyType, X509Certificate};
|
|
|
|
use crate::crypto::{HashFunction, KeyType, X509Certificate, CRT_NB_DAYS_VALIDITY};
|
|
|
|
use std::collections::HashSet;
|
|
|
|
use std::iter::FromIterator;
|
|
|
|
|
|
|
@ -52,6 +52,34 @@ eX1G4/Av0XE7RqJ3Frq8qa5EjjLJTw0iEaWS5NGtZxMqWEIetCgb0IDZNxNvbeAv |
|
|
|
mmH6qnF3xQPx5FkwP/Yw4d9T4KhSHNf2/tImIlbuk3SEsOglGbKNY1juor8uw+J2
|
|
|
|
5XsUZxD5QiDbCFd3dGmH58XmkiQHXs8hhIbhu9ZLgp+fNv0enVMHTTI1gGpZ5MPm
|
|
|
|
-----END CERTIFICATE-----"#;
|
|
|
|
const CERTIFICATE_EXPIRED_PEM: &str = r#"-----BEGIN CERTIFICATE-----
|
|
|
|
MIIEsTCCA5mgAwIBAgISBApMImYflPdX7BYLjinQ+ErUMA0GCSqGSIb3DQEBCwUA
|
|
|
|
MEoxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MSMwIQYDVQQD
|
|
|
|
ExpMZXQncyBFbmNyeXB0IEF1dGhvcml0eSBYMzAeFw0xOTExMzAxODQxNTZaFw0y
|
|
|
|
MDAyMjgxODQxNTZaMBExDzANBgNVBAMTBmJ6aC50ZjB2MBAGByqGSM49AgEGBSuB
|
|
|
|
BAAiA2IABLSEIYJpT2SM+F9mEzFypkqbBm64dgX0KnyZuYGB2qHHsBLIBBK5Ev9Y
|
|
|
|
vPvYb8lzX3uJFHPn0JwPpGR0YBzPHBspyvwrhedokt8pNFEDC1eE4BH9XVN35utt
|
|
|
|
EGP1ZT92mKOCAnYwggJyMA4GA1UdDwEB/wQEAwIHgDAdBgNVHSUEFjAUBggrBgEF
|
|
|
|
BQcDAQYIKwYBBQUHAwIwDAYDVR0TAQH/BAIwADAdBgNVHQ4EFgQUOALpvHYbvH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RwEnimTffjnIX6xqol+2bcxMuLWxt9
|
|
|
|
HmjTgcY4JMMcOAiNk3roJK9ayMi7jn0Cd097BFnvx08+oWSMOZ29hFHMHp3KCSzT
|
|
|
|
bQg4DAU6E9VT+pvyGsc1NNyREKxOlDkam3CqfYc0oAowjn11MmDac2aKP8Pyt4pk
|
|
|
|
ehm+yKg=
|
|
|
|
-----END CERTIFICATE-----"#;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_san_domains() {
|
|
|
@ -132,3 +160,22 @@ fn generate_ed448_certificate() { |
|
|
|
.unwrap();
|
|
|
|
assert_eq!(kp.key_type, KeyType::Ed448);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn cert_expiration_date_future() {
|
|
|
|
let (_, crt) =
|
|
|
|
X509Certificate::from_acme_ext("example.org", "", KeyType::EcdsaP256, HashFunction::Sha256)
|
|
|
|
.unwrap();
|
|
|
|
let duration = crt.expires_in().unwrap().as_secs();
|
|
|
|
let validity_sec = CRT_NB_DAYS_VALIDITY as u64 * 24 * 60 * 60;
|
|
|
|
let delta = 60;
|
|
|
|
assert!(duration > validity_sec - delta);
|
|
|
|
assert!(duration < validity_sec + delta);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn cert_expiration_date_past() {
|
|
|
|
let crt = X509Certificate::from_pem(CERTIFICATE_EXPIRED_PEM.as_bytes()).unwrap();
|
|
|
|
let duration = crt.expires_in().unwrap().as_secs();
|
|
|
|
assert_eq!(duration, 0);
|
|
|
|
}
|