简体   繁体   English

HTTPS 是如何工作的,它是否使用 cookie?

[英]How does HTTPS work, and does it use cookies?

I have a basic understanding that HTTPS creates a secure connection between a user and a server using some sort of unique identifying code.我有一个基本的理解,即 HTTPS 使用某种唯一的识别代码在用户和服务器之间创建安全连接。 However, if the server sends this code (or whatever it is) to the user, can't that code be intercepted and that renders the entire HTTPS just as vulnerable as HTTP?但是,如果服务器将此代码(或其他任何代码)发送给用户,难道该代码不能被拦截,从而使整个 HTTPS 与 HTTP 一样容易受到攻击吗?

I'm a total newbie to this area, and am interested in how it works.我是这个领域的新手,对它的工作原理很感兴趣。 The current answers on Stack Overflow don't give me the full answer. Stack Overflow 上的当前答案并没有给我完整的答案。

I'm not sure it's fair to say there isn't any answer on Stack Overflow to the question of how SSL works: https://stackoverflow.com/search?q=how+does+ssl+work我不确定在 Stack Overflow 上对 SSL 如何工作的问题没有任何答案是否公平: https : //stackoverflow.com/search?q= how+does+ssl+ work

Cookies work the same way over HTTPS that they do over HTTP. Cookie 在 HTTPS 上的工作方式与在 HTTP 上的工作方式相同。 HTTPS is just HTTP, but with the server and client using a "shared secret" symmetric encryption key to encrypt and decrypt the data they exchange so that a third party can't intercept and read the communication. HTTPS 只是 HTTP,但服务器和客户端使用“共享秘密”对称加密密钥来加密和解密它们交换的数据,因此第三方无法拦截和读取通信。

So having said that, and largely agreeing with the advice to start reading at Wikipedia , why don't I take a quick stab at doing this a modest disservice by explaining it as briefly as I know how.话虽如此,并且在很大程度上同意在Wikipedia上开始阅读的建议,为什么我不通过尽可能简短地解释它来快速尝试一下这样做是一种适度的伤害。

First, "SSL" is now officially obsolete since the POODLE exploit in SSLv3 will never be fixed.首先,“SSL”现在正式过时,因为 SSLv3 中的POODLE漏洞永远不会被修复。 SSL (Secure Sockets Layer) has been succeeded by TLS (Transport Layer Security) and has really become a generic although somewhat inaccurate term referring to secure HTTP (HTTPS). SSL(安全套接字层)已被 TLS(传输层安全性)取代,并真正成为一个通用的术语,尽管有些不准确,指的是安全 HTTP (HTTPS)。

Still, SSL and TLS both use the same underlying technologies and general ideas.尽管如此,SSL 和 TLS 都使用相同的底层技术和一般思想。

There are several technologies involved, all of them complicated, and the interplay between them is complicated.涉及的技术很多,都很复杂,而且它们之间的相互作用也很复杂。

But here are the high points, jammed into a little nutshell.但这里是高点,简而言之。

SSL/TLS fundamentally relies on public/private key asymmetric encryption , in order to securely exchange a shared secret--an ephemeral (disposable, short-lived) symmetric encryption key known only to the server and the client, which the client and server then use to encrypt the messages they exchange from that point forward. SSL/TLS 从根本上依赖于公钥/私钥非对称加密,以便安全地交换共享秘密——一个只有服务器和客户端知道的临时(一次性的、短期的)对称加密密钥,客户端和服务器然后用于加密他们从那时起交换的消息。

Asymmetric encryption is a big, quite sciencey topic all by itself.非对称加密本身就是一个很大的、非常科学的话题。

a·sym·me·try一个·符号·我·尝试

āˈsimətrē/ āˈsimətrē/

noun : lack of equality or equivalence between parts or aspects of something;名词:事物的部分或方面之间缺乏平等或等同; lack of symmetry.缺乏对称性。

Assymetric encryption utilizes paired private and public keys which are derived mathematically from very large, mathematically related prime numbers.非对称加密使用成对的私钥和公钥,这些密钥是从非常大的、数学上相关的素数以数学方式推导出来的。

The encryption is asymmetric because if a message is encrypted with the "private" key, it can only be decrypted by the "public" key, and vice-versa.加密是非对称的,因为如果使用“私有”密钥加密消息,则只能通过“公共”密钥解密,反之亦然。

It is therefore absolutely critical to keep the private key private.因此,将私钥保密是绝对重要的。 The public key can be (indeed is ) published to the world公钥可以(确实)公开给全世界

