Skip to content

Commit 249f37c

Browse files
committed
tests/custom_ekus: Introduce tests for ExtendedKeyUsage::XRequiredIfYPresent
This introduces three test cases for XRequiredIfYPresent ExtendedKeyUsage policy. Signed-off-by: Stanislaw Grams <[email protected]>
1 parent f5a2f74 commit 249f37c

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

tests/custom_ekus.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,62 @@ pub fn verify_custom_eku_required_if_present() {
9797
let ca = include_bytes!("custom_ekus/cert_with_both_ekus_accepted_for_client_auth.ca.der");
9898
check_cert(ee, ca, eku, time, Ok(()));
9999
}
100+
101+
#[test]
102+
pub fn verify_x_required_if_y_present_without_y() {
103+
let time = UnixTime::since_unix_epoch(Duration::from_secs(0x1fed_f00d));
104+
105+
let server_auth_oid = &[43, 6, 1, 5, 5, 7, 3, 1]; // id-kp-serverAuth
106+
let client_auth_oid = &[43, 6, 1, 5, 5, 7, 3, 2]; // id-kp-clientAuth
107+
108+
let eku = KeyUsage::x_required_if_y_present(server_auth_oid, client_auth_oid);
109+
110+
let ee = include_bytes!("custom_ekus/cert_with_no_eku_accepted_for_client_auth.ee.der");
111+
let ca = include_bytes!("custom_ekus/cert_with_no_eku_accepted_for_client_auth.ca.der");
112+
check_cert(ee, ca, eku, time, Ok(()));
113+
}
114+
115+
#[test]
116+
pub fn verify_x_required_if_y_present_with_other_ekus() {
117+
let time = UnixTime::since_unix_epoch(Duration::from_secs(0x1fed_f00d));
118+
119+
let server_auth_oid = &[43, 6, 1, 5, 5, 7, 3, 1]; // id-kp-serverAuth
120+
let client_auth_oid = &[43, 6, 1, 5, 5, 7, 3, 2]; // id-kp-clientAuth
121+
122+
let eku = KeyUsage::x_required_if_y_present(server_auth_oid, client_auth_oid);
123+
124+
let ee = include_bytes!("custom_ekus/cert_with_both_ekus_accepted_for_client_auth.ee.der");
125+
let ca = include_bytes!("custom_ekus/cert_with_both_ekus_accepted_for_client_auth.ca.der");
126+
check_cert(ee, ca, eku, time, Ok(()));
127+
}
128+
129+
#[test]
130+
pub fn verify_x_required_if_y_present_negative_case() {
131+
let time = UnixTime::since_unix_epoch(Duration::from_secs(0x1fed_f00d));
132+
133+
// Negative test: require a non-existent EKU when client-auth is present
134+
// Using a made-up OID that definitely won't be in any certificate
135+
let non_existent_oid = &[99, 99, 99, 99, 99, 99, 99, 99]; // mock non-existent OID
136+
let client_auth_oid = &[43, 6, 1, 5, 5, 7, 3, 2]; // id-kp-clientAuth
137+
138+
let eku = KeyUsage::x_required_if_y_present(non_existent_oid, client_auth_oid);
139+
140+
let ee = include_bytes!("custom_ekus/cert_with_both_ekus_accepted_for_client_auth.ee.der");
141+
let ca = include_bytes!("custom_ekus/cert_with_both_ekus_accepted_for_client_auth.ca.der");
142+
143+
check_cert(
144+
ee,
145+
ca,
146+
eku,
147+
time,
148+
Err(webpki::Error::RequiredEkuNotFoundContext(
149+
RequiredEkuNotFoundContext {
150+
required: eku,
151+
present: vec![
152+
vec![1, 3, 6, 1, 5, 5, 7, 3, 2], // id-kp-clientAuth (decoded)
153+
vec![1, 3, 6, 1, 5, 5, 7, 3, 1], // id-kp-serverAuth (decoded)
154+
],
155+
},
156+
)),
157+
);
158+
}

0 commit comments

Comments
 (0)