Estou com problema com um certificado .pfx de um cliente:
Minha aplicação está funcionando perfeitamente em um cliente com o mesmo certificado .pfx (tipo A1), mes em outro cliente ao tentar acessar qualquer um dos web services dá o seguinte erro:
[b]
com.sun.xml.internal.ws.wsdl.parser.InaccessibleWSDLException: 2 counts of InaccessibleWSDLException.
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(RuntimeWSDLParser.java:161)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:133)
at com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:254)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:217)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:165)
at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:93)
at javax.xml.ws.Service.<init>(Service.java:56)
at br.inf.portalfiscal.nfe.wsdl.nfestatusservico.NfeStatusServico.<init>(NfeStatusServico.java:44)
at Main.main(Main.java:45)
[/b]
Minha classe de teste:
public class Main {
public static void main(String... args) {
try {
acceptSSL();
System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
//System.setProperty("javax.net.ssl.trustStoreType", "JKS");
System.setProperty("javax.net.ssl.trustStore", "c:\\homologa_SP"); // Arquivo gerado com o InstallCert
System.setProperty("javax.net.ssl.keyStoreType", "PKCS12");
System.setProperty("javax.net.ssl.keyStore", "c:\\arquivo_certificado.pfx"); // o arquivo com o certificado do emitente
System.setProperty("javax.net.ssl.keyStorePassword", "senha"); // a senha do arquivo
NfeStatusServicoNF status = new ObjectFactory().createNfeStatusServicoNF();
status.setNfeCabecMsg("<?xml version=\"1.0\" encoding=\"UTF-8\" ?><cabecMsg xmlns=\"http://www.portalfiscal.inf.br/nfe\" versao=\"1.02\"><versaoDados>1.07</versaoDados></cabecMsg>");
status.setNfeDadosMsg("<?xml version=\"1.0\" encoding=\"UTF-8\" ?><consStatServ xmlns=\"http://www.portalfiscal.inf.br/nfe\" versao=\"1.07\"><tpAmb>2</tpAmb><cUF>35</cUF><xServ>STATUS</xServ></consStatServ>");
NfeStatusServico service = new NfeStatusServico(new URL("https://homologacao.nfe.fazenda.sp.gov.br/nfeweb/services/nfestatusservico.asmx "), new QName("http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico", "NfeStatusServico"));
NfeStatusServicoSoap soap = service.getNfeStatusServicoSoap();
String result = soap.nfeStatusServicoNF(status.getNfeCabecMsg(), status.getNfeDadosMsg());
System.out.println(result);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void acceptSSL() {
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
}
} };
// Install the all-trusting trust manager
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (Exception e) {
}
}
}
Será que falta algum cadastro? Segundo o cliente o já foram feitos todos os cadastros na Sefaz.
E com esse mesmo certificado o cliente está usando perfeitamente (em produção) o programa da receita para envio de Nfe.
Agradeço a quem puder ajudar.