下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
千里之行,始于足下。第2頁/共2頁精品文檔推薦http使用curl發(fā)起https請求http使用curl發(fā)起https請求
今天一具同事反映,使用curl發(fā)起https請求的時候報錯:“SSLcertificateproblem,verifythattheCAcertisOK.Details:error:14090086:SSL
routines:SSL3_GET_SERVER_CERTIFICATE:certificateverifyfailed”
非常明顯,驗證證書的時候浮現(xiàn)了咨詢題。
使用curl假如想發(fā)起的https請求正常的話有2種做法:
辦法一、設(shè)定為別驗證證書和host。
在執(zhí)行curl_exec()之前。設(shè)置option
$ch=curl_init();
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE);
辦法二、設(shè)定一具正確的證書。
本地ssl判不證書太舊,導(dǎo)致鏈接報錯ssl證書別正確。
我們需要下載新的ssl本地判不文件
http://curl.haxx.se/ca/cacert.pem
放到程序文件名目
curl增加下面的配置
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,true);;
curl_setopt($ch,CURLOPT_CAINFO,dirname(__FILE__).'/cacert.pem');
大功告成
(本人驗證未經(jīng)過。。。報錯信息為:SSLcertificateproblem,verifythattheCAcertisOK.Details:error:14090086:SSLroutines:SSL3_GET_SERVER_CERTIFICATE:certificateverifyfailed)
假如對此感興趣的話能夠參看國外一大神文章。
/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/
為了防止某天該文章被Q今復(fù)制過來。內(nèi)容如下:
UsingcURLinPHPtoaccessHTTPS(SSL/TLS)protectedsites
FromPHP,youcanaccesstheusefulcURLLibrary(libcurl)tomakerequeststoURLsusingavarietyofprotocolssuchasHTTP,FTP,LDAPandevenGopher.(Ifyou’vespenttimeonthe*nixcommandline,mostenviroXXXentsalsohavethecurlcommandavailablethatusesthelibcurllibrary)
Inpractice,however,themostcommonly-usedprotocoltendstobeHTTP,especiallywhenusingPHPforserver-to-servercommunication.Typicallythisinvolvesaccessinganotherwebserveraspartofawebservicecall,usingsomemethodsuchasXML-RPCorRESTtoqueryaresource.Forexample,DeliciousoffersaHTTP-basedAPItomanipulateandreadauser’sposts.However,whentryingtoaccessaHTTPSresource(suchasthedeliciousAPI),there’salittlemoreconfigurationyouhavetodobeforeyoucangetcURLworkingrightinPHP.
Theproblem
IfyousimplytrytoaccessaHTTPS(SSLorTLS-protectedresource)inPHPusingcURL,you’relikelytorunintosomedifficulty.Sayyouhavethefollowingcode:(Errorhandlingomittedforbrevity)
//InitializesessionandsetURL.
$ch=curl_init();curl_setopt($ch,CURLOPT_URL,$url);
//Setsocurl_execreturnstheresultinsteadofoutputtingit.
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
//Gettheresponseandclosethechannel.
$response=curl_exec($ch);
curl_close($ch);
If$urlpointstowardanHTTPSresource,you’relikelytoencounteranerrorliketheonebelow:
Failed:ErrorNumber:60.Reason:SSLcertificateproblem,verifythattheCAcertisOK.Details:error:14090086:SSLroutines:SSL3_GET_SERVER_CERTIFICATE:certificateverifyfailed
TheproblemisthatcURLhasnotbeenconfiguredtotrusttheserver’sHTTPScertificate.TheconceptsofcertificatesandPKIrevolvesaroundthetrustofCertificateAuthorities(CAs),andbydefault,cURLissetuptonottrustanyCAs,thusitwon’ttrustanywebserver’scertificate.Sowhydon’tyouhaveproblemsvisitingHTTPssitesthroughyourwebbrowser?Asithappens,thebrowserdeveloperswereniceenoughtoincludealistofdefaultCAstotrust,coveringmostsituations,soaslongasthewebsiteoperatorpurchasedacertificatefromoneoftheseCAs.
Thequickfix
Therearetwowaystosolvethisproblem.Firstly,wecansimplyconfigurecURLtoacceptanyserver(peer)certificate.Thisisn’toptimalfromasecuritypointofview,butifyou’renotpassingsensitiveinformationbackandforth,thisisprobablyalright.Simplyaddthefollowinglinebeforecallingcurl_exec():
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
ThisbasicallycausescURLtoblindlyacceptanyservercertificate,withoutdoinganyverificationastowhichCAsignedit,andwhetherornotthatCAistrusted.Ifyou’reatallconcernedaboutthedatayou’repassingtoorreceivingfromtheserver,you’llwanttoenablethispeerverificationproperly.Doingsoisabitmorecomplicated.
Theproperfix
TheproperfixinvolvessettingtheCURLOPT_CAINFOparameter.ThisisusedtopointtowardsaCAcertificatethatcURLshouldtrust.Thus,anyserver/peercertificatesissuedbythisCAwillalsobetrusted.Inordertodothis,wefirstneedtogettheCAcertificate.Inthisexample,I’llbeusingthehttps://api.del.icio.us/serverasareference.
First,you’llneedtovisittheURLwithyourwebbrowserinordertograbtheCAcertificate.Then,(inFirefox)openupthesecuritydetailsforthesitebydouble-clickingonthepadlockiconinthelowerrightcorner:
Thenclickon“ViewCertificate”:
Bringupthe“Details”tabofthecerficatespage,andselectthecertificateatthetopofthehierarchy.ThisistheCAcertificate.
Thenclick“Export”,andsavetheCAcertificatetoyourselectedlocation,makingsuretoselecttheX.509Certificate(PEM)asthesavetype/format.
NowweneedtomodifythecURLsetuptousethisCAcertificate,withCURLOPT_CAINFOsettopointtowherewesavedtheCAcertificatefileto.
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,true);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,2);
curl_setopt($ch,CURLOPT_CAINFO,getXXXd().
"/CAcerts/BuiltinObjectToken-EquifaxSecureCA.crt");
TheotheroptionI’veincluded,CURLOPT_SSL_VERIFYHOSTcanbesettothefollowingintegervalues:
0:Don’tcheckthecommonname(CN)attribute
1:Checkthatthecommonnameattributeatleastexists
2:CheckthatthecommonnameexistsandthatitmatchesthehostnameoftheserverIfyouhaveCURLOPT_SSL_VERIFYPEERsettofalse,thenfromasecurityperspective,itdoesn’treallymatterwhatyou’vesetCURLOPT_SSL_VERIFYHOSTto,sincewithoutpeer
certificateverification,theservercoulduseanycertificate,includingaself-signedonethatwasguaranteedtohaveaCNthatmatchedtheserver’shostname.Sothissettingisreallyonlyrelevantifyou’veenabledcertificateverification.
ThisensuresthatnotjustanyservercertificatewillbetrustedbyyourcURLsession.Forexample,ifanattackerweretosomehowredirecttrafficfromtotheirownserver,thecURLsessionherewouldnotproperlyinitialize,sincetheattackerwouldnothaveaccesstoaservercertificate(i.e.wouldnothavetheprivatekey)trustedbytheCAweadded.ThesestepseffectivelyexportthetrustedCAfromthewebbrowsertothecURLconfiguration.
Moreinformation
IfyouhavetheCAce
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 臨沂職業(yè)學(xué)院《篆刻2》2023-2024學(xué)年第一學(xué)期期末試卷
- 江西應(yīng)用工程職業(yè)學(xué)院《建筑設(shè)備自動化系統(tǒng)》2023-2024學(xué)年第一學(xué)期期末試卷
- 湖北開放職業(yè)學(xué)院《城市設(shè)計B》2023-2024學(xué)年第一學(xué)期期末試卷
- 遵義職業(yè)技術(shù)學(xué)院《中國古代文學(xué)5》2023-2024學(xué)年第一學(xué)期期末試卷
- 株洲師范高等??茖W(xué)校《非遺影像策劃與制作》2023-2024學(xué)年第一學(xué)期期末試卷
- 重慶青年職業(yè)技術(shù)學(xué)院《數(shù)據(jù)結(jié)構(gòu)及算法》2023-2024學(xué)年第一學(xué)期期末試卷
- 株洲師范高等??茖W(xué)?!吨攸c傳染病防治知識規(guī)培》2023-2024學(xué)年第一學(xué)期期末試卷
- 浙江外國語學(xué)院《課程與教學(xué)基礎(chǔ)》2023-2024學(xué)年第一學(xué)期期末試卷
- 浙江工貿(mào)職業(yè)技術(shù)學(xué)院《建筑美術(shù)Ⅲ》2023-2024學(xué)年第一學(xué)期期末試卷
- 中南林業(yè)科技大學(xué)《物理化學(xué)(1)》2023-2024學(xué)年第一學(xué)期期末試卷
- 2024-2030年鋁合金粉行業(yè)市場現(xiàn)狀供需分析及重點企業(yè)投資評估規(guī)劃分析研究報告
- JGJ106-2014建筑基樁檢測技術(shù)規(guī)范
- 植入(介入)性醫(yī)療器械管理制度
- 遼寧農(nóng)業(yè)職業(yè)技術(shù)學(xué)院2024年單招復(fù)習(xí)題庫(普通高中畢業(yè)生)-數(shù)學(xué)(130道)
- 內(nèi)鏡下粘膜剝離術(shù)(ESD)護理要點及健康教育課件
- 2024年民族宗教理論政策知識競賽考試題庫及答案
- 項目七電子商務(wù)消費者權(quán)益保護的法律法規(guī)
- 品質(zhì)經(jīng)理工作總結(jié)
- 供電搶修述職報告
- 集成電路設(shè)計工藝節(jié)點演進趨勢
- 新型電力系統(tǒng)簡介演示
評論
0/150
提交評論