| 62 | |
| 63 | |
| 64 | void client_test(void* args) |
| 65 | { |
| 66 | #ifdef _WIN32 |
| 67 | WSADATA wsd; |
| 68 | WSAStartup(0x0002, &wsd); |
| 69 | #endif |
| 70 | |
| 71 | SOCKET_T sockfd = 0; |
| 72 | int argc = 0; |
| 73 | char** argv = 0; |
| 74 | |
| 75 | set_args(argc, argv, *static_cast<func_args*>(args)); |
| 76 | tcp_connect(sockfd); |
| 77 | #ifdef NON_BLOCKING |
| 78 | tcp_set_nonblocking(sockfd); |
| 79 | #endif |
| 80 | SSL_METHOD* method = TLSv1_client_method(); |
| 81 | SSL_CTX* ctx = SSL_CTX_new(method); |
| 82 | |
| 83 | set_certs(ctx); |
| 84 | if (argc >= 2) { |
| 85 | printf("setting cipher list to %s\n", argv[1]); |
| 86 | if (SSL_CTX_set_cipher_list(ctx, argv[1]) != SSL_SUCCESS) { |
| 87 | ClientError(ctx, NULL, sockfd, "set_cipher_list error\n"); |
| 88 | } |
| 89 | } |
| 90 | SSL* ssl = SSL_new(ctx); |
| 91 | |
| 92 | SSL_set_fd(ssl, sockfd); |
| 93 | |
| 94 | |
| 95 | #ifdef NON_BLOCKING |
| 96 | NonBlockingSSL_Connect(ssl, ctx, sockfd); |
| 97 | #else |
| 98 | // if you get an error here see note at top of README |
| 99 | if (SSL_connect(ssl) != SSL_SUCCESS) |
| 100 | ClientError(ctx, ssl, sockfd, "SSL_connect failed"); |
| 101 | #endif |
| 102 | showPeer(ssl); |
| 103 | |
| 104 | const char* cipher = 0; |
| 105 | int index = 0; |
| 106 | char list[1024]; |
| 107 | strncpy(list, "cipherlist", 11); |
| 108 | while ( (cipher = SSL_get_cipher_list(ssl, index++)) ) { |
| 109 | strncat(list, ":", 2); |
| 110 | strncat(list, cipher, strlen(cipher) + 1); |
| 111 | } |
| 112 | printf("%s\n", list); |
| 113 | printf("Using Cipher Suite: %s\n", SSL_get_cipher(ssl)); |
| 114 | |
| 115 | char msg[] = "hello yassl!"; |
| 116 | if (SSL_write(ssl, msg, sizeof(msg)) != sizeof(msg)) |
| 117 | ClientError(ctx, ssl, sockfd, "SSL_write failed"); |
| 118 | |
| 119 | char reply[1024]; |
| 120 | int input = SSL_read(ssl, reply, sizeof(reply)); |
| 121 | if (input > 0) { |