Java Exception when trying to proxy HTTPS

2,757 views
Skip to first unread message

Richard Corcoran

unread,
Feb 16, 2012, 3:35:06 AM2/16/12
to BrowserMob Proxy
Hi,

When I use the proxy just for HTTP it works perfectly, however when
used for HTTPS this exception is thrown:

INFO 02/16 08:22:29 o.b.p.h.BrowserMobH~ -
java.lang.ClassCastException: java.net.Socket cannot be cast to
javax.net.ssl.SSLSocket when requesting https://...

I am using version 2.0-beta-5 with Java version 1.6.0_30. Is there
something I am missing?

Thanks,
Richard.

Niharika_Neo

unread,
Feb 17, 2012, 1:52:51 AM2/17/12
to BrowserMob Proxy
M too facing the same issue...

I am just trying to use the beta-5 for the first time. Added it in
the maven dependencies.
When I run the sample code from the readme, I get the following :

- Version Jetty/5.1.x
- Started HttpContext[/,/]
- Started SocketListener on 0.0.0.0:9093
- Started org.browsermob.proxy.jetty.jetty.Server@12bcd4b
.
.
.
java.lang.NoSuchFieldError: BasicConstraints
at
org.browsermob.proxy.selenium.CertificateCreator.generateStdSSLServerCertificate(CertificateCreator.java:
147)
at
org.browsermob.proxy.selenium.KeyStoreManager.getMappedCertificateForHostname(KeyStoreManager.java:
552)
at
org.browsermob.proxy.selenium.KeyStoreManager.getCertificateByHostname(KeyStoreManager.java:
389)
at
org.browsermob.proxy.selenium.SeleniumProxyHandler.wireUpSslWithCyberVilliansCA(SeleniumProxyHandler.java:
583)
at
org.browsermob.proxy.BrowserMobProxyHandler.wireUpSslWithCyberVilliansCA(BrowserMobProxyHandler.java:
92)
at
org.browsermob.proxy.selenium.SeleniumProxyHandler.getSslRelayOrCreateNew(SeleniumProxyHandler.java:
518)
at
org.browsermob.proxy.BrowserMobProxyHandler.getSslRelayOrCreateNew(BrowserMobProxyHandler.java:
97)
at
org.browsermob.proxy.selenium.SeleniumProxyHandler.handleConnect(SeleniumProxyHandler.java:
466)
at
org.browsermob.proxy.BrowserMobProxyHandler.handleConnect(BrowserMobProxyHandler.java:
76)
at
org.browsermob.proxy.selenium.SeleniumProxyHandler.handle(SeleniumProxyHandler.java:
158)
at
org.browsermob.proxy.jetty.http.HttpContext.handle(HttpContext.java:
1509)
at
org.browsermob.proxy.jetty.http.HttpContext.handle(HttpContext.java:
1461)
at org.browsermob.proxy.jetty.http.HttpServer.service(HttpServer.java:
892)
at
org.browsermob.proxy.jetty.http.HttpConnection.service(HttpConnection.java:
815)
at
org.browsermob.proxy.jetty.http.HttpConnection.handleNext(HttpConnection.java:
981)
at
org.browsermob.proxy.jetty.http.HttpConnection.handle(HttpConnection.java:
832)
at
org.browsermob.proxy.jetty.http.SocketListener.handleConnection(SocketListener.java:
245)
at
org.browsermob.proxy.jetty.util.ThreadedServer.handle(ThreadedServer.java:
357)
at org.browsermob.proxy.jetty.util.ThreadPool
$PoolThread.run(ThreadPool.java:534)

So I tried starting the proxy manually and opening up a site..the log
that i see in the proxy is

INFO 02/16 13:13:26 o.b.p.h.BrowserMobH~ -
java.lang.ClassCastException: java.ne
t.Socket cannot be cast to javax.net.ssl.SSLSocket when requesting
https://www.abc,.

Both things work with http site..any workaround?

Regards,
Niharika


On Feb 16, 1:35 pm, Richard Corcoran <richard.corco...@spilgames.com>
wrote:

Patrick Lightbody

unread,
Mar 1, 2012, 2:41:14 AM3/1/12
to browserm...@googlegroups.com
This might be a bug in the beta 5 release. I'll check in to it.

