2 FreeRTOS V7.5.0 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
65 #pragma comment( lib, "ws2_32.lib" )
\r
67 /* Win32 includes. */
\r
68 #include <WinSock2.h>
\r
70 /* CyaSSL includes. */
\r
71 #include "cyassl/ssl.h"
\r
73 /* Standard includes. */
\r
77 /* FreeRTOS includes. */
\r
78 #include "FreeRTOS.h"
\r
81 /*-----------------------------------------------------------*/
\r
83 /* The CyaSSL context for the client. */
\r
84 static CYASSL_CTX* xCyaSSL_ClientContext = NULL;
\r
86 /*-----------------------------------------------------------*/
\r
88 /* See the comments at the top of main.c. */
\r
89 void vSecureTCPClientTask( void *pvParameters )
\r
91 SOCKET xClientSocket;
\r
92 struct sockaddr_in xConnection;
\r
93 CYASSL* xCyaSSL_Object;
\r
94 WORD wVersionRequested;
\r
96 uint8_t cString[ 50 ];
\r
97 portBASE_TYPE lReturned;
\r
98 uint32_t ulCount = 0UL;
\r
100 /* Remove compiler warning about unused parameters. */
\r
101 ( void ) pvParameters;
\r
103 /* Prepare to use WinSock. */
\r
104 wVersionRequested = MAKEWORD( 2, 2 );
\r
105 configASSERT( WSAStartup( wVersionRequested, &xWSAData ) == 0 );
\r
107 /* Set family and port for client socket. */
\r
108 memset( ( void * ) &xConnection, 0x00, sizeof( struct sockaddr_in ) );
\r
109 xConnection.sin_family = AF_INET;
\r
110 xConnection.sin_addr.s_addr = inet_addr("127.0.0.1");
\r
111 xConnection.sin_port = htons( configTCP_PORT_NUMBER );
\r
113 /* Attempt to create a context that uses the TLS V1 server protocol. */
\r
114 xCyaSSL_ClientContext = CyaSSL_CTX_new( CyaTLSv1_client_method() );
\r
115 configASSERT( xCyaSSL_ClientContext );
\r
117 /* Load the CA certificate. */
\r
118 lReturned = CyaSSL_CTX_load_verify_locations( xCyaSSL_ClientContext, "ca-cert.pem", 0 );
\r
119 configASSERT( lReturned == SSL_SUCCESS );
\r
123 /* Create the socket. */
\r
124 xClientSocket = socket( AF_INET, SOCK_STREAM, 0 );
\r
125 configASSERT( xClientSocket != INVALID_SOCKET );
\r
127 /* Connect to the secure server. */
\r
128 if( connect( xClientSocket, ( SOCKADDR * ) &xConnection, sizeof( xConnection ) ) == 0 )
\r
130 /* The connect was successful. Create a CyaSSL object to associate
\r
131 with this connection. */
\r
132 xCyaSSL_Object = CyaSSL_new( xCyaSSL_ClientContext );
\r
134 if( xCyaSSL_Object != NULL )
\r
136 /* Associate the created CyaSSL object with the connected
\r
138 lReturned = CyaSSL_set_fd( xCyaSSL_Object, xClientSocket );
\r
139 configASSERT( lReturned == SSL_SUCCESS );
\r
141 /* The count is used to differentiate between messages sent to
\r
142 the server, and to break out of the do while loop below. */
\r
147 /* Create the string that is sent to the secure server. */
\r
148 sprintf( ( char * ) cString, "Message number %lu\r\n", ulCount );
\r
150 /* The next line is the secure equivalent of the standard
\r
152 lReturned = send( xClientSocket, cString, strlen( cString ) + 1, 0 ); */
\r
153 lReturned = CyaSSL_write( xCyaSSL_Object, ( const char * ) cString, strlen( ( const char * ) cString ) + 1 );
\r
156 /* Short delay to prevent the messages streaming up the
\r
157 console too quickly. */
\r
161 } while( ( lReturned != SOCKET_ERROR ) && ( ulCount < 10UL ) );
\r
164 CyaSSL_free( xCyaSSL_Object );
\r
165 closesocket( xClientSocket );
\r
167 /* Delay for a short time before starting over. */
\r
172 /*-----------------------------------------------------------*/
\r