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);
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);
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);
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
154 #ifndef NO_MAIN_DRIVER
156 int main(
int argc,
char** argv)
166 return args.return_code;
169 #endif // NO_MAIN_DRIVER