Java的keytool命令,带有IP地址 [英] Java's keytool command with IP addresses

查看:851
本文介绍了Java的keytool命令,带有IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过https网址获取图片,但我遇到了一些问题。我用Java的keytool命令生成一个密钥库。如果我指定公共名称(CN)等于我的主机名,例如CN = JONMORRA,然后尝试通过我的主机名查询,例如 https:// JONMORRA:8443 / 然后它运行正常。但是,如果我将公共名称指定为我的IP地址,例如CN = 192.168.56.1,并尝试通过我的IP地址查询,例如 https://192.168.56.1:8443/ 然后我收到错误

I'm trying to get an image via an https URL, and am having some problems. I generate a keystore with Java's keytool command. If I specify the common name (CN) equal to my hostname, such as CN=JONMORRA, and then try to query via my hostname, such as https://JONMORRA:8443/ then it works fine. However, if I specify the common name as my ip address, such that CN=192.168.56.1, and try to query via my ip address, such as https://192.168.56.1:8443/ then I get an error

HTTPS主机名错误:应该是< 192.168.56.1 >

HTTPS hostname wrong: should be <192.168.56.1>

这说明我的主机名错了,即使这是我在密钥库中指定的内容。

Which is stating that my hostname is wrong, even though that's what I specified in the keystore.

我想使用ip地址而不是主机名,这样我就可以在Linux和Windows框之间进行查询而不必担心主机名。

I would like to use ip addresses instead of hostnames so I can query between Linux and Windows boxes without worrying about hostnames.

为什么CN不接受IP地址,以及如何我能解决吗?

Why is the CN not accepting ip addresses, and how can I fix it?

谢谢

推荐答案

这个片段可能有效为你:

This snippet might work for you:

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSession;

HostnameVerifier hv = new HostnameVerifier() {
    public boolean verify(String urlHostName, SSLSession session) {
        System.out.println("Warning: URL Host: " + urlHostName + " vs. " + session.getPeerHost());
        return true;
    }
};

HttpsURLConnection.setDefaultHostnameVerifier(hv);

如果您尝试使用此代码,但它不起作用,请发布为<打印的内容code> urlHostName 和 session.getPeerHost()

If you do try this code, and it doesn't work, please post what is printed for urlHostName and session.getPeerHost().

此外,为什么让Windows和Linux机箱互操作需要使用IP地址而不是主机名?

Also, why does having Windows and Linux boxes interoperating require the use of IP addresses rather than hostnames?

这篇关于Java的keytool命令,带有IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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