17
17
#include "mbedtls/version.h" // Must be first in order to pick up version
18
18
19
19
#include "mbedtls/error.h"
20
+ #ifdef MBEDTLS_PSA_CRYPTO_C
21
+ #include "psa/crypto.h"
22
+ #endif
20
23
21
24
#include "nng/nng.h"
22
25
#include "nng/supplemental/tls/tls.h"
28
31
#include "mbedtls/net.h"
29
32
#endif
30
33
34
+ #include "mbedtls/debug.h"
31
35
#include "mbedtls/ssl.h"
32
36
33
37
#include "core/nng_impl.h"
@@ -465,7 +469,11 @@ config_init(nng_tls_engine_config *cfg, enum nng_tls_mode mode)
465
469
// SSL v3.3. As of this writing, Mbed TLS still does not support
466
470
// version 1.3, and we would want to test it before enabling it here.
467
471
cfg -> min_ver = MBEDTLS_SSL_MINOR_VERSION_3 ;
472
+ #ifdef MBEDTLS_SSL_PROTO_TLS1_3
473
+ cfg -> max_ver = MBEDTLS_SSL_MINOR_VERSION_4 ;
474
+ #else
468
475
cfg -> max_ver = MBEDTLS_SSL_MINOR_VERSION_3 ;
476
+ #endif
469
477
470
478
mbedtls_ssl_conf_min_version (
471
479
& cfg -> cfg_ctx , MBEDTLS_SSL_MAJOR_VERSION_3 , cfg -> min_ver );
@@ -689,9 +697,16 @@ config_version(nng_tls_engine_config *cfg, nng_tls_version min_ver,
689
697
v1 = MBEDTLS_SSL_MINOR_VERSION_2 ;
690
698
break ;
691
699
#endif
700
+ #ifdef MBEDTLS_SSL_MINOR_VERSION_3
692
701
case NNG_TLS_1_2 :
693
702
v1 = MBEDTLS_SSL_MINOR_VERSION_3 ;
694
703
break ;
704
+ #endif
705
+ #ifdef MBEDTLS_SSL_PROTO_TLS1_3
706
+ case NNG_TLS_1_3 :
707
+ v1 = MBEDTLS_SSL_MINOR_VERSION_4 ;
708
+ break ;
709
+ #endif
695
710
default :
696
711
nng_log_err (
697
712
"TLS-CFG-VER" , "TLS minimum version not supported" );
@@ -709,9 +724,17 @@ config_version(nng_tls_engine_config *cfg, nng_tls_version min_ver,
709
724
v2 = MBEDTLS_SSL_MINOR_VERSION_2 ;
710
725
break ;
711
726
#endif
727
+ #ifdef MBEDTLS_SSL_MINOR_VERSION_3
712
728
case NNG_TLS_1_2 :
729
+ v2 = MBEDTLS_SSL_MINOR_VERSION_3 ;
730
+ break ;
731
+ #endif
713
732
case NNG_TLS_1_3 : // We lack support for 1.3, so treat as 1.2.
733
+ #ifdef MBEDTLS_SSL_PROTO_TLS1_3
734
+ v2 = MBEDTLS_SSL_MINOR_VERSION_4 ;
735
+ #else
714
736
v2 = MBEDTLS_SSL_MINOR_VERSION_3 ;
737
+ #endif
715
738
break ;
716
739
default :
717
740
// Note that this means that if we ever TLS 1.4 or 2.0,
@@ -778,10 +801,18 @@ nng_tls_engine_init_mbed(void)
778
801
nni_mtx_fini (& rng_lock );
779
802
return (rv );
780
803
}
804
+ #endif
805
+ #ifdef MBEDTLS_PSA_CRYPTO_C
806
+ rv = psa_crypto_init ();
807
+ if (rv != 0 ) {
808
+ tls_log_err (
809
+ "NNG-TLS-INIT" , "Failed initializing PSA crypto" , rv );
810
+ return (rv );
811
+ }
781
812
#endif
782
813
// Uncomment the following to have noisy debug from mbedTLS.
783
814
// This may be useful when trying to debug failures.
784
- // mbedtls_debug_set_threshold(3 );
815
+ // mbedtls_debug_set_threshold(9 );
785
816
786
817
rv = nng_tls_engine_register (& tls_engine_mbed );
787
818
@@ -801,4 +832,7 @@ nng_tls_engine_fini_mbed(void)
801
832
mbedtls_ctr_drbg_free (& rng_ctx );
802
833
nni_mtx_fini (& rng_lock );
803
834
#endif
835
+ #ifdef MBEDTLS_PSA_CRYPTO_C
836
+ mbedtls_psa_crypto_free ();
837
+ #endif
804
838
}
0 commit comments