ssherr.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /* $OpenBSD: ssherr.c,v 1.10 2020/01/25 23:13:09 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 <errno.h>
  18. #include <string.h>
  19. #include "ssherr.h"
  20. const char *
  21. ssh_err(int n)
  22. {
  23. switch (n) {
  24. case SSH_ERR_SUCCESS:
  25. return "success";
  26. case SSH_ERR_INTERNAL_ERROR:
  27. return "unexpected internal error";
  28. case SSH_ERR_ALLOC_FAIL:
  29. return "memory allocation failed";
  30. case SSH_ERR_MESSAGE_INCOMPLETE:
  31. return "incomplete message";
  32. case SSH_ERR_INVALID_FORMAT:
  33. return "invalid format";
  34. case SSH_ERR_BIGNUM_IS_NEGATIVE:
  35. return "bignum is negative";
  36. case SSH_ERR_STRING_TOO_LARGE:
  37. return "string is too large";
  38. case SSH_ERR_BIGNUM_TOO_LARGE:
  39. return "bignum is too large";
  40. case SSH_ERR_ECPOINT_TOO_LARGE:
  41. return "elliptic curve point is too large";
  42. case SSH_ERR_NO_BUFFER_SPACE:
  43. return "insufficient buffer space";
  44. case SSH_ERR_INVALID_ARGUMENT:
  45. return "invalid argument";
  46. case SSH_ERR_KEY_BITS_MISMATCH:
  47. return "key bits do not match";
  48. case SSH_ERR_EC_CURVE_INVALID:
  49. return "invalid elliptic curve";
  50. case SSH_ERR_KEY_TYPE_MISMATCH:
  51. return "key type does not match";
  52. case SSH_ERR_KEY_TYPE_UNKNOWN:
  53. return "unknown or unsupported key type";
  54. case SSH_ERR_EC_CURVE_MISMATCH:
  55. return "elliptic curve does not match";
  56. case SSH_ERR_EXPECTED_CERT:
  57. return "plain key provided where certificate required";
  58. case SSH_ERR_KEY_LACKS_CERTBLOB:
  59. return "key lacks certificate data";
  60. case SSH_ERR_KEY_CERT_UNKNOWN_TYPE:
  61. return "unknown/unsupported certificate type";
  62. case SSH_ERR_KEY_CERT_INVALID_SIGN_KEY:
  63. return "invalid certificate signing key";
  64. case SSH_ERR_KEY_INVALID_EC_VALUE:
  65. return "invalid elliptic curve value";
  66. case SSH_ERR_SIGNATURE_INVALID:
  67. return "incorrect signature";
  68. case SSH_ERR_LIBCRYPTO_ERROR:
  69. return "error in libcrypto"; /* XXX fetch and return */
  70. case SSH_ERR_UNEXPECTED_TRAILING_DATA:
  71. return "unexpected bytes remain after decoding";
  72. case SSH_ERR_SYSTEM_ERROR:
  73. return strerror(errno);
  74. case SSH_ERR_KEY_CERT_INVALID:
  75. return "invalid certificate";
  76. case SSH_ERR_AGENT_COMMUNICATION:
  77. return "communication with agent failed";
  78. case SSH_ERR_AGENT_FAILURE:
  79. return "agent refused operation";
  80. case SSH_ERR_DH_GEX_OUT_OF_RANGE:
  81. return "DH GEX group out of range";
  82. case SSH_ERR_DISCONNECTED:
  83. return "disconnected";
  84. case SSH_ERR_MAC_INVALID:
  85. return "message authentication code incorrect";
  86. case SSH_ERR_NO_CIPHER_ALG_MATCH:
  87. return "no matching cipher found";
  88. case SSH_ERR_NO_MAC_ALG_MATCH:
  89. return "no matching MAC found";
  90. case SSH_ERR_NO_COMPRESS_ALG_MATCH:
  91. return "no matching compression method found";
  92. case SSH_ERR_NO_KEX_ALG_MATCH:
  93. return "no matching key exchange method found";
  94. case SSH_ERR_NO_HOSTKEY_ALG_MATCH:
  95. return "no matching host key type found";
  96. case SSH_ERR_PROTOCOL_MISMATCH:
  97. return "protocol version mismatch";
  98. case SSH_ERR_NO_PROTOCOL_VERSION:
  99. return "could not read protocol version";
  100. case SSH_ERR_NO_HOSTKEY_LOADED:
  101. return "could not load host key";
  102. case SSH_ERR_NEED_REKEY:
  103. return "rekeying not supported by peer";
  104. case SSH_ERR_PASSPHRASE_TOO_SHORT:
  105. return "passphrase is too short (minimum five characters)";
  106. case SSH_ERR_FILE_CHANGED:
  107. return "file changed while reading";
  108. case SSH_ERR_KEY_UNKNOWN_CIPHER:
  109. return "key encrypted using unsupported cipher";
  110. case SSH_ERR_KEY_WRONG_PASSPHRASE:
  111. return "incorrect passphrase supplied to decrypt private key";
  112. case SSH_ERR_KEY_BAD_PERMISSIONS:
  113. return "bad permissions";
  114. case SSH_ERR_KEY_CERT_MISMATCH:
  115. return "certificate does not match key";
  116. case SSH_ERR_KEY_NOT_FOUND:
  117. return "key not found";
  118. case SSH_ERR_AGENT_NOT_PRESENT:
  119. return "agent not present";
  120. case SSH_ERR_AGENT_NO_IDENTITIES:
  121. return "agent contains no identities";
  122. case SSH_ERR_BUFFER_READ_ONLY:
  123. return "internal error: buffer is read-only";
  124. case SSH_ERR_KRL_BAD_MAGIC:
  125. return "KRL file has invalid magic number";
  126. case SSH_ERR_KEY_REVOKED:
  127. return "Key is revoked";
  128. case SSH_ERR_CONN_CLOSED:
  129. return "Connection closed";
  130. case SSH_ERR_CONN_TIMEOUT:
  131. return "Connection timed out";
  132. case SSH_ERR_CONN_CORRUPT:
  133. return "Connection corrupted";
  134. case SSH_ERR_PROTOCOL_ERROR:
  135. return "Protocol error";
  136. case SSH_ERR_KEY_LENGTH:
  137. return "Invalid key length";
  138. case SSH_ERR_NUMBER_TOO_LARGE:
  139. return "number is too large";
  140. case SSH_ERR_SIGN_ALG_UNSUPPORTED:
  141. return "signature algorithm not supported";
  142. case SSH_ERR_FEATURE_UNSUPPORTED:
  143. return "requested feature not supported";
  144. case SSH_ERR_DEVICE_NOT_FOUND:
  145. return "device not found";
  146. default:
  147. return "unknown error";
  148. }
  149. }