@@ -87,8 +87,12 @@ static int dtls_srtp_selfsign_cert(DtlsSrtp *dtls_srtp) {
8787 int ret ;
8888
8989 mbedtls_x509write_cert crt ;
90-
91- mbedtls_mpi serial ;
90+
91+ #if ESP_IDF_VERSION > ESP_IDF_VERSION_VAL (5 , 0 , 2 )
92+ char * serial = "peer" ;
93+ #else
94+ mbedtls_mpi serial ;
95+ #endif
9296
9397 unsigned char * cert_buf = (unsigned char * ) malloc (RSA_KEY_LENGTH * 2 );
9498
@@ -116,11 +120,13 @@ static int dtls_srtp_selfsign_cert(DtlsSrtp *dtls_srtp) {
116120
117121 mbedtls_x509write_crt_set_issuer_name (& crt , "CN=dtls_srtp" );
118122
119- mbedtls_mpi_init (& serial );
120-
121- mbedtls_mpi_fill_random (& serial , 16 , mbedtls_ctr_drbg_random , & dtls_srtp -> ctr_drbg );
122-
123- mbedtls_x509write_crt_set_serial (& crt , & serial );
123+ #if ESP_IDF_VERSION > ESP_IDF_VERSION_VAL (5 , 0 , 2 )
124+ mbedtls_x509write_crt_set_serial_raw (& crt , (unsigned char * ) serial , strlen (serial ));
125+ #else
126+ mbedtls_mpi_init (& serial );
127+ mbedtls_mpi_fill_random (& serial , 16 , mbedtls_ctr_drbg_random , & dtls_srtp -> ctr_drbg );
128+ mbedtls_x509write_crt_set_serial (& crt , & serial );
129+ #endif
124130
125131 mbedtls_x509write_crt_set_validity (& crt , "20180101000000" , "20280101000000" );
126132
@@ -134,8 +140,11 @@ static int dtls_srtp_selfsign_cert(DtlsSrtp *dtls_srtp) {
134140 mbedtls_x509_crt_parse (& dtls_srtp -> cert , cert_buf , 2 * RSA_KEY_LENGTH );
135141
136142 mbedtls_x509write_crt_free (& crt );
137-
138- mbedtls_mpi_free (& serial );
143+
144+ #if ESP_IDF_VERSION > ESP_IDF_VERSION_VAL (5 , 0 , 2 )
145+ #else
146+ mbedtls_mpi_free (& serial );
147+ #endif
139148
140149 free (cert_buf );
141150
0 commit comments