22 #include "../../testsuite/test.hpp"
25 void ServerError(
SSL_CTX* ctx,
SSL* ssl, SOCKET_T& sockfd,
const char*
msg)
35 void NonBlockingSSL_Accept(
SSL* ssl,
SSL_CTX* ctx, SOCKET_T& clientfd)
37 int ret = SSL_accept(ssl);
38 int err = SSL_get_error(ssl, 0);
39 while (ret != SSL_SUCCESS && (err == SSL_ERROR_WANT_READ ||
40 err == SSL_ERROR_WANT_WRITE)) {
41 if (err == SSL_ERROR_WANT_READ)
42 printf(
"... server would read block\n");
44 printf(
"... server would write block\n");
50 ret = SSL_accept(ssl);
51 err = SSL_get_error(ssl, 0);
53 if (ret != SSL_SUCCESS)
54 ServerError(ctx, ssl, clientfd,
"SSL_accept failed");
59 THREAD_RETURN YASSL_API server_test(
void* args)
63 WSAStartup(0x0002, &wsd);
67 SOCKET_T clientfd = 0;
71 set_args(argc, argv, *static_cast<func_args*>(args));
72 tcp_accept(sockfd, clientfd, *static_cast<func_args*>(args));
77 SSL_CTX* ctx = SSL_CTX_new(method);
80 SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, 0);
82 DH* dh = set_tmpDH(ctx);
84 SSL* ssl = SSL_new(ctx);
85 SSL_set_fd(ssl, clientfd);
88 NonBlockingSSL_Accept(ssl, ctx, clientfd);
90 if (SSL_accept(ssl) != SSL_SUCCESS)
91 ServerError(ctx, ssl, clientfd,
"SSL_accept failed");
95 printf(
"Using Cipher Suite: %s\n", SSL_get_cipher(ssl));
98 int input = SSL_read(ssl, command,
sizeof(command));
101 printf(
"First client command: %s\n", command);
104 char msg[] =
"I hear you, fa shizzle!";
105 if (SSL_write(ssl, msg,
sizeof(msg)) !=
sizeof(msg))
106 ServerError(ctx, ssl, clientfd,
"SSL_write failed");
120 #ifndef NO_MAIN_DRIVER
122 int main(
int argc,
char** argv)
132 return args.return_code;
135 #endif // NO_MAIN_DRIVER