fix: add serial number to certificate

This commit is contained in:
Richard Ramos 2025-02-06 18:51:23 -04:00
parent f87cc67130
commit 4f3651b63d
No known key found for this signature in database
GPG Key ID: 7218C1B2A89A1B6D

View File

@ -374,6 +374,18 @@ proc generate*(
# Set the MD algorithm # Set the MD algorithm
mbedtls_x509write_crt_set_md_alg(addr crt, SIGNATURE_ALG) mbedtls_x509write_crt_set_md_alg(addr crt, SIGNATURE_ALG)
# Generate a random serial number
const SERIAL_LEN = 20
var serialBuffer: array[SERIAL_LEN, byte]
ret = mbedtls_ctr_drbg_random(addr ctrDrbg, addr serialBuffer[0], SERIAL_LEN);
if ret != 0:
raise newException(CertificateCreationError, "Failed to generate serial number")
# Set the serial number
ret = mbedtls_x509write_crt_set_serial_raw(addr crt, addr serialBuffer[0], SERIAL_LEN);
if ret != 0:
raise newException(CertificateCreationError, "Failed to set serial number")
# Prepare Buffer for Certificate Serialization # Prepare Buffer for Certificate Serialization
const CERT_BUFFER_SIZE = 4096 const CERT_BUFFER_SIZE = 4096
var var