실험: 시 뮬 레이 션 실현 https

19696 단어 linux
우리 가 평소에 인터넷 에 접속 한 적 이 있 는 지 모 르 겠 지만, 우리 가 인터넷 주 소 를 졌 을 때 가끔 이름 (예 를 들 어 www. baidu. com) 을 직접 지 거나 http (예 를 들 어 http: / www. taobao. com) 을 입력 하 는 등 브 라 우 저 에 서 는 자동 으로 https 로 이동 합 니 다.위 (일부 브 라 우 저 는 표시 되 지 않 음) 아래 그림 에서 보 듯 이 불 여우 브 라 우 저 로 두 개의 웹 페이지 를 열 고 차 로 돌아 가면 자물쇠 가 있 는 https 의 사이트 주소 가 나타 납 니 다.
  实验:模拟实现https_第1张图片 实验:模拟实现https_第2张图片
实验:模拟实现https_第3张图片
그래서 현재 많은 웹 페이지 는 이름 을 직접 입력 하 든 http 의 주 소 를 입력 하 든 암호 화 된 비교적 안전 한 https 의 사이트 로 자동 으로 이동 합 니 다. 그래서 다음 에 우 리 는 http 에서 https 로 어떻게 뛰 는 지 간단하게 모 의 해 보 겠 습 니 다.
실험의 마지막 에 제 인증서 가 만 료 되 는 오류 가 발생 했 습 니 다. 해결 하지 못 했 습 니 다. 어떤 신 이 보고 해결 해 주 셨 으 면 좋 겠 습 니 다. 감사합니다!!
1. 실험 배경;                                                                                                                                                                                          
1. https 작업 체제: 1) 클 라 이언 트 (A) 가 서버 엔 드 (B) 에 요청 을 보 냅 니 다.2) B 는 A 에 게 CA 서명 을 하고 CA 의 비밀 키 로 암호 화 된 B 공개 키 의 인증 서 를 보 냅 니 다.3) 클 라 이언 트 (A) 는 일반적으로 CA 를 신뢰 하기 때문에 CA 의 공개 키 가 있 습 니 다. CA 의 공개 키 를 통 해 이 를 풀 고 인증서 가 합 법 적 인지 검증 합 법 적 인 지 를 검증 한 후에 클 라 이언 트 는 B 의 공개 키 를 받 습 니 다.4) 클 라 이언 트 (A) 는 임시 세 션 비밀 키 (session key) 를 생 성하 고 서버 (B) 의 공개 키 로 암호 화하 여 서버 에 보 냅 니 다.5) 、 서버 (B) 는 세 션 비밀 키 를 통 해 사용자 가 요청 한 자원 을 암호 화하 고 클 라 이언 트 에 응답 하여 암호 화 된 데이터 전송 을 완성 합 니 다.
2. 세 션 비밀 키 가 대칭 적 임 을 주의 하 십시오.
3. 기계 세 대 준비: A: 클 라 이언 트 192.168.242.202 (; B: 서버 192.168.242.206 (172.17.0.108), C: CA 192.168.242.248 (여기 세 대의 기계 이름 은 각각 client, server, ca 로 설정)
4. https 는 http 프로 토 콜 과 ssl / tles 프로 토 콜 의 조합 입 니 다. 즉, ssl / tles 로 http 프로 토 콜 의 텍스트 데 이 터 를 암호 화 처리 한 후에 바 이 너 리 형식 으로 전송 합 니 다.
2. 실험 절차;                                                                                                                                                                    
1. C 기계 에서 선생님 성 근 CA;                                                                                                       
1. 필요 한 파일 만 들 기;
[root@ca ~]# cd /etc/pki/CA/                 #    CA    (                 )
[root@ca /etc/pki/CA]# tree                  #               (                 )
.
├── certs
├── crl
├── newcerts                        
└── private

4 directories, 0 files
[root@ca /etc/pki/CA]# touch index.txt      #           
[root@ca /etc/pki/CA]# echo 01 > serial     #             
#  ,             ,         ,        (       ,        )

2. 비밀 키 생 성;
[root@ca /etc/pki/CA]# umask 066;openssl genrsa -out private/cakey.pem -des3 2048    #umask    ;     cakey.pem,-des3     2048       。(       ,        -des3  )
Generating RSA private key, 2048 bit long modulus
...+++
.............................+++
e is 65537 (0x10001)
Enter pass phrase for private/cakey.pem:                                             #      
Verifying - Enter pass phrase for private/cakey.pem:                                 #      
[root@ca /etc/pki/CA]# tree
.
├── certs
├── crl
├── index.txt           #        
├── newcerts
├── private
│   └── cakey.pem    #     
└── serial             #          

3. 자체 서명 인증서 (자신 이 발급 한 인증서);
[root@ca /etc/pki/CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 7500      #  :-new:          、-x509:    CA      、-key:             、-days n:       、-out /PATH/TO/SOMECERTFILE:        
Enter pass phrase for private/cakey.pem:                                                             #            ,         
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) []:henan                                                        # ;
Locality Name (eg, city) [Default City]:zhengzhou                                                  # ;   
Organization Name (eg, company) [Default Company Ltd]:magedu.com                                   #  ;
Organizational Unit Name (eg, section) []:opt                                                      #  ;
Common Name (eg, your name or your server's hostname) []:www.magedu.com                            #      
Email Address []:                                                                                  #  (     )
[root@ca /etc/pki/CA]#

2. 서버 B 가 CA 에 인증 서 를 신청 합 니 다.
1. 가방 mod ssl 을 먼저 넣는다.
[root@server ~]# yum install mod_ssl

이 가방 의 프로필 / etc / httpd / conf. d / ssl. conf;
2. 자신의 비밀 키 를 구축한다.
[root@server ~]# mkdir /etc/httpd/conf.d/ssl/                                            #       http  ,                                 
[root@server ~]# umask 066;openssl genrsa -out /etc/httpd/conf.d/ssl/httpd.key 2048      #         
Generating RSA private key, 2048 bit long modulus
................................................+++
.........+++
e is 65537 (0x10001)
[root@server ~]#

3. 인증서 신청 파일 생 성;
[root@server ~]# openssl req -new -key /etc/httpd/conf.d/ssl/httpd.key -out /etc/httpd/conf.d/ssl/httpd.csr     #       .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) []:henan                                                                    # ;
Locality Name (eg, city) [Default City]:luoyang
Organization Name (eg, company) [Default Company Ltd]:magedu.com                                               #  ;        ,     
Organizational Unit Name (eg, section) []:opt
Common Name (eg, your name or your server's hostname) []:www.sjj.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 []:
[root@server ~]# 

4
루트 에 생 성 된 요청 파일 보 내기
CA
호스트
[root@server ~]# scp /etc/httpd/conf.d/ssl/httpd.csr 192.168.242.248:/etc/pki/CA/                #  CA     ,   /etc/pki/CA  
The authenticity of host '192.168.242.248 (192.168.242.248)' can't be established.
RSA key fingerprint is d9:7b:df:54:60:ae:b0:f9:d2:b2:64:5c:39:8e:69:e4.
Are you sure you want to continue connecting (yes/no)? yes                                       #               
Warning: Permanently added '192.168.242.248' (RSA) to the list of known hosts.
[email protected]'s password:                                                                 #  CA     
httpd.csr                      100% 1045     1.0KB/s   00:00    
[root@server ~]# 

3. 인증서 발급;
1. CA 기기 에서 인증 서 를 생 성 합 니 다.
[root@ca /etc/pki/CA]# openssl ca -in httpd.csr -out certs/httpd.crt -days 300                    #          300 
Using configuration from /etc/pki/tls/openssl.cnf
Enter pass phrase for /etc/pki/CA/private/cakey.pem:                                              #          ,              ;
Check that the request matches the signature
Signature ok
Certificate Details:
        Serial Number: 1 (0x1)
        Validity
            Not Before: Oct 22 03:08:16 2017 GMT
            Not After : Aug 18 03:08:16 2018 GMT
        Subject:                                                                                 #     
            countryName               = CN
            stateOrProvinceName       = henan
            organizationName          = magedu.com
            organizationalUnitName    = opt
            commonName                = www.sjj.com
            emailAddress              = [email protected]
        X509v3 extensions:
            X509v3 Basic Constraints:        
                CA:FALSE
            Netscape Comment: 
                OpenSSL Generated Certificate
            X509v3 Subject Key Identifier: 
                2B:83:77:0F:57:7F:B9:49:EA:00:00:A7:B2:C3:70:11:1D:5B:8F:A7
            X509v3 Authority Key Identifier: 
                keyid:2F:6B:1D:F4:78:8C:DF:1A:17:2E:66:C9:EB:BF:EB:9C:D7:2A:B1:9D

Certificate is to be certified until Aug 18 03:08:16 2018 GMT (300 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

\ # 메모: index. txt 와 serial 두 파일 을 미리 만 들 지 않 았 다 면 인증 서 를 발급 할 때 오류 가 발생 했 을 수 있 으 므 로 오류 알림 에 따라 파일 을 만 들 면 됩 니 다.
[root@ca /etc/pki/CA]# tree
.
├── cacert.pem
├── certs
│   └── httpd.crt #      
├── crl
├── httpd.csr #B           
├── index.txt #                
├── index.txt.attr
├── index.txt.old
├── newcerts
│   └── 01.pem
├── private
│   └── cakey.pem # CA       
├── serial
└── serial.old
[root@ca /etc/pki/CA]# cat index.txt       #                ,        ;              ,     index.txt.old
        
V       180818030816Z           01      unknown /C=CN/ST=henan/O=magedu.com/OU=opt/CN=www.sjj.com/[email protected]
[root@ca /etc/pki/CA]#

2. 생 성 된 인증 서 를 신청자 B 기기 에 전송 한다.
[root@ca /etc/pki/CA]# scp certs/httpd.crt 192.168.242.206:/etc/httpd/conf.d/ssl/        #           
The authenticity of host '192.168.242.206 (192.168.242.206)' can't be established.
RSA key fingerprint is 30:49:c8:65:14:10:12:ba:93:8c:da:97:23:03:b1:88.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.242.206' (RSA) to the list of known hosts.
[email protected]'s password: 
httpd.crt                      100% 4533     4.4KB/s   00:00    
[root@ca /etc/pki/CA]# 

동시에 CA 자신의 인증서 도 복사 합 니 다.
[root@ca /etc/pki/CA]# scp cacert.pem 192.168.242.206:/etc/httpd/conf.d/ssl/     
[email protected]'s password: 
cacert.pem                     100% 1334     1.3KB/s   00:00    
[root@ca /etc/pki/CA]# 

4. 서버 설정 파일 정의 하기;
서버 B 기기 의 / etc / httpd / conf. d / ssl. conf 에는 세 가지 변경 사항 이 있 습 니 다. 원래 내용 은 mod ssl 패 키 지 를 설치 하면 자동 으로 생 성 되 고 관련 인증서 파일 을 만 드 는 것 입 니 다.
	SSLCertificateFile /etc/pki/tls/certs/localhost.crt          #    
	SSLCertificateKeyFile /etc/pki/tls/private/localhost.key     #key  
	#SSLCertificateChainFile /etc/pki/tls/certs/server-chain.crt #CA   ---》        ,        ,     CA ,
  :
	SSLCertificateFile /etc/httpd/conf.d/ssl/httpd.crt               
	SSLCertificateKeyFile /etc/httpd/conf.d/ssl/httpd.key   
	SSLCACertificateFile /etc/httpd/conf.d/ssl/cacert.pem   #      ,          CA ;

5. 환경 검사;
1. 먼저 80 포트 가 열 려 있 는 지 확인 합 니 다: ss - ntl; 80 포트 가 없 으 면 httpd 서비스 가 열 리 지 않 았 음 을 증명 합 니 다: service httpd start 가 서 비 스 를 시작 합 니 다. 포트 가 열 려 있 으 면 service httpdrestart 가 다시 시작 합 니 다.
2. 방화벽 을 검사 합 니 다. iptables - F 로 방화벽 을 닫 는 것 이 좋 습 니 다.
3. SElinux 상태 확인:
[root@client /etc/pki/CA]# getenforce            #    
Enforcing                     
[root@client /etc/pki/CA]# setenforce 0
[root@client /etc/pki/CA]#  getenforce 
Permissive                                     #       ,   setenforce 0    ;

3. 실험 테스트;                                                                            
서버 쪽 B 기기 기본 홈 페이지 는 / var / www / html / index. html 에 있 습 니 다.
[root@server ~]# cat /var/www/html/index.html 
Centos 6

클 라 이언 트 A 에서 curl 명령 으로 검사 하기;
[root@client /etc/pki/CA]# curl http://192.168.242.206/                         #   http    
Centos 6
[root@client /etc/pki/CA]# curl https://192.168.242.206/                        # https      
curl: (60) Peer certificate cannot be authenticated with known CA certificates
More details here: http://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a "bundle"
 of Certificate Authority (CA) public keys (CA certs). If the default
 bundle file isn't adequate, you can specify an alternate file
 using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
 the bundle, the certificate verification probably failed due to a
 problem with the certificate (it might be expired, or the name might
 not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
 the -k (or --insecure) option.
[root@client /etc/pki/CA]#curl -k https://192.168.242.206/                      #  CA     A      ,    -k(    )          
Centos 6

그리고 우 리 는 웹 브 라 우 저 에서 볼 수 있 는데 효과 가 비교적 뚜렷 하 다.
1. 우 리 는 windows 아래 의 "c: \ Windows \ System 32 \ drivers \ etc" 의 hosts 파일 에 192.168.242.206 을 추가 합 니 다.    www.sjj.com ; 172.17.0.108    www.sjj.com;
2. 우 리 는 이름 으로 사이트 에 접근 합 니 다.
다음은 불 여우 브 라 우 저 를 사용 합 니 다.
实验:模拟实现https_第4张图片
实验:模拟实现https_第5张图片
实验:模拟实现https_第6张图片
인증서 정보 보기;
实验:模拟实现https_第7张图片
实验:模拟实现https_第8张图片
"보안 예외 확인" 후 페이지 에 접근 할 수 있 지만 경고 가 있 습 니 다.
实验:模拟实现https_第9张图片
다음은 IE 브 라 우 저 로 보기;
实验:模拟实现https_第10张图片
"자 왕 역 을 계속 둘 러 보 세 요."

"인증서 오류" 를 보고 하고 여 기 를 클릭 하면 "인증서 보기" 가 나타 나 고 들 어가 기 를 클릭 합 니 다.
实验:模拟实现https_第11张图片
신뢰 할 수 없 는 인증서 기관 이 라 고 하 니 신뢰 하고 인증 서 를 설치 하 세 요.
实验:模拟实现https_第12张图片
实验:模拟实现https_第13张图片
제시 에 따라 한 걸음 한 걸음 걷다.
实验:模拟实现https_第14张图片
마지막 으로 다음 과 같은 인터페이스 가 나타 나 고 설치 성공 을 나타 낸다.
实验:模拟实现https_第15张图片
그러나 인증 서 를 가 져 온 후에 제 인증 서 는 만 료 된 인증서 가 되 었 습 니 다. 다음 그림 에서 보 듯 이 저 는 인증 서 를 다시 신청 하고 여러 번 시도 해 보 았 습 니 다. 아직도 이 렇 습 니 다. 무슨 이유 인지 모 르 겠 습 니 다.
实验:模拟实现https_第16张图片
이 스티커 를 보신 분 들 이 도와 주 셨 으 면 좋 겠 습 니 다. 감사합니다!!
 
  
 
  
 
  
 
  
 
  
 
  
 
  
 
  
 
  
 
  
 
 

좋은 웹페이지 즐겨찾기