简体   繁体   English

从X509Certificate获取HttpsURLConnection的SSL上下文

[英]Getting SSL context for HttpsURLConnection from X509Certificate

I am pretty new to certificates, but I have to do something like this (in Java): 我对证书还很陌生,但是我必须这样做(在Java中):

1) I have requestor's certificate in my hand: 1)我手中有请求者的证书:

X509Certificate[] certs = (X509Certificate[]) request.getAttribute("javax.servlet.request.X509Certificate");

2) I need to request another url with that certificate (is it even possible?), something like: 2)我需要使用该证书请求另一个网址(甚至可能吗?),例如:

URL url = new URL(server);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            if (connection instanceof HttpsURLConnection) {
                ((HttpsURLConnection) connection).setSSLSocketFactory(???);
            }

My question is: how do I link certificates from 1) with request from 2)? 我的问题是:如何将1)的证书与2)的请求链接?

cheers. 干杯。

You won't be able to do this. 您将无法执行此操作。 In order to establish an authenticated SSL connection you need both the public and private components of the certificate. 为了建立经过身份验证的SSL连接,您需要证书的公共和私有组件。 It would be a security hole to do something like what you are suggesting, allowing a server to masquerade as an entity that it isn't. 进行类似您建议的操作将是一个安全漏洞,允许服务器伪装成不是的实体。

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

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