summaryrefslogtreecommitdiff
path: root/key.c
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2015-08-19 14:23:51 +0100
committerColin Watson <cjwatson@debian.org>2015-08-19 16:48:11 +0100
commit0f0841b2d28b7463267d4d91577e72e3340a1d3a (patch)
treeba55fcd2b6e2cc22b30f5afb561dbb3da4c8b6c7 /key.c
parentf2a5f5dae656759efb0b76c3d94890b65c197a02 (diff)
parent8698446b972003b63dfe5dcbdb86acfe986afb85 (diff)
New upstream release (6.8p1).
Diffstat (limited to 'key.c')
-rw-r--r--key.c59
1 files changed, 3 insertions, 56 deletions
diff --git a/key.c b/key.c
index 206076159..bbe027b66 100644
--- a/key.c
+++ b/key.c
@@ -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
42u_char*
43key_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
60int 42int
61key_read(Key *ret, char **cpp) 43key_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
440Key *
441key_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
460int 421int
461key_perm_ok(int fd, const char *filename) 422key_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
466int
467key_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}