Open gustavoaalves opened 9 years ago
No return?
@gustavoaalves, what is the question? ;)
My need is to make a secure HTTP request using a digital certificate to capture the wsdl. The code that I put up, only reports exactly what the problem is and what the need. There is no way that I could contribute with you to add this possibility (secure HTTP request using digital certificates)? Or do you have any plans to implement something related?
Hi, I think you did a great job with the class above. You can clone the repository here on github, make your extension and generate a pull request. Then we can incorporate this into the next release.
Okay. I'm going to pull request on this... Thanks!!
This need to do this to use the framework of you and generate sample request envelope on the web services of the Secretariats of the Brazilian Finance (SEFAZ - Invoice Project).
I am using a smartcard. For my case quickly made some changes just to better show my need.
Functions ExternalResolver.groovy:
private resolveAsString(url) { try{ HttpResponse con = requestSSL(url) EntityUtils.toString(con.entity) } catch (ResourceDownloadException e) { throw e } catch (Exception e) { throw new ResourceDownloadException(rootCause : e.getCause(), url : url) } }
ClientSSL.java:
package com.predic8.xml.util;
import java.io.ByteArrayInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.net.Socket; import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.Principal; import java.security.PrivateKey; import java.security.Provider; import java.security.Security; import java.security.UnrecoverableKeyException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.Enumeration;
import javax.net.ssl.KeyManager; import javax.net.ssl.SSLContext; import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; import javax.net.ssl.X509KeyManager; import javax.net.ssl.X509TrustManager;
import org.apache.http.HttpResponse; import org.apache.http.conn.ClientConnectionManager; import org.apache.http.conn.scheme.Scheme; import org.apache.http.conn.ssl.SSLSocketFactory; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.params.HttpConnectionParams; import org.apache.http.params.HttpParams;
public class ClientSSL {
}
NFeBuildCacerts.java:
/**
*/ package com.predic8.xml.util;
import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; import java.security.KeyStore; import java.security.MessageDigest; import java.security.cert.CertificateException; import java.security.cert.X509Certificate;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLException; import javax.net.ssl.SSLHandshakeException; import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; import javax.net.ssl.X509TrustManager;
/**
@author JavaC - Java Community */ public class NFeBuildCacerts { private static final String JSSECACERTS = "nfe-cacerts"; private static final int TIMEOUT_WS = 60; private static String directory;
public NFeBuildCacerts(final String saveDirectory, String url) throws Exception {
}
public static File gerarCacerts(final String host, final int port) throws Exception { final char[] passphrase = "changeit".toCharArray();
}
private static class SavingTrustManager implements X509TrustManager { private final X509TrustManager tm; private X509Certificate[] chain;
}
private static void info(final String info) { System.out.println("INFO: " + info); }
private static void error(final String error) { System.out.println("ERROR: " + error); }
}