油漆工程承包,居家油漆粉刷、外牆油漆
油漆老師傅專業施工,來電免費估價!
搬家公司內外玄關門、優質採光罩、藝術欄杆
各種材質、造型門窗設計工程,歡迎洽詢

首頁  •  j2h 論壇 • 程式設計討論     • 

[php] 利用Openssl實作ssl網頁加密

房東:分析師
發表時間:2015-12-04


一般的網頁伺服器架設起來之後


往往都是沒有作加密的動作


在網際網路的傳輸上都是以明碼做傳輸


以下為利用wireshark擷取封包實例


 


noly80-1


此為80port且為加密的網頁傳輸情形


可以看到完全都是明碼


 


443nossl-2


而此為將網頁的通訊port改為443而未做ssl加密傳輸情形


可以看到只有port轉向443輸出,仍然是明碼傳輸


 


ssl加密-1


而此為利用openssl製做加密憑證來進行ssl加密


可以看到傳輸都是利用編碼加密過的方式來做加密


在此可以看出來是得實做ssl加密才會稍微安全一點


單單轉換傳輸的port到443不會有加密的效果


 


而實做的方式如下


 


1  


appserv官方網站下載appserv


 


2


安裝過程就不贅述,完成後可看到此畫面 


 


9


開啟C:\AppServ\Apache2.2\conf內的httpd.conf


 


91   


將LoadModule ssl_module modules/mod_ssl.so這行前面的#註解拿掉並存檔


 


3


接著可在C:\AppServ\Apache2.2\bin資料夾底下看見openssl.exe


 


4  


開啟後輸入genrsa -out server.key 1024產生rsa私鑰


 


5    


輸入req -new -out server.csr -key server.key -config ../conf/openssl.cnf產生簽署申請


Country Name為國籍鍵入TW


State or Province Name為省份鍵入Taiwan


Locality Name為所在地


Organization Name為組織名稱


Organizational Unit Name為組織內單位


Common Name為domain name


Email Address為管理者的電子信箱


剩餘兩項可不填入


 


 6  


鍵入genrsa -out ca.key 1024產生ca的rsa私鑰


 


7  


鍵入req -new -x509 -days 365 -key ca.key -out ca.crt -config ../conf/openssl.cnf利用ca私鑰產生簽署憑證


下面的參數同上面設定


 


8


接著於C:\AppServ\Apache2.2\bin資料夾內新建demoCA資料夾


 


81


接著於demoCA資料夾內新增newcerts資料夾與index.txt跟serial檔案


並利用記事本開啟serial後鍵入01後存檔


 


82  


利用ca替網站簽署認證


鍵入ca -in server.csr -out server.crt -cert ca.crt -keyfile ca.key -config ../conf/openssl.cnf


 


83  


接著將C:\AppServ\Apache2.2\bin底下的server.crt與server.key兩個檔案


複製至C:\AppServ\Apache2.2\conf資料夾底下


 


84


接著於httpd.conf內新增此兩行


#Virtual host with SSL


Include C:\Appserv\Apache2.2\conf\extra\http-vhost-ssl.conf


並存檔


並於C:\Appserv\Apache2.2\conf\extra\內新增http-vhost-ssl.conf檔案


 


輸入以下內容:


 


## SSL Global Context

#

# When we also provide SSL we have to listen to the

# standard HTTP port (see above) and to the HTTPS port

#

# Note: Configurations that use IPv6 but not IPv4-mapped addresses need two

# Listen directives: "Listen [::]:443" and "Listen 0.0.0.0:443"

#

Listen 443

##

## SSL Global Context

##

## All SSL configuration in this context applies both to

## the main server and all SSL-enabled virtual hosts.

##

#

# Some MIME-types for downloading Certificates and CRLs

#

AddType application/x-x509-ca-cert .crt

AddType application/x-pkcs7-crl .crl

# Pass Phrase Dialog:

# Configure the pass phrase gathering process.

# The filtering dialog program (`builtin' is a internal

# terminal dialog) has to provide the pass phrase on stdout.

#SSLPassPhraseDialog builtin

# Inter-Process Session Cache:

