Topic: WolfSSL and FreeRTOS+TCP LPC1788 MCUXpresso
Hi,
I'm trying work with Wolfssl using FreeRTOS+TCP. My lib FreeRTOS+TCP is working well.
What i done:
I startup the wolfssl using a constant with the certificate.
wolfSSL_Init();
/* Attempt to create a context that uses the TLS 1.2 server protocol. */
xWolfSSL_ClientContext = wolfSSL_CTX_new( wolfTLSv1_2_client_method() );
configASSERT( xWolfSSL_ClientContext );
/* Load the CA certificate. */
lReturned = wolfSSL_CTX_load_verify_buffer(xWolfSSL_ClientContext, my_cert, sizeof(ca_cert_perm), SSL_FILETYPE_PEM);
configASSERT( lReturned == SSL_SUCCESS );
wolfSSL_SetIOSend(xWolfSSL_ClientContext, cbk_send);
wolfSSL_SetIORecv(xWolfSSL_ClientContext, cbk_recv);
The certificate:
const unsigned char my_cert[] = {
"-----BEGIN CERTIFICATE-----\n"
"MIIESTCCAzGgAwIBAgITBn+UV4WH6Kx33rJTMlu8mYtWDTANBgkqhkiG9w0BAQsF\n"
"ADA5MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6\n"
"b24gUm9vdCBDQSAxMB4XDTE1MTAyMjAwMDAwMFoXDTI1MTAxOTAwMDAwMFowRjEL\n"
"MAkGA1UEBhMCVVMxDzANBgNVBAoTBkFtYXpvbjEVMBMGA1UECxMMU2VydmVyIENB\n"
"IDFCMQ8wDQYDVQQDEwZBbWF6b24wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK\n"
"AoIBAQDCThZn3c68asg3Wuw6MLAd5tES6BIoSMzoKcG5blPVo+sDORrMd4f2AbnZ\n"
"cMzPa43j4wNxhplty6aUKk4T1qe9BOwKFjwK6zmxxLVYo7bHViXsPlJ6qOMpFge5\n"
"blDP+18x+B26A0piiQOuPkfyDyeR4xQghfj66Yo19V+emU3nazfvpFA+ROz6WoVm\n"
"B5x+F2pV8xeKNR7u6azDdU5YVX1TawprmxRC1+WsAYmz6qP+z8ArDITC2FMVy2fw\n"
"0IjKOtEXc/VfmtTFch5+AfGYMGMqqvJ6LcXiAhqG5TI+Dr0RtM88k+8XUBCeQ8IG\n"
"KuANaL7TiItKZYxK1MMuTJtV9IblAgMBAAGjggE7MIIBNzASBgNVHRMBAf8ECDAG\n"
"AQH/AgEAMA4GA1UdDwEB/wQEAwIBhjAdBgNVHQ4EFgQUWaRmBlKge5WSPKOUByeW\n"
"dFv5PdAwHwYDVR0jBBgwFoAUhBjMhTTsvAyUlC4IWZzHshBOCggwewYIKwYBBQUH\n"
"AQEEbzBtMC8GCCsGAQUFBzABhiNodHRwOi8vb2NzcC5yb290Y2ExLmFtYXpvbnRy\n"
"dXN0LmNvbTA6BggrBgEFBQcwAoYuaHR0cDovL2NydC5yb290Y2ExLmFtYXpvbnRy\n"
"dXN0LmNvbS9yb290Y2ExLmNlcjA/BgNVHR8EODA2MDSgMqAwhi5odHRwOi8vY3Js\n"
"LnJvb3RjYTEuYW1hem9udHJ1c3QuY29tL3Jvb3RjYTEuY3JsMBMGA1UdIAQMMAow\n"
"CAYGZ4EMAQIBMA0GCSqGSIb3DQEBCwUAA4IBAQCFkr41u3nPo4FCHOTjY3NTOVI1\n"
"59Gt/a6ZiqyJEi+752+a1U5y6iAwYfmXss2lJwJFqMp2PphKg5625kXg8kP2CN5t\n"
"6G7bMQcT8C8xDZNtYTd7WPD8UZiRKAJPBXa30/AbwuZe0GaFEQ8ugcYQgSn+IGBI\n"
"8/LwhBNTZTUVEWuCUUBVV18YtbAiPq3yXqMB48Oz+ctBWuZSkbvkNodPLamkB2g1\n"
"upRyzQ7qDn1X8nn8N8V7YJ6y68AtkHcNSRAnpTitxBKjtKPISLMVCx7i4hncxHZS\n"
"yLyKQXhw2W2Xs0qLeC1etA+jTGDK4UfLeC0SF7FSi8o5LL21L8IzApar2pR/\n"
"-----END CERTIFICATE-----\n"
};
And after this i try send a message to server:
/* Set family and port for client socket. */
xConnection.sin_family = FREERTOS_AF_INET;
xConnection.sin_addr = FreeRTOS_gethostbyname("api.tago.io");
xConnection.sin_port = FreeRTOS_htons( 80 );
if(xConnection.sin_addr == 0){
ret = 1;
return ret;
}
xClientSocket = FreeRTOS_socket(FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP);
configASSERT( xClientSocket != FREERTOS_INVALID_SOCKET );
DEBUGOUT("FreeRTOS_connect \n");
ret = FreeRTOS_connect( xClientSocket, &xConnection, sizeof( xConnection ) );
if(ret == 0){
DEBUGOUT("wolfSSL_new \n");
/* The connect was successful. Create a wolfSSL object to associate
with this connection. */
xWolfSSL_Object = wolfSSL_new( xWolfSSL_ClientContext );
if( xWolfSSL_Object != NULL ){
DEBUGOUT("wolfSSL_set_fd \n");
/* Associate the created wolfSSL object with the connected
socket. */
ret = wolfSSL_set_fd( xWolfSSL_Object, xClientSocket );
ret = wolfSSL_connect(xWolfSSL_Object);
configASSERT( ret == SSL_SUCCESS );
xTotalLengthToSend = strlen((char*)sendBuf);
xAlreadyTransmitted = 0;
DEBUGOUT("SENDING... \n");
while( xAlreadyTransmitted < xTotalLengthToSend ){
/* How many bytes are left to send? */
xLenToSend = xTotalLengthToSend - xAlreadyTransmitted;
/* The next line is the secure equivalent of the standard
sockets call:
lReturned = send( xClientSocket, cString, strlen( cString ) + 1, 0 ); */
xBytesSent = wolfSSL_write( xWolfSSL_Object,
/* The data being sent. */
(char*) &(sendBuf[ xAlreadyTransmitted ]),
/* The remaining length of data to send. */
xLenToSend);
DEBUGOUT("\nsend: %d\n",xBytesSent);
if( xBytesSent >= 0 ){
/* Data was sent successfully. */
xAlreadyTransmitted += xBytesSent;
}
else{
/* Error – break out of the loop for graceful socket close. */
ret = 3;
break;
}
}
DEBUGOUT("RECEIVING... \n");
for( ;; ){
/* Receive another block of data into the cRxedData buffer. */
/*xReceLen = FreeRTOS_recv( xSocketSend, recBuf, sizeof(recBuf), 0 );*/
xRecLen = wolfSSL_read(xWolfSSL_Object, recBuf, sizeof(recBuf));
if( xRecLen > 0 )
{
/* Data was received, process it here. */
for(i=0; i<xRecLen; i++){
receive[xSizeReceive+i] = recBuf[i];
}
DEBUGOUT("->: %d\n",xRecLen);
xSizeReceive += xRecLen;
}
else if( xRecLen == 0 )
{
/* No data was received, but FreeRTOS_recv() did not return an error.
Timeout? */
DEBUGOUT("Timeout\n");
}
else
{
DEBUGOUT("Shutdown\n");
/* Error (maybe the connected socket already shut down the socket?).
Attempt graceful shutdown. */
/*FreeRTOS_shutdown( xSocketSend, FREERTOS_SHUT_RDWR );*/
wolfSSL_shutdown(xWolfSSL_Object);
break;
}
}
wolfSSL_free( xWolfSSL_Object );
}
DEBUGOUT("FreeRTOS_closesocket \n");
FreeRTOS_closesocket( xClientSocket );
}
I enabled the debug messages on WolfSSL and when i try send my message i receive a error of version SSL:
connect state: CLIENT_HELLO_SENT
SSL version error
84 84 3 3
->../WolfSSL/src/ssl.c-5214 - error:-326
where the values '84' are about ssl->curRL.pvMajor and rh->pvMinor, and the values '3' are about ssl->version.major and ssl->version.minor on GetRecordHeader function in internal.c file.
I'm sending my user_settings.h.
If anyone can help me.