SSL握手期间浏览器如何生成对称密钥

发布于 2024-09-27 15:44:34 字数 317 浏览 3 评论 0原文

在典型的 https Web 场景中,我对浏览器和服务器之间的 SSL 握手有一个小困惑:

到目前为止,我所理解的是,在 SSL 握手过程中,客户端(在本例中为浏览器)使用公共加密随机选择的对称密钥密钥(从服务器收到的证书)。这被发送回服务器,服务器用私钥解密它(对称密钥)。现在,在会话的其余部分使用此对称密钥来加密/解密两端的消息。这样做的主要原因之一是使用对称密钥进行更快的加密。

问题

1)浏览器如何选择并生成这个“随机”选择的对称密钥?

2)开发人员(或/和浏览器用户)是否可以控制这种生成对称密钥的机制?

I have a small confusion on SSL handshake between browser and server in a typical https web scenario:

What I have understood so far is that in the process of SSL handshake, client (browser in this case) encrypts a randomly selected symmetric key with the public key (certificate received from server). This is sent back to the server, server decrypts it (symmetric key) with the private key. This symmetric key is now used during rest of the session to encrypt/decrypt the messages at both the ends. One of main reasons to do so is given as faster encryption using symmetric keys.

Questions

1) How does browser pick and generates this "randomly" selected symmetric key?

2) Do developers (or/and browser users) have control on this mechanism of generating symmetric keys?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一影成城 2024-10-04 15:44:34

这里很好地描述了 HTTPS 如何实现连接建立工作。我将总结双方(客户端和服务器)如​​何获取会话密钥,这个过程称为“密钥协商协议”,这里它是如何工作的:

  1. 客户端生成 48 字节的“预主密钥”随机值。
  2. 客户端用随机数据填充这些字节,使输入等于 128 字节。
  3. 客户端用服务器的公钥对其进行加密并发送给服务器。
  4. 然后双方通过以下方式生成主密钥:

    master_secret = PRF(
       预主秘密, 
       “大师秘密”, 
       ClientHello.random + ServerHello.random
    )
    

PRF 是“伪随机函数”,也在
规范并且非常聪明。它结合了秘密、ASCII 标签和
我们通过使用键控哈希消息提供的种子数据
MD5 和 SHA-1 哈希的身份验证代码 (HMAC) 版本
功能。一半的输入被发送到每个哈希函数。它是
聪明是因为它对攻击具有很强的抵抗力,即使面对
MD5 和 SHA-1 的弱点。这个过程可以自我反馈
永远迭代以生成我们需要的尽可能多的字节。

按照此过程,我们获得一个 48 字节的“主密钥”。

Here is a very good description of how HTTPS connection establishment works. I will provide summary how session key is acquired by both parties (client and server), this process is known as "a key agreement protocol", here how it works:

  1. The client generates the 48 byte “pre-master secret” random value.
  2. The client pads these bytes with random data to make the input equal to 128 bytes.
  3. The client encrypts it with server's public key and sends it to the server.
  4. Then master key is produced by both parties in following manner:

    master_secret = PRF(
       pre_master_secret, 
       "master secret", 
       ClientHello.random + ServerHello.random
    )
    

The PRF is the “Pseudo-Random Function” that’s also defined in the
spec and is quite clever. It combines the secret, the ASCII label, and
the seed data we give it by using the keyed-Hash Message
Authentication Code (HMAC) versions of both MD5 and SHA-1 hash
functions. Half of the input is sent to each hash function. It’s
clever because it is quite resistant to attack, even in the face of
weaknesses in MD5 and SHA-1. This process can feedback on itself and
iterate forever to generate as many bytes as we need.

Following this procedure, we obtain a 48 byte “master secret”.

卸妝后依然美 2024-10-04 15:44:34

引用网络视频上这段精彩的视频,分钟 1:18:07

那么你在计算机上从哪里获得随机性,因为你的
计算机是确定性设备吗?

它会收集熵,比如你的鼠标笔划动作、你的按键
它尝试收集笔划动作和硬盘的计时
将宇宙中的所有随机性转化为拉力,以便它可以仅为一个连接[此会话]生成随机密钥。如果这种随机性被打破并且发生了很多次
在过去的30年里,这一切都不起作用。如果对手能够
弄清楚你的随机性是什么,然后他们就可以猜出你的密钥。因此,请使用良好的随机性。

注意:密钥是每个会话创建的。

Quoting from a this great video on network video, minute 1:18:07

Well where do you get randomness on your computer because your
computer is a deterministic device?

Well it collects entropies like your mouse stroke movements, your key
stroke movements and the timing of your hard disk, it tries to collect
all that randomness from the universe into a pull so that it can generate random keys just for one connection [this session]. And if that randomness is broken and its happened many times
in the last 30 years, then none of this works. If the adversary can
figure what your randomness can be then they can guess your keys. So use good randomness.

Note: the keys are created per session.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文