日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
HTTP/HTTPS自動加密上網(wǎng)

HTTP/HTTPS如何自動加密上網(wǎng)?本篇文章重點為大家講解一下HTTP/HTTPS自動加密上網(wǎng)具體方案,有需要的小伙伴可以參考一下。

樂都網(wǎng)站建設公司創(chuàng)新互聯(lián)建站,樂都網(wǎng)站設計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為樂都上千提供企業(yè)網(wǎng)站建設服務。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站建設要多少錢,請找那個售后服務好的樂都做網(wǎng)站的公司定做!

方案介紹

涉及到的軟件

  1. BIND: 一個流行的域名解析服務器,我們可以設置哪些域名需要走加密線路。
  2. Stunnel: 使用TLS對tcp協(xié)議進行加密,也就是對tcp建立一條加密線路。
  3. SNI Proxy: 代理軟件。對于HTTP協(xié)議,它可以根據(jù)Host請求頭解析得出目標站IP;對于HTTPS協(xié)議,它可以根據(jù)SNI擴展中的域名解析得出目標站IP。

此方案優(yōu)缺點

優(yōu)點:
無需手動設置任何代理,就能夠自動加密代理特定網(wǎng)站的HTTP或HTTPS協(xié)議
相對于我們常用的ssh隧道,ssh隧道是單路,而此方案是支持多并發(fā)連接,可以極大加速網(wǎng)站訪問。

缺點:
對于代理HTTPS協(xié)議,需要發(fā)起HTTPS連接的客戶端,比如瀏覽器支持TLS的SNI擴展。好消息是目前瀏覽器幾乎都支持此擴展,但對于一些非瀏覽器的客戶端,不支持SNI擴展。我們只能設置正向代理來解決此問題。

方案原理

流程圖:

原理介紹:
1、首先我們需要準備三臺服務器,一臺是內網(wǎng)DNS服務器(安裝bind),一臺是內網(wǎng)代理服務器(安裝stunnel),另一臺國外服務器(安裝stunnel,sniproxy)。
2、我們還需要設置DNS為內網(wǎng)的DNS,并在內網(wǎng)bind dns設置谷歌域名解析的IP為內網(wǎng)代理服務器
3、當我們訪問谷歌網(wǎng)站時,首先會向內網(wǎng)DNS服務器發(fā)送DNS A記錄查詢,此時內網(wǎng)DNS服務器會返回內網(wǎng)代理服務器的IP。
4、瀏覽器得到谷歌域名的解析IP后(即內網(wǎng)代理服務器的IP),會向內網(wǎng)代理服務器發(fā)送HTTP或HTTPS請求。
5、此時內網(wǎng)代理服務器(即stunnel),會接收到請求,經(jīng)過加密,把請求轉發(fā)到國外服務器(stunnel)的指定端口上。
6、國外服務器(stunnel)接收到來自國內服務器(stunnel)的加密數(shù)據(jù)后,經(jīng)過解密,把請求轉發(fā)到sniproxy。
7、sniproxy再根據(jù)HTTP Host請求頭或者HTTPS sni擴展的域名解析出谷歌服務器的IP,并把請求轉發(fā)給谷歌服務器。
8、谷歌服務器收到來自sniproxy發(fā)送的請求后,馬上返回網(wǎng)頁內容給sniproxy,sniproxy再原路返回數(shù)據(jù)給瀏覽器。

方案實施

由于時間有限,我們僅在Ubuntu server 12.04演示安裝。

環(huán)境介紹

系統(tǒng):Ubuntu server 12.04

內網(wǎng)DNS IP: 10.96.153.201(主),10.96.153.204(從)

內網(wǎng)代理服務器: 10.96.153.204

國外服務器IP: 1.2.3.4

安裝BIND9

1、在主DNS和從DNS安裝bind,即10.96.153.201(主),10.96.153.204(從)。

    wget http://www.isc.org/downloads/file/bind-9-10-0b1-2/?version=tar.gz -O bind-9-10-0b1-2.tar.gz
    tar xzf bind-9-10-0b1-2.tar.gz
    cd bind-9-10-0b1-2
    ./configure --prefix=/usr/local/bind
    make && make install

2、配置主DNS服務器(10.96.153.201)

2.1、生成/usr/local/bind/etc/rndc.key密鑰文件

/usr/local/bind/sbin/rndc-confgen -a -k rndckey -c /usr/local/bind/etc/rndc.key

2.2、編輯/usr/local/bind/etc/named.conf,寫入如何內容:

    include "/usr/local/bind/etc/rndc.key";
    controls { inet 127.0.0.1 port 953 allow { 127.0.0.1; } keys { "rndckey"; }; };
    logging {
    channel default_syslog { syslog local2; severity notice; };
    channel audit_log { file "/var/log/bind.log"; severity notice; print-time yes; };
    category default { default_syslog; };
    category general { default_syslog; };
    category security { audit_log; default_syslog; };
    category config { default_syslog; };
    category resolver { audit_log; };
    category xfer-in { audit_log; };
    category xfer-out { audit_log; };
    category notify { audit_log; };
    category client { audit_log; };
    category network { audit_log; };
    category update { audit_log; };
    category queries { audit_log; };
    category lame-servers { audit_log; };
    };
    options {
        directory "/usr/local/bind/etc";
    pid-file "/usr/local/bind/var/run/bind.pid";
    transfer-format many-answers;
    interface-interval 0;
    forward only;
    forwarders { 202.96.128.166;202.96.134.133; };
    allow-query {any;};
    };
    zone "google.com" {
    type master;
    file "google.com.zone";
    allow-transfer { 10.96.153.204; };
    };

在這個named.conf文件中,我們只需要關心如下內容:

對于options{}區(qū)域,202.96.128.166和202.96.134.133這兩個是ISP提供的本地DNS,需要修改為自己所在ISP的本地DNS。
對于zone “google.com”{}區(qū)域,這里定義了google.com域名的區(qū)域文件google.com.zone,還有允許10.96.153.204(即從DNS)同步區(qū)域文件。

2.3、建立google.com.zone區(qū)域文件:

    $TTL 3600
    @ IN SOA ns1.google.com. hostmaster.google.com. (
    2014072015  ; Serial
    3600 ; Refresh
    900 ; Retry
    3600000 ; Expire
    3600 ) ; Minimum
    @ IN NS ns1.google.com.
    @ IN NS ns2.google.com.
    ns1 IN A 10.96.153.201
    ns2 IN A 10.96.153.204
    @ IN A 10.96.153.204
    * IN A 10.96.153.204

對于這個區(qū)域文件:
ns1 IN A 10.96.153.201 指向第一個dns服務器,即主DNS。
ns2 IN A 10.96.153.204 指向第二個dns服務器,即從DNS。
@ IN A 10.96.153.204和* IN A 10.96.153.204指向內網(wǎng)的代理服務器(stunnel)。我們只需要修改這三個地方就好了。

3、配置從DNS服務器(10.96.153.204)
編輯named.conf,寫入如下內容

    logging {
    channel default_syslog { syslog local2; severity notice; };
    channel audit_log { file "/var/log/bind.log"; severity notice; print-time yes; };
    category default { default_syslog; };
    category general { default_syslog; };
    category security { audit_log; default_syslog; };
    category config { default_syslog; };
    category resolver { audit_log; };
    category xfer-in { audit_log; };
    category xfer-out { audit_log; };
    category notify { audit_log; };
    category client { audit_log; };
    category network { audit_log; };
    category update { audit_log; };
    category queries { audit_log; };
    category lame-servers { audit_log; };
    };
    options {
        directory "/usr/local/bind/etc";
    pid-file "/usr/local/bind/var/run/bind.pid";
    transfer-format many-answers;
    interface-interval 0;
    forward only;
    forwarders { 202.96.128.166;202.96.134.133; };
    allow-query {any;};
    };
     
    zone "google.com" {
    type slave;
    file "google.com.zone";
    masters { 10.96.153.201; };
    };

配置從DNS就簡單得多,只需要寫入如上內容到named.conf文件。同樣的,options{}中202.96.128.166和202.96.134.133這兩個是當?shù)豂SP本地dns。zone “google.com”{}中10.96.153.201指明主DNS服務器IP。
4、啟動bind dns服務器

/usr/local/bind/sbin/named

安裝Stunnel

1、在內網(wǎng)代理服務器和國外主機安裝stunnel

    apt-get install stunnel4

