问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

Top urgent

发布网友 发布时间:2022-04-24 20:15

我来回答

3个回答

热心网友 时间:2023-08-23 23:23

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<string.h>
#include<my_global.h>
#include<mysql.h>
#include<my_getopt.h>

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=strp(argument);
if(opt_password==NULL)
{
print_error(NULL,"could not allocate password buffer");
exit(1);
}
while(*argument)
*argument++='x';
}
break;
#include <sslopt-case.h>
}
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<sslopt-longopts.h>
{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);
}

参考资料:http://www.mysql.org

热心网友 时间:2023-08-23 23:23

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 <my_global.h>
00018 #if defined(HAVE_OPENSSL) && !defined(__NETWARE__)
00019 #include <my_sys.h>
00020 #include <m_string.h>
00021 #include <m_ctype.h>
00022 #include "mysql.h"
00023 #include "errmsg.h"
00024 #include <my_dir.h>
00025 #include <my_getopt.h>
00026 #include <signal.h>
00027 #include <violite.h>
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 */

热心网友 时间:2023-08-23 23:23

are you so crazy ?go and buy any computer
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
抖音弹幕怎么关掉?怎么关闭抖音弹幕? 惠普LaserJet P3005D是否支持B5纸的双面打印? word打印出图片总是缺一部分怎么办-word打印图片不完整怎么解决_百度... 理想one哪里产的车辆? 抚州抚州ONE在哪里? one地址在哪里? 如何在图片上写字(如何在图片上添加文字) 网商贷为什么钱没到账 高级经济师职称怎么评 高级经济师需要评审吗 认证标志分为哪几种? perl怎么安装Crypt:SSLeay模块 为什么我国质量认证坚持自愿性认证和强制性认证管理相结合的原则? 强制性认证的审厂和自愿性认证的审厂 有什么不一样? 电线电缆国家强制性认证和自愿性认证有什么不同 大理三日游,推荐一下,游玩路线,怎么走 大理—丽江2天游 大理、丽江、昆明各二日游 从楚雄到大理两日游,请推荐一条好一点的路线,谢谢 带女朋友从昆明去大理3-4天游,求网友们给个攻略。急,急,急 昆明到大理周末2日游行程安排 云南大理 丽江 行程怎么安排 大理三日游最佳路线? 介绍下去大理旅游的路线 云南2日游旅游景点,不知道云南如何玩 大理2日游一些细节问题求解答 计划如下 第一天早上7点到大理火车站,坐车先去古城入住后坐车去洱海公园 大理2日游细节提问 大理两日游,想去大理古城、苍山、洱海、双廊,怎么安排比较好?(从丽江出发,游完大理后准备去昆明。) 云南大理二日游线路 母乳和奶粉混合喂养可以更换奶粉吗 认证的意思? websphere 添加节点出错 TISI认证标准是什么 glemos热水器漏电检测键是干吗的?按下去显示标志分别是什么意思?_百度... 市质监局开展强制性认证和自愿性认证监督检查工作总结 格林姆斯的热水器都需要安装一个漏电开关吗? 对于实验室来说,CMA,CAL,CNAS,ilac-MAR认证哪个是强制认证?哪个是自愿认证?为什么?谢谢! 格林姆斯热水器出现e1啥意思,怎么解决 政府采购怎么规范使用认证 格林姆斯电热水器自带漏电开关插座跳闸什么毛病? 我国已开展的自愿认证的种类 格林姆斯热水器泄压阀的工作原理是怎样的? 节能产品认证是强制活动还是自愿活动 格林姆斯速热热水器好用吗? 什么叫产品认证?认证的种类有哪些?它们有何实际意义 格林姆斯的速热式热水器安全吗? 格林姆斯热水器自动断电怎么回事 格林姆斯热水器防水性能怎么样? 格林姆斯电热水器怎么除圬 听说格林姆斯的热水器没有水垢,真的吗?什么原理?