HTTPS(全稱:Hypertext Transfer Protocol over Secure Socket Layer),是以安全爲目標的HTTP通道,簡單講是HTTP的安全版。即HTTP下加入SSL層,HTTPS的安全基礎是SSL,因此加密的詳細內容就需要SSL。 它是一個URI scheme(抽象標識符體系),句法類同http:體系。用於安全的HTTP數據傳輸。https:URL表明它使用了HTTP,但HTTPS存在不同於HTTP的默認端口及一個加密/身份驗證層(在HTTP與TCP之間)。這個系統的最初研發由網景公司進行,提供了身份驗證與加密通訊方法,現在它被廣泛用於萬維網上安全敏感的通訊,
區別編輯
HTTPS和HTTP的區別
一、https協議需要到ca申請證書,一般免費證書很少,需要交費。
二、http是超文本傳輸協議,信息是明文傳輸,https 則是具有安全性的ssl加密傳輸協議。
三、http和https使用的是完全不同的連接方式,用的端口也不一樣,前者是80,後者是443。
四、http的連接很簡單,是無狀態的;HTTPS協議是由SSL+HTTP協議構建的可進行加密傳輸、身份認證的網絡協議,比http協議安全。
ssl簡介
SSL(Secure Sockets Layer 安全套接層),及其繼任者傳輸層安全(TransportLayer Security,TLS)是爲網絡通信提供安全及數據完整性的一種安全協議。TLS與SSL在傳輸層對網絡連接進行加密。
SSL (Secure Socket Layer)爲Netscape所研發,用以保障在Internet上數據傳輸之安全,利用數據加密(Encryption)技術,可確保數據在網絡上之傳輸過程中不會被截取及竊聽。目前一般通用之規格爲40 bit之安全標準,美國則已推出128 bit之更高安全標準,但限制出境。只要3.0版本以上之I.E.或Netscape瀏覽器即可支持SSL。
當前版本爲3.0。它已被廣泛地用於Web瀏覽器與服務器之間的身份認證和加密數據傳輸。
SSL協議位於TCP/IP協議與各種應用層協議之間,爲數據通訊提供安全支持。SSL協議可分爲兩層:SSL記錄協議(SSL Record Protocol):它建立在可靠的傳輸協議(如TCP)之上,爲高層協議提供數據封裝、壓縮、加密等基本功能的支持。SSL握手協議(SSLHandshake Protocol):它建立在SSL記錄協議之上,用於在實際的數據傳輸開始前,通訊雙方進行身份認證、協商加密算法、交換加密密鑰等。
SSL協議提供的服務主要有哪些
1)認證用戶和服務器,確保數據發送到正確的客戶機和服務器
2)加密數據以防止數據中途被竊取
3)維護數據的完整性,確保數據在傳輸過程中不被改變。
SSL協議的工作流程
服務器認證階段:1)客戶端向服務器發送一個開始信息“Hello”以便開始一個新的會話連接;2)服務器根據客戶 的信息確定是否需要生成新的主密鑰,如需要則服務器在響應客戶的“Hello”信息時將包含生成主密鑰所需的信息;3)客戶根據收到的服務器響應信息,產 生一個主密鑰,並用服務器的公開密鑰加密後傳給服務器;4)服務器恢復該主密鑰,並返回給客戶一個用主密鑰認證的信息,以此讓客戶認證服務器。
用戶認證階段
在此之前,服務器已經通過了客戶認證,這一階段主要完成對客戶的認證。經認證的服務器發送一個提問給客戶,客戶則返回(數字)簽名後的提問和其公開密鑰,從而向服務器提供認證。
從SSL 協議所提供的服務及其工作流程可以看出,SSL協議運行的基礎是商家對消費者信息保密的承諾,這就有利於商家而不利於消費者。在電子商務初級階段,由於運作電子商務的企業大多是信譽較高的大公司,因此這問題還沒有充分暴露出來。但隨着電子商務的發展,各中小型公司也參與進來,這樣在電子支付過程中的單一認證問題就越來越突出。雖然在SSL3.0中通過數字簽名和數字證書可實現瀏覽器和Web服務器雙方的身份驗證,但是SSL協議仍存在一些問題,比如,只能提供交易中客戶與服務器間的雙方認證,在涉及多方的電子交易中,SSL協議並不能協調各方間的安全傳輸和信任關係。
[root@host2 ~]mount /dev/cdrom /media/cdrom
[root@host2 ~]cd /media/cdrom/Packages
[root@host2 Packages]# ll |grep ssl
-r--r--r--. 3 root root 1572996 Nov 25 03:30 openssl-1.0.1e-15.el6.i686.rpm
-r--r--r--. 2 root root 1219248 Nov 25 03:30 openssl-devel-1.0.1e-15.el6.i686.rpm
-r--r--r--. 2 root root 791760 Apr 25 2012 openssl098e-0.9.8e-17.el6.centos.2.i686.rpm
[root@host2 Packages]# rpm -qa httpd
httpd-2.2.15-29.el6.centos.i686
[root@host2 Packages]# yum install httpd-2.2.15-29.el6.centos.i686.rpm
Loaded plugins: fastestmirror,refresh-packagekit
Loading mirror speeds from cached hostfile
*c6-media:
file:///media/CentOS/repodata/repomd.xml:[Errno 14] Could not open/read file:///media/CentOS/repodata/repomd.xml
Trying other mirror.
file:///media/cdrecorder/repodata/repomd.xml:[Errno 14] Could not open/read file:///media/cdrecorder/repodata/repomd.xml
Trying other mirror.
c6-media | 4.0 kB 00:00 ...
Setting up Install Process
Examining httpd-2.2.15-29.el6.centos.i686.rpm:httpd-2.2.15-29.el6.centos.i686
httpd-2.2.15-29.el6.centos.i686.rpm:does not update installed package.
Error: Nothing to do
[root@host2 Packages]# yum installhttpd-tools-2.2.15-29.el6.centos.i686.rpm
Loaded plugins: fastestmirror,refresh-packagekit
Loading mirror speeds from cached hostfile
*c6-media:
Setting up Install Process
Examining httpd-tools-2.2.15-29.el6.centos.i686.rpm:httpd-tools-2.2.15-29.el6.centos.i686
httpd-tools-2.2.15-29.el6.centos.i686.rpm:does not update installed package.
Error: Nothing to do
[root@host2Packages]# ll |grep ssl
-r--r--r--. 2 root root 93340 Aug 14 2013 mod_ssl-2.2.15-29.el6.centos.i686.rpm
-r--r--r--. 2 root root 34212 Jul 6 2011 nss_compat_ossl-0.9.6-1.el6.i686.rpm
-r--r--r--. 3 root root 1572996 Nov 25 03:30 openssl-1.0.1e-15.el6.i686.rpm
-r--r--r--. 2 root root 1219248 Nov 25 03:30 openssl-devel-1.0.1e-15.el6.i686.rpm
-r--r--r--. 2 root root 791760 Apr 25 2012 openssl098e-0.9.8e-17.el6.centos.2.i686.rpm
-r--r--r--. 2 root root 105748 Jul 3 2011 qca-ossl-2.0.0-0.8.beta3.1.el6.i686.rpm
-r--r--r--. 2 root root 114224 Sep 20 2012qpid-cpp-client-ssl-0.14-22.el6_3.i686.rpm
-r--r--r--. 2 root root 61756 Sep 20 2012qpid-cpp-server-ssl-0.14-22.el6_3.i686.rpm
[root@host2Packages]# yum install mod_ssl-2.2.15-29.el6.centos.i686.rpm
Loaded plugins: fastestmirror,refresh-packagekit
Loading mirror speeds from cached hostfile
*c6-media:
Setting up Install Process
Examining mod_ssl-2.2.15-29.el6.centos.i686.rpm:1:mod_ssl-2.2.15-29.el6.centos.i686
mod_ssl-2.2.15-29.el6.centos.i686.rpm:does not update installed package.
Error: Nothing to do
[root@host2 Packages]#
[root@host2 Packages]# chkconfig httpd on
Usage: httpd{start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}
[root@host2 Packages]# netstat -tipln |grep80
[root@host2 Packages]# cd
[root@host2 ~]# netstat -tipln |grep 80
[root@host2 ~]# service network restart
Shutting down interface eth0: Device state: 3 (disconnected)
[ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: Active connection state: activating
Active connection path:/org/freedesktop/NetworkManager/ActiveConnection/1
state: activating
state: activated
Connection activated
[ OK ]
[root@host2 ~]# netstat -tipln |grep 80
[root@host2 ~]# netstat -tupln |grep 80
tcp 0 0 :::80 :::* LISTEN 1451/httpd
[root@host2 ~]# cd /etc/httpd
[root@host2 httpd]# ll
total 8
drwxr-xr-x. 2 root root 4096 Apr 20 02:28conf
drwxr-xr-x. 2 root root 4096 Apr 25 00:36conf.d
lrwxrwxrwx. 1 root root 19 Apr 20 02:28 logs ->../../var/log/httpd
lrwxrwxrwx. 1 root root 27 Apr 20 02:28 modules ->../../usr/lib/httpd/modules
lrwxrwxrwx. 1 root root 19 Apr 20 02:28 run ->../../var/run/httpd
[root@host2 httpd]# vim conf/httpd.conf
[root@host2 httpd]# cd /var/www/html
[root@host2 html]# vim .htaccess
root@host2 html]# which htpasswd
/usr/bin/htpasswd
[root@host2 html]# rpm -qf `which htpasswd`
httpd-tools-2.2.15-29.el6.centos.i686
[root@host2 html]# htpasswd -c/var/www/.htpasswd user1
New password:
Re-type new password:
Adding password for user user1
[root@host2 html]# htpasswd /var/www/.htpasswd user2
New password:
Re-type new password:
Adding password for user user2
[root@host2 html]# ll -a
total 268
drwxr-xr-x. 15 root root 4096 May 20 23:04 .
drwxr-xr-x. 6 root root 4096 May 20 23:06 ..
-rw-r--r--. 1 root root 135 May 20 23:04 .htaccess
drwxrwxr-x. 2 root root 4096 Dec 4 2012 BitstreamVeraFonts
drwxrwxr-x. 2 root root 4096Dec 4 2012 admin
drwxrwxr-x. 3 root root 4096 Dec 4 2012 templates
drwxrwxr-x. 4 root root 4096 Dec 4 2012 themes
-rw-rw-r--. 1 root root 3362 Dec 4 2012 userchange.php
[root@host2 html]# cat .htpasswd
[root@host2html]# cd ..
[root@host2 www]# cat .htpasswd
user1:1Z2V2IxaxktqU
user2:9kDZ1dPbt3Kng
[root@host2 www]# cd /etc/httpd
[root@host2 httpd]# vim conf/httpd.conf
[root@host2 httpd]# rpm -qa |grep openssl
openssl-1.0.1e-15.el6.i686
[root@host2 httpd]# cd /etc/pki/tls
[root@host2 tls]# ll
total 24
lrwxrwxrwx. 1 root root 19 Apr 19 23:13 cert.pem ->certs/ca-bundle.crt
drwxr-xr-x. 2 root root 4096 Apr 25 00:36 certs
drwxr-xr-x. 2 root root 4096 Apr 19 23:14 misc
-rw-r--r--. 1 root root 10906 Sep 27 2013 openssl.cnf
drwxr-xr-x. 2 root root 4096 Apr 25 00:36 private
[root@host2 tls]# vim openssl.cnf
[root@host2 tls]# [root@host2 Packages]# ll|grep ssl
-r--r--r--. 2 root root 283912 Jul 3 2011docbook-style-dsssl-1.79-10.el6.noarch.rpm
-r--r--r--. 2 root root 120560 Sep 10 2013 krb5-pkinit-openssl-1.10.3-10.el6_4.6.i686.rpm
-r--r--r--. 2 root root 93340 Aug 14 2013 mod_ssl-2.2.15-29.el6.centos.i686.rpm
-r--r--r--. 2 root root 34212 Jul 6 2011 nss_compat_ossl-0.9.6-1.el6.i686.rpm
-r--r--r--. 3 root root 1572996 Nov 25 03:30 openssl-1.0.1e-15.el6.i686.rpm
-r--r--r--. 2 root root 1219248 Nov 25 03:30 openssl-devel-1.0.1e-15.el6.i686.rpm
-r--r--r--. 2 root root 791760 Apr 25 2012 openssl098e-0.9.8e-17.el6.centos.2.i686.rpm
-r--r--r--. 2 root root 105748 Jul 3 2011 qca-ossl-2.0.0-0.8.beta3.1.el6.i686.rpm
-r--r--r--. 2 root root 114224 Sep 20 2012qpid-cpp-client-ssl-0.14-22.el6_3.i686.rpm
-r--r--r--. 2 root root 61756 Sep 20 2012qpid-cpp-server-ssl-0.14-22.el6_3.i686.rpm
[root@host2 Packages]#
[root@host2 Packages]#
[root@host2 Packages]# rpm -qa httpd
httpd-2.2.15-29.el6.centos.i686
[root@host2 Packages]# yum install httpd-2.2.15-29.el6.centos.i686.rpm
[root@host2 tls]# cd /etc/pki/CA/
[root@host2 CA]# touch index.txt
[root@host2 CA]# touch serial
[root@host2 CA]# openssl genrsa 1024>private/cakey.pem
Generating RSA private key, 1024 bit longmodulus
...........++++++
...........................++++++
e is 65537 (0x10001)
[root@host2 CA]# ll private/cakey.pem
-rw-r--r--. 1 root root 887 May 20 23:25private/cakey.pem
[root@host2 CA]# cat private/cakey.pem
-----BEGIN RSA PRIVATE KEY-----
f5lh+9u8EoO3qvZj/pvWYvrio+NfylWOorRzC+1Oae79
-----END RSA PRIVATE KEY-----
[root@host2 CA]# chmod 600private/cakey.pem
[root@host2 CA]# openssl req -new -keyprivate/cakey.pem -x509 -out cacert.pem
You are about to be asked to enterinformation that will be incorporated
into your certificate request.
What you are about to enter is what iscalled a Distinguished Name or a DN.
There are quite a few fields but you canleave some blank
For some fields there will be a defaultvalue,
If you enter '.', the field will be leftblank.
-----
Country Name (2 letter code) [XX]:
State or Province Name (full name) []:
Locality Name (eg, city) [DefaultCity]:zhengzhou
Organization Name (eg, company) [DefaultCompany Ltd]:gongchengbu
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server'shostname) []:gongchengbu
Email Address []:
[root@host2 CA]# ll
total 24
-rw-r--r--. 1 root root 989 May 20 23:34 cacert.pem
drwxr-xr-x. 2 root root 4096 Nov 22 20:14certs
drwxr-xr-x. 2 root root 4096 Nov 22 20:14crl
-rw-r--r--. 1 root root 887 May 20 23:34 httpd.key
-rw-r--r--. 1 root root 0 May 20 23:24 index.txt
drwxr-xr-x. 2 root root 4096 Nov 22 20:14newcerts
drwx------. 2 root root 4096 May 20 23:25private
-rw-r--r--. 1 root root 0 May 20 23:25 serial
[root@host2 CA]# cd certs
[root@host2 certs]# openssl genrsa 1024>httpd.key
Generating RSA private key, 1024 bit longmodulus
............................................................++++++
...................................................++++++
e is 65537 (0x10001)
[root@host2 CA]# cat index.txt
[root@host2 CA]# ll
total 24
-rw-r--r--. 1 root root 989 May 20 23:34 cacert.pem
drwxr-xr-x. 2 root root 4096 May 20 23:48certs
drwxr-xr-x. 2 root root 4096 Nov 22 20:14crl
-rw-r--r--. 1 root root 0 May 20 23:50 httpd.cert
-rw-r--r--. 1 root root 887 May 20 23:34 httpd.key
-rw-r--r--. 1 root root 0 May 20 23:24 index.txt
drwxr-xr-x. 2 root root 4096 Nov 22 20:14newcerts
drwx------. 2 root root 4096 May 20 23:25private
-rw-r--r--. 1 root root 0 May 20 23:25 serial
[root@host2 CA]# vim index.txt
[1]+ Stopped vimindex.txt
[root@host2 CA]# vim index.txt
[root@host2CA]# vim /etc/httpd/conf.d/ssl.conf
[root@host2 CA]# service httpd restart
Stopping httpd: [ OK ]
[root@host2 CA]# netstat -tupln |grep httpd
tcp 0 0 :::80 :::* LISTEN 2799/httpd
tcp 0 0 :::443 :::* LISTEN 2799/httpd
[root@host2 CA]# netstat -tupln |grcdephttpd
[root@host2 CA]# cd
[root@host2 ~]# cd /etc/httpd/conf
[root@host2 conf]# vim /etc/httpd/conf
[root@host2 conf]# cd /var/www/html/
[root@host2 html]# echo"ceshi">index.html
[root@host2 html]#
測試把證書安裝
測試看結果是不是輸入用戶名就可以顯示ceshi頁面就完成了。