mirror of https://github.com/breard-r/acmed.git
Rodolphe Breard
4 years ago
7 changed files with 353 additions and 55 deletions
-
40acme_common/src/crypto/openssl_keys.rs
-
48acme_common/src/lib.rs
-
2acme_common/src/tests.rs
-
266acme_common/src/tests/crypto_keys.rs
-
42acme_common/src/tests/idna.rs
-
4acmed/src/jws.rs
-
6acmed/src/jws/algorithms.rs
@ -0,0 +1,2 @@ |
|||
mod crypto_keys;
|
|||
mod idna;
|
@ -0,0 +1,266 @@ |
|||
use crate::crypto::KeyPair;
|
|||
|
|||
const KEY_ECDSA_P256_PEM: &str = r#"-----BEGIN PRIVATE KEY-----
|
|||
MEECAQAwEwYHKoZIzj0CAQYIKoZIzj0DAQcEJzAlAgEBBCCQc9OXwvygYqOFT4fN
|
|||
NpXynr1lu+1sSplFdYoWu7hE4g==
|
|||
-----END PRIVATE KEY-----"#;
|
|||
const KEY_ECDSA_P384_PEM: &str = r#"-----BEGIN PRIVATE KEY-----
|
|||
ME4CAQAwEAYHKoZIzj0CAQYFK4EEACIENzA1AgEBBDCMsN9kHPueLABk+0PKi7WO
|
|||
PO2/53dpt/yV5zOPrYPEoKs4t973nbt46IUN19lLF/s=
|
|||
-----END PRIVATE KEY-----"#;
|
|||
const KEY_RSA_2048_PEM: &str = r#"-----BEGIN PRIVATE KEY-----
|
|||
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCzfwZGF8zKNAg2
|
|||
9mdZ9ieE7V2clY3oeI+2V7eV5kUwOGqhhpDaDyDmju+l0dKFwF8xeDeeGmTSED10
|
|||
e38ZsHqJF0cZqKDrB3hOeDAsn7Z6stHf/RZozQO5sAmZpN7g0P0lhXJnyAr+WL58
|
|||
X41kWuufiPVbvURQv/tK3yN2K+rC6MdZ2lLsLemKiwAlbyGrPfUzuVc6dXrU8JvX
|
|||
kkwuIpAyEEJ7OTXdBaT4VAHHtm2YDWIwW+34Otyp2FvbSJYsIwJjC00t7Phmah9b
|
|||
MjiypCZB6OknZV7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Ea1oH8k8HY13hC8q
|
|||
1Qw1Avr/yjgTfOhFySLcwi6CsrguFKOSVrum4sXvj6r4mdowXfqVr1aQkEc0gEHn
|
|||
ltXkUb5eN+khnDNjlO74qSYMf1Yn6hnWJNoYu23psym4J3MvgO19xmThhqah/Vjc
|
|||
98QIK3lHUlCzBN+vg6IxLe7uMUu6ltqG58Ybi7AtLgXX5snTeu97wR6B0RCzPUkY
|
|||
u9Spe0WQOxQRZdtOoCTyy4bJUc9WTT3LEhp0Uqa2lBBNSn8p224jGbiPwPbRU1+M
|
|||
/eQBAoIBAGTYVbha9dMdxlFnP63Cf2Ec7nraVSzm+6x414pCSosFTrl9eKI5dTV9
|
|||
zUsLfYVgqWcqGN3S5Q/8lM6ppmZapaUFrgKHtKdYEUnWBeobnrKR4iUSyqxlAKtJ
|
|||
fYfcw5ZfX8GHABopmKUC9UzarqhmM3Am423EGd1CUzseaWme52EUiAbbxSjlzhwM
|
|||
Q2ZTyps7X64dx6yOIRv6pPd3qZGRz2VoKW2x/sLoeErPsVtUW0u+NSKgR6O5sh7v
|
|||
Mc5vg/2W9HWaAXdjyrXIJyypitp0Q9M1cSowzt/BaWNvb3i/En8uEXR5zZjl/CFG
|
|||
yr9E4nQyE5YlYlPUK6iIRBu9j1N2MhY=
|
|||
-----END PRIVATE KEY-----"#;
|
|||
|
|||
#[test]
|
|||
fn test_ecdsa_p256_jwk() {
|
|||
let k = KeyPair::from_pem(KEY_ECDSA_P256_PEM.as_bytes()).unwrap();
|
|||
let jwk = k.jwk_public_key().unwrap();
|
|||
assert!(jwk.is_object());
|
|||
let jwk = jwk.as_object().unwrap();
|
|||
assert_eq!(jwk.len(), 6);
|
|||
assert!(jwk.contains_key("kty"));
|
|||
assert!(jwk.contains_key("crv"));
|
|||
assert!(jwk.contains_key("x"));
|
|||
assert!(jwk.contains_key("y"));
|
|||
assert!(jwk.contains_key("use"));
|
|||
assert!(jwk.contains_key("alg"));
|
|||
assert_eq!(jwk.get("kty").unwrap(), "EC");
|
|||
assert_eq!(jwk.get("crv").unwrap(), "P-256");
|
|||
assert_eq!(
|
|||
jwk.get("x").unwrap(),
|
|||
"VpJrz2a8rASzmbHStuDxNCjQc8ZiDnrGvVeRayNskrQ"
|
|||
);
|
|||
assert_eq!(
|
|||
jwk.get("y").unwrap(),
|
|||
"GrVCHhF5hN68efEgdoYS7acUT88qhMKQbULVcBgPBUg"
|
|||
);
|
|||
assert_eq!(jwk.get("use").unwrap(), "sig");
|
|||
assert_eq!(jwk.get("alg").unwrap(), "ES256");
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_ecdsa_p256_jwk_thumbprint() {
|
|||
let k = KeyPair::from_pem(KEY_ECDSA_P256_PEM.as_bytes()).unwrap();
|
|||
let jwk = k.jwk_public_key_thumbprint().unwrap();
|
|||
assert!(jwk.is_object());
|
|||
let jwk = jwk.as_object().unwrap();
|
|||
assert_eq!(jwk.len(), 4);
|
|||
assert!(jwk.contains_key("kty"));
|
|||
assert!(jwk.contains_key("crv"));
|
|||
assert!(jwk.contains_key("x"));
|
|||
assert!(jwk.contains_key("y"));
|
|||
assert!(!jwk.contains_key("use"));
|
|||
assert!(!jwk.contains_key("alg"));
|
|||
assert_eq!(jwk.get("kty").unwrap(), "EC");
|
|||
assert_eq!(jwk.get("crv").unwrap(), "P-256");
|
|||
assert_eq!(
|
|||
jwk.get("x").unwrap(),
|
|||
"VpJrz2a8rASzmbHStuDxNCjQc8ZiDnrGvVeRayNskrQ"
|
|||
);
|
|||
assert_eq!(
|
|||
jwk.get("y").unwrap(),
|
|||
"GrVCHhF5hN68efEgdoYS7acUT88qhMKQbULVcBgPBUg"
|
|||
);
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_ecdsa_p384_jwk() {
|
|||
let k = KeyPair::from_pem(KEY_ECDSA_P384_PEM.as_bytes()).unwrap();
|
|||
let jwk = k.jwk_public_key().unwrap();
|
|||
assert!(jwk.is_object());
|
|||
let jwk = jwk.as_object().unwrap();
|
|||
assert_eq!(jwk.len(), 6);
|
|||
assert!(jwk.contains_key("kty"));
|
|||
assert!(jwk.contains_key("crv"));
|
|||
assert!(jwk.contains_key("x"));
|
|||
assert!(jwk.contains_key("y"));
|
|||
assert!(jwk.contains_key("use"));
|
|||
assert!(jwk.contains_key("alg"));
|
|||
assert_eq!(jwk.get("kty").unwrap(), "EC");
|
|||
assert_eq!(jwk.get("crv").unwrap(), "P-384");
|
|||
assert_eq!(
|
|||
jwk.get("x").unwrap(),
|
|||
"N7TmS8prIp0DAGvwg1saML4UK61oe2PPJTeGLJt0iW-PMNcetFPcMF4WCa0ez80a"
|
|||
);
|
|||
assert_eq!(
|
|||
jwk.get("y").unwrap(),
|
|||
"RE5dtMDKV9Y8hsKf3fqLzMx75WORJaGswqC68xkRNjo0HcTar4tCB9VF9eSFfTMU"
|
|||
);
|
|||
assert_eq!(jwk.get("use").unwrap(), "sig");
|
|||
assert_eq!(jwk.get("alg").unwrap(), "ES384");
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_ecdsa_p384_jwk_thumbprint() {
|
|||
let k = KeyPair::from_pem(KEY_ECDSA_P384_PEM.as_bytes()).unwrap();
|
|||
let jwk = k.jwk_public_key_thumbprint().unwrap();
|
|||
assert!(jwk.is_object());
|
|||
let jwk = jwk.as_object().unwrap();
|
|||
assert_eq!(jwk.len(), 4);
|
|||
assert!(jwk.contains_key("kty"));
|
|||
assert!(jwk.contains_key("crv"));
|
|||
assert!(jwk.contains_key("x"));
|
|||
assert!(jwk.contains_key("y"));
|
|||
assert!(!jwk.contains_key("use"));
|
|||
assert!(!jwk.contains_key("alg"));
|
|||
assert_eq!(jwk.get("kty").unwrap(), "EC");
|
|||
assert_eq!(jwk.get("crv").unwrap(), "P-384");
|
|||
assert_eq!(
|
|||
jwk.get("x").unwrap(),
|
|||
"N7TmS8prIp0DAGvwg1saML4UK61oe2PPJTeGLJt0iW-PMNcetFPcMF4WCa0ez80a"
|
|||
);
|
|||
assert_eq!(
|
|||
jwk.get("y").unwrap(),
|
|||
"RE5dtMDKV9Y8hsKf3fqLzMx75WORJaGswqC68xkRNjo0HcTar4tCB9VF9eSFfTMU"
|
|||
);
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_rsa_2048_jwk() {
|
|||
let k = KeyPair::from_pem(KEY_RSA_2048_PEM.as_bytes()).unwrap();
|
|||
let jwk = k.jwk_public_key().unwrap();
|
|||
assert!(jwk.is_object());
|
|||
let jwk = jwk.as_object().unwrap();
|
|||
assert_eq!(jwk.len(), 5);
|
|||
assert!(jwk.contains_key("kty"));
|
|||
assert!(jwk.contains_key("e"));
|
|||
assert!(jwk.contains_key("n"));
|
|||
assert!(jwk.contains_key("use"));
|
|||
assert!(jwk.contains_key("alg"));
|
|||
assert_eq!(jwk.get("kty").unwrap(), "RSA");
|
|||
assert_eq!(jwk.get("e").unwrap(), "AQAB");
|
|||
assert_eq!(jwk.get("n").unwrap(), "s38GRhfMyjQINvZnWfYnhO1dnJWN6HiPtle3leZFMDhqoYaQ2g8g5o7vpdHShcBfMXg3nhpk0hA9dHt_GbB6iRdHGaig6wd4TngwLJ-2erLR3_0WaM0DubAJmaTe4ND9JYVyZ8gK_li-fF-NZFrrn4j1W71EUL_7St8jdivqwujHWdpS7C3piosAJW8hqz31M7lXOnV61PCb15JMLiKQMhBCezk13QWk-FQBx7ZtmA1iMFvt-Drcqdhb20iWLCMCYwtNLez4ZmofWzI4sqQmQejpJ2Ve1gGeeY2hf68qQEQf8804nksp-EIv1Y4qVhO5zvxo7m8s6ybUJqvqOz5u9Q");
|
|||
assert_eq!(jwk.get("use").unwrap(), "sig");
|
|||
assert_eq!(jwk.get("alg").unwrap(), "RS256");
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_rsa_2048_jwk_thumbprint() {
|
|||
let k = KeyPair::from_pem(KEY_RSA_2048_PEM.as_bytes()).unwrap();
|
|||
let jwk = k.jwk_public_key_thumbprint().unwrap();
|
|||
assert!(jwk.is_object());
|
|||
let jwk = jwk.as_object().unwrap();
|
|||
assert_eq!(jwk.len(), 3);
|
|||
assert!(jwk.contains_key("kty"));
|
|||
assert!(jwk.contains_key("e"));
|
|||
assert!(jwk.contains_key("n"));
|
|||
assert!(!jwk.contains_key("use"));
|
|||
assert!(!jwk.contains_key("alg"));
|
|||
assert_eq!(jwk.get("kty").unwrap(), "RSA");
|
|||
assert_eq!(jwk.get("e").unwrap(), "AQAB");
|
|||
assert_eq!(jwk.get("n").unwrap(), "s38GRhfMyjQINvZnWfYnhO1dnJWN6HiPtle3leZFMDhqoYaQ2g8g5o7vpdHShcBfMXg3nhpk0hA9dHt_GbB6iRdHGaig6wd4TngwLJ-2erLR3_0WaM0DubAJmaTe4ND9JYVyZ8gK_li-fF-NZFrrn4j1W71EUL_7St8jdivqwujHWdpS7C3piosAJW8hqz31M7lXOnV61PCb15JMLiKQMhBCezk13QWk-FQBx7ZtmA1iMFvt-Drcqdhb20iWLCMCYwtNLez4ZmofWzI4sqQmQejpJ2Ve1gGeeY2hf68qQEQf8804nksp-EIv1Y4qVhO5zvxo7m8s6ybUJqvqOz5u9Q");
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_rsa_4096_jwk() {
|
|||
let k = KeyPair::from_pem(KEY_RSA_4096_PEM.as_bytes()).unwrap();
|
|||
let jwk = k.jwk_public_key().unwrap();
|
|||
assert!(jwk.is_object());
|
|||
let jwk = jwk.as_object().unwrap();
|
|||
assert_eq!(jwk.len(), 5);
|
|||
assert!(jwk.contains_key("kty"));
|
|||
assert!(jwk.contains_key("e"));
|
|||
assert!(jwk.contains_key("n"));
|
|||
assert!(jwk.contains_key("use"));
|
|||
assert!(jwk.contains_key("alg"));
|
|||
assert_eq!(jwk.get("kty").unwrap(), "RSA");
|
|||
assert_eq!(jwk.get("e").unwrap(), "AQAB");
|
|||
assert_eq!(jwk.get("n").unwrap(), "jm0Jh8Zk-aRqUxME0yLeHhBtdDFq6IvVesr_ffFwGqtlI4tIa6MqYuuOE5qlqoBrxt1fpccqGF82j47JqeoWerkNdZxYh1uKGQa9G2vB4OBOFHxYujT-NNPPlwnVPrp1_pjxK0hiOGzZRliNhO65lMbEueQCaLbQ6wstr4aVsWKiw8O4MG8Cc2ZegkWlYg0ZHOAn-uJlAt17NJfX8x576XRwX2KCssPYeyiwBukRne3ahVVqrc35EmV9JH3CxDaG9MeBLo7FUV5P1GNOIs313cbAgdMYV6Ahr2LvsaLucFvhSwmHh42--meDui-0wdFILjrz7MsITZy4xXjl8_zqMZ2dBaO38wP5o9VCfCXaVlD3IYB9A4-Y9IQ6wEVeodzGloPQyddUZ70kZ7O3E1kYu0tBKhoAL1VcKiUvOj1ABGooqf8QIAWCiAWqDqkZJ5HiR61NC9lJ3MH-aqYXzeHUuOxdlfr3oWPQKlRyYoUW93xD4dXjHQyHsIS4gWYE9ZJ9aIomNHj93UPNfR8ScxQTQBJV9Ttgl_vOUdmlasTmo0OXbTLMexzWCVISvUuoBoTcTY4DXCFeYHz3EE3ijJ9fnDkX3SsvV43x8X58py9rEyAQnRxfeahpWEoxW6TA5qBxg1GMBQu6CY2MupqsmI0XHTXzy8xCt4Pqd_a5zP6Wh_E");
|
|||
assert_eq!(jwk.get("use").unwrap(), "sig");
|
|||
assert_eq!(jwk.get("alg").unwrap(), "RS256");
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_rsa_4096_jwk_thumbprint() {
|
|||
let k = KeyPair::from_pem(KEY_RSA_4096_PEM.as_bytes()).unwrap();
|
|||
let jwk = k.jwk_public_key_thumbprint().unwrap();
|
|||
assert!(jwk.is_object());
|
|||
let jwk = jwk.as_object().unwrap();
|
|||
assert_eq!(jwk.len(), 3);
|
|||
assert!(jwk.contains_key("kty"));
|
|||
assert!(jwk.contains_key("e"));
|
|||
assert!(jwk.contains_key("n"));
|
|||
assert!(!jwk.contains_key("use"));
|
|||
assert!(!jwk.contains_key("alg"));
|
|||
assert_eq!(jwk.get("kty").unwrap(), "RSA");
|
|||
assert_eq!(jwk.get("e").unwrap(), "AQAB");
|
|||
assert_eq!(jwk.get("n").unwrap(), "jm0Jh8Zk-aRqUxME0yLeHhBtdDFq6IvVesr_ffFwGqtlI4tIa6MqYuuOE5qlqoBrxt1fpccqGF82j47JqeoWerkNdZxYh1uKGQa9G2vB4OBOFHxYujT-NNPPlwnVPrp1_pjxK0hiOGzZRliNhO65lMbEueQCaLbQ6wstr4aVsWKiw8O4MG8Cc2ZegkWlYg0ZHOAn-uJlAt17NJfX8x576XRwX2KCssPYeyiwBukRne3ahVVqrc35EmV9JH3CxDaG9MeBLo7FUV5P1GNOIs313cbAgdMYV6Ahr2LvsaLucFvhSwmHh42--meDui-0wdFILjrz7MsITZy4xXjl8_zqMZ2dBaO38wP5o9VCfCXaVlD3IYB9A4-Y9IQ6wEVeodzGloPQyddUZ70kZ7O3E1kYu0tBKhoAL1VcKiUvOj1ABGooqf8QIAWCiAWqDqkZJ5HiR61NC9lJ3MH-aqYXzeHUuOxdlfr3oWPQKlRyYoUW93xD4dXjHQyHsIS4gWYE9ZJ9aIomNHj93UPNfR8ScxQTQBJV9Ttgl_vOUdmlasTmo0OXbTLMexzWCVISvUuoBoTcTY4DXCFeYHz3EE3ijJ9fnDkX3SsvV43x8X58py9rEyAQnRxfeahpWEoxW6TA5qBxg1GMBQu6CY2MupqsmI0XHTXzy8xCt4Pqd_a5zP6Wh_E");
|
|||
}
|
@ -0,0 +1,42 @@ |
|||
use crate::to_idna;
|
|||
|
|||
#[test]
|
|||
fn test_no_idna() {
|
|||
let idna_res = to_idna("HeLo.example.com");
|
|||
assert!(idna_res.is_ok());
|
|||
assert_eq!(idna_res.unwrap(), "helo.example.com");
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_simple_idna() {
|
|||
let idna_res = to_idna("Hélo.Example.com");
|
|||
assert!(idna_res.is_ok());
|
|||
assert_eq!(idna_res.unwrap(), "xn--hlo-bma.example.com");
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_multiple_idna() {
|
|||
let idna_res = to_idna("ns1.hÉlo.aç-éièè.example.com");
|
|||
assert!(idna_res.is_ok());
|
|||
assert_eq!(
|
|||
idna_res.unwrap(),
|
|||
"ns1.xn--hlo-bma.xn--a-i-2lahae.example.com"
|
|||
);
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_already_idna() {
|
|||
let idna_res = to_idna("xn--hlo-bma.example.com");
|
|||
assert!(idna_res.is_ok());
|
|||
assert_eq!(idna_res.unwrap(), "xn--hlo-bma.example.com");
|
|||
}
|
|||
|
|||
#[test]
|
|||
fn test_mixed_idna_parts() {
|
|||
let idna_res = to_idna("ns1.xn--hlo-bma.aç-éièè.example.com");
|
|||
assert!(idna_res.is_ok());
|
|||
assert_eq!(
|
|||
idna_res.unwrap(),
|
|||
"ns1.xn--hlo-bma.xn--a-i-2lahae.example.com"
|
|||
);
|
|||
}
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue