现在的位置: 首页 > 综合 > 正文

TLS协议简介

2018年02月21日 ⁄ 综合 ⁄ 共 2188字 ⁄ 字号 评论关闭

这里提供一个对TLS协议简单的描述,旨在对TLS协议有一个大概的理解和概念,详细内容参考文档RFC2246
TLS协议是对SSL协议规范后协议版本,建立在可靠的传输层之上,如TCP(UDP则不行)。应用层可以透明的利用TLS协议传输各种数据,来保证数据的安全性和保密性。它包括两层:
1.TLS Record Protocol
2.handshake protocol, alert protocol, change cipher spec protocol, application data protocol.

1.TLS Record Protocol
1.1 封装了上层的四个协议。另外可以在TLS Record Protocol上定义支持其他的类型,进行扩展。TLS记录协议包括几个头域:
1.Content Type,标示封装的协议类型,(如handshake protocol)
2.Version,TLS的版本。(一般现在时1.0)
3.Length,负载的长度。
4.content,负载内容。
在一个TCP包中,可能同时包含了多个TLS Record Protocol域。

1.2 四种connection state,即current read and write states, and pending read and write states。
1.2.1 所有的record数据都是通过current read and write states处理的。
1.2.2 pending read and write states的安全参数通过TLS Handshake Protocol设定。TLS Handshake Protocol可以决定放弃current read and write states,将
pending read and write states转为current read and write states。但是不能将还没有设置安全参数的pending read and write states设为current read and write
states。
安全参数如下结构体所示:
struct {
            ConnectionEnd          entity;
         BulkCipherAlgorithm    bulk_cipher_algorithm;
           CipherType             cipher_type;
         uint8                  key_size;
           uint8                  key_material_length;
         IsExportable           is_exportable;
         MACAlgorithm           mac_algorithm;
         uint8                  hash_size;
         CompressionMethod      compression_algorithm;
         opaque                 master_secret[48];
         opaque                 client_random[32];
         opaque                 server_random[32];
       } SecurityParameters;

2. handshake protocol
握手协议用来为TLS记录层提供安全参数,通过双方协商验证证书,交换密钥,确定加密算法等。
握手协议的全过程如下:
      Client                                               Server

      ClientHello                  -------->
                                                      ServerHello
                                                     Certificate*
                                               ServerKeyExchange*
                                              CertificateRequest*
                                   <--------      ServerHelloDone
      Certificate*
      ClientKeyExchange
      CertificateVerify*
      [ChangeCipherSpec]
      Finished                     -------->
                                               [ChangeCipherSpec]
                                   <--------             Finished
      Application Data             <------->     Application Data

概况总结:
1.首先通过非对称密钥算法产生交换对称密钥算法的主密钥。
2.然后利用这对主密钥,用对称加密算法对通信数据进行加密传输。
3.假设暴雪为server,小明为client,他们都有一对自己的私钥和公钥。握手的过程中,暴雪和小明都把自己的公钥发送给对方;另外,暴雪和小明都各自产生一个随机数,也相互发送给对方。之后,小明通过一系列步骤,计算产生主密钥,并用暴雪的公钥对主密钥进行加密,发送给暴雪;暴雪收到消息后,用他自己的私钥对消息进行解密,就获得了主密钥。
4.暴雪和小明相互发送一个握手结束消息,确认可以正确的使用刚刚协商的主密钥进行加密通信。然后就可以进行安全的加密通信了。

抱歉!评论已关闭.