@@ -97,3 +97,62 @@ pub fn verify_custom_eku_required_if_present() {
97
97
let ca = include_bytes ! ( "custom_ekus/cert_with_both_ekus_accepted_for_client_auth.ca.der" ) ;
98
98
check_cert ( ee, ca, eku, time, Ok ( ( ) ) ) ;
99
99
}
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