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 trato de enviar el mensaje, me sale el siguiente excepción:Construcción de rutas PKIX fallida al hacer la conexión SSL
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 he escrito, y que ya existe en nuestra base de código) que realiza el cargo 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 comercial no dice nada sobre los certificados. Nos proporcionaron algo de código JSP de ejemplo que parece aceptar ciegamente 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, y yo tratamos de añadir el certificado (que he exportado desde Firefox) usando el comando keytool
, pero que no lo hicieron trabajo y obtuve el mismo error. He intentado con soluciones en la web (importando la clave y usando System.setProperty
) pero parece un poco torpe y no funcionó (me dio un NoSuchAlgorithmError
). ¡Cualquier ayuda es apreciada!
http://stackoverflow.com/questions/21076179/pkix-path-building-failed-and-unable-to-find-valid-certification-path-to-requ/36427118#36427118 – MagGGG