Skip to content

Commit

Permalink
fix: add serial number to certificate
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-ramos committed Feb 6, 2025
1 parent f87cc67 commit 4f3651b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions libp2p/transports/tls/certificate.nim
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,18 @@ proc generate*(
# Set the MD algorithm
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
const CERT_BUFFER_SIZE = 4096
var
Expand Down

0 comments on commit 4f3651b

Please sign in to comment.