简体   繁体   English

Java:TCP加密,SSL和Netty

[英]Java: TCP Encryption, SSL and Netty

Ok so I have a peer to peer (client/server on one host) setup (over a local LAN), this is using Netty, a Java networking framework. 好的,我有一个点对点(一个主机上的客户端/服务器)设置(通过本地局域网),这是使用Netty,一个Java网络框架。 I use raw TCP/IP (as in, no HTTP) for communication and transfers. 我使用原始TCP / IP(如在,没有HTTP)进行通信和传输。

Currently all data is transferred in "plain-text" and i'm starting the process of securing such transmitted data. 目前,所有数据都以“纯文本”传输,我正在开始保护此类传输数据的过程。

I've had a good read of types of encryption/practices etc (but probably only touched the surface and its melting my brain already) 我已经很好地阅读了加密/实践等类型(但可能只是触及表面并且已经融化了我的大脑)

Netty includes a SSL implemntation, heres some links to hopefully better explain myself: Netty包含一个SSL实现,有一些链接可以更好地解释自己:

http://docs.jboss.org/netty/3.2/xref/org/jboss/netty/example/securechat/package-summary.html http://docs.jboss.org/netty/3.2/xref/org/jboss/netty/example/securechat/package-summary.html

Inside "SecureChatTrustManagerFactory" there are 2 methods: 在“SecureChatTrustManagerFactory”里面有两种方法:

          public void checkClientTrusted(
                  X509Certificate[] chain, String authType) throws CertificateException {
              // Always trust - it is an example.
              // You should do something in the real world.
              // You will reach here only if you enabled client certificate auth,
              // as described in SecureChatSslContextFactory.
              System.err.println(
                      "UNKNOWN CLIENT CERTIFICATE: " + chain[0].getSubjectDN());
          }

          public void checkServerTrusted(
                 X509Certificate[] chain, String authType) throws CertificateException {
             // Always trust - it is an example.
              // You should do something in the real world.
              System.err.println(
                      "UNKNOWN SERVER CERTIFICATE: " + chain[0].getSubjectDN());
          }

"SecureChatKeyStore" contains a hard coded certificate from what I can see. “SecureChatKeyStore”包含我可以看到的硬编码证书。

So my questions are: 所以我的问题是:

  • Do I need to generate a certificate? 我需要生成证书吗?
  • if so, each time the application is run? 如果是这样,每次运行应用程序?
  • if so, per client? 如果是这样,每个客户?
  • if so, is this certification passed between client and server? 如果是这样,该认证是否在客户端和服务器之间传递?
  • if so, how is it done securely? 如果是这样,它是如何安全地完成的?

I'm not entirely sure where to start. 我不完全确定从哪里开始。 From what I can see the Netty implementation is saying "Here's the basis of creating secure connections, but we have left out the part that actually makes them secure/authenticated". 从我可以看到的Netty实现是说“这是创建安全连接的基础,但我们遗漏了实际使它们安全/认证的部分”。

Any other pointers/tips I should know about? 我应该知道的任何其他指针/提示?

Thank you in advance. 先感谢您。

As others have pointed out, there is a difference between application security and transport link security. 正如其他人所指出的,应用程序安全性和传输链接安全性之间存在差异。 I think you are aiming for the last one as you mainly mention encryption. 我认为你的目标是最后一个,因为你主要提到加密。 Encryption offers confidentiallity from eavesdroppers. 加密提供了窃听者的机密性。 Furhermore, as SSL also incorporates message authentication code, it will also offer protection of a third party altering packets during transit. 此外,由于SSL还包含消息身份验证代码,因此它还可以保护第三方在传输过程中更改数据包。 It does not provide any protection of messages once received. 收到消息后,它不提供任何消息保护。

As you may have noticed on the internet for HTTPS connections, you will need at least a server certificate. 您可能已经在互联网上注意到HTTPS连接,您至少需要一个服务器证书。 This certificate can remain static, although it should contain an expiry date at which time you should replace the certificate. 此证书可以保持静态,但应包含到期日,您应该更换证书。 The server certificate should be trusted by the client (eg by embedding it as a resource). 客户端应该信任服务器证书(例如,通过将其作为资源嵌入)。 You can also use SSL with client authentication, but that means you need to have ample security measures to keep the private key on the client safe. 您还可以将SSL与客户端身份验证一起使用,但这意味着您需要有足够的安全措施来保护客户端上的私钥安全。

It's probably best to start off with a "self-signed" server certificate only. 最好只从“自签名”服务器证书开始。 Thats the one you need to trust in the checkServerTrusted method. 这是你需要在checkServerTrusted方法中信任的checkServerTrusted Basically, the chain is simply that one certificate. 基本上,链只是一个证书。

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

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