Skip to content

Commit a309e29

Browse files
gowthamsk-armtgonzalezorlandoarm
authored andcommitted
test: Add test for mismatched key and certificate
The key management match function compares the private key and the public key extracted from the x509 certificate when configured. This test checks if the match function is able to report an error when a wrong certificate is configured for the client. Signed-off-by: Gowtham Suresh Kumar <[email protected]>
1 parent 5dfdd91 commit a309e29

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

parsec-openssl-provider-shared/e2e_tests/tests/handshake.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,25 @@ fn test_handshake_client_authentication_with_fake_ca() {
151151
);
152152
client.connect(addr);
153153
}
154+
155+
// This is a negative test case. When a client is configured with a wrong certificate for a private
156+
// key, the key management match function should report an error about the mismatched private key and
157+
// public key from the x509 certificate.
158+
#[test]
159+
fn test_client_with_mismatched_key_and_certificate() {
160+
let mut ctx_builder = SslContext::builder(SslMethod::tls_client()).unwrap();
161+
162+
ctx_builder
163+
.set_certificate_file(
164+
String::from("../../tests/tls/fake_client/client_cert.pem"),
165+
SslFiletype::PEM,
166+
)
167+
.unwrap();
168+
169+
ctx_builder
170+
.set_private_key_file(
171+
String::from("../../tests/tls/client/client_priv_key.pem"),
172+
SslFiletype::PEM,
173+
)
174+
.unwrap_err();
175+
}

0 commit comments

Comments
 (0)