La construcción de la ruta PKIX falló al realizar la conexión SSL
Me estoy integrando con una cuenta de comerciante llamada CommWeb y estoy enviando una publicación SSL a su URL (https://migs.mastercard.com.au/vpcdps) Cuando intento enviar la publicación, recibo la siguiente excepción:
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
El código (que no escribí y que ya existe en nuestra base de código) que realiza la publicación es:
public static HttpResponse sendHttpPostSSL(String url, Map<String, String> params) throws IOException {
PostMethod postMethod = new PostMethod(url);
for (Map.Entry<String, String> entry : params.entrySet()) {
postMethod.addParameter(entry.getKey(), StringUtils.Nz(entry.getValue()));
}
HttpClient client = new HttpClient();
int status = client.executeMethod(postMethod);
if (status == 200) {
StringBuilder resultBuffer = new StringBuilder();
resultBuffer.append(postMethod.getResponseBodyAsString());
return new HttpResponse(resultBuffer.toString(), "");
} else {
throw new IOException("Invalid response code: " + status);
}
}
La documentación para la integración de la cuenta mercantil no dice nada acerca de los certificados. Proporcionaron un código JSP de muestra que parece aceptar ciegamente los certificados:
<%! // Define Static Constants
// ***********************
public static X509TrustManager s_x509TrustManager = null;
public static SSLSocketFactory s_sslSocketFactory = null;
static {
s_x509TrustManager = new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[] {}; }
public boolean isClientTrusted(X509Certificate[] chain) { return true; }
public boolean isServerTrusted(X509Certificate[] chain) { return true; }
};
java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
try {
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, new X509TrustManager[] { s_x509TrustManager }, null);
s_sslSocketFactory = context.getSocketFactory();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}
}
...
...
// write output to VPC
SSLSocket ssl = (SSLSocket)s_sslSocketFactory.createSocket(s, vpc_Host, vpc_Port, true);
ssl.startHandshake();
os = ssl.getOutputStream();
// get response data from VPC
is = ssl.getInputStream();
...
...
%>
Nuestra aplicación web tiene un almacén de claves, e intenté agregar el certificado (que exporté de Firefox) usando elkeytool
comando, pero eso no funcionó y obtuve el mismo error. He probado soluciones en la web (importando la clave y usandoSystem.setProperty
) pero eso parece un poco torpe y no funcionó (me dio unNoSuchAlgorithmError
) Cualquier ayuda es apreciada!