I am trying to scrape an application that uses self signed
certificates, this is to work with EnvJS library. Rhino access
HTTPS using the jsse.jar library and I am trying to create a
new "TrustManager" to make Rhino accept connect.
I created a package with one class called TrustAll that give support
for self signed certificates and at the Rhino command prompt try to
install my new TrustManager in this way:
$ java -classpath /opt/tmp/trustallssl.jar -jar ../rhino/js.jar
Rhino 1.7 release 2 2009 03 22
js> importPackage(Packages.javax.
net.ssl)
js> importPackage(Packages.trustallssl)
js>
HttpsURLConnection.setDefaultSSLSocketFactory(TrustAll.getTrustAllSocketFactory())
js: "<stdin>", line 4: uncaught JavaScript runtime exception:
ReferenceError: "TrustAll" is not defined.
at <stdin>:4
It seems that Rhino doesn't see my package, but recognize the
HttpsURLConnection. If I try different code;
js> HttpsURLConnection.setDefaultSSLSocketFactory(null)
org.mozilla.javascript.WrappedException: Wrapped
java.lang.IllegalArgumentException: no default SSLSocketFactory
specified (<stdin>#5)
This exception is correct and it means that the javax.net.ssl was
loaded.
What I am doing wrong ????
Below is the code of my package.
Thanks in advance,
Ventura
package trustallssl;
/**
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
/**
* @author Ventura
*
*/
public class TrustAll {
// Create a trust manager that does not validate certificate chains
static TrustManager[] trustAllCerts() {
return 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) {
}
}
};
}
static public SSLSocketFactory getTrustAllSocketFactory() {
SSLContext sc = null;
try {
sc = SSLContext.getInstance("SSL");
sc.init(null, TrustAll.trustAllCerts(), new
java.security.SecureRandom());
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return sc.getSocketFactory();
}
}
_______________________________________________
dev-tech-js-engine-rhino mailing list
dev-tech-js-engine-rhino@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino