diff options
Diffstat (limited to 'key.c')
-rw-r--r-- | key.c | 59 |
1 files changed, 3 insertions, 56 deletions
@@ -1,15 +1,15 @@ | |||
1 | /* $OpenBSD: key.c,v 1.122 2014/07/22 01:18:50 dtucker Exp $ */ | 1 | /* $OpenBSD: key.c,v 1.127 2015/01/28 22:36:00 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * placed in the public domain | 3 | * placed in the public domain |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #include "includes.h" | 6 | #include "includes.h" |
7 | 7 | ||
8 | #include <sys/param.h> | ||
9 | #include <sys/types.h> | 8 | #include <sys/types.h> |
10 | #include <errno.h> | 9 | #include <errno.h> |
11 | #include <stdarg.h> | 10 | #include <stdarg.h> |
12 | #include <stdio.h> | 11 | #include <stdio.h> |
12 | #include <limits.h> | ||
13 | 13 | ||
14 | #define SSH_KEY_NO_DEFINE | 14 | #define SSH_KEY_NO_DEFINE |
15 | #include "key.h" | 15 | #include "key.h" |
@@ -39,24 +39,6 @@ key_new_private(int type) | |||
39 | return ret; | 39 | return ret; |
40 | } | 40 | } |
41 | 41 | ||
42 | u_char* | ||
43 | key_fingerprint_raw(const Key *k, enum fp_type dgst_type, | ||
44 | u_int *dgst_raw_length) | ||
45 | { | ||
46 | u_char *ret = NULL; | ||
47 | size_t dlen; | ||
48 | int r; | ||
49 | |||
50 | if (dgst_raw_length != NULL) | ||
51 | *dgst_raw_length = 0; | ||
52 | if ((r = sshkey_fingerprint_raw(k, dgst_type, &ret, &dlen)) != 0) | ||
53 | fatal("%s: %s", __func__, ssh_err(r)); | ||
54 | if (dlen > INT_MAX) | ||
55 | fatal("%s: giant len %zu", __func__, dlen); | ||
56 | *dgst_raw_length = dlen; | ||
57 | return ret; | ||
58 | } | ||
59 | |||
60 | int | 42 | int |
61 | key_read(Key *ret, char **cpp) | 43 | key_read(Key *ret, char **cpp) |
62 | { | 44 | { |
@@ -329,7 +311,7 @@ key_load_file(int fd, const char *filename, struct sshbuf *blob) | |||
329 | { | 311 | { |
330 | int r; | 312 | int r; |
331 | 313 | ||
332 | if ((r = sshkey_load_file(fd, filename, blob)) != 0) { | 314 | if ((r = sshkey_load_file(fd, blob)) != 0) { |
333 | fatal_on_fatal_errors(r, __func__, SSH_ERR_LIBCRYPTO_ERROR); | 315 | fatal_on_fatal_errors(r, __func__, SSH_ERR_LIBCRYPTO_ERROR); |
334 | error("%s: %s", __func__, ssh_err(r)); | 316 | error("%s: %s", __func__, ssh_err(r)); |
335 | return 0; | 317 | return 0; |
@@ -436,44 +418,9 @@ key_load_private_type(int type, const char *filename, const char *passphrase, | |||
436 | return ret; | 418 | return ret; |
437 | } | 419 | } |
438 | 420 | ||
439 | #ifdef WITH_OPENSSL | ||
440 | Key * | ||
441 | key_load_private_pem(int fd, int type, const char *passphrase, | ||
442 | char **commentp) | ||
443 | { | ||
444 | int r; | ||
445 | Key *ret = NULL; | ||
446 | |||
447 | if ((r = sshkey_load_private_pem(fd, type, passphrase, | ||
448 | &ret, commentp)) != 0) { | ||
449 | fatal_on_fatal_errors(r, __func__, SSH_ERR_LIBCRYPTO_ERROR); | ||
450 | if (r == SSH_ERR_KEY_WRONG_PASSPHRASE) | ||
451 | debug("%s: %s", __func__, ssh_err(r)); | ||
452 | else | ||
453 | error("%s: %s", __func__, ssh_err(r)); | ||
454 | return NULL; | ||
455 | } | ||
456 | return ret; | ||
457 | } | ||
458 | #endif /* WITH_OPENSSL */ | ||
459 | |||
460 | int | 421 | int |
461 | key_perm_ok(int fd, const char *filename) | 422 | key_perm_ok(int fd, const char *filename) |
462 | { | 423 | { |
463 | return sshkey_perm_ok(fd, filename) == 0 ? 1 : 0; | 424 | return sshkey_perm_ok(fd, filename) == 0 ? 1 : 0; |
464 | } | 425 | } |
465 | 426 | ||
466 | int | ||
467 | key_in_file(Key *key, const char *filename, int strict_type) | ||
468 | { | ||
469 | int r; | ||
470 | |||
471 | if ((r = sshkey_in_file(key, filename, strict_type)) != 0) { | ||
472 | fatal_on_fatal_errors(r, __func__, SSH_ERR_LIBCRYPTO_ERROR); | ||
473 | if (r == SSH_ERR_SYSTEM_ERROR && errno == ENOENT) | ||
474 | return 0; | ||
475 | error("%s: %s", __func__, ssh_err(r)); | ||
476 | return r == SSH_ERR_KEY_NOT_FOUND ? 0 : -1; | ||
477 | } | ||
478 | return 1; | ||
479 | } | ||