eclipse - how to Capture https with fiddler, in java -


i running following java program in eclipse ide:

import java.net.*; import java.io.*;   public class hh  {     public static void main(string[] args)throws exception     {       //if comment out system properties, , don't set jvm arguments, program runs , prints out html fine.             system.setproperty("http.proxyhost", "localhost");              system.setproperty("http.proxyport", "8888");              system.setproperty("https.proxyhost", "localhost");              system.setproperty("https.proxyport", "8888");               url x=new url("https://www.google.com");             httpurlconnection hc=(httpurlconnection)x.openconnection();              hc.setrequestproperty("user-agent","mozilla/5.0 (windows nt 6.0)             applewebkit/535.2 (khtml, gecko) chrome/15.0.874.121 safari/535.2");               inputstream is=hc.getinputstream();              int u=0;             byte[] kj=new byte[1024];             while((u=is.read(kj))!=-1)            {                 system.out.write(kj,0,u);             }            is.close();           }            } 

this produces following exception, if fiddler running, both while capturing, , not capturing:

exception in thread "main" javax.net.ssl.sslhandshakeexception: sun.security.validator.validatorexception: pkix path building failed: sun.security.provider.certpath.suncertpathbuilderexception: unable find valid certification path requested target     @ com.sun.net.ssl.internal.ssl.alerts.getsslexception(unknown source)     @ com.sun.net.ssl.internal.ssl.sslsocketimpl.fatal(unknown source)     @ com.sun.net.ssl.internal.ssl.handshaker.fatalse(unknown source)     @ com.sun.net.ssl.internal.ssl.handshaker.fatalse(unknown source)     @ com.sun.net.ssl.internal.ssl.clienthandshaker.servercertificate(unknown source)     @ com.sun.net.ssl.internal.ssl.clienthandshaker.processmessage(unknown source)     @ com.sun.net.ssl.internal.ssl.handshaker.processloop(unknown source)     @ com.sun.net.ssl.internal.ssl.handshaker.process_record(unknown source)     @ com.sun.net.ssl.internal.ssl.sslsocketimpl.readrecord(unknown source)     @ com.sun.net.ssl.internal.ssl.sslsocketimpl.performinitialhandshake(unknown ... 

if close fiddler, program runs fine without exceptions, producing html on url connecting to.

alternatively, if specify system.setproperty("https.proxyport", "443");, instead of: system.setproperty("https.proxyport", "8888");, runs , prints out html, without exceptions, while fiddler open, in capturing mode, there still no capturing fiddler @ all.

then if set these system properties through eclipse's jvm arguments like: -dproxyset=true -dproxyhost=127.0.0.1 -dproxyport=8888, same exact exception happens again, long fiddler app running, both in capturing , non capturing mode. if close fiddler, program run fine.

if use: system.setproperty("http.proxyhost", "127.0.0.1"); instead of: system.setproperty("http.proxyhost", "localhost");, runs fine fiddler application running, both cap-/non capturing mode, no captured traffic.

is out there, able capture own https traffic fiddler, not through web browser, through java program? jvm arguments, how set this? thanks

create keystore containing fiddler certificate. use keystore truststore jvm along proxy settings.

here's how that:

  • export fiddler's root certificate

tools -> fiddler options... -> https -> export root certificate desktop

  • create keystore certificate

open command line administrator (keytool doesn't work otherwise)

<jdk_home>\bin\keytool.exe -import -file c:\users\<username>\desktop\fiddlerroot.cer -keystore fiddlerkeystore -alias fiddler

enter password when prompted. should create file called fiddlerkeystore.

  • now start jvm fiddler proxy , keystore truststore. you'll need these vmargs:

-dproxyset=true

-dproxyhost=127.0.0.1

-dproxyport=8888

-djavax.net.ssl.truststore=<path\to\fiddlerkeystore>

-djavax.net.ssl.truststorepassword=<keystore password>

use these vmargs in eclipse run configuration , should go.

i'm able capture https requests made jvm without issues setup.


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -