目的

为能够透彻理解HTTPS报文交互过程,做此笔记。

本文大部分内容来自 : http://albertx.mx/blog/https-handshake/

http://www.cnblogs.com/svan/p/5090201.html

TLS Handshake Protocol

The TLS Handshake its like a sub-protocol of the TLS protocol. Its purpose is to define the algorithms and keys to authenticate the parties, verify and encrypt the data.

一次完整的http交互如下:

client hello -- 客户端向服务器打招呼 (带着 支持的 ciper suites)

server hello -- 服务器响应客户端 (告诉客户端, 我选择了哪一个 ciper suite)

Certificate Server hello done -- 服务器向客户端送证书(表明自己的身份)

Client Key Exchange, change ciper spec, encrypted handshake message -- 客户端发送密钥,  告诉服务器开始传送密文数据了, 传送一个加密的握手数据

New Session Ticket, change ciper spec, encrypted handshake message -- 服务器建立会话凭据, 告诉客户端开始传送密文数据了,传送一个加密的握手数据。

流程如下:

http://security.stackexchange.com/questions/20803/how-does-ssl-tls-work/20847#20847

  Client                                               Server

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

Client Hello

  • The version of SSL that the client is trying to use for negotiating with the server
  • Some random bytes generated by the client that will be used next to generate a master key for encryption.
  • A list of encryption algorithms called cipher_suites. The client tells the server which cipher suites it understands.

主要传送 客户端支持的 加密算法列表:

Cipher Suites

包括四个部分:

TLS_DHE_RSA_WITH_AES_256_CBC_SHA

DHE -- 密码交换加密算法

RSA -- 认证算法

AES_256_CBC -- 数据交换加密算法

SHA -- 数据完整性算法

Now, let me talk about the cipher suites listed above. If you review the image posted in the client hello section you will see a list. This list indicates the algorithms that will be used during the handshake and data transmission. The protocol needs 4 algorithms to work:

  • Authentication algorithm
  • Key Exchange algorithm
  • Bulk cipher algorithm
  • Message Authentication algorithm

These 4 algorithms are specified in the cipher suite.
Analyzing the first suite in the list we have the text: TLS_DHE_RSA_WITH_AES_256_CBC_SHA.

    • TLS: This is Transport Layer Security, the protocol we are using in the negotiation
    • DHE: Denotes Ephemeral Diffie-Hellman. Diffie-Hellman is an
      algorithm for key exchanging cryptographic keys. Diffie-Hellman in
      ephemeral mode enhances its security
    • RSA: This is the algorithm used for authentication. The most used algorithm in public-key cryptography (Rivest, Shamir and Adleman)
    • WITH_AES_256_CBC: Advanced Encryption Standard is one of
      the best algorithms used in symmetric cryptography. Its key size can be
      of 128 bits, 192 bits or 256 bits. In this case the key size is 256
      bits. CBC stands for Cipher-block Chaining one mode of
      operation in encryption. It means that the algorithm will encrypt the
      bytes of data by blocks and then it will link the encrypted blocks like a
      chain.
    • SHA: Secure Hash Algorithm will be used for message authentication creating a hash of each block of the message to verify the integrity of such message.

Server Hello

  • Some random bytes now generated by the server that will be used to generate a master key.
  • The cipher suite selected by the server (from the previous list sent by the client) that will be used for authentication, encryption and verification of the messages

告诉客户端,我选择的算法。

Certificate

The Certificate command is usually sent again from server to client. In this command the information transmitted is the list of certificates that the client needs to have in order to authenticate the server and to encrypt some information. This can be one, two or more certificates.

证书用于认证服务器端的身份,防止被钓鱼等攻击。 其中也包括 服务器端的 公钥, 用于加密数据。

证书 可以是多个, 呈现链式法则。

Server Hello Done

Immediately after the Certificate message the server sends the Server Hello Done message. At this point the client has all the information it needs to generate the key material that both parties will need to encrypt the data. This key material is sent in the next handshake message…

服务器端,告诉客户端, 你已经具备产生密钥的条件, 快生成吧。

Client Key Exchange

The client generates some bytes of data, encrypt them with the public key of the certificate it received and then sends the encrypted data to the server (this is called PreMaster secret and will be used to generate the Master secret). The algorithm by which the client protects the data is defined during the Client Hello and Server Hello messages. It can be RSA or Diffie-Hellman.

客户端生成  一串随机的byte(PreMaster secret), 使用公钥加密后,传给服务器。 加密的算法hello过程已经确定。

关于master secret 生成, 见如下文章介绍(在第五点告诉你 master secret产生):

http://www.cnblogs.com/svan/p/5090201.html

使用RSA算法的SSL握手过程是这样的

Source: Keyless SSL: The Nitty Gritty Technical Details

  1. [明文] 客户端发送随机数client_random和支持的加密方式列表
  2. [明文] 服务器返回随机数server_random,选择的加密方式和服务器证书链
  3. [RSA] 客户端验证服务器证书,使用证书中的公钥加密premaster secret发送给服务端
  4. 服务端使用私钥解密premaster secret
  5. 两端分别通过client_randomserver_randompremaster secret生成master secret,用于对称加密后续通信内容

master secret是如何计算的

 
  master_secret = PRF(pre_master_secret, "master secret",
ClientHello.random + ServerHello.random)
[0..47];

Change Cipher Spec

This is also sent from client to server indicating that the server MUST be prepared to receive the data in encrypted format and not in readable format because all the previous messages exchanged between client and server had been readable. This is the last message sent from client to server as readable. After this all the data sent to the server will be encrypted and we will not be able to read the contents with wireshark or any other sniffer tool. Proof of this is that in the below image the message after the Change Cipher Spec is an Encrypted Handshake Message.

客户端告诉服务器, 下一个报文开始传送 密文 了噢。

Finished

This is the first message protected by the algorithms and keys negotiated between the entities (this is the Encrypted Handshake Messsage we saw in the image). Both client and server send the Finished message but the first to do it is the client. If the server receives the message and could decrypt and understand it, it means the the server is reading the encrypted information in the right way. Now the only missing part is that client could decrypt the information sent by the server. To do that the server must send a Change Cipher Spec message too followed by the Finished message in the encrypted way. Exactly the same as client did. Again if the client could decrypt the Finished message it means that both parties are in frequency and they can talk to each other protecting all the data in transit.

客户端先想服务器端, 发送一个加密的报文, 如果服务器能够解密,并理解无误(客户端加密的内容, 是之前明文报文的一个摘要, 服务器端解密后, 计算其受到报文的摘要,并跟解密的摘要比较, 如果相等,则服务器接受客户端数据通道无误。)

然后服务器端,也一致, 需要按照客户端的做法, 先发送一个 change ciper spec消息, 告诉客户端要发送 密文了准备接受哦,

然后发送一个验证性通道畅通的加密报文, 客户端解密OK, 并可以理解(同上), 则两端握手成功。

开始传送应用数据。

HTTPS and the TLS handshake protocol阅读笔记的更多相关文章

  1. Formal Analysis of the TLS Handshake Protocol -----论文整理

    1.关键词  TLS.SSL.Formal Analsysis  Conridentiality  Secerecy 2.Table  THE SSL/TLS handshake Protocol 3 ...

  2. normalization 阅读笔记

    https://zhuanlan.zhihu.com/p/33173246 阅读笔记 1. normalization whiting - PCA 2. Internal Covariate Shif ...

  3. 解决docker pull出现 error pulling image configuration: Get https://dseasb33srnrn.cloudfront.net······: net/http: TLS handshake timeout的问题

    [root@MyCentos7 var]# docker pull javaUsing default tag: latestTrying to pull repository docker.io/l ...

  4. 解决 docker.io 上拉取 images Get https://registry-1.docker.io/v2/: net/http: TLS handshake timeout

    处理方式 使用如下命令获取 registry-1.docker.io 可用的 ip dig @114.114.114.114 registry-1.docker.io 看到如下输出结果 ; <& ...

  5. Hadoop阅读笔记(七)——代理模式

    关于Hadoop已经小记了六篇,<Hadoop实战>也已经翻完7章.仔细想想,这么好的一个框架,不能只是流于应用层面,跑跑数据排序.单表链接等,想得其精髓,还需深入内部. 按照<Ha ...

  6. CI框架源码阅读笔记3 全局函数Common.php

    从本篇开始,将深入CI框架的内部,一步步去探索这个框架的实现.结构和设计. Common.php文件定义了一系列的全局函数(一般来说,全局函数具有最高的加载优先权,因此大多数的框架中BootStrap ...

  7. Mongodb Manual阅读笔记:CH4 管理

    4 管理 Mongodb Manual阅读笔记:CH2 Mongodb CRUD 操作Mongodb Manual阅读笔记:CH3 数据模型(Data Models)Mongodb Manual阅读笔 ...

  8. “CoreCLR is now Open Source”阅读笔记

    英文原文:CoreCLR is now Open Source 阅读笔记如下: CoreCLR是.NET Core的执行引擎,功能包括GC(Garbage Collection), JIT(将CIL代 ...

  9. QCon 2015 阅读笔记 - 移动开发最佳实践

    所有ppt下载地址:http://pan.baidu.com/s/1mg9o4TM 下面是移动开发实践部分的阅读笔记. 移动开发网络性能优化实践 - 陈浩然 (携程) 携程是非常标准的移动App架构, ...

随机推荐

  1. Ubuntu 14.04 安装 VirtualBox

    参考: ubuntu14.04,安装VirtualBox 5.0(虚拟机软件)! 由于Vagrant工具的需要,安装了一下VirtualBox. 使用参考链接的法一居然在软件中心里面报错,我想可能是没 ...

  2. Nginx 笔记与总结(14)expires 缓存设置

    设置缓存,可以提高网站性能. 当网站的部分内容,比如新闻站的图片,一旦发布就不太可能发生更改,此时需要用户在访问一次页面之后,把该页面的图片缓存在用户的浏览器端一段时间,就可以用到 nginx 的 e ...

  3. http304状态码缓存设置问题

    当浏览器第一次加载资源的时候,返回一般为200,意思是成功获取资源,并会在浏览器的缓存中记录下max-age,第二次访问的时候:如果只是用浏览器打开,那么浏览器会去判断这个资源在缓存里有没有,如果有的 ...

  4. charles 常用设置

    一.过滤网络请求 通常情况下,我们需要对网络请求进行过滤,只监控向指定目录服务器上发送的请求.对于这种需求,我们有2种办法. 1.在主界面的中部的Filter栏中填入需要过滤出来的关键字.例如我们的服 ...

  5. IOS开发之开篇--CocoaPods安装

    CocoaPods是什么?当你开发iOS应用时,会经常使用到很多第三方开源类库,比如JSONKit,AFNetWorking等等.可能某个类库又用到其他类库,所以要使用它,必须得另外下载其他类库,而其 ...

  6. linux下mysql定时备份数据库

    linux下mysql定时备份数据库 (2010-10-21 12:40:17) 转载▼ 标签: 杂谈   一.用命令实现备份 首页进入mysql的bin目录 1.备份数据#mysqldump -uu ...

  7. Unity 为NGUI增加体感输入方式

    背景 NGUI在处理UI和输入方面确实做的不错,但是现在的问题是公司引入体感之后,是通过手的位置来实现按钮的点击操作,前提我不想改变原先设计好的NGUI界面和机制,怎么破? NGUI的输入底层机制 N ...

  8. Oracle 语句常见错误

    Merge into的注意点之ORA-30926:无法在源表中获得一组稳定的行? merge into 的内部处理是将table_source 的每一条记录和table_target的每一条记录对比匹 ...

  9. ubuntu lnmp

    apt-get update apt-get upgrade apt-get install libxml2 libxml2-dev apt-get install make apt-get inst ...

  10. laravel md5+salt 密码

    laravel 默认用的登录密码加密方式是: $password = Hash::make('password'); 修改密码加密方式为: $password = md5('password'.'sa ...