Skip to content

Commit ebb98f1

Browse files
committed
examples/csr: size PEM buffer for RSA-4096 signatures
MAX_PEM_SIZE aliased to MAX_CONTEXT_SIZE (2 KB), which is enough for an RSA-2048 self-signed cert but overflows at RSA-4096 where the signature alone is 512 B plus the cert body, ASN.1, and base64 overhead. wc_MakeCertReq / wc_MakeSelfSignedCert then returned BUFFER_E (0xffffff7c / 0xffffff53). Gate on MAX_RSA_KEY_BITS so 2048-bit builds keep the exact same buffer size; 4096-bit builds (Nations NS350, Infineon SLB967x, or anyone overriding) get 4 KB. Mirrors the fix already applied to examples/pkcs7/pkcs7.c.
1 parent 52cdcdc commit ebb98f1

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

examples/csr/csr.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,14 @@ static const char* gClientCertEccFile = ECC_CERT_PEM;
6060
#endif
6161

6262
#ifndef MAX_PEM_SIZE
63-
#define MAX_PEM_SIZE MAX_CONTEXT_SIZE
63+
/* Must hold the full PEM-encoded CSR/cert (cert body + RSA signature +
64+
* ASN.1 + base64 overhead). MAX_CONTEXT_SIZE (2 KB) fits RSA-2048 but
65+
* overflows at RSA-4096 where the signature alone is 512 B. */
66+
#if MAX_RSA_KEY_BITS >= 4096
67+
#define MAX_PEM_SIZE 4096
68+
#else
69+
#define MAX_PEM_SIZE MAX_CONTEXT_SIZE
70+
#endif
6471
#endif
6572

6673
/******************************************************************************/

0 commit comments

Comments
 (0)