Nota fiscal Eletrônica: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure

2 respostas
B

Pessoal,

Eu percebi que já houveram vários tópicos relacionados a comunicação webservice para o envio de notas fiscais eletronicas, mas nenhum com a solução do problema:

fgarnica postou no ani passado, mas sem respostas:
http://www.guj.com.br/posts/list/70567.java#370633

Alguém já conseguiu solucionar esse problema, visto que os certificados digitais da receita já foram já foram adicionados
na aplicação?

2 Respostas

R

Como foi adicionado.
Todos os problemas que tive de ‘handshake’ foram problemas com certificado.

B
public static void main( String[] args ) throws Exception 
       { 
           HttpSecureProtocol f = new HttpSecureProtocol(); 
    
           // might as well trust the usual suspects: 
           f.addTrustMaterial(TrustMaterial.JSSE_CACERTS); 
    
           // here's where we start trusting usertrust.com's CA: 
           //FileInputStream stream = new FileInputStream ("certificate.cer");
          FileInputStream stream = new FileInputStream ("base64.cer");
           f.addTrustMaterial(new TrustMaterial(stream )); 

           
           Protocol trustHttps = new Protocol("https", f, 443); 
           Protocol.registerProtocol("https", trustHttps); 
    
           HttpClient client = new HttpClient(); 
           GetMethod httpget = new GetMethod("https://hnfe.fazenda.mg.gov.br/nfe/services/CadConsultaCadastro/"); 
           //GetMethod httpget = new GetMethod("https://www.usertrust.com/"); 
           client.executeMethod(httpget); 
           String statusLine = httpget.getStatusLine().toString();
           String body = httpget.getResponseBodyAsString(); 
           System.out.println( "HTTPClient: " + statusLine ); 
    
          // Notice that Java still can't access it.  Only HTTPClient knows 
          // to trust the cert! 
          URL u = new URL( "https://www.usertrust.com/" ); 
          try 
          { 
              // This will throw an SSLHandshakeException 
              u.openStream(); 
          } 
          catch ( SSLHandshakeException she ) 
          { 
              System.out.println( "Java:       " + she ); 
          } 
      }

Onde meu arquivo jssecacerts contém as certificações que adicionei de acordo com o código:
http://blogs.sun.com/andreas/resource/InstallCert.java

Criado 24 de junho de 2008
Ultima resposta 24 de jun. de 2008
Respostas 2
Participantes 2