A paragraph to sum up HTTPS:
HTTPSIn order to secure the communication process between the client and the server side, the symmetric encryption algorithm must be used, but the asymmetric encryption algorithm is needed to ensure security. However, the process itself is not safe to use asymmetric encryption, and the possibility of tampering with the public key is possible.So the client and server do not use the public key directly, but use the certificate issued by the digital certificate issuing authority to ensure the security of the asymmetric encryption process itself. In this way, a symmetric encryption algorithm can be consulted through these mechanisms, so that both sides can use this algorithm to encrypt and decrypt. It solves the client and server side.The problem of communication security between them.
1.Communication is plaintext (not encrypted) and content may be eavesdropper.
2.If you do not verify the identity of the communication party, you may encounter camouflage. (anyone can send a request, no matter who the other person is, will return to respond).
3.It is impossible to prove the integrity of the message. It may be tampered with. (there is no way to confirm the request / response sent out and the received request / response consistent).
HTTPS (Secure Hypertext Transfer Protocol)The Secure Hypertext Transfer Protocol is a secure communication channel, which is developed based on HTTP to exchange information between the client computer and the server. It uses the secure sockets layer (SSL) for information exchange. In simple terms, it is a secure version of HTTP, and is a HTT encrypted with TLS/SSL.P protocol. The HTTP protocol uses a clear message to transmit information, and there is a risk of information eavesdropping, information tampering and information hijacking. The protocol TLS/SSL has the functions of identity verification, information encryption and integrity checking, which can avoid such problems.
TLS/SSLThe full name secure transport layer protocol Transport Layer Security, a layer of security protocols between TCP and HTTP, does not affect the original TCP protocol and the HTTP protocol, so the use of HTTPS is basically not necessary for the HTTP pages.A lot of transformation.
The level of risk is high.
TLS/SSLThe realization of functions mainly depends on three basic algorithms:The hash function Hash, symmetric encryption and asymmetric encryption make use of asymmetric encryption to realize identity authentication and key negotiation. The symmetric encryption algorithm encrypts the data using a negotiated key, and verifies the integrity of the information based on hash function. Such
Hash function Hash
MD5, SHA1, and SHA256 are common. This function is characterized by unidirectional and irreversible function, very sensitive to input, and fixed output length. Any modification to the data will change the result of the hash function.It is used to prevent information tampering and verify the integrity of data.;
In the process of information transmission, the hash function can not be used to prevent the tampering of information, because the information transmission, the intermediate person can modify the information and recalculate the information summary, so it is necessary to encrypt the information of the transmission and the information summary.
Common are AES-CBC, DES, 3DES, AES-GCM and so on. The same key can be used.Encryption and decryption of information，The key to obtain information is to prevent information from eavesdropping, and the communication mode is 1 to 1.
The advantage of symmetric encryption is that information transmission is 1 to 1, and the same password needs to be shared. The security of the password is the basis for ensuring information security. The server is communicating with the N client. It needs to maintain the N password record and lack the mechanism to modify the password.
The common RSA algorithm also includes ECC, DH and other algorithms. The algorithm is characterized by the occurrence of keys in pairs, commonly known as public key (open) and private key (secret).The information of public key encryption can only be untied by private key, and private key encrypted information can only be untied by public key.。Therefore, the different clients who master the public key can not decrypt information between each other. They can only communicate with the servers that master the private key. The server can achieve more than 1 pairs of communication, and the client can also use it.Verify the identity of the server that holds the private key。
Asymmetric encryption is characterized by more than 1 pairs of information transmission. The server can communicate with multiple clients only by maintaining one private key, but the information sent by the server can be decrypted by all clients, and the computation is complex and the speed of encryption is slow.
Combined with the characteristics of the three kinds of algorithms, the basic working mode of TLS is:The client uses asymmetric encryption (public key encryption) to communicate with the server to authenticate and negotiate the key used for symmetric encryption, and then symmetric encryption (shared key encryption) algorithm uses negotiation key to encrypt information and information digest，The symmetric keys used by different nodes are different, so that information can only be acquired by both sides of communication.
Using asymmetric encryption algorithm, the client needs to hold a public key at the very beginning, or not to encrypt the behavior.How to get the client to secure the public key?
Scenario: the server sends the public key to each client. But if you send it directlyWhat about the public key being wrapped up?If we use asymmetric encryption again, it will be another.Chicken egg raw chicken problem?
The problem of the public key being transferred is because our client can not tell whether the person returning the public key is an intermediary or a real server. This is actually mentioned in cryptography.Authentication problem?
Use of third party institutions and digital certificates
Instead of passing the public key of the server directly to the client, the third party uses its private key to encrypt our public key before transmitting it to the client. The client then decrypts the public key of the third party mechanism. If it can be decrypted, it means that the public key is not transferred by middleman. Because if the middleman uses itThe private key is encrypted to the client, and the client is unable to decrypt by using the third party’s public key.
Scenario: the third party organization can not only produce certificates for a company, it may also issue certificates to such bad companies as middlemen. In this way, the middleman will have the opportunity to pack your certificate. In this case, the client can not tell whether it is your certificate or the middleman. becauseFor intermediaries or your certificates, you can use the third party’s public key to decrypt.
Digital signature solves the problem of tampering with different certificates issued by the same organization. First of all, we need to think clearly about a problem, and identify the responsibilities of different certificates in the same organization. Where should we put it? It can only be placed on the client side. It means that the client will be able to distinguish whether the certificate has been tampered with after obtaining the certificate.How can we have this ability?
We find inspiration from reality. For example, you are HR, you get a candidate’s diploma on your hand, the certificate has written a witness, the issuing agency, the issuing time and so on, and on the certificate, there is also one of the most important: the certificate number! How can we identify the authenticity of this certificate? Just take the certificate numberIf the certificate is consistent with the actual candidate and the certificate number can correspond, the certificate is true.
But where is the “third party organization”? Is it a remote service? Isn’t it possible? If it’s a remote service, the whole interaction will be slow. Therefore, the verification function of the third party organization can only be placed on the local side of the client.
1. The client initiates the HTTPS request
This is nothing to say, that is, the user enters a HTTPS address in the browser and then connects to the 443 port of server.
2. Server configuration
The server that uses the HTTPS protocol must have a set of digital certificates, which can be produced by itself, or can be applied to the organization. The difference is that the certificate that you issued requires the client authentication to pass through, and can continue to access, and the certificate that is applied by the trusted company does not pop up the prompt page (startssL is a good choice with 1 years of free service. The certificate is actually a pair of public keys and private keys. If you don’t understand the public key and the private key too much, you can imagine a key and a lock. Only if you have the key in the world, you can give the lock to others and others can use this lock.The important thing is locked up and sent to you, because only you have the key, so only you can see what is locked by this lock.
3. Transfer certificate
This certificate is actually a public key, but contains a lot of information, such as the issuing authority of the certificate, the expiration date and so on.
4. Client parsing certificate
This part of the work is done by the client’s TLS. First, it will verify whether the public key is valid, such as the issuing agency, the expiration time, and so on. If the exception is found, a warning box will be popped out to indicate the problem of the certificate. If there is no problem with the certificate, a random value is generated. And then with the certificate to the randomThe value is encrypted. As mentioned above, lock the random value with a lock, so that unless you have a key, you won’t see the contents locked. It
5. Transmit encrypted information
This part sends the random value after the certificate is encrypted, the purpose is to let the server get the random value, and then the communication between the client and the server can be encrypted and decrypted through the random value.
6. Server-side decryption information
After decrypting the private key, the server gets the random value (private key) transmitted by the client, and then encrypts the content through the value. Symmetric encryption means that the information and the private key (random value) are mixed together through some algorithm, so that the content can not be obtained unless the private key (random value) is known.The private key (random value) is known to both the client and the server, so as long as the encryption algorithm is tough enough, the private key (random value) is complex enough, and the data is safe enough.
7. Transmission of encrypted information
This part of the information is the information encrypted by the server using the private key (random value) and can be restored on the client side.
8. Client-side decryption information
The client uses the previously generated private key (random value) to decrypt the information transmitted by the server, thus obtaining the decrypted content. During the whole process, the third party was helpless even if they monitored the data.
HTTPSProtocol message interaction process
Step 1: the client starts the SSL communication by sending the Client Hello message. The message contains the specified version of the SSL supported by the client, the list of Cipher Suite (the encryption algorithm and key length used).
Step 2: when the server can carry out SSL communication, it will reply with Server Hello message. Like the client, the SSL version and encryption component are included in the message. The contents of the encrypted component of the server are filtered from the received client encryption components..
Step 3: after that, the server sends the Certificate message. The message contains the public key certificate.
Step 4: finally, the server sends the Server Hello Done message to the client, and the initial SSL handshake negotiation part ends.
Step 5:SSL after the first handshake is ended, the client responds to the Client Key Exchange message. The message contains a random cipher string called Pre-master secret used in communication encryption. The message has already been reportedUse the public key in step 3 to encrypt.
Step 6: then the client continues to send the Change Cipher Spec message. The message will prompt the server. The communication after this message will be encrypted by Pre-master secret key.
Step 7: the client sends the Finished message. The message contains the overall check value for all packets up to now. The success of this handshake negotiation depends on whether the server can decrypt the message correctly.
Step 8: the server also sends Change Cipher Spec messages.
Step 9: the server sends the same Finished message.
Step 10: after the Finished message exchange between the server and the client is completed, the SSL connection will be completed. Of course, the communication will be protected by the SSL. From then on, the application layer protocol is started to communicate, that is, to send HTTP requests.
Step 11: application layer protocol communication, that is, send HTTP response.
Step 12: finally, the connection is disconnected by the client. When the connection is disconnected, the close_notify message is sent. The above figure has done some ellipsis. After that, send the TCP FIN message to close the communication with TCP. In the above process, the application layer will attach data when it sends data.Add a message digest called MAC (Message Authentication Code). MAC can detect whether the message is tampered with, thereby protecting the integrity of the message. It
Self signed certificate
If you use the openSSL set of open source programs, you can build a certification body of your own to issue yourself a server certificate for yourself, but the server certificate is not used as a certificate on the Internet.
The certification body that is built independently is called the self certification certificate issued by the self certification body. When browsers access the server, they will show “unable to confirm connection security” or “there is a problem with the security certificate on the website”.
HTTPSClient certificates can also be used. Client certificates are used for client authentication, proving that the server is always communicating as a expected client, acting as a server certificate.
When you want to get a certificate, the user needs to install the client certificate on its own. The certificate is paid for, and each certificate corresponds to each user to mean the cost of paying and the number of users. In addition, it is full of challenges for different users to install their own certificates.
The present situation is that a highly secure authentication institution can issue client certificates but only for special purpose services. For example, the bank’s net silver uses a client certificate. A client certificate can only prove the actual existence of the client, but can not be used to prove the authenticity of the user.
SSL’s biggest problem – slow!
SSLThere are two kinds of slowness: one is slow communication, the other is the slow processing speed due to the huge consumption of CPU and memory resources.
The network load may be 2 to 100 times slower than the use of HTTP. Remove the TCP connection and send the HTTP request & in addition to the response, the SSL communication must be carried out, so the overall processing traffic will inevitably increase.
The other point is that the SSL must be encrypted. Both the server and the client should be encrypted and decrypted. The hardware resources of the server and the client are consumed more than the HTTP, resulting in the load enhancement.
There is no fundamental solution to the problem of slow speed.Optimization scheme：
HTTPS The increase delay is mainly transmission delay RTT, the characteristic of RTT is that the closer the node is, the smaller the delay time, the CDN is the nearest to the user. Therefore, the choice of CDN as the entrance of HTTPS access will greatly reduce the access delay. CDN nodes are maintained through and service serversControllable methods such as long connection, session multiplexing and link quality optimization can greatly reduce the delay caused by HTTPS.
HTTPS Even if the session cache is at least 1*RTT delay, at least the delay has been reduced to half of the original, the obvious delay optimization; at the same time, the HTTPS connection based on the session cache does not require the server to decrypt the Pre-master information using the RSA private key,To save the consumption of CPU. If the business access connection is centralized and the cache hit rate is high, the access capability of HTTPS can be significantly improved. At present, the cache hit rate of the TRP platform is more than 30% in the peak period. The access resources of 10k/s can actually carry 13k/ access, and the effect is very considerable.
Install a dedicated SSL hardware acceleration card for the access server, which is similar to GPU, release CPU, and can have higher HTTPS access capabilities without affecting the business program. Testing a hardware acceleration card can provide 35K decryption capability, equivalent to 175 core CPU toIt is less than 7 servers with 24 cores. Considering the overhead of other programs in the access server, a hardware card can achieve access capability close to 10 servers.
The local access consumes too much CPU resources, wastes the resources of the network card and hard disk, and considers the RSA decryption computing task that consumes the most CPU resources to other servers, so that the access ability of the server can be fully exploited, and the bandwidth and network card resources are fully utilized. Remote decryption server canChoose a lower load CPU machine as a machine resource reuse, or a specially optimized high-performance computing server. It is also one of the solutions used by CDN for large-scale HTTPS access.
The previous methods improve the HTTPS access performance from the method of reducing the transmission delay and the single machine load respectively, but the methods are based on the optimization method based on the HTTP protocol. SPDY/HTTP2 uses the advantages brought by TLS/SSL by modifying the protocol.Methods to improve the performance of HTTPS and improve the download speed.
The process of using Https
If you are a server developer who wants to use Https to protect your services and user data security, you can operate according to the following procedures:The second step should be the public key. The server will not send its private key to CA.