Top urgentWho can do me a favor?Please offer the source of SSL of the example for MySQL via Remark:please don't translate aboves to chinese stupidly.the reply would be good,you should get the bonus extra.Thank you for your browsing.

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/05 06:31:35

Top urgentWho can do me a favor?Please offer the source of SSL of the example for MySQL via Remark:please don't translate aboves to chinese stupidly.the reply would be good,you should get the bonus extra.Thank you for your browsing.
Top urgent
Who can do me a favor?Please offer the source of SSL of the example for MySQL via
Remark:please don't translate aboves to chinese stupidly.the reply would be good,you should get the bonus extra.Thank you for your browsing.

Top urgentWho can do me a favor?Please offer the source of SSL of the example for MySQL via Remark:please don't translate aboves to chinese stupidly.the reply would be good,you should get the bonus extra.Thank you for your browsing.
the importance is the latest mysql not yet support the SSL in windows platform.This means its SSL just support unix platform.
Note my source is verbose as following while you feel free:
#include
#include
#include
#include
static char *opt_host_name=NULL;
static char *opt_user_name=NULL;
static char *opt_password=NULL;
static unsigned int opt_port_num=0;
static char *opt_socket_name=NULL;
static char *opt_db_name=NULL;
static unsigned int opt_flags=0;
static MYSQL *conn;
static const char *client_groups[]={"client',NULL};
static struct my_option my_opts[]={
{"help",',"Display this help and exit",NULL,NULL,NULL,GET_NO_ARG,NO_ARG,0,0,0,0,0,0},
{"host",'h',"Host to connect to",(gptr *) &opt_host_name,NULL,NULL,GET_STR_ALLOC,REQUIRED_ARG,0,0,0,0,0,0}'
{"password",'p',"Password",(gptr *) &opt_password,NULL,NULL,GET_STR_ALLOC,OPT_ARG,0,0,0,0,0,0},
{"port",'P',"Port number",(gptr *) &opt_port_num,NULL,NULL,GET_UINT,REQUIRED_ARG,0,0,0,0,0,0},
{"SOCKET",'S',"Socket path",(gptr *) &opt_socket_name,NULL,NULL,GET_UINT,REQUIRED_ARG,0,0,0,0,0,0},
{"user",'u',"User name",(gptr *) &opt_user_name,NULL,NULL,GET_UINT,REQUIRED_ARG,0,0,0,0,0,0}
};
void
print_error(MYSQL *conn,char *message)
{
fprintf(stderr,"%s\n",message);
if (conn!=NULL)
{
fprintf(stderr,"Error %u (%s)\n"'mysql_errno(conn),mysql_error(conn));
}
}
my_bool
get_one_option(int optid,const struct my_option *opt,char *argument)
{
switch(optid)
{
case'?':
my_print_help(my_opt);
exit(0);
case'p':
if(!argument)
ask_password=1;
else
{
opt_password=strdup(argument);
if(opt_password==NULL)
{
print_error(NULL,"could not allocate password buffer");
exit(1);
}
while(*argument)
*argument++='x';
}
break;
#include
}
return(0);
}
int
main(int argc,char *argv[])
{
int opt_err;
my_init();
load_defaults("my",client_groups,&argc,&argv);
if((opt_err=handle_options(&argc,&argv,my_opts,get_one_option)))
exit(opt_err);
if(ask_password)
opt_password=get_tty_password(NULL);
if(argc>0)
{
opt_db_name=argv[0];
--argc;==argv;
}
conn=mysql_init(NULL);
if(conn==NULL)
{
print_error(NULL,"mysql_init() dailed(probably out of memory)");
exit(1);
}
if(mysql_real_connect(conn,opt_host_name,opt_user_name,opt_password,opt_db_name,opt_port_num,opt_socket_name,opt_flags)==NULL)
{
print_error(conn,"mysql_real_connect() failed");
mysql_close(conn);
exit(1);
}
mysql_close(conn);
exit(0);
}
#include
{NULL,0,NULL,NULL,NULL,NULL,GET_NO_ARG,NO_ARG,0,0,0,0,0,0}
};
#ifdef HAVE_OPENSSL
{"ssl",OPT_SLL_SLL,"Enable SSL for connection.Disable with --skip-sll",(gptr*) &opt_use_ssl,NULL,0,GET_BOOL,NO_ARG,0,0,0,0,0,0},
{"ssl-key",OPT_SSL_CERT,"X509 key in PEM format(implies --ssl)",(gptr*) &opt_ssl_key,NULL,0,GET_STR,REQUIRED_ARG,0,0,0,0,0,0},
{"ssl-cert",OPT_SSL_CERT,"X509 cert in PEM format(implies --ssl)",(gptr*) &opt_ssl_cert,NULL,0,GET_STR,REQUIRED_ARG,0,0,0,0,0,0},
{"ssl-ca",OPT_SSL_CA,"CA file in PEM format(check openSSL docs,implies --sl)",(gptr*) &opt_ssl_ca,NULL,0,GET_STR,REQUIRED_ARG,0,0,0,0,0,0},
{"ssl-capath",OPT_SSL_CAPATH,"CA direcory(check openSSL docs,implies --sl)",(gptr*) &opt_ssl_capath,NULL,0,GET_STR,REQUIRED_ARG,0,0,0,0,0,0},
{"ssl-cipher",OPT_SSL_CIPHER,"SSLcipher to use(implies --ssl)",(gptr*) &opt_ssl_cipher,NULL,0,GET_STR,REQUIRED_ARG,0,0,0,0,0,0},
#endif
#ifdef HAVE_OPENSSL
eum options
{
OPT_SSL_SSL=256,
OPT_SSL_KEY'
OPT_SSL_CERT,
OPT_SSL_CA,
OPT_SSL_CAPATH,
OPT_SSL_CIPHER
};
#endif
#ifdef HAVE_OPENSSL
static my bool opt_use_ssl=0;
static char *opt_ssl_key=0;
static char *opt_ssl_cert=0;
static char *opt_ssl_ca=0;
static char *opt_ssl_capath=0;
static char *opt_ssl_cipher=0;
#endif
#ifdef HAVE_OPENSSL
case OPT_SSL_KEY:
case OPT_SSL_CERT:
case OPT_SSL_CA:
case OPT_SSL_CAPATH:
case OPT_SSL_CIPHER:
opt_use_ssl=1;
break
#endif
Now put following source to the program sslclient:
conn=mysql_init(NULL);
if(conn==NULL)
{
print_error(NULL,"mysql_init() failed(probably out of memory)");
exit(1);
}
#ifdef HAVE_OPENSSL
if(opt_use_ssl)
mysql_ssl_set(conn,opt_ssl_key,opt_ssl_cert,opt_ssl_ca,opt_ssl_capath,opt_ssl_cipher);
#endif
if(mysql_real_connect(conn,opt_host_name,opt_user_name,_opt_password,opt_db_name,opt_port_num,opt_socket_name,opt_flags)==NULL)
{
print_error(conn,"mysql_real_connect() failed");
mysql_close(conn);
exit(1);
}

00001 /* Copyright (C) 2000 MySQL AB
00002
00003 This program is free software; you can redistribute it and/or modify
00004 it under the terms of the GNU General Public License as p...

全部展开

00001 /* Copyright (C) 2000 MySQL AB
00002
00003 This program is free software; you can redistribute it and/or modify
00004 it under the terms of the GNU General Public License as published by
00005 the Free Software Foundation; either version 2 of the License, or
00006 (at your option) any later version.
00007
00008 This program is distributed in the hope that it will be useful,
00009 but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00011 GNU General Public License for more details.
00012
00013 You should have received a copy of the GNU General Public License
00014 along with this program; if not, write to the Free Software
00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
00016
00017 #include
00018 #if defined(HAVE_OPENSSL) && !defined(__NETWARE__)
00019 #include
00020 #include
00021 #include
00022 #include "mysql.h"
00023 #include "errmsg.h"
00024 #include
00025 #include
00026 #include
00027 #include
00028
00029 const char *VER="0.2";
00030
00031
00032 #ifndef DBUG_OFF
00033 const char *default_dbug_option="d:t:O,-";
00034 #endif
00035
00036 void
00037 fatal_error( const char* r)
00038 {
00039 perror(r);
00040 exit(0);
00041 }
00042
00043 void
00044 print_usage()
00045 {
00046 printf("viossl-test: testing SSL virtual IO. Usage:\n");
00047 printf("viossl-test server-key server-cert client-key client-cert [CAfile] [CApath]\n");
00048 }
00049
00050
00051 int
00052 main(int argc, char** argv)
00053 {
00054 char* server_key = 0, *server_cert = 0;
00055 char* client_key = 0, *client_cert = 0;
00056 char* ca_file = 0, *ca_path = 0;
00057 char* cipher=0;
00058 int child_pid,sv[2];
00059 my_bool unused;
00060 struct st_VioSSLAcceptorFd* ssl_acceptor=0;
00061 struct st_VioSSLConnectorFd* ssl_connector=0;
00062 Vio* client_vio=0, *server_vio=0;
00063 MY_INIT(argv[0]);
00064 DBUG_PROCESS(argv[0]);
00065 DBUG_PUSH(default_dbug_option);
00066
00067 if (argc<5)
00068 {
00069 print_usage();
00070 return 1;
00071 }
00072
00073 server_key = argv[1];
00074 server_cert = argv[2];
00075 client_key = argv[3];
00076 client_cert = argv[4];
00077 if (argc>5)
00078 ca_file = argv[5];
00079 if (argc>6)
00080 ca_path = argv[6];
00081 printf("Server key/cert : %s/%s\n", server_key, server_cert);
00082 printf("Client key/cert : %s/%s\n", client_key, client_cert);
00083 if (ca_file!=0)
00084 printf("CAfile : %s\n", ca_file);
00085 if (ca_path!=0)
00086 printf("CApath : %s\n", ca_path);
00087
00088
00089 if (socketpair(PF_UNIX, SOCK_STREAM, IPPROTO_IP, sv)==-1)
00090 fatal_error("socketpair");
00091
00092 ssl_acceptor = new_VioSSLAcceptorFd(server_key, server_cert, ca_file,
00093 ca_path, cipher);
00094 ssl_connector = new_VioSSLConnectorFd(client_key, client_cert, ca_file,
00095 ca_path, cipher);
00096
00097 client_vio = (struct st_vio*)my_malloc(sizeof(struct st_vio),MYF(0));
00098 client_vio->sd = sv[0];
00099 client_vio->vioblocking(client_vio, 0, &unused);
00100 sslconnect(ssl_connector,client_vio,60L);
00101 server_vio = (struct st_vio*)my_malloc(sizeof(struct st_vio),MYF(0));
00102 server_vio->sd = sv[1];
00103 server_vio->vioblocking(client_vio, 0, &unused);
00104 sslaccept(ssl_acceptor,server_vio,60L);
00105
00106 printf("Socketpair: %d , %d\n", client_vio->sd, server_vio->sd);
00107
00108 child_pid = fork();
00109 if (child_pid==-1) {
00110 my_free((gptr)ssl_acceptor,MYF(0));
00111 my_free((gptr)ssl_connector,MYF(0));
00112 fatal_error("fork");
00113 }
00114 if (child_pid==0)
00115 {
00116 /* child, therefore, client */
00117 char xbuf[100];
00118 int r = vio_read(client_vio,xbuf, sizeof(xbuf));
00119 if (r<=0) {
00120 my_free((gptr)ssl_acceptor,MYF(0));
00121 my_free((gptr)ssl_connector,MYF(0));
00122 fatal_error("client:SSL_read");
00123 }
00124 xbuf[r] = 0;
00125 printf("client:got %s\n", xbuf);
00126 my_free((gptr)client_vio,MYF(0));
00127 my_free((gptr)ssl_acceptor,MYF(0));
00128 my_free((gptr)ssl_connector,MYF(0));
00129 }
00130 else
00131 {
00132 const char* s = "Huhuhuh";
00133 int r = vio_write(server_vio,(gptr)s, strlen(s));
00134 if (r<=0) {
00135 my_free((gptr)ssl_acceptor,MYF(0));
00136 my_free((gptr)ssl_connector,MYF(0));
00137 fatal_error("server:SSL_write");
00138 }
00139 my_free((gptr)server_vio,MYF(0));
00140 my_free((gptr)ssl_acceptor,MYF(0));
00141 my_free((gptr)ssl_connector,MYF(0));
00142 }
00143 return 0;
00144 }
00145 #else /* HAVE_OPENSSL */
00146
00147 int main() {
00148 return 0;
00149 }
00150 #endif /* HAVE_OPENSSL */

收起

are you so crazy ?go and buy any computer