@@ -460,7 +460,11 @@ HL_PRIM varray *HL_NAME(cert_get_altnames)(hl_ssl_cert *cert) {
460
460
varray * a = NULL ;
461
461
vbyte * * current = NULL ;
462
462
mbedtls_x509_crt * crt = cert -> c ;
463
+ #if MBEDTLS_VERSION_MAJOR >= 3
464
+ if (mbedtls_x509_crt_has_ext_type (crt , MBEDTLS_X509_EXT_SUBJECT_ALT_NAME )) {
465
+ #else
463
466
if (crt -> ext_types & MBEDTLS_X509_EXT_SUBJECT_ALT_NAME ) {
467
+ #endif
464
468
cur = & crt -> subject_alt_names ;
465
469
while (cur != NULL ) {
466
470
if (pos == count ) {
@@ -593,7 +597,11 @@ HL_PRIM hl_ssl_pkey *HL_NAME(key_from_der)(vbyte *data, int len, bool pub) {
593
597
if (pub )
594
598
r = mbedtls_pk_parse_public_key (pk , (const unsigned char * )data , len );
595
599
else
600
+ #if MBEDTLS_VERSION_MAJOR >= 3
601
+ r = mbedtls_pk_parse_key (pk , (const unsigned char * )data , len , NULL , 0 , mbedtls_ctr_drbg_random , & ctr_drbg );
602
+ #else
596
603
r = mbedtls_pk_parse_key (pk , (const unsigned char * )data , len , NULL , 0 );
604
+ #endif
597
605
if (r != 0 ) {
598
606
mbedtls_pk_free (pk );
599
607
free (pk );
@@ -618,10 +626,17 @@ HL_PRIM hl_ssl_pkey *HL_NAME(key_from_pem)(vbyte *data, bool pub, vbyte *pass) {
618
626
buf [len - 1 ] = '\0' ;
619
627
if (pub )
620
628
r = mbedtls_pk_parse_public_key (pk , buf , len );
629
+ #if MBEDTLS_VERSION_MAJOR >= 3
630
+ else if (pass == NULL)
631
+ r = mbedtls_pk_parse_key (pk , buf , len , NULL , 0 , mbedtls_ctr_drbg_random , & ctr_drbg );
632
+ else
633
+ r = mbedtls_pk_parse_key (pk , buf , len , (const unsigned char * )pass , strlen ((char * )pass ), mbedtls_ctr_drbg_random , & ctr_drbg );
634
+ #else
621
635
else if (pass == NULL)
622
636
r = mbedtls_pk_parse_key (pk , buf , len , NULL , 0 );
623
637
else
624
638
r = mbedtls_pk_parse_key (pk , buf , len , (const unsigned char * )pass , strlen ((char * )pass ));
639
+ #endif
625
640
free (buf );
626
641
if (r != 0 ) {
627
642
mbedtls_pk_free (pk );
@@ -676,9 +691,13 @@ HL_PRIM vbyte *HL_NAME(dgst_sign)(vbyte *data, int len, hl_ssl_pkey *key, vbyte
676
691
ssl_error (r );
677
692
return NULL ;
678
693
}
679
-
694
+ #if MBEDTLS_VERSION_MAJOR >= 3
695
+ out = hl_gc_alloc_noptr (MBEDTLS_PK_SIGNATURE_MAX_SIZE );
696
+ if ((r = mbedtls_pk_sign (key -> k , mbedtls_md_get_type (md ), hash , mbedtls_md_get_size (md ), out , MBEDTLS_PK_SIGNATURE_MAX_SIZE , (size ? & ssize : NULL ), mbedtls_ctr_drbg_random , & ctr_drbg )) != 0 ) {
697
+ #else
680
698
out = hl_gc_alloc_noptr (MBEDTLS_MPI_MAX_SIZE );
681
699
if ((r = mbedtls_pk_sign (key -> k , mbedtls_md_get_type (md ), hash , 0 , out , (size ? & ssize : NULL ), mbedtls_ctr_drbg_random , & ctr_drbg )) != 0 ){
700
+ #endif
682
701
ssl_error (r );
683
702
return NULL ;
684
703
}
0 commit comments