【问题标题】:How to remove exception of security certificate using Java?如何使用 Java 删除安全证书的异常?
【发布时间】:2014-02-05 05:43:15
【问题描述】:

我正在使用 vmware API。通过使用这个 API,我可以获得 ESX 设备的信息。现在我想使用此 API 获取有关 vCenter 的信息,但得到异常:

java.rmi.RemoteException: VI SDK invoke exception:javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: Certificates does not conform to algorithm constraints

这是一个代码:

                    public void realesx(){
    System.out.println("Running ESX Realtime for host ..."+host);
    JSONObject esxcmdout = new JSONObject();
    String url = "https://" + host + "/sdk/vimService";
    try {
    ServiceInstance si = new ServiceInstance(new URL(url), user, pass,true);
    System.out.println("host :"+host+"---"+si.getAboutInfo().getFullName());

    System.out.println(" Version is .. " +si.getAboutInfo().version);
    System.out.println(" os type is .. " +si.getAboutInfo().osType);
    System.out.println("Vendor is .. " + si.getAboutInfo().vendor);
    System.out.println("name is" + si.getAboutInfo().name);

ManagedEntity[] managedEntities = new InventoryNavigator(
            si.getRootFolder()).searchManagedEntities("VirtualMachine");
ManagedEntity[] hostmanagedEntities = new InventoryNavigator(
            si.getRootFolder()).searchManagedEntities("HostSystem");

for (ManagedEntity hostmanagedEntity : hostmanagedEntities) {
HostSystem hostsys = (HostSystem) hostmanagedEntity;

String ESXhostname = hostsys.getName();
//System.out.println("main system version is .. " + hostsys.getConfig());

HostListSummary hls = hostsys.getSummary();
        HostHardwareSummary hosthwi = hls.getHardware();
        HostListSummaryQuickStats hqs = hls.getQuickStats();
        Datastore[] HDS = hostsys.getDatastores();
        StringBuilder DS = new StringBuilder();
        for (int i=0;i <HDS.length;i++){
            DatastoreSummary dsm =HDS[i].getSummary();

            DS.append(dsm.name+":"+dsm.capacity+":"+dsm.freeSpace+"-");
        }

int MEM=hqs.overallMemoryUsage;
int UPT=hqs.getUptime();
Integer CPU=hqs.getOverallCpuUsage();   

String esxkey = "ESXRealInfo";
String esxvalue = "ESXhostname-" + ESXhostname
        + ";CPU Usage-" + CPU + ";MEM Usage-"
        + MEM + ";UPTIME-" + UPT+"; Datastores -"+DS;
try {
    esxcmdout.put(esxkey, esxvalue);
} catch (JSONException e) {
    // TODO Auto-generated catch block
e.printStackTrace();
}
}

si.getServerConnection().logout();
}

catch (InvalidProperty e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (RuntimeFault e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (RemoteException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (MalformedURLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}


}

此代码适用于收集 ESX 设备的信息。如何解决 vCenter 证书错误?有没有其他方法可以做到这一点?

【问题讨论】:

    标签: java ssl


    【解决方案1】:

    出现此异常的原因之一是当 HTTPs 服务器(在您的情况下为 vCenter Server)提供的证书使用 MD2 算法进行签名并且 HTTP 客户端(您的代码)使用 JAVA 7 时。请参阅this 帖子了解更多细节。请尝试以下 2 个选项之一。

    1. 使用 JAVA 6。
    2. 注释掉文件 JDK_HOME/jre/lib/security/java.security 中的“jdk.certpath.disabledAlgorithms=MD2”行

    检查错误是否已解决。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-09
      • 2016-02-03
      • 1970-01-01
      • 2016-05-09
      • 1970-01-01
      • 1970-01-01
      • 2013-05-25
      相关资源
      最近更新 更多