Other Parts Discussed in Thread: UNIFLASH
Hello guys,
I used the CC3200 example "http_client_demo" to do as a "https client" . I downloaded secure_http_client_demo.7z. Then i added file main.c into http_client demo project. I have generated the certificate as per the document and flashed it . The time is set to the current time.But An error occurred"Connection to server failed.error(-102)".
The ConnectToHTTPServer function code:
static int ConnectToHTTPServer(HTTPCli_Handle httpClient) { long lRetVal = -1; struct sockaddr_in addr;
#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 #ifdef SECURE SlDateTime_t dt; /* Set current Date to validate certificate */ dt.sl_tm_day = 3; dt.sl_tm_mon = 6; dt.sl_tm_year = 2017; dt.sl_tm_hour = 9; dt.sl_tm_min = 51; dt.sl_tm_sec = 0; sl_DevSet(SL_DEVICE_GENERAL_CONFIGURATION, SL_DEVICE_GENERAL_CONFIGURATION_DATE_TIME, sizeof(SlDateTime_t), (unsigned char *)(&dt)); #endif /* 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); } #ifdef SECURE #define SL_SSL_CA_CERT "/cert/129.der" struct HTTPCli_SecureParams sparams; /* Set secure TLS connection */ /* Security parameters */ sparams.method.secureMethod = SL_SO_SEC_METHOD_TLSV1_2; sparams.mask.secureMask =SL_SEC_MASK_TLS_RSA_WITH_AES_256_CBC_SHA256 ; //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); #endif /* 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); /* Testing HTTPCli open call: handle, address params only */ HTTPCli_construct(httpClient); #ifdef SECURE lRetVal = HTTPCli_connect(httpClient, (struct sockaddr *)&addr, HTTPCli_TYPE_TLS, NULL); #else lRetVal = HTTPCli_connect(httpClient, (struct sockaddr *)&addr, 0, NULL); #endif if (lRetVal < 0) { UART_PRINT("Connection to server failed. error(%d)\n\r", lRetVal); ASSERT_ON_ERROR(SERVER_CONNECTION_FAILED); } else { UART_PRINT("Connection to server created successfully\r\n"); } return 0; }
Host name and the port:
#define HOST_NAME "www.howsmyssl.com" //"<host name>"
#define HOST_PORT 44 3
I programed the certificate into the targert device by UniFlash.
the version information is CC3200SDK_1.3.0
When i run the project in IAR,it always returned "Connection to server failed. error(-102)" in this code " lRetVal = HTTPCli_connect(httpClient, (struct sockaddr *)&addr, HTTPCli_TYPE_TLS, NULL)"
who can help me?Grateful!
Regards,
Guojing PAN.