解決linux netcore https請求使用自簽名證書忽略安全檢查方法


當前系統環境:centos7 x64. dotnet 2.0.
不管是
ServicePointManager.ServerCertificateValidationCallback = (a, b, c, d) => true;
還是:
HttpClient httpClient = new HttpClient(new HttpClientHandler() { ServerCertificateCustomValidationCallback = (a, b, c, d) => true });

都會發生錯誤:
錯誤信息大致如下:
(The handler does not support custom handling of certificates with this combination of libcurl (7.29.0) and its SSL backend ("NSS/3.28.4").) ---> System.PlatformNotSupportedException: The handler does not support custom handling of certificates with this combination of libcurl (7.29.0) and its SSL backend ("NSS/3.28.4").
at System.Net.Http.CurlHandler.SslProvider.SetSslOptionsForUnsupportedBackend(EasyRequest easy, ClientCertificateProvider certProvider)
at System.Net.Http.CurlHandler.SslProvider.SetSslOptions(EasyRequest easy, ClientCertificateOption clientCertOption)

解決方案:

# yum update(可選)
# yum install openssl-devel gcc #安裝openssl和gcc

# 安裝指定版本的curl
# wget https://curl.haxx.se/download/curl-7.55.1.tar.gz
# tar -zxf curl-7.55.1.tar.gz
# cd curl-7.55.1
# ./configure --prefix=/usr/local/curl/ --without-nss --with-ssl=/usr/local/ssl/
# make
# make install

#備份原來的curl
mv /usr/bin/curl /usr/bin/curl.bak

#將安裝的curl 創建軟連
ln -s /usr/local/curl/bin/curl /usr/bin/curl
#  curl --version
#差不多輸出下面的內容
#curl 7.55.1 (x86_64-pc-linux-gnu) libcurl/7.55.1 OpenSSL/1.0.2k zlib/1.2.7

#增加lib搜索目錄
# vi /etc/ld.so.conf 
#增加
# /usr/local/curl/lib
# cat /etc/ld.so.conf 
差不多下面這樣子
#
include ld.so.conf.d/*.conf
/usr/local/curl/lib

# 重新load配置
# ldconfig

參考文章:
https://www.latoooo.com/xia_zhe_teng/368.htm
https://segmentfault.com/a/1190000012282935
https://www.cnblogs.com/Anker/p/3209876.html
https://github.com/dotnet/corefx/issues/9728#issuecomment-286251370


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM