Spring Boot SSL 客户端 [英] Spring Boot SSL Client

查看:46
本文介绍了Spring Boot SSL 客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Spring Boot 的新手.到目前为止,我很享受.我开发了一个演示 SSL REST Web 服务器,可以正确处理相互 X.509 证书身份验证.使用带有自签名客户端的 IE 浏览器和服务器证书,我已经测试了演示 rest web 服务器工作正常——服务器和浏览器都成功地交换和验证了彼此的证书.

I am new to Spring Boot. So far I am enjoying it. I have developed a demo SSL rest web server that correctly handles mutual X.509 certificate authentication. Using an IE browser with self signed client & server certificates, I have tested that the demo rest web server is working correctly -- both the server and browser are successfully exchanging and validating each others certificates.

我在查找 SSL 客户端示例时遇到了问题,该示例显示了如何包含客户端证书并颁发 https.有人有一个简单的 REST 客户端示例来展示如何使用我的 ssl 服务器吗?

I am having trouble finding an SSL client example that shows how to include the client certificate and issue the https. Anybody have a simple rest client example that shows how to consume my ssl server?

最好的问候,史蒂夫·曼斯菲尔德

Best Regards, Steve Mansfield

推荐答案

我无法让 Andy 提交的上述客户端工作.我不断收到错误消息,说localhost!= clientname".无论如何,我让它正常工作.

I could not get the above client submitted by Andy to work. I kept getting errors saying that "localhost != clientname". Anyways, I got this to work correctly.

 import java.io.IOException;

 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.HttpException;
 import org.apache.commons.httpclient.URI;
 import org.apache.commons.httpclient.methods.GetMethod;

 public class SSLClient {

      static
        {
          System.setProperty("javax.net.ssl.trustStore","c:/apachekeys/client1.jks");
          System.setProperty("javax.net.ssl.trustStorePassword", "password");
          System.setProperty("javax.net.ssl.keyStore", "c:/apachekeys/client1.jks");
          System.setProperty("javax.net.ssl.keyStorePassword", "password");
       }

     public static void main(String[] args) throws HttpException, IOException {

         HttpClient client = new HttpClient();
         GetMethod method = new GetMethod();
         method.setURI(new URI("https://localhost:8443/restserver", false));
         client.executeMethod(method);

         System.out.println(method.getResponseBodyAsString());

     }

 }

这篇关于Spring Boot SSL 客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