- TD-79 Bad error message for wrong hostname configuration (thanks to Jens
        Erat).
This commit is contained in:
Paul Beckingham 2014-10-23 22:46:50 -04:00
parent 959df159fa
commit 2c6b3b3991
3 changed files with 11 additions and 7 deletions

View file

@ -42,6 +42,7 @@
#include <sys/errno.h>
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <TLSClient.h>
#include <gnutls/x509.h>
@ -119,11 +120,11 @@ void TLSClient::trust (const enum trust_level value)
if (_debug)
{
if (_trust == allow_all)
std::cout << "c: INFO Server certificate trusted automatically.\n";
std::cout << "c: INFO Server certificate will be trusted automatically.\n";
else if (_trust == ignore_hostname)
std::cout << "c: INFO Server certificate trust verified but hostname ignored.\n";
std::cout << "c: INFO Server certificate will be verified but hostname ignored.\n";
else
std::cout << "c: INFO Server certificate trust verified.\n";
std::cout << "c: INFO Server certificate will be verified.\n";
}
}
@ -208,8 +209,9 @@ void TLSClient::connect (const std::string& host, const std::string& port)
hints.ai_flags = AI_PASSIVE; // use my IP
struct addrinfo* res;
if (::getaddrinfo (host.c_str (), port.c_str (), &hints, &res) != 0)
throw std::string (::gai_strerror (errno));
int ret = ::getaddrinfo (host.c_str (), port.c_str (), &hints, &res);
if (ret != 0)
throw std::string (::gai_strerror (ret));
// Try them all, stop on success.
struct addrinfo* p;
@ -247,7 +249,6 @@ void TLSClient::connect (const std::string& host, const std::string& port)
#endif
// Perform the TLS handshake
int ret;
do
{
ret = gnutls_handshake (_session);
@ -261,7 +262,7 @@ void TLSClient::connect (const std::string& host, const std::string& port)
// gnutls_certificate_set_verify_function does only work with gnutls
// >=2.9.10. So with older versions we should call the verify function
// manually after the gnutls handshake.
ret = verify_certificate();
ret = verify_certificate ();
if (ret < 0)
{
if (_debug)