Java可以连接到通配符ssl [英] Can Java connect to wildcard ssl

查看:91
本文介绍了Java可以连接到通配符ssl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们希望购买外卡SSL证书,因为我们有很多子域名。但是我不知道Java是否信任通配符证书。当人们通过SSL连接到我们的API时,我们迫使我们与之通信的所有第三方将我们的SSL证书添加到他们的本地信任库中是不够的。

We wish to buy a wild-card SSL certificate as we have a lot of sub-domains. However I don't know if Java trusts wild-card certificates. As people connect into our API via SSL it will not be sufficient for us to force all third parties we communicate with to add our SSL certificate into their local truststore.

当我面临着从一个java信任的发行者那里购买通配符证书或者每个子域购买一个多个证书的困境。

At the moment I'm facing a dilemma to buy a wildcard certificate from a java trusted issuer or buy multiple certs one per sub-domain.

其他语言是否也有信任库?如果是这样,任何人都知道通配符证书是否也适用于它们。

Do other languages also have a truststore? If so does anyone know if wildcard certificates work with them also.

推荐答案

我用java 6尝试过这个。

I've attempted this with java 6.

它似乎工作正常。我已成功从具有通配符SSL证书的文件中读取标题和正文内容。

It appears to work correctly. I've succesfully read headers and body content from a file that had a wildcard SSL certificate.

package com.example.test;

import java.io.DataInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;


public class SSLTEST {
    public static void main(String[] args) {
        try {
            URL url = new URL("https://test.example.com/robots.txt");
            URLConnection connection = null;
            try {
                connection = url.openConnection();
            } catch (IOException e) {
                e.printStackTrace();
            }
            Map<String, List<String>> fields = connection.getHeaderFields();
            Iterator<Entry<String, List<String>>> headerIterator = fields.entrySet().iterator();
            System.out.println("HEADERS");
            System.out.println("-------------------------------");
            while (headerIterator.hasNext()){
                Entry<String, List<String>> header = headerIterator.next();
                System.out.println(header.getKey()+" :");
                Iterator<String> valueIterator = header.getValue().iterator();
                while (valueIterator.hasNext()){
                    System.out.println("\t"+valueIterator.next());
                }

            }

            String inputLine;
            DataInputStream input = new DataInputStream(connection.getInputStream());
            System.out.println("BODY CONTENT");
            System.out.println("-------------------------------");
            while ((inputLine = input.readLine()) != null) {
                System.out.println(inputLine);
            }


        } catch (MalformedURLException e) {
            System.err.println(e);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

编辑我刚收到确认,这适用于java 1.5

EDIT I've just recieved confirmation that this works on java 1.5

这篇关于Java可以连接到通配符ssl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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