# Configure the SSL Session Cache: First the mechanism

# to use and second the expiring timeout (in seconds).

#SSLSessionCache "dbm:/usr/local/apache/logs/ssl_scache"

#SSLSessionCache "shmcb:/usr/local/apache/logs/ssl_scache(512000)"

#SSLSessionCacheTimeout 300

# Semaphore:

# Configure the path to the mutual exclusion semaphore the

# SSL engine uses internally for inter-process synchronization.

#SSLMutex "file:/usr/local/apache/logs/ssl_mutex"




# Virtual Hosts

NameVirtualHost *:80

NameVirtualHost *:443

ServerAdmin [email protected] <---電子信箱

DocumentRoot "C:\AppServ\www" <---網站根目錄

ServerName xxx.xxx.org <---網站domain


# Secure Shell ver.

ServerAdmin [email protected] <---電子信箱

DocumentRoot "C:\AppServ\www" <---網站根目錄

ServerName xxx.xxx.org:443 <---網站domain

#SSL Engine Switch:

#Enable/Disable SSL for this virtual host.

SSLEngine on

# Server Private Key:

# If the key is not combined with the certificate, use this

# directive to point at the key file. Keep in mind that if

# you've both a RSA and a DSA private key you can configure

# both in parallel (to also allow the use of DSA ciphers, etc.)

SSLCertificateFile C:\AppServ\Apache2.2\conf\server.crt <---server.crt路徑

SSLCertificateKeyFile C:\AppServ\Apache2.2\conf\server.key <---server.key路徑


 


然後存檔


 


接著重新啟動Apache伺服器


 


86


若是出現此檔案遺失


 


87


則開啟C:\Windows\php.ini


將extension=php_exif.dll放置於extension=php_mbstring.dll之後即可解決


 


88


接著於網頁鍵入127.0.0.1觀看網頁即可看到此畫面


點擊連結即可連至https頁面


 


89    


由於憑證是我們自己產生的,沒有經過認證


所以是不可靠的,但是我們只是需要他的SSL加密


 


891


可於網址列的鎖點左鍵看到我們剛剛產生的憑證資訊,這樣就代表成功了


 


在實做的過程中我發現電腦當中443port被佔用著


利用netstat -ano指令可以看到是哪個pid去佔著這個port


再利用process explorer來觀看是哪個程式佔用著


ffff


檔案為smss.exe


在網路上搜尋此檔案可能為病毒


如果在多個資料夾底下有搜尋到此檔案


那可能就是中毒了


但是如果檔案路徑在C:\Windows\system32資料夾底下


那應該是正常的檔案


但是他一直佔著服務該怎麼辦?


 


10000    


將此服務停止即可釋放出443port


 


同樣會佔用443port的常用軟體還有vm workstation及skype這兩個


皆可在netstat -ano這指令當中看到是哪個程式佔用


再去關掉即可


 


http://joe01032002.pixnet.net/blog/post/92665237


 





  • 贊助網站       

    廣利不動產-新板特區指名度最高、值得您信賴的好房仲
    您的托付,廣利用心為您服務
    廣利不動產-板橋在地生根最實在--新板特區指名度最高、值得您信賴的好房仲
    完整房訊,房屋、店面熱門精選物件,廣利不動產 優質仲介,房屋租賃、買賣資訊透明,交易真安心!

  • 1 樓住戶:阿凱
    發表時間:2015-12-04

    Certificate Authority(CA) 憑證簡介 瞭解 CA 憑證的概念後,現在就先拿 Apache Httpd Server 來作網站的測試。免錢的 OpenSSL 就是一個好的工具,而 AppServ 套件本身即有 Apache、MySQL、PHP、phpMyAdmin 與 OpenSSL 工具,是最方便的軟體了。


    一、準備檔案:

    下載 AppServ 2.5.10





    二、安裝 Apache Server 與設定:



    1. 先行安裝AppServ,預設路徑應該安裝在 C:/AppServ/Apache2.2/,並先停止Apache伺服器。

    2. 開啟C:\AppServ\Apache2.2\conf 內的 httpd.conf 作修改


    把 LoadModule ssl_module modules/mod_ssl.so 的#註解拿掉

    把 Include conf/extra/httpd-ssl.conf 的#註解拿掉


    httpd.conf-mod_ssl.png  


    三、在 C:\AppServ\Apache2.2\bin資料夾底下看見openssl.exe,滑鼠double click執行它,用它來作憑證



    1. 輸入 genrsa -out server.key 1024 產生rsa私鑰(Server Private Key:server.key)


    ServerPrivateKey.png  



    2. 利用私鑰(Server Private Key:server.key)來產生簽署申請:輸入 req -new -out server.csr -key server.key -config ../conf/openssl.cnf 產生簽署申請


    Country Name為國籍鍵入TW

    State or Province Name為省份鍵入Taiwan

    Locality Name為所在地

    Organization Name為組織名稱

    Organizational Unit Name為組織內單位

    Common Name為domain name

    Email Address為管理者的電子信箱

    剩餘兩項可不填入

     ServerPrivateKeyForCASignRequest.png  


    Step 3 & 4 是模擬 CA 第三方認證單位

    3. 輸入 genrsa -out ca.key 1024 產生CA的rsa私鑰



    4. 輸入 req -new -x509 -days 365 -key ca.key -out ca.crt -config ../conf/openssl.cnf 利用ca私鑰產生待會幫自己主機的簽署憑證,參數同step2上面設定


    CACenter.png  



    5. 接著於C:\AppServ\Apache2.2\bin資料夾內新建demoCA資料夾,並於demoCA資料夾內新增newcerts資料夾,與 index.txt跟serial檔案,並利用記事本開啟serial後鍵入01後存檔(這裡的值是參考C:\AppServ\Apache2.2 \conf\openssl.cnf 檔案裡 [ CA_default ] 這區段中的設定)



    6. 利用step 3 &4 中模擬CA替網站簽署認證的檔案,私鑰:ca.key & 簽署憑證 ca.crt 兩個檔案來替自己的網站提出的簽署憑證申請檔: server.csr 作簽署憑證,產生憑證:server.crt

    輸入ca -in server.csr -out server.crt -cert ca.crt -keyfile ca.key -config ../conf/openssl.cnf



    詢問是否簽署都回答 Y


    ServerPublicKey.png  



    7. 將C:\AppServ\Apache2.2\bin底下的私鑰 server.key 及CA簽署過的公鑰 server.crt 兩個檔案複製至C:\AppServ\Apache2.2\conf資料夾底下



    8.打開 C:\Appserv\Apache2.2\conf\extra\http-ssl.conf檔案,修改部份如下:




    #   General setup for the virtual host

    DocumentRoot "C:/AppServ/www"

    ServerName www.xxx.com:443

    ServerAdmin [email protected]

    ErrorLog "C:/AppServ/Apache2.2/logs/error.log"

    TransferLog "C:/AppServ/Apache2.2/logs/access.log"



    #   Server Certificate:

    SSLCertificateFile "C:/AppServ/Apache2.2/conf/server.crt"

    #   Server Private Key:

    SSLCertificateKeyFile "C:/AppServ/Apache2.2/conf/server.key"



    CustomLog "C:/AppServ/Apache2.2/logs/ssl_request.log" \

              "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"



    再重啟 Apache Server 即可登入 https://localhost





    Troubleshooting:



    1. 若有 php_mbstring.dll 檔案遺失的警告,則開啟 C:\Windows\php.ini 將 extension=php_exif.dll 放置於 extension=php_mbstring.dll 之後即可解決



    2. 在實做的過程中若電腦的 port:443 被佔用著,利用netstat -ano指 令可以看到是哪個pid去佔著這個port,再利用 process explorer(在Win 7&8 可以執行 Task manager -> Performance -> Resource Monitor)來觀看是哪個程式佔用著,再到服務 Services 關掉即可



    http://mistech.pixnet.net/blog/post/80886829-appserv-%2B-openssl-setup-ssl%28https%29-in-win32--%E6%86%91%E8%AD%89%E5%BB%BA%E7%AB%8B



     共 1 人回應  選擇頁數 【第1 頁】 

    姓名:
    佈告內容:
    其他選項: