I would like to use the HTTP Client Library to connect securely using TLS.
I cannot find or work out the required steps to get this to function, I always get a -102 error returned when I call HTTPCli_connect
I know all my settings are correct, the certificate is installed and so on, as everything is fine when I use the ssl example (which does not use the HTTP Client Library)
I followed the details provided in the PDF for the http_client_demo example for using TLS, but I still get the -102 error.
What are the steps to get TLS working with the HTTP Client Library?
Here is my code
//***************************************************************************** // //! Function to connect to HTTP server //! //! \param httpClient - Pointer to HTTP Client instance //! //! \return Error-code or SUCCESS //! //***************************************************************************** static int ConnectToHTTPServer(HTTPCli_Handle httpClient) { long lRetVal = -1; struct sockaddr_in addr; struct HTTPCli_SecureParams sparams; #ifdef USE_PROXY struct sockaddr_in paddr; paddr.sin_family = AF_INET; paddr.sin_port = htons(PROXY_PORT); paddr.sin_addr.s_addr = sl_Htonl(PROXY_IP); HTTPCli_setProxy((struct sockaddr *)&paddr); #endif SlDateTime_t dt; /* Set current Date to validate certificate */ dt.sl_tm_day = 28; dt.sl_tm_mon = 6; dt.sl_tm_year = 2015; dt.sl_tm_hour = 4; dt.sl_tm_min = 45; dt.sl_tm_sec = 0; sl_DevSet(SL_DEVICE_GENERAL_CONFIGURATION, SL_DEVICE_GENERAL_CONFIGURATION_DATE_TIME, sizeof(SlDateTime_t), (unsigned char *)(&dt)); /* Resolve HOST NAME/IP */ lRetVal = sl_NetAppDnsGetHostByName((signed char *)HOST_NAME, strlen((const char *)HOST_NAME), &g_ulDestinationIP,SL_AF_INET); if(lRetVal < 0) { ASSERT_ON_ERROR(GET_HOST_IP_FAILED); } /* Set secure TLS connection */ /* Security parameters */ sparams.method.secureMethod = SL_SO_SEC_METHOD_TLSV1_2; sparams.mask.secureMask = SL_SEC_MASK_SSL_RSA_WITH_RC4_128_SHA; //SL_SEC_MASK_TLS_RSA_WITH_AES_256_CBC_SHA; strncpy(sparams.cafile, SL_SSL_CA_CERT, sizeof(SL_SSL_CA_CERT)); sparams.privkey[0] = 0; sparams.cert[0] = 0; sparams.dhkey[0] = 0; HTTPCli_setSecureParams(&sparams); /* Set up the input parameters for HTTP Connection */ addr.sin_family = AF_INET; addr.sin_port = htons(HOST_PORT); addr.sin_addr.s_addr = sl_Htonl(g_ulDestinationIP); HTTPCli_construct(httpClient); lRetVal = HTTPCli_connect(httpClient, (struct sockaddr *)&addr, HTTPCli_TYPE_TLS, NULL); if(lRetVal < 0) { UART_PRINT("Failed to connect securely to server. error(%d)\n\r", lRetVal); return lRetVal; //ASSERT_ON_ERROR(SERVER_CONNECTION_FAILED); } else { UART_PRINT("Connection to server created successfully\r\n"); } return 0; }