xref: /dflybsd-src/crypto/openssh/ssherr.c (revision 0cbfa66cdb87e23928a110d9b02839f403e32c11)
1*0cbfa66cSDaniel Fojt /*	$OpenBSD: ssherr.c,v 1.10 2020/01/25 23:13:09 djm Exp $	*/
236e94dc5SPeter Avalos /*
336e94dc5SPeter Avalos  * Copyright (c) 2011 Damien Miller
436e94dc5SPeter Avalos  *
536e94dc5SPeter Avalos  * Permission to use, copy, modify, and distribute this software for any
636e94dc5SPeter Avalos  * purpose with or without fee is hereby granted, provided that the above
736e94dc5SPeter Avalos  * copyright notice and this permission notice appear in all copies.
836e94dc5SPeter Avalos  *
936e94dc5SPeter Avalos  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1036e94dc5SPeter Avalos  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1136e94dc5SPeter Avalos  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1236e94dc5SPeter Avalos  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1336e94dc5SPeter Avalos  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1436e94dc5SPeter Avalos  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1536e94dc5SPeter Avalos  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1636e94dc5SPeter Avalos  */
1736e94dc5SPeter Avalos 
1836e94dc5SPeter Avalos #include <errno.h>
1936e94dc5SPeter Avalos #include <string.h>
2036e94dc5SPeter Avalos #include "ssherr.h"
2136e94dc5SPeter Avalos 
2236e94dc5SPeter Avalos const char *
ssh_err(int n)2336e94dc5SPeter Avalos ssh_err(int n)
2436e94dc5SPeter Avalos {
2536e94dc5SPeter Avalos 	switch (n) {
2636e94dc5SPeter Avalos 	case SSH_ERR_SUCCESS:
2736e94dc5SPeter Avalos 		return "success";
2836e94dc5SPeter Avalos 	case SSH_ERR_INTERNAL_ERROR:
2936e94dc5SPeter Avalos 		return "unexpected internal error";
3036e94dc5SPeter Avalos 	case SSH_ERR_ALLOC_FAIL:
3136e94dc5SPeter Avalos 		return "memory allocation failed";
3236e94dc5SPeter Avalos 	case SSH_ERR_MESSAGE_INCOMPLETE:
3336e94dc5SPeter Avalos 		return "incomplete message";
3436e94dc5SPeter Avalos 	case SSH_ERR_INVALID_FORMAT:
3536e94dc5SPeter Avalos 		return "invalid format";
3636e94dc5SPeter Avalos 	case SSH_ERR_BIGNUM_IS_NEGATIVE:
3736e94dc5SPeter Avalos 		return "bignum is negative";
3836e94dc5SPeter Avalos 	case SSH_ERR_STRING_TOO_LARGE:
3936e94dc5SPeter Avalos 		return "string is too large";
4036e94dc5SPeter Avalos 	case SSH_ERR_BIGNUM_TOO_LARGE:
4136e94dc5SPeter Avalos 		return "bignum is too large";
4236e94dc5SPeter Avalos 	case SSH_ERR_ECPOINT_TOO_LARGE:
4336e94dc5SPeter Avalos 		return "elliptic curve point is too large";
4436e94dc5SPeter Avalos 	case SSH_ERR_NO_BUFFER_SPACE:
4536e94dc5SPeter Avalos 		return "insufficient buffer space";
4636e94dc5SPeter Avalos 	case SSH_ERR_INVALID_ARGUMENT:
4736e94dc5SPeter Avalos 		return "invalid argument";
4836e94dc5SPeter Avalos 	case SSH_ERR_KEY_BITS_MISMATCH:
4936e94dc5SPeter Avalos 		return "key bits do not match";
5036e94dc5SPeter Avalos 	case SSH_ERR_EC_CURVE_INVALID:
5136e94dc5SPeter Avalos 		return "invalid elliptic curve";
5236e94dc5SPeter Avalos 	case SSH_ERR_KEY_TYPE_MISMATCH:
5336e94dc5SPeter Avalos 		return "key type does not match";
5436e94dc5SPeter Avalos 	case SSH_ERR_KEY_TYPE_UNKNOWN:
5536e94dc5SPeter Avalos 		return "unknown or unsupported key type";
5636e94dc5SPeter Avalos 	case SSH_ERR_EC_CURVE_MISMATCH:
5736e94dc5SPeter Avalos 		return "elliptic curve does not match";
5836e94dc5SPeter Avalos 	case SSH_ERR_EXPECTED_CERT:
5936e94dc5SPeter Avalos 		return "plain key provided where certificate required";
6036e94dc5SPeter Avalos 	case SSH_ERR_KEY_LACKS_CERTBLOB:
6136e94dc5SPeter Avalos 		return "key lacks certificate data";
6236e94dc5SPeter Avalos 	case SSH_ERR_KEY_CERT_UNKNOWN_TYPE:
6336e94dc5SPeter Avalos 		return "unknown/unsupported certificate type";
6436e94dc5SPeter Avalos 	case SSH_ERR_KEY_CERT_INVALID_SIGN_KEY:
6536e94dc5SPeter Avalos 		return "invalid certificate signing key";
6636e94dc5SPeter Avalos 	case SSH_ERR_KEY_INVALID_EC_VALUE:
6736e94dc5SPeter Avalos 		return "invalid elliptic curve value";
6836e94dc5SPeter Avalos 	case SSH_ERR_SIGNATURE_INVALID:
6936e94dc5SPeter Avalos 		return "incorrect signature";
7036e94dc5SPeter Avalos 	case SSH_ERR_LIBCRYPTO_ERROR:
7136e94dc5SPeter Avalos 		return "error in libcrypto";  /* XXX fetch and return */
7236e94dc5SPeter Avalos 	case SSH_ERR_UNEXPECTED_TRAILING_DATA:
7336e94dc5SPeter Avalos 		return "unexpected bytes remain after decoding";
7436e94dc5SPeter Avalos 	case SSH_ERR_SYSTEM_ERROR:
7536e94dc5SPeter Avalos 		return strerror(errno);
7636e94dc5SPeter Avalos 	case SSH_ERR_KEY_CERT_INVALID:
7736e94dc5SPeter Avalos 		return "invalid certificate";
7836e94dc5SPeter Avalos 	case SSH_ERR_AGENT_COMMUNICATION:
7936e94dc5SPeter Avalos 		return "communication with agent failed";
8036e94dc5SPeter Avalos 	case SSH_ERR_AGENT_FAILURE:
8136e94dc5SPeter Avalos 		return "agent refused operation";
8236e94dc5SPeter Avalos 	case SSH_ERR_DH_GEX_OUT_OF_RANGE:
8336e94dc5SPeter Avalos 		return "DH GEX group out of range";
8436e94dc5SPeter Avalos 	case SSH_ERR_DISCONNECTED:
8536e94dc5SPeter Avalos 		return "disconnected";
8636e94dc5SPeter Avalos 	case SSH_ERR_MAC_INVALID:
8736e94dc5SPeter Avalos 		return "message authentication code incorrect";
8836e94dc5SPeter Avalos 	case SSH_ERR_NO_CIPHER_ALG_MATCH:
8936e94dc5SPeter Avalos 		return "no matching cipher found";
9036e94dc5SPeter Avalos 	case SSH_ERR_NO_MAC_ALG_MATCH:
9136e94dc5SPeter Avalos 		return "no matching MAC found";
9236e94dc5SPeter Avalos 	case SSH_ERR_NO_COMPRESS_ALG_MATCH:
9336e94dc5SPeter Avalos 		return "no matching compression method found";
9436e94dc5SPeter Avalos 	case SSH_ERR_NO_KEX_ALG_MATCH:
9536e94dc5SPeter Avalos 		return "no matching key exchange method found";
9636e94dc5SPeter Avalos 	case SSH_ERR_NO_HOSTKEY_ALG_MATCH:
9736e94dc5SPeter Avalos 		return "no matching host key type found";
9836e94dc5SPeter Avalos 	case SSH_ERR_PROTOCOL_MISMATCH:
9936e94dc5SPeter Avalos 		return "protocol version mismatch";
10036e94dc5SPeter Avalos 	case SSH_ERR_NO_PROTOCOL_VERSION:
10136e94dc5SPeter Avalos 		return "could not read protocol version";
10236e94dc5SPeter Avalos 	case SSH_ERR_NO_HOSTKEY_LOADED:
10336e94dc5SPeter Avalos 		return "could not load host key";
10436e94dc5SPeter Avalos 	case SSH_ERR_NEED_REKEY:
10536e94dc5SPeter Avalos 		return "rekeying not supported by peer";
10636e94dc5SPeter Avalos 	case SSH_ERR_PASSPHRASE_TOO_SHORT:
107e9778795SPeter Avalos 		return "passphrase is too short (minimum five characters)";
10836e94dc5SPeter Avalos 	case SSH_ERR_FILE_CHANGED:
10936e94dc5SPeter Avalos 		return "file changed while reading";
11036e94dc5SPeter Avalos 	case SSH_ERR_KEY_UNKNOWN_CIPHER:
11136e94dc5SPeter Avalos 		return "key encrypted using unsupported cipher";
11236e94dc5SPeter Avalos 	case SSH_ERR_KEY_WRONG_PASSPHRASE:
11336e94dc5SPeter Avalos 		return "incorrect passphrase supplied to decrypt private key";
11436e94dc5SPeter Avalos 	case SSH_ERR_KEY_BAD_PERMISSIONS:
11536e94dc5SPeter Avalos 		return "bad permissions";
11636e94dc5SPeter Avalos 	case SSH_ERR_KEY_CERT_MISMATCH:
11736e94dc5SPeter Avalos 		return "certificate does not match key";
11836e94dc5SPeter Avalos 	case SSH_ERR_KEY_NOT_FOUND:
11936e94dc5SPeter Avalos 		return "key not found";
12036e94dc5SPeter Avalos 	case SSH_ERR_AGENT_NOT_PRESENT:
12136e94dc5SPeter Avalos 		return "agent not present";
12236e94dc5SPeter Avalos 	case SSH_ERR_AGENT_NO_IDENTITIES:
12336e94dc5SPeter Avalos 		return "agent contains no identities";
124e9778795SPeter Avalos 	case SSH_ERR_BUFFER_READ_ONLY:
125e9778795SPeter Avalos 		return "internal error: buffer is read-only";
12636e94dc5SPeter Avalos 	case SSH_ERR_KRL_BAD_MAGIC:
12736e94dc5SPeter Avalos 		return "KRL file has invalid magic number";
12836e94dc5SPeter Avalos 	case SSH_ERR_KEY_REVOKED:
12936e94dc5SPeter Avalos 		return "Key is revoked";
130e9778795SPeter Avalos 	case SSH_ERR_CONN_CLOSED:
131e9778795SPeter Avalos 		return "Connection closed";
132e9778795SPeter Avalos 	case SSH_ERR_CONN_TIMEOUT:
133e9778795SPeter Avalos 		return "Connection timed out";
134e9778795SPeter Avalos 	case SSH_ERR_CONN_CORRUPT:
135e9778795SPeter Avalos 		return "Connection corrupted";
136e9778795SPeter Avalos 	case SSH_ERR_PROTOCOL_ERROR:
137e9778795SPeter Avalos 		return "Protocol error";
138ce74bacaSMatthew Dillon 	case SSH_ERR_KEY_LENGTH:
139ce74bacaSMatthew Dillon 		return "Invalid key length";
140ce74bacaSMatthew Dillon 	case SSH_ERR_NUMBER_TOO_LARGE:
141ce74bacaSMatthew Dillon 		return "number is too large";
142664f4763Szrj 	case SSH_ERR_SIGN_ALG_UNSUPPORTED:
143664f4763Szrj 		return "signature algorithm not supported";
144*0cbfa66cSDaniel Fojt 	case SSH_ERR_FEATURE_UNSUPPORTED:
145*0cbfa66cSDaniel Fojt 		return "requested feature not supported";
146*0cbfa66cSDaniel Fojt 	case SSH_ERR_DEVICE_NOT_FOUND:
147*0cbfa66cSDaniel Fojt 		return "device not found";
14836e94dc5SPeter Avalos 	default:
14936e94dc5SPeter Avalos 		return "unknown error";
15036e94dc5SPeter Avalos 	}
15136e94dc5SPeter Avalos }
152