1
/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16
#include <my_global.h>
17
#if defined(HAVE_OPENSSL)
24
#include <my_getopt.h>
28
const char *VER="0.2";
32
const char *default_dbug_option="d:t:O,-";
36
fatal_error( const char* r)
45
printf("viossl-test: testing SSL virtual IO. Usage:\n");
46
printf("viossl-test server-key server-cert client-key client-cert [CAfile] [CApath]\n");
51
main(int argc, char** argv)
53
char* server_key = 0, *server_cert = 0;
54
char* client_key = 0, *client_cert = 0;
55
char* ca_file = 0, *ca_path = 0;
59
struct st_VioSSLFd* ssl_acceptor= 0;
60
struct st_VioSSLFd* ssl_connector= 0;
61
Vio* client_vio=0, *server_vio=0;
62
enum enum_ssl_init_error ssl_init_error;
63
unsigned long ssl_error;
66
DBUG_PROCESS(argv[0]);
67
DBUG_PUSH(default_dbug_option);
76
server_cert = argv[2];
78
client_cert = argv[4];
83
printf("Server key/cert : %s/%s\n", server_key, server_cert);
84
printf("Client key/cert : %s/%s\n", client_key, client_cert);
86
printf("CAfile : %s\n", ca_file);
88
printf("CApath : %s\n", ca_path);
91
if (socketpair(PF_UNIX, SOCK_STREAM, IPPROTO_IP, sv)==-1)
92
fatal_error("socketpair");
94
ssl_acceptor = new_VioSSLAcceptorFd(server_key, server_cert, ca_file,
96
ssl_connector = new_VioSSLConnectorFd(client_key, client_cert, ca_file,
97
ca_path, cipher, &ssl_init_error);
99
client_vio = (struct st_vio*)my_malloc(sizeof(struct st_vio),MYF(0));
100
client_vio->sd = sv[0];
101
client_vio->vioblocking(client_vio, 0, &unused);
102
sslconnect(ssl_connector,client_vio,60L,&ssl_error);
103
server_vio = (struct st_vio*)my_malloc(sizeof(struct st_vio),MYF(0));
104
server_vio->sd = sv[1];
105
server_vio->vioblocking(client_vio, 0, &unused);
106
sslaccept(ssl_acceptor,server_vio,60L, &ssl_error);
108
printf("Socketpair: %d , %d\n", client_vio->sd, server_vio->sd);
112
my_free(ssl_acceptor);
113
my_free(ssl_connector);
118
/* child, therefore, client */
120
int r = vio_read(client_vio,xbuf, sizeof(xbuf));
122
my_free(ssl_acceptor);
123
my_free(ssl_connector);
124
fatal_error("client:SSL_read");
127
printf("client:got %s\n", xbuf);
129
my_free(ssl_acceptor);
130
my_free(ssl_connector);
134
const char* s = "Huhuhuh";
135
int r = vio_write(server_vio,(uchar*)s, strlen(s));
137
my_free(ssl_acceptor);
138
my_free(ssl_connector);
139
fatal_error("server:SSL_write");
142
my_free(ssl_acceptor);
143
my_free(ssl_connector);
147
#else /* HAVE_OPENSSL */
152
#endif /* HAVE_OPENSSL */