Topic: [SOLVED] Getting -188 while connecting using wolfsslconnect
Hi All,
I am trying to connect to the MQTT server (AWS). I am using ti rtos with tm4c129encpdt microcontroller.
While connecting to server, I am using the root ca, certificate, and private key. I put these using buffer apis which is given below in the code.
When I am trying to connect, I am getting the error -188. Can anyone help me in this?
My code is -
// structure
typedef struct TLSDataParams {
WOLFSSL *ssl_aws;
WOLFSSL_CTX* ctx_aws ;
int sockfd_aws;
struct sockaddr_in g_addr_aws ;
Error_Block eb;
} TLSDataParams;
///actual code
Error_init(&tlsDataParams->eb);
wolfSSL_Init();
tlsDataParams->ctx_aws = wolfSSL_CTX_new(wolfTLSv1_2_client_method());
if (tlsDataParams->ctx_aws == 0){
// logg("****Error****: WolfSSL_CTX error", "");
exitApp(tlsDataParams->ctx_aws);
return -1;
}
uint8_t *der = NULL;
uint32_t len, ret1;
ret1 = CertConv_pem2der(tlsParams->pRootCALocation, root_ca_pem_len, &der, &len);
if (ret1 != 0){
//logg("***Error***: cert conversion to .der fail", "");
return -1;
}
status = wolfSSL_CTX_load_verify_buffer(tlsDataParams->ctx_aws, der, len, SSL_FILETYPE_ASN1);
if (status != SSL_SUCCESS){
// logg("tcpHandler: Error loading ca_cert_der_2048\n", "");
exitApp(tlsDataParams->ctx_aws);
return -1;
}
*der = NULL; len =0;
ret1 = CertConv_pem2der(tlsParams->pDeviceCertLocation, client_cert_pem_len, &der, &len);
if (ret1 != 0){
//logg("***Error***: cert conversion to .der fail", "");
return -1;
}
status = wolfSSL_CTX_use_certificate_buffer (tlsDataParams->ctx_aws, der, len, SSL_FILETYPE_ASN1);
if (status != SSL_SUCCESS){
// logg("tcpHandler: Error loading ca_cert_der_2048\n", "");
exitApp(tlsDataParams->ctx_aws);
return -1;
}
*der = NULL; len =0;
ret1 = CertConv_pem2der(tlsParams->pDevicePrivateKeyLocation, client_private_key_pem_len, &der, &len);
if (ret1 != 0){
//logg("***Error***: cert conversion to .der fail", "");
return -1;
}
status = wolfSSL_CTX_use_PrivateKey_buffer (tlsDataParams->ctx_aws, der, len, SSL_FILETYPE_ASN1);
if (status != SSL_SUCCESS){
// logg("tcpHandler: Error loading ca_cert_der_2048\n", "");
exitApp(tlsDataParams->ctx_aws);
return -1;
}
tlsDataParams->ssl_aws = wolfSSL_new(tlsDataParams->ctx_aws);
if (tlsDataParams->ssl_aws == NULL){
// logg("tcpHandler: wolfSSL_new error.\n", "");
exitApp(tlsDataParams->ctx_aws);
return -1;
}
tlsDataParams->sockfd_aws= socket(AF_INET, SOCK_STREAM, 0);
if (tlsDataParams->sockfd_aws < 0){
// logInt("***Error***: ftp socket creation failed val is %d", "", sockfd);
return -1;
}
memset((char *) &tlsDataParams->g_addr_aws, 0, sizeof(tlsDataParams->g_addr_aws));
tlsDataParams->g_addr_aws.sin_family = AF_INET;
tlsDataParams->g_addr_aws.sin_port = htons(tlsParams->DestinationPort);
strcat(tlsParams->pDestinationURL, ":"); strcat(tlsParams->pDestinationURL, portStr);
strcpy(url,tlsParams->pDestinationURL);
if (HTTPCli_initSockAddr((struct sockaddr *) &tlsDataParams->g_addr_aws, tlsParams->pDestinationURL, 0) < 0){
// logg("ftp: ***ERROR*** - address not resolved.", "");
tlsDataParams->sockfd_aws = 0;
return -1;
}
ret = connect(tlsDataParams->sockfd_aws, (struct sockaddr *)&tlsDataParams->g_addr_aws, sizeof(tlsDataParams->g_addr_aws));
if(ret < 0){
wolfSSL_free(tlsDataParams->ssl_aws);
close(tlsDataParams->sockfd_aws);
exitApp(tlsDataParams->ctx_aws);
return -1;
}
wolfSSL_set_fd(tlsDataParams->ssl_aws, tlsDataParams->sockfd_aws);
ret = wolfSSL_connect(tlsDataParams->ssl_aws); // this return failure
if(ret < 0){
char buffer[80];
error = wolfSSL_get_error(tlsDataParams->ssl_aws , 0); // this returns -188
return -1;
}
else if(ret == SSL_SUCCESS){
tlsDataParams->sockfd_aws = wolfSSL_get_fd(tlsDataParams->ssl_aws);
}
EDIT: I am able to enable logs in wolfssl. I am attaching the log file. I am finding it difficult to understand.
Thanks
Akhilesh