@@ -87,8 +87,12 @@ static int dtls_srtp_selfsign_cert(DtlsSrtp *dtls_srtp) {
87
87
int ret ;
88
88
89
89
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
92
96
93
97
unsigned char * cert_buf = (unsigned char * ) malloc (RSA_KEY_LENGTH * 2 );
94
98
@@ -116,11 +120,13 @@ static int dtls_srtp_selfsign_cert(DtlsSrtp *dtls_srtp) {
116
120
117
121
mbedtls_x509write_crt_set_issuer_name (& crt , "CN=dtls_srtp" );
118
122
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
124
130
125
131
mbedtls_x509write_crt_set_validity (& crt , "20180101000000" , "20280101000000" );
126
132
@@ -134,8 +140,11 @@ static int dtls_srtp_selfsign_cert(DtlsSrtp *dtls_srtp) {
134
140
mbedtls_x509_crt_parse (& dtls_srtp -> cert , cert_buf , 2 * RSA_KEY_LENGTH );
135
141
136
142
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
139
148
140
149
free (cert_buf );
141
150
0 commit comments