SSL Introduction

SSL Introduction:

Secure Sockets (Secure Socket Layer, SSL) protocol is a protocol for secure exchange of information between the Web browser and the Web server, provides two basic security services: Authentication and Privacy.

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

There are currently three versions: 2,3,3.1, the most commonly used version 3, 1995 release.

Characteristics of three SSL protocol

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

② identification: optional client authentication, server-side authentication and enforcement.

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

SSL location

SSL is interposed between the application layer and the TCP layer. The application layer data is no longer directly transmitted to the transport layer, but is transmitted to the SSL layer, SSL layer data received from the application layer encryption, SSL and increase their head.

 

 

SSL works of

Handshake protocol (Handshake protocol)

Record Protocol (Record protocol)

Alert Protocol (Alert protocol)

1, the handshake protocol

Handshake protocol is the protocol used to connect the first sub SSL communication server and the client, including a series of message handshake protocol between a client and server. SSL is the most complex protocol handshake protocol. This protocol allows each server and client authentication, negotiate an encryption algorithm and a secret key, and MAC, is used to protect data transmitted in the SSL records. Handshake protocol is used prior to data transmission applications.

Each handshake protocol contains the following three fields
(1) Type: message type represents one of ten
(2) Length: the length of a message indicating the number of bytes
(3) Content: parameters associated with the message

 

 

4 phase handshake protocol

 

 

1.1 build security capacity

    SSL握手的第一阶段启动逻辑连接,建立这个连接的安全能力。首先客户机向服务器发出client hello消息并等待服务器响应,随后服务器向客户机返回server hello消息,对client hello消息中的信息进行确认。
    Client hello消息包括Version,Random,Session id,Cipher suite,Compression method等信息。

 

 

ClientHello 客户发送CilentHello信息,包含如下内容:

(1)客户端可以支持的SSL最高版本号

(2)一个用于生成主秘密的32字节的随机数。(等会介绍主秘密是什么)

(3)一个确定会话的会话ID。

(4)一个客户端可以支持的密码套件列表。

    密码套件格式:每个套件都以“SSL”开头,紧跟着的是密钥交换算法。用“With”这个词把密钥交换算法、加密算法、散列算法分开,例如:SSL_DHE_RSA_WITH_DES_CBC_SHA,表示把DHE_RSA(带有RSA数字签名的暂时Diffie-HellMan)定义为密钥交换算法;把DES_CBC定义为加密算法;把SHA定义为散列算法。

(5)一个客户端可以支持的压缩算法列表。

 ServerHello 服务器用ServerHello信息应答客户,包括下列内容

(1)一个SSL版本号。取客户端支持的最高版本号和服务端支持的最高版本号中的较低者。

(2)一个用于生成主秘密的32字节的随机数。(客户端一个、服务端一个)

(3)会话ID

(4)从客户端的密码套件列表中选择的一个密码套件

(5)从客户端的压缩方法的列表中选择的压缩方法

这个阶段之后,客户端服务端知道了下列内容:

(1)SSL版本

(2)密钥交换、信息验证和加密算法

(3)压缩方法

(4)有关密钥生成的两个随机数。

1.2 服务器鉴别与密钥交换

 服务器启动SSL握手第2阶段,是本阶段所有消息的唯一发送方,客户机是所有消息的唯一接收方。该阶段分为4步:
(a)证书:服务器将数字证书和到根CA整个链发给客户端,使客户端能用服务器证书中的服务器公钥认证服务器。
(b)服务器密钥交换(可选):这里视密钥交换算法而定
(c)证书请求:服务端可能会要求客户自身进行验证。
(d)服务器握手完成:第二阶段的结束,第三阶段开始的信号

 

 

这里重点介绍一下服务端的验证和密钥交换。这个阶段的前面的(a)证书 和(b)服务器密钥交换是基于密钥交换方法的。而在SSL中密钥交换算法有6种:无效(没有密钥交换)、RSA、匿名Diffie-Hellman、暂时Diffie-Hellman、固定Diffie-Hellman、Fortezza。

在阶段1过程客户端与服务端协商的过程中已经确定使哪种密钥交换算法。

如果协商过程中确定使用RSA交换密钥,那么过程如下图:

 

 

这个方法中,服务器在它的第一个信息中,发送了RSA加密/解密公钥证书。不过,因为预备主秘密是由客户端在下一个阶段生成并发送的,所以第二个信息是空的。注意,公钥证书会进行从服务器到客户端的验证。当服务器收到预备主秘密时,它使用私钥进行解密。服务端拥有私钥是一个证据,可以证明服务器是一个它在第一个信息发送的公钥证书中要求的实体。

其他的几种密钥交换算法这里就不介绍了。可以参考Behrouz A.Forouzan著的《密码学与网络安全》。

 1.3 客户机鉴别与密钥交换:

 

 

 

客户机启动SSL握手第3阶段,是本阶段所有消息的唯一发送方,服务器是所有消息的唯一接收方。该阶段分为3步:

(a)证书(可选):为了对服务器证明自身,客户要发送一个证书信息,这是可选的,在IIS中可以配置强制客户端证书认证。

(b)客户机密钥交换(Pre-master-secret):这里客户端将预备主密钥发送给服务端,注意这里会使用服务端的公钥进行加密。

(c)证书验证(可选),对预备秘密和随机数进行签名,证明拥有(a)证书的公钥。

下面也重点介绍一下RSA方式的客户端验证和密钥交换。

 

 

这种情况,除非服务器在阶段II明确请求,否则没有证书信息。客户端密钥交换方法包括阶段II收到的由RSA公钥加密的预备主密钥。

阶段III之后,客户要有服务器进行验证,客户和服务器都知道预备主密钥。

1.4 完成

 

 

客户机启动SSL握手第4阶段,使服务器结束。该阶段分为4步,前2个消息来自客户机,后2个消息来自服务器。

1.5密钥生成的过程

这样握手协议完成,下面看下什么是预备主密钥,主密钥是怎么生成的。为了保证信息的完整性和机密性,SSL需要有六个加密秘密:四个密钥和两个IV。为了信息的可信性,客户端需要一个密钥(HMAC),为了加密要有一个密钥,为了分组加密要一个IV,服务也是如此。SSL需要的密钥是单向的,不同于那些在其他方向的密钥。如果在一个方向上有攻击,这种攻击在其他方向是没影响的。生成过程如下:

 

 

 

 

 

 

 

 

 

 

2、记录协议

记录协议在客户机和服务器握手成功后使用,即客户机和服务器鉴别对方和确定安全信息交换使用的算法后,进入SSL记录协议,记录协议向SSL连接提供两个服务:

(1)保密性:使用握手协议定义的秘密密钥实现

(2)完整性:握手协议定义了MAC,用于保证消息完整性

记录协议的过程:

 

 

 3、警报协议

客户机和服务器发现错误时,向对方发送一个警报消息。如果是致命错误,则算法立即关闭SSL连接,双方还会先删除相关的会话号,秘密和密钥。每个警报消息共2个字节,第1个字节表示错误类型,如果是警报,则值为1,如果是致命错误,则值为2;第2个字节制定实际错误类型。

总结

SSL中,使用握手协议协商加密和MAC算法以及保密密钥 ,使用握手协议对交换的数据进行加密和签名,使用警报协议定义数据传输过程中,出现问题如何去解决。

 

 

Guess you like

Origin www.cnblogs.com/chuanzi/p/11041745.html