Merge pull request #10973 from saadgodikat/fix-cert-write-der-windows

Fix DER certificate output on Windows
This commit is contained in:
Manuel Pégourié-Gonnard
2026-10-07 06:55:27 +00:00
committed by GitHub
2 changed files with 9 additions and 1 deletions
+4
View File
@@ -0,0 +1,4 @@
Bugfix
* Fix corruption of DER certificates generated by the `cert_write`
sample program on Windows. #10152
+5 -1
View File
@@ -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;
}