Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Error message information |
| 3 | * |
| 4 | * Copyright (C) 2006-2010, Brainspark B.V. |
| 5 | * |
| 6 | * This file is part of PolarSSL (http://www.polarssl.org) |
| 7 | * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> |
| 8 | * |
| 9 | * All rights reserved. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along |
| 22 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 23 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 24 | */ |
| 25 | |
| 26 | #include "polarssl/config.h" |
| 27 | |
| 28 | #if defined(POLARSSL_ERROR_C) |
| 29 | |
| 30 | #if defined(POLARSSL_AES_C) |
| 31 | #include "polarssl/aes.h" |
| 32 | #endif |
| 33 | |
| 34 | #if defined(POLARSSL_BASE64_C) |
| 35 | #include "polarssl/base64.h" |
| 36 | #endif |
| 37 | |
| 38 | #if defined(POLARSSL_BIGNUM_C) |
| 39 | #include "polarssl/bignum.h" |
| 40 | #endif |
| 41 | |
| 42 | #if defined(POLARSSL_CAMELLIA_C) |
| 43 | #include "polarssl/camellia.h" |
| 44 | #endif |
| 45 | |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame] | 46 | #if defined(POLARSSL_CIPHER_C) |
| 47 | #include "polarssl/cipher.h" |
| 48 | #endif |
| 49 | |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 50 | #if defined(POLARSSL_DES_C) |
| 51 | #include "polarssl/des.h" |
| 52 | #endif |
| 53 | |
| 54 | #if defined(POLARSSL_DHM_C) |
| 55 | #include "polarssl/dhm.h" |
| 56 | #endif |
| 57 | |
| 58 | #if defined(POLARSSL_MD_C) |
| 59 | #include "polarssl/md.h" |
| 60 | #endif |
| 61 | |
| 62 | #if defined(POLARSSL_NET_C) |
| 63 | #include "polarssl/net.h" |
| 64 | #endif |
| 65 | |
| 66 | #if defined(POLARSSL_PADLOCK_C) |
| 67 | #include "polarssl/padlock.h" |
| 68 | #endif |
| 69 | |
| 70 | #if defined(POLARSSL_PEM_C) |
| 71 | #include "polarssl/pem.h" |
| 72 | #endif |
| 73 | |
| 74 | #if defined(POLARSSL_RSA_C) |
| 75 | #include "polarssl/rsa.h" |
| 76 | #endif |
| 77 | |
Paul Bakker | 831a755 | 2011-05-18 13:32:51 +0000 | [diff] [blame] | 78 | #if defined(POLARSSL_SSL_TLS_C) |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 79 | #include "polarssl/ssl.h" |
| 80 | #endif |
| 81 | |
| 82 | #if defined(POLARSSL_X509_PARSE_C) |
| 83 | #include "polarssl/x509.h" |
| 84 | #endif |
| 85 | |
| 86 | #if defined(POLARSSL_XTEA_C) |
| 87 | #include "polarssl/xtea.h" |
| 88 | #endif |
| 89 | |
| 90 | |
| 91 | #include <string.h> |
| 92 | |
Paul Bakker | dceecd8 | 2011-11-15 16:38:34 +0000 | [diff] [blame] | 93 | #if defined _MSC_VER && !defined snprintf |
| 94 | #define snprintf _snprintf |
| 95 | #endif |
| 96 | |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 97 | void error_strerror( int ret, char *buf, size_t buflen ) |
| 98 | { |
| 99 | size_t len; |
| 100 | int use_ret; |
| 101 | |
| 102 | memset( buf, 0x00, buflen ); |
| 103 | |
| 104 | if( ret < 0 ) |
| 105 | ret = -ret; |
| 106 | |
| 107 | if( ret & 0xFF80 ) |
| 108 | { |
| 109 | use_ret = ret & 0xFF80; |
| 110 | |
| 111 | // High level error codes |
| 112 | // |
Paul Bakker | ff61a78 | 2011-06-09 15:42:02 +0000 | [diff] [blame] | 113 | #if defined(POLARSSL_CIPHER_C) |
| 114 | if( use_ret == -(POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE) ) |
| 115 | snprintf( buf, buflen, "CIPHER - The selected feature is not available" ); |
| 116 | if( use_ret == -(POLARSSL_ERR_CIPHER_BAD_INPUT_DATA) ) |
| 117 | snprintf( buf, buflen, "CIPHER - Bad input parameters to function" ); |
| 118 | if( use_ret == -(POLARSSL_ERR_CIPHER_ALLOC_FAILED) ) |
| 119 | snprintf( buf, buflen, "CIPHER - Failed to allocate memory" ); |
| 120 | if( use_ret == -(POLARSSL_ERR_CIPHER_INVALID_PADDING) ) |
| 121 | snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" ); |
| 122 | if( use_ret == -(POLARSSL_ERR_CIPHER_FULL_BLOCK_EXPECTED) ) |
| 123 | snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" ); |
| 124 | #endif /* POLARSSL_CIPHER_C */ |
| 125 | |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 126 | #if defined(POLARSSL_DHM_C) |
| 127 | if( use_ret == -(POLARSSL_ERR_DHM_BAD_INPUT_DATA) ) |
| 128 | snprintf( buf, buflen, "DHM - Bad input parameters to function" ); |
| 129 | if( use_ret == -(POLARSSL_ERR_DHM_READ_PARAMS_FAILED) ) |
| 130 | snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" ); |
| 131 | if( use_ret == -(POLARSSL_ERR_DHM_MAKE_PARAMS_FAILED) ) |
| 132 | snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" ); |
| 133 | if( use_ret == -(POLARSSL_ERR_DHM_READ_PUBLIC_FAILED) ) |
| 134 | snprintf( buf, buflen, "DHM - Reading of the public values failed" ); |
| 135 | if( use_ret == -(POLARSSL_ERR_DHM_MAKE_PUBLIC_FAILED) ) |
| 136 | snprintf( buf, buflen, "DHM - Makeing of the public value failed" ); |
| 137 | if( use_ret == -(POLARSSL_ERR_DHM_CALC_SECRET_FAILED) ) |
| 138 | snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" ); |
| 139 | #endif /* POLARSSL_DHM_C */ |
| 140 | |
| 141 | #if defined(POLARSSL_MD_C) |
| 142 | if( use_ret == -(POLARSSL_ERR_MD_FEATURE_UNAVAILABLE) ) |
| 143 | snprintf( buf, buflen, "MD - The selected feature is not available" ); |
Paul Bakker | 9c021ad | 2011-06-09 15:55:11 +0000 | [diff] [blame] | 144 | if( use_ret == -(POLARSSL_ERR_MD_BAD_INPUT_DATA) ) |
| 145 | snprintf( buf, buflen, "MD - Bad input parameters to function" ); |
| 146 | if( use_ret == -(POLARSSL_ERR_MD_ALLOC_FAILED) ) |
| 147 | snprintf( buf, buflen, "MD - Failed to allocate memory" ); |
| 148 | if( use_ret == -(POLARSSL_ERR_MD_FILE_OPEN_FAILED) ) |
| 149 | snprintf( buf, buflen, "MD - Opening of file failed" ); |
| 150 | if( use_ret == -(POLARSSL_ERR_MD_FILE_READ_FAILED) ) |
| 151 | snprintf( buf, buflen, "MD - Failure when reading from file" ); |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 152 | #endif /* POLARSSL_MD_C */ |
| 153 | |
| 154 | #if defined(POLARSSL_PEM_C) |
| 155 | if( use_ret == -(POLARSSL_ERR_PEM_NO_HEADER_PRESENT) ) |
| 156 | snprintf( buf, buflen, "PEM - No PEM header found" ); |
| 157 | if( use_ret == -(POLARSSL_ERR_PEM_INVALID_DATA) ) |
| 158 | snprintf( buf, buflen, "PEM - PEM string is not as expected" ); |
| 159 | if( use_ret == -(POLARSSL_ERR_PEM_MALLOC_FAILED) ) |
| 160 | snprintf( buf, buflen, "PEM - Failed to allocate memory" ); |
| 161 | if( use_ret == -(POLARSSL_ERR_PEM_INVALID_ENC_IV) ) |
| 162 | snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" ); |
| 163 | if( use_ret == -(POLARSSL_ERR_PEM_UNKNOWN_ENC_ALG) ) |
| 164 | snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" ); |
| 165 | if( use_ret == -(POLARSSL_ERR_PEM_PASSWORD_REQUIRED) ) |
| 166 | snprintf( buf, buflen, "PEM - Private key password can't be empty" ); |
| 167 | if( use_ret == -(POLARSSL_ERR_PEM_PASSWORD_MISMATCH) ) |
| 168 | snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" ); |
| 169 | if( use_ret == -(POLARSSL_ERR_PEM_FEATURE_UNAVAILABLE) ) |
| 170 | snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" ); |
| 171 | #endif /* POLARSSL_PEM_C */ |
| 172 | |
| 173 | #if defined(POLARSSL_RSA_C) |
| 174 | if( use_ret == -(POLARSSL_ERR_RSA_BAD_INPUT_DATA) ) |
| 175 | snprintf( buf, buflen, "RSA - Bad input parameters to function" ); |
| 176 | if( use_ret == -(POLARSSL_ERR_RSA_INVALID_PADDING) ) |
| 177 | snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" ); |
| 178 | if( use_ret == -(POLARSSL_ERR_RSA_KEY_GEN_FAILED) ) |
| 179 | snprintf( buf, buflen, "RSA - Something failed during generation of a key" ); |
| 180 | if( use_ret == -(POLARSSL_ERR_RSA_KEY_CHECK_FAILED) ) |
| 181 | snprintf( buf, buflen, "RSA - Key failed to pass the libraries validity check" ); |
| 182 | if( use_ret == -(POLARSSL_ERR_RSA_PUBLIC_FAILED) ) |
| 183 | snprintf( buf, buflen, "RSA - The public key operation failed" ); |
| 184 | if( use_ret == -(POLARSSL_ERR_RSA_PRIVATE_FAILED) ) |
| 185 | snprintf( buf, buflen, "RSA - The private key operation failed" ); |
| 186 | if( use_ret == -(POLARSSL_ERR_RSA_VERIFY_FAILED) ) |
| 187 | snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" ); |
| 188 | if( use_ret == -(POLARSSL_ERR_RSA_OUTPUT_TOO_LARGE) ) |
| 189 | snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" ); |
| 190 | if( use_ret == -(POLARSSL_ERR_RSA_RNG_FAILED) ) |
| 191 | snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" ); |
| 192 | #endif /* POLARSSL_RSA_C */ |
| 193 | |
Paul Bakker | 831a755 | 2011-05-18 13:32:51 +0000 | [diff] [blame] | 194 | #if defined(POLARSSL_SSL_TLS_C) |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 195 | if( use_ret == -(POLARSSL_ERR_SSL_FEATURE_UNAVAILABLE) ) |
| 196 | snprintf( buf, buflen, "SSL - The requested feature is not available" ); |
| 197 | if( use_ret == -(POLARSSL_ERR_SSL_BAD_INPUT_DATA) ) |
| 198 | snprintf( buf, buflen, "SSL - Bad input parameters to function" ); |
| 199 | if( use_ret == -(POLARSSL_ERR_SSL_INVALID_MAC) ) |
| 200 | snprintf( buf, buflen, "SSL - Verification of the message MAC failed" ); |
| 201 | if( use_ret == -(POLARSSL_ERR_SSL_INVALID_RECORD) ) |
| 202 | snprintf( buf, buflen, "SSL - An invalid SSL record was received" ); |
Paul Bakker | 831a755 | 2011-05-18 13:32:51 +0000 | [diff] [blame] | 203 | if( use_ret == -(POLARSSL_ERR_SSL_CONN_EOF) ) |
| 204 | snprintf( buf, buflen, "SSL - The connection indicated an EOF" ); |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 205 | if( use_ret == -(POLARSSL_ERR_SSL_UNKNOWN_CIPHER) ) |
| 206 | snprintf( buf, buflen, "SSL - An unknown cipher was received" ); |
| 207 | if( use_ret == -(POLARSSL_ERR_SSL_NO_CIPHER_CHOSEN) ) |
| 208 | snprintf( buf, buflen, "SSL - The server has no ciphersuites in common with the client" ); |
| 209 | if( use_ret == -(POLARSSL_ERR_SSL_NO_SESSION_FOUND) ) |
| 210 | snprintf( buf, buflen, "SSL - No session to recover was found" ); |
| 211 | if( use_ret == -(POLARSSL_ERR_SSL_NO_CLIENT_CERTIFICATE) ) |
| 212 | snprintf( buf, buflen, "SSL - No client certification received from the client, but required by the authentication mode" ); |
| 213 | if( use_ret == -(POLARSSL_ERR_SSL_CERTIFICATE_TOO_LARGE) ) |
| 214 | snprintf( buf, buflen, "SSL - DESCRIPTION MISSING" ); |
| 215 | if( use_ret == -(POLARSSL_ERR_SSL_CERTIFICATE_REQUIRED) ) |
| 216 | snprintf( buf, buflen, "SSL - The own certificate is not set, but needed by the server" ); |
| 217 | if( use_ret == -(POLARSSL_ERR_SSL_PRIVATE_KEY_REQUIRED) ) |
| 218 | snprintf( buf, buflen, "SSL - The own private key is not set, but needed" ); |
| 219 | if( use_ret == -(POLARSSL_ERR_SSL_CA_CHAIN_REQUIRED) ) |
| 220 | snprintf( buf, buflen, "SSL - No CA Chain is set, but required to operate" ); |
| 221 | if( use_ret == -(POLARSSL_ERR_SSL_UNEXPECTED_MESSAGE) ) |
| 222 | snprintf( buf, buflen, "SSL - An unexpected message was received from our peer" ); |
| 223 | if( use_ret == -(POLARSSL_ERR_SSL_FATAL_ALERT_MESSAGE) ) |
| 224 | snprintf( buf, buflen, "SSL - A fatal alert message was received from our peer" ); |
| 225 | if( use_ret == -(POLARSSL_ERR_SSL_PEER_VERIFY_FAILED) ) |
| 226 | snprintf( buf, buflen, "SSL - Verification of our peer failed" ); |
| 227 | if( use_ret == -(POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY) ) |
| 228 | snprintf( buf, buflen, "SSL - The peer notified us that the connection is going to be closed" ); |
| 229 | if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO) ) |
| 230 | snprintf( buf, buflen, "SSL - Processing of the ClientHello handshake message failed" ); |
| 231 | if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO) ) |
| 232 | snprintf( buf, buflen, "SSL - Processing of the ServerHello handshake message failed" ); |
| 233 | if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE) ) |
| 234 | snprintf( buf, buflen, "SSL - Processing of the Certificate handshake message failed" ); |
| 235 | if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST) ) |
| 236 | snprintf( buf, buflen, "SSL - Processing of the CertificateRequest handshake message failed" ); |
| 237 | if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE) ) |
| 238 | snprintf( buf, buflen, "SSL - Processing of the ServerKeyExchange handshake message failed" ); |
| 239 | if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO_DONE) ) |
| 240 | snprintf( buf, buflen, "SSL - Processing of the ServerHelloDone handshake message failed" ); |
| 241 | if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE) ) |
| 242 | snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed" ); |
| 243 | if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_DHM_RP) ) |
| 244 | snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM Read Public" ); |
| 245 | if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_DHM_CS) ) |
| 246 | snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM Calculate Secret" ); |
| 247 | if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY) ) |
| 248 | snprintf( buf, buflen, "SSL - Processing of the CertificateVerify handshake message failed" ); |
| 249 | if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC) ) |
| 250 | snprintf( buf, buflen, "SSL - Processing of the ChangeCipherSpec handshake message failed" ); |
| 251 | if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_FINISHED) ) |
| 252 | snprintf( buf, buflen, "SSL - Processing of the Finished handshake message failed" ); |
Paul Bakker | 831a755 | 2011-05-18 13:32:51 +0000 | [diff] [blame] | 253 | #endif /* POLARSSL_SSL_TLS_C */ |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 254 | |
| 255 | #if defined(POLARSSL_X509_PARSE_C) |
| 256 | if( use_ret == -(POLARSSL_ERR_X509_FEATURE_UNAVAILABLE) ) |
| 257 | snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" ); |
| 258 | if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_PEM) ) |
| 259 | snprintf( buf, buflen, "X509 - The PEM-encoded certificate contains invalid elements, e.g. invalid character" ); |
| 260 | if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_FORMAT) ) |
| 261 | snprintf( buf, buflen, "X509 - The certificate format is invalid, e.g. different type expected" ); |
| 262 | if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_VERSION) ) |
| 263 | snprintf( buf, buflen, "X509 - The certificate version element is invalid" ); |
| 264 | if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_SERIAL) ) |
| 265 | snprintf( buf, buflen, "X509 - The serial tag or value is invalid" ); |
| 266 | if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_ALG) ) |
| 267 | snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" ); |
| 268 | if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_NAME) ) |
| 269 | snprintf( buf, buflen, "X509 - The name tag or value is invalid" ); |
| 270 | if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_DATE) ) |
| 271 | snprintf( buf, buflen, "X509 - The date tag or value is invalid" ); |
| 272 | if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_PUBKEY) ) |
| 273 | snprintf( buf, buflen, "X509 - The pubkey tag or value is invalid (only RSA is supported)" ); |
| 274 | if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_SIGNATURE) ) |
| 275 | snprintf( buf, buflen, "X509 - The signature tag or value invalid" ); |
| 276 | if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_EXTENSIONS) ) |
| 277 | snprintf( buf, buflen, "X509 - The extension tag or value is invalid" ); |
| 278 | if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_VERSION) ) |
| 279 | snprintf( buf, buflen, "X509 - Certificate or CRL has an unsupported version number" ); |
| 280 | if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_SIG_ALG) ) |
| 281 | snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" ); |
Paul Bakker | 9db7742 | 2011-07-13 11:47:32 +0000 | [diff] [blame] | 282 | if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_PK_ALG) ) |
| 283 | snprintf( buf, buflen, "X509 - Key algorithm is unsupported (only RSA is supported)" ); |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 284 | if( use_ret == -(POLARSSL_ERR_X509_CERT_SIG_MISMATCH) ) |
| 285 | snprintf( buf, buflen, "X509 - Certificate signature algorithms do not match. (see \\c ::x509_cert sig_oid)" ); |
| 286 | if( use_ret == -(POLARSSL_ERR_X509_CERT_VERIFY_FAILED) ) |
| 287 | snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" ); |
| 288 | if( use_ret == -(POLARSSL_ERR_X509_KEY_INVALID_VERSION) ) |
| 289 | snprintf( buf, buflen, "X509 - Unsupported RSA key version" ); |
| 290 | if( use_ret == -(POLARSSL_ERR_X509_KEY_INVALID_FORMAT) ) |
| 291 | snprintf( buf, buflen, "X509 - Invalid RSA key tag or value" ); |
| 292 | if( use_ret == -(POLARSSL_ERR_X509_POINT_ERROR) ) |
| 293 | snprintf( buf, buflen, "X509 - Not used" ); |
| 294 | if( use_ret == -(POLARSSL_ERR_X509_VALUE_TO_LENGTH) ) |
| 295 | snprintf( buf, buflen, "X509 - Not used" ); |
| 296 | #endif /* POLARSSL_X509_PARSE_C */ |
| 297 | |
| 298 | if( strlen( buf ) == 0 ) |
| 299 | snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret ); |
| 300 | } |
| 301 | |
| 302 | use_ret = ret & ~0xFF80; |
| 303 | |
| 304 | if( use_ret == 0 ) |
| 305 | return; |
| 306 | |
| 307 | // If high level code is present, make a concatenation between both |
| 308 | // error strings. |
| 309 | // |
| 310 | len = strlen( buf ); |
| 311 | |
| 312 | if( len > 0 ) |
| 313 | { |
| 314 | if( buflen - len < 5 ) |
| 315 | return; |
| 316 | |
| 317 | snprintf( buf + len, buflen - len, " : " ); |
| 318 | |
| 319 | buf += len + 3; |
| 320 | buflen -= len + 3; |
| 321 | } |
| 322 | |
| 323 | // Low level error codes |
| 324 | // |
| 325 | #if defined(POLARSSL_AES_C) |
| 326 | if( use_ret == -(POLARSSL_ERR_AES_INVALID_KEY_LENGTH) ) |
| 327 | snprintf( buf, buflen, "AES - Invalid key length" ); |
| 328 | if( use_ret == -(POLARSSL_ERR_AES_INVALID_INPUT_LENGTH) ) |
| 329 | snprintf( buf, buflen, "AES - Invalid data input length" ); |
| 330 | #endif /* POLARSSL_AES_C */ |
| 331 | |
Paul Bakker | dceecd8 | 2011-11-15 16:38:34 +0000 | [diff] [blame] | 332 | #if defined(POLARSSL_ASN1_PARSE_C) |
| 333 | if( use_ret == -(POLARSSL_ERR_ASN1_OUT_OF_DATA) ) |
| 334 | snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" ); |
| 335 | if( use_ret == -(POLARSSL_ERR_ASN1_UNEXPECTED_TAG) ) |
| 336 | snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" ); |
| 337 | if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_LENGTH) ) |
| 338 | snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" ); |
| 339 | if( use_ret == -(POLARSSL_ERR_ASN1_LENGTH_MISMATCH) ) |
| 340 | snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" ); |
| 341 | if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_DATA) ) |
| 342 | snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" ); |
| 343 | #endif /* POLARSSL_ASN1_PARSE_C */ |
| 344 | |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 345 | #if defined(POLARSSL_BASE64_C) |
| 346 | if( use_ret == -(POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL) ) |
| 347 | snprintf( buf, buflen, "BASE64 - Output buffer too small" ); |
| 348 | if( use_ret == -(POLARSSL_ERR_BASE64_INVALID_CHARACTER) ) |
| 349 | snprintf( buf, buflen, "BASE64 - Invalid character in input" ); |
| 350 | #endif /* POLARSSL_BASE64_C */ |
| 351 | |
| 352 | #if defined(POLARSSL_BIGNUM_C) |
| 353 | if( use_ret == -(POLARSSL_ERR_MPI_FILE_IO_ERROR) ) |
| 354 | snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" ); |
| 355 | if( use_ret == -(POLARSSL_ERR_MPI_BAD_INPUT_DATA) ) |
| 356 | snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" ); |
| 357 | if( use_ret == -(POLARSSL_ERR_MPI_INVALID_CHARACTER) ) |
| 358 | snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" ); |
| 359 | if( use_ret == -(POLARSSL_ERR_MPI_BUFFER_TOO_SMALL) ) |
| 360 | snprintf( buf, buflen, "BIGNUM - The output buffer is too small to write too" ); |
| 361 | if( use_ret == -(POLARSSL_ERR_MPI_NEGATIVE_VALUE) ) |
| 362 | snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" ); |
| 363 | if( use_ret == -(POLARSSL_ERR_MPI_DIVISION_BY_ZERO) ) |
| 364 | snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" ); |
| 365 | if( use_ret == -(POLARSSL_ERR_MPI_NOT_ACCEPTABLE) ) |
| 366 | snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" ); |
| 367 | #endif /* POLARSSL_BIGNUM_C */ |
| 368 | |
| 369 | #if defined(POLARSSL_CAMELLIA_C) |
| 370 | if( use_ret == -(POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH) ) |
| 371 | snprintf( buf, buflen, "CAMELLIA - Invalid key length" ); |
| 372 | if( use_ret == -(POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH) ) |
| 373 | snprintf( buf, buflen, "CAMELLIA - Invalid data input length" ); |
| 374 | #endif /* POLARSSL_CAMELLIA_C */ |
| 375 | |
| 376 | #if defined(POLARSSL_DES_C) |
| 377 | if( use_ret == -(POLARSSL_ERR_DES_INVALID_INPUT_LENGTH) ) |
| 378 | snprintf( buf, buflen, "DES - The data input has an invalid length" ); |
| 379 | #endif /* POLARSSL_DES_C */ |
| 380 | |
| 381 | #if defined(POLARSSL_NET_C) |
| 382 | if( use_ret == -(POLARSSL_ERR_NET_UNKNOWN_HOST) ) |
| 383 | snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" ); |
| 384 | if( use_ret == -(POLARSSL_ERR_NET_SOCKET_FAILED) ) |
| 385 | snprintf( buf, buflen, "NET - Failed to open a socket" ); |
| 386 | if( use_ret == -(POLARSSL_ERR_NET_CONNECT_FAILED) ) |
| 387 | snprintf( buf, buflen, "NET - The connection to the given server / port failed" ); |
| 388 | if( use_ret == -(POLARSSL_ERR_NET_BIND_FAILED) ) |
| 389 | snprintf( buf, buflen, "NET - Binding of the socket failed" ); |
| 390 | if( use_ret == -(POLARSSL_ERR_NET_LISTEN_FAILED) ) |
| 391 | snprintf( buf, buflen, "NET - Could not listen on the socket" ); |
| 392 | if( use_ret == -(POLARSSL_ERR_NET_ACCEPT_FAILED) ) |
| 393 | snprintf( buf, buflen, "NET - Could not accept the incoming connection" ); |
| 394 | if( use_ret == -(POLARSSL_ERR_NET_RECV_FAILED) ) |
| 395 | snprintf( buf, buflen, "NET - Reading information from the socket failed" ); |
| 396 | if( use_ret == -(POLARSSL_ERR_NET_SEND_FAILED) ) |
| 397 | snprintf( buf, buflen, "NET - Sending information through the socket failed" ); |
| 398 | if( use_ret == -(POLARSSL_ERR_NET_CONN_RESET) ) |
| 399 | snprintf( buf, buflen, "NET - Connection was reset by peer" ); |
Paul Bakker | 831a755 | 2011-05-18 13:32:51 +0000 | [diff] [blame] | 400 | if( use_ret == -(POLARSSL_ERR_NET_WANT_READ) ) |
| 401 | snprintf( buf, buflen, "NET - Connection requires a read call" ); |
| 402 | if( use_ret == -(POLARSSL_ERR_NET_WANT_WRITE) ) |
| 403 | snprintf( buf, buflen, "NET - Connection requires a write call" ); |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 404 | #endif /* POLARSSL_NET_C */ |
| 405 | |
| 406 | #if defined(POLARSSL_PADLOCK_C) |
| 407 | if( use_ret == -(POLARSSL_ERR_PADLOCK_DATA_MISALIGNED) ) |
| 408 | snprintf( buf, buflen, "PADLOCK - Input data should be aligned" ); |
| 409 | #endif /* POLARSSL_PADLOCK_C */ |
| 410 | |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 411 | #if defined(POLARSSL_XTEA_C) |
| 412 | if( use_ret == -(POLARSSL_ERR_XTEA_INVALID_INPUT_LENGTH) ) |
| 413 | snprintf( buf, buflen, "XTEA - The data input has an invalid length" ); |
| 414 | #endif /* POLARSSL_XTEA_C */ |
| 415 | |
| 416 | if( strlen( buf ) != 0 ) |
| 417 | return; |
| 418 | |
| 419 | snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret ); |
| 420 | } |
| 421 | |
| 422 | #endif /* POLARSSL_VERBOSE_ERROR */ |