--
Patrick Lightbody



Marc

unread,
Mar 7, 2012, 8:54:50 AM3/7/12
to BrowserMob Proxy
The BasicConstraints error started showing up for us when we upgraded
to selenium-server-standalone-2.20.0.jar. We did not see the error in
previous versions of Selenium. I am guessing this is due to
WebDriver updating to the latest version of BouncyCastle. See
http://code.google.com/p/selenium/source/detail?r=15993.

-Marc

James Lukensow

unread,
Mar 8, 2012, 2:32:11 AM3/8/12
to browserm...@googlegroups.com
Did you ever find an update on this?

Simonz

unread,
Mar 9, 2012, 2:31:15 AM3/9/12
to BrowserMob Proxy
> > When I use the proxy just for HTTP it works perfectly, however when
> > used for HTTPS this exception is thrown:
>
> > INFO 02/16 08:22:29 o.b.p.h.BrowserMobH~ -
> > java.lang.ClassCastException: java.net.Socket cannot be cast to
> > javax.net.ssl.SSLSocket when requesting https://...

Fwiw, I'm seeing this as well. It's pretty strange because I can
stop browser-mob in the debugger at the point where it calls
"this.socketfactory.createSocket()" (inside apache httpclient
SSLSocketFactory) and I can see it is using a
javax.net.ssl.SSLSocketFactory and I can even invoke that call myself
using the debugger while it is stopped at the breakpoint and get back
SSLSocket instances, but when it actually runs it gets back plain old
java.net.Socket.

Simon

Simonz

unread,
Mar 9, 2012, 2:47:01 AM3/9/12
to BrowserMob Proxy
Hello all,

On Mar 9, 6:31 pm, Simonz <ssade...@gmail.com> wrote:
> > > When I use the proxy just for HTTP it works perfectly, however when
> > > used for HTTPS this exception is thrown:
>
> > > INFO 02/16 08:22:29 o.b.p.h.BrowserMobH~ -
> > > java.lang.ClassCastException: java.net.Socket cannot be cast to
> > > javax.net.ssl.SSLSocket when requesting https://...
>
> Fwiw,  I'm seeing this as well.

Sorry to reply to myself ... but I thought I would update that for me
updating to HttpClient 4.1.3 seems to have fixed it. Or more
precisely, I downloaded the source tarball for HttpClient 4.1.3,
compiled it myself and replaced the httpclient jar file. So I don't
know if it was compiling it myself or updating the version, but one
way or another it works now ...

Cheers,

Simon

niharika varshney

unread,
Mar 9, 2012, 5:42:14 AM3/9/12
to browserm...@googlegroups.com
Works by adding dependency to 4.1.3!!
Thanks for the workaround!

Regards,
Niharika

Patrick Lightbody

unread,
Mar 10, 2012, 8:36:12 PM3/10/12
to browserm...@googlegroups.com
Thanks everyone for bringing my attention to this. I just updated the dependencies and confirmed SSL is working fine now in the last source code. I'll probably do a release sometime this week.

--
Patrick Lightbody




Marc

unread,
Mar 13, 2012, 9:25:17 AM3/13/12
to BrowserMob Proxy
We are still seeing the BasicConstraints issue when we use Selenium-
Server-Standalone-2.20 with beta 6. Attached is a test case and build
file demonstrating the problem.

import org.browsermob.proxy.ProxyServer;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.remote.DesiredCapabilities;


public class BasicConstraintsErrorTest {

private WebDriver driver;
private ProxyServer proxyServer;

@Before
public void setUp() throws Exception{
proxyServer = new ProxyServer(45454);
proxyServer.start();
Proxy proxy = proxyServer.seleniumProxy();

FirefoxProfile profile = new FirefoxProfile();
profile.setProxyPreferences(proxy);

DesiredCapabilities caps = DesiredCapabilities.firefox();
caps.setCapability(FirefoxDriver.PROFILE, profile);

driver = new FirefoxDriver(caps);


}

@After
public void teadDown() throws Exception{
driver.quit();
proxyServer.stop();

}

@Test
public void test(){

driver.get("https://www.gmail.com");

}



}



<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- WARNING: Eclipse auto-generated file.
Any modifications will be overwritten.
To include a user specific buildfile here, simply create
one in the same
directory with the processing instruction <?
eclipse.ant.import?>
as the first entry and export the buildfile again. -->
<project basedir="." default="build" name="BrowserMob-Bug">
<property environment="env"/>
<property name="junit.output.dir" value="junit"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.6"/>
<property name="source" value="1.6"/>
<path id="BrowserMob-Bug.classpath">
<pathelement location="bin"/>
<pathelement location="libs/browsermob-proxy-2.0-beta-6.jar"/>
<pathelement location="libs/jackson-core-asl-1.7.1.jar"/>
<pathelement location="libs/jackson-mapper-asl-1.7.1.jar"/>
<pathelement location="libs/jetty-util-7.3.0.v20110203.jar"/>
<pathelement location="libs/selenium-server-
standalone-2.20.0.jar"/>
<pathelement location="libs/hamcrest-all-1.1.jar"/>
<pathelement location="libs/junit-4.10.jar"/>
</path>
<target name="init">
<mkdir dir="bin"/>
<copy includeemptydirs="false" todir="bin">
<fileset dir="src">
<exclude name="**/*.launch"/>
<exclude name="**/*.uad"/>
<exclude name="**/*.ucd"/>
<exclude name="**/*.uld"/>
<exclude name="**/*.upd"/>
<exclude name="**/*.udd"/>
<exclude name="**/*.uod"/>
<exclude name="**/*.usd"/>
<exclude name="**/*.utd"/>
<exclude name="**/*.uud"/>
<exclude name="**/*.odd"/>
<exclude name="**/*.ead"/>
<exclude name="**/*.ecd"/>
<exclude name="**/*.eld"/>
<exclude name="**/*.epd"/>
<exclude name="**/*.edd"/>
<exclude name="**/*.eod"/>
<exclude name="**/*.esd"/>
<exclude name="**/*.etd"/>
<exclude name="**/*.eud"/>
<exclude name="**/*.urd"/>
<exclude name="**/*.uml"/>
<exclude name="**/*.ecore"/>
<exclude name="**/*.ucls"/>
<exclude name="**/*.useq"/>
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="bin"/>
</target>
<target depends="clean" name="cleanall"/>
<target depends="build-subprojects,build-project" name="build"/>
<target name="build-subprojects"/>
<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true" debuglevel="${debuglevel}" destdir="bin"
source="${source}" target="${target}">
<src path="src"/>
<classpath refid="BrowserMob-Bug.classpath"/>
</javac>
</target>
<target description="Build all projects which reference this
project. Useful to propagate changes." name="build-refprojects"/>
<target name="test" depends="build">
<mkdir dir="${junit.output.dir}"/>
<junit fork="yes" printsummary="withOutAndErr">
<formatter type="xml"/>
<test name="BasicConstraintsErrorTest" todir="$
{junit.output.dir}"/>
<jvmarg line="-ea"/>
<classpath refid="BrowserMob-Bug.classpath"/>
</junit>
</target>
<target name="junitreport">
<junitreport todir="${junit.output.dir}">
<fileset dir="${junit.output.dir}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${junit.output.dir}"/>
</junitreport>
</target>
</project>



If we use selenium-java 2.20 and include all the dependent jars, we do
not see the error.

Thanks,

-Marc

On Mar 10, 9:36 pm, Patrick Lightbody <patr...@lightbody.net> wrote:
> Thanks everyone for bringing my attention to this. I just updated the dependencies and confirmed SSL is working fine now in the last source code. I'll probably do a release sometime this week.
>
> --
> Patrick Lightbody
> +1 (415) 830-5488
>
> On Mar 9, 2012, at 2:42 AM, niharika varshney wrote:
>
>
>
>
>
>
>
> > Works by adding dependency to 4.1.3!!
> > Thanks for the workaround!
>
> > Regards,
> > Niharika
>

Patrick Lightbody

unread,
Mar 23, 2012, 1:23:14 AM3/23/12
to browserm...@googlegroups.com
Marc,
I ran the test and don't see the error you're talking about. It passes successfully for me and this is what the logs show:

INFO 03/23 05:19:15 o.b.p.j.h.HttpServer - Version Jetty/5.1.x
INFO 03/23 05:19:15 o.b.p.j.u.Container - Started HttpContext[/,/]
INFO 03/23 05:19:15 o.b.p.j.h.SocketLis~ - Started SocketListener on 0.0.0.0:45454
INFO 03/23 05:19:15 o.b.p.j.u.Container - Started org.browsermob.proxy.jetty.jetty.Server@ee51b2c
INFO 03/23 05:19:31 o.b.p.j.u.Credential - Checking Resource aliases
INFO 03/23 05:19:32 o.b.p.j.h.SocketLis~ - Started SocketListener on 0.0.0.0:59703
INFO 03/23 05:19:33 o.b.p.j.h.SocketLis~ - Started SocketListener on 0.0.0.0:59707
INFO 03/23 05:19:34 o.b.p.j.h.SocketLis~ - Started SocketListener on 0.0.0.0:59711
INFO 03/23 05:19:35 o.b.p.j.h.SocketLis~ - Started SocketListener on 0.0.0.0:59721
INFO 03/23 05:19:36 o.b.p.j.h.SocketLis~ - Started SocketListener on 0.0.0.0:59723
INFO 03/23 05:19:36 o.b.p.j.h.SocketLis~ - Started SocketListener on 0.0.0.0:59725
INFO 03/23 05:19:40 o.b.p.j.u.ThreadedS~ - Stopping Acceptor [SSL: ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=59721]]
INFO 03/23 05:19:40 o.b.p.j.h.SocketLis~ - Stopped SocketListener on 0.0.0.0:59721
INFO 03/23 05:19:40 o.b.p.j.u.ThreadedS~ - Stopping Acceptor [SSL: ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=59707]]
INFO 03/23 05:19:40 o.b.p.j.h.SocketLis~ - Stopped SocketListener on 0.0.0.0:59707
INFO 03/23 05:19:40 o.b.p.j.u.ThreadedS~ - Stopping Acceptor [SSL: ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=59711]]
INFO 03/23 05:19:40 o.b.p.j.h.SocketLis~ - Stopped SocketListener on 0.0.0.0:59711
INFO 03/23 05:19:40 o.b.p.j.u.ThreadedS~ - Stopping Acceptor [SSL: ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=59725]]
INFO 03/23 05:19:40 o.b.p.j.h.SocketLis~ - Stopped SocketListener on 0.0.0.0:59725
INFO 03/23 05:19:40 o.b.p.j.u.ThreadedS~ - Stopping Acceptor [SSL: ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=59723]]
INFO 03/23 05:19:40 o.b.p.j.h.SocketLis~ - Stopped SocketListener on 0.0.0.0:59723
INFO 03/23 05:19:40 o.b.p.j.u.ThreadedS~ - Stopping Acceptor [SSL: ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=59703]]
INFO 03/23 05:19:40 o.b.p.j.h.SocketLis~ - Stopped SocketListener on 0.0.0.0:59703
INFO 03/23 05:19:40 o.b.p.j.u.ThreadedS~ - Stopping Acceptor ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=45454]
INFO 03/23 05:19:40 o.b.p.j.h.SocketLis~ - Stopped SocketListener on 0.0.0.0:45454
INFO 03/23 05:19:41 o.b.p.j.u.Container - Stopped HttpContext[/,/]
INFO 03/23 05:19:41 o.b.p.j.u.Container - Stopped org.browsermob.proxy.jetty.jetty.Server@ee51b2c

I guess what you're saying is the difference is between selenium-server-standalone vs just selenium-firefox-driver + dependencies is causing the issue? If so, it might just not be something we support. The selenium-server-standalone jar is one of those "jar of jars" packages that can cause strange classpath issues sometimes. I generally avoid those kinds of uberjars unless I'm running it as a standalone process. But mixing it with other libraries can produce unexpected results.

Patrick

--
Patrick Lightbody
+1 (415) 830-5488

Marc Holden

unread,
Mar 23, 2012, 7:35:16 AM3/23/12
to browserm...@googlegroups.com
Thanks for trying to reproduce.  Using the standalone jar was done out of convenience (laziness...).  All the projects which use BMP have been moved to normal selenium-java.jar.  

Thanks again,

-Marc
Reply all
Reply to author
Forward
0 new messages