~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000 MySQL AB
2
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.
6
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.
11
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
16
#include <my_global.h>
17
#ifdef HAVE_OPENSSL
18
#include <my_sys.h>
19
#include <m_string.h>
20
#include <m_ctype.h>
21
#include "mysql.h"
22
#include "errmsg.h"
23
#include <my_dir.h>
24
#include <my_getopt.h>
25
#include <signal.h>
26
#include <violite.h>
27
28
const char *VER="0.2";
29
30
31
#ifndef DBUG_OFF
32
const char *default_dbug_option="d:t:O,-";
33
#endif
34
35
void
36
fatal_error(	const char*	r)
37
{
38
	perror(r);
39
	exit(0);
40
}
41
42
int
43
main(	int	argc __attribute__((unused)),
44
	char**	argv)
45
{
46
	char	client_key[] = "../SSL/client-key.pem",	client_cert[] = "../SSL/client-cert.pem";
47
	char	ca_file[] = "../SSL/cacert.pem",	*ca_path = 0, *cipher=0;
48
	struct st_VioSSLFd* ssl_connector= 0;
49
	struct sockaddr_in sa;
50
	Vio* client_vio=0;
51
	int err;
52
	char	xbuf[100]="Ohohhhhoh1234";
53
	MY_INIT(argv[0]);
54
        DBUG_PROCESS(argv[0]);
55
        DBUG_PUSH(default_dbug_option);
56
57
	printf("Client key/cert : %s/%s\n", client_key, client_cert);
58
	if (ca_file!=0)
59
		printf("CAfile          : %s\n", ca_file);
60
	if (ca_path!=0)
61
		printf("CApath          : %s\n", ca_path);
62
63
	ssl_connector = new_VioSSLConnectorFd(client_key, client_cert, ca_file, ca_path, cipher);
64
	if(!ssl_connector) {
65
                 fatal_error("client:new_VioSSLConnectorFd failed");
66
	}
67
68
	/* ----------------------------------------------- */
69
	/* Create a socket and connect to server using normal socket calls. */
70
71
	client_vio = vio_new(socket (AF_INET, SOCK_STREAM, 0), VIO_TYPE_TCPIP, TRUE);
72
73
	memset (&sa, '\0', sizeof(sa));
74
	sa.sin_family      = AF_INET;
75
	sa.sin_addr.s_addr = inet_addr ("127.0.0.1");   /* Server IP */
76
	sa.sin_port        = htons     (1111);          /* Server Port number */
77
78
	err = connect(client_vio->sd, (struct sockaddr*) &sa,
79
		sizeof(sa));
80
81
	/* ----------------------------------------------- */
82
	/* Now we have TCP conncetion. Start SSL negotiation. */
83
	read(client_vio->sd,xbuf, sizeof(xbuf));
84
        sslconnect(ssl_connector,client_vio,60L);
85
	err = vio_read(client_vio,xbuf, sizeof(xbuf));
86
	if (err<=0) {
87
		my_free((uchar*)ssl_connector,MYF(0));
88
		fatal_error("client:SSL_read");
89
	}
90
	xbuf[err] = 0;
91
	printf("client:got %s\n", xbuf);
92
	my_free((uchar*)client_vio,MYF(0));
93
	my_free((uchar*)ssl_connector,MYF(0));
94
	return 0;
95
}
96
#else /* HAVE_OPENSSL */
97
98
int main() {
99
return 0;
100
}
101
#endif /* HAVE_OPENSSL */