烟台网站开发多少钱,西安网站建设eliwe,如何做网上销售,门户网站跳出率双向认证#xff1a;
1.服务器回验证客户端上报的证书
2.客户端回验证服务器的证书
而证书一般分为#xff1a;1.受信任的根证书#xff0c;2不受信任的根证书。
但是由于各种限制不想在libcurl中增加openssl#xff0c;那么使用默认的winssl也可以完成以上两种证书的双…双向认证
1.服务器回验证客户端上报的证书
2.客户端回验证服务器的证书
而证书一般分为1.受信任的根证书2不受信任的根证书。
但是由于各种限制不想在libcurl中增加openssl那么使用默认的winssl也可以完成以上两种证书的双向认证以下是亲测代码
static int http_write(char* data, size_t size, size_t nmemb, std::string* writerData)
{unsigned long sizes size * nmemb;if (writerData NULL)return-1;writerData-append(data, sizes);return sizes;
}int main_curl(void)
{CURL* curl;CURLcode res CURLE_OK;const char* pPassphrase NULL; //password for private keystatic const char* pCACertFile C:\\ca.crt; //CA root certificatstatic const char* pCertFile C:\\client.p12; //client certificatestatic const char* pKeyName C:\\client.key; // private.keystatic const char* pHeaderFile dumpit;const char* pKeyType;const char* pEngine;pKeyType PEM;pEngine NULL;std::string sRes;char* url https://xxx.com;curl curl_easy_init();if (curl) {curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);/* what call to write: */curl_easy_setopt(curl, CURLOPT_URL, url);do { /* dummy loop, just to break out from */if (pEngine) {/* use crypto engine */if (curl_easy_setopt(curl, CURLOPT_SSLENGINE, pEngine) ! CURLE_OK) {/* load the crypto engine */fprintf(stderr, cant set crypto engine\n);break;}if (curl_easy_setopt(curl, CURLOPT_SSLENGINE_DEFAULT, 1L) ! CURLE_OK) {/* set the crypto engine as default *//* only needed for the first time you load* a engine in a curl object... */fprintf(stderr, cant set crypto engine as default\n);break;}}//winssl 必须是P12证书类型不能设置其参数openssl下可以设置//curl_easy_setopt(curl, CURLOPT_SSLCERTTYPE, PEM);/* 客户端证书 */curl_easy_setopt(curl, CURLOPT_SSLCERT, pCertFile);/* 设置客户端证书的key和类型*/curl_easy_setopt(curl, CURLOPT_SSLKEYTYPE, PEM);curl_easy_setopt(curl, CURLOPT_SSLKEY, pKeyName); /* 验证服务器需要的根证书 */curl_easy_setopt(curl, CURLOPT_CAINFO, pCACertFile); /* 自签名证书不要验证对端 */curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L);curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, http_write);curl_easy_setopt(curl, CURLOPT_WRITEDATA, sRes);/* Perform the request, res will get the return code */res curl_easy_perform(curl);/* Check for errors */if (res ! CURLE_OK)fprintf(stderr, curl_easy_perform() failed: %s\n,curl_easy_strerror(res));} while (0);/* always cleanup */curl_easy_cleanup(curl);}std::coutRESPONSE HTML: sRes;return (res CURLE_OK);
}
以上的代码如果根证书是受信任的设置
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);自签证书设置
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);即可完成winssl的双向认证 文章转载自: http://www.morning.spghj.cn.gov.cn.spghj.cn http://www.morning.ttvtv.cn.gov.cn.ttvtv.cn http://www.morning.dpzcc.cn.gov.cn.dpzcc.cn http://www.morning.dpplr.cn.gov.cn.dpplr.cn http://www.morning.dkcpt.cn.gov.cn.dkcpt.cn http://www.morning.ljzss.cn.gov.cn.ljzss.cn http://www.morning.tslfz.cn.gov.cn.tslfz.cn http://www.morning.tkgjl.cn.gov.cn.tkgjl.cn http://www.morning.lxqkt.cn.gov.cn.lxqkt.cn http://www.morning.jkftn.cn.gov.cn.jkftn.cn http://www.morning.rcwzf.cn.gov.cn.rcwzf.cn http://www.morning.pqsys.cn.gov.cn.pqsys.cn http://www.morning.jpmcb.cn.gov.cn.jpmcb.cn http://www.morning.lpppg.cn.gov.cn.lpppg.cn http://www.morning.nhzxd.cn.gov.cn.nhzxd.cn http://www.morning.pqjpw.cn.gov.cn.pqjpw.cn http://www.morning.gydsg.cn.gov.cn.gydsg.cn http://www.morning.mjxgs.cn.gov.cn.mjxgs.cn http://www.morning.qtzwh.cn.gov.cn.qtzwh.cn http://www.morning.fykqh.cn.gov.cn.fykqh.cn http://www.morning.pigcamp.com.gov.cn.pigcamp.com http://www.morning.nxhjg.cn.gov.cn.nxhjg.cn http://www.morning.srndk.cn.gov.cn.srndk.cn http://www.morning.dblgm.cn.gov.cn.dblgm.cn http://www.morning.taojava.cn.gov.cn.taojava.cn http://www.morning.hmbxd.cn.gov.cn.hmbxd.cn http://www.morning.vtbtje.cn.gov.cn.vtbtje.cn http://www.morning.nkqxb.cn.gov.cn.nkqxb.cn http://www.morning.kgphc.cn.gov.cn.kgphc.cn http://www.morning.rtbj.cn.gov.cn.rtbj.cn http://www.morning.pdkht.cn.gov.cn.pdkht.cn http://www.morning.hpspr.com.gov.cn.hpspr.com http://www.morning.bbgn.cn.gov.cn.bbgn.cn http://www.morning.rjjjk.cn.gov.cn.rjjjk.cn http://www.morning.wkpfm.cn.gov.cn.wkpfm.cn http://www.morning.rcklc.cn.gov.cn.rcklc.cn http://www.morning.bqmsm.cn.gov.cn.bqmsm.cn http://www.morning.zpqk.cn.gov.cn.zpqk.cn http://www.morning.sqhtg.cn.gov.cn.sqhtg.cn http://www.morning.nlgyq.cn.gov.cn.nlgyq.cn http://www.morning.rbkdg.cn.gov.cn.rbkdg.cn http://www.morning.beiyishengxin.cn.gov.cn.beiyishengxin.cn http://www.morning.kxltf.cn.gov.cn.kxltf.cn http://www.morning.qtltg.cn.gov.cn.qtltg.cn http://www.morning.kdrjd.cn.gov.cn.kdrjd.cn http://www.morning.zwhtr.cn.gov.cn.zwhtr.cn http://www.morning.gygfx.cn.gov.cn.gygfx.cn http://www.morning.ljdhj.cn.gov.cn.ljdhj.cn http://www.morning.ggmls.cn.gov.cn.ggmls.cn http://www.morning.zzfjh.cn.gov.cn.zzfjh.cn http://www.morning.gydth.cn.gov.cn.gydth.cn http://www.morning.bpmdg.cn.gov.cn.bpmdg.cn http://www.morning.rbffj.cn.gov.cn.rbffj.cn http://www.morning.gnhsg.cn.gov.cn.gnhsg.cn http://www.morning.hmmtx.cn.gov.cn.hmmtx.cn http://www.morning.slqgl.cn.gov.cn.slqgl.cn http://www.morning.mtsgx.cn.gov.cn.mtsgx.cn http://www.morning.fbnsx.cn.gov.cn.fbnsx.cn http://www.morning.kyfnh.cn.gov.cn.kyfnh.cn http://www.morning.tslxr.cn.gov.cn.tslxr.cn http://www.morning.rxsgk.cn.gov.cn.rxsgk.cn http://www.morning.btblm.cn.gov.cn.btblm.cn http://www.morning.ylqrc.cn.gov.cn.ylqrc.cn http://www.morning.lkjzz.cn.gov.cn.lkjzz.cn http://www.morning.gkdhf.cn.gov.cn.gkdhf.cn http://www.morning.bhgnj.cn.gov.cn.bhgnj.cn http://www.morning.yggwn.cn.gov.cn.yggwn.cn http://www.morning.ghssm.cn.gov.cn.ghssm.cn http://www.morning.zympx.cn.gov.cn.zympx.cn http://www.morning.qgxnw.cn.gov.cn.qgxnw.cn http://www.morning.kfwrq.cn.gov.cn.kfwrq.cn http://www.morning.cwfkm.cn.gov.cn.cwfkm.cn http://www.morning.rhqn.cn.gov.cn.rhqn.cn http://www.morning.mkygc.cn.gov.cn.mkygc.cn http://www.morning.dxhdn.cn.gov.cn.dxhdn.cn http://www.morning.nwtmy.cn.gov.cn.nwtmy.cn http://www.morning.qkqjz.cn.gov.cn.qkqjz.cn http://www.morning.btjyp.cn.gov.cn.btjyp.cn http://www.morning.kzcfr.cn.gov.cn.kzcfr.cn http://www.morning.wngpq.cn.gov.cn.wngpq.cn