2
Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; version 2 of the License.
8
This program is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License
14
along with this program; see the file COPYING. If not, write to the
15
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
21
#include "../../testsuite/test.hpp"
24
void EchoClientError(SSL_CTX* ctx, SSL* ssl, SOCKET_T& sockfd, const char* msg)
33
void echoclient_test(void* args)
37
WSAStartup(0x0002, &wsd);
47
bool inCreated = false;
48
bool outCreated = false;
50
set_args(argc, argv, *static_cast<func_args*>(args));
52
fin = fopen(argv[1], "r");
56
fout = fopen(argv[2], "w");
60
if (!fin) err_sys("can't open input file");
61
if (!fout) err_sys("can't open output file");
65
SSL_METHOD* method = SSLv23_client_method();
66
SSL_CTX* ctx = SSL_CTX_new(method);
68
SSL* ssl = SSL_new(ctx);
70
SSL_set_fd(ssl, sockfd);
72
if (SSL_connect(ssl) != SSL_SUCCESS)
73
EchoClientError(ctx, ssl, sockfd, "SSL_connect failed");
78
while (fgets(send, sizeof(send), fin)) {
80
int sendSz = (int)strlen(send) + 1;
81
if (SSL_write(ssl, send, sendSz) != sendSz)
82
EchoClientError(ctx, ssl, sockfd, "SSL_write failed");
84
if (strncmp(send, "quit", 4) == 0) {
85
fputs("sending server shutdown command: quit!\n", fout);
89
if (SSL_read(ssl, reply, sizeof(reply)) > 0)
98
if (inCreated) fclose(fin);
99
if (outCreated) fclose(fout);
101
((func_args*)args)->return_code = 0;
105
#ifndef NO_MAIN_DRIVER
107
int main(int argc, char** argv)
114
echoclient_test(&args);
117
return args.return_code;
120
#endif // NO_MAIN_DRIVER