简体   繁体   English

没有SSLStream的加密连接?

[英]Encrypted connection without SSLStream?

I need to encrypt the data that will be sent/received, client <> server and vice-versa. 我需要加密将发送/接收的数据,客户端<>服务器,反之亦然。

Since I can't use SSLStream right now, I am looking for other alternatives. 由于我现在无法使用SSLStream,因此我正在寻找其他替代方法。

While thinking about the alternatives I have, I got stucked on how would I send the data to the client in a way it can't be read/intercepted. 在考虑我拥有的替代方案时,我被困在如何以一种无法读取/拦截的方式将数据发送给客户端的问题上。

Here is how I thinked of doing it: 这是我的想法:

  • Client/Server will have a RSA private key inside the application that will be loaded from a string to encrypt/decrypt the data received from the server. 客户端/服务器将在应用程序内部具有RSA私钥,该私钥将从字符串中加载以加密/解密从服务器接收的数据。

  • After the initial connection request, the server will send a session id along with a inner AES key/iv. 在初始连接请求之后,服务器将发送会话ID以及内部AES密钥/ iv。

  • From here on the client will communicate using both, the RSA and the AES. 从这里开始,客户端将使用RSA和AES进行通信。

I would like to hear from experienced people some new ideas or better ways to do what I need here which is: 我想从经验丰富的人那里听到一些新想法或更好的方法来完成我在这里需要做的事情:

Send encrypted data from client to server and vice-versa without using SSLStream and yet having a good level of security. 在不使用SSLStream的情况下,将加密的数据从客户端发送到服务器,反之亦然,但具有很高的安全性。

I understand that having the private key on the client is risk but I am yet to find a better solution. 我知道在客户端上拥有私钥是有风险的,但是我还没有找到更好的解决方案。

If you really can't use SSL, you can build poor man's SSL yourself: 如果您确实无法使用SSL,则可以自己构建穷人的SSL:

The client knows a RSA public key, the server knows the corresponding private key. 客户端知道RSA公钥,服务器知道相应的私钥。

To communicate the client creates a random session key that can be used with AES. 为了进行通信,客户端创建了可以与AES一起使用的随机会话密钥。 It encrypts it with the RSA public key, and sends it to the server. 它使用RSA公钥对其进行加密,然后将其发送到服务器。 It encrypts the rest of the communication with the AES session key. 它使用AES会话密钥加密其余的通信。

The server decrypts the first message with the RSA private key, and thus gets the session key. 服务器使用RSA私钥解密第一条消息,从而获得会话密钥。 It uses this key for the rest of the communication. 它在其余的通信中使用此密钥。

That way the client doesn't contain anything secret, but the communication itself is private. 这样,客户端不会包含任何秘密,但是通信本身是私有的。 The main thing that's lacking with this scheme is client authentication. 该方案缺少的主要内容是客户端身份验证。

You should also use different nonces/IVs for the server->client and the client->server stream. 您还应该对服务器->客户端和客户端->服务器流使用不同的nonce / IV。 You might also want to add integrity checking(MACs). 您可能还需要添加完整性检查(MAC)。

The only way you can do this is using a shared secret : something both the client and the server know, but no-one else does. 做到这一点的唯一方法是使用共享机密 :客户端和服务器都知道这一点,而其他人则不知道。

Public key SSL works on the premise that a certificate (and hence a key-pair) is locked to a particular server/domain which can be independently confirmed via a third party (the signing authority). 公钥SSL的前提是证书(因此是密钥对)被锁定到可以通过第三方(签名机构)独立确认的特定服务器/域。

As soon as you get rid of this premise, you are open to man-in-the-middle attacks with public key encryption because you cannot guarantee who you are talking to (or at least you cannot guarantee someone is not intercepting/relaying your messages). 一旦摆脱了这一前提,您就可以接受使用公钥加密的中间人攻击,因为您不能保证与谁交谈(或者至少不能保证某人不会拦截/中继您的消息) )。

If you use a shared secret, you don't need public keys, certificates or anything else - but if any unauthorised party discovers your secret, you're screwed. 如果您使用共享机密,则不需要公钥,证书或其他任何内容-但是,如果任何未经授权的一方发现您的机密,您就会上当受骗。

A possible approach: 可能的方法:

-Server has a well-known public key and a private key no one knows (not even the clients) -服务器有一个众所周知的公钥和一个没人知道的私钥(甚至没有客户端)

-Client generates a 'handshake' packet and encrypts it with the server's public key. -客户端生成一个“握手”数据包,并使用服务器的公共密钥对其进行加密。 The handshake packet contains any initialisation/authentication stuff you need, plus a randomly generated passphrase + IV to use for AES encryption. 握手数据包包含您需要的任何初始化/身份验证内容,以及用于AES加密的随机生成的密码+ IV。

-Server decrypts handshake packet using its private key and now has access to the AES passphrase + IV. -服务器使用其私钥解密握手数据包,现在可以访问AES密码+ IV。 It responds with an 'ACK' packet indicating its ready. 它以“ ACK”数据包作为响应,指示其已准备就绪。

-Now client can send data using the AES passphrase to encrypt symmetrically, and the server can decrypt, and vice versa. -现在,客户端可以使用AES密码发送数据进行对称加密,服务器可以解密,反之亦然。

There's no need for the client having any private key bundled with it. 客户端不需要绑定任何私钥。 RSA is specifically designed for data exchange without the need for a shared key. RSA是专门为数据交换而设计的,不需要共享密钥。

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

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