diff options
Diffstat (limited to 'ssh-keygen.c')
-rw-r--r-- | ssh-keygen.c | 220 |
1 files changed, 114 insertions, 106 deletions
diff --git a/ssh-keygen.c b/ssh-keygen.c index 46b3af5a8..3898b281e 100644 --- a/ssh-keygen.c +++ b/ssh-keygen.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssh-keygen.c,v 1.322 2018/09/14 04:17:44 djm Exp $ */ | 1 | /* $OpenBSD: ssh-keygen.c,v 1.329 2019/03/25 16:19:44 dtucker Exp $ */ |
2 | /* | 2 | /* |
3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
4 | * Copyright (c) 1994 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 4 | * Copyright (c) 1994 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
@@ -67,79 +67,52 @@ | |||
67 | # define DEFAULT_KEY_TYPE_NAME "ed25519" | 67 | # define DEFAULT_KEY_TYPE_NAME "ed25519" |
68 | #endif | 68 | #endif |
69 | 69 | ||
70 | /* Number of bits in the RSA/DSA key. This value can be set on the command line. */ | ||
71 | #define DEFAULT_BITS 2048 | ||
72 | #define DEFAULT_BITS_DSA 1024 | ||
73 | #define DEFAULT_BITS_ECDSA 256 | ||
74 | u_int32_t bits = 0; | ||
75 | |||
76 | /* | 70 | /* |
77 | * Flag indicating that we just want to change the passphrase. This can be | 71 | * Default number of bits in the RSA, DSA and ECDSA keys. These value can be |
78 | * set on the command line. | 72 | * overridden on the command line. |
79 | */ | 73 | * |
80 | int change_passphrase = 0; | 74 | * These values, with the exception of DSA, provide security equivalent to at |
81 | 75 | * least 128 bits of security according to NIST Special Publication 800-57: | |
82 | /* | 76 | * Recommendation for Key Management Part 1 rev 4 section 5.6.1. |
83 | * Flag indicating that we just want to change the comment. This can be set | 77 | * For DSA it (and FIPS-186-4 section 4.2) specifies that the only size for |
84 | * on the command line. | 78 | * which a 160bit hash is acceptable is 1kbit, and since ssh-dss specifies only |
79 | * SHA1 we limit the DSA key size 1k bits. | ||
85 | */ | 80 | */ |
86 | int change_comment = 0; | 81 | #define DEFAULT_BITS 3072 |
87 | 82 | #define DEFAULT_BITS_DSA 1024 | |
88 | int quiet = 0; | 83 | #define DEFAULT_BITS_ECDSA 256 |
89 | |||
90 | int log_level = SYSLOG_LEVEL_INFO; | ||
91 | |||
92 | /* Flag indicating that we want to hash a known_hosts file */ | ||
93 | int hash_hosts = 0; | ||
94 | /* Flag indicating that we want lookup a host in known_hosts file */ | ||
95 | int find_host = 0; | ||
96 | /* Flag indicating that we want to delete a host from a known_hosts file */ | ||
97 | int delete_host = 0; | ||
98 | 84 | ||
99 | /* Flag indicating that we want to show the contents of a certificate */ | 85 | static int quiet = 0; |
100 | int show_cert = 0; | ||
101 | 86 | ||
102 | /* Flag indicating that we just want to see the key fingerprint */ | 87 | /* Flag indicating that we just want to see the key fingerprint */ |
103 | int print_fingerprint = 0; | 88 | static int print_fingerprint = 0; |
104 | int print_bubblebabble = 0; | 89 | static int print_bubblebabble = 0; |
105 | 90 | ||
106 | /* Hash algorithm to use for fingerprints. */ | 91 | /* Hash algorithm to use for fingerprints. */ |
107 | int fingerprint_hash = SSH_FP_HASH_DEFAULT; | 92 | static int fingerprint_hash = SSH_FP_HASH_DEFAULT; |
108 | 93 | ||
109 | /* The identity file name, given on the command line or entered by the user. */ | 94 | /* The identity file name, given on the command line or entered by the user. */ |
110 | char identity_file[1024]; | 95 | static char identity_file[1024]; |
111 | int have_identity = 0; | 96 | static int have_identity = 0; |
112 | 97 | ||
113 | /* This is set to the passphrase if given on the command line. */ | 98 | /* This is set to the passphrase if given on the command line. */ |
114 | char *identity_passphrase = NULL; | 99 | static char *identity_passphrase = NULL; |
115 | 100 | ||
116 | /* This is set to the new passphrase if given on the command line. */ | 101 | /* This is set to the new passphrase if given on the command line. */ |
117 | char *identity_new_passphrase = NULL; | 102 | static char *identity_new_passphrase = NULL; |
118 | |||
119 | /* This is set to the new comment if given on the command line. */ | ||
120 | char *identity_comment = NULL; | ||
121 | |||
122 | /* Path to CA key when certifying keys. */ | ||
123 | char *ca_key_path = NULL; | ||
124 | |||
125 | /* Prefer to use agent keys for CA signing */ | ||
126 | int prefer_agent = 0; | ||
127 | |||
128 | /* Certificate serial number */ | ||
129 | unsigned long long cert_serial = 0; | ||
130 | 103 | ||
131 | /* Key type when certifying */ | 104 | /* Key type when certifying */ |
132 | u_int cert_key_type = SSH2_CERT_TYPE_USER; | 105 | static u_int cert_key_type = SSH2_CERT_TYPE_USER; |
133 | 106 | ||
134 | /* "key ID" of signed key */ | 107 | /* "key ID" of signed key */ |
135 | char *cert_key_id = NULL; | 108 | static char *cert_key_id = NULL; |
136 | 109 | ||
137 | /* Comma-separated list of principal names for certifying keys */ | 110 | /* Comma-separated list of principal names for certifying keys */ |
138 | char *cert_principals = NULL; | 111 | static char *cert_principals = NULL; |
139 | 112 | ||
140 | /* Validity period for certificates */ | 113 | /* Validity period for certificates */ |
141 | u_int64_t cert_valid_from = 0; | 114 | static u_int64_t cert_valid_from = 0; |
142 | u_int64_t cert_valid_to = ~0ULL; | 115 | static u_int64_t cert_valid_to = ~0ULL; |
143 | 116 | ||
144 | /* Certificate options */ | 117 | /* Certificate options */ |
145 | #define CERTOPT_X_FWD (1) | 118 | #define CERTOPT_X_FWD (1) |
@@ -149,9 +122,9 @@ u_int64_t cert_valid_to = ~0ULL; | |||
149 | #define CERTOPT_USER_RC (1<<4) | 122 | #define CERTOPT_USER_RC (1<<4) |
150 | #define CERTOPT_DEFAULT (CERTOPT_X_FWD|CERTOPT_AGENT_FWD| \ | 123 | #define CERTOPT_DEFAULT (CERTOPT_X_FWD|CERTOPT_AGENT_FWD| \ |
151 | CERTOPT_PORT_FWD|CERTOPT_PTY|CERTOPT_USER_RC) | 124 | CERTOPT_PORT_FWD|CERTOPT_PTY|CERTOPT_USER_RC) |
152 | u_int32_t certflags_flags = CERTOPT_DEFAULT; | 125 | static u_int32_t certflags_flags = CERTOPT_DEFAULT; |
153 | char *certflags_command = NULL; | 126 | static char *certflags_command = NULL; |
154 | char *certflags_src_addr = NULL; | 127 | static char *certflags_src_addr = NULL; |
155 | 128 | ||
156 | /* Arbitrary extensions specified by user */ | 129 | /* Arbitrary extensions specified by user */ |
157 | struct cert_userext { | 130 | struct cert_userext { |
@@ -159,41 +132,37 @@ struct cert_userext { | |||
159 | char *val; | 132 | char *val; |
160 | int crit; | 133 | int crit; |
161 | }; | 134 | }; |
162 | struct cert_userext *cert_userext; | 135 | static struct cert_userext *cert_userext; |
163 | size_t ncert_userext; | 136 | static size_t ncert_userext; |
164 | 137 | ||
165 | /* Conversion to/from various formats */ | 138 | /* Conversion to/from various formats */ |
166 | int convert_to = 0; | ||
167 | int convert_from = 0; | ||
168 | enum { | 139 | enum { |
169 | FMT_RFC4716, | 140 | FMT_RFC4716, |
170 | FMT_PKCS8, | 141 | FMT_PKCS8, |
171 | FMT_PEM | 142 | FMT_PEM |
172 | } convert_format = FMT_RFC4716; | 143 | } convert_format = FMT_RFC4716; |
173 | int print_public = 0; | ||
174 | int print_generic = 0; | ||
175 | 144 | ||
176 | char *key_type_name = NULL; | 145 | static char *key_type_name = NULL; |
177 | 146 | ||
178 | /* Load key from this PKCS#11 provider */ | 147 | /* Load key from this PKCS#11 provider */ |
179 | char *pkcs11provider = NULL; | 148 | static char *pkcs11provider = NULL; |
180 | 149 | ||
181 | /* Use new OpenSSH private key format when writing SSH2 keys instead of PEM */ | 150 | /* Use new OpenSSH private key format when writing SSH2 keys instead of PEM */ |
182 | int use_new_format = 1; | 151 | static int use_new_format = 1; |
183 | 152 | ||
184 | /* Cipher for new-format private keys */ | 153 | /* Cipher for new-format private keys */ |
185 | char *new_format_cipher = NULL; | 154 | static char *new_format_cipher = NULL; |
186 | 155 | ||
187 | /* | 156 | /* |
188 | * Number of KDF rounds to derive new format keys / | 157 | * Number of KDF rounds to derive new format keys / |
189 | * number of primality trials when screening moduli. | 158 | * number of primality trials when screening moduli. |
190 | */ | 159 | */ |
191 | int rounds = 0; | 160 | static int rounds = 0; |
192 | 161 | ||
193 | /* argv0 */ | 162 | /* argv0 */ |
194 | extern char *__progname; | 163 | extern char *__progname; |
195 | 164 | ||
196 | char hostname[NI_MAXHOST]; | 165 | static char hostname[NI_MAXHOST]; |
197 | 166 | ||
198 | #ifdef WITH_OPENSSL | 167 | #ifdef WITH_OPENSSL |
199 | /* moduli.c */ | 168 | /* moduli.c */ |
@@ -243,7 +212,11 @@ type_bits_valid(int type, const char *name, u_int32_t *bitsp) | |||
243 | case KEY_ECDSA: | 212 | case KEY_ECDSA: |
244 | if (sshkey_ecdsa_bits_to_nid(*bitsp) == -1) | 213 | if (sshkey_ecdsa_bits_to_nid(*bitsp) == -1) |
245 | fatal("Invalid ECDSA key length: valid lengths are " | 214 | fatal("Invalid ECDSA key length: valid lengths are " |
215 | #ifdef OPENSSL_HAS_NISTP521 | ||
246 | "256, 384 or 521 bits"); | 216 | "256, 384 or 521 bits"); |
217 | #else | ||
218 | "256 or 384 bits"); | ||
219 | #endif | ||
247 | } | 220 | } |
248 | #endif | 221 | #endif |
249 | } | 222 | } |
@@ -806,7 +779,7 @@ do_download(struct passwd *pw) | |||
806 | fptype = print_bubblebabble ? SSH_DIGEST_SHA1 : fingerprint_hash; | 779 | fptype = print_bubblebabble ? SSH_DIGEST_SHA1 : fingerprint_hash; |
807 | rep = print_bubblebabble ? SSH_FP_BUBBLEBABBLE : SSH_FP_DEFAULT; | 780 | rep = print_bubblebabble ? SSH_FP_BUBBLEBABBLE : SSH_FP_DEFAULT; |
808 | 781 | ||
809 | pkcs11_init(0); | 782 | pkcs11_init(1); |
810 | nkeys = pkcs11_add_provider(pkcs11provider, NULL, &keys); | 783 | nkeys = pkcs11_add_provider(pkcs11provider, NULL, &keys); |
811 | if (nkeys <= 0) | 784 | if (nkeys <= 0) |
812 | fatal("cannot read public key from pkcs11"); | 785 | fatal("cannot read public key from pkcs11"); |
@@ -819,7 +792,7 @@ do_download(struct passwd *pw) | |||
819 | fatal("%s: sshkey_fingerprint fail", __func__); | 792 | fatal("%s: sshkey_fingerprint fail", __func__); |
820 | printf("%u %s %s (PKCS11 key)\n", sshkey_size(keys[i]), | 793 | printf("%u %s %s (PKCS11 key)\n", sshkey_size(keys[i]), |
821 | fp, sshkey_type(keys[i])); | 794 | fp, sshkey_type(keys[i])); |
822 | if (log_level >= SYSLOG_LEVEL_VERBOSE) | 795 | if (log_level_get() >= SYSLOG_LEVEL_VERBOSE) |
823 | printf("%s\n", ra); | 796 | printf("%s\n", ra); |
824 | free(ra); | 797 | free(ra); |
825 | free(fp); | 798 | free(fp); |
@@ -867,7 +840,7 @@ fingerprint_one_key(const struct sshkey *public, const char *comment) | |||
867 | fatal("%s: sshkey_fingerprint failed", __func__); | 840 | fatal("%s: sshkey_fingerprint failed", __func__); |
868 | mprintf("%u %s %s (%s)\n", sshkey_size(public), fp, | 841 | mprintf("%u %s %s (%s)\n", sshkey_size(public), fp, |
869 | comment ? comment : "no comment", sshkey_type(public)); | 842 | comment ? comment : "no comment", sshkey_type(public)); |
870 | if (log_level >= SYSLOG_LEVEL_VERBOSE) | 843 | if (log_level_get() >= SYSLOG_LEVEL_VERBOSE) |
871 | printf("%s\n", ra); | 844 | printf("%s\n", ra); |
872 | free(ra); | 845 | free(ra); |
873 | free(fp); | 846 | free(fp); |
@@ -1015,6 +988,7 @@ do_gen_all_hostkeys(struct passwd *pw) | |||
1015 | { NULL, NULL, NULL } | 988 | { NULL, NULL, NULL } |
1016 | }; | 989 | }; |
1017 | 990 | ||
991 | u_int bits = 0; | ||
1018 | int first = 0; | 992 | int first = 0; |
1019 | struct stat st; | 993 | struct stat st; |
1020 | struct sshkey *private, *public; | 994 | struct sshkey *private, *public; |
@@ -1138,6 +1112,9 @@ struct known_hosts_ctx { | |||
1138 | int has_unhashed; /* When hashing, original had unhashed hosts */ | 1112 | int has_unhashed; /* When hashing, original had unhashed hosts */ |
1139 | int found_key; /* For find/delete, host was found */ | 1113 | int found_key; /* For find/delete, host was found */ |
1140 | int invalid; /* File contained invalid items; don't delete */ | 1114 | int invalid; /* File contained invalid items; don't delete */ |
1115 | int hash_hosts; /* Hash hostnames as we go */ | ||
1116 | int find_host; /* Search for specific hostname */ | ||
1117 | int delete_host; /* Delete host from known_hosts */ | ||
1141 | }; | 1118 | }; |
1142 | 1119 | ||
1143 | static int | 1120 | static int |
@@ -1157,7 +1134,7 @@ known_hosts_hash(struct hostkey_foreach_line *l, void *_ctx) | |||
1157 | */ | 1134 | */ |
1158 | if (was_hashed || has_wild || l->marker != MRK_NONE) { | 1135 | if (was_hashed || has_wild || l->marker != MRK_NONE) { |
1159 | fprintf(ctx->out, "%s\n", l->line); | 1136 | fprintf(ctx->out, "%s\n", l->line); |
1160 | if (has_wild && !find_host) { | 1137 | if (has_wild && !ctx->find_host) { |
1161 | logit("%s:%lu: ignoring host name " | 1138 | logit("%s:%lu: ignoring host name " |
1162 | "with wildcard: %.64s", l->path, | 1139 | "with wildcard: %.64s", l->path, |
1163 | l->linenum, l->hosts); | 1140 | l->linenum, l->hosts); |
@@ -1203,7 +1180,7 @@ known_hosts_find_delete(struct hostkey_foreach_line *l, void *_ctx) | |||
1203 | rep = print_bubblebabble ? SSH_FP_BUBBLEBABBLE : SSH_FP_DEFAULT; | 1180 | rep = print_bubblebabble ? SSH_FP_BUBBLEBABBLE : SSH_FP_DEFAULT; |
1204 | 1181 | ||
1205 | if (l->status == HKF_STATUS_MATCHED) { | 1182 | if (l->status == HKF_STATUS_MATCHED) { |
1206 | if (delete_host) { | 1183 | if (ctx->delete_host) { |
1207 | if (l->marker != MRK_NONE) { | 1184 | if (l->marker != MRK_NONE) { |
1208 | /* Don't remove CA and revocation lines */ | 1185 | /* Don't remove CA and revocation lines */ |
1209 | fprintf(ctx->out, "%s\n", l->line); | 1186 | fprintf(ctx->out, "%s\n", l->line); |
@@ -1219,7 +1196,7 @@ known_hosts_find_delete(struct hostkey_foreach_line *l, void *_ctx) | |||
1219 | ctx->host, l->linenum); | 1196 | ctx->host, l->linenum); |
1220 | } | 1197 | } |
1221 | return 0; | 1198 | return 0; |
1222 | } else if (find_host) { | 1199 | } else if (ctx->find_host) { |
1223 | ctx->found_key = 1; | 1200 | ctx->found_key = 1; |
1224 | if (!quiet) { | 1201 | if (!quiet) { |
1225 | printf("# Host %s found: line %lu %s\n", | 1202 | printf("# Host %s found: line %lu %s\n", |
@@ -1227,7 +1204,7 @@ known_hosts_find_delete(struct hostkey_foreach_line *l, void *_ctx) | |||
1227 | l->linenum, l->marker == MRK_CA ? "CA" : | 1204 | l->linenum, l->marker == MRK_CA ? "CA" : |
1228 | (l->marker == MRK_REVOKE ? "REVOKED" : "")); | 1205 | (l->marker == MRK_REVOKE ? "REVOKED" : "")); |
1229 | } | 1206 | } |
1230 | if (hash_hosts) | 1207 | if (ctx->hash_hosts) |
1231 | known_hosts_hash(l, ctx); | 1208 | known_hosts_hash(l, ctx); |
1232 | else if (print_fingerprint) { | 1209 | else if (print_fingerprint) { |
1233 | fp = sshkey_fingerprint(l->key, fptype, rep); | 1210 | fp = sshkey_fingerprint(l->key, fptype, rep); |
@@ -1238,7 +1215,7 @@ known_hosts_find_delete(struct hostkey_foreach_line *l, void *_ctx) | |||
1238 | fprintf(ctx->out, "%s\n", l->line); | 1215 | fprintf(ctx->out, "%s\n", l->line); |
1239 | return 0; | 1216 | return 0; |
1240 | } | 1217 | } |
1241 | } else if (delete_host) { | 1218 | } else if (ctx->delete_host) { |
1242 | /* Retain non-matching hosts when deleting */ | 1219 | /* Retain non-matching hosts when deleting */ |
1243 | if (l->status == HKF_STATUS_INVALID) { | 1220 | if (l->status == HKF_STATUS_INVALID) { |
1244 | ctx->invalid = 1; | 1221 | ctx->invalid = 1; |
@@ -1250,7 +1227,8 @@ known_hosts_find_delete(struct hostkey_foreach_line *l, void *_ctx) | |||
1250 | } | 1227 | } |
1251 | 1228 | ||
1252 | static void | 1229 | static void |
1253 | do_known_hosts(struct passwd *pw, const char *name) | 1230 | do_known_hosts(struct passwd *pw, const char *name, int find_host, |
1231 | int delete_host, int hash_hosts) | ||
1254 | { | 1232 | { |
1255 | char *cp, tmp[PATH_MAX], old[PATH_MAX]; | 1233 | char *cp, tmp[PATH_MAX], old[PATH_MAX]; |
1256 | int r, fd, oerrno, inplace = 0; | 1234 | int r, fd, oerrno, inplace = 0; |
@@ -1269,6 +1247,9 @@ do_known_hosts(struct passwd *pw, const char *name) | |||
1269 | memset(&ctx, 0, sizeof(ctx)); | 1247 | memset(&ctx, 0, sizeof(ctx)); |
1270 | ctx.out = stdout; | 1248 | ctx.out = stdout; |
1271 | ctx.host = name; | 1249 | ctx.host = name; |
1250 | ctx.hash_hosts = hash_hosts; | ||
1251 | ctx.find_host = find_host; | ||
1252 | ctx.delete_host = delete_host; | ||
1272 | 1253 | ||
1273 | /* | 1254 | /* |
1274 | * Find hosts goes to stdout, hash and deletions happen in-place | 1255 | * Find hosts goes to stdout, hash and deletions happen in-place |
@@ -1433,7 +1414,8 @@ do_change_passphrase(struct passwd *pw) | |||
1433 | * Print the SSHFP RR. | 1414 | * Print the SSHFP RR. |
1434 | */ | 1415 | */ |
1435 | static int | 1416 | static int |
1436 | do_print_resource_record(struct passwd *pw, char *fname, char *hname) | 1417 | do_print_resource_record(struct passwd *pw, char *fname, char *hname, |
1418 | int print_generic) | ||
1437 | { | 1419 | { |
1438 | struct sshkey *public; | 1420 | struct sshkey *public; |
1439 | char *comment = NULL; | 1421 | char *comment = NULL; |
@@ -1460,7 +1442,7 @@ do_print_resource_record(struct passwd *pw, char *fname, char *hname) | |||
1460 | * Change the comment of a private key file. | 1442 | * Change the comment of a private key file. |
1461 | */ | 1443 | */ |
1462 | static void | 1444 | static void |
1463 | do_change_comment(struct passwd *pw) | 1445 | do_change_comment(struct passwd *pw, const char *identity_comment) |
1464 | { | 1446 | { |
1465 | char new_comment[1024], *comment, *passphrase; | 1447 | char new_comment[1024], *comment, *passphrase; |
1466 | struct sshkey *private; | 1448 | struct sshkey *private; |
@@ -1672,7 +1654,9 @@ agent_signer(const struct sshkey *key, u_char **sigp, size_t *lenp, | |||
1672 | } | 1654 | } |
1673 | 1655 | ||
1674 | static void | 1656 | static void |
1675 | do_ca_sign(struct passwd *pw, int argc, char **argv) | 1657 | do_ca_sign(struct passwd *pw, const char *ca_key_path, int prefer_agent, |
1658 | unsigned long long cert_serial, int cert_serial_autoinc, | ||
1659 | int argc, char **argv) | ||
1676 | { | 1660 | { |
1677 | int r, i, fd, found, agent_fd = -1; | 1661 | int r, i, fd, found, agent_fd = -1; |
1678 | u_int n; | 1662 | u_int n; |
@@ -1812,6 +1796,8 @@ do_ca_sign(struct passwd *pw, int argc, char **argv) | |||
1812 | 1796 | ||
1813 | sshkey_free(public); | 1797 | sshkey_free(public); |
1814 | free(out); | 1798 | free(out); |
1799 | if (cert_serial_autoinc) | ||
1800 | cert_serial++; | ||
1815 | } | 1801 | } |
1816 | #ifdef ENABLE_PKCS11 | 1802 | #ifdef ENABLE_PKCS11 |
1817 | pkcs11_terminate(); | 1803 | pkcs11_terminate(); |
@@ -2003,8 +1989,9 @@ print_cert(struct sshkey *key) | |||
2003 | printf(" Type: %s %s certificate\n", sshkey_ssh_name(key), | 1989 | printf(" Type: %s %s certificate\n", sshkey_ssh_name(key), |
2004 | sshkey_cert_type(key)); | 1990 | sshkey_cert_type(key)); |
2005 | printf(" Public key: %s %s\n", sshkey_type(key), key_fp); | 1991 | printf(" Public key: %s %s\n", sshkey_type(key), key_fp); |
2006 | printf(" Signing CA: %s %s\n", | 1992 | printf(" Signing CA: %s %s (using %s)\n", |
2007 | sshkey_type(key->cert->signature_key), ca_fp); | 1993 | sshkey_type(key->cert->signature_key), ca_fp, |
1994 | key->cert->signature_type); | ||
2008 | printf(" Key ID: \"%s\"\n", key->cert->key_id); | 1995 | printf(" Key ID: \"%s\"\n", key->cert->key_id); |
2009 | printf(" Serial: %llu\n", (unsigned long long)key->cert->serial); | 1996 | printf(" Serial: %llu\n", (unsigned long long)key->cert->serial); |
2010 | printf(" Valid: %s\n", valid); | 1997 | printf(" Valid: %s\n", valid); |
@@ -2297,7 +2284,9 @@ update_krl_from_file(struct passwd *pw, const char *file, int wild_ca, | |||
2297 | } | 2284 | } |
2298 | 2285 | ||
2299 | static void | 2286 | static void |
2300 | do_gen_krl(struct passwd *pw, int updating, int argc, char **argv) | 2287 | do_gen_krl(struct passwd *pw, int updating, const char *ca_key_path, |
2288 | unsigned long long krl_version, const char *krl_comment, | ||
2289 | int argc, char **argv) | ||
2301 | { | 2290 | { |
2302 | struct ssh_krl *krl; | 2291 | struct ssh_krl *krl; |
2303 | struct stat sb; | 2292 | struct stat sb; |
@@ -2332,10 +2321,10 @@ do_gen_krl(struct passwd *pw, int updating, int argc, char **argv) | |||
2332 | else if ((krl = ssh_krl_init()) == NULL) | 2321 | else if ((krl = ssh_krl_init()) == NULL) |
2333 | fatal("couldn't create KRL"); | 2322 | fatal("couldn't create KRL"); |
2334 | 2323 | ||
2335 | if (cert_serial != 0) | 2324 | if (krl_version != 0) |
2336 | ssh_krl_set_version(krl, cert_serial); | 2325 | ssh_krl_set_version(krl, krl_version); |
2337 | if (identity_comment != NULL) | 2326 | if (krl_comment != NULL) |
2338 | ssh_krl_set_comment(krl, identity_comment); | 2327 | ssh_krl_set_comment(krl, krl_comment); |
2339 | 2328 | ||
2340 | for (i = 0; i < argc; i++) | 2329 | for (i = 0; i < argc; i++) |
2341 | update_krl_from_file(pw, argv[i], wild_ca, ca, krl); | 2330 | update_krl_from_file(pw, argv[i], wild_ca, ca, krl); |
@@ -2387,9 +2376,10 @@ static void | |||
2387 | usage(void) | 2376 | usage(void) |
2388 | { | 2377 | { |
2389 | fprintf(stderr, | 2378 | fprintf(stderr, |
2390 | "usage: ssh-keygen [-q] [-b bits] [-t dsa | ecdsa | ed25519 | rsa]\n" | 2379 | "usage: ssh-keygen [-q] [-b bits] [-t dsa | ecdsa | ed25519 | rsa] [-m format]\n" |
2391 | " [-N new_passphrase] [-C comment] [-f output_keyfile]\n" | 2380 | " [-N new_passphrase] [-C comment] [-f output_keyfile]\n" |
2392 | " ssh-keygen -p [-P old_passphrase] [-N new_passphrase] [-f keyfile]\n" | 2381 | " ssh-keygen -p [-P old_passphrase] [-N new_passphrase] [-m format]\n" |
2382 | " [-f keyfile]\n" | ||
2393 | " ssh-keygen -i [-m key_format] [-f input_keyfile]\n" | 2383 | " ssh-keygen -i [-m key_format] [-f input_keyfile]\n" |
2394 | " ssh-keygen -e [-m key_format] [-f input_keyfile]\n" | 2384 | " ssh-keygen -e [-m key_format] [-f input_keyfile]\n" |
2395 | " ssh-keygen -y [-f input_keyfile]\n" | 2385 | " ssh-keygen -y [-f input_keyfile]\n" |
@@ -2433,9 +2423,17 @@ main(int argc, char **argv) | |||
2433 | struct passwd *pw; | 2423 | struct passwd *pw; |
2434 | struct stat st; | 2424 | struct stat st; |
2435 | int r, opt, type, fd; | 2425 | int r, opt, type, fd; |
2426 | int change_passphrase = 0, change_comment = 0, show_cert = 0; | ||
2427 | int find_host = 0, delete_host = 0, hash_hosts = 0; | ||
2436 | int gen_all_hostkeys = 0, gen_krl = 0, update_krl = 0, check_krl = 0; | 2428 | int gen_all_hostkeys = 0, gen_krl = 0, update_krl = 0, check_krl = 0; |
2429 | int prefer_agent = 0, convert_to = 0, convert_from = 0; | ||
2430 | int print_public = 0, print_generic = 0, cert_serial_autoinc = 0; | ||
2431 | unsigned long long cert_serial = 0; | ||
2432 | char *identity_comment = NULL, *ca_key_path = NULL; | ||
2433 | u_int bits = 0; | ||
2437 | FILE *f; | 2434 | FILE *f; |
2438 | const char *errstr; | 2435 | const char *errstr; |
2436 | int log_level = SYSLOG_LEVEL_INFO; | ||
2439 | #ifdef WITH_OPENSSL | 2437 | #ifdef WITH_OPENSSL |
2440 | /* Moduli generation/screening */ | 2438 | /* Moduli generation/screening */ |
2441 | char out_file[PATH_MAX], *checkpoint = NULL; | 2439 | char out_file[PATH_MAX], *checkpoint = NULL; |
@@ -2454,13 +2452,10 @@ main(int argc, char **argv) | |||
2454 | 2452 | ||
2455 | __progname = ssh_get_progname(argv[0]); | 2453 | __progname = ssh_get_progname(argv[0]); |
2456 | 2454 | ||
2457 | #ifdef WITH_OPENSSL | ||
2458 | OpenSSL_add_all_algorithms(); | ||
2459 | #endif | ||
2460 | log_init(argv[0], SYSLOG_LEVEL_INFO, SYSLOG_FACILITY_USER, 1); | ||
2461 | |||
2462 | seed_rng(); | 2455 | seed_rng(); |
2463 | 2456 | ||
2457 | log_init(argv[0], SYSLOG_LEVEL_INFO, SYSLOG_FACILITY_USER, 1); | ||
2458 | |||
2464 | msetlocale(); | 2459 | msetlocale(); |
2465 | 2460 | ||
2466 | /* we need this for the home * directory. */ | 2461 | /* we need this for the home * directory. */ |
@@ -2628,6 +2623,10 @@ main(int argc, char **argv) | |||
2628 | break; | 2623 | break; |
2629 | case 'z': | 2624 | case 'z': |
2630 | errno = 0; | 2625 | errno = 0; |
2626 | if (*optarg == '+') { | ||
2627 | cert_serial_autoinc = 1; | ||
2628 | optarg++; | ||
2629 | } | ||
2631 | cert_serial = strtoull(optarg, &ep, 10); | 2630 | cert_serial = strtoull(optarg, &ep, 10); |
2632 | if (*optarg < '0' || *optarg > '9' || *ep != '\0' || | 2631 | if (*optarg < '0' || *optarg > '9' || *ep != '\0' || |
2633 | (errno == ERANGE && cert_serial == ULLONG_MAX)) | 2632 | (errno == ERANGE && cert_serial == ULLONG_MAX)) |
@@ -2707,7 +2706,8 @@ main(int argc, char **argv) | |||
2707 | usage(); | 2706 | usage(); |
2708 | } | 2707 | } |
2709 | if (gen_krl) { | 2708 | if (gen_krl) { |
2710 | do_gen_krl(pw, update_krl, argc, argv); | 2709 | do_gen_krl(pw, update_krl, ca_key_path, |
2710 | cert_serial, identity_comment, argc, argv); | ||
2711 | return (0); | 2711 | return (0); |
2712 | } | 2712 | } |
2713 | if (check_krl) { | 2713 | if (check_krl) { |
@@ -2717,12 +2717,15 @@ main(int argc, char **argv) | |||
2717 | if (ca_key_path != NULL) { | 2717 | if (ca_key_path != NULL) { |
2718 | if (cert_key_id == NULL) | 2718 | if (cert_key_id == NULL) |
2719 | fatal("Must specify key id (-I) when certifying"); | 2719 | fatal("Must specify key id (-I) when certifying"); |
2720 | do_ca_sign(pw, argc, argv); | 2720 | do_ca_sign(pw, ca_key_path, prefer_agent, |
2721 | cert_serial, cert_serial_autoinc, argc, argv); | ||
2721 | } | 2722 | } |
2722 | if (show_cert) | 2723 | if (show_cert) |
2723 | do_show_cert(pw); | 2724 | do_show_cert(pw); |
2724 | if (delete_host || hash_hosts || find_host) | 2725 | if (delete_host || hash_hosts || find_host) { |
2725 | do_known_hosts(pw, rr_hostname); | 2726 | do_known_hosts(pw, rr_hostname, find_host, |
2727 | delete_host, hash_hosts); | ||
2728 | } | ||
2726 | if (pkcs11provider != NULL) | 2729 | if (pkcs11provider != NULL) |
2727 | do_download(pw); | 2730 | do_download(pw); |
2728 | if (print_fingerprint || print_bubblebabble) | 2731 | if (print_fingerprint || print_bubblebabble) |
@@ -2730,7 +2733,7 @@ main(int argc, char **argv) | |||
2730 | if (change_passphrase) | 2733 | if (change_passphrase) |
2731 | do_change_passphrase(pw); | 2734 | do_change_passphrase(pw); |
2732 | if (change_comment) | 2735 | if (change_comment) |
2733 | do_change_comment(pw); | 2736 | do_change_comment(pw, identity_comment); |
2734 | #ifdef WITH_OPENSSL | 2737 | #ifdef WITH_OPENSSL |
2735 | if (convert_to) | 2738 | if (convert_to) |
2736 | do_convert_to(pw); | 2739 | do_convert_to(pw); |
@@ -2743,23 +2746,28 @@ main(int argc, char **argv) | |||
2743 | unsigned int n = 0; | 2746 | unsigned int n = 0; |
2744 | 2747 | ||
2745 | if (have_identity) { | 2748 | if (have_identity) { |
2746 | n = do_print_resource_record(pw, | 2749 | n = do_print_resource_record(pw, identity_file, |
2747 | identity_file, rr_hostname); | 2750 | rr_hostname, print_generic); |
2748 | if (n == 0) | 2751 | if (n == 0) |
2749 | fatal("%s: %s", identity_file, strerror(errno)); | 2752 | fatal("%s: %s", identity_file, strerror(errno)); |
2750 | exit(0); | 2753 | exit(0); |
2751 | } else { | 2754 | } else { |
2752 | 2755 | ||
2753 | n += do_print_resource_record(pw, | 2756 | n += do_print_resource_record(pw, |
2754 | _PATH_HOST_RSA_KEY_FILE, rr_hostname); | 2757 | _PATH_HOST_RSA_KEY_FILE, rr_hostname, |
2758 | print_generic); | ||
2755 | n += do_print_resource_record(pw, | 2759 | n += do_print_resource_record(pw, |
2756 | _PATH_HOST_DSA_KEY_FILE, rr_hostname); | 2760 | _PATH_HOST_DSA_KEY_FILE, rr_hostname, |
2761 | print_generic); | ||
2757 | n += do_print_resource_record(pw, | 2762 | n += do_print_resource_record(pw, |
2758 | _PATH_HOST_ECDSA_KEY_FILE, rr_hostname); | 2763 | _PATH_HOST_ECDSA_KEY_FILE, rr_hostname, |
2764 | print_generic); | ||
2759 | n += do_print_resource_record(pw, | 2765 | n += do_print_resource_record(pw, |
2760 | _PATH_HOST_ED25519_KEY_FILE, rr_hostname); | 2766 | _PATH_HOST_ED25519_KEY_FILE, rr_hostname, |
2767 | print_generic); | ||
2761 | n += do_print_resource_record(pw, | 2768 | n += do_print_resource_record(pw, |
2762 | _PATH_HOST_XMSS_KEY_FILE, rr_hostname); | 2769 | _PATH_HOST_XMSS_KEY_FILE, rr_hostname, |
2770 | print_generic); | ||
2763 | if (n == 0) | 2771 | if (n == 0) |
2764 | fatal("no keys found."); | 2772 | fatal("no keys found."); |
2765 | exit(0); | 2773 | exit(0); |