1. 程式人生 > 實用技巧 >設計模式中建立型模式——工廠模式

設計模式中建立型模式——工廠模式

實驗目的

  • 掌握SSL證書的基本概念
  • 掌握使用Openssl手動建立證書

實驗原理

1.瞭解什麼是SSL
  SSL證書是數字證書的一種,類似於駕駛證、護照和營業執照的電子副本。
  SSL證書通過在客戶端瀏覽器和Web伺服器之間建立一條SSL安全通道。
2.SSL證書
  全協議是由Netscape Communication公司設計開發。該安全協議主要用來提供對使用者和伺服器的認證;對傳送的資料進行加密和隱藏;確保資料在傳送中不被改變,即資料的完整性,現已成為該領域中全球化的標準。由於SSL技術已建立到所有主要的瀏覽器和WEB伺服器程式中,因此,僅需安裝伺服器證書就可以啟用該功能了)。即通過它可以啟用SSL協議,實現資料資訊在客戶端和伺服器之間的加密傳輸,可以防止資料資訊的洩露。保證了雙方傳遞資訊的安全性,而且使用者可以通過伺服器證書驗證他所訪問的網站是否是真實可靠。
3.SSL證書的功能


  確認網站真實性(網站身份認證):使用者需要登入正確的網站進行線上購物或其它交易活動,但由於網際網路的廣泛性和開放性,使得網際網路上存在著許多假冒、釣魚網站,使用者如何來判斷網站的真實性,如何信任自己正在訪問的網站,可信網站將幫你確認網站的身份。   
  保證資訊傳輸的機密性:使用者在登入網站線上購物或進行各種交易時,需要多次向伺服器端傳送資訊,而這些資訊很多是使用者的隱私和機密資訊,直接涉及經濟利益或私密,如何來確保這些資訊的安全呢?可信網站將幫您建立一條安全的資訊傳輸加密通道。
  在SSL會話產生時,伺服器會傳送它的證書,使用者端瀏覽器會自動的分析伺服器證書,並根據不同版本的瀏覽器,從而產生40位或128位的會話金鑰,用於對交易的資訊進行加密。所有的過程都會自動完成,對使用者是透明的,因而,伺服器證書可分為兩種:最低40位和最低128位(這裡指的是SSL會話時生成加密金鑰的長度,金鑰越長越不容易破解)證書。   
  最低40位的伺服器證書在建立會話時,根據瀏覽器版本不同,可產生40位或128位的SSL會話金鑰用來建立使用者瀏覽器與伺服器之間的安全通道。而最低128位的伺服器證書不受瀏覽器版本的限制可以產生128位以上的會話金鑰,實現高級別的加密強度,無論是IE或Netscape瀏覽器,即使使用強行攻擊的辦法破譯密碼,也需要10年。
4.SSL證書分類

  SSL證書依據功能和品牌不同分類有所不同,但SSL證書作為國際通用的產品,最為重要的便是產品相容性(即證書根預埋技術),因為他解決了網民登入網站的信任問題,網民可以通過SSL證書輕鬆識別網站的真實身份。目前國際上,常見的證書品牌如VeriSign、GeoTrust等均可以實現該技術。我們以VeriSign證書為例,該類證書分為如下品類:

  • VeriSign 128位SSL支援型證書(VeriSign Secure Site)
  • VeriSign 128位SSL強制型證書(VeriSign Secure Site Pro)  
  • VeriSign 128位EV SSL支援型證書(VeriSign Secure Site with EV):支援綠色位址列技術  
  • VeriSign 128位EV SSL強制型證書(VeriSign Secure Site Pro with EV ):支援綠色位址列技術

實驗環境

1.作業系統
  操作機: Linux_Centos7

  • IP:192.168.254.128
  • 閘道器:192.168.254.255  

目標機:Windows 7
  目標機預設使用者名稱:administrator  密碼:1234

實驗步驟

一、安裝Apache

yum -y install httpd

二、安裝ssl模組

yum -y install mod_ssl

三、配置httpd配置檔案

3.1修改地址為localhost

vi /etc/httpd/conf/httpd.conf

3.2重啟Apache

/usr/sbin/httpd -k start

四、使用OpenSSL建立自定義證書

4.1安裝OpenSSL

yum -y install openssl

4.2生成伺服器私鑰

cd /etc/pki/tls

openssl genrsa -out server.key 1024

server.key是私鑰

[root@localhost /]# cd /etc/pki/tls
[root@localhost tls]# openssl genrsa -out sever.key 1024
Generating RSA private key, 1024 bit long modulus
..............++++++
................++++++
e is 65537 (0x10001)

4.3用私鑰server.key檔案生成證書請求檔案csr

openssl req -new -key server.key -out server.csr

[root@localhost tls]# openssl req -new -key server.key -out server.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:cn
State or Province Name (full name) []:jiangsu
Locality Name (eg, city) [Default City]:zhenjiang
Organization Name (eg, company) [Default Company Ltd]:ujs
Organizational Unit Name (eg, section) []:aaa
Common Name (eg, your name or your server's hostname) []:www.test.com
Email Address []:[email protected]

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

4.4生成數字簽名crt檔案(證書檔案)

openssl x509 -days 365 -req -in server.csr -signkey server.key -out server.crt

[root@localhost tls]# openssl x509 -days 365 -req -in server.csr -signkey server.key -out server.crt
Signature ok
subject=/C=cn/ST=jiangsu/L=zhenjiang/O=ujs/OU=aaa/CN=www.test.com/[email protected]
Getting Private key

4.5編輯apache的ssl配置檔案

vim /etc/httpd/conf.d/ssl.conf

#   Server Certificate:
# Point SSLCertificateFile at a PEM encoded certificate.  If
# the certificate is encrypted, then you will be prompted for a
# pass phrase.  Note that a kill -HUP will prompt again.  A new
# certificate can be generated using the genkey(1) command.
SSLCertificateFile /etc/pki/tls/server.crt  ##與證書存放的路徑一致

#   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.)
SSLCertificateKeyFile /etc/pki/tls/server.key ##與證書存放的路徑一致

4.5再次重啟apache

/usr/sbin/httpd -k restart

五、切換到目標機,開啟瀏覽器,輸入配置的IP地址,出現證書不安全,說明配置成功