From f99e60c33948432648babd29911075295398862e Mon Sep 17 00:00:00 2001 From: saadgodikat Date: Fri, 25 Sep 2026 21:30:16 +0530 Subject: [PATCH] Fix DER certificate output on Windows Fixes #10152 Signed-off-by: saadgodikat --- programs/x509/cert_write.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/programs/x509/cert_write.c b/programs/x509/cert_write.c index 5d9a306ee7..947d73f54a 100644 --- a/programs/x509/cert_write.c +++ b/programs/x509/cert_write.c @@ -238,7 +238,11 @@ static int write_certificate(mbedtls_x509write_cert *crt, const char *output_fil output_start = output_buf; } - if ((f = fopen(output_file, "w")) == NULL) { + /* + * DER output is binary data. Use binary mode on Windows to prevent + * text-mode newline translation. + */ + if ((f = fopen(output_file, opt.format == FORMAT_DER ? "wb" : "w")) == NULL) { return -1; }