@@ -89,12 +89,14 @@ static int rpk_verify_server_cb(int ok, X509_STORE_CTX *ctx)
8989 * idx = 13 - resumption with client authentication
9090 * idx = 14 - resumption with client authentication, no ticket
9191 * idx = 15 - like 0, but use non-default libctx
92+ * idx = 16 - like 7, but with SSL_VERIFY_PEER connection should fail
93+ * idx = 17 - like 8, but with SSL_VERIFY_PEER connection should fail
9294 *
93- * 16 * 2 * 4 * 2 * 2 * 2 * 2 = 2048 tests
95+ * 18 * 2 * 4 * 2 * 2 * 2 * 2 = 2048 tests
9496 */
9597static int test_rpk (int idx )
9698{
97- # define RPK_TESTS 16
99+ # define RPK_TESTS 18
98100# define RPK_DIMS (2 * 4 * 2 * 2 * 2 * 2)
99101 SSL_CTX * cctx = NULL , * sctx = NULL ;
100102 SSL * clientssl = NULL , * serverssl = NULL ;
@@ -114,6 +116,7 @@ static int test_rpk(int idx)
114116 int idx_cert , idx_prot ;
115117 int client_auth = 0 ;
116118 int resumption = 0 ;
119+ int want_error = SSL_ERROR_NONE ;
117120 long server_verify_result = 0 ;
118121 long client_verify_result = 0 ;
119122 OSSL_LIB_CTX * test_libctx = NULL ;
@@ -188,7 +191,7 @@ static int test_rpk(int idx)
188191#ifdef OPENSSL_NO_ECDSA
189192 /* Can't get other_key if it's ECDSA */
190193 if (other_pkey == NULL && idx_cert == 0
191- && (idx == 4 || idx == 6 || idx == 7 )) {
194+ && (idx == 4 || idx == 6 || idx == 7 || idx == 16 )) {
192195 testresult = TEST_skip ("EDCSA disabled" );
193196 goto end ;
194197 }
@@ -266,8 +269,10 @@ static int test_rpk(int idx)
266269 goto end ;
267270 /* Only a private key */
268271 if (idx == 1 ) {
269- if (idx_server_server_rpk == 0 || idx_client_server_rpk == 0 )
272+ if (idx_server_server_rpk == 0 || idx_client_server_rpk == 0 ) {
270273 expected = 0 ;
274+ want_error = SSL_ERROR_SSL ;
275+ }
271276 } else {
272277 /* Add certificate */
273278 if (!TEST_int_eq (SSL_use_certificate_file (serverssl , cert_file , SSL_FILETYPE_PEM ), 1 ))
@@ -333,12 +338,14 @@ static int test_rpk(int idx)
333338 client_expected = -1 ;
334339 if (!TEST_true (SSL_add_expected_rpk (clientssl , other_pkey )))
335340 goto end ;
341+ SSL_set_verify (clientssl , SSL_VERIFY_NONE , rpk_verify_client_cb );
336342 client_verify_result = X509_V_ERR_DANE_NO_MATCH ;
337343 break ;
338344 case 8 :
339345 if (idx_server_server_rpk == 1 && idx_client_server_rpk == 1 )
340346 client_expected = -1 ;
341347 /* no peer keys */
348+ SSL_set_verify (clientssl , SSL_VERIFY_NONE , rpk_verify_client_cb );
342349 client_verify_result = X509_V_ERR_RPK_UNTRUSTED ;
343350 break ;
344351 case 9 :
@@ -370,9 +377,13 @@ static int test_rpk(int idx)
370377 if (!TEST_int_eq (SSL_use_PrivateKey_file (clientssl , privkey_file , SSL_FILETYPE_PEM ), 1 ))
371378 goto end ;
372379 /* Since there's no cert, this is expected to fail without RPK support */
373- if (!idx_server_client_rpk || !idx_client_client_rpk )
380+ if (!idx_server_client_rpk || !idx_client_client_rpk ) {
374381 expected = 0 ;
375- SSL_set_verify (serverssl , SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT , rpk_verify_server_cb );
382+ want_error = SSL_ERROR_SSL ;
383+ SSL_set_verify (serverssl , SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT , NULL );
384+ } else {
385+ SSL_set_verify (serverssl , SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT , rpk_verify_server_cb );
386+ }
376387 client_auth = 1 ;
377388 break ;
378389 case 11 :
@@ -449,12 +460,35 @@ static int test_rpk(int idx)
449460 if (!TEST_true (SSL_add_expected_rpk (clientssl , pkey )))
450461 goto end ;
451462 break ;
463+ case 16 :
464+ if (idx_server_server_rpk == 1 && idx_client_server_rpk == 1 ) {
465+ /* wrong expected server key */
466+ expected = 0 ;
467+ want_error = SSL_ERROR_SSL ;
468+ SSL_set_verify (serverssl , SSL_VERIFY_PEER , NULL );
469+ }
470+ if (!TEST_true (SSL_add_expected_rpk (clientssl , other_pkey )))
471+ goto end ;
472+ break ;
473+ case 17 :
474+ if (idx_server_server_rpk == 1 && idx_client_server_rpk == 1 ) {
475+ /* no expected server keys */
476+ expected = 0 ;
477+ want_error = SSL_ERROR_SSL ;
478+ SSL_set_verify (serverssl , SSL_VERIFY_PEER , NULL );
479+ }
480+ break ;
452481 }
453482
454- ret = create_ssl_connection (serverssl , clientssl , SSL_ERROR_NONE );
483+ ret = create_ssl_connection (serverssl , clientssl , want_error );
455484 if (!TEST_int_eq (expected , ret ))
456485 goto end ;
457486
487+ if (expected <= 0 ) {
488+ testresult = 1 ;
489+ goto end ;
490+ }
491+
458492 /* Make sure client gets RPK or certificate as configured */
459493 if (expected == 1 ) {
460494 if (idx_server_server_rpk && idx_client_server_rpk ) {
0 commit comments