@@ -716,16 +716,11 @@ static int load_endpoint_ecc(mbedtls_test_ssl_endpoint *ep)
716
716
}
717
717
718
718
int mbedtls_test_ssl_endpoint_certificate_init (mbedtls_test_ssl_endpoint * ep ,
719
- int pk_alg ,
720
- int opaque_alg , int opaque_alg2 ,
721
- int opaque_usage )
719
+ int pk_alg )
722
720
{
723
721
int i = 0 ;
724
722
int ret = -1 ;
725
723
int ok = 0 ;
726
- #if defined(MBEDTLS_USE_PSA_CRYPTO )
727
- mbedtls_svc_key_id_t key_slot = MBEDTLS_SVC_KEY_ID_INIT ;
728
- #endif
729
724
730
725
if (ep == NULL ) {
731
726
return MBEDTLS_ERR_SSL_BAD_INPUT_DATA ;
@@ -757,29 +752,6 @@ int mbedtls_test_ssl_endpoint_certificate_init(mbedtls_test_ssl_endpoint *ep,
757
752
TEST_EQUAL (load_endpoint_ecc (ep ), 0 );
758
753
}
759
754
760
- #if defined(MBEDTLS_USE_PSA_CRYPTO )
761
- if (opaque_alg != 0 ) {
762
- psa_key_attributes_t key_attr = PSA_KEY_ATTRIBUTES_INIT ;
763
- /* Use a fake key usage to get a successful initial guess for the PSA attributes. */
764
- TEST_EQUAL (mbedtls_pk_get_psa_attributes (ep -> pkey , PSA_KEY_USAGE_SIGN_HASH ,
765
- & key_attr ), 0 );
766
- /* Then manually usage, alg and alg2 as requested by the test. */
767
- psa_set_key_usage_flags (& key_attr , opaque_usage );
768
- psa_set_key_algorithm (& key_attr , opaque_alg );
769
- if (opaque_alg2 != PSA_ALG_NONE ) {
770
- psa_set_key_enrollment_algorithm (& key_attr , opaque_alg2 );
771
- }
772
- TEST_EQUAL (mbedtls_pk_import_into_psa (ep -> pkey , & key_attr , & key_slot ), 0 );
773
- mbedtls_pk_free (ep -> pkey );
774
- mbedtls_pk_init (ep -> pkey );
775
- TEST_EQUAL (mbedtls_pk_setup_opaque (ep -> pkey , key_slot ), 0 );
776
- }
777
- #else
778
- (void ) opaque_alg ;
779
- (void ) opaque_alg2 ;
780
- (void ) opaque_usage ;
781
- #endif
782
-
783
755
mbedtls_ssl_conf_ca_chain (& (ep -> conf ), ep -> ca_chain , NULL );
784
756
785
757
ret = mbedtls_ssl_conf_own_cert (& (ep -> conf ), ep -> cert ,
@@ -800,6 +772,52 @@ int mbedtls_test_ssl_endpoint_certificate_init(mbedtls_test_ssl_endpoint *ep,
800
772
return ret ;
801
773
}
802
774
775
+ int mbedtls_test_ssl_endpoint_make_key_opaque (mbedtls_test_ssl_endpoint * ep ,
776
+ int opaque_alg , int opaque_alg2 ,
777
+ int opaque_usage )
778
+ {
779
+ psa_key_attributes_t key_attr = PSA_KEY_ATTRIBUTES_INIT ;
780
+ #if defined(MBEDTLS_USE_PSA_CRYPTO )
781
+ mbedtls_svc_key_id_t key_slot = MBEDTLS_SVC_KEY_ID_INIT ;
782
+ #endif
783
+ int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED ;
784
+ int ok = 0 ;
785
+
786
+ /* Use a fake key usage to get a successful initial guess for the PSA attributes. */
787
+ TEST_EQUAL (mbedtls_pk_get_psa_attributes (ep -> pkey , PSA_KEY_USAGE_SIGN_HASH ,
788
+ & key_attr ), 0 );
789
+ /* Then manually usage, alg and alg2 as requested by the test. */
790
+ psa_set_key_usage_flags (& key_attr , opaque_usage );
791
+ psa_set_key_algorithm (& key_attr , opaque_alg );
792
+ if (opaque_alg2 != PSA_ALG_NONE ) {
793
+ psa_set_key_enrollment_algorithm (& key_attr , opaque_alg2 );
794
+ }
795
+ TEST_EQUAL (mbedtls_pk_import_into_psa (ep -> pkey , & key_attr , & key_slot ), 0 );
796
+ mbedtls_pk_free (ep -> pkey );
797
+ mbedtls_pk_init (ep -> pkey );
798
+ TEST_EQUAL (mbedtls_pk_setup_opaque (ep -> pkey , key_slot ), 0 );
799
+
800
+ /* Reset (key, certificate) pair(s) in the SSL configuration, so that
801
+ * the configuration will only contain what we put explicitly in
802
+ * this function. */
803
+ ret = mbedtls_ssl_conf_own_cert (& (ep -> conf ), NULL , NULL );
804
+ TEST_EQUAL (ret , 0 );
805
+
806
+ /* Only put the opaque key, with the same certificate as before. */
807
+ ret = mbedtls_ssl_conf_own_cert (& (ep -> conf ), ep -> cert , ep -> pkey );
808
+ TEST_EQUAL (ret , 0 );
809
+
810
+ ok = 1 ;
811
+
812
+ exit :
813
+ if (ret == 0 && !ok ) {
814
+ /* Exiting due to a test assertion that isn't ret == 0 */
815
+ ret = -1 ;
816
+ }
817
+
818
+ return ret ;
819
+ }
820
+
803
821
int mbedtls_test_ssl_endpoint_init (
804
822
mbedtls_test_ssl_endpoint * ep , int endpoint_type ,
805
823
const mbedtls_test_handshake_test_options * options )
@@ -970,10 +988,7 @@ int mbedtls_test_ssl_endpoint_init(
970
988
#endif
971
989
#endif /* MBEDTLS_DEBUG_C */
972
990
973
- ret = mbedtls_test_ssl_endpoint_certificate_init (ep , options -> pk_alg ,
974
- options -> opaque_alg ,
975
- options -> opaque_alg2 ,
976
- options -> opaque_usage );
991
+ ret = mbedtls_test_ssl_endpoint_certificate_init (ep , options -> pk_alg );
977
992
TEST_EQUAL (ret , 0 );
978
993
979
994
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED )
0 commit comments