From f99e60c33948432648babd29911075295398862e Mon Sep 17 00:00:00 2001 From: saadgodikat Date: Fri, 25 Sep 2026 21:30:16 +0530 Subject: [PATCH 1/2] 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; } From b6d441ed52c517b3bf776998f763476a7ee34620 Mon Sep 17 00:00:00 2001 From: saadgodikat Date: Mon, 5 Oct 2026 16:09:24 +0530 Subject: [PATCH 2/2] Add changelog for DER certificate output fix Signed-off-by: saadgodikat --- ChangeLog.d/cert-write-der-windows.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 ChangeLog.d/cert-write-der-windows.txt diff --git a/ChangeLog.d/cert-write-der-windows.txt b/ChangeLog.d/cert-write-der-windows.txt new file mode 100644 index 0000000000..002092b943 --- /dev/null +++ b/ChangeLog.d/cert-write-der-windows.txt @@ -0,0 +1,3 @@ +Bugfix + * Fix corruption of DER certificates generated by the `cert_write` + sample program on Windows. #10152