@@ -159,7 +159,12 @@ static int cert_write(SSLCert &certCtx, std::string dn, std::string validityFrom
159
159
mbedtls_ctr_drbg_context ctr_drbg;
160
160
mbedtls_pk_context key;
161
161
mbedtls_x509write_cert crt;
162
- mbedtls_mpi serial;
162
+ #if MBEDTLS_VERSION_NUMBER >= 0x03000000
163
+ const char *serial = " peer" ;
164
+ #else
165
+ mbedtls_mpi serial;
166
+ #endif
167
+
163
168
unsigned char * primary_buffer;
164
169
unsigned char *certOffset;
165
170
unsigned char * output_buffer;
@@ -223,6 +228,9 @@ static int cert_write(SSLCert &certCtx, std::string dn, std::string validityFrom
223
228
goto error_after_cert;
224
229
}
225
230
231
+ #if MBEDTLS_VERSION_NUMBER >= 0x03000000
232
+ mbedtls_x509write_crt_set_serial_raw (&crt, (unsigned char *) serial, strlen (serial));
233
+ #else
226
234
// generate random serial number
227
235
mbedtls_mpi_init ( &serial );
228
236
stepRes = mbedtls_mpi_fill_random ( &serial, 10 , mbedtls_ctr_drbg_random, &ctr_drbg );
@@ -235,7 +243,7 @@ static int cert_write(SSLCert &certCtx, std::string dn, std::string validityFrom
235
243
funcRes = HTTPS_SERVER_ERROR_CERTGEN_SERIAL;
236
244
goto error_after_cert_serial;
237
245
}
238
-
246
+ # endif
239
247
// Create buffer to write the certificate
240
248
primary_buffer = new unsigned char [4096 ];
241
249
if (primary_buffer == NULL ) {
@@ -270,7 +278,9 @@ static int cert_write(SSLCert &certCtx, std::string dn, std::string validityFrom
270
278
delete[] primary_buffer;
271
279
272
280
error_after_cert_serial:
281
+ #if MBEDTLS_VERSION_NUMBER < 0x03000000
273
282
mbedtls_mpi_free ( &serial );
283
+ #endif
274
284
275
285
error_after_cert:
276
286
mbedtls_x509write_crt_free ( &crt );
0 commit comments