Network protocol - HTTPS

encryption

  1. In symmetric encryption algorithm, the encryption and decryption keys are the same , and therefore, symmetric encryption algorithms to ensure the security, then key remains confidential
  2. In asymmetric encryption algorithm, the encryption and decryption keys are different , and are a public key , it is a secret key
    • Public key encryption, only the private key can decrypt the private key encryption, public key can decrypt only
  3. In efficiency and performance terms, a symmetric encryption algorithm is better than asymmetric encryption algorithm

Symmetric encryption

  1. Browser and server agree on a key, when the browser sends a request encrypted with this key, the server decrypts with the same key
  2. But how key it agreed? A key assumptions used to encrypt the key of B, but how do B key agreement, so it will fall into an infinite loop

Asymmetric encryption

  1. Asymmetric encryption private key in the server, is not transmitted over the network, to ensure that the private key is private , while the private key corresponding to the public key is available on the web circulate freely in
  2. Public key encryption server browser with the information sent to the server, even if the middle was intercepted by hackers, but also can not be decrypted, because the private key to decrypt only use the service side
    • But the information server response is everyone can be decrypted, because it is encrypted with the private server, with the corresponding public key can decrypt - unsafe
  3. In addition, if only one pair of public and private key, hackers can simulate normal user behavior because the server's public key is public
  4. Seen in this light, a pair of public and private key is not enough, the browser also needs its own public and private keys
    • Public key encryption server response to the browser, the browser; browser requests the server, encrypted with the public server
    • In this way, there is no way to simulate hacker browser to get information, or intercept a response message, because hackers without the private key browser or server, can not decrypt

Digital Certificates

  1. Your public key can only solve your problem but not solve the problem of who you are, hence the need for certificate
  2. Since anyone can create private and public keys, requiring authorities to intervene, and authorities issued called a certificate (Certificate)
  3. Content certificate includes a public key , the certificate owner , the certificate issuing authority , the certificate is valid
  4. Generate the certificate needs to initiate a certificate request , and then sent to a authority ( CA , Certificate Authority) to certification
  5. Authority will use its private key to the certificate signature ( Signature Algorithm )

Signing Certificate

  1. Information to make a Hash calculation to obtain a Hash value, the process of formula irreversible in
  2. With the CA's private key will be the Hash value encryption as a signature , and then sent out with information
  3. Simple statement:signature = encrypt(hash(msg), ca_private_key)
  4. Endorsement: CA with its private key to the public key signature A website !!

Issuer: Who issued; Subject: to whom the certificate is issued; Validity: Certificate deadline, Public Key: the public key content; Signature Algorithm: Signature Algorithm

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
openssl x509 -in server-cert.pem -noout -text
Certificate:
Data:
Version: 1 (0x0)
Serial Number: 11689652687981033366 (0xa239fd2f6eccb796)
Signature Algorithm: sha256WithRSAEncryption
Issuer:
Validity
Not Before: Aug 19 03:53:44 2019 GMT
Not After : Aug 18 03:53:44 2020 GMT
Subject: CN=zhongmingmao.me
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
Public-Key: (4096 bit)
Modulus:
00:be:75:a7:9d:85:c1:a5:d1:e7:d6:59:66:6e:3a:
...
3a:6a:e9
Exponent: 65,537 (0x10001)
Signature Algorithm: sha256WithRSAEncryption
a5: b9: 65: 10: 4e: 46: 50: 1e: 3f: b0: ae : 3f: bf: a0: 88: 94: e4: e2:
...
c2 : ca: 81: 06: e4: 9c: 6b: 66

The layers of credit

  1. As a result, the browser get from A website is no longer a public key, but will get a certificate , the certificate issuing authority will have a CA
  2. Just need to get the agency to issue a public key of the CA , the signature to decrypt A site certificate, if the decryption is successful, Hash also on the public website description no problem
  3. Certificate of verification process, the need CA's public key, that determine how CA public key is right?
    • CA's public key need for more advanced CA to sign it, and then form a CA certificate
    • To know if a CA certificate is reliable, superior public need to see CA certificates, can not solve the CA's signature
    • Such layers up until rootCA, final endorsement by which the layers of credit endorsement of the way to ensure that asymmetric encryption normal operation mode

HTTPS mode of operation

  1. Asymmetric encryption performance as good as the symmetric encryption
  2. Public key is asymmetrically encrypted symmetric encryption is mainly used for transmission of the key, and a large number of real symmetric encryption completed data communication
  1. When you log HTTPS site, the client first sends a Client Hello message to the server
    • 明文传输TLS版本信息加密套件候选列表压缩算法候选列表
    • 另外还会有一个随机数,用户后续的对称密钥协商
  2. 网站会返回Server Hello消息
    • 告诉客户端,服务器选择使用的协议版本加密套件压缩算法
    • 另外还会有一个随机数,用户后续的对称密钥协商
  3. 网站会发送Server Certificate消息,里面包含服务器端的证书,最后网站会发送Server Hello Done消息
  4. 客户端肯定不会直接信任该证书,于是会从它自己信任的CA仓库中,拿CA证书的公钥去解密网站的证书
    • 如果能成功,说明网站是可信的
    • 这个过程可能会不断地往上追溯,直到一个授信的CA
  5. 客户端在验证完服务端的证书后,会计算产生随机数pre-master,发送Client Key Exchange
    • 服务器证书中的公钥加密,再发送给服务器,服务器可以通过私钥进行解密
    • 到目前为止,无论是客户端还是服务器,都已经有了三个随机数
    • 通过这三个随机数,可以在客户端和服务端产生相同的对称密钥
  6. 计算出对称密钥后,客户端会发送Change Cipher Spec消息,表示后面都采用协商的通信密钥加密算法进行加密通信
  7. 客户端发送Encrypted Handshake Message消息
    • 将已经商定好的参数,采用协商密钥进行加密,发送给服务器用于数据和握手验证
  8. 服务器也可以发送Change Cipher Spec消息和Encrypted Handshake Message消息,目的与客户端的一致
  9. 双方握手结束后,就可以用对称密钥进行加密传输了
    • 这个过程除了加密解密外,其他过程与HTTP是一样的
  10. 上面的过程只包含了HTTPS的单向认证,即客户端验证服务器端的证书
    • 在对安全要求更严格的场景下,可以启用双向认证,即服务器也会验证客户端的证书

重放和篡改

  1. 重放
    • 有了加密和解密,黑客即使截获了包,也无法打开,但可以选择重放
    • Solution: The Timestamp and Nonce random numbers together, do a irreversible signature
    • Nonce guarantee a unique random number or random number Nonce and Timestamp guaranteed unique together, once the same request acceptance
    • Server repeatedly receive the same random number Nonce and Timestamp, are considered invalid
  2. tamper
    • The signature is irreversible , the equivalent of having a tamper-proof nature
    • Hackers can modify Timestamp and Nonce random numbers, but can not modify the signature server solution with a signature algorithm will find out not on both, will directly discarded

summary

  1. Encryption is divided into symmetric encryption and asymmetric encryption
    • Symmetric encryption high efficiency , but it can not solve the key transmission problems
    • Asymmetric encryption can solve this problem, but the efficiency is not high
  2. Asymmetric encryption required by the certificate and authority CA to verify that the server public key legitimacy
  3. HTTPS is a combination of symmetric encryption algorithms and asymmetric encryption HTTP protocol algorithm, both to ensure transmission security , but also to ensure the transmission efficiency

Original: Big Box  network protocol - HTTPS


Guess you like

Origin www.cnblogs.com/chinatrump/p/11584926.html