16 #include <my_global.h>
24 #include <my_getopt.h>
28 const char *VER=
"0.2";
32 const char *default_dbug_option=
"d:t:O,/tmp/viotest-ssl.trace";
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");
50 int main(
int argc,
char **argv)
53 char* server_cert = 0;
55 char* client_cert = 0;
59 struct st_VioSSLAcceptorFd* ssl_acceptor=0;
60 struct st_VioSSLConnectorFd* ssl_connector=0;
63 enum enum_ssl_init_error ssl_init_error;
64 unsigned long ssl_error;
67 DBUG_PROCESS(argv[0]);
68 DBUG_PUSH(default_dbug_option);
77 server_cert = argv[2];
79 client_cert = argv[4];
84 printf(
"Server key/cert : %s/%s\n", server_key, server_cert);
85 printf(
"Client key/cert : %s/%s\n", client_key, client_cert);
87 printf(
"CAfile : %s\n", ca_file);
89 printf(
"CApath : %s\n", ca_path);
92 if (socketpair(PF_UNIX, SOCK_STREAM, IPPROTO_IP, sv)==-1)
93 fatal_error(
"socketpair");
95 ssl_acceptor = new_VioSSLAcceptorFd(server_key, server_cert, ca_file,
97 ssl_connector = new_VioSSLConnectorFd(client_key, client_cert, ca_file,
98 ca_path, &ssl_init_error);
100 client_vio = (
Vio*)my_malloc(
sizeof(
struct st_vio),MYF(0));
101 client_vio->sd = sv[0];
102 sslconnect(ssl_connector,client_vio,&ssl_error);
103 server_vio = (
Vio*)my_malloc(
sizeof(
struct st_vio),MYF(0));
104 server_vio->sd = sv[1];
105 sslaccept(ssl_acceptor,server_vio,&ssl_error);
107 printf(
"Socketpair: %d , %d\n", client_vio->sd, server_vio->sd);
112 my_free(ssl_acceptor);
113 my_free(ssl_connector);
120 int r = vio_ssl_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);
135 const char* s =
"Huhuhuh";
136 int r = vio_ssl_write(server_vio,(uchar*)s, strlen(s));
138 my_free(ssl_acceptor);
139 my_free(ssl_connector);
140 fatal_error(
"server:SSL_write");
143 my_free(ssl_acceptor);
144 my_free(ssl_connector);