2、內網(wǎng)代理服務器stunnel配置
編輯/etc/default/stunnel4,設置ENABLED=1。

    client = yes
    pid = /etc/stunnel/stunnel.pid
    [http]
    accept = 80
    connect = 1.2.3.4:8082
     
    [https]
    accept = 443
    connect = 1.2.3.4:4433

此配置文件表示,監(jiān)聽了80端口,并把此端口流量轉發(fā)到1.2.3.4:8082,監(jiān)聽了443端口,并把此端口流量轉發(fā)到1.2.3.4:4433

3、國外服務器stunnel配置

3.1、生成ssl證書stunnel.pem文件

    openssl genrsa -out key.pem 2048
    openssl req -new -x509 -key key.pem -out cert.pem -days 1095
    cat key.pem cert.pem >> /etc/stunnel/stunnel.pem

3.2、編輯/etc/stunnel/stunnel.conf文件

    client = no
    [http]
    accept = 1.2.3.4:8082
    connect = 127.0.0.1:8082
    cert = /etc/stunnel/stunnel.pem
     
    [https]
    accept = 1.2.3.4:4433
    connect = 127.0.0.1:4433
    cert = /etc/stunnel/stunnel.pem

此配置文件表示,監(jiān)聽了1.2.3.4:8082,并轉發(fā)此地址流量到127.0.0.1:8082,監(jiān)聽了1.2.3.4:4433,并轉發(fā)給地址流量到127.0.0.1:4433。

3.3、編輯/etc/default/stunnel4,設置ENABLED=1。

4、啟動stunnel

    service stunnel4 start

安裝sniproxy

sniproxy項目地址:https://github.com/dlundquist/sniproxy

1、安裝sniproxy
同樣只演示在ubuntu server 12.04安裝。

1.1、安裝UDNS

    mkdir udns_packaging
    cd udns_packaging
    wget http://archive.ubuntu.com/ubuntu/pool/universe/u/udns/udns_0.4-1.dsc
    wget http://archive.ubuntu.com/ubuntu/pool/universe/u/udns/udns_0.4.orig.tar.gz
    wget http://archive.ubuntu.com/ubuntu/pool/universe/u/udns/udns_0.4-1.debian.tar.gz
    tar xfz udns_0.4.orig.tar.gz
    cd udns-0.4/
    tar xfz ../udns_0.4-1.debian.tar.gz
    dpkg-buildpackage
    cd ..
    dpkg -i *.deb

1.2、安裝sniproxy

    apt-get install autotools-dev cdbs debhelper dh-autoreconf dpkg-dev gettext libev-dev libpcre3-dev libudns-dev pkg-config
    wget https://github.com/dlundquist/sniproxy/archive/master.zip
    unzip master.zip
    cd sniproxy-master/
    dpkg-buildpackage
    cd ..
    dpkg -i *.deb

2、配置sniproxy
/etc/sniproxy.conf內容如下:

    user daemon
    pidfile /var/run/sniproxy.pid
    error_log {
        syslog deamon
        priority notice
    }
    listen 127.0.0.1:8082 {
        proto http
        table http_hosts
    }
    table http_hosts {
            .*      *:80
    }
     
    listen 127.0.0.1:4433 {
        proto tls
        table https_hosts
    }
    table https_hosts {
    .* *:443
    }

此配置文件表示,監(jiān)聽了127.0.0.1:8082地址,并解析http協(xié)議中的Host請求頭為IP,然后轉發(fā)請求到此IP;監(jiān)聽了127.0.0.1:4433地址,并解析TLS中SNI擴展中的域名為IP,并轉發(fā)請求到此IP。

3、啟動sniproxy

    sniproxy

結束
到目前為止,我們已經(jīng)搭建完成了整套HTTP/HTTPS加密代理方案。方案中的HTTP明文協(xié)議,利用stunnel使用了TLS加密,變成了HTTPS協(xié)議,使得數(shù)據(jù)包無法被解析出明文。方案中的HTTPS協(xié)議,本身是加密的,但為了防止SNI擴展的中域名被嗅探,還是走了stunnel的加密通道。對于發(fā)送HTTPS請求而不支持SNI擴展的客戶端,需要手動設置下代理。


名稱欄目:HTTP/HTTPS自動加密上網(wǎng)
鏈接分享:http://www.dlmjj.cn/article/djcdcco.html