SSL protocol Detailed

Source: Internet
Author: User
Tags ssl connection cipher suite

http://kb.cnblogs.com/page/162080/

 Background introduction

Recently in the "Cryptography and Cyber Security" related books, this article is mainly about the famous Network security protocol SSL.

Before beginning the introduction of SSL, we will introduce a few cryptography concepts and related knowledge.

1. Cryptography Related Concepts

    • Cryptography (Cryptography): The goal is to achieve security by encoding the information so that it is unreadable.
    • PlainText (plain text): A message that the sender, the recipient, and anyone who accesses the message can understand.
    • Ciphertext (cipher text): PlainText message after some encoding, get ciphertext message.
    • Encryption (encryption): Converts plaintext messages into ciphertext messages.
    • Decrypt (decryption): Turns a ciphertext message into a plaintext message.
    • Algorithm: Takes an input text, produces an output text.
    • Encryption algorithm: The sender encrypts the algorithm.
    • Decryption algorithm: The receiver decrypts the algorithm.
    • Key (Key): Only messages understood by the sender and the receiving party
    • Symmetric key encryption (symmetric key Cryptography): Encryption and decryption use the same key.
    • Asymmetric key encryption (asymmetric key cryptography): Encryption and decryption use different keys.

2, the related encryption algorithm introduction

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

Encryption algorithms such as Packet des and Sanchong des algorithms are used to encrypt data in SSL. Of course, you can choose other non-DES encryption algorithm, depending on the situation, will be described in detail later.

3. Key exchange algorithm

When using symmetric encryption algorithm, key exchange is a big problem, so Diffie and Hellman put forward the famous Diffie-hellman key exchange algorithm.

Diffie-hellman key exchange Algorithm principle:

The RSA encryption algorithm is based on the mathematical fact that two large primes are easy to multiply, while it is difficult to obtain a factor for the resulting product. The encryption process is as follows:

(1) Select two large prime number P, Q (2) Calculation n=p*q (3) Select a public key (encryption key) E, so that it is not (P-1) and (Q-1) factor (4) Select the private key (decryption key) D, meet the following conditions:          (d*e) mod (P-1) (Q-1) =1 (5) When encrypting, the plaintext PT calculates the ciphertext CT as follows:          ct=pte mod N (6) When decrypting, the plaintext computed from the ciphertext CT is as follows:          

3, hashing algorithm:

It is mainly used to verify the integrity of the data, that is, the guaranteed message is not tampered with after it is sent and before it is received MD5, SHA-1 for the hashing algorithm used in SSL.

4. Digital Certificate:

A digital certificate is actually a small computer file that acts like our identity card, passport, identity, and, in SSL, using a digital certificate to prove our identity, not a forgery.

5, a simple summary:

In SSL, the key exchange algorithm is used to exchange keys, the data is encrypted with a key, the integrity of the data is verified using a hashing algorithm, and a digital certificate is used to prove its identity. OK, let's start with the SSL protocol.

SSL Introduction:

The Secure Socket LAYER,SSL protocol is the protocol for securely exchanging information between a Web browser and a Web server, providing two basic security services: Authentication and confidentiality.

SSL was developed by Netscape in 1994 and later became the most famous web security mechanism in the world, with all major browsers supporting the SSL protocol.

There are currently three versions: 2, 3, 3.1, the most commonly used is the 3rd edition, 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.

② Identification: Optional client authentication, and mandatory server-side authentication.

③ Integrity: Messages that are delivered include message integrity checks (using MAC).

Location of SSL

SSL is between the application layer and the TCP layer. The application layer data is no longer passed directly to the transport layer, but is passed to the SSL layer, which encrypts the data received from the application layer and adds its own SSL header.

How SSL Works

Handshake Protocol (Handshake Protocol)

Recording Protocol (record Protocol)

Alarm Protocol (Alert Protocol)

1. Handshake protocol

The handshake protocol is the first sub-protocol used by both the client and the server to communicate with SSL connections, which includes a series of messages between the client and the server. The most complex protocol in SSL is the handshake protocol. This protocol allows the server and client to authenticate each other, negotiate encryption and Mac algorithms, and a secret key to protect the data sent in the SSL record. The handshake protocol is used before the application's data transfer.

Each handshake protocol consists of the following 3 fields

(1) Type: represents one of 10 message types

(2) Length: Indicates the length of the message bytes

(3) Content: message-related parameters

4 Stages of a handshake protocol

1.1 Building security capabilities

The first phase of the SSL handshake initiates a logical connection that establishes the security capability of the connection. First the client sends a client Hello message to the server and waits for the server to respond, then the server returns the server Hello message to the client and confirms the information in the client Hello message.

The Client hello message includes information such as Version,random,session Id,cipher Suite,compression method.

ClientHello the customer to send Cilenthello information, including the following content:

(1) The maximum number of SSL versions a client can support

(2) A random number of 32 bytes used to generate the master secret. (What is the main secret?)

(3) A session ID that determines the session.

(4) A list of cipher suites that a client can support.

