xref: /netbsd-src/crypto/external/bsd/openssh/dist/ssherr.c (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1 /*	$OpenBSD: ssherr.c,v 1.7 2017/09/12 06:32:08 djm Exp $	*/
2 /*
3  * Copyright (c) 2011 Damien Miller
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 #include "includes.h"
18 __RCSID("$NetBSD: ssherr.c,v 1.7 2017/10/07 19:39:19 christos Exp $");
19 
20 #include <errno.h>
21 #include <stdio.h>
22 #include <string.h>
23 #include "ssherr.h"
24 
25 const char *
26 ssh_err(int n)
27 {
28 	switch (n) {
29 	case SSH_ERR_SUCCESS:
30 		return "success";
31 	case SSH_ERR_INTERNAL_ERROR:
32 		return "unexpected internal error";
33 	case SSH_ERR_ALLOC_FAIL:
34 		return "memory allocation failed";
35 	case SSH_ERR_MESSAGE_INCOMPLETE:
36 		return "incomplete message";
37 	case SSH_ERR_INVALID_FORMAT:
38 		return "invalid format";
39 	case SSH_ERR_BIGNUM_IS_NEGATIVE:
40 		return "bignum is negative";
41 	case SSH_ERR_STRING_TOO_LARGE:
42 		return "string is too large";
43 	case SSH_ERR_BIGNUM_TOO_LARGE:
44 		return "bignum is too large";
45 	case SSH_ERR_ECPOINT_TOO_LARGE:
46 		return "elliptic curve point is too large";
47 	case SSH_ERR_NO_BUFFER_SPACE:
48 		return "insufficient buffer space";
49 	case SSH_ERR_INVALID_ARGUMENT:
50 		return "invalid argument";
51 	case SSH_ERR_KEY_BITS_MISMATCH:
52 		return "key bits do not match";
53 	case SSH_ERR_EC_CURVE_INVALID:
54 		return "invalid elliptic curve";
55 	case SSH_ERR_KEY_TYPE_MISMATCH:
56 		return "key type does not match";
57 	case SSH_ERR_KEY_TYPE_UNKNOWN:
58 		return "unknown or unsupported key type";
59 	case SSH_ERR_EC_CURVE_MISMATCH:
60 		return "elliptic curve does not match";
61 	case SSH_ERR_EXPECTED_CERT:
62 		return "plain key provided where certificate required";
63 	case SSH_ERR_KEY_LACKS_CERTBLOB:
64 		return "key lacks certificate data";
65 	case SSH_ERR_KEY_CERT_UNKNOWN_TYPE:
66 		return "unknown/unsupported certificate type";
67 	case SSH_ERR_KEY_CERT_INVALID_SIGN_KEY:
68 		return "invalid certificate signing key";
69 	case SSH_ERR_KEY_INVALID_EC_VALUE:
70 		return "invalid elliptic curve value";
71 	case SSH_ERR_SIGNATURE_INVALID:
72 		return "incorrect signature";
73 	case SSH_ERR_LIBCRYPTO_ERROR:
74 		return "error in libcrypto";  /* XXX fetch and return */
75 	case SSH_ERR_UNEXPECTED_TRAILING_DATA:
76 		return "unexpected bytes remain after decoding";
77 	case SSH_ERR_SYSTEM_ERROR:
78 		return strerror(errno);
79 	case SSH_ERR_KEY_CERT_INVALID:
80 		return "invalid certificate";
81 	case SSH_ERR_AGENT_COMMUNICATION:
82 		return "communication with agent failed";
83 	case SSH_ERR_AGENT_FAILURE:
84 		return "agent refused operation";
85 	case SSH_ERR_DH_GEX_OUT_OF_RANGE:
86 		return "DH GEX group out of range";
87 	case SSH_ERR_DISCONNECTED:
88 		return "disconnected";
89 	case SSH_ERR_MAC_INVALID:
90 		return "message authentication code incorrect";
91 	case SSH_ERR_NO_CIPHER_ALG_MATCH:
92 		return "no matching cipher found";
93 	case SSH_ERR_NO_MAC_ALG_MATCH:
94 		return "no matching MAC found";
95 	case SSH_ERR_NO_COMPRESS_ALG_MATCH:
96 		return "no matching compression method found";
97 	case SSH_ERR_NO_KEX_ALG_MATCH:
98 		return "no matching key exchange method found";
99 	case SSH_ERR_NO_HOSTKEY_ALG_MATCH:
100 		return "no matching host key type found";
101 	case SSH_ERR_PROTOCOL_MISMATCH:
102 		return "protocol version mismatch";
103 	case SSH_ERR_NO_PROTOCOL_VERSION:
104 		return "could not read protocol version";
105 	case SSH_ERR_NO_HOSTKEY_LOADED:
106 		return "could not load host key";
107 	case SSH_ERR_NEED_REKEY:
108 		return "rekeying not supported by peer";
109 	case SSH_ERR_PASSPHRASE_TOO_SHORT:
110 		return "passphrase is too short (minimum five characters)";
111 	case SSH_ERR_FILE_CHANGED:
112 		return "file changed while reading";
113 	case SSH_ERR_KEY_UNKNOWN_CIPHER:
114 		return "key encrypted using unsupported cipher";
115 	case SSH_ERR_KEY_WRONG_PASSPHRASE:
116 		return "incorrect passphrase supplied to decrypt private key";
117 	case SSH_ERR_KEY_BAD_PERMISSIONS:
118 		return "bad permissions";
119 	case SSH_ERR_KEY_CERT_MISMATCH:
120 		return "certificate does not match key";
121 	case SSH_ERR_KEY_NOT_FOUND:
122 		return "key not found";
123 	case SSH_ERR_AGENT_NOT_PRESENT:
124 		return "agent not present";
125 	case SSH_ERR_AGENT_NO_IDENTITIES:
126 		return "agent contains no identities";
127 	case SSH_ERR_BUFFER_READ_ONLY:
128 		return "internal error: buffer is read-only";
129 	case SSH_ERR_KRL_BAD_MAGIC:
130 		return "KRL file has invalid magic number";
131 	case SSH_ERR_KEY_REVOKED:
132 		return "Key is revoked";
133 	case SSH_ERR_CONN_CLOSED:
134 		return "Connection closed";
135 	case SSH_ERR_CONN_TIMEOUT:
136 		return "Connection timed out";
137 	case SSH_ERR_CONN_CORRUPT:
138 		return "Connection corrupted";
139 	case SSH_ERR_PROTOCOL_ERROR:
140 		return "Protocol error";
141 	case SSH_ERR_KEY_LENGTH:
142 		return "Invalid key length";
143 	case SSH_ERR_NUMBER_TOO_LARGE:
144 		return "number is too large";
145 	default:
146 		{
147 			static char buf[1024];
148 			snprintf(buf, sizeof(buf), "unknown error %d", n);
149 			return buf;
150 		}
151 	}
152 }
153