| 60 | |
| 61 | |
| 62 | THREAD_RETURN YASSL_API server_test(void* args) |
| 63 | { |
| 64 | #ifdef _WIN32 |
| 65 | WSADATA wsd; |
| 66 | WSAStartup(0x0002, &wsd); |
| 67 | #endif |
| 68 | |
| 69 | SOCKET_T sockfd = 0; |
| 70 | SOCKET_T clientfd = 0; |
| 71 | int argc = 0; |
| 72 | char** argv = 0; |
| 73 | |
| 74 | set_args(argc, argv, *static_cast<func_args*>(args)); |
| 75 | #ifdef SERVER_READY_FILE |
| 76 | set_file_ready("server_ready", *static_cast<func_args*>(args)); |
| 77 | #endif |
| 78 | tcp_accept(sockfd, clientfd, *static_cast<func_args*>(args)); |
| 79 | |
| 80 | tcp_close(sockfd); |
| 81 | |
| 82 | SSL_METHOD* method = TLSv1_server_method(); |
| 83 | SSL_CTX* ctx = SSL_CTX_new(method); |
| 84 | |
| 85 | //SSL_CTX_set_cipher_list(ctx, "RC4-SHA:RC4-MD5"); |
| 86 | |
| 87 | // should we disable client auth |
| 88 | if (argc >= 2 && argv[1][0] == 'n') |
| 89 | printf("disabling client auth\n"); |
| 90 | else |
| 91 | SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, 0); |
| 92 | |
| 93 | // are we using DSA certs |
| 94 | if (argc >= 3 && argv[2][0] == 'd') { |
| 95 | printf("using DSA certs\n"); |
| 96 | set_dsaServerCerts(ctx); |
| 97 | } |
| 98 | else { |
| 99 | set_serverCerts(ctx); |
| 100 | } |
| 101 | DH* dh = set_tmpDH(ctx); |
| 102 | |
| 103 | SSL* ssl = SSL_new(ctx); |
| 104 | SSL_set_fd(ssl, clientfd); |
| 105 | |
| 106 | #ifdef NON_BLOCKING |
| 107 | NonBlockingSSL_Accept(ssl, ctx, clientfd); |
| 108 | #else |
| 109 | if (SSL_accept(ssl) != SSL_SUCCESS) |
| 110 | ServerError(ctx, ssl, clientfd, "SSL_accept failed"); |
| 111 | #endif |
| 112 | |
| 113 | showPeer(ssl); |
| 114 | printf("Using Cipher Suite: %s\n", SSL_get_cipher(ssl)); |
| 115 | |
| 116 | char command[1024]; |
| 117 | int input = SSL_read(ssl, command, sizeof(command)); |
| 118 | if (input > 0) { |
| 119 | command[input] = 0; |
no test coverage detected