Skip to content

Commit 2fb177b

Browse files
gowthamsk-armtgonzalezorlandoarm
authored andcommitted
e2e_tests: Add key types to the test setup
Signed-off-by: Gowtham Suresh Kumar <[email protected]>
1 parent 3cf322b commit 2fb177b

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ pub use std::io::{Read, Write};
1313
pub use std::net::{SocketAddr, TcpListener, TcpStream};
1414
pub use std::thread::{self, JoinHandle};
1515

16-
const RSA: &[u8; 8] = b"RSA-PSS\0";
1716
use openssl::pkey::Private;
1817
use parsec_openssl_provider::parsec_openssl2::ossl_param;
1918
use parsec_openssl_provider::PARSEC_PROVIDER_KEY_NAME;
@@ -137,7 +136,7 @@ impl Client {
137136
}
138137

139138
// Creates a TCP stream and initiates a TLS handshake to the server
140-
pub fn connect(self, addr: SocketAddr) {
139+
pub fn connect(self, addr: SocketAddr, key_type: &[u8]) {
141140
unsafe {
142141
let provider_path = String::from("../../target/debug/");
143142
let provider_name = String::from("libparsec_openssl_provider_shared");
@@ -150,7 +149,7 @@ impl Client {
150149

151150
if let Some(key) = &self.private_key_name {
152151
let mut param = ossl_param!(PARSEC_PROVIDER_KEY_NAME, OSSL_PARAM_UTF8_PTR, key);
153-
load_key(&lib_ctx, &mut param, &mut parsec_pkey, RSA);
152+
load_key(&lib_ctx, &mut param, &mut parsec_pkey, key_type);
154153

155154
let key: openssl::pkey::PKey<Private> =
156155
openssl::pkey::PKey::from_ptr(parsec_pkey as _);
@@ -177,7 +176,7 @@ impl Client {
177176
}
178177
}
179178

180-
pub fn check_mismatched_key_certificate(key: String, certificate: String) {
179+
pub fn check_mismatched_key_certificate(key: String, certificate: String, key_type: &[u8]) {
181180
unsafe {
182181
let provider_path = String::from("../../target/debug/");
183182
let provider_name = String::from("libparsec_openssl_provider_shared");
@@ -193,7 +192,7 @@ pub fn check_mismatched_key_certificate(key: String, certificate: String) {
193192
.unwrap();
194193

195194
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);
195+
load_key(&lib_ctx, &mut param, &mut parsec_pkey, key_type);
197196

198197
let key: openssl::pkey::PKey<Private> = openssl::pkey::PKey::from_ptr(parsec_pkey as _);
199198

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// Copyright 2024 Contributors to the Parsec project.
22
// SPDX-License-Identifier: Apache-2.0
33
use e2e_tests::*;
4+
const RSA: &[u8; 8] = b"RSA-PSS\0";
5+
const ECDSA: &[u8; 3] = b"EC\0";
6+
const NONE: &[u8; 5] = b"None\0";
47

58
#[test]
69
fn test_handshake_no_authentication() {
@@ -16,7 +19,7 @@ fn test_handshake_no_authentication() {
1619
server.accept(listener);
1720

1821
let client = Client::new(None, None, None, SslVerifyMode::NONE);
19-
client.connect(addr);
22+
client.connect(addr, NONE);
2023
}
2124

2225
#[should_panic]
@@ -34,7 +37,7 @@ fn test_handshake_server_authentication_no_client_ca() {
3437
server.accept(listener);
3538

3639
let client = Client::new(None, None, None, SslVerifyMode::PEER);
37-
client.connect(addr);
40+
client.connect(addr, NONE);
3841
}
3942

4043
#[test]
@@ -56,7 +59,7 @@ fn test_handshake_server_authentication_with_client_ca() {
5659
Some(String::from("../../tests/tls/ca/ca_cert.pem")),
5760
SslVerifyMode::PEER,
5861
);
59-
client.connect(addr);
62+
client.connect(addr, NONE);
6063
}
6164

6265
#[should_panic]
@@ -79,7 +82,7 @@ fn test_handshake_client_authentication_with_no_client_settings() {
7982
Some(String::from("../../tests/tls/ca/ca_cert.pem")),
8083
SslVerifyMode::PEER,
8184
);
82-
client.connect(addr);
85+
client.connect(addr, NONE);
8386
}
8487

8588
#[should_panic]
@@ -102,7 +105,7 @@ fn test_handshake_client_authentication_with_no_rsa_client_key() {
102105
Some(String::from("../../tests/tls/ca/ca_cert.pem")),
103106
SslVerifyMode::PEER,
104107
);
105-
client.connect(addr);
108+
client.connect(addr, RSA);
106109
}
107110

108111
#[should_panic]
@@ -125,7 +128,7 @@ fn test_handshake_client_authentication_with_no_ecdsa_client_key() {
125128
Some(String::from("../../tests/tls/ca/ca_cert.pem")),
126129
SslVerifyMode::PEER,
127130
);
128-
client.connect(addr);
131+
client.connect(addr, ECDSA);
129132
}
130133

131134
#[test]
@@ -147,7 +150,7 @@ fn test_handshake_client_authentication_rsa() {
147150
Some(String::from("../../tests/tls/ca/ca_cert.pem")),
148151
SslVerifyMode::PEER,
149152
);
150-
client.connect(addr);
153+
client.connect(addr, RSA);
151154
}
152155

153156
#[test]
@@ -169,7 +172,7 @@ fn test_handshake_client_authentication_ecdsa() {
169172
Some(String::from("../../tests/tls/ca/ca_cert.pem")),
170173
SslVerifyMode::PEER,
171174
);
172-
client.connect(addr);
175+
client.connect(addr, ECDSA);
173176
}
174177

175178
#[should_panic]
@@ -192,7 +195,7 @@ fn test_handshake_client_authentication_with_fake_ca() {
192195
Some(String::from("../../tests/tls/fake_ca/ca_cert.pem")),
193196
SslVerifyMode::PEER,
194197
);
195-
client.connect(addr);
198+
client.connect(addr, RSA);
196199
}
197200

198201
// This is a negative test case. When a client is configured with a wrong certificate for a private
@@ -203,6 +206,7 @@ fn test_client_with_mismatched_rsa_key_and_certificate() {
203206
check_mismatched_key_certificate(
204207
String::from("PARSEC_TEST_RSA_KEY"),
205208
String::from("../../tests/tls/fake_client/parsec_rsa.pem"),
209+
RSA,
206210
);
207211
}
208212

@@ -214,5 +218,6 @@ fn test_client_with_mismatched_ecdsa_key_and_certificate() {
214218
check_mismatched_key_certificate(
215219
String::from("PARSEC_TEST_ECDSA_KEY"),
216220
String::from("../../tests/tls/fake_client/parsec_ecdsa.pem"),
221+
ECDSA,
217222
);
218223
}

0 commit comments

Comments
 (0)