File tree Expand file tree Collapse file tree 2 files changed +33
-24
lines changed
parsec-openssl-provider-shared/e2e_tests Expand file tree Collapse file tree 2 files changed +33
-24
lines changed Original file line number Diff line number Diff line change @@ -176,3 +176,28 @@ impl Client {
176
176
}
177
177
}
178
178
}
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
+ }
Original file line number Diff line number Diff line change @@ -200,35 +200,19 @@ fn test_handshake_client_authentication_with_fake_ca() {
200
200
// public key from the x509 certificate.
201
201
#[ test]
202
202
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
+ ) ;
215
207
}
216
208
217
209
// This is a negative test case. When a client is configured with a wrong certificate for a private
218
210
// key, the key management match function should report an error about the mismatched private key and
219
211
// public key from the x509 certificate.
220
212
#[ test]
221
213
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
+ ) ;
234
218
}
You can’t perform that action at this time.
0 commit comments