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