3 * Copyright (C) 2006-2015 wolfSSL Inc.
5 * This file is part of wolfSSL. (formerly known as CyaSSL)
7 * wolfSSL is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * wolfSSL is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26 #include <cyassl/ctaocrypt/settings.h>
28 /* let's use cyassl layer AND cyassl openssl layer */
29 #include <cyassl/ssl.h>
30 #include <cyassl/openssl/ssl.h>
32 #if defined(CYASSL_MDK_ARM)
36 #if defined(CYASSL_MDK5)
44 #include "cyassl_MDK_ARM.h"
47 #include <cyassl/test.h>
49 #include "examples/echoclient/echoclient.h"
51 void echoclient_test(void* args)
64 SSL_METHOD* method = 0;
73 word16 port = yasslPort;
75 ((func_args*)args)->return_code = -1; /* error state */
77 #ifndef CYASSL_MDK_SHELL
78 argc = ((func_args*)args)->argc;
79 argv = ((func_args*)args)->argv;
83 fin = fopen(argv[1], "r");
87 fout = fopen(argv[2], "w");
91 if (!fin) err_sys("can't open input file");
92 if (!fout) err_sys("can't open output file");
102 #if defined(NO_RSA) && !defined(HAVE_ECC)
106 #if defined(NO_MAIN_DRIVER) && !defined(USE_WINDOWS_API) && !defined(CYASSL_MDK_SHELL)
107 port = ((func_args*)args)->signal->port;
110 #if defined(CYASSL_DTLS)
111 method = DTLSv1_2_client_method();
112 #elif !defined(NO_TLS)
113 method = CyaSSLv23_client_method();
115 method = SSLv3_client_method();
117 ctx = SSL_CTX_new(method);
119 #ifndef NO_FILESYSTEM
121 if (SSL_CTX_load_verify_locations(ctx, caCert, 0) != SSL_SUCCESS)
122 err_sys("can't load ca file, Please run from wolfSSL home dir");
125 if (SSL_CTX_load_verify_locations(ctx, eccCert, 0) != SSL_SUCCESS)
126 err_sys("can't load ca file, Please run from wolfSSL home dir");
128 #elif !defined(NO_CERTS)
130 load_buffer(ctx, caCert, CYASSL_CA);
133 #if defined(CYASSL_SNIFFER)
134 /* don't use EDH, can't sniff tmp keys */
135 SSL_CTX_set_cipher_list(ctx, "AES256-SHA");
139 const char *defaultCipherList;
141 CyaSSL_CTX_set_psk_client_callback(ctx, my_psk_client_cb);
142 #ifdef HAVE_NULL_CIPHER
143 defaultCipherList = "PSK-NULL-SHA256";
145 defaultCipherList = "PSK-AES128-CBC-SHA256";
147 if (CyaSSL_CTX_set_cipher_list(ctx,defaultCipherList) !=SSL_SUCCESS)
148 err_sys("client can't set cipher list 2");
152 #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
153 SSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
156 #if defined(CYASSL_MDK_ARM)
157 CyaSSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0);
164 build_addr(&addr, yasslIP, port, 1);
165 CyaSSL_dtls_set_peer(ssl, &addr, sizeof(addr));
166 tcp_socket(&sockfd, 1);
169 tcp_connect(&sockfd, yasslIP, port, 0);
172 SSL_set_fd(ssl, sockfd);
173 #if defined(USE_WINDOWS_API) && defined(CYASSL_DTLS) && defined(NO_MAIN_DRIVER)
174 /* let echoserver bind first, TODO: add Windows signal like pthreads does */
178 if (SSL_connect(ssl) != SSL_SUCCESS) err_sys("SSL_connect failed");
180 while (fgets(msg, sizeof(msg), fin) != 0) {
182 sendSz = (int)strlen(msg);
184 if (SSL_write(ssl, msg, sendSz) != sendSz)
185 err_sys("SSL_write failed");
187 if (strncmp(msg, "quit", 4) == 0) {
188 fputs("sending server shutdown command: quit!\n", fout);
192 if (strncmp(msg, "break", 5) == 0) {
193 fputs("sending server session close: break!\n", fout);
197 #ifndef CYASSL_MDK_SHELL
200 if ( (got = SSL_read(ssl, reply, sizeof(reply)-1)) > 0) {
212 if ( (got = SSL_read(ssl, reply, sizeof(reply)-1)) > 0) {
224 strncpy(msg, "break", 6);
225 sendSz = (int)strlen(msg);
226 /* try to tell server done */
227 SSL_write(ssl, msg, sendSz);
236 if (inCreated) fclose(fin);
237 if (outCreated) fclose(fout);
240 ((func_args*)args)->return_code = 0;
244 /* so overall tests can pull in test function */
245 #ifndef NO_MAIN_DRIVER
247 int main(int argc, char** argv)
252 int ret = OpenNitroxDevice(CAVIUM_DIRECT, CAVIUM_DEV_ID);
254 err_sys("Cavium OpenNitroxDevice failed");
255 #endif /* HAVE_CAVIUM */
263 #if defined(DEBUG_CYASSL) && !defined(CYASSL_MDK_SHELL)
264 CyaSSL_Debugging_ON();
266 #ifndef CYASSL_TIRTOS
267 if (CurrentDir("echoclient"))
269 else if (CurrentDir("Debug") || CurrentDir("Release"))
272 echoclient_test(&args);
277 CspShutdown(CAVIUM_DEV_ID);
279 return args.return_code;
282 #endif /* NO_MAIN_DRIVER */