This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/CC3200-LAUNCHXL: HTTPS client with tirtos

Expert 1255 points

Part Number: CC3200-LAUNCHXL
Other Parts Discussed in Thread: CC3200

Tool/software: TI-RTOS

hi 

I want to implement an https client on my device to connect to a server of the following format : [subdomain].firebaseio.com

I was successful in doing so with the cc3200 sdk example-http client demo, by adding corresponding mask, method and certificate.

But when it come to tirtos --

The httpcli.h and httpcli.c file are different. The httpcli.h file has a provided example in it as follows:

 // Make HTTP 1.1 POST request
 *  //
 *  // Send request to the server:
 *  //
 *  // POST /index.html HTTP/1.1
 *  // Host: www.example.com
 *  HTTPCli_sendRequest(&cli, HTTPStd_POST, "/index.html", true);
 *
 *  // Send additional fields
 *  //
 *  // Content-Length: <length>
 *  // <blank line>
 *  HTTPCli_sendField(&cli, HTTPStd_FIELD_NAME_CONTENT_LENGTH, len, true);
 *
 *  // Send request body
 *  //
 *  // <data>
 *  HTTPCli_sendRequestBody(&cli, data, strlen(data));
 *
 *  // Get the processed response status
 *  //
 *  // HTTP/1.1 200 OK
 *  status = HTTPCli_getResponseStatus(&cli);
 *
 *  // Check the HTTP return status and process remaining response
 *  if (status == HTTPStd_OK) {
 *      do {
 *          // Filter the response headers and get the set response field
 *          //
 *          //...
 *          // Content-type: text/xml; charset=utf-8\r\n
 *          // Content-length: 34
 *          //  ...
 *          ret = HTTPCli_getResponseField(&cli, buf, sizeof(buf), &moreFlag);
 *
 *          //  Process data in buf if field is content length
 *          //  Zero is the index of Content length in respFields array
 *          if (ret == 0) {
 *              len = (int)strtoul(buf, NULL, 0);
 *          }
 *
 *      } while (ret != HTTPCli_FIELD_ID_END);
 *
 *      while (len > 0) {
 *          len -= HTTPCli_readRawResponseBody(&cli, buf, sizeof(buf));
 *          // ... process buf data and save ...
 *      }
 *   }
 *
 *   HTTPCli_disconnect(&cli);
 *
 *   HTTPCli_destruct(&cli);

But the sssl.h file in not found in the tirtos folders. TIRTOS VERSION: tirtos_cc32xx_2_16_01_14

I believe we have to use tls.h file for this, I tried with the following code , BUT STILL GETTING ERROR

	HTTPCli_Struct cli;
	HTTPCli_Params cli_param;
	// Request fields
	HTTPCli_Field fields[4] = {
			{HTTPCli_FIELD_NAME_HOST, HOST_NAME},
			{HTTPCli_FIELD_NAME_ACCEPT, "*/*"},
			{HTTPCli_FIELD_NAME_CONTENT_LENGTH, "0"},
			{NULL, NULL}
	};
	// Response field filters
	const char *respFields[2] = {
			HTTPStd_FIELD_NAME_CONTENT_LENGTH,
			NULL
	};
	const char *ids[4] = {
			HTTPCli_FIELD_NAME_CONTENT_LENGTH,
			HTTPCli_FIELD_NAME_CONNECTION,
			HTTPCli_FIELD_NAME_CONTENT_TYPE,
			NULL
	};
	bool        moreFlag;
	long lRetVal = -1;
	struct sockaddr_in addr;
	lRetVal = sl_NetAppDnsGetHostByName((signed char *)HOST_NAME,
			strlen((const char *)HOST_NAME),
			&g_ulDestinationIP,SL_AF_INET);
	if(lRetVal < 0)
	{
		ASSERT_ON_ERROR(lRetVal);
	}
	UART_PRINT("dnsipget=%d\n\r",lRetVal);
	addr.sin_family = AF_INET;
	addr.sin_port = htons(HOST_PORT);
	addr.sin_addr.s_addr = sl_Htonl(g_ulDestinationIP);
	SlDateTime_t dt;
	//	/* Set current Date to validate certificate */
	dt.sl_tm_day = 4;
	dt.sl_tm_mon = 1;
	dt.sl_tm_year = 2017;
	dt.sl_tm_hour = 9;
	dt.sl_tm_min = 39;
	dt.sl_tm_sec = 00;
	sl_DevSet(SL_DEVICE_GENERAL_CONFIGURATION,
			SL_DEVICE_GENERAL_CONFIGURATION_DATE_TIME,
			sizeof(SlDateTime_t), (unsigned char *)(&dt));
	TLS_Handle tls;
