SSL protocol details

Source: Internet
Author: User
I recently read books related to cryptography and network security. This article mainly describes the famous SSL protocol.

Before getting started with SSl, I would like to introduce several cryptographic concepts and related knowledge.

1. Concepts related to cryptography

  • Cryptography: it aims to make information unreadable by encoding, so as to achieve security.
  • Plain text: messages that can be understood by the sender, receiver, and anyone accessing the message.
  • Ciphertext (cipher text): After a plaintext message is encoded, the ciphertext message is obtained.
  • Encryption: converts a plaintext message into a ciphertext message.
  • Decryption: converts a ciphertext message into a plaintext message.
  • Algorithm: extract an input text to generate an output text.
  • Encryption Algorithm: The algorithm that the sender encrypts.
  • Decryption algorithm: the algorithm that the receiver decrypts.
  • Key: only messages understood by the sender and receiver
  • Symmetric Key Encryption: the same Key is used for encryption and decryption.
  • Asypolicric Key Cryptography: different keys are used for encryption and decryption.

2. Introduction to related encryption algorithms

The DES algorithm is the Data Encryption Standard, also known as the Data Encryption Algorithm. The encryption process is as follows:

In SSL, data is encrypted using encryption algorithms such as grouping DES and Triple DES. Of course, you can use other non-DES encryption algorithms, depending on the situation, which will be detailed later.

3. Key exchange algorithm

Key Exchange is a big challenge when using symmetric encryption algorithms. Therefore, Diffie and Hellman proposed the famous Diffie-Hellman key exchange algorithm.

Principle of Diffie-Hellman key exchange algorithm:

(1) Alice and Bob determine two large prime numbers n and g, which do not need to be kept confidential (2) Alice chooses another large random number x and calculates A as follows: A = gx mod n (3) Alice sends A to Bob (4) Bob selects another large random number y and calculates B as follows: B = gy mod n (5) bob sends B to Alice (6) to calculate the secret key K1 as follows: K1 = Bx mod n (7) calculate the secret key K2 as follows: K2 = Ay mod nK1 = K2, so Alice and Bob can use it for encryption and decryption.

The RSA encryption algorithm is based on the mathematical fact that it is easy to multiply two large prime numbers, while it is difficult to evaluate the factor of the obtained product. The encryption process is as follows:

(1) select two large prime numbers P, Q (2) calculate N = P * Q (3) Select a public key (encryption key) E so that it is not (P-1) with (Q-1) factor (4) select private key (decryption key) D to meet the following conditions: (D * E) mod (P-1) (Q-1) = 1 (5) during encryption, the plaintext PT is calculated as follows: CT = PTE mod N (6) when decryption, the plaintext PT is calculated from the ciphertext CT as follows: PT = CTDmodN this is also a key exchange algorithm used in SSL.

3. Hash algorithm:

It is mainly used to verify data integrity, that is, to ensure that the message is not tampered with after sending and before receiving. MD5 and SHA-1 hash algorithms used in SSL are used.

4. Digital certificate:

A digital certificate is actually a small computer file. It acts like our ID card and passport to prove your identity. In SSL, digital certificates are used to prove your identity, rather than forged.

5. Summary:

In SSL, key exchange algorithms are used to exchange keys, encrypt data using keys, verify data integrity using hash algorithms, and use digital certificates to prove your identity. Now, we will introduce the SSL protocol.

SSL introduction:

Secure Socket Layer (SSL) is a Secure exchange of information between Web browsers and Web servers. It provides two basic security services: authentication and confidentiality.

SSL was developed by Netscape in 1994 and later became the world's most famous web security mechanism. All major browsers support the SSL protocol.

Currently, there are three versions: 2, 3, and 3.1. The most common version is 3rd, which was released in 1995.

Three features of the SSL protocol

① Confidentiality: After the session key is defined in the handshake protocol, all messages are encrypted.

② Authentication: optional client authentication and mandatory server authentication.

③ Integrity: The Sent message includes message integrity check (using MAC ).

SSL location

SSL is between the application layer and the TCP layer. The application layer data is not directly transmitted to the transport layer, but to the SSL layer. The SSL layer encrypts the data received from the application layer and adds its own SSL header.

How SSL works

Handshake protocol)

Record protocol)

Alert protocol)

1. Handshake Protocol

The handshake protocol is the first sub-protocol used by the client and the server to communicate over SSL connections. The handshake protocol includes a series of messages between the client and the server. The most complex protocol in SSL is the handshake protocol. This protocol allows servers and clients to verify each other and negotiate encryption and MAC algorithms and secret keys to protect data sent in SSL records. The handshake protocol is used before the data transmission of the application.

Each handshake protocol contains the following three fields:

(1) Type: indicates one of 10 message types.

(2) Length: The number of bytes in the message Length.

(3) Content: Message-related parameters

Four phases of the handshake protocol

1.1 establish security capabilities

In the first phase of the SSL Handshake, start the logical connection to establish the security capability of the connection. First, the client sends the client hello message to the server and waits for the server to respond. Then, the server returns the server hello message to the client to confirm the information in the client hello message.

Client hello messages include Version, Random, Session id, Cipher suite, and Compression method.

The ClientHello client sends the CilentHello information, which includes the following content:

(1) the maximum SSL version number supported by the client

(2) a 32-byte random number used to generate the master secret. (What is the main secret)

(3) a session ID that determines the session.

(4) list of cipher suites supported by a client.

Cipher suite format: each cipher suite starts with "SSL" and follows the key exchange algorithm. Use the word "With" to separate the key exchange algorithm, encryption algorithm, and hash algorithm. For example, SSL_DHE_RSA_WITH_DES_CBC_SHA indicates that DHE_RSA (temporary Diffie-HellMan With RSA digital signature) it is defined as a key exchange algorithm; DES_CBC is defined as an encryption algorithm; SHA is defined as a hash algorithm.

(5) a list of compression algorithms supported by a client.

The ServerHello server uses the ServerHello message to respond to the customer, including the following content:

(1) an SSL version number. Take the lowest version supported by the client and the lowest version supported by the server.

(2) a 32-byte random number used to generate the master secret. (One client and one server)

(3) session ID

(4) select a cipher suite from the list of client cipher suites

(5) the compression method selected from the client's compression method list

After this stage, the client server knows the following:

(1) SSL version

(2) key exchange, information verification and encryption algorithms

(3) compression method

(4) two random numbers generated by the CMK.

1.2 server authentication and key exchange

The server initiates the SSL Handshake phase 2nd, which is the only sender of all messages in this phase, and the client is the only receiver of all messages. This phase consists of four steps:

(A) Certificate: The server sends the digital certificate and the entire chain from the root CA to the client, so that the client can use the server public key in the server certificate to authenticate the server.

(B) server key exchange (optional): depends on the key exchange algorithm.

(C) certificate request: The server may require the customer to verify the request.

(D) Server handshake completed: the end of the second stage and the signal from the third stage

Here we will focus on server verification and key exchange. In this phase, the previous (a) certificate and (B) server key exchange are based on the key exchange method. In SSL, there are six key exchange algorithms: invalid (no key exchange), RSA, anonymous Diffie-Hellman, temporary Diffie-Hellman, fixed Diffie-Hellman, and Fortezza.

In Phase 1, the client negotiates with the server to determine which key exchange algorithm is used.

If the RSA Exchange key is determined during the negotiation process, the process is as follows:

In this method, the server sends the RSA encryption/decryption public key certificate in its first information. However, because the master/slave secret is generated and sent by the client in the next stage, the second information is empty. Note that the public key certificate will be verified from the server to the client. When the server receives the master preparation secret, it uses the private key for decryption. The private key of the server is evidence that the server is an entity required by the public key certificate for sending the first message.

Other key exchange algorithms are not described here. For more information, see Cryptography and Network Security by Behrouz A. Forouzan.

1.3 Client authentication and key exchange:

The client initiates the SSL Handshake phase 3rd, which is the only sender of all messages in this phase, and the server is the only receiver of all messages. This stage consists of three steps:

(A) certificate (optional): to prove itself to the server, the customer needs to send a certificate information. This is optional. In IIS, you can configure mandatory client certificate authentication.

(B) client key exchange (Pre-master-secret): The client sends the Pre-master key to the server. Note that the public key of the server is used for encryption.

(C) certificate verification (optional): Sign the prepared secret and random number to prove that the public key that owns the (a) certificate.

The following describes the RSA client authentication and key exchange.

In this case, no certificate information is provided unless the server explicitly requests in Phase II. Client key exchange methods include the backup master key encrypted by the RSA public key received by Phase II.

After stage III, the customer must have the server for verification, and both the customer and the server know the master key preparation.

1.4 Completed

The client starts the SSL Handshake 4th phase to end the server. This phase is divided into four steps. The first two messages come from the client, and the last two messages come from the server.

1.5 Key generation process

After the handshake is completed, let's take a look at what is the primary key and how it is generated. To ensure information integrity and confidentiality, SSL requires six encryption secrets: four keys and two IV. For the sake of information credibility, the client needs a key (HMAC). For the sake of encryption, a key is required, and for the sake of group encryption, an IV is required. This is also true for services. SSL requires one-way keys, different from those in other directions. If there is an attack in one direction, this attack will not be affected in other directions. The generation process is as follows:

2. Record Protocol

The record protocol is used after the client and the server shake hands successfully, that is, the client and the server identify the other party and determine the algorithm used for security information exchange, and then enter the SSL record protocol, the record Protocol provides two services to the SSL connection:

(1) confidentiality: secret keys defined by the handshake protocol are used for implementation.

(2) integrity: the handshake protocol defines MAC to ensure message integrity.

Record Protocol process:

3. Alarm protocols

When an error is detected on the client and server, an alert message is sent to the other party. If a fatal error occurs, the algorithm immediately closes the SSL connection, and both parties delete the session number, secret, and key. There are 2 bytes in each alert message, and 1st bytes indicate the error type. For an alert, the value is 1. For a fatal error, the value is 2; the actual error type is set to 2nd bytes.

Summary

In SSL, the handshake protocol is used to negotiate encryption and MAC algorithms and secret keys, and the handshake protocol is used to encrypt and sign the exchanged data. The alarm protocol is used to define the data transmission process, how to solve the problem.

The entire process is complicated. If you have any questions that you don't understand and I don't know, please let us know!

SSL protocol details

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.