From 80d7a91d86f8cde7b1a550ef18ae7b84e2236ab6 Mon Sep 17 00:00:00 2001 From: Niklas Hofmann Date: Thu, 4 Dec 2014 21:59:52 +0100 Subject: [PATCH] fix private key file read and write on windows (binary read/write) --- src/meshlink.c | 6 +++--- src/net_setup.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/meshlink.c b/src/meshlink.c index 8b97be79..cbe88a3e 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -660,7 +660,7 @@ static bool ecdsa_keygen(meshlink_handle_t *mesh) { logger(mesh, MESHLINK_DEBUG, "Done.\n"); snprintf(privname, sizeof privname, "%s" SLASH "ecdsa_key.priv", mesh->confbase); - f = fopen(privname, "w"); + f = fopen(privname, "wb"); if(!f) { meshlink_errno = MESHLINK_ESTORAGE; @@ -1292,7 +1292,7 @@ static bool refresh_invitation_key(meshlink_handle_t *mesh) { } // Create a new key if necessary. - FILE *f = fopen(filename, "r"); + FILE *f = fopen(filename, "rb"); if(!f) { if(errno != ENOENT) { logger(mesh, MESHLINK_DEBUG, "Could not read %s: %s\n", filename, strerror(errno)); @@ -1308,7 +1308,7 @@ static bool refresh_invitation_key(meshlink_handle_t *mesh) { pthread_mutex_unlock(&(mesh->mesh_mutex)); return false; } - f = fopen(filename, "w"); + f = fopen(filename, "wb"); if(!f) { logger(mesh, MESHLINK_DEBUG, "Could not write %s: %s\n", filename, strerror(errno)); meshlink_errno = MESHLINK_ESTORAGE; diff --git a/src/net_setup.c b/src/net_setup.c index 1ba98077..a2c44141 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -83,7 +83,7 @@ bool read_ecdsa_private_key(meshlink_handle_t *mesh) { char filename[PATH_MAX]; snprintf(filename,PATH_MAX, "%s" SLASH "ecdsa_key.priv", mesh->confbase); - fp = fopen(filename, "r"); + fp = fopen(filename, "rb"); if(!fp) { logger(mesh, MESHLINK_ERROR, "Error reading ECDSA private key file: %s", strerror(errno)); @@ -110,7 +110,7 @@ static bool read_invitation_key(meshlink_handle_t *mesh) { snprintf(filename,PATH_MAX, "%s" SLASH "invitations" SLASH "ecdsa_key.priv", mesh->confbase); - fp = fopen(filename, "r"); + fp = fopen(filename, "rb"); if(fp) { mesh->invitation_key = ecdsa_read_pem_private_key(fp); -- 2.39.5