#define SL_CA_CERT "cert1.cer"
	struct TLS_Params params;
	TLS_Params_init(&params);
	char storage[10];
	memset(storage,0,10);
	memcpy(storage,SL_CA_CERT,strlen(SL_CA_CERT));
	params.ca=storage;
	UART_PRINT("params.ca=%s\n\r",params.ca);
	params.calen=strlen(SL_CA_CERT);
	UART_PRINT("params.calen=%d\n\r",params.calen);
	*(params.ca+params.calen)='\0';
	tls=TLS_create(TLS_METHOD_CLIENT_TLSV1_2,&params,"cert");
	if(tls==NULL)
	{
		UART_PRINT("NULL");
	}
	else
	{
		UART_PRINT("TLS HANDLE not null==>");
		UART_PRINT("tls handle=%p\n\r",tls);
	}
	cli.tls=tls;
	cli_param.tls=tls;
	cli_param.timeout=20;
	UART_PRINT("cli.tls=%p\n\r",cli.tls);
	// Construct a static HTTP client instance
	HTTPCli_construct(&cli);
	// Connect to the HTTP Server
	lRetVal=HTTPCli_connect(&cli, (struct sockaddr *)&addr,HTTPCli_TYPE_TLS,&cli_param);
	if(lRetVal<0)
	{
		UART_PRINT("lRetVal=%d",lRetVal);
		UART_PRINT("not connected\n\r");
	}

THE OUTPUT ERROR IS:

HTTP Get Begin:
dnsipget=0
params.ca=cert1.cer
params.calen=9
TLS HANDLE not null==>tls handle=2001b440
cli.tls=2001b440
lRetVal=-102not connected
connectval=-102sendreq=-103status=-104HTTP Get failed.
HTTP Get End:

Could you guide me on this

Thanks 

av

  • Hi av,

    It looks like you are not setting the request and response fields, your code should look as such:

    HTTPCli_construct(&cli);
    
    HTTPCli_setRequestFields(&cli, fields);
    
    HTTPCli_setResponseFields(&cli, respFields);

    You can then call HTTPCli_connect.

    Hope this helps,
    Gerardo

  • Hi Gerardo

    The error is coming at connect (sl_connect)  function present in HTTPCli_connect api. I dont believe the set fields option affects this. But i have tried with set request/response fields as u suggested, and the error remains.

    In my rtsc project i also tried to connect using raw sockets method(the one used in ssl demo example). But still sl_connect in this case gives -370 error.(i would prefer working with httpCli api)

    But i was successful in connecting with server using my (method +mask+certificate) configs when i used them with http client demo and ssl demo(both sdk projects).When it comes to tirtos https client, I am not able to find enough documentation on it.

    Do i need any thrid party add-ons or does tirtos support ssl/tls lib?

    if tls.h  ,tls_sl.h and tls_sl.c (C:\ti\tirtos_cc32xx_2_16_01_14\products\ns_1_11_00_10\packages\ti\net) are the files required to set secure params- could you guide me on how to use these api correctly.

    Thanks again

    av

  • Hi


    I was able to connect to secure sever by using httpcli api itself. To set secure params i used tls apis found in tls.h ,tls_sl.h and tls_sl.c

    Now:

    in ssl demo(sdk project) i found an option for SECURE_DOMAIN_NAME_VERIFICATION.

    but this definition is not present in socket.h of tirtos(it is present in cc3200 sdk socket.h)

    so i added this to the socket.h file :  #define SO_SECURE_DOMAIN_NAME_VERIFICATION (35)

    Is this the right method? (Once i do this sl_setsockopt returns 0)

    Thank You for the help and support
    av

  • Hi av,

    What you're doing is OK. I think this is happening because the SDK has been updated more recently and has added these options.

    Another option that would remove the need to do this is for you to add the SDK include path before your TI-RTOS include path in your compiler options. That way it will use the first version of the file it finds which would be the one on the SDK.

    Hope this helps,
    Gerardo