3 * Copyright (C) 2006-2014 wolfSSL Inc.
5 * This file is part of CyaSSL.
7 * CyaSSL 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 * CyaSSL 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 #include <cyassl/openssl/ssl.h>
30 #if defined(CYASSL_MDK_ARM)
34 #if defined(CYASSL_MDK5)
42 #include "cyassl_MDK_ARM.h"
45 #include <cyassl/test.h>
47 #include "examples/echoclient/echoclient.h"
49 void echoclient_test(void* args)
62 SSL_METHOD* method = 0;
71 word16 port = yasslPort;
73 ((func_args*)args)->return_code = -1; /* error state */
75 #ifndef CYASSL_MDK_SHELL
76 argc = ((func_args*)args)->argc;
77 argv = ((func_args*)args)->argv;
81 fin = fopen(argv[1], "r");
85 fout = fopen(argv[2], "w");
89 if (!fin) err_sys("can't open input file");
90 if (!fout) err_sys("can't open output file");
100 #if defined(NO_RSA) && !defined(HAVE_ECC)
104 #if defined(NO_MAIN_DRIVER) && !defined(USE_WINDOWS_API) && !defined(CYASSL_MDK_SHELL)
105 port = ((func_args*)args)->signal->port;
108 #if defined(CYASSL_DTLS)
109 method = DTLSv1_client_method();
110 #elif !defined(NO_TLS)
111 method = CyaSSLv23_client_method();
113 method = SSLv3_client_method();
115 ctx = SSL_CTX_new(method);
117 #ifndef NO_FILESYSTEM
119 if (SSL_CTX_load_verify_locations(ctx, caCert, 0) != SSL_SUCCESS)
120 err_sys("can't load ca file, Please run from CyaSSL home dir");
123 if (SSL_CTX_load_verify_locations(ctx, eccCert, 0) != SSL_SUCCESS)
124 err_sys("can't load ca file, Please run from CyaSSL home dir");
126 #elif !defined(NO_CERTS)
128 load_buffer(ctx, caCert, CYASSL_CA);
131 #if defined(CYASSL_SNIFFER) && !defined(HAVE_NTRU) && !defined(HAVE_ECC)
132 /* don't use EDH, can't sniff tmp keys */
133 SSL_CTX_set_cipher_list(ctx, "AES256-SHA");
137 const char *defaultCipherList;
139 CyaSSL_CTX_set_psk_client_callback(ctx, my_psk_client_cb);
140 #ifdef HAVE_NULL_CIPHER
141 defaultCipherList = "PSK-NULL-SHA256";
143 defaultCipherList = "PSK-AES128-CBC-SHA256";
145 if (CyaSSL_CTX_set_cipher_list(ctx,defaultCipherList) !=SSL_SUCCESS)
146 err_sys("client can't set cipher list 2");
150 #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
151 SSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
154 #if defined(CYASSL_MDK_ARM)
155 CyaSSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0);
163 build_addr(&addr, yasslIP, port, 1);
164 CyaSSL_dtls_set_peer(ssl, &addr, sizeof(addr));
165 tcp_socket(&sockfd, 1);
168 tcp_connect(&sockfd, yasslIP, port, 0);
171 SSL_set_fd(ssl, sockfd);
172 #if defined(USE_WINDOWS_API) && defined(CYASSL_DTLS) && defined(NO_MAIN_DRIVER)
173 /* let echoserver bind first, TODO: add Windows signal like pthreads does */
177 if (SSL_connect(ssl) != SSL_SUCCESS) err_sys("SSL_connect failed");
179 while (fgets(msg, sizeof(msg), fin) != 0) {
181 sendSz = (int)strlen(msg);
183 if (SSL_write(ssl, msg, sendSz) != sendSz)
184 err_sys("SSL_write failed");
186 if (strncmp(msg, "quit", 4) == 0) {
187 fputs("sending server shutdown command: quit!\n", fout);
191 if (strncmp(msg, "break", 5) == 0) {
192 fputs("sending server session close: break!\n", fout);
196 #ifndef CYASSL_MDK_SHELL
199 if ( (got = SSL_read(ssl, reply, sizeof(reply)-1)) > 0) {
211 if ( (got = SSL_read(ssl, reply, sizeof(reply)-1)) > 0) {
223 strncpy(msg, "break", 6);
224 sendSz = (int)strlen(msg);
225 /* try to tell server done */
226 SSL_write(ssl, msg, sendSz);
235 if (inCreated) fclose(fin);
236 if (outCreated) fclose(fout);
239 ((func_args*)args)->return_code = 0;
243 /* so overall tests can pull in test function */
244 #ifndef NO_MAIN_DRIVER
246 int main(int argc, char** argv)
251 int ret = OpenNitroxDevice(CAVIUM_DIRECT, CAVIUM_DEV_ID);
253 err_sys("Cavium OpenNitroxDevice failed");
254 #endif /* HAVE_CAVIUM */
262 #if defined(DEBUG_CYASSL) && !defined(CYASSL_MDK_SHELL)
263 CyaSSL_Debugging_ON();
266 if (CurrentDir("echoclient"))
268 else if (CurrentDir("Debug") || CurrentDir("Release"))
270 echoclient_test(&args);
275 CspShutdown(CAVIUM_DEV_ID);
277 return args.return_code;
280 #endif /* NO_MAIN_DRIVER */