1296781Sdes/* $OpenBSD: ssherr.c,v 1.5 2015/09/13 14:39:16 tim Exp $ */ 2276707Sdes/* 3276707Sdes * Copyright (c) 2011 Damien Miller 4276707Sdes * 5276707Sdes * Permission to use, copy, modify, and distribute this software for any 6276707Sdes * purpose with or without fee is hereby granted, provided that the above 7276707Sdes * copyright notice and this permission notice appear in all copies. 8276707Sdes * 9276707Sdes * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10276707Sdes * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11276707Sdes * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12276707Sdes * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13276707Sdes * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14276707Sdes * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15276707Sdes * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16276707Sdes */ 17276707Sdes 18276707Sdes#include <errno.h> 19276707Sdes#include <string.h> 20276707Sdes#include "ssherr.h" 21276707Sdes 22276707Sdesconst char * 23276707Sdesssh_err(int n) 24276707Sdes{ 25276707Sdes switch (n) { 26276707Sdes case SSH_ERR_SUCCESS: 27276707Sdes return "success"; 28276707Sdes case SSH_ERR_INTERNAL_ERROR: 29276707Sdes return "unexpected internal error"; 30276707Sdes case SSH_ERR_ALLOC_FAIL: 31276707Sdes return "memory allocation failed"; 32276707Sdes case SSH_ERR_MESSAGE_INCOMPLETE: 33276707Sdes return "incomplete message"; 34276707Sdes case SSH_ERR_INVALID_FORMAT: 35276707Sdes return "invalid format"; 36276707Sdes case SSH_ERR_BIGNUM_IS_NEGATIVE: 37276707Sdes return "bignum is negative"; 38276707Sdes case SSH_ERR_STRING_TOO_LARGE: 39276707Sdes return "string is too large"; 40276707Sdes case SSH_ERR_BIGNUM_TOO_LARGE: 41276707Sdes return "bignum is too large"; 42276707Sdes case SSH_ERR_ECPOINT_TOO_LARGE: 43276707Sdes return "elliptic curve point is too large"; 44276707Sdes case SSH_ERR_NO_BUFFER_SPACE: 45276707Sdes return "insufficient buffer space"; 46276707Sdes case SSH_ERR_INVALID_ARGUMENT: 47276707Sdes return "invalid argument"; 48276707Sdes case SSH_ERR_KEY_BITS_MISMATCH: 49276707Sdes return "key bits do not match"; 50276707Sdes case SSH_ERR_EC_CURVE_INVALID: 51276707Sdes return "invalid elliptic curve"; 52276707Sdes case SSH_ERR_KEY_TYPE_MISMATCH: 53276707Sdes return "key type does not match"; 54276707Sdes case SSH_ERR_KEY_TYPE_UNKNOWN: 55276707Sdes return "unknown or unsupported key type"; 56276707Sdes case SSH_ERR_EC_CURVE_MISMATCH: 57276707Sdes return "elliptic curve does not match"; 58276707Sdes case SSH_ERR_EXPECTED_CERT: 59276707Sdes return "plain key provided where certificate required"; 60276707Sdes case SSH_ERR_KEY_LACKS_CERTBLOB: 61276707Sdes return "key lacks certificate data"; 62276707Sdes case SSH_ERR_KEY_CERT_UNKNOWN_TYPE: 63276707Sdes return "unknown/unsupported certificate type"; 64276707Sdes case SSH_ERR_KEY_CERT_INVALID_SIGN_KEY: 65276707Sdes return "invalid certificate signing key"; 66276707Sdes case SSH_ERR_KEY_INVALID_EC_VALUE: 67276707Sdes return "invalid elliptic curve value"; 68276707Sdes case SSH_ERR_SIGNATURE_INVALID: 69276707Sdes return "incorrect signature"; 70276707Sdes case SSH_ERR_LIBCRYPTO_ERROR: 71276707Sdes return "error in libcrypto"; /* XXX fetch and return */ 72276707Sdes case SSH_ERR_UNEXPECTED_TRAILING_DATA: 73276707Sdes return "unexpected bytes remain after decoding"; 74276707Sdes case SSH_ERR_SYSTEM_ERROR: 75276707Sdes return strerror(errno); 76276707Sdes case SSH_ERR_KEY_CERT_INVALID: 77276707Sdes return "invalid certificate"; 78276707Sdes case SSH_ERR_AGENT_COMMUNICATION: 79276707Sdes return "communication with agent failed"; 80276707Sdes case SSH_ERR_AGENT_FAILURE: 81276707Sdes return "agent refused operation"; 82276707Sdes case SSH_ERR_DH_GEX_OUT_OF_RANGE: 83276707Sdes return "DH GEX group out of range"; 84276707Sdes case SSH_ERR_DISCONNECTED: 85276707Sdes return "disconnected"; 86276707Sdes case SSH_ERR_MAC_INVALID: 87276707Sdes return "message authentication code incorrect"; 88276707Sdes case SSH_ERR_NO_CIPHER_ALG_MATCH: 89276707Sdes return "no matching cipher found"; 90276707Sdes case SSH_ERR_NO_MAC_ALG_MATCH: 91276707Sdes return "no matching MAC found"; 92276707Sdes case SSH_ERR_NO_COMPRESS_ALG_MATCH: 93276707Sdes return "no matching compression method found"; 94276707Sdes case SSH_ERR_NO_KEX_ALG_MATCH: 95276707Sdes return "no matching key exchange method found"; 96276707Sdes case SSH_ERR_NO_HOSTKEY_ALG_MATCH: 97276707Sdes return "no matching host key type found"; 98276707Sdes case SSH_ERR_PROTOCOL_MISMATCH: 99276707Sdes return "protocol version mismatch"; 100276707Sdes case SSH_ERR_NO_PROTOCOL_VERSION: 101276707Sdes return "could not read protocol version"; 102276707Sdes case SSH_ERR_NO_HOSTKEY_LOADED: 103276707Sdes return "could not load host key"; 104276707Sdes case SSH_ERR_NEED_REKEY: 105276707Sdes return "rekeying not supported by peer"; 106276707Sdes case SSH_ERR_PASSPHRASE_TOO_SHORT: 107296781Sdes return "passphrase is too short (minimum five characters)"; 108276707Sdes case SSH_ERR_FILE_CHANGED: 109276707Sdes return "file changed while reading"; 110276707Sdes case SSH_ERR_KEY_UNKNOWN_CIPHER: 111276707Sdes return "key encrypted using unsupported cipher"; 112276707Sdes case SSH_ERR_KEY_WRONG_PASSPHRASE: 113276707Sdes return "incorrect passphrase supplied to decrypt private key"; 114276707Sdes case SSH_ERR_KEY_BAD_PERMISSIONS: 115276707Sdes return "bad permissions"; 116276707Sdes case SSH_ERR_KEY_CERT_MISMATCH: 117276707Sdes return "certificate does not match key"; 118276707Sdes case SSH_ERR_KEY_NOT_FOUND: 119276707Sdes return "key not found"; 120276707Sdes case SSH_ERR_AGENT_NOT_PRESENT: 121276707Sdes return "agent not present"; 122276707Sdes case SSH_ERR_AGENT_NO_IDENTITIES: 123276707Sdes return "agent contains no identities"; 124295367Sdes case SSH_ERR_BUFFER_READ_ONLY: 125295367Sdes return "internal error: buffer is read-only"; 126276707Sdes case SSH_ERR_KRL_BAD_MAGIC: 127276707Sdes return "KRL file has invalid magic number"; 128276707Sdes case SSH_ERR_KEY_REVOKED: 129276707Sdes return "Key is revoked"; 130295367Sdes case SSH_ERR_CONN_CLOSED: 131295367Sdes return "Connection closed"; 132295367Sdes case SSH_ERR_CONN_TIMEOUT: 133295367Sdes return "Connection timed out"; 134295367Sdes case SSH_ERR_CONN_CORRUPT: 135295367Sdes return "Connection corrupted"; 136295367Sdes case SSH_ERR_PROTOCOL_ERROR: 137295367Sdes return "Protocol error"; 138276707Sdes default: 139276707Sdes return "unknown error"; 140276707Sdes } 141276707Sdes} 142