Use gnutls_strerror() for reporting errors.

This commit is contained in:
Vincent Richard 2011-08-20 06:35:06 +00:00
parent 92b4dc8648
commit bcdffb5355

View File

@ -41,6 +41,9 @@
//#define GNUTLS_DEBUG 1
#include <sstream>
#include <iomanip>
#if VMIME_DEBUG && GNUTLS_DEBUG
#include <iostream>
#endif // VMIME_DEBUG && GNUTLS_DEBUG
@ -257,119 +260,14 @@ ref <security::cert::certificateVerifier> TLSSession::getCertificateVerifier()
void TLSSession::throwTLSException(const string& fname, const int code)
{
string msg = fname + "() returned ";
std::ostringstream msg;
#define ERROR(x) \
case x: msg += #x; break;
msg << fname + "() returned code ";
msg << std::hex << code;
msg << ": ";
msg << gnutls_strerror(code);
switch (code)
{
ERROR(GNUTLS_E_SUCCESS)
ERROR(GNUTLS_E_UNKNOWN_COMPRESSION_ALGORITHM)
ERROR(GNUTLS_E_UNKNOWN_CIPHER_TYPE)
ERROR(GNUTLS_E_LARGE_PACKET)
ERROR(GNUTLS_E_UNSUPPORTED_VERSION_PACKET)
ERROR(GNUTLS_E_UNEXPECTED_PACKET_LENGTH)
ERROR(GNUTLS_E_INVALID_SESSION)
ERROR(GNUTLS_E_FATAL_ALERT_RECEIVED)
ERROR(GNUTLS_E_UNEXPECTED_PACKET)
ERROR(GNUTLS_E_WARNING_ALERT_RECEIVED)
ERROR(GNUTLS_E_ERROR_IN_FINISHED_PACKET)
ERROR(GNUTLS_E_UNEXPECTED_HANDSHAKE_PACKET)
ERROR(GNUTLS_E_UNKNOWN_CIPHER_SUITE)
ERROR(GNUTLS_E_UNWANTED_ALGORITHM)
ERROR(GNUTLS_E_MPI_SCAN_FAILED)
ERROR(GNUTLS_E_DECRYPTION_FAILED)
ERROR(GNUTLS_E_MEMORY_ERROR)
ERROR(GNUTLS_E_DECOMPRESSION_FAILED)
ERROR(GNUTLS_E_COMPRESSION_FAILED)
ERROR(GNUTLS_E_AGAIN)
ERROR(GNUTLS_E_EXPIRED)
ERROR(GNUTLS_E_DB_ERROR)
ERROR(GNUTLS_E_SRP_PWD_ERROR)
ERROR(GNUTLS_E_INSUFFICIENT_CREDENTIALS)
ERROR(GNUTLS_E_HASH_FAILED)
ERROR(GNUTLS_E_BASE64_DECODING_ERROR)
ERROR(GNUTLS_E_MPI_PRINT_FAILED)
ERROR(GNUTLS_E_REHANDSHAKE)
ERROR(GNUTLS_E_GOT_APPLICATION_DATA)
ERROR(GNUTLS_E_RECORD_LIMIT_REACHED)
ERROR(GNUTLS_E_ENCRYPTION_FAILED)
ERROR(GNUTLS_E_PK_ENCRYPTION_FAILED)
ERROR(GNUTLS_E_PK_DECRYPTION_FAILED)
ERROR(GNUTLS_E_PK_SIGN_FAILED)
ERROR(GNUTLS_E_X509_UNSUPPORTED_CRITICAL_EXTENSION)
ERROR(GNUTLS_E_KEY_USAGE_VIOLATION)
ERROR(GNUTLS_E_NO_CERTIFICATE_FOUND)
ERROR(GNUTLS_E_INVALID_REQUEST)
ERROR(GNUTLS_E_SHORT_MEMORY_BUFFER)
ERROR(GNUTLS_E_INTERRUPTED)
ERROR(GNUTLS_E_PUSH_ERROR)
ERROR(GNUTLS_E_PULL_ERROR)
ERROR(GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER)
ERROR(GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE)
ERROR(GNUTLS_E_PKCS1_WRONG_PAD)
ERROR(GNUTLS_E_RECEIVED_ILLEGAL_EXTENSION)
ERROR(GNUTLS_E_INTERNAL_ERROR)
ERROR(GNUTLS_E_DH_PRIME_UNACCEPTABLE)
ERROR(GNUTLS_E_FILE_ERROR)
ERROR(GNUTLS_E_TOO_MANY_EMPTY_PACKETS)
ERROR(GNUTLS_E_UNKNOWN_PK_ALGORITHM)
ERROR(GNUTLS_E_INIT_LIBEXTRA)
ERROR(GNUTLS_E_LIBRARY_VERSION_MISMATCH)
ERROR(GNUTLS_E_NO_TEMPORARY_RSA_PARAMS)
ERROR(GNUTLS_E_LZO_INIT_FAILED)
ERROR(GNUTLS_E_NO_COMPRESSION_ALGORITHMS)
ERROR(GNUTLS_E_NO_CIPHER_SUITES)
ERROR(GNUTLS_E_OPENPGP_GETKEY_FAILED)
ERROR(GNUTLS_E_PK_SIG_VERIFY_FAILED)
ERROR(GNUTLS_E_ILLEGAL_SRP_USERNAME)
ERROR(GNUTLS_E_SRP_PWD_PARSING_ERROR)
ERROR(GNUTLS_E_NO_TEMPORARY_DH_PARAMS)
ERROR(GNUTLS_E_ASN1_ELEMENT_NOT_FOUND)
ERROR(GNUTLS_E_ASN1_IDENTIFIER_NOT_FOUND)
ERROR(GNUTLS_E_ASN1_DER_ERROR)
ERROR(GNUTLS_E_ASN1_VALUE_NOT_FOUND)
ERROR(GNUTLS_E_ASN1_GENERIC_ERROR)
ERROR(GNUTLS_E_ASN1_VALUE_NOT_VALID)
ERROR(GNUTLS_E_ASN1_TAG_ERROR)
ERROR(GNUTLS_E_ASN1_TAG_IMPLICIT)
ERROR(GNUTLS_E_ASN1_TYPE_ANY_ERROR)
ERROR(GNUTLS_E_ASN1_SYNTAX_ERROR)
ERROR(GNUTLS_E_ASN1_DER_OVERFLOW)
//ERROR(GNUTLS_E_OPENPGP_TRUSTDB_VERSION_UNSUPPORTED)
ERROR(GNUTLS_E_OPENPGP_UID_REVOKED)
ERROR(GNUTLS_E_CERTIFICATE_ERROR)
//ERROR(GNUTLS_E_X509_CERTIFICATE_ERROR)
ERROR(GNUTLS_E_CERTIFICATE_KEY_MISMATCH)
ERROR(GNUTLS_E_UNSUPPORTED_CERTIFICATE_TYPE)
ERROR(GNUTLS_E_X509_UNKNOWN_SAN)
ERROR(GNUTLS_E_OPENPGP_FINGERPRINT_UNSUPPORTED)
ERROR(GNUTLS_E_X509_UNSUPPORTED_ATTRIBUTE)
ERROR(GNUTLS_E_UNKNOWN_HASH_ALGORITHM)
ERROR(GNUTLS_E_UNKNOWN_PKCS_CONTENT_TYPE)
ERROR(GNUTLS_E_UNKNOWN_PKCS_BAG_TYPE)
ERROR(GNUTLS_E_INVALID_PASSWORD)
ERROR(GNUTLS_E_MAC_VERIFY_FAILED)
ERROR(GNUTLS_E_CONSTRAINT_ERROR)
ERROR(GNUTLS_E_BASE64_ENCODING_ERROR)
ERROR(GNUTLS_E_INCOMPATIBLE_GCRYPT_LIBRARY)
//ERROR(GNUTLS_E_INCOMPATIBLE_CRYPTO_LIBRARY)
ERROR(GNUTLS_E_INCOMPATIBLE_LIBTASN1_LIBRARY)
ERROR(GNUTLS_E_OPENPGP_KEYRING_ERROR)
ERROR(GNUTLS_E_X509_UNSUPPORTED_OID)
//ERROR(GNUTLS_E_RANDOM_FAILED)
ERROR(GNUTLS_E_UNIMPLEMENTED_FEATURE)
default:
msg += "unknown error";
break;
}
#undef ERROR
throw exceptions::tls_exception(msg);
throw exceptions::tls_exception(msg.str());
}