diff --git a/ssh-keygen.c b/ssh-keygen.c index 0a7cdd8..026cf26 100644 --- a/ssh-keygen.c +++ b/ssh-keygen.c @@ -67,7 +67,7 @@ # define DEFAULT_KEY_TYPE_NAME "ed25519" #endif - /* Number of bits in the RSA/DSA key. This value can be set on the command line. */ +/* Number of bits in the RSA/DSA key. This value can be set on the command line. */ #define DEFAULT_BITS 2048 #define DEFAULT_BITS_DSA 1024 #define DEFAULT_BITS_ECDSA 256 @@ -199,7 +199,7 @@ char hostname[NI_MAXHOST]; /* moduli.c */ int gen_candidates(FILE *, u_int32_t, u_int32_t, BIGNUM *); int prime_test(FILE *, FILE *, u_int32_t, u_int32_t, char *, unsigned long, - unsigned long); + unsigned long); #endif static void @@ -217,18 +217,17 @@ type_bits_valid(int type, const char *name, u_int32_t *bitsp) *bitsp = DEFAULT_BITS_DSA; else if (type == KEY_ECDSA) { if (name != NULL && - (nid = sshkey_ecdsa_nid_from_name(name)) > 0) + (nid = sshkey_ecdsa_nid_from_name(name)) > 0) *bitsp = sshkey_curve_nid_to_bits(nid); if (*bitsp == 0) *bitsp = DEFAULT_BITS_ECDSA; - } - else + } else #endif *bitsp = DEFAULT_BITS; } #ifdef WITH_OPENSSL maxbits = (type == KEY_DSA) ? - OPENSSL_DSA_MAX_MODULUS_BITS : OPENSSL_RSA_MAX_MODULUS_BITS; + OPENSSL_DSA_MAX_MODULUS_BITS : OPENSSL_RSA_MAX_MODULUS_BITS; if (*bitsp > maxbits) fatal("key bits exceeds maximum %d", maxbits); switch (type) { @@ -239,7 +238,7 @@ type_bits_valid(int type, const char *name, u_int32_t *bitsp) case KEY_RSA: if (*bitsp < SSH_RSA_MINIMUM_MODULUS_SIZE) fatal("Invalid RSA key length: minimum is %d bits", - SSH_RSA_MINIMUM_MODULUS_SIZE); + SSH_RSA_MINIMUM_MODULUS_SIZE); break; case KEY_ECDSA: if (sshkey_ecdsa_bits_to_nid(*bitsp) == -1) @@ -286,7 +285,7 @@ ask_filename(struct passwd *pw, const char *prompt) } } snprintf(identity_file, sizeof(identity_file), - "%s/%s", pw->pw_dir, name); + "%s/%s", pw->pw_dir, name); printf("%s (%s): ", prompt, identity_file); fflush(stdout); if (fgets(buf, sizeof(buf), stdin) == NULL) @@ -338,9 +337,9 @@ do_convert_to_ssh2(struct passwd *pw, struct sshkey *k) fatal("key_to_blob failed: %s", ssh_err(r)); /* Comment + surrounds must fit into 72 chars (RFC 4716 sec 3.3) */ snprintf(comment, sizeof(comment), - "%u-bit %s, converted by %s@%s from OpenSSH", - sshkey_size(k), sshkey_type(k), - pw->pw_name, hostname); + "%u-bit %s, converted by %s@%s from OpenSSH", + sshkey_size(k), sshkey_type(k), + pw->pw_name, hostname); fprintf(stdout, "%s\n", SSH_COM_PUBLIC_BEGIN); fprintf(stdout, "Comment: \"%s\"\n", comment); @@ -389,7 +388,7 @@ do_convert_to_pem(struct sshkey *k) fatal("PEM_write_DSAPublicKey failed"); break; #endif - /* XXX ECDSA? */ + /* XXX ECDSA? */ default: fatal("%s: unsupported key type %s", __func__, sshkey_type(k)); } @@ -440,7 +439,7 @@ buffer_get_bignum_bits(struct sshbuf *b, BIGNUM *value) bytes = (bignum_bits + 7) / 8; if (sshbuf_len(b) < bytes) fatal("%s: input buffer too small: need %d have %zu", - __func__, bytes, sshbuf_len(b)); + __func__, bytes, sshbuf_len(b)); if (BN_bin2bn(sshbuf_ptr(b), bytes, value) == NULL) fatal("%s: BN_bin2bn failed", __func__); if ((r = sshbuf_consume(b, bytes)) != 0) @@ -466,16 +465,16 @@ do_convert_private_ssh2_from_blob(u_char *blob, u_int blen) if (magic != SSH_COM_PRIVATE_KEY_MAGIC) { error("bad magic 0x%x != 0x%x", magic, - SSH_COM_PRIVATE_KEY_MAGIC); + SSH_COM_PRIVATE_KEY_MAGIC); sshbuf_free(b); return NULL; } if ((r = sshbuf_get_u32(b, &i1)) != 0 || - (r = sshbuf_get_cstring(b, &type, NULL)) != 0 || - (r = sshbuf_get_cstring(b, &cipher, NULL)) != 0 || - (r = sshbuf_get_u32(b, &i2)) != 0 || - (r = sshbuf_get_u32(b, &i3)) != 0 || - (r = sshbuf_get_u32(b, &i4)) != 0) + (r = sshbuf_get_cstring(b, &type, NULL)) != 0 || + (r = sshbuf_get_cstring(b, &cipher, NULL)) != 0 || + (r = sshbuf_get_u32(b, &i2)) != 0 || + (r = sshbuf_get_u32(b, &i3)) != 0 || + (r = sshbuf_get_u32(b, &i4)) != 0) fatal("%s: buffer error: %s", __func__, ssh_err(r)); debug("ignore (%d %d %d %d)", i1, i2, i3, i4); if (strcmp(cipher, "none") != 0) { @@ -489,11 +488,9 @@ do_convert_private_ssh2_from_blob(u_char *blob, u_int blen) if (strstr(type, "dsa")) { ktype = KEY_DSA; - } - else if (strstr(type, "rsa")) { + } else if (strstr(type, "rsa")) { ktype = KEY_RSA; - } - else { + } else { sshbuf_free(b); free(type); return NULL; @@ -512,8 +509,8 @@ do_convert_private_ssh2_from_blob(u_char *blob, u_int blen) break; case KEY_RSA: if ((r = sshbuf_get_u8(b, &e1)) != 0 || - (e1 < 30 && (r = sshbuf_get_u8(b, &e2)) != 0) || - (e1 < 30 && (r = sshbuf_get_u8(b, &e3)) != 0)) + (e1 < 30 && (r = sshbuf_get_u8(b, &e2)) != 0) || + (e1 < 30 && (r = sshbuf_get_u8(b, &e3)) != 0)) fatal("%s: buffer error: %s", __func__, ssh_err(r)); e = e1; debug("e %lx", e); @@ -542,12 +539,12 @@ do_convert_private_ssh2_from_blob(u_char *blob, u_int blen) rlen = sshbuf_len(b); if (rlen != 0) error("do_convert_private_ssh2_from_blob: " - "remaining bytes in key blob %d", rlen); + "remaining bytes in key blob %d", rlen); sshbuf_free(b); /* try the key */ if (sshkey_sign(key, &sig, &slen, data, sizeof(data), NULL, 0) != 0 || - sshkey_verify(key, sig, slen, data, sizeof(data), 0) != 0) { + sshkey_verify(key, sig, slen, data, sizeof(data), 0) != 0) { sshkey_free(key); free(sig); return NULL; @@ -599,7 +596,7 @@ do_convert_from_ssh2(struct passwd *pw, struct sshkey **k, int *private) if (blen > 0 && line[blen - 1] == '\\') escaped++; if (strncmp(line, "----", 4) == 0 || - strstr(line, ": ") != NULL) { + strstr(line, ": ") != NULL) { if (strstr(line, SSH_COM_PRIVATE_BEGIN) != NULL) *private = 1; if (strstr(line, " END ") != NULL) { @@ -617,10 +614,10 @@ do_convert_from_ssh2(struct passwd *pw, struct sshkey **k, int *private) } len = strlen(encoded); if (((len % 4) == 3) && - (encoded[len - 1] == '=') && - (encoded[len - 2] == '=') && - (encoded[len - 3] == '=')) - encoded[len - 3] = '\0'; + (encoded[len-1] == '=') && + (encoded[len-2] == '=') && + (encoded[len-3] == '=')) + encoded[len-3] = '\0'; blen = uudecode(encoded, blob, sizeof(blob)); if (blen < 0) fatal("uudecode failed."); @@ -641,7 +638,7 @@ do_convert_from_pkcs8(struct sshkey **k, int *private) fatal("%s: %s: %s", __progname, identity_file, strerror(errno)); if ((pubkey = PEM_read_PUBKEY(fp, NULL, NULL, NULL)) == NULL) { fatal("%s: %s is not a recognised public key format", __func__, - identity_file); + identity_file); } fclose(fp); switch (EVP_PKEY_type(pubkey->type)) { @@ -668,7 +665,7 @@ do_convert_from_pkcs8(struct sshkey **k, int *private) #endif default: fatal("%s: unsupported pubkey type %d", __func__, - EVP_PKEY_type(pubkey->type)); + EVP_PKEY_type(pubkey->type)); } EVP_PKEY_free(pubkey); return; @@ -739,26 +736,25 @@ do_convert_from(struct passwd *pw) ok = 1; if (ok) fprintf(stdout, "\n"); - } - else { + } else { switch (k->type) { case KEY_DSA: ok = PEM_write_DSAPrivateKey(stdout, k->dsa, NULL, - NULL, 0, NULL, NULL); + NULL, 0, NULL, NULL); break; #ifdef OPENSSL_HAS_ECC case KEY_ECDSA: ok = PEM_write_ECPrivateKey(stdout, k->ecdsa, NULL, - NULL, 0, NULL, NULL); + NULL, 0, NULL, NULL); break; #endif case KEY_RSA: ok = PEM_write_RSAPrivateKey(stdout, k->rsa, NULL, - NULL, 0, NULL, NULL); + NULL, 0, NULL, NULL); break; default: fatal("%s: unsupported key type %s", __func__, - sshkey_type(k)); + sshkey_type(k)); } } @@ -799,7 +795,7 @@ do_download(struct passwd *pw) char *fp, *ra; fptype = print_bubblebabble ? SSH_DIGEST_SHA1 : fingerprint_hash; - rep = print_bubblebabble ? SSH_FP_BUBBLEBABBLE : SSH_FP_DEFAULT; + rep = print_bubblebabble ? SSH_FP_BUBBLEBABBLE : SSH_FP_DEFAULT; pkcs11_init(0); nkeys = pkcs11_add_provider(pkcs11provider, NULL, &keys); @@ -809,18 +805,17 @@ do_download(struct passwd *pw) if (print_fingerprint) { fp = sshkey_fingerprint(keys[i], fptype, rep); ra = sshkey_fingerprint(keys[i], fingerprint_hash, - SSH_FP_RANDOMART); + SSH_FP_RANDOMART); if (fp == NULL || ra == NULL) fatal("%s: sshkey_fingerprint fail", __func__); printf("%u %s %s (PKCS11 key)\n", sshkey_size(keys[i]), - fp, sshkey_type(keys[i])); + fp, sshkey_type(keys[i])); if (log_level >= SYSLOG_LEVEL_VERBOSE) printf("%s\n", ra); free(ra); free(fp); - } - else { - (void)sshkey_write(keys[i], stdout); /* XXX check */ + } else { + (void) sshkey_write(keys[i], stdout); /* XXX check */ fprintf(stdout, "\n"); } sshkey_free(keys[i]); @@ -856,13 +851,13 @@ fingerprint_one_key(const struct sshkey *public, const char *comment) int fptype; fptype = print_bubblebabble ? SSH_DIGEST_SHA1 : fingerprint_hash; - rep = print_bubblebabble ? SSH_FP_BUBBLEBABBLE : SSH_FP_DEFAULT; + rep = print_bubblebabble ? SSH_FP_BUBBLEBABBLE : SSH_FP_DEFAULT; fp = sshkey_fingerprint(public, fptype, rep); ra = sshkey_fingerprint(public, fingerprint_hash, SSH_FP_RANDOMART); if (fp == NULL || ra == NULL) fatal("%s: sshkey_fingerprint failed", __func__); mprintf("%u %s %s (%s)\n", sshkey_size(public), fp, - comment ? comment : "no comment", sshkey_type(public)); + comment ? comment : "no comment", sshkey_type(public)); if (log_level >= SYSLOG_LEVEL_VERBOSE) printf("%s\n", ra); free(ra); @@ -882,7 +877,7 @@ fingerprint_private(const char *path) if ((r = sshkey_load_public(path, &public, &comment)) != 0) { debug("load public \"%s\": %s", path, ssh_err(r)); if ((r = sshkey_load_private(path, NULL, - &public, &comment)) != 0) { + &public, &comment)) != 0) { debug("load private \"%s\": %s", path, ssh_err(r)); fatal("%s is not a key file.", path); } @@ -910,8 +905,7 @@ do_fingerprint(struct passwd *pw) if (strcmp(identity_file, "-") == 0) { f = stdin; path = "(stdin)"; - } - else if ((f = fopen(path, "r")) == NULL) + } else if ((f = fopen(path, "r")) == NULL) fatal("%s: %s: %s", __progname, path, strerror(errno)); while (read_keyfile_line(f, path, line, sizeof(line), &lnum) == 0) { @@ -927,13 +921,13 @@ do_fingerprint(struct passwd *pw) * or known_hosts. */ - /* - * Try private keys first. Assume a key is private if - * "SSH PRIVATE KEY" appears on the first line and we're - * not reading from stdin (XXX support private keys on stdin). - */ + /* + * Try private keys first. Assume a key is private if + * "SSH PRIVATE KEY" appears on the first line and we're + * not reading from stdin (XXX support private keys on stdin). + */ if (lnum == 1 && strcmp(identity_file, "-") != 0 && - strstr(cp, "PRIVATE KEY") != NULL) { + strstr(cp, "PRIVATE KEY") != NULL) { fclose(f); fingerprint_private(path); exit(0); @@ -947,12 +941,12 @@ do_fingerprint(struct passwd *pw) if ((public = try_read_key(&cp)) == NULL) { i = strtol(cp, &ep, 10); if (i == 0 || ep == NULL || - (*ep != ' ' && *ep != '\t')) { + (*ep != ' ' && *ep != '\t')) { int quoted = 0; comment = cp; for (; *cp && (quoted || (*cp != ' ' && - *cp != '\t')); cp++) { + *cp != '\t')); cp++) { if (*cp == '\\' && cp[1] == '"') cp++; /* Skip both */ else if (*cp == '"') @@ -1017,16 +1011,15 @@ do_gen_all_hostkeys(struct passwd *pw) prv_tmp = pub_tmp = prv_file = pub_file = NULL; xasprintf(&prv_file, "%s%s", - identity_file, key_types[i].path); + identity_file, key_types[i].path); /* Check whether private key exists and is not zero-length */ if (stat(prv_file, &st) == 0) { if (st.st_size != 0) goto next; - } - else if (errno != ENOENT) { + } else if (errno != ENOENT) { error("Could not stat %s: %s", key_types[i].path, - strerror(errno)); + strerror(errno)); goto failnext; } @@ -1035,11 +1028,11 @@ do_gen_all_hostkeys(struct passwd *pw) * key generation. */ xasprintf(&prv_tmp, "%s%s.XXXXXXXXXX", - identity_file, key_types[i].path); + identity_file, key_types[i].path); xasprintf(&pub_tmp, "%s%s.pub.XXXXXXXXXX", - identity_file, key_types[i].path); + identity_file, key_types[i].path); xasprintf(&pub_file, "%s%s.pub", - identity_file, key_types[i].path); + identity_file, key_types[i].path); if (first == 0) { first = 1; @@ -1050,7 +1043,7 @@ do_gen_all_hostkeys(struct passwd *pw) type = sshkey_type_from_name(key_types[i].key_type); if ((fd = mkstemp(prv_tmp)) == -1) { error("Could not save your public key in %s: %s", - prv_tmp, strerror(errno)); + prv_tmp, strerror(errno)); goto failnext; } close(fd); /* just using mkstemp() to generate/reserve a name */ @@ -1063,16 +1056,16 @@ do_gen_all_hostkeys(struct passwd *pw) if ((r = sshkey_from_private(private, &public)) != 0) fatal("sshkey_from_private failed: %s", ssh_err(r)); snprintf(comment, sizeof comment, "%s@%s", pw->pw_name, - hostname); + hostname); if ((r = sshkey_save_private(private, prv_tmp, "", - comment, use_new_format, new_format_cipher, rounds)) != 0) { + comment, use_new_format, new_format_cipher, rounds)) != 0) { error("Saving key \"%s\" failed: %s", - prv_tmp, ssh_err(r)); + prv_tmp, ssh_err(r)); goto failnext; } if ((fd = mkstemp(pub_tmp)) == -1) { error("Could not save your public key in %s: %s", - pub_tmp, strerror(errno)); + pub_tmp, strerror(errno)); goto failnext; } #ifdef WINDOWS @@ -1112,17 +1105,17 @@ do_gen_all_hostkeys(struct passwd *pw) /* Rename temporary files to their permanent locations. */ if (rename(pub_tmp, pub_file) != 0) { error("Unable to move %s into position: %s", - pub_file, strerror(errno)); + pub_file, strerror(errno)); goto failnext; } if (rename(prv_tmp, prv_file) != 0) { error("Unable to move %s into position: %s", - key_types[i].path, strerror(errno)); - failnext: + key_types[i].path, strerror(errno)); + failnext: first = 0; goto next; } - next: + next: sshkey_free(private); sshkey_free(public); free(prv_tmp); @@ -1161,8 +1154,8 @@ known_hosts_hash(struct hostkey_foreach_line *l, void *_ctx) fprintf(ctx->out, "%s\n", l->line); if (has_wild && !find_host) { logit("%s:%lu: ignoring host name " - "with wildcard: %.64s", l->path, - l->linenum, l->hosts); + "with wildcard: %.64s", l->path, + l->linenum, l->hosts); } return 0; } @@ -1202,15 +1195,14 @@ known_hosts_find_delete(struct hostkey_foreach_line *l, void *_ctx) char *fp; fptype = print_bubblebabble ? SSH_DIGEST_SHA1 : fingerprint_hash; - rep = print_bubblebabble ? SSH_FP_BUBBLEBABBLE : SSH_FP_DEFAULT; + rep = print_bubblebabble ? SSH_FP_BUBBLEBABBLE : SSH_FP_DEFAULT; if (l->status == HKF_STATUS_MATCHED) { if (delete_host) { if (l->marker != MRK_NONE) { /* Don't remove CA and revocation lines */ fprintf(ctx->out, "%s\n", l->line); - } - else { + } else { /* * Hostname matches and has no CA/revoke * marker, delete it by *not* writing the @@ -1219,32 +1211,29 @@ known_hosts_find_delete(struct hostkey_foreach_line *l, void *_ctx) ctx->found_key = 1; if (!quiet) printf("# Host %s found: line %lu\n", - ctx->host, l->linenum); + ctx->host, l->linenum); } return 0; - } - else if (find_host) { + } else if (find_host) { ctx->found_key = 1; if (!quiet) { printf("# Host %s found: line %lu %s\n", - ctx->host, - l->linenum, l->marker == MRK_CA ? "CA" : - (l->marker == MRK_REVOKE ? "REVOKED" : "")); + ctx->host, + l->linenum, l->marker == MRK_CA ? "CA" : + (l->marker == MRK_REVOKE ? "REVOKED" : "")); } if (hash_hosts) known_hosts_hash(l, ctx); else if (print_fingerprint) { fp = sshkey_fingerprint(l->key, fptype, rep); mprintf("%s %s %s %s\n", ctx->host, - sshkey_type(l->key), fp, l->comment); + sshkey_type(l->key), fp, l->comment); free(fp); - } - else + } else fprintf(ctx->out, "%s\n", l->line); return 0; } - } - else if (delete_host) { + } else if (delete_host) { /* Retain non-matching hosts when deleting */ if (l->status == HKF_STATUS_INVALID) { ctx->invalid = 1; @@ -1259,9 +1248,9 @@ static void do_known_hosts(struct passwd *pw, const char *name) { #ifdef WINDOWS - fatal("Updating known_hosts is not supported in Windows yet."); + fatal("Updating known_hosts is not supported in Windows yet."); #else /* !WINDOWS */ - + char *cp, tmp[PATH_MAX], old[PATH_MAX]; int r, fd, oerrno, inplace = 0; struct known_hosts_ctx ctx; @@ -1270,7 +1259,7 @@ do_known_hosts(struct passwd *pw, const char *name) if (!have_identity) { cp = tilde_expand_filename(_PATH_SSH_USER_HOSTFILE, pw->pw_uid); if (strlcpy(identity_file, cp, sizeof(identity_file)) >= - sizeof(identity_file)) + sizeof(identity_file)) fatal("Specified known hosts path too long"); free(cp); have_identity = 1; @@ -1286,9 +1275,9 @@ do_known_hosts(struct passwd *pw, const char *name) */ if (!find_host && (hash_hosts || delete_host)) { if (strlcpy(tmp, identity_file, sizeof(tmp)) >= sizeof(tmp) || - strlcat(tmp, ".XXXXXXXXXX", sizeof(tmp)) >= sizeof(tmp) || - strlcpy(old, identity_file, sizeof(old)) >= sizeof(old) || - strlcat(old, ".old", sizeof(old)) >= sizeof(old)) + strlcat(tmp, ".XXXXXXXXXX", sizeof(tmp)) >= sizeof(tmp) || + strlcpy(old, identity_file, sizeof(old)) >= sizeof(old) || + strlcat(old, ".old", sizeof(old)) >= sizeof(old)) fatal("known_hosts path too long"); umask(077); if ((fd = mkstemp(tmp)) == -1) @@ -1305,8 +1294,8 @@ do_known_hosts(struct passwd *pw, const char *name) foreach_options = find_host ? HKF_WANT_MATCH : 0; foreach_options |= print_fingerprint ? HKF_WANT_PARSE_KEY : 0; if ((r = hostkeys_foreach(identity_file, - hash_hosts ? known_hosts_hash : known_hosts_find_delete, &ctx, - name, NULL, foreach_options)) != 0) { + hash_hosts ? known_hosts_hash : known_hosts_find_delete, &ctx, + name, NULL, foreach_options)) != 0) { if (inplace) unlink(tmp); fatal("%s: hostkeys_foreach failed: %s", __func__, ssh_err(r)); @@ -1319,27 +1308,25 @@ do_known_hosts(struct passwd *pw, const char *name) error("%s is not a valid known_hosts file.", identity_file); if (inplace) { error("Not replacing existing known_hosts " - "file because of errors"); + "file because of errors"); unlink(tmp); } exit(1); - } - else if (delete_host && !ctx.found_key) { + } else if (delete_host && !ctx.found_key) { logit("Host %s not found in %s", name, identity_file); if (inplace) unlink(tmp); - } - else if (inplace) { + } else if (inplace) { /* Backup existing file */ if (unlink(old) == -1 && errno != ENOENT) fatal("unlink %.100s: %s", old, strerror(errno)); if (link(identity_file, old) == -1) fatal("link %.100s to %.100s: %s", identity_file, old, - strerror(errno)); + strerror(errno)); /* Move new one into place */ if (rename(tmp, identity_file) == -1) { error("rename\"%s\" to \"%s\": %s", tmp, identity_file, - strerror(errno)); + strerror(errno)); unlink(tmp); unlink(old); exit(1); @@ -1350,11 +1337,11 @@ do_known_hosts(struct passwd *pw, const char *name) if (ctx.has_unhashed) { logit("WARNING: %s contains unhashed entries", old); logit("Delete this file to ensure privacy " - "of hostnames"); + "of hostnames"); } } - exit(find_host && !ctx.found_key); + exit (find_host && !ctx.found_key); #endif /* !WINDOWS */ } @@ -1382,17 +1369,16 @@ do_change_passphrase(struct passwd *pw) old_passphrase = xstrdup(identity_passphrase); else old_passphrase = - read_passphrase("Enter old passphrase: ", - RP_ALLOW_STDIN); + read_passphrase("Enter old passphrase: ", + RP_ALLOW_STDIN); r = sshkey_load_private(identity_file, old_passphrase, - &private, &comment); + &private, &comment); explicit_bzero(old_passphrase, strlen(old_passphrase)); free(old_passphrase); if (r != 0) goto badkey; - } - else if (r != 0) { - badkey: + } else if (r != 0) { + badkey: fatal("Failed to load key %s: %s", identity_file, ssh_err(r)); } if (comment) @@ -1402,13 +1388,12 @@ do_change_passphrase(struct passwd *pw) if (identity_new_passphrase) { passphrase1 = xstrdup(identity_new_passphrase); passphrase2 = NULL; - } - else { + } else { passphrase1 = read_passphrase("Enter new passphrase (empty for no " - "passphrase): ", RP_ALLOW_STDIN); + "passphrase): ", RP_ALLOW_STDIN); passphrase2 = read_passphrase("Enter same passphrase again: ", - RP_ALLOW_STDIN); + RP_ALLOW_STDIN); /* Verify that they are the same. */ if (strcmp(passphrase1, passphrase2) != 0) { @@ -1426,9 +1411,9 @@ do_change_passphrase(struct passwd *pw) /* Save the file using the new passphrase. */ if ((r = sshkey_save_private(private, identity_file, passphrase1, - comment, use_new_format, new_format_cipher, rounds)) != 0) { + comment, use_new_format, new_format_cipher, rounds)) != 0) { error("Saving key \"%s\" failed: %s.", - identity_file, ssh_err(r)); + identity_file, ssh_err(r)); explicit_bzero(passphrase1, strlen(passphrase1)); free(passphrase1); sshkey_free(private); @@ -1465,7 +1450,7 @@ do_print_resource_record(struct passwd *pw, char *fname, char *hname) } if ((r = sshkey_load_public(fname, &public, &comment)) != 0) fatal("Failed to read v2 public key from \"%s\": %s.", - fname, ssh_err(r)); + fname, ssh_err(r)); export_dns_rr(hname, public, stdout, print_generic); sshkey_free(public); free(comment); @@ -1490,11 +1475,11 @@ do_change_comment(struct passwd *pw) if (stat(identity_file, &st) < 0) fatal("%s: %s", identity_file, strerror(errno)); if ((r = sshkey_load_private(identity_file, "", - &private, &comment)) == 0) + &private, &comment)) == 0) passphrase = xstrdup(""); else if (r != SSH_ERR_KEY_WRONG_PASSPHRASE) fatal("Cannot load private key \"%s\": %s.", - identity_file, ssh_err(r)); + identity_file, ssh_err(r)); else { if (identity_passphrase) passphrase = xstrdup(identity_passphrase); @@ -1502,20 +1487,20 @@ do_change_comment(struct passwd *pw) passphrase = xstrdup(identity_new_passphrase); else passphrase = read_passphrase("Enter passphrase: ", - RP_ALLOW_STDIN); + RP_ALLOW_STDIN); /* Try to load using the passphrase. */ if ((r = sshkey_load_private(identity_file, passphrase, - &private, &comment)) != 0) { + &private, &comment)) != 0) { explicit_bzero(passphrase, strlen(passphrase)); free(passphrase); fatal("Cannot load private key \"%s\": %s.", - identity_file, ssh_err(r)); + identity_file, ssh_err(r)); } } if (private->type != KEY_ED25519 && !use_new_format) { error("Comments are only supported for keys stored in " - "the new format (-o)."); + "the new format (-o)."); explicit_bzero(passphrase, strlen(passphrase)); sshkey_free(private); exit(1); @@ -1527,8 +1512,7 @@ do_change_comment(struct passwd *pw) if (identity_comment) { strlcpy(new_comment, identity_comment, sizeof(new_comment)); - } - else { + } else { printf("Enter new comment: "); fflush(stdout); if (!fgets(new_comment, sizeof(new_comment), stdin)) { @@ -1541,9 +1525,9 @@ do_change_comment(struct passwd *pw) /* Save the file using the new passphrase. */ if ((r = sshkey_save_private(private, identity_file, passphrase, - new_comment, use_new_format, new_format_cipher, rounds)) != 0) { + new_comment, use_new_format, new_format_cipher, rounds)) != 0) { error("Saving key \"%s\" failed: %s", - identity_file, ssh_err(r)); + identity_file, ssh_err(r)); explicit_bzero(passphrase, strlen(passphrase)); free(passphrase); sshkey_free(private); @@ -1560,7 +1544,6 @@ do_change_comment(struct passwd *pw) fd = open(identity_file, O_WRONLY | O_CREAT | O_TRUNC, 0644); if (fd == -1) fatal("Could not save your public key in %s", identity_file); - #ifdef WINDOWS /* Windows POSIX adpater does not support fdopen() on open(file)*/ close(fd); @@ -1571,7 +1554,6 @@ do_change_comment(struct passwd *pw) if (f == NULL) fatal("fdopen %s failed: %s", identity_file, strerror(errno)); #endif /* !WINDOWS */ - if ((r = sshkey_write(public, f)) != 0) fatal("write key failed: %s", ssh_err(r)); sshkey_free(public); @@ -1591,7 +1573,7 @@ add_flag_option(struct sshbuf *c, const char *name) debug3("%s: %s", __func__, name); if ((r = sshbuf_put_cstring(c, name)) != 0 || - (r = sshbuf_put_string(c, NULL, 0)) != 0) + (r = sshbuf_put_string(c, NULL, 0)) != 0) fatal("%s: buffer error: %s", __func__, ssh_err(r)); } @@ -1605,8 +1587,8 @@ add_string_option(struct sshbuf *c, const char *name, const char *value) if ((b = sshbuf_new()) == NULL) fatal("%s: sshbuf_new failed", __func__); if ((r = sshbuf_put_cstring(b, value)) != 0 || - (r = sshbuf_put_cstring(c, name)) != 0 || - (r = sshbuf_put_stringb(c, b)) != 0) + (r = sshbuf_put_cstring(c, name)) != 0 || + (r = sshbuf_put_stringb(c, b)) != 0) fatal("%s: buffer error: %s", __func__, ssh_err(r)); sshbuf_free(b); @@ -1621,35 +1603,35 @@ prepare_options_buf(struct sshbuf *c, int which) sshbuf_reset(c); if ((which & OPTIONS_CRITICAL) != 0 && - certflags_command != NULL) + certflags_command != NULL) add_string_option(c, "force-command", certflags_command); if ((which & OPTIONS_EXTENSIONS) != 0 && - (certflags_flags & CERTOPT_X_FWD) != 0) + (certflags_flags & CERTOPT_X_FWD) != 0) add_flag_option(c, "permit-X11-forwarding"); if ((which & OPTIONS_EXTENSIONS) != 0 && - (certflags_flags & CERTOPT_AGENT_FWD) != 0) + (certflags_flags & CERTOPT_AGENT_FWD) != 0) add_flag_option(c, "permit-agent-forwarding"); if ((which & OPTIONS_EXTENSIONS) != 0 && - (certflags_flags & CERTOPT_PORT_FWD) != 0) + (certflags_flags & CERTOPT_PORT_FWD) != 0) add_flag_option(c, "permit-port-forwarding"); if ((which & OPTIONS_EXTENSIONS) != 0 && - (certflags_flags & CERTOPT_PTY) != 0) + (certflags_flags & CERTOPT_PTY) != 0) add_flag_option(c, "permit-pty"); if ((which & OPTIONS_EXTENSIONS) != 0 && - (certflags_flags & CERTOPT_USER_RC) != 0) + (certflags_flags & CERTOPT_USER_RC) != 0) add_flag_option(c, "permit-user-rc"); if ((which & OPTIONS_CRITICAL) != 0 && - certflags_src_addr != NULL) + certflags_src_addr != NULL) add_string_option(c, "source-address", certflags_src_addr); for (i = 0; i < ncert_userext; i++) { if ((cert_userext[i].crit && (which & OPTIONS_EXTENSIONS)) || - (!cert_userext[i].crit && (which & OPTIONS_CRITICAL))) + (!cert_userext[i].crit && (which & OPTIONS_CRITICAL))) continue; if (cert_userext[i].val == NULL) add_flag_option(c, cert_userext[i].key); else { add_string_option(c, cert_userext[i].key, - cert_userext[i].val); + cert_userext[i].val); } } } @@ -1663,7 +1645,7 @@ load_pkcs11_key(char *path) if ((r = sshkey_load_public(path, &public, NULL)) != 0) fatal("Couldn't load CA public key \"%s\": %s", - path, ssh_err(r)); + path, ssh_err(r)); nkeys = pkcs11_add_provider(pkcs11provider, identity_passphrase, &keys); debug3("%s: %d keys", __func__, nkeys); @@ -1688,13 +1670,13 @@ load_pkcs11_key(char *path) /* Signer for sshkey_certify_custom that uses the agent */ static int agent_signer(const struct sshkey *key, u_char **sigp, size_t *lenp, - const u_char *data, size_t datalen, - const char *alg, u_int compat, void *ctx) + const u_char *data, size_t datalen, + const char *alg, u_int compat, void *ctx) { int *agent_fdp = (int *)ctx; return ssh_agent_sign(*agent_fdp, key, sigp, lenp, - data, datalen, alg, compat); + data, datalen, alg, compat); } static void @@ -1716,8 +1698,7 @@ do_ca_sign(struct passwd *pw, int argc, char **argv) /* If a PKCS#11 token was specified then try to use it */ if ((ca = load_pkcs11_key(tmp)) == NULL) fatal("No PKCS#11 key matching %s found", ca_key_path); - } - else if (prefer_agent) { + } else if (prefer_agent) { /* * Agent signature requested. Try to use agent after making * sure the public key specified is actually present in the @@ -1725,10 +1706,10 @@ do_ca_sign(struct passwd *pw, int argc, char **argv) */ if ((r = sshkey_load_public(tmp, &ca, NULL)) != 0) fatal("Cannot load CA public key %s: %s", - tmp, ssh_err(r)); + tmp, ssh_err(r)); if ((r = ssh_get_authentication_socket(&agent_fd)) != 0) fatal("Cannot use public key for CA signature: %s", - ssh_err(r)); + ssh_err(r)); if ((r = ssh_fetch_identitylist(agent_fd, &agent_ids)) != 0) fatal("Retrieve agent key list: %s", ssh_err(r)); found = 0; @@ -1742,17 +1723,16 @@ do_ca_sign(struct passwd *pw, int argc, char **argv) fatal("CA key %s not found in agent", tmp); ssh_free_identitylist(agent_ids); ca->flags |= SSHKEY_FLAG_EXT; - } - else { + } else { /* CA key is assumed to be a private key on the filesystem */ ca = load_identity(tmp); } free(tmp); if (key_type_name != NULL && - sshkey_type_from_name(key_type_name) != ca->type) { + sshkey_type_from_name(key_type_name) != ca->type) { fatal("CA key type %s doesn't match specified %s", - sshkey_ssh_name(ca), key_type_name); + sshkey_ssh_name(ca), key_type_name); } for (i = 0; i < argc; i++) { @@ -1768,20 +1748,20 @@ do_ca_sign(struct passwd *pw, int argc, char **argv) } free(otmp); } - + tmp = tilde_expand_filename(argv[i], pw->pw_uid); if ((r = sshkey_load_public(tmp, &public, &comment)) != 0) fatal("%s: unable to open \"%s\": %s", - __func__, tmp, ssh_err(r)); + __func__, tmp, ssh_err(r)); if (public->type != KEY_RSA && public->type != KEY_DSA && - public->type != KEY_ECDSA && public->type != KEY_ED25519) + public->type != KEY_ECDSA && public->type != KEY_ED25519) fatal("%s: key \"%s\" type %s cannot be certified", - __func__, tmp, sshkey_type(public)); + __func__, tmp, sshkey_type(public)); /* Prepare certificate to sign */ if ((r = sshkey_to_certified(public)) != 0) fatal("Could not upgrade key %s to certificate: %s", - tmp, ssh_err(r)); + tmp, ssh_err(r)); public->cert->type = cert_key_type; public->cert->serial = (u_int64_t)cert_serial; public->cert->key_id = xstrdup(cert_key_id); @@ -1791,21 +1771,20 @@ do_ca_sign(struct passwd *pw, int argc, char **argv) public->cert->valid_before = cert_valid_to; prepare_options_buf(public->cert->critical, OPTIONS_CRITICAL); prepare_options_buf(public->cert->extensions, - OPTIONS_EXTENSIONS); + OPTIONS_EXTENSIONS); if ((r = sshkey_from_private(ca, - &public->cert->signature_key)) != 0) + &public->cert->signature_key)) != 0) fatal("sshkey_from_private (ca key): %s", ssh_err(r)); if (agent_fd != -1 && (ca->flags & SSHKEY_FLAG_EXT) != 0) { if ((r = sshkey_certify_custom(public, ca, - key_type_name, agent_signer, &agent_fd)) != 0) + key_type_name, agent_signer, &agent_fd)) != 0) fatal("Couldn't certify key %s via agent: %s", - tmp, ssh_err(r)); - } - else { + tmp, ssh_err(r)); + } else { if ((sshkey_certify(public, ca, key_type_name)) != 0) fatal("Couldn't certify key %s: %s", - tmp, ssh_err(r)); + tmp, ssh_err(r)); } if ((cp = strrchr(tmp, '.')) != NULL && strcmp(cp, ".pub") == 0) @@ -1813,9 +1792,9 @@ do_ca_sign(struct passwd *pw, int argc, char **argv) xasprintf(&out, "%s-cert.pub", tmp); free(tmp); - if ((fd = open(out, O_WRONLY | O_CREAT | O_TRUNC, 0644)) == -1) + if ((fd = open(out, O_WRONLY|O_CREAT|O_TRUNC, 0644)) == -1) fatal("Could not open \"%s\" for writing: %s", out, - strerror(errno)); + strerror(errno)); #ifdef WINDOWS /* Windows POSIX adpater does not support fdopen() on open(file)*/ close(fd); @@ -1827,20 +1806,20 @@ do_ca_sign(struct passwd *pw, int argc, char **argv) #endif /* !WINDOWS */ if ((r = sshkey_write(public, f)) != 0) fatal("Could not write certified key to %s: %s", - out, ssh_err(r)); + out, ssh_err(r)); fprintf(f, " %s\n", comment); fclose(f); if (!quiet) { sshkey_format_cert_validity(public->cert, - valid, sizeof(valid)); + valid, sizeof(valid)); logit("Signed %s key %s: id \"%s\" serial %llu%s%s " - "valid %s", sshkey_cert_type(public), - out, public->cert->key_id, - (unsigned long long)public->cert->serial, - cert_principals != NULL ? " for " : "", - cert_principals != NULL ? cert_principals : "", - valid); + "valid %s", sshkey_cert_type(public), + out, public->cert->key_id, + (unsigned long long)public->cert->serial, + cert_principals != NULL ? " for " : "", + cert_principals != NULL ? cert_principals : "", + valid); } sshkey_free(public); @@ -1886,7 +1865,7 @@ parse_absolute_time(const char *s) case 14: fmt = "%Y-%m-%dT%H:%M:%S"; snprintf(buf, sizeof(buf), "%.4s-%.2s-%.2sT%.2s:%.2s:%.2s", - s, s + 4, s + 6, s + 8, s + 10, s + 12); + s, s + 4, s + 6, s + 8, s + 10, s + 12); break; default: fatal("Invalid certificate time format \"%s\"", s); @@ -1916,7 +1895,7 @@ parse_cert_times(char *timespec) * Backdate certificate one minute to avoid problems on hosts * with poorly-synchronised clocks. */ - cert_valid_from = ((now - 59) / 60) * 60; + cert_valid_from = ((now - 59)/ 60) * 60; return; } @@ -1985,8 +1964,7 @@ add_cert_option(char *opt) if (certflags_command != NULL) fatal("force-command already specified"); certflags_command = xstrdup(val); - } - else if (strncasecmp(opt, "source-address=", 15) == 0) { + } else if (strncasecmp(opt, "source-address=", 15) == 0) { val = opt + 15; if (*val == '\0') fatal("Empty source-address option"); @@ -1995,21 +1973,19 @@ add_cert_option(char *opt) if (addr_match_cidr_list(NULL, val) != 0) fatal("Invalid source-address list"); certflags_src_addr = xstrdup(val); - } - else if (strncasecmp(opt, "extension:", 10) == 0 || - (iscrit = (strncasecmp(opt, "critical:", 9) == 0))) { + } else if (strncasecmp(opt, "extension:", 10) == 0 || + (iscrit = (strncasecmp(opt, "critical:", 9) == 0))) { val = xstrdup(strchr(opt, ':') + 1); if ((cp = strchr(val, '=')) != NULL) *cp++ = '\0'; cert_userext = xreallocarray(cert_userext, ncert_userext + 1, - sizeof(*cert_userext)); + sizeof(*cert_userext)); cert_userext[ncert_userext].key = val; cert_userext[ncert_userext].val = cp == NULL ? - NULL : xstrdup(cp); + NULL : xstrdup(cp); cert_userext[ncert_userext].crit = iscrit; ncert_userext++; - } - else + } else fatal("Unsupported certificate option \"%s\"", opt); } @@ -2026,28 +2002,27 @@ show_options(struct sshbuf *optbuf, int in_critical) sshbuf_free(option); option = NULL; if ((r = sshbuf_get_cstring(options, &name, NULL)) != 0 || - (r = sshbuf_froms(options, &option)) != 0) + (r = sshbuf_froms(options, &option)) != 0) fatal("%s: buffer error: %s", __func__, ssh_err(r)); printf(" %s", name); if (!in_critical && - (strcmp(name, "permit-X11-forwarding") == 0 || - strcmp(name, "permit-agent-forwarding") == 0 || - strcmp(name, "permit-port-forwarding") == 0 || - strcmp(name, "permit-pty") == 0 || - strcmp(name, "permit-user-rc") == 0)) + (strcmp(name, "permit-X11-forwarding") == 0 || + strcmp(name, "permit-agent-forwarding") == 0 || + strcmp(name, "permit-port-forwarding") == 0 || + strcmp(name, "permit-pty") == 0 || + strcmp(name, "permit-user-rc") == 0)) printf("\n"); else if (in_critical && - (strcmp(name, "force-command") == 0 || - strcmp(name, "source-address") == 0)) { + (strcmp(name, "force-command") == 0 || + strcmp(name, "source-address") == 0)) { if ((r = sshbuf_get_cstring(option, &arg, NULL)) != 0) fatal("%s: buffer error: %s", - __func__, ssh_err(r)); + __func__, ssh_err(r)); printf(" %s\n", arg); free(arg); - } - else { + } else { printf(" UNKNOWN OPTION (len %zu)\n", - sshbuf_len(option)); + sshbuf_len(option)); sshbuf_reset(option); } free(name); @@ -2066,16 +2041,16 @@ print_cert(struct sshkey *key) key_fp = sshkey_fingerprint(key, fingerprint_hash, SSH_FP_DEFAULT); ca_fp = sshkey_fingerprint(key->cert->signature_key, - fingerprint_hash, SSH_FP_DEFAULT); + fingerprint_hash, SSH_FP_DEFAULT); if (key_fp == NULL || ca_fp == NULL) fatal("%s: sshkey_fingerprint fail", __func__); sshkey_format_cert_validity(key->cert, valid, sizeof(valid)); printf(" Type: %s %s certificate\n", sshkey_ssh_name(key), - sshkey_cert_type(key)); + sshkey_cert_type(key)); printf(" Public key: %s %s\n", sshkey_type(key), key_fp); printf(" Signing CA: %s %s\n", - sshkey_type(key->cert->signature_key), ca_fp); + sshkey_type(key->cert->signature_key), ca_fp); printf(" Key ID: \"%s\"\n", key->cert->key_id); printf(" Serial: %llu\n", (unsigned long long)key->cert->serial); printf(" Valid: %s\n", valid); @@ -2085,7 +2060,7 @@ print_cert(struct sshkey *key) else { for (i = 0; i < key->cert->nprincipals; i++) printf("\n %s", - key->cert->principals[i]); + key->cert->principals[i]); printf("\n"); } printf(" Critical Options: "); @@ -2125,8 +2100,7 @@ do_show_cert(struct passwd *pw) f = stdin; path = "(stdin)"; is_stdin = 1; - } - else if ((f = fopen(identity_file, "r")) == NULL) + } else if ((f = fopen(identity_file, "r")) == NULL) fatal("fopen %s: %s", identity_file, strerror(errno)); while (read_keyfile_line(f, path, line, sizeof(line), &lnum) == 0) { @@ -2140,7 +2114,7 @@ do_show_cert(struct passwd *pw) fatal("sshkey_new"); if ((r = sshkey_read(key, &cp)) != 0) { error("%s:%lu: invalid key: %s", path, - lnum, ssh_err(r)); + lnum, ssh_err(r)); continue; } if (!sshkey_is_cert(key)) { @@ -2174,14 +2148,14 @@ load_krl(const char *path, struct ssh_krl **krlp) close(fd); /* XXX check sigs */ if ((r = ssh_krl_from_blob(krlbuf, krlp, NULL, 0)) != 0 || - *krlp == NULL) + *krlp == NULL) fatal("Invalid KRL file: %s", ssh_err(r)); sshbuf_free(krlbuf); } static void update_krl_from_file(struct passwd *pw, const char *file, int wild_ca, - const struct sshkey *ca, struct ssh_krl *krl) + const struct sshkey *ca, struct ssh_krl *krl) { struct sshkey *key = NULL; u_long lnum = 0; @@ -2195,14 +2169,13 @@ update_krl_from_file(struct passwd *pw, const char *file, int wild_ca, krl_spec = stdin; free(path); path = xstrdup("(standard input)"); - } - else if ((krl_spec = fopen(path, "r")) == NULL) + } else if ((krl_spec = fopen(path, "r")) == NULL) fatal("fopen %s: %s", path, strerror(errno)); if (!quiet) printf("Revoking from %s\n", path); while (read_keyfile_line(krl_spec, path, line, sizeof(line), - &lnum) == 0) { + &lnum) == 0) { was_explicit_key = was_sha1 = 0; cp = line + strspn(line, " \t"); /* Trim trailing space, comments and strip \n */ @@ -2215,8 +2188,7 @@ update_krl_from_file(struct passwd *pw, const char *file, int wild_ca, /* Remember the start of a span of whitespace */ if (r == -1) r = i; - } - else + } else r = -1; } if (r != -1) @@ -2226,7 +2198,7 @@ update_krl_from_file(struct passwd *pw, const char *file, int wild_ca, if (strncasecmp(cp, "serial:", 7) == 0) { if (ca == NULL && !wild_ca) { fatal("revoking certificates by serial number " - "requires specification of a CA key"); + "requires specification of a CA key"); } cp += 7; cp = cp + strspn(cp, " \t"); @@ -2234,10 +2206,10 @@ update_krl_from_file(struct passwd *pw, const char *file, int wild_ca, serial = strtoull(cp, &ep, 0); if (*cp == '\0' || (*ep != '\0' && *ep != '-')) fatal("%s:%lu: invalid serial \"%s\"", - path, lnum, cp); + path, lnum, cp); if (errno == ERANGE && serial == ULLONG_MAX) fatal("%s:%lu: serial out of range", - path, lnum); + path, lnum); serial2 = serial; if (*ep == '-') { cp = ep + 1; @@ -2245,44 +2217,40 @@ update_krl_from_file(struct passwd *pw, const char *file, int wild_ca, serial2 = strtoull(cp, &ep, 0); if (*cp == '\0' || *ep != '\0') fatal("%s:%lu: invalid serial \"%s\"", - path, lnum, cp); + path, lnum, cp); if (errno == ERANGE && serial2 == ULLONG_MAX) fatal("%s:%lu: serial out of range", - path, lnum); + path, lnum); if (serial2 <= serial) fatal("%s:%lu: invalid serial range " - "%llu:%llu", path, lnum, - (unsigned long long)serial, - (unsigned long long)serial2); + "%llu:%llu", path, lnum, + (unsigned long long)serial, + (unsigned long long)serial2); } if (ssh_krl_revoke_cert_by_serial_range(krl, - ca, serial, serial2) != 0) { + ca, serial, serial2) != 0) { fatal("%s: revoke serial failed", - __func__); + __func__); } - } - else if (strncasecmp(cp, "id:", 3) == 0) { + } else if (strncasecmp(cp, "id:", 3) == 0) { if (ca == NULL && !wild_ca) { fatal("revoking certificates by key ID " - "requires specification of a CA key"); + "requires specification of a CA key"); } cp += 3; cp = cp + strspn(cp, " \t"); if (ssh_krl_revoke_cert_by_key_id(krl, ca, cp) != 0) fatal("%s: revoke key ID failed", __func__); - } - else { + } else { if (strncasecmp(cp, "key:", 4) == 0) { cp += 4; cp = cp + strspn(cp, " \t"); was_explicit_key = 1; - } - else if (strncasecmp(cp, "sha1:", 5) == 0) { + } else if (strncasecmp(cp, "sha1:", 5) == 0) { cp += 5; cp = cp + strspn(cp, " \t"); was_sha1 = 1; - } - else { + } else { /* * Just try to process the line as a key. * Parsing will fail if it isn't. @@ -2292,7 +2260,7 @@ update_krl_from_file(struct passwd *pw, const char *file, int wild_ca, fatal("sshkey_new"); if ((r = sshkey_read(key, &cp)) != 0) fatal("%s:%lu: invalid key: %s", - path, lnum, ssh_err(r)); + path, lnum, ssh_err(r)); if (was_explicit_key) r = ssh_krl_revoke_key_explicit(krl, key); else if (was_sha1) @@ -2301,7 +2269,7 @@ update_krl_from_file(struct passwd *pw, const char *file, int wild_ca, r = ssh_krl_revoke_key(krl, key); if (r != 0) fatal("%s: revoke key failed: %s", - __func__, ssh_err(r)); + __func__, ssh_err(r)); sshkey_free(key); } } @@ -2325,7 +2293,7 @@ do_gen_krl(struct passwd *pw, int updating, int argc, char **argv) if (stat(identity_file, &sb) == -1) { if (errno != ENOENT) fatal("Cannot access KRL \"%s\": %s", - identity_file, strerror(errno)); + identity_file, strerror(errno)); if (updating) fatal("KRL \"%s\" does not exist", identity_file); } @@ -2336,7 +2304,7 @@ do_gen_krl(struct passwd *pw, int updating, int argc, char **argv) tmp = tilde_expand_filename(ca_key_path, pw->pw_uid); if ((r = sshkey_load_public(tmp, &ca, NULL)) != 0) fatal("Cannot load CA public key %s: %s", - tmp, ssh_err(r)); + tmp, ssh_err(r)); free(tmp); } } @@ -2358,10 +2326,10 @@ do_gen_krl(struct passwd *pw, int updating, int argc, char **argv) fatal("sshbuf_new failed"); if (ssh_krl_to_blob(krl, kbuf, NULL, 0) != 0) fatal("Couldn't generate KRL"); - if ((fd = open(identity_file, O_WRONLY | O_CREAT | O_TRUNC, 0644)) == -1) + if ((fd = open(identity_file, O_WRONLY|O_CREAT|O_TRUNC, 0644)) == -1) fatal("open %s: %s", identity_file, strerror(errno)); if (atomicio(vwrite, fd, (void *)sshbuf_ptr(kbuf), sshbuf_len(kbuf)) != - sshbuf_len(kbuf)) + sshbuf_len(kbuf)) fatal("write %s: %s", identity_file, strerror(errno)); close(fd); sshbuf_free(kbuf); @@ -2383,11 +2351,11 @@ do_check_krl(struct passwd *pw, int argc, char **argv) for (i = 0; i < argc; i++) { if ((r = sshkey_load_public(argv[i], &k, &comment)) != 0) fatal("Cannot load public key %s: %s", - argv[i], ssh_err(r)); + argv[i], ssh_err(r)); r = ssh_krl_check_key(krl, k); printf("%s%s%s%s: %s\n", argv[i], - *comment ? " (" : "", comment, *comment ? ")" : "", - r == 0 ? "ok" : "REVOKED"); + *comment ? " (" : "", comment, *comment ? ")" : "", + r == 0 ? "ok" : "REVOKED"); if (r != 0) ret = 1; sshkey_free(k); @@ -2401,37 +2369,37 @@ static void usage(void) { fprintf(stderr, - "usage: ssh-keygen [-q] [-b bits] [-t dsa | ecdsa | ed25519 | rsa]\n" - " [-N new_passphrase] [-C comment] [-f output_keyfile]\n" - " ssh-keygen -p [-P old_passphrase] [-N new_passphrase] [-f keyfile]\n" - " ssh-keygen -i [-m key_format] [-f input_keyfile]\n" - " ssh-keygen -e [-m key_format] [-f input_keyfile]\n" - " ssh-keygen -y [-f input_keyfile]\n" - " ssh-keygen -c [-P passphrase] [-C comment] [-f keyfile]\n" - " ssh-keygen -l [-v] [-E fingerprint_hash] [-f input_keyfile]\n" - " ssh-keygen -B [-f input_keyfile]\n"); + "usage: ssh-keygen [-q] [-b bits] [-t dsa | ecdsa | ed25519 | rsa]\n" + " [-N new_passphrase] [-C comment] [-f output_keyfile]\n" + " ssh-keygen -p [-P old_passphrase] [-N new_passphrase] [-f keyfile]\n" + " ssh-keygen -i [-m key_format] [-f input_keyfile]\n" + " ssh-keygen -e [-m key_format] [-f input_keyfile]\n" + " ssh-keygen -y [-f input_keyfile]\n" + " ssh-keygen -c [-P passphrase] [-C comment] [-f keyfile]\n" + " ssh-keygen -l [-v] [-E fingerprint_hash] [-f input_keyfile]\n" + " ssh-keygen -B [-f input_keyfile]\n"); #ifdef ENABLE_PKCS11 fprintf(stderr, - " ssh-keygen -D pkcs11\n"); + " ssh-keygen -D pkcs11\n"); #endif fprintf(stderr, - " ssh-keygen -F hostname [-f known_hosts_file] [-l]\n" - " ssh-keygen -H [-f known_hosts_file]\n" - " ssh-keygen -R hostname [-f known_hosts_file]\n" - " ssh-keygen -r hostname [-f input_keyfile] [-g]\n" + " ssh-keygen -F hostname [-f known_hosts_file] [-l]\n" + " ssh-keygen -H [-f known_hosts_file]\n" + " ssh-keygen -R hostname [-f known_hosts_file]\n" + " ssh-keygen -r hostname [-f input_keyfile] [-g]\n" #ifdef WITH_OPENSSL - " ssh-keygen -G output_file [-v] [-b bits] [-M memory] [-S start_point]\n" - " ssh-keygen -T output_file -f input_file [-v] [-a rounds] [-J num_lines]\n" - " [-j start_line] [-K checkpt] [-W generator]\n" + " ssh-keygen -G output_file [-v] [-b bits] [-M memory] [-S start_point]\n" + " ssh-keygen -T output_file -f input_file [-v] [-a rounds] [-J num_lines]\n" + " [-j start_line] [-K checkpt] [-W generator]\n" #endif - " ssh-keygen -s ca_key -I certificate_identity [-h] [-U]\n" - " [-D pkcs11_provider] [-n principals] [-O option]\n" - " [-V validity_interval] [-z serial_number] file ...\n" - " ssh-keygen -L [-f input_keyfile]\n" - " ssh-keygen -A\n" - " ssh-keygen -k -f krl_file [-u] [-s ca_public] [-z version_number]\n" - " file ...\n" - " ssh-keygen -Q -f krl_file file ...\n"); + " ssh-keygen -s ca_key -I certificate_identity [-h] [-U]\n" + " [-D pkcs11_provider] [-n principals] [-O option]\n" + " [-V validity_interval] [-z serial_number] file ...\n" + " ssh-keygen -L [-f input_keyfile]\n" + " ssh-keygen -A\n" + " ssh-keygen -k -f krl_file [-u] [-s ca_public] [-z version_number]\n" + " file ...\n" + " ssh-keygen -Q -f krl_file file ...\n"); exit(1); } @@ -2486,8 +2454,8 @@ main(int argc, char **argv) /* Remaining characters: Ydw */ while ((opt = getopt(argc, argv, "ABHLQUXceghiklopquvxy" - "C:D:E:F:G:I:J:K:M:N:O:P:R:S:T:V:W:Z:" - "a:b:f:g:j:m:n:r:s:t:z:")) != -1) { + "C:D:E:F:G:I:J:K:M:N:O:P:R:S:T:V:W:Z:" + "a:b:f:g:j:m:n:r:s:t:z:")) != -1) { switch (opt) { case 'A': gen_all_hostkeys = 1; @@ -2528,7 +2496,7 @@ main(int argc, char **argv) break; case 'm': if (strcasecmp(optarg, "RFC4716") == 0 || - strcasecmp(optarg, "ssh2") == 0) { + strcasecmp(optarg, "ssh2") == 0) { convert_format = FMT_RFC4716; break; } @@ -2555,7 +2523,7 @@ main(int argc, char **argv) break; case 'f': if (strlcpy(identity_file, optarg, - sizeof(identity_file)) >= sizeof(identity_file)) + sizeof(identity_file)) >= sizeof(identity_file)) fatal("Identity filename too long"); have_identity = 1; break; @@ -2623,7 +2591,7 @@ main(int argc, char **argv) log_level = SYSLOG_LEVEL_DEBUG1; else { if (log_level >= SYSLOG_LEVEL_DEBUG1 && - log_level < SYSLOG_LEVEL_DEBUG3) + log_level < SYSLOG_LEVEL_DEBUG3) log_level++; } break; @@ -2643,15 +2611,15 @@ main(int argc, char **argv) errno = 0; cert_serial = strtoull(optarg, &ep, 10); if (*optarg < '0' || *optarg > '9' || *ep != '\0' || - (errno == ERANGE && cert_serial == ULLONG_MAX)) + (errno == ERANGE && cert_serial == ULLONG_MAX)) fatal("Invalid serial number \"%s\"", optarg); break; #ifdef WITH_OPENSSL - /* Moduli generation/screening */ + /* Moduli generation/screening */ case 'G': do_gen_candidates = 1; if (strlcpy(out_file, optarg, sizeof(out_file)) >= - sizeof(out_file)) + sizeof(out_file)) fatal("Output filename too long"); break; case 'J': @@ -2667,7 +2635,7 @@ main(int argc, char **argv) break; case 'M': memory = (u_int32_t)strtonum(optarg, 1, UINT_MAX, - &errstr); + &errstr); if (errstr) fatal("Memory limit is %s: %s", errstr, optarg); break; @@ -2679,15 +2647,15 @@ main(int argc, char **argv) case 'T': do_screen_candidates = 1; if (strlcpy(out_file, optarg, sizeof(out_file)) >= - sizeof(out_file)) + sizeof(out_file)) fatal("Output filename too long"); break; case 'W': generator_wanted = (u_int32_t)strtonum(optarg, 1, - UINT_MAX, &errstr); + UINT_MAX, &errstr); if (errstr != NULL) fatal("Desired generator invalid: %s (%s)", - optarg, errstr); + optarg, errstr); break; #endif /* WITH_OPENSSL */ case '?': @@ -2707,8 +2675,7 @@ main(int argc, char **argv) error("Too few arguments."); usage(); } - } - else if (argc > 0 && !gen_krl && !check_krl) { + } else if (argc > 0 && !gen_krl && !check_krl) { error("Too many arguments."); usage(); } @@ -2758,21 +2725,20 @@ main(int argc, char **argv) if (have_identity) { n = do_print_resource_record(pw, - identity_file, rr_hostname); + identity_file, rr_hostname); if (n == 0) fatal("%s: %s", identity_file, strerror(errno)); exit(0); - } - else { + } else { n += do_print_resource_record(pw, - _PATH_HOST_RSA_KEY_FILE, rr_hostname); + _PATH_HOST_RSA_KEY_FILE, rr_hostname); n += do_print_resource_record(pw, - _PATH_HOST_DSA_KEY_FILE, rr_hostname); + _PATH_HOST_DSA_KEY_FILE, rr_hostname); n += do_print_resource_record(pw, - _PATH_HOST_ECDSA_KEY_FILE, rr_hostname); + _PATH_HOST_ECDSA_KEY_FILE, rr_hostname); n += do_print_resource_record(pw, - _PATH_HOST_ED25519_KEY_FILE, rr_hostname); + _PATH_HOST_ED25519_KEY_FILE, rr_hostname); if (n == 0) fatal("no keys found."); exit(0); @@ -2785,7 +2751,7 @@ main(int argc, char **argv) if (out == NULL) { error("Couldn't open modulus candidate file \"%s\": %s", - out_file, strerror(errno)); + out_file, strerror(errno)); return (1); } if (bits == 0) @@ -2803,20 +2769,19 @@ main(int argc, char **argv) if (have_identity && strcmp(identity_file, "-") != 0) { if ((in = fopen(identity_file, "r")) == NULL) { fatal("Couldn't open modulus candidate " - "file \"%s\": %s", identity_file, - strerror(errno)); + "file \"%s\": %s", identity_file, + strerror(errno)); } - } - else + } else in = stdin; if (out == NULL) { fatal("Couldn't open moduli file \"%s\": %s", - out_file, strerror(errno)); + out_file, strerror(errno)); } if (prime_test(in, out, rounds == 0 ? 100 : rounds, - generator_wanted, checkpoint, - start_lineno, lines_to_process) != 0) + generator_wanted, checkpoint, + start_lineno, lines_to_process) != 0) fatal("modulus screening failed"); return (0); } @@ -2835,7 +2800,7 @@ main(int argc, char **argv) if (!quiet) printf("Generating public/private %s key pair.\n", - key_type_name); + key_type_name); if ((r = sshkey_generate(type, bits, &private)) != 0) fatal("sshkey_generate failed"); if ((r = sshkey_from_private(private, &public)) != 0) @@ -2846,18 +2811,16 @@ main(int argc, char **argv) /* Create ~/.ssh directory if it doesn't already exist. */ snprintf(dotsshdir, sizeof dotsshdir, "%s/%s", - pw->pw_dir, _PATH_SSH_USER_DIR); + pw->pw_dir, _PATH_SSH_USER_DIR); if (strstr(identity_file, dotsshdir) != NULL) { if (stat(dotsshdir, &st) < 0) { if (errno != ENOENT) { error("Could not stat %s: %s", dotsshdir, - strerror(errno)); - } - else if (mkdir(dotsshdir, 0700) < 0) { + strerror(errno)); + } else if (mkdir(dotsshdir, 0700) < 0) { error("Could not create directory '%s': %s", - dotsshdir, strerror(errno)); - } - else if (!quiet) + dotsshdir, strerror(errno)); + } else if (!quiet) printf("Created directory '%s'.\n", dotsshdir); } } @@ -2878,12 +2841,12 @@ main(int argc, char **argv) else if (identity_new_passphrase) passphrase1 = xstrdup(identity_new_passphrase); else { - passphrase_again: +passphrase_again: passphrase1 = read_passphrase("Enter passphrase (empty for no " - "passphrase): ", RP_ALLOW_STDIN); + "passphrase): ", RP_ALLOW_STDIN); passphrase2 = read_passphrase("Enter same passphrase again: ", - RP_ALLOW_STDIN); + RP_ALLOW_STDIN); if (strcmp(passphrase1, passphrase2) != 0) { /* * The passphrases do not match. Clear them and @@ -2903,17 +2866,16 @@ main(int argc, char **argv) if (identity_comment) { strlcpy(comment, identity_comment, sizeof(comment)); - } - else { + } else { /* Create default comment field for the passphrase. */ snprintf(comment, sizeof comment, "%s@%s", pw->pw_name, hostname); } /* Save the key with the given passphrase and comment. */ if ((r = sshkey_save_private(private, identity_file, passphrase1, - comment, use_new_format, new_format_cipher, rounds)) != 0) { + comment, use_new_format, new_format_cipher, rounds)) != 0) { error("Saving key \"%s\" failed: %s", - identity_file, ssh_err(r)); + identity_file, ssh_err(r)); explicit_bzero(passphrase1, strlen(passphrase1)); free(passphrase1); exit(1); @@ -2929,9 +2891,9 @@ main(int argc, char **argv) printf("Your identification has been saved in %s.\n", identity_file); strlcat(identity_file, ".pub", sizeof(identity_file)); - if ((fd = open(identity_file, O_WRONLY | O_CREAT | O_TRUNC, 0644)) == -1) + if ((fd = open(identity_file, O_WRONLY|O_CREAT|O_TRUNC, 0644)) == -1) fatal("Unable to save public key to %s: %s", - identity_file, strerror(errno)); + identity_file, strerror(errno)); #ifdef WINDOWS /* Windows POSIX adpater does not support fdopen() on open(file)*/ close(fd); @@ -2948,13 +2910,13 @@ main(int argc, char **argv) if (!quiet) { fp = sshkey_fingerprint(public, fingerprint_hash, - SSH_FP_DEFAULT); + SSH_FP_DEFAULT); ra = sshkey_fingerprint(public, fingerprint_hash, - SSH_FP_RANDOMART); + SSH_FP_RANDOMART); if (fp == NULL || ra == NULL) fatal("sshkey_fingerprint failed"); printf("Your public key has been saved in %s.\n", - identity_file); + identity_file); printf("The key fingerprint is:\n"); printf("%s %s\n", fp, comment); printf("The key's randomart image is:\n");