Skip to content

Commit 3cf322b

Browse files
gowthamsk-armtgonzalezorlandoarm
authored andcommitted
e2e_tests: Update mismatced key/certificate test to use parsec provider
Signed-off-by: Gowtham Suresh Kumar <[email protected]>
1 parent 694f209 commit 3cf322b

File tree

2 files changed

+33
-24
lines changed

2 files changed

+33
-24
lines changed

parsec-openssl-provider-shared/e2e_tests/src/lib.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,28 @@ impl Client {
176176
}
177177
}
178178
}
179+
180+
pub fn check_mismatched_key_certificate(key: String, certificate: String) {
181+
unsafe {
182+
let provider_path = String::from("../../target/debug/");
183+
let provider_name = String::from("libparsec_openssl_provider_shared");
184+
let lib_ctx = LibCtx::new().unwrap();
185+
let _provider: Provider = load_provider(&lib_ctx, &provider_name, provider_path);
186+
187+
let mut parsec_pkey: *mut EVP_PKEY = std::ptr::null_mut();
188+
189+
let mut ctx_builder = SslContextBuilder::new(SslMethod::tls_client()).unwrap();
190+
191+
ctx_builder
192+
.set_certificate_file(certificate, SslFiletype::PEM)
193+
.unwrap();
194+
195+
let mut param = ossl_param!(PARSEC_PROVIDER_KEY_NAME, OSSL_PARAM_UTF8_PTR, key);
196+
load_key(&lib_ctx, &mut param, &mut parsec_pkey, RSA);
197+
198+
let key: openssl::pkey::PKey<Private> = openssl::pkey::PKey::from_ptr(parsec_pkey as _);
199+
200+
// The match function gets called here to compare public and private key and it should throw an error.
201+
ctx_builder.set_private_key(&key).unwrap_err();
202+
}
203+
}

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

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -200,35 +200,19 @@ fn test_handshake_client_authentication_with_fake_ca() {
200200
// public key from the x509 certificate.
201201
#[test]
202202
fn test_client_with_mismatched_rsa_key_and_certificate() {
203-
let mut ctx_builder = SslContext::builder(SslMethod::tls_client()).unwrap();
204-
205-
ctx_builder
206-
.set_certificate_file(
207-
String::from("../../tests/tls/fake_client/parsec_rsa.pem"),
208-
SslFiletype::PEM,
209-
)
210-
.unwrap();
211-
212-
ctx_builder
213-
.set_private_key_file(String::from("PARSEC_TEST_RSA_KEY"), SslFiletype::PEM)
214-
.unwrap_err();
203+
check_mismatched_key_certificate(
204+
String::from("PARSEC_TEST_RSA_KEY"),
205+
String::from("../../tests/tls/fake_client/parsec_rsa.pem"),
206+
);
215207
}
216208

217209
// This is a negative test case. When a client is configured with a wrong certificate for a private
218210
// key, the key management match function should report an error about the mismatched private key and
219211
// public key from the x509 certificate.
220212
#[test]
221213
fn test_client_with_mismatched_ecdsa_key_and_certificate() {
222-
let mut ctx_builder = SslContext::builder(SslMethod::tls_client()).unwrap();
223-
224-
ctx_builder
225-
.set_certificate_file(
226-
String::from("../../tests/tls/fake_client/parsec_ecdsa.pem"),
227-
SslFiletype::PEM,
228-
)
229-
.unwrap();
230-
231-
ctx_builder
232-
.set_private_key_file(String::from("PARSEC_TEST_ECDSA_KEY"), SslFiletype::PEM)
233-
.unwrap_err();
214+
check_mismatched_key_certificate(
215+
String::from("PARSEC_TEST_ECDSA_KEY"),
216+
String::from("../../tests/tls/fake_client/parsec_ecdsa.pem"),
217+
);
234218
}

0 commit comments

Comments
 (0)