在 SSL 套接字工厂连接中使用多个密钥对
我正在使用一对密钥,并且我考虑是否可以使用多个私钥来创建 SSL 套接字工厂。
这样我就能够共享不同的公钥并进行握手
动态地基于为客户端提供的公钥存储中,
下面是解释我如何创建此连接的源代码 SSL
...
...log("Activating an SSL connection");
System.setProperty("javax.net.ssl.keyStore", "myPrivateKey");
System.setProperty("javax.net.ssl.keyStorePassword", "myPass");
// SSL Server Socket Factory
SSLServerSocketFactory sslSrvFact = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
objServerSocket = sslSrvFact.createServerSocket(iPort);
log("SSL connection actived");
...
这是可能的还是一个梦想?
谢谢
I'm using a key-pair and I thinking in the possibility to use more than one private key to create ans SSL socket factory.
So I'll be able to share distinct public keys and make the hand shake
dynamically based in the public key store provide for clients
Bellow is the source code explaining how I create this connection SSL
...
...log("Activating an SSL connection");
System.setProperty("javax.net.ssl.keyStore", "myPrivateKey");
System.setProperty("javax.net.ssl.keyStorePassword", "myPass");
// SSL Server Socket Factory
SSLServerSocketFactory sslSrvFact = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
objServerSocket = sslSrvFact.createServerSocket(iPort);
log("SSL connection actived");
...
It's possible or is a dream?
Thx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过使用自己的
X509KeyManager
构造自己的SSLContext
并使用其 选择密钥库别名
来完成此操作href="http://docs.oracle.com/javase/6/docs/api/javax/net/ssl/X509KeyManager.html#chooseClientAlias%28java.lang.String%5B%5D,%20java.security.Principal% 5B%5D,%20java.net.Socket%29" rel="nofollow">chooseClientAlias
方法(或选择ServerAlias
,具体取决于侧面)。按照这些思路应该可以工作:(
有一个
java/org/jsslutils/sslcontext/keymanagers/FixedServerAliasKeyManager.java" rel="nofollow">这里的简短示例可能会帮助您 实际上不必委托给原始的 KeyManager (我只是发现它更方便)。您可以很好地实现它的所有方法,以使用您加载的 KeyStore 返回密钥和证书。
请注意,这对于选择客户端证书最有用。 Java 在服务器端不支持服务器名称指示(SNI)(即使在 Java 7 中也是如此),因此在选择别名之前您将无法知道客户端正在请求哪个主机名(来自服务器的角度)。
You can do this by constructing your own
SSLContext
using your ownX509KeyManager
and choose the keystorealias
using itschooseClientAlias
method (orchooseServerAlias
, depending on the side).Something along these lines should work:
(There is a short example here that may help you get started.)
You don't actually have to delegate to the original KeyManager (I just find it more convenient). You could very well implement all its methods to return the keys and certs using the KeyStore you've loaded
Note that this is mostly useful for choosing the client-certificate. Java doesn't support Server Name Indication (SNI) on the server-side (even in Java 7 as far as I know), so you won't be able to know which host name the client is requesting before choosing the alias (from a server point of view).