TLS uses asymmetric encryption and a handshake protocol to create and exchange a symmetric session encryption key that is known only to the server and the client. TLS 使用非对称加密和握手协议来创建和交换只有服务器和客户端知道的对称会话加密密钥。

Asymmetric encryption is an order of magnitude slower than symmetric encryption, making it unsuitable for encrypting data for real-time communication.非对称加密比对称加密慢一个数量级,因此不适合用于实时通信的数据加密。 The other thing making it unsuitable for encrypting data for two-way communication is that anything encrypted with the server's private key can be decrypted by anybody who has possession of the public key.使其不适合用于双向通信加密数据的另一件事是,任何使用服务器私钥加密的内容都可以被拥有公钥的任何人解密。 By definition, that's everybody .根据定义,这就是每个人

So, committing an atrocious act of willful oversimplification;因此,犯下故意过度简化的残暴行为; the handshake protocol basically allows the client to send an encrypted challenge that only the server can decrypt, the server can then sign that challenge with its private key and return it.握手协议基本上允许客户端发送一个只有服务器才能解密的加密质询,然后服务器可以用它的私钥对该质询进行签名并返回它。 The client knows both which challenge it sent, and how to verify the server's signature using the server's public key.客户端知道它发送了哪个挑战,以及如何使用服务器的公钥验证服务器的签名。 Once the client and the server are satisfied that their communication has not been tampered with, they can securely exchange an ephemeral symmetric encryption key.一旦客户端和服务器确信他们的通信没有被篡改,他们就可以安全地交换临时对称加密密钥。 Some steps may be combined to reduce the number of round trips, and different versions of the protocol, you know, differ somewhat in the details... (willfully oversimplified, remember).可能会组合一些步骤以减少往返次数,并且协议的不同版本,您知道,在细节上有所不同......(故意过度简化,记住)。

There are a number of encryption protocols and key lengths that can be used, and these specifics are negotiated during the key exchange.可以使用多种加密协议和密钥长度,这些细节是在密钥交换期间协商的。 Let's just say the client and server agree to AES encryption with a 256 bit key.假设客户端和服务器同意使用 256 位密钥进行 AES 加密。

So, once the client and server have securely exchanged that 256 bit key (the size of which they negotiated), they can encrypt and exchange data securely at will using that key with the AES algorithm that they also negotiated.因此,一旦客户端和服务器安全地交换了 256 位密钥(他们协商的大小),他们就可以使用该密钥和他们协商的 AES 算法安全地加密和交换数据。 No other party has that ephemeral encryption key, thus no other party can decrypt the data they exchange.没有其他方拥有该临时加密密钥,因此没有其他方可以解密他们交换的数据。

Symmetric encryption is much, much faster than asymmetric encryption.对称加密比非对称加密快得多。 As such, the performance impact of encrypting/decrypting large data transfers is virtually irrelevant.因此,加密/解密大数据传输对性能的影响几乎无关紧要。

The expensive part of HTTPS is in the initial protocol handshake and key exchange since it requires multiple round trips and a couple of rounds of super expensive asymmetric encryption. HTTPS 的昂贵部分在于初始协议握手和密钥交换,因为它需要多次往返和几轮非常昂贵的非对称加密。 Because of this, HTTPS communication benefits enormously when the client and server reuse the same connection for multiple requests.因此,当客户端和服务器为多个请求重用相同的连接时,HTTPS 通信会受益匪浅。 For information on that, look into the SPDY protocol.有关这方面的信息,请查看SPDY协议。

Finally, you should research forward secrecy and/or perfect forward secrecy .最后,您应该研究前向保密和/或完美前向保密 What forward secrecy does is to exchange an ephemeral public/private keypair during the handshake, then use that ephemeral public/private key pair to handshake and exchange a private symmetric key and quickly discard the ephemeral private/public keypair.前向保密的作用是在握手期间交换临时公钥/私钥对,然后使用该临时公钥/私钥对握手和交换私钥对称密钥并快速丢弃临时私钥/公钥对。 What this accomplishes is protection against replay and decryption of a captured HTTPS session in the future if the web server's private key is compromised.这样做的目的是防止在 Web 服务器的私钥被泄露的情况下,在未来对捕获的 HTTPS 会话进行重放和解密。

There are protocols that allow two parties to arrive at a shared encryption key, even though all communication between them is in the clear.有一些协议允许两方获得共享的加密密钥,即使他们之间的所有通信都是明文。

Check out the Wikipedia article on how this happens during the SSL handshake.查看Wikipedia 文章,了解在 SSL 握手期间如何发生这种情况。

After they have this session key, this is used to encrypt the payload messages.在他们拥有此会话密钥后,这将用于加密有效负载消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM