安全性的網路程式設計主要是通過ssl實現的,首先要建立建立sslroot,可用的根證書通常是常用的verisign 根證書。它們可以節省手持裝置上的空間,並且僅保留乙個副本,而不是在每個使用 ssl 的應用程式中都保留副本。手持裝置僅包含常用根證書的一小部分,從而防止占用過多的空間。ssl的實現有兩種方法,一種是面向socket的實現,另一種是面向http的實現及https。這裡主要闡明怎樣使用iweb介面實現https的功能。
// defined in pme
iwebopts *piroots; …
if(ishell_createinstance(pishell, aeeclisd_sslrootcerts, (void **)&piroots) != success)
然後傳送root證書給伺服器
aeecallback pcb;
iweb *piweb;
iwebresp *piwebresp;
// create instance of iweb
if(ishell_createinstance(pishell, aeeclisd_web, (void**)&pme->piweb) !=
success)
goto failure;
// initialize callback
callback_init(&pme->pcb, (pfnnotify)checksecureresp, pme);
// first secure connection attempt
iweb_getresponse(pme->piweb, (pme->piweb, &pme->piwebresp, &pme->pcb,
"",webopt_headerhandler, headerhandlerfn,
webopt_default, pme->piroots,
webopt_end));
同時,需要獲得https的頭資訊,如果需要的話,還要提供登入等功能:
現在,就可以順利的建立https的連線了
// create new iweb transaction
if(pme->piweb) {
iweb_release(pme->piweb);
pme->piweb = null;
if(ishell_createinstance(pishell, aeeclisd_web, (void**)&pme->piweb) != success)
// handle failure
// initialize callback
callback_cancel(&pme->pcb);
callback_init(&pme->pcb, (pfnnotify)checksecureresp, pme);
// try a successful attempt
iweb_getresponse(pme->piweb, (pme->piweb, &pme->piwebresp, &pme->pcb,
"", webopt_header, pme->buffer,
webopt_headerhandler, headerhandlerfn,webopt_defaults, pme->piroots,
webopt_end));
為了保證應用的健壯性,需要關注ssl中的錯誤處理:
webopt wo;
sslinfo* psslinfo = null;
// query for ssl webopt
iwebresp_getopt(pme->piwebresp, webopt_ssl_sec_info, 0, &wo);
// pointer to ssl info
psslinfo = (sslinfo*)(wo.pval);
// error values are held in psslinfo->nresult
另外,還可以通過x.509對ssl進行配置:
x509trustoverride to;
to.ucertid = 0;
to.uoverridebits = x509chain_cert_exipred;
iweb_getresponse(pme->piweb,(pme->piweb,pme->pwebresp,&pme->callback,
"",webopt_ssl_allowed_version, ssl_version_30,
webopt_x509_root_cert, pourroot, webopt_x509_override, &to,
webopt_defaults, pme->piroots, webopt_end));
對於銀行類應用,或者**交易類應用,一般會使用自定義的證書,示例如下:
ifilemgr* pifilemgr;
ifile* pifile;
webopt apwoz;
if(ishell_createinstance(pishell, aeeclsid_filemgr, &pifilemgr)) !=success)
goto failure;
pifile = ifilemgr_openfile(pifilemgr, 「mycert.cer」, _ofm_read);
ifile_read(pifile, buffer, sizeof(buffer));
apwoz.nid = webopt_x509_root_cert;
apwoz.pval = buffer;
iweb_addopt(pme->piweb, apwoz);
ifile_release(pifile);
ifilemgr_release(pifilemgr);
mysql 網路安全性 MySQL安全性指南(1)
作為乙個mysql的系統管理員,你有責任維護你的mysql資料庫系統的資料安全性和完整性。本文主要主要介紹如何建立乙個安全的mysql系統,從系統內部和外部網路兩個角度,為你提供乙個指南。為什麼安全性很重要,你應該防範那些攻擊?伺服器面臨的風險 內部安全性 如何處理?連線伺服器的客戶端風險 外部安全...
mysql 網路安全性 MySQL安全性指南(3)
2.4 不用grant設定使用者 當你發出一條grant語句時,你指定乙個使用者名稱和主機名,可能還有口令。對該使用者生成乙個user表記錄,並且這些值記錄在user host和password列中。如果你在grant語句中指定全域性許可權,這些許可權記錄在記錄的許可權列中。其中要留神的是grant...
併發程式設計的安全性(2)
安全 安全的首先是正確的且是我們預期的,正確性 某個類的行為與其規範完全一致。在良好的規範中通常會定義各種不變性條件來約束物件的狀態,以及定義各種後驗條件來描述物件操作的結果。我們根據這些規範在單執行緒中執行獲取正確的預期結果,代表這個程式的正確性,即所見即所知。而當多個執行緒同時訪問某個類,這個類...