diff options
author | Nick Mathewson <nickm@torproject.org> | 2007-08-29 19:02:43 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2007-08-29 19:02:43 +0000 |
commit | f189ecbf202b8cb96ff3ecea775c259083a3b8e3 (patch) | |
tree | 5ef5ad3894ab9d5eabc685c38dab5e075427073e /src/tools | |
parent | 8408122222bda77347e46dedafc12abcd2b45e1e (diff) | |
download | tor-f189ecbf202b8cb96ff3ecea775c259083a3b8e3.tar.gz tor-f189ecbf202b8cb96ff3ecea775c259083a3b8e3.zip |
r14832@catbus: nickm | 2007-08-29 15:00:27 -0400
Use (and debug) new file-writing functions in order to simplify code that formerly built big strings in RAM.
svn:r11301
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/tor-gencert.c | 38 |
1 files changed, 12 insertions, 26 deletions
diff --git a/src/tools/tor-gencert.c b/src/tools/tor-gencert.c index abb2ac298a..4b956981d9 100644 --- a/src/tools/tor-gencert.c +++ b/src/tools/tor-gencert.c @@ -151,7 +151,7 @@ load_identity_key(void) FILE *f; if (make_new_id) { - int fd; + open_file_t *open_file = NULL; RSA *key; if (status != FN_NOENT) { log_err(LD_GENERAL, "--create-identity-key was specified, but %s " @@ -171,18 +171,10 @@ load_identity_key(void) return 1; } - if ((fd = open(identity_key_file, O_CREAT|O_EXCL|O_WRONLY, 0400))<0) { - log_err(LD_GENERAL, "Couldn't fdopen %s for writing: %s", - identity_key_file, strerror(errno)); + if (!(f = start_writing_to_stdio_file(identity_key_file, + OPEN_FLAGS_REPLACE, 0400, + &open_file))) return 1; - } - - if (!(f = fdopen(fd, "w"))) { - close(fd); - log_err(LD_GENERAL, "Couldn't fdopen %s for writing: %s", - identity_key_file, strerror(errno)); - return 1; - } if (!PEM_write_PKCS8PrivateKey_nid(f, identity_key, NID_pbe_WithSHA1And3_Key_TripleDES_CBC, @@ -191,9 +183,10 @@ load_identity_key(void) log_err(LD_GENERAL, "Couldn't write identity key to %s", identity_key_file); crypto_log_errors(LOG_ERR, "Writing identity key"); + abort_writing_to_file(open_file); return 1; } - fclose(f); + finish_writing_to_file(open_file); } else { if (status != FN_FILE) { log_err(LD_GENERAL, @@ -224,7 +217,7 @@ load_identity_key(void) static int generate_signing_key(void) { - int fd; + open_file_t *open_file; FILE *f; RSA *key; log_notice(LD_GENERAL, "Generating %d-bit RSA signing key.", @@ -240,26 +233,19 @@ generate_signing_key(void) return 1; } - if ((fd = open(signing_key_file, O_CREAT|O_EXCL|O_WRONLY, 0600))<0) { - log_err(LD_GENERAL, "Couldn't open %s for writing: %s", - signing_key_file, strerror(errno)); + if (!(f = start_writing_to_stdio_file(signing_key_file, + OPEN_FLAGS_REPLACE, 0600, + &open_file))) return 1; - } - - if (!(f = fdopen(fd, "w"))) { - close(fd); - log_err(LD_GENERAL, "Couldn't open %s for writing: %s", - signing_key_file, strerror(errno)); - return 1; - } /* Write signing key with no encryption. */ if (!PEM_write_RSAPrivateKey(f, key, NULL, NULL, 0, NULL, NULL)) { crypto_log_errors(LOG_WARN, "writing signing key"); + abort_writing_to_file(open_file); return 1; } - fclose(f); + finish_writing_to_file(open_file); return 0; } |