Skip to content

Commit 2ab1741

Browse files
committed
Make it also work for IDF4
1 parent d7cee50 commit 2ab1741

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/HTTPSServer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,12 @@ int HTTPSServer::setupCert() {
7878
return res;
7979
}
8080

81+
#if ESP_IDF_VERSION_MAJOR > 4
8182
res = mbedtls_pk_parse_key(&_ssl_pk, _cert->getPKData(), _cert->getPKLength(), nullptr, 0,
8283
mbedtls_ctr_drbg_random, &_ssl_ctr_drbg);
84+
#else
85+
res = mbedtls_pk_parse_key(&_ssl_pk, _cert->getPKData(), _cert->getPKLength(), nullptr, 0);
86+
#endif
8387
if (res != 0) {
8488
return res;
8589
}

src/SSLCert.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,12 @@ static int cert_write(SSLCert &certCtx, std::string dn, std::string validityFrom
181181
}
182182

183183
mbedtls_pk_init( &key );
184+
185+
#if ESP_IDF_VERSION_MAJOR > 4
184186
stepRes = mbedtls_pk_parse_key( &key, certCtx.getPKData(), certCtx.getPKLength(), NULL, 0, mbedtls_entropy_func, &ctr_drbg );
187+
#else
188+
stepRes = mbedtls_pk_parse_key( &key, certCtx.getPKData(), certCtx.getPKLength(), NULL, 0 );
189+
#endif
185190
if (stepRes != 0) {
186191
funcRes = HTTPS_SERVER_ERROR_CERTGEN_READKEY;
187192
goto error_after_key;
@@ -230,13 +235,17 @@ static int cert_write(SSLCert &certCtx, std::string dn, std::string validityFrom
230235
funcRes = HTTPS_SERVER_ERROR_CERTGEN_SERIAL;
231236
goto error_after_cert_serial;
232237
}
238+
#if ESP_IDF_VERSION_MAJOR > 4
233239
unsigned char serial_bytes[10];
234240
stepRes = mbedtls_mpi_write_binary( &serial, serial_bytes, 10 );
235241
if (stepRes != 0) {
236242
funcRes = HTTPS_SERVER_ERROR_CERTGEN_SERIAL;
237243
goto error_after_cert_serial;
238244
}
239245
stepRes = mbedtls_x509write_crt_set_serial_raw( &crt, serial_bytes, 10 );
246+
#else
247+
stepRes = mbedtls_x509write_crt_set_serial( &crt, &serial );
248+
#endif
240249
if (stepRes != 0) {
241250
funcRes = HTTPS_SERVER_ERROR_CERTGEN_SERIAL;
242251
goto error_after_cert_serial;

0 commit comments

Comments
 (0)