diff options
-rw-r--r-- | auth2-hostbased.c | 3 | ||||
-rw-r--r-- | authfile.c | 64 | ||||
-rw-r--r-- | authfile.h | 10 | ||||
-rw-r--r-- | key.c | 25 | ||||
-rw-r--r-- | key.h | 3 | ||||
-rw-r--r-- | krl.c | 4 | ||||
-rw-r--r-- | ssh-keysign.c | 21 | ||||
-rw-r--r-- | sshconnect2.c | 4 | ||||
-rw-r--r-- | sshkey.c | 26 | ||||
-rw-r--r-- | sshkey.h | 4 |
10 files changed, 62 insertions, 102 deletions
diff --git a/auth2-hostbased.c b/auth2-hostbased.c index eb6bee50b..2db3d2524 100644 --- a/auth2-hostbased.c +++ b/auth2-hostbased.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: auth2-hostbased.c,v 1.20 2014/12/23 22:42:48 djm Exp $ */ | 1 | /* $OpenBSD: auth2-hostbased.c,v 1.21 2015/01/08 10:14:08 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. | 3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. |
4 | * | 4 | * |
@@ -84,6 +84,7 @@ userauth_hostbased(Authctxt *authctxt) | |||
84 | buffer_dump(&b); | 84 | buffer_dump(&b); |
85 | buffer_free(&b); | 85 | buffer_free(&b); |
86 | #endif | 86 | #endif |
87 | /* XXX provide some way to allow admin to specify key types accepted */ | ||
87 | pktype = key_type_from_name(pkalg); | 88 | pktype = key_type_from_name(pkalg); |
88 | if (pktype == KEY_UNSPEC) { | 89 | if (pktype == KEY_UNSPEC) { |
89 | /* this is perfectly legal */ | 90 | /* this is perfectly legal */ |
diff --git a/authfile.c b/authfile.c index 95877e159..de9708607 100644 --- a/authfile.c +++ b/authfile.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: authfile.c,v 1.108 2014/12/04 02:24:32 djm Exp $ */ | 1 | /* $OpenBSD: authfile.c,v 1.109 2015/01/08 10:14:08 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2000, 2013 Markus Friedl. All rights reserved. | 3 | * Copyright (c) 2000, 2013 Markus Friedl. All rights reserved. |
4 | * | 4 | * |
@@ -95,7 +95,7 @@ sshkey_save_private(struct sshkey *key, const char *filename, | |||
95 | 95 | ||
96 | /* Load a key from a fd into a buffer */ | 96 | /* Load a key from a fd into a buffer */ |
97 | int | 97 | int |
98 | sshkey_load_file(int fd, const char *filename, struct sshbuf *blob) | 98 | sshkey_load_file(int fd, struct sshbuf *blob) |
99 | { | 99 | { |
100 | u_char buf[1024]; | 100 | u_char buf[1024]; |
101 | size_t len; | 101 | size_t len; |
@@ -142,8 +142,7 @@ sshkey_load_file(int fd, const char *filename, struct sshbuf *blob) | |||
142 | * otherwise. | 142 | * otherwise. |
143 | */ | 143 | */ |
144 | static int | 144 | static int |
145 | sshkey_load_public_rsa1(int fd, const char *filename, | 145 | sshkey_load_public_rsa1(int fd, struct sshkey **keyp, char **commentp) |
146 | struct sshkey **keyp, char **commentp) | ||
147 | { | 146 | { |
148 | struct sshbuf *b = NULL; | 147 | struct sshbuf *b = NULL; |
149 | int r; | 148 | int r; |
@@ -154,7 +153,7 @@ sshkey_load_public_rsa1(int fd, const char *filename, | |||
154 | 153 | ||
155 | if ((b = sshbuf_new()) == NULL) | 154 | if ((b = sshbuf_new()) == NULL) |
156 | return SSH_ERR_ALLOC_FAIL; | 155 | return SSH_ERR_ALLOC_FAIL; |
157 | if ((r = sshkey_load_file(fd, filename, b)) != 0) | 156 | if ((r = sshkey_load_file(fd, b)) != 0) |
158 | goto out; | 157 | goto out; |
159 | if ((r = sshkey_parse_public_rsa1_fileblob(b, keyp, commentp)) != 0) | 158 | if ((r = sshkey_parse_public_rsa1_fileblob(b, keyp, commentp)) != 0) |
160 | goto out; | 159 | goto out; |
@@ -165,33 +164,6 @@ sshkey_load_public_rsa1(int fd, const char *filename, | |||
165 | } | 164 | } |
166 | #endif /* WITH_SSH1 */ | 165 | #endif /* WITH_SSH1 */ |
167 | 166 | ||
168 | #ifdef WITH_OPENSSL | ||
169 | /* XXX Deprecate? */ | ||
170 | int | ||
171 | sshkey_load_private_pem(int fd, int type, const char *passphrase, | ||
172 | struct sshkey **keyp, char **commentp) | ||
173 | { | ||
174 | struct sshbuf *buffer = NULL; | ||
175 | int r; | ||
176 | |||
177 | *keyp = NULL; | ||
178 | if (commentp != NULL) | ||
179 | *commentp = NULL; | ||
180 | |||
181 | if ((buffer = sshbuf_new()) == NULL) | ||
182 | return SSH_ERR_ALLOC_FAIL; | ||
183 | if ((r = sshkey_load_file(fd, NULL, buffer)) != 0) | ||
184 | goto out; | ||
185 | if ((r = sshkey_parse_private_pem_fileblob(buffer, type, passphrase, | ||
186 | keyp, commentp)) != 0) | ||
187 | goto out; | ||
188 | r = 0; | ||
189 | out: | ||
190 | sshbuf_free(buffer); | ||
191 | return r; | ||
192 | } | ||
193 | #endif /* WITH_OPENSSL */ | ||
194 | |||
195 | /* XXX remove error() calls from here? */ | 167 | /* XXX remove error() calls from here? */ |
196 | int | 168 | int |
197 | sshkey_perm_ok(int fd, const char *filename) | 169 | sshkey_perm_ok(int fd, const char *filename) |
@@ -227,7 +199,6 @@ sshkey_load_private_type(int type, const char *filename, const char *passphrase, | |||
227 | struct sshkey **keyp, char **commentp, int *perm_ok) | 199 | struct sshkey **keyp, char **commentp, int *perm_ok) |
228 | { | 200 | { |
229 | int fd, r; | 201 | int fd, r; |
230 | struct sshbuf *buffer = NULL; | ||
231 | 202 | ||
232 | *keyp = NULL; | 203 | *keyp = NULL; |
233 | if (commentp != NULL) | 204 | if (commentp != NULL) |
@@ -247,18 +218,31 @@ sshkey_load_private_type(int type, const char *filename, const char *passphrase, | |||
247 | if (perm_ok != NULL) | 218 | if (perm_ok != NULL) |
248 | *perm_ok = 1; | 219 | *perm_ok = 1; |
249 | 220 | ||
221 | r = sshkey_load_private_type_fd(fd, type, passphrase, keyp, commentp); | ||
222 | out: | ||
223 | close(fd); | ||
224 | return r; | ||
225 | } | ||
226 | |||
227 | int | ||
228 | sshkey_load_private_type_fd(int fd, int type, const char *passphrase, | ||
229 | struct sshkey **keyp, char **commentp) | ||
230 | { | ||
231 | struct sshbuf *buffer = NULL; | ||
232 | int r; | ||
233 | |||
250 | if ((buffer = sshbuf_new()) == NULL) { | 234 | if ((buffer = sshbuf_new()) == NULL) { |
251 | r = SSH_ERR_ALLOC_FAIL; | 235 | r = SSH_ERR_ALLOC_FAIL; |
252 | goto out; | 236 | goto out; |
253 | } | 237 | } |
254 | if ((r = sshkey_load_file(fd, filename, buffer)) != 0) | 238 | if ((r = sshkey_load_file(fd, buffer)) != 0 || |
255 | goto out; | 239 | (r = sshkey_parse_private_fileblob_type(buffer, type, |
256 | if ((r = sshkey_parse_private_fileblob_type(buffer, type, passphrase, | 240 | passphrase, keyp, commentp)) != 0) |
257 | keyp, commentp)) != 0) | ||
258 | goto out; | 241 | goto out; |
242 | |||
243 | /* success */ | ||
259 | r = 0; | 244 | r = 0; |
260 | out: | 245 | out: |
261 | close(fd); | ||
262 | if (buffer != NULL) | 246 | if (buffer != NULL) |
263 | sshbuf_free(buffer); | 247 | sshbuf_free(buffer); |
264 | return r; | 248 | return r; |
@@ -287,7 +271,7 @@ sshkey_load_private(const char *filename, const char *passphrase, | |||
287 | r = SSH_ERR_ALLOC_FAIL; | 271 | r = SSH_ERR_ALLOC_FAIL; |
288 | goto out; | 272 | goto out; |
289 | } | 273 | } |
290 | if ((r = sshkey_load_file(fd, filename, buffer)) != 0 || | 274 | if ((r = sshkey_load_file(fd, buffer)) != 0 || |
291 | (r = sshkey_parse_private_fileblob(buffer, passphrase, filename, | 275 | (r = sshkey_parse_private_fileblob(buffer, passphrase, filename, |
292 | keyp, commentp)) != 0) | 276 | keyp, commentp)) != 0) |
293 | goto out; | 277 | goto out; |
@@ -363,7 +347,7 @@ sshkey_load_public(const char *filename, struct sshkey **keyp, char **commentp) | |||
363 | goto skip; | 347 | goto skip; |
364 | #ifdef WITH_SSH1 | 348 | #ifdef WITH_SSH1 |
365 | /* try rsa1 private key */ | 349 | /* try rsa1 private key */ |
366 | r = sshkey_load_public_rsa1(fd, filename, keyp, commentp); | 350 | r = sshkey_load_public_rsa1(fd, keyp, commentp); |
367 | close(fd); | 351 | close(fd); |
368 | switch (r) { | 352 | switch (r) { |
369 | case SSH_ERR_INTERNAL_ERROR: | 353 | case SSH_ERR_INTERNAL_ERROR: |
diff --git a/authfile.h b/authfile.h index 645404e61..624d269f1 100644 --- a/authfile.h +++ b/authfile.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: authfile.h,v 1.20 2014/12/04 02:24:32 djm Exp $ */ | 1 | /* $OpenBSD: authfile.h,v 1.21 2015/01/08 10:14:08 djm Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2000, 2013 Markus Friedl. All rights reserved. | 4 | * Copyright (c) 2000, 2013 Markus Friedl. All rights reserved. |
@@ -30,9 +30,12 @@ | |||
30 | struct sshbuf; | 30 | struct sshbuf; |
31 | struct sshkey; | 31 | struct sshkey; |
32 | 32 | ||
33 | /* XXX document these */ | ||
34 | /* XXX some of these could probably be merged/retired */ | ||
35 | |||
33 | int sshkey_save_private(struct sshkey *, const char *, | 36 | int sshkey_save_private(struct sshkey *, const char *, |
34 | const char *, const char *, int, const char *, int); | 37 | const char *, const char *, int, const char *, int); |
35 | int sshkey_load_file(int, const char *, struct sshbuf *); | 38 | int sshkey_load_file(int, struct sshbuf *); |
36 | int sshkey_load_cert(const char *, struct sshkey **); | 39 | int sshkey_load_cert(const char *, struct sshkey **); |
37 | int sshkey_load_public(const char *, struct sshkey **, char **); | 40 | int sshkey_load_public(const char *, struct sshkey **, char **); |
38 | int sshkey_load_private(const char *, const char *, struct sshkey **, char **); | 41 | int sshkey_load_private(const char *, const char *, struct sshkey **, char **); |
@@ -40,7 +43,8 @@ int sshkey_load_private_cert(int, const char *, const char *, | |||
40 | struct sshkey **, int *); | 43 | struct sshkey **, int *); |
41 | int sshkey_load_private_type(int, const char *, const char *, | 44 | int sshkey_load_private_type(int, const char *, const char *, |
42 | struct sshkey **, char **, int *); | 45 | struct sshkey **, char **, int *); |
43 | int sshkey_load_private_pem(int, int, const char *, struct sshkey **, char **); | 46 | int sshkey_load_private_type_fd(int fd, int type, const char *passphrase, |
47 | struct sshkey **keyp, char **commentp); | ||
44 | int sshkey_perm_ok(int, const char *); | 48 | int sshkey_perm_ok(int, const char *); |
45 | int sshkey_in_file(struct sshkey *, const char *, int, int); | 49 | int sshkey_in_file(struct sshkey *, const char *, int, int); |
46 | int sshkey_check_revoked(struct sshkey *key, const char *revoked_keys_file); | 50 | int sshkey_check_revoked(struct sshkey *key, const char *revoked_keys_file); |
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: key.c,v 1.124 2014/12/21 22:27:56 djm Exp $ */ | 1 | /* $OpenBSD: key.c,v 1.125 2015/01/08 10:14:08 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * placed in the public domain | 3 | * placed in the public domain |
4 | */ | 4 | */ |
@@ -328,7 +328,7 @@ key_load_file(int fd, const char *filename, struct sshbuf *blob) | |||
328 | { | 328 | { |
329 | int r; | 329 | int r; |
330 | 330 | ||
331 | if ((r = sshkey_load_file(fd, filename, blob)) != 0) { | 331 | if ((r = sshkey_load_file(fd, blob)) != 0) { |
332 | fatal_on_fatal_errors(r, __func__, SSH_ERR_LIBCRYPTO_ERROR); | 332 | fatal_on_fatal_errors(r, __func__, SSH_ERR_LIBCRYPTO_ERROR); |
333 | error("%s: %s", __func__, ssh_err(r)); | 333 | error("%s: %s", __func__, ssh_err(r)); |
334 | return 0; | 334 | return 0; |
@@ -435,27 +435,6 @@ key_load_private_type(int type, const char *filename, const char *passphrase, | |||
435 | return ret; | 435 | return ret; |
436 | } | 436 | } |
437 | 437 | ||
438 | #ifdef WITH_OPENSSL | ||
439 | Key * | ||
440 | key_load_private_pem(int fd, int type, const char *passphrase, | ||
441 | char **commentp) | ||
442 | { | ||
443 | int r; | ||
444 | Key *ret = NULL; | ||
445 | |||
446 | if ((r = sshkey_load_private_pem(fd, type, passphrase, | ||
447 | &ret, commentp)) != 0) { | ||
448 | fatal_on_fatal_errors(r, __func__, SSH_ERR_LIBCRYPTO_ERROR); | ||
449 | if (r == SSH_ERR_KEY_WRONG_PASSPHRASE) | ||
450 | debug("%s: %s", __func__, ssh_err(r)); | ||
451 | else | ||
452 | error("%s: %s", __func__, ssh_err(r)); | ||
453 | return NULL; | ||
454 | } | ||
455 | return ret; | ||
456 | } | ||
457 | #endif /* WITH_OPENSSL */ | ||
458 | |||
459 | int | 438 | int |
460 | key_perm_ok(int fd, const char *filename) | 439 | key_perm_ok(int fd, const char *filename) |
461 | { | 440 | { |
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: key.h,v 1.44 2014/12/21 22:27:56 djm Exp $ */ | 1 | /* $OpenBSD: key.h,v 1.45 2015/01/08 10:14:08 djm Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. | 4 | * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. |
@@ -104,7 +104,6 @@ Key *key_load_public(const char *, char **); | |||
104 | Key *key_load_private(const char *, const char *, char **); | 104 | Key *key_load_private(const char *, const char *, char **); |
105 | Key *key_load_private_cert(int, const char *, const char *, int *); | 105 | Key *key_load_private_cert(int, const char *, const char *, int *); |
106 | Key *key_load_private_type(int, const char *, const char *, char **, int *); | 106 | Key *key_load_private_type(int, const char *, const char *, char **, int *); |
107 | Key *key_load_private_pem(int, int, const char *, char **); | ||
108 | int key_perm_ok(int, const char *); | 107 | int key_perm_ok(int, const char *); |
109 | 108 | ||
110 | #endif | 109 | #endif |
@@ -14,7 +14,7 @@ | |||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | /* $OpenBSD: krl.c,v 1.21 2014/12/21 22:27:56 djm Exp $ */ | 17 | /* $OpenBSD: krl.c,v 1.22 2015/01/08 10:14:08 djm Exp $ */ |
18 | 18 | ||
19 | #include "includes.h" | 19 | #include "includes.h" |
20 | 20 | ||
@@ -1248,7 +1248,7 @@ ssh_krl_file_contains_key(const char *path, const struct sshkey *key) | |||
1248 | oerrno = errno; | 1248 | oerrno = errno; |
1249 | goto out; | 1249 | goto out; |
1250 | } | 1250 | } |
1251 | if ((r = sshkey_load_file(fd, path, krlbuf)) != 0) { | 1251 | if ((r = sshkey_load_file(fd, krlbuf)) != 0) { |
1252 | oerrno = errno; | 1252 | oerrno = errno; |
1253 | goto out; | 1253 | goto out; |
1254 | } | 1254 | } |
diff --git a/ssh-keysign.c b/ssh-keysign.c index b86e18d8c..d59f115fc 100644 --- a/ssh-keysign.c +++ b/ssh-keysign.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssh-keysign.c,v 1.44 2014/12/21 22:27:56 djm Exp $ */ | 1 | /* $OpenBSD: ssh-keysign.c,v 1.45 2015/01/08 10:14:08 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2002 Markus Friedl. All rights reserved. | 3 | * Copyright (c) 2002 Markus Friedl. All rights reserved. |
4 | * | 4 | * |
@@ -52,6 +52,8 @@ | |||
52 | #include "pathnames.h" | 52 | #include "pathnames.h" |
53 | #include "readconf.h" | 53 | #include "readconf.h" |
54 | #include "uidswap.h" | 54 | #include "uidswap.h" |
55 | #include "sshkey.h" | ||
56 | #include "ssherr.h" | ||
55 | 57 | ||
56 | /* XXX readconf.c needs these */ | 58 | /* XXX readconf.c needs these */ |
57 | uid_t original_real_uid; | 59 | uid_t original_real_uid; |
@@ -69,6 +71,8 @@ valid_request(struct passwd *pw, char *host, Key **ret, u_char *data, | |||
69 | char *pkalg, *p; | 71 | char *pkalg, *p; |
70 | int pktype, fail; | 72 | int pktype, fail; |
71 | 73 | ||
74 | if (ret != NULL) | ||
75 | *ret = NULL; | ||
72 | fail = 0; | 76 | fail = 0; |
73 | 77 | ||
74 | buffer_init(&b); | 78 | buffer_init(&b); |
@@ -153,7 +157,7 @@ main(int argc, char **argv) | |||
153 | #define NUM_KEYTYPES 4 | 157 | #define NUM_KEYTYPES 4 |
154 | Key *keys[NUM_KEYTYPES], *key = NULL; | 158 | Key *keys[NUM_KEYTYPES], *key = NULL; |
155 | struct passwd *pw; | 159 | struct passwd *pw; |
156 | int key_fd[NUM_KEYTYPES], i, found, version = 2, fd; | 160 | int r, key_fd[NUM_KEYTYPES], i, found, version = 2, fd; |
157 | u_char *signature, *data; | 161 | u_char *signature, *data; |
158 | char *host, *fp; | 162 | char *host, *fp; |
159 | u_int slen, dlen; | 163 | u_int slen, dlen; |
@@ -209,14 +213,15 @@ main(int argc, char **argv) | |||
209 | keys[i] = NULL; | 213 | keys[i] = NULL; |
210 | if (key_fd[i] == -1) | 214 | if (key_fd[i] == -1) |
211 | continue; | 215 | continue; |
212 | #ifdef WITH_OPENSSL | 216 | r = sshkey_load_private_type_fd(key_fd[i], KEY_UNSPEC, |
213 | /* XXX wrong api */ | 217 | NULL, &key, NULL); |
214 | keys[i] = key_load_private_pem(key_fd[i], KEY_UNSPEC, | ||
215 | NULL, NULL); | ||
216 | #endif | ||
217 | close(key_fd[i]); | 218 | close(key_fd[i]); |
218 | if (keys[i] != NULL) | 219 | if (r != 0) |
220 | debug("parse key %d: %s", i, ssh_err(r)); | ||
221 | else if (key != NULL) { | ||
222 | keys[i] = key; | ||
219 | found = 1; | 223 | found = 1; |
224 | } | ||
220 | } | 225 | } |
221 | if (!found) | 226 | if (!found) |
222 | fatal("no hostkey found"); | 227 | fatal("no hostkey found"); |
diff --git a/sshconnect2.c b/sshconnect2.c index ad20fae6a..6a7b69938 100644 --- a/sshconnect2.c +++ b/sshconnect2.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: sshconnect2.c,v 1.212 2014/12/21 22:27:56 djm Exp $ */ | 1 | /* $OpenBSD: sshconnect2.c,v 1.213 2015/01/08 10:14:08 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. | 3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. |
4 | * Copyright (c) 2008 Damien Miller. All rights reserved. | 4 | * Copyright (c) 2008 Damien Miller. All rights reserved. |
@@ -1489,6 +1489,8 @@ userauth_hostbased(Authctxt *authctxt) | |||
1489 | u_int blen, slen; | 1489 | u_int blen, slen; |
1490 | int ok, i, found = 0; | 1490 | int ok, i, found = 0; |
1491 | 1491 | ||
1492 | /* XXX provide some way to allow user to specify key types attempted */ | ||
1493 | |||
1492 | /* check for a useful key */ | 1494 | /* check for a useful key */ |
1493 | for (i = 0; i < sensitive->nkeys; i++) { | 1495 | for (i = 0; i < sensitive->nkeys; i++) { |
1494 | private = sensitive->keys[i]; | 1496 | private = sensitive->keys[i]; |
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: sshkey.c,v 1.7 2014/12/21 22:27:55 djm Exp $ */ | 1 | /* $OpenBSD: sshkey.c,v 1.8 2015/01/08 10:14:08 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. | 3 | * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. |
4 | * Copyright (c) 2008 Alexander von Gernler. All rights reserved. | 4 | * Copyright (c) 2008 Alexander von Gernler. All rights reserved. |
@@ -3719,20 +3719,16 @@ sshkey_parse_private_rsa1(struct sshbuf *blob, const char *passphrase, | |||
3719 | #endif /* WITH_SSH1 */ | 3719 | #endif /* WITH_SSH1 */ |
3720 | 3720 | ||
3721 | #ifdef WITH_OPENSSL | 3721 | #ifdef WITH_OPENSSL |
3722 | /* XXX make private once ssh-keysign.c fixed */ | 3722 | static int |
3723 | int | ||
3724 | sshkey_parse_private_pem_fileblob(struct sshbuf *blob, int type, | 3723 | sshkey_parse_private_pem_fileblob(struct sshbuf *blob, int type, |
3725 | const char *passphrase, struct sshkey **keyp, char **commentp) | 3724 | const char *passphrase, struct sshkey **keyp) |
3726 | { | 3725 | { |
3727 | EVP_PKEY *pk = NULL; | 3726 | EVP_PKEY *pk = NULL; |
3728 | struct sshkey *prv = NULL; | 3727 | struct sshkey *prv = NULL; |
3729 | char *name = "<no key>"; | ||
3730 | BIO *bio = NULL; | 3728 | BIO *bio = NULL; |
3731 | int r; | 3729 | int r; |
3732 | 3730 | ||
3733 | *keyp = NULL; | 3731 | *keyp = NULL; |
3734 | if (commentp != NULL) | ||
3735 | *commentp = NULL; | ||
3736 | 3732 | ||
3737 | if ((bio = BIO_new(BIO_s_mem())) == NULL || sshbuf_len(blob) > INT_MAX) | 3733 | if ((bio = BIO_new(BIO_s_mem())) == NULL || sshbuf_len(blob) > INT_MAX) |
3738 | return SSH_ERR_ALLOC_FAIL; | 3734 | return SSH_ERR_ALLOC_FAIL; |
@@ -3755,7 +3751,6 @@ sshkey_parse_private_pem_fileblob(struct sshbuf *blob, int type, | |||
3755 | } | 3751 | } |
3756 | prv->rsa = EVP_PKEY_get1_RSA(pk); | 3752 | prv->rsa = EVP_PKEY_get1_RSA(pk); |
3757 | prv->type = KEY_RSA; | 3753 | prv->type = KEY_RSA; |
3758 | name = "rsa w/o comment"; | ||
3759 | #ifdef DEBUG_PK | 3754 | #ifdef DEBUG_PK |
3760 | RSA_print_fp(stderr, prv->rsa, 8); | 3755 | RSA_print_fp(stderr, prv->rsa, 8); |
3761 | #endif | 3756 | #endif |
@@ -3771,7 +3766,6 @@ sshkey_parse_private_pem_fileblob(struct sshbuf *blob, int type, | |||
3771 | } | 3766 | } |
3772 | prv->dsa = EVP_PKEY_get1_DSA(pk); | 3767 | prv->dsa = EVP_PKEY_get1_DSA(pk); |
3773 | prv->type = KEY_DSA; | 3768 | prv->type = KEY_DSA; |
3774 | name = "dsa w/o comment"; | ||
3775 | #ifdef DEBUG_PK | 3769 | #ifdef DEBUG_PK |
3776 | DSA_print_fp(stderr, prv->dsa, 8); | 3770 | DSA_print_fp(stderr, prv->dsa, 8); |
3777 | #endif | 3771 | #endif |
@@ -3793,7 +3787,6 @@ sshkey_parse_private_pem_fileblob(struct sshbuf *blob, int type, | |||
3793 | r = SSH_ERR_INVALID_FORMAT; | 3787 | r = SSH_ERR_INVALID_FORMAT; |
3794 | goto out; | 3788 | goto out; |
3795 | } | 3789 | } |
3796 | name = "ecdsa w/o comment"; | ||
3797 | # ifdef DEBUG_PK | 3790 | # ifdef DEBUG_PK |
3798 | if (prv != NULL && prv->ecdsa != NULL) | 3791 | if (prv != NULL && prv->ecdsa != NULL) |
3799 | sshkey_dump_ec_key(prv->ecdsa); | 3792 | sshkey_dump_ec_key(prv->ecdsa); |
@@ -3803,11 +3796,6 @@ sshkey_parse_private_pem_fileblob(struct sshbuf *blob, int type, | |||
3803 | r = SSH_ERR_INVALID_FORMAT; | 3796 | r = SSH_ERR_INVALID_FORMAT; |
3804 | goto out; | 3797 | goto out; |
3805 | } | 3798 | } |
3806 | if (commentp != NULL && | ||
3807 | (*commentp = strdup(name)) == NULL) { | ||
3808 | r = SSH_ERR_ALLOC_FAIL; | ||
3809 | goto out; | ||
3810 | } | ||
3811 | r = 0; | 3799 | r = 0; |
3812 | *keyp = prv; | 3800 | *keyp = prv; |
3813 | prv = NULL; | 3801 | prv = NULL; |
@@ -3839,8 +3827,8 @@ sshkey_parse_private_fileblob_type(struct sshbuf *blob, int type, | |||
3839 | case KEY_DSA: | 3827 | case KEY_DSA: |
3840 | case KEY_ECDSA: | 3828 | case KEY_ECDSA: |
3841 | case KEY_RSA: | 3829 | case KEY_RSA: |
3842 | return sshkey_parse_private_pem_fileblob(blob, type, passphrase, | 3830 | return sshkey_parse_private_pem_fileblob(blob, type, |
3843 | keyp, commentp); | 3831 | passphrase, keyp); |
3844 | #endif /* WITH_OPENSSL */ | 3832 | #endif /* WITH_OPENSSL */ |
3845 | case KEY_ED25519: | 3833 | case KEY_ED25519: |
3846 | return sshkey_parse_private2(blob, type, passphrase, | 3834 | return sshkey_parse_private2(blob, type, passphrase, |
@@ -3850,8 +3838,8 @@ sshkey_parse_private_fileblob_type(struct sshbuf *blob, int type, | |||
3850 | commentp)) == 0) | 3838 | commentp)) == 0) |
3851 | return 0; | 3839 | return 0; |
3852 | #ifdef WITH_OPENSSL | 3840 | #ifdef WITH_OPENSSL |
3853 | return sshkey_parse_private_pem_fileblob(blob, type, passphrase, | 3841 | return sshkey_parse_private_pem_fileblob(blob, type, |
3854 | keyp, commentp); | 3842 | passphrase, keyp); |
3855 | #else | 3843 | #else |
3856 | return SSH_ERR_INVALID_FORMAT; | 3844 | return SSH_ERR_INVALID_FORMAT; |
3857 | #endif /* WITH_OPENSSL */ | 3845 | #endif /* WITH_OPENSSL */ |
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: sshkey.h,v 1.2 2014/12/21 22:27:55 djm Exp $ */ | 1 | /* $OpenBSD: sshkey.h,v 1.3 2015/01/08 10:14:08 djm Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. | 4 | * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. |
@@ -184,8 +184,6 @@ int sshkey_private_to_fileblob(struct sshkey *key, struct sshbuf *blob, | |||
184 | int force_new_format, const char *new_format_cipher, int new_format_rounds); | 184 | int force_new_format, const char *new_format_cipher, int new_format_rounds); |
185 | int sshkey_parse_public_rsa1_fileblob(struct sshbuf *blob, | 185 | int sshkey_parse_public_rsa1_fileblob(struct sshbuf *blob, |
186 | struct sshkey **keyp, char **commentp); | 186 | struct sshkey **keyp, char **commentp); |
187 | int sshkey_parse_private_pem_fileblob(struct sshbuf *blob, int type, | ||
188 | const char *passphrase, struct sshkey **keyp, char **commentp); | ||
189 | int sshkey_parse_private_fileblob(struct sshbuf *buffer, | 187 | int sshkey_parse_private_fileblob(struct sshbuf *buffer, |
190 | const char *passphrase, const char *filename, struct sshkey **keyp, | 188 | const char *passphrase, const char *filename, struct sshkey **keyp, |
191 | char **commentp); | 189 | char **commentp); |