Browse Source

report errors to output

master
Odilitime 5 years ago
parent
commit
ec2b468715
  1. 16
      src/networking/HTTPSRequest.cpp

16
src/networking/HTTPSRequest.cpp

@ -36,11 +36,13 @@ bool HTTPSRequest::sendRequest(std::function<void(const HTTPResponse&)> response @@ -36,11 +36,13 @@ bool HTTPSRequest::sendRequest(std::function<void(const HTTPResponse&)> response
int ret;
unsigned flags;
if(mbedtls_net_connect(&server_fd, host.c_str(),port.c_str(), MBEDTLS_NET_PROTO_TCP) != 0 ){
if(mbedtls_net_connect(&server_fd, host.c_str(),port.c_str(), MBEDTLS_NET_PROTO_TCP) != 0 ) {
std::cout << "HTTPS Request: cant connect to " << host << ":" << port << std::endl;
return false;
}
if (mbedtls_ssl_config_defaults(&conf,MBEDTLS_SSL_IS_CLIENT,MBEDTLS_SSL_TRANSPORT_STREAM,MBEDTLS_SSL_PRESET_DEFAULT) != 0){
if (mbedtls_ssl_config_defaults(&conf,MBEDTLS_SSL_IS_CLIENT,MBEDTLS_SSL_TRANSPORT_STREAM,MBEDTLS_SSL_PRESET_DEFAULT) != 0) {
std::cout << "HTTPS Request: cant config" << std::endl;
return false;
}
@ -48,10 +50,12 @@ bool HTTPSRequest::sendRequest(std::function<void(const HTTPResponse&)> response @@ -48,10 +50,12 @@ bool HTTPSRequest::sendRequest(std::function<void(const HTTPResponse&)> response
mbedtls_ssl_conf_rng(&conf, mbedtls_ctr_drbg_random, &ctr_drbg);
mbedtls_ssl_conf_ca_chain( &conf, &cacert, nullptr );
if( mbedtls_ssl_setup( &ssl, &conf ) != 0 ){
if( mbedtls_ssl_setup( &ssl, &conf ) != 0 ) {
std::cout << "HTTPS Request: cant setup" << std::endl;
return false;
}
if(mbedtls_ssl_set_hostname( &ssl, uri->host.c_str() ) != 0 ){
if(mbedtls_ssl_set_hostname( &ssl, uri->host.c_str() ) != 0 ) {
std::cout << "HTTPS Request: cant hostname" << std::endl;
return false;
}
@ -60,13 +64,13 @@ bool HTTPSRequest::sendRequest(std::function<void(const HTTPResponse&)> response @@ -60,13 +64,13 @@ bool HTTPSRequest::sendRequest(std::function<void(const HTTPResponse&)> response
int state = mbedtls_ssl_handshake( &ssl );
while(state != 0){
if( state != MBEDTLS_ERR_SSL_WANT_READ && state != MBEDTLS_ERR_SSL_WANT_WRITE ){
if( state != MBEDTLS_ERR_SSL_WANT_READ && state != MBEDTLS_ERR_SSL_WANT_WRITE ) {
printf( " failed\n ! mbedtls_ssl_handshake returned -0x%x\n\n", -state );
return false;
}
}
if( ( flags = mbedtls_ssl_get_verify_result( &ssl ) ) != 0 ){
if( ( flags = mbedtls_ssl_get_verify_result( &ssl ) ) != 0 ) {
printf("Invalid server cert!");
return false;
}

Loading…
Cancel
Save