Cipher Suite format: Each suite starts with "SSL", followed by a key exchange algorithm. Use the word "with" to separate the key exchange algorithm, encryption algorithm, hashing algorithm, for example: Ssl_dhe_rsa_with_des_cbc_sha, the Dhe_rsa (with the RSA digital signature of the temporary Diffie-hellman) defined as the key exchange algorithm ; DES_CBC is defined as a cryptographic algorithm, and SHA is defined as a hashing algorithm.

(5) A list of compression algorithms that a client can support.

Serverhello Server uses Serverhello information to answer customers, including the following content

(1) An SSL version number. The highest version number supported by the client and the lower of the highest version number supported by the server.

(2) A random number of 32 bytes used to generate the master secret. (Client one, server-side one)

(3) Session ID

(4) A cipher suite selected from the client's cipher suite list

(5) Compression method selected from the list of compression methods of the client

After this phase, the client server knows the following:

(1) SSL version

(2) Key exchange, information verification and encryption algorithm

(3) Compression method

(4) About two random numbers generated by the key.

1.2 Server authentication and key exchange

The server initiates the SSL handshake phase 2nd, which is the only sender of all messages at this stage, and the client is the only recipient of all messages. This phase is divided into 4 steps:

(a) Certificate: The server sends the digital certificate and the entire chain to the root CA to the client, enabling the client to authenticate the server with the server's public key in the server certificate.

(b) Server key exchange (optional): This depends on the key exchange algorithm

(c) Certificate request: The server may require the customer to authenticate itself.

(d) Server handshake completion: End of second phase, signal starting at phase three

Here we focus on the authentication and key exchange of the server. The preceding (a) certificate and (b) Server key exchange in this phase are based on the key exchange method. There are 6 types of key exchange algorithms in SSL: Invalid (no key exchange), RSA, anonymous Diffie-hellman, temporary diffie-hellman, fixed Diffie-hellman, Fortezza.

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

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

In this method, the server sends the RSA encryption/decryption public key certificate in its first message. However, because the master secret is generated and sent by the client at the next stage, the second message is empty. Note that the public key certificate is validated from the server to the client. When the server receives a prestaged master secret, it uses the private key to decrypt it. Having a private key on the server side is an evidence that it is a required entity in the public key certificate it sends in the first message.

Several other key exchange algorithms are not introduced here. You can refer to Behrouz A.forouzan, "Cryptography and Cyber security".

1.3 Client Authentication and key exchange:

The client initiates the SSL handshake phase 3rd, which is the only sender of all messages at this stage, and the server is the only recipient of all messages. This phase is divided into 3 steps:

(a) certificate (optional): In order to prove itself to the server, the customer sends a certificate information, which is optional and can be configured in IIS to enforce client certificate authentication.

(b) Client key exchange (Pre-master-secret): Here the client sends the master key to the server, noting that it is encrypted using the server's public key.

(c) certificate validation (optional), signing of the pre-secret and random number to prove that the public key of the certificate has (a).

The following also focuses on the RSA method of client authentication and key exchange.

In this case, there is no certificate information unless the server explicitly requests it in phase II. The client key exchange method includes the preliminary master key that is received by the RSA public key in Phase II.

After Phase III, the customer has to have the server to authenticate, and the client and the server are aware of the prestaged master key.

  1.4 Complete

The client initiates the 4th phase of the SSL handshake and ends the server. The stage is divided into 4 steps, the first 2 messages from the client, and the last 2 messages from the server.

1.5 Key generation Process

So the handshake protocol is complete, and below is what the master key is, and how it is generated. To ensure the integrity and confidentiality of information, SSL requires six encryption secrets: Four keys and two IV. For the credibility of the information, the client needs a key (HMAC), in order to encrypt to have a key, in order to block encryption to a IV, the service is the same. SSL requires a one-way key that differs from those in other directions. If there is an attack in one direction, this attack is not affected in the other direction. The build process is as follows:

2. Record Agreement

The logging protocol is used after the client and server handshake are successful, that is, after the client and server authenticate each other and determine the algorithm used for secure information exchange, enter the SSL logging protocol, which provides two services to the SSL connection:

(1) Confidentiality: implementation of secret keys defined using handshake protocol

(2) Integrity: Handshake protocol defines MAC for guaranteed message integrity

The process of documenting the protocol:

3. Alarm protocol

When the client and server find an error, an alert message is sent to the other party. If it is a fatal error, the algorithm immediately shuts down the SSL connection, and the parties will first delete the associated session number, secret, and key. Each alert message has a total of 2 bytes, the 1th byte represents the error type, and if it is an alert, the value is 1, if it is a fatal error, the value is 2, and the 2nd byte is the actual error type.

Summarize

In SSL, the handshake protocol is used to negotiate encryption and Mac algorithms as well as secret keys, to encrypt and sign exchanged data using the handshake protocol, and to define how problems are resolved during data transfer using the alert protocol.

The whole process is more complicated, if everyone has not understand and I do not describe the place, you are welcome to correct it!

SSL protocol Detailed

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.