Skip to content

Commit 2c50b67

Browse files
committed
apply fix for mbedtls_x509write_crt_set_serial() deprecation
source: sepfy/libpeer@a0ba3d8
1 parent 17b4c37 commit 2c50b67

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/SSLCert.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,12 @@ static int cert_write(SSLCert &certCtx, std::string dn, std::string validityFrom
159159
mbedtls_ctr_drbg_context ctr_drbg;
160160
mbedtls_pk_context key;
161161
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+
163168
unsigned char * primary_buffer;
164169
unsigned char *certOffset;
165170
unsigned char * output_buffer;
@@ -223,6 +228,9 @@ static int cert_write(SSLCert &certCtx, std::string dn, std::string validityFrom
223228
goto error_after_cert;
224229
}
225230

231+
#if MBEDTLS_VERSION_NUMBER >= 0x03000000
232+
mbedtls_x509write_crt_set_serial_raw(&crt, (unsigned char *) serial, strlen(serial));
233+
#else
226234
// generate random serial number
227235
mbedtls_mpi_init( &serial );
228236
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
235243
funcRes = HTTPS_SERVER_ERROR_CERTGEN_SERIAL;
236244
goto error_after_cert_serial;
237245
}
238-
246+
#endif
239247
// Create buffer to write the certificate
240248
primary_buffer = new unsigned char[4096];
241249
if (primary_buffer == NULL) {
@@ -270,7 +278,9 @@ static int cert_write(SSLCert &certCtx, std::string dn, std::string validityFrom
270278
delete[] primary_buffer;
271279

272280
error_after_cert_serial:
281+
#if MBEDTLS_VERSION_NUMBER < 0x03000000
273282
mbedtls_mpi_free( &serial );
283+
#endif
274284

275285
error_after_cert:
276286
mbedtls_x509write_crt_free( &crt );

0 commit comments

Comments
 (0)