Options and Features Use
103
SWRU455A – February 2017 – Revised March 2017
Copyright © 2017, Texas Instruments Incorporated
Secure Socket
char
*CAname;
if
(SL_SOCKET_ASYNC_EVENT == pSlSockEvent->Event)
{
/* debug print "an event received on socket %d\n",
pSlSockEvent-
>SocketAsyncEvent.SockAsyncData.Sd */
switch
(pSlSockEvent->SocketAsyncEvent.SockAsyncData.Type)
{
case
SL_SSL_NOTIFICATION_CONNECTED_SECURED:
/* indicate handshake successful ok */
break
;
case
SL_SSL_NOTIFICATION_HANDSHAKE_FAILED:
/* retrieve an error from pSlSockEvent->SocketAsyncEvent.SockAsyncData.Val; */
break
;
default
:
break
;
}
}
}
void
ClientSTARTTLSExample()
{
SlSockAddrIn_t
Addr;
SlSockSecureMethod_t method;
_i32 sd,len,dummyVar;
_i16 status;
_u32 DestinationIP = SL_IPV4_VAL(192,168,1,31);
/* An SMTP server's IP */
_i16 AddrSize;
_i8 buf[100];
Addr.sin_family = SL_AF_INET;
Addr.sin_port = sl_Htons(587);
Addr.sin_addr.s_addr = sl_Htonl(DestinationIP);
AddrSize =
sizeof
(SlSockAddrIn_t);
/* Open SSL socket */
sd = sl_Socket(SL_AF_INET,SL_SOCK_STREAM,0);
if
(sd < 0)
{
/* error... */
}
method.SecureMethod = SL_SO_SEC_METHOD_SSLv3_TLSV1_2;
status = sl_SetSockOpt(sd,SL_SOL_SOCKET,SL_SO_SECMETHOD,&method,
sizeof
(SlSockSecureMethod_t));
if
(status < 0)
{
/* error... */
}
/* set a CA filename to be used to verify the SMTP server
certificate when the
handshake will take place */
status = sl_SetSockOpt(sd,SL_SOL_SOCKET,SL_SO_SECURE_FILES_CA_FILE_NAME,
"smtpCa.der",strlen("smtpCa.der"));
if
(status < 0)
{
/* error... */
}
status = sl_Connect(sd, ( SlSockAddr_t *)&Addr, AddrSize);
if
(status < 0)
{
/* error... */
}
/* unsecured transaction */
len = sl_Recv(sd,buf,100,0);
if
(len < 0)