3 * Copyright (C) 2006-2012 Sawtooth Consulting Ltd.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
26 #include <cyassl/openssl/ssl.h>
27 #include <cyassl/test.h>
30 void echoclient_test(void* args)
43 SSL_METHOD* method = 0;
52 ((func_args*)args)->return_code = -1; /* error state */
53 argc = ((func_args*)args)->argc;
54 argv = ((func_args*)args)->argv;
57 fin = fopen(argv[1], "r");
61 fout = fopen(argv[2], "w");
65 if (!fin) err_sys("can't open input file");
66 if (!fout) err_sys("can't open output file");
72 tcp_connect(&sockfd, yasslIP, yasslPort, doDTLS);
74 #if defined(CYASSL_DTLS)
75 method = DTLSv1_client_method();
76 #elif !defined(NO_TLS)
77 method = CyaSSLv23_client_method();
79 method = SSLv3_client_method();
81 ctx = SSL_CTX_new(method);
84 if (SSL_CTX_load_verify_locations(ctx, caCert, 0) != SSL_SUCCESS)
85 err_sys("can't load ca file, Please run from CyaSSL home dir");
87 if (SSL_CTX_load_verify_locations(ctx, eccCert, 0) != SSL_SUCCESS)
88 err_sys("can't load ca file, Please run from CyaSSL home dir");
91 load_buffer(ctx, caCert, CYASSL_CA);
94 #if defined(CYASSL_SNIFFER) && !defined(HAVE_NTRU) && !defined(HAVE_ECC)
95 /* don't use EDH, can't sniff tmp keys */
96 SSL_CTX_set_cipher_list(ctx, "AES256-SHA");
100 SSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
104 SSL_set_fd(ssl, sockfd);
105 #if defined(USE_WINDOWS_API) && defined(CYASSL_DTLS) && defined(NO_MAIN_DRIVER)
106 /* let echoserver bind first, TODO: add Windows signal like pthreads does */
109 if (SSL_connect(ssl) != SSL_SUCCESS) err_sys("SSL_connect failed");
111 while (fgets(send, sizeof(send), fin)) {
113 sendSz = (int)strlen(send);
115 if (SSL_write(ssl, send, sendSz) != sendSz)
116 err_sys("SSL_write failed");
118 if (strncmp(send, "quit", 4) == 0) {
119 fputs("sending server shutdown command: quit!\n", fout);
123 if (strncmp(send, "break", 5) == 0) {
124 fputs("sending server session close: break!\n", fout);
130 if ( (got = SSL_read(ssl, reply, sizeof(reply))) > 0) {
141 strncpy(send, "break", 6);
142 sendSz = (int)strlen(send);
143 /* try to tell server done */
144 SSL_write(ssl, send, sendSz);
153 if (inCreated) fclose(fin);
154 if (outCreated) fclose(fout);
157 ((func_args*)args)->return_code = 0;
161 /* so overall tests can pull in test function */
162 #ifndef NO_MAIN_DRIVER
164 int main(int argc, char** argv)
175 CyaSSL_Debugging_ON();
177 if (CurrentDir("echoclient") || CurrentDir("build"))
179 echoclient_test(&args);
182 return args.return_code;
186 char* myoptarg = NULL;
188 #endif /* NO_MAIN_DRIVER */