简体   繁体   English

双向SSL认证

[英]Two-way mutual SSL authentication

I've been tasked with implementing functionality in a Spring Boot REST API to contact another API (XML webservice).我的任务是在 Spring 启动 REST API 中实现功能以联系另一个 ZDB974238714CA8DE634ACE 网络服务。 The outside API uses two-way SSL authentication.外部API采用双向SSL认证。 I've been given the correct certificate to implement on our side, and I've implemented the Java code.我已经获得了要在我们这边实施的正确证书,并且我已经实施了 Java 代码。 But whenever I run the code I get "Received fatal alert: handshake_failure".但是每当我运行代码时,我都会收到“收到致命警报:handshake_failure”。 I've loaded the jks keystore into the SSLContext like this:我已经将 jks 密钥库加载到 SSLContext 中,如下所示:

FileInputStream truststoreFile = new FileInputStream("/Users/myUser/Desktop/myProject/myProjectName/src/main/resources/keystore-name.jks");
        TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        KeyStore truststore = KeyStore.getInstance(KeyStore.getDefaultType());
        char[] trustorePassword = "keyStorePassword".toCharArray();
        truststore.load(truststoreFile, trustorePassword);
        trustManagerFactory.init(truststore);
        SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
        KeyManager[] keyManagers = {};//if you have key managers;
        sslContext.init(keyManagers, trustManagerFactory.getTrustManagers(), new SecureRandom());

Would I actually have to configure anything else to enable mutual two-way SSL from our API, acting like I client in this scenario?我是否真的需要配置其他任何东西才能从我们的 API 启用双向 SSL,在这种情况下就像我的客户端一样? I thought I could just like the cert keystore and go.我想我可以喜欢证书密钥库和 go。 But maybe I need to do something else to enable this?但也许我需要做其他事情来启用它?

You are using the file shared with you in the wrong context.您在错误的上下文中使用了与您共享的文件。 That file is a Keystore containing the client certificate and corresponding key.该文件是包含客户端证书和相应密钥的密钥库。

TrustStore - Tells which CAs should be trusted by the client (you). TrustStore - 告诉客户(您)应该信任哪些 CA。

Keystore - Tells the server about the client (you).密钥库 - 告诉服务器有关客户端(您)的信息。

In order for the mutual TLS handshake to pass through, you need to load the Keystore and set it in KeyManager like below.为了使双向 TLS 握手能够通过,您需要加载 Keystore 并在 KeyManager 中进行设置,如下所示。

// Load the Keystore
KeyStore keyStore = KeyStore.getInstance("JKS");
InputStream keystoreStream = new FileInputStream(pathToJKSFile);
keyStore.load(keystoreStream, keystorePassword.toCharArray());

// Add Keystore to KeyManager
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keyStore, keystorePassword.toCharArray());

// Create SSLContext with KeyManager and TrustManager
SSLContext context = SSLContext.getInstance("TLS");
context.init(keyManagerFactory.getKeyManagers(), null, new SecureRandom());
SSLSocketFactory sslSocketFactory = context.getSocketFactory();

// Now, use this SSLSocketFactory while making the HTTPS request

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

相关问题 两种方式相互 SSL 认证 - Two way mutual SSL authentication 使用Apache CXF客户端插件进行双向(双向)SSL身份验证 - Two-way (mutual) SSL authentication with the Apache CXF client plugin for grails 具有云驻留密钥库和信任库(秘密管理器)的相互认证(双向 TLS/SSL)-Spring 启动 - Mutual Authentication(Two-Way TLS/SSL) with cloud residing KeyStores and TrustStores(Secret Manager) -Spring boot 与Glassfish3 / 4或Tomcat 8的双向(相互)SSL和自签名证书 - Two-way (mutual) SSL with Glassfish3/4 or Tomcat 8 and self-signed certificates Apache Thrift 2路SSL相互认证 - Apache Thrift 2-way SSL mutual authentication AWS Lambda 中的相互身份验证(2 路 SSL) - Mutual Authentication (2-way SSL) in AWS Lambda 使用双向身份验证连接到服务器时 Java 测试客户端中的 SSL Handshake_failure - SSL Handshake_failure in Java test client while connecting to server with two-way authentication 双向SSL下的Java小程序 - Java applet under Two-way SSL 与Tomcat的双向SSL通信 - Two-way SSL communication with Tomcat 为WebServices启用SSL“相互认证”和为GUI启用“单向认证”吗? - Enable SSL “Mutual Authentication” for WebServices and “One Way Authentication” for the GUI?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM