本文整理了Java中javax.net.ssl.HttpsURLConnection.getServerCertificates()
方法的一些代码示例,展示了HttpsURLConnection.getServerCertificates()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpsURLConnection.getServerCertificates()
方法的具体详情如下:
包路径:javax.net.ssl.HttpsURLConnection
类名称:HttpsURLConnection
方法名:getServerCertificates
[英]Return the list of certificates identifying the peer during the handshake.
[中]返回在握手过程中标识对等方的证书列表。
代码示例来源:origin: robovm/robovm
/**
* Returns the {@code Principal} identifying the peer.
*
* @return the {@code Principal} identifying the peer.
* @throws SSLPeerUnverifiedException
* if the identity of the peer has not been verified.
* @throws IllegalStateException
* if no connection has been established yet.
*/
public Principal getPeerPrincipal() throws SSLPeerUnverifiedException {
Certificate[] certs = getServerCertificates();
if (certs == null || certs.length == 0 || (!(certs[0] instanceof X509Certificate))) {
throw new SSLPeerUnverifiedException("No server's end-entity certificate");
}
return ((X509Certificate) certs[0]).getSubjectX500Principal();
}
代码示例来源:origin: square/okhttp
peerCertificates = httpsUrlConnection.getServerCertificates();
} catch (SSLPeerUnverifiedException e) {
peerCertificates = null;
代码示例来源:origin: stackoverflow.com
.openConnection();
conn.connect();
Certificate[] certs = conn.getServerCertificates();
for (Certificate cert : certs) {
System.out.println("Certificate is: " + cert);
代码示例来源:origin: org.apache.cxf/cxf-rt-transports-http
localCertificates = conn.getLocalCertificates();
localPrincipal = conn.getLocalPrincipal();
serverCertificates = conn.getServerCertificates();
peerPrincipal = conn.getPeerPrincipal();
} else {
代码示例来源:origin: com.hazelcast/hazelcast-all
private void checkCertificate(HttpsURLConnection con) throws IOException, CertificateException {
for (Certificate cert : con.getServerCertificates()) {
if (cert instanceof X509Certificate) {
((X509Certificate) cert).checkValidity();
} else {
throw new CertificateException("Invalid certificate from hazelcast.cloud endpoint");
}
}
}
代码示例来源:origin: hazelcast/hazelcast-jet
private void checkCertificate(HttpURLConnection connection) throws IOException, CertificateException {
if (!(connection instanceof HttpsURLConnection)) {
return;
}
HttpsURLConnection con = (HttpsURLConnection) connection;
for (Certificate cert : con.getServerCertificates()) {
if (cert instanceof X509Certificate) {
((X509Certificate) cert).checkValidity();
} else {
throw new CertificateException("Invalid certificate from hazelcast.cloud endpoint");
}
}
}
代码示例来源:origin: stackoverflow.com
URL url = new URL("https://www.google.com");
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.connect();
for(Certificate crt : conn.getServerCertificates()) {
System.out.println(crt);
}
代码示例来源:origin: stackoverflow.com
public void certInformation(String aURL) throws Exception{
URL destinationURL = new URL(aURL);
HttpsURLConnection conn = (HttpsURLConnection) destinationURL.openConnection();
conn.connect();
Certificate[] certs = conn.getServerCertificates();
for (Certificate cert : certs) {
System.out.println("Certificate is: " + cert);
if(cert instanceof X509Certificate) {
X509Certificate x = (X509Certificate ) cert;
System.out.println(x.getIssuerDN());
}
}
}
代码示例来源:origin: stackoverflow.com
import java.io.IOException;
import java.net.URL;
import java.security.cert.Certificate;
import javax.net.ssl.HttpsURLConnection;
public class Test {
public static void main(String[] args) throws IOException {
URL httpsURL = new URL("https://www.google.com.br/");
HttpsURLConnection connection = (HttpsURLConnection) httpsURL.openConnection();
connection.connect();
Certificate[] certs = connection.getServerCertificates();
for (Certificate cer : certs) {
System.out.println(cer.getPublicKey());
}
}
}
代码示例来源:origin: stackoverflow.com
URL url = new URL("https://www.google.com/");
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
con.connect();
Certificate userCert[] = con.getServerCertificates();
X509Certificate x509cert = ((X509Certificate) userCert[0]);
byte[] tbs=x509cert.getTBSCertificate();
代码示例来源:origin: stackoverflow.com
URL url = new URL("https://www.google.com/");
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
con.connect();
Certificate userCert[] = con.getServerCertificates();
X509Certificate x509cert = ((X509Certificate) userCert[0]);
byte[] tbs=x509cert.getTBSCertificate();
代码示例来源:origin: ibinti/bugvm
/**
* Returns the {@code Principal} identifying the peer.
*
* @return the {@code Principal} identifying the peer.
* @throws SSLPeerUnverifiedException
* if the identity of the peer has not been verified.
* @throws IllegalStateException
* if no connection has been established yet.
*/
public Principal getPeerPrincipal() throws SSLPeerUnverifiedException {
Certificate[] certs = getServerCertificates();
if (certs == null || certs.length == 0 || (!(certs[0] instanceof X509Certificate))) {
throw new SSLPeerUnverifiedException("No server's end-entity certificate");
}
return ((X509Certificate) certs[0]).getSubjectX500Principal();
}
代码示例来源:origin: MobiVM/robovm
/**
* Returns the {@code Principal} identifying the peer.
*
* @return the {@code Principal} identifying the peer.
* @throws SSLPeerUnverifiedException
* if the identity of the peer has not been verified.
* @throws IllegalStateException
* if no connection has been established yet.
*/
public Principal getPeerPrincipal() throws SSLPeerUnverifiedException {
Certificate[] certs = getServerCertificates();
if (certs == null || certs.length == 0 || (!(certs[0] instanceof X509Certificate))) {
throw new SSLPeerUnverifiedException("No server's end-entity certificate");
}
return ((X509Certificate) certs[0]).getSubjectX500Principal();
}
代码示例来源:origin: com.gluonhq/robovm-rt
/**
* Returns the {@code Principal} identifying the peer.
*
* @return the {@code Principal} identifying the peer.
* @throws SSLPeerUnverifiedException
* if the identity of the peer has not been verified.
* @throws IllegalStateException
* if no connection has been established yet.
*/
public Principal getPeerPrincipal() throws SSLPeerUnverifiedException {
Certificate[] certs = getServerCertificates();
if (certs == null || certs.length == 0 || (!(certs[0] instanceof X509Certificate))) {
throw new SSLPeerUnverifiedException("No server's end-entity certificate");
}
return ((X509Certificate) certs[0]).getSubjectX500Principal();
}
代码示例来源:origin: com.mobidevelop.robovm/robovm-rt
/**
* Returns the {@code Principal} identifying the peer.
*
* @return the {@code Principal} identifying the peer.
* @throws SSLPeerUnverifiedException
* if the identity of the peer has not been verified.
* @throws IllegalStateException
* if no connection has been established yet.
*/
public Principal getPeerPrincipal() throws SSLPeerUnverifiedException {
Certificate[] certs = getServerCertificates();
if (certs == null || certs.length == 0 || (!(certs[0] instanceof X509Certificate))) {
throw new SSLPeerUnverifiedException("No server's end-entity certificate");
}
return ((X509Certificate) certs[0]).getSubjectX500Principal();
}
代码示例来源:origin: FlexoVM/flexovm
/**
* Returns the {@code Principal} identifying the peer.
*
* @return the {@code Principal} identifying the peer.
* @throws SSLPeerUnverifiedException
* if the identity of the peer has not been verified.
* @throws IllegalStateException
* if no connection has been established yet.
*/
public Principal getPeerPrincipal() throws SSLPeerUnverifiedException {
Certificate[] certs = getServerCertificates();
if (certs == null || certs.length == 0 || (!(certs[0] instanceof X509Certificate))) {
throw new SSLPeerUnverifiedException("No server's end-entity certificate");
}
return ((X509Certificate) certs[0]).getSubjectX500Principal();
}
代码示例来源:origin: com.bugvm/bugvm-rt
/**
* Returns the {@code Principal} identifying the peer.
*
* @return the {@code Principal} identifying the peer.
* @throws SSLPeerUnverifiedException
* if the identity of the peer has not been verified.
* @throws IllegalStateException
* if no connection has been established yet.
*/
public Principal getPeerPrincipal() throws SSLPeerUnverifiedException {
Certificate[] certs = getServerCertificates();
if (certs == null || certs.length == 0 || (!(certs[0] instanceof X509Certificate))) {
throw new SSLPeerUnverifiedException("No server's end-entity certificate");
}
return ((X509Certificate) certs[0]).getSubjectX500Principal();
}
代码示例来源:origin: org.symphonyoss.symphony/jcurl
private void processResponseCertificates(HttpURLConnection con, Response response) throws SSLPeerUnverifiedException {
if (con instanceof HttpsURLConnection) {
try {
HttpsURLConnection secureConn = (HttpsURLConnection) con;
response.cipherSuite = secureConn.getCipherSuite();
response.serverCertificates = secureConn.getServerCertificates();
response.clientCertificates = secureConn.getLocalCertificates();
} catch (IllegalStateException e) {
// If the response is not a 200, getting response certificates will fail with the (misleading) message
// "connection not yet open". Ignore this.
}
}
}
代码示例来源:origin: org.microemu/microemu-javase
public SecurityInfo getSecurityInfo() throws IOException {
if (securityInfo == null) {
if (cn == null) {
throw new IOException();
}
if (!connected) {
cn.connect();
connected = true;
}
HttpsURLConnection https = (HttpsURLConnection) cn;
Certificate[] certs = https.getServerCertificates();
if (certs.length == 0) {
throw new IOException();
}
securityInfo = new SecurityInfoImpl(
https.getCipherSuite(),
sslContext.getProtocol(),
new CertificateImpl((X509Certificate) certs[0]));
}
return securityInfo;
}
代码示例来源:origin: candrews/HttpResponseCache
public Entry(URI uri, RawHeaders varyHeaders, HttpURLConnection httpConnection) {
this.uri = uri.toString();
this.varyHeaders = varyHeaders;
this.requestMethod = httpConnection.getRequestMethod();
this.responseHeaders = RawHeaders.fromMultimap(httpConnection.getHeaderFields());
if (isHttps()) {
HttpsURLConnection httpsConnection = (HttpsURLConnection) httpConnection;
cipherSuite = httpsConnection.getCipherSuite();
Certificate[] peerCertificatesNonFinal = null;
try {
peerCertificatesNonFinal = httpsConnection.getServerCertificates();
} catch (SSLPeerUnverifiedException ignored) {
}
peerCertificates = peerCertificatesNonFinal;
localCertificates = httpsConnection.getLocalCertificates();
} else {
cipherSuite = null;
peerCertificates = null;
localCertificates = null;
}
}
内容来源于网络,如有侵权,请联系作者删除!