Because the content of http is transmitted in clear text, it will pass through many physical nodes, such as intermediate proxy server, router, wifi hotspot, communication service operator and so on. If the information is hijacked in the process of transmission, the content of transmission will be completely exposed, and the transmitted information can be tampered with without being detected by both parties. This is a man-in-the-middle attack. So the information needs to be encrypted.
A secret key that encrypts a piece of content and can only be used to decrypt the original content. Transmission process:
Two keys, one public key and one private key. The content encrypted with the public key can only be solved with the private key. Similarly, the content encrypted by the private key can only be solved by the public key. Transmission process:
Use two sets of public and private keys Drawback: asymmetric encryption algorithms are very time-consuming
Transmission process:
Vulnerability: forged CA certificate.
Generate a "signature" for the content, and you can detect whether it has been tampered with by comparing whether the content and the signature are consistent. The process of generating a digital signature:
the main task is to decrypt the digital signature. Compare it with the content.
- Get the content and digital signature encrypted by the CA private key. two。 The encrypted digital signature is decrypted with the public key of the CA mechanism, and the digital signature is obtained. because CA is an organization trusted by browsers, browsers keep the public key of CA.
- Hash the digital signature using the hash algorithm described in the certificate to get the content protected by the digital signature.
- Comparing whether the [content protected by digital signature] is equal to the content indicates that the certificate is credible.
Why do I need hash?
What you get after hash is that the encryption and decryption of fixed-length information is much faster.
How to prove that the CA public key is trusted?
The browser holds the CA public key. How can you prove that the public key is trusted? The operating system and browsers themselves will preinstall some root certificates they trust (such as CA certificates).
Does HTTPS have to shake hands at the SSL/TLS layer to transfer the key in each request?
The server maintains a session ID for each browser (or client software), which is passed to the browser during the TSL handshake phase, and the key is cached to session. There is no need for duplicate authentication during the session.