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"
26
void ClientError(SSL_CTX* ctx, SSL* ssl, SOCKET_T& sockfd, const char* msg)
36
void NonBlockingSSL_Connect(SSL* ssl, SSL_CTX* ctx, SOCKET_T& sockfd)
38
int ret = SSL_connect(ssl);
39
int err = SSL_get_error(ssl, 0);
40
while (ret != SSL_SUCCESS && (err == SSL_ERROR_WANT_READ ||
41
err == SSL_ERROR_WANT_WRITE)) {
42
if (err == SSL_ERROR_WANT_READ)
43
printf("... client would read block\n");
45
printf("... client would write block\n");
51
ret = SSL_connect(ssl);
52
err = SSL_get_error(ssl, 0);
54
if (ret != SSL_SUCCESS)
55
ClientError(ctx, ssl, sockfd, "SSL_connect failed");
60
void client_test(void* args)
64
WSAStartup(0x0002, &wsd);
71
set_args(argc, argv, *static_cast<func_args*>(args));
74
tcp_set_nonblocking(sockfd);
77
SSL_METHOD* method = TLSv1_client_method();
78
SSL_CTX* ctx = SSL_CTX_new(method);
81
SSL* ssl = SSL_new(ctx);
83
SSL_set_fd(ssl, sockfd);
87
NonBlockingSSL_Connect(ssl, ctx, sockfd);
89
// if you get an error here see note at top of README
90
if (SSL_connect(ssl) != SSL_SUCCESS)
91
ClientError(ctx, ssl, sockfd, "SSL_connect failed");
95
const char* cipher = 0;
98
strncpy(list, "cipherlist", 11);
99
while ( (cipher = SSL_get_cipher_list(ssl, index++)) ) {
100
strncat(list, ":", 2);
101
strncat(list, cipher, strlen(cipher) + 1);
103
printf("%s\n", list);
104
printf("Using Cipher Suite: %s\n", SSL_get_cipher(ssl));
106
char msg[] = "hello yassl!";
107
if (SSL_write(ssl, msg, sizeof(msg)) != sizeof(msg))
108
ClientError(ctx, ssl, sockfd, "SSL_write failed");
111
int input = SSL_read(ssl, reply, sizeof(reply));
114
printf("Server response: %s\n", reply);
118
SSL_SESSION* session = SSL_get_session(ssl);
119
SSL* sslResume = SSL_new(ctx);
128
SSL_set_fd(sslResume, sockfd);
129
SSL_set_session(sslResume, session);
131
if (SSL_connect(sslResume) != SSL_SUCCESS)
132
ClientError(ctx, sslResume, sockfd, "SSL_resume failed");
135
if (SSL_write(sslResume, msg, sizeof(msg)) != sizeof(msg))
136
ClientError(ctx, sslResume, sockfd, "SSL_write failed");
138
input = SSL_read(sslResume, reply, sizeof(reply));
141
printf("Server response: %s\n", reply);
144
SSL_shutdown(sslResume);
147
#endif // TEST_RESUME
150
((func_args*)args)->return_code = 0;
154
#ifndef NO_MAIN_DRIVER
156
int main(int argc, char** argv)
166
return args.return_code;
169
#endif // NO_MAIN_DRIVER