Other Parts Discussed in Thread: UNIFLASH, , CC3100, CC3100SDK
Hi
I'm programming a IoT network using the MQTT protocol (TCP/IPv4). Using the Paho lib's I have succesfully made an API where I have functions to connect, ping, pub/sub and disconnect properly.
Now for the next step I want to implement TLS for a secured connection. To do this I have taken the following steps to achieve this, but without succes.
1. Use OpenSSL to make certificates (for certificate based TLS).
I have tested the certificates using mosquitto server and a GUI mqtt client app. So no problems here.
2. Converting the certificate for the client to a .der file and make an C application which converts the .der file to a byte array.
I have done this, so I can use the Fs_api (uniflash is not an option), but I don't no if this is the proper aproach. after running the app I copied the bytearray the app outputted and pasted it in the CCS app into an array. The file was succesfully (i've tested this) created on the cc3100mod using the name parameter "mqtt_ca.der".
3. I wrote the following function to connect to the server:
_u32 cipher = SL_SEC_MASK_TLS_RSA_WITH_AES_128_CBC_SHA256;
_u8 method = SL_SO_SEC_METHOD_TLSV1;
int TLSConnectNetwork(int g_SockID, SlSockAddrIn_t sAddr, SlSockSecureFiles_t* certificates,
unsigned char sec_method, unsigned int cipher)
{
int addrSize;
int retVal;
addrSize = sizeof(SlSockAddrIn_t);
g_SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, SL_SEC_SOCKET);
if (g_SockID < 0) {
return -1;
}
SlSockSecureMethod method;
method.secureMethod = sec_method;
retVal = sl_SetSockOpt(g_SockID, SL_SOL_SOCKET, SL_SO_SECMETHOD, &method, sizeof(method));
if (retVal < 0) {
return retVal;
}
SlSockSecureMask mask;
mask.secureMask = cipher;
retVal = sl_SetSockOpt(g_SockID, SL_SOL_SOCKET, SL_SO_SECURE_MASK, &mask, sizeof(mask));
if (retVal < 0) {
return retVal;
}
retVal = sl_SetSockOpt(g_SockID, SL_SOL_SOCKET, SL_SO_SECURE_FILES_CA_FILE_NAME, SL_SSL_CA_CERT, strlen(SL_SSL_CA_CERT));
if(retVal < 0)
{
return retVal;
}
retVal = sl_Connect(g_SockID, ( SlSockAddr_t *)&sAddr, addrSize);
if( retVal < 0 ) {
sl_Close(g_SockID);
return retVal;
}
return retVal;
}
I am rather new in network programming and have never used TLS/SSL, so please could some one help me?
Thanks in advance!