Proxy authentication doesn't work with JSSE

Hello,
Seems like there is no common way to authenticate with proxy for HTTP and HTTPS.
Connecting to http://... - works fine, but https://... returns error message:
Unable to tunnel through 111.111.111.111:8080. Proxy returns "HTTP/1.0 407 Proxy Authentication Required"
(IP address is intentionally changed in the message above)
I'm using JSSE with VAJ JDK 1.2 and here is a Java code snippet that works well with HTTP connections:
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
System.setProperty("java.protocol.handler.pkgs",
"com.sun.net.ssl.internal.www.protocol");
System.setProperty("https.proxyHost", proxyHost);
System.setProperty("https.proxyPort", proxyPort);
System.setProperty("http.proxyHost", proxyHost);
System.setProperty("http.proxyPort", proxyPort);
try {
URL url = new URL("https://www.sun.com");
URLConnection connection = url.openConnection();
String authString = proxyUserID + ":" + proxyPasswd;
String encodedAuthString =
"Basic " + new sun.misc.BASE64Encoder().encode(authString.getBytes());
connection.setUseCaches(false);
connection.setRequestProperty("Proxy-authorization", encodedAuthString);
Listening to the network traffic helped me to understand that there is a difference between the way HTTP and HTTPS is handled. For some reason HTTPS ignores all the headers that I specify using setRequestProperty().
Here is example of request and responses sent by HTTPS handler:
Request:
CONNECT 198.175.98.32:443 HTTP/1.0
User-Agent: JSSE
Proxy response:
HTTP/1.0 407 Proxy Authentication Required
Date: Wed, 07 Nov 2001 22:04:11 GMT
Content-Length: 233
Content-Type: text/html
Server: NetCache (NetApp/5.1R2D4)
Proxy-Authenticate: basic realm="NETCACHE2"
Please note that there is no Proxy-authorization header in the request above.
Compare it with HTTPS request sent by Netscape browser:
Request to proxy:
CONNECT www.sun.com:443 HTTP/1.0
Proxy-authorization: Basic am0vbDphrGxHa22lLg==
User-Agent: Mozilla/4.76 [en] (Windows NT 5.0; U)
Response:
HTTP/1.0 200 Connection established
Proxy-Agent: NetCache NetApp/5.1R2D4
So, the question is:
What is the best way to pass "Proxy-authorization" header to proxy server??
Thanks in advance for your time.

Hi Guys,
Just like, i assume, all of you, i've had my battles with javas' handling of https comms from behind a firewall. I'm actually amazed at how something that is a simple combination of protocol and security should become so messy.
Luckily , i managed to get all my requirements met, but the sad thing is after all that hard work, i'm not much closer to understanding why the standard java sdk (im using 1.4) forces us to endure such painful tasks.
Really, Java is quite a mature language now, and one of its touted benefits is its applicability to web and internet technologies... so why the messy proxy code when dealing with ssl?
Anyway, i didn't really come here to b**tch, but rather to point you all to a handy library from apache - httpClient - http://jakarta.apache.org/commons/httpclient.
After implementing ssl proxy tunnelling and all the fun that goes with it, i found this tool, and subsequently deleted all that ugly code, and let http client deal with all that for me.
Its seriously simple, heres a snippet:
httpClient = new HttpClient();
httpClient.setTimeout(responseTimeoutMillies);
Protocol myHttps = new Protocol("https", new SSLContextBasedSocketFactory(sslContext), targetServerPort);
httpClient.getHostConfiguration().setHost(targetServerHost, targetServerPort, myHttps);
if (useProxy)
     httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort);
        httpClient.getState().setProxyCredentials("my-proxy-realm", proxyHost, new UsernamePasswordCredentials(proxyUser, proxyPassword));
}This initialises the client, and after this, making http requests is simple:
String response = null;
PostMethod postMethod = new PostMethod("/secure/blah.jsp"); // A HTTP Post
postMethod.setRequestBody("Hello there"); // this is the data in the http post body
int responseCode = httpClient.executeMethod(postMethod);
if(responseCode == 200)
    response = postMethod.getResponseBody();...
As you can see, its alot less painful. It certainly makes me feel better, knowing i don't have to support/maintain the ugly proxy tunnelling code. Give it a shot on your next project.
Hope it helps.
Regards
Marcus Eaton

Similar Messages

  • Proxy authorization doesn't work with JSSE 1.02

    Hello,
    Seems like there is no common way to authenticate with proxy for HTTP and HTTPS.
    Connecting to http://... - works fine, but https://... returns error message:
    Unable to tunnel through 111.111.111.111:8080. Proxy returns "HTTP/1.0 407 Proxy Authentication Required"
    (IP address is intentionally changed in the message above)
    I'm using JSSE with VAJ JDK 1.2 and here is a Java code snippet that works well with HTTP connections:
         Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
         System.setProperty("java.protocol.handler.pkgs",
              "com.sun.net.ssl.internal.www.protocol");
         System.setProperty("https.proxyHost", proxyHost);
         System.setProperty("https.proxyPort", proxyPort);
         System.setProperty("http.proxyHost", proxyHost);
         System.setProperty("http.proxyPort", proxyPort);
         try {
              URL url = new URL("https://www.sun.com");
              URLConnection connection = url.openConnection();
              String authString = proxyUserID + ":" + proxyPasswd;
              String encodedAuthString =
                   "Basic " + new sun.misc.BASE64Encoder().encode(authString.getBytes());
              connection.setUseCaches(false);
              connection.setRequestProperty("Proxy-authorization", encodedAuthString);
    Listening to the network traffic helped me to understand that there is a difference between the way HTTP and HTTPS is handled. For some reason HTTPS ignores all the headers that I specify using setRequestProperty().
    Here is example of request and responses sent by HTTPS handler:
    Request:
    CONNECT 198.175.98.32:443 HTTP/1.0
    User-Agent: JSSE
    Proxy response:
    HTTP/1.0 407 Proxy Authentication Required
    Date: Wed, 07 Nov 2001 22:04:11 GMT
    Content-Length: 233
    Content-Type: text/html
    Server: NetCache (NetApp/5.1R2D4)
    Proxy-Authenticate: basic realm="NETCACHE2"
    Please note that there is no Proxy-authorization header in the request above.
    Compare it with HTTPS request sent by Netscape browser:
    Request to proxy:
    CONNECT www.sun.com:443 HTTP/1.0
    Proxy-authorization: Basic am0vbDphrGxHa22lLg==
    User-Agent: Mozilla/4.76 [en] (Windows NT 5.0; U)
    Response:
    HTTP/1.0 200 Connection established
    Proxy-Agent: NetCache NetApp/5.1R2D4
    So, the question is:
    What is the best way to pass "Proxy-authorization" header to proxy server??
    Thanks in advance for your time.

    Hi, I am also facing same problem
    Software : Weblogic jdk1.3.1
    If anyone know the solution ,Please help me
    Thanks,
    Suneel

  • Working with JSSE using multi-purpose keystore

    Hello,
    I am currently working on an application which employs the JCA for providing signatures, authenticating users etc., but also working with JSSE.
    More specifically: The application must be able to verify signatures on code packages created by known users and loaded at runtime; but for communication with other parts of the application, it shall use SSL connections.
    Now I worked through the JSSE manuals and I was able to set up a simple SSL application with client and server, using all the getDefaults() I could get a hold on.
    In the final application that I am working on, I will have a keystore with quite a lot of keys from users, public and possibly private ones, and also a key for the SSL communication. I have the strong feeling that I will not see many getDefault()s anymore.
    My problem is that by looking at the API, I don't have any clue how to tell the JSSE which key to use for the SSL connection from the keystore holding possibly many keys of users.
    Moreover, how do I pass the passphrase for unlocking the private key to the JSSE if it is not equal to the keystore password? (Which, by the way, seems to me to require passing via the command line - argh!)
    Help would be greatly appreciated.
    Michael

    I've got it.
    The secret is to create an own X509KeyManager. This key manager gets its keys from the keystore, so I have the chance to provide an alias which is intended to be used for SSL and to provide the key password.
    public class SpecialX509KeyManager implements X509KeyManager {
    public SpecialX509KeyManager(KeyStore keys, String sSSLAlias, String sPassword) {
    // browse the keystore,
    // get the key which has the given alias - and only this one -
    // and use the password to decrypt it
    // keep the key and its certificate chain
    The keystore must be loaded before, using the keystore password:
    KeyStore keys = KeyStore.getInstance("JKS");
    keys.load(new FileInputStream("server.ks"), "keystorepw".toCharArray());
    KeyManager[] akm = new KeyManager[1];
    akm[0] = new SpecialX509KeyManager(keys, "ssl", "ssl012");
    SSLContext sc = SSLContext.getInstance("TLS");
    sc.init(akm, null, null);
    SSLServerSocketFactory sslSrvFact = sc.getServerSocketFactory();
    That is, I have a keystore, using the password "keystorepw", containing keys with one using the alias "ssl" and the password "ssl012".
    Michael

  • I use an online application that doesn't work with FF, but I had been able to use an IE plugin within FF and it worked fine. After the last update (3.6.12), it says plugin is not compatable with version. Help?

    I use an online application that doesn't work with FF, but I had been able to use an IE plugin within FF and it worked fine. After the last update (3.6.12), it says plugin is not compatable with version. Help

    go to '''TOOLS '''then '''OPTIONS''' then '''ADVANCED''' then '''NETWORK tab''' then '''SETTINGS tab''' and select the options '''NO PROXY''' click '''OK''' and '''OK '''again in the next screen. With that you have disabled the proxy settings.
    ''if you like to not disable the proxy settings choose'' : '''Auto-detect proxy settings for this network''' (it is in the same session)
    thank you
    Please mark "Solved" the answer that really solve the problem, to help others with a similar problem.

  • Trying to load illustrator 6cs onto new mac and the old activation code for my ill cs doesn't work with it

    Trying to load a downloaded version of illustrator 6cs onto new mac and the old activation code for my illustrator cs doesn't work with it.  Do I need a new code or am I missing something?  Same goes for my Photoshop cs.

    you need your serial number.
    if you purchased from or registered with adobe check your account, https://www.adobe.com/account.html

  • Cinema Display (clear) with DVI/ADC box doesn't work with MacBook Pro

    Cinema Display (clear) with DVI/ADC box doesn't work with MacBook Pro when plugged in with a dvi to mini dvi cable. Any ideas what to do to make it work? I lugged the 23" 2500 miles into the wilderness and I need help

    Okay, here's an update: the DVI to ADC adapter does work with the Apple displays that I have tried, but it won't work with the Formac. I have tried multiple time to contact them, but to no avail... they don't even respond to threats of posting my opinion of them, which is this:
    DON'T BUY ANYTHING FROM FORMAC! They make quality products, but their customer service is a big time joke! They won't take care of you.

  • HT201210 hi everyone, i have a problem about my iphone 4S, doesn't work with wifi connection and bluetooth since upgrade to the IOS 7.0.3. Can anyone can help me tosolve this problem?????Thank's regards paulus

    hi everyone, i have a problem about my iphone 4S, doesn't work with wifi connection and bluetooth since upgrade to the IOS 7.0.3. Can anyone can help me tosolve this problem?????Thank's regards paulus

    Try the suggestions here to see if they resolve your problem:
    http://support.apple.com/kb/ts1559
    If these don't work you may have a hardware problem. Visit an Apple store for an evaluation or contact Apple Support.

  • TS1253 I have a printer epson TX210, but it doesn't work with my time-capsule. What need to do?

    I have a printer epson TX210, but it doesn't work with my time-capsule. What need to do?

    What have you tried?
    You are going to get nowhere quick with the 6.1 utility in Mountain Lion if this is the only OS you have available.
    Look up how to install 5.6 utility under ML. At least then you can see printers. That is assuming you are trying to use USB.
    Has this worked ever on Mountain Lion? Did you download the drivers for that printer for ML?
    Plug it into a computer directly.. does it work? If it doesn't work locally it sure will not work via the network.

  • My i pod nano first generation doesn't work with windows 8

    My i pod nano first generation doesn't work with windows 8

    Howdy yvesmd,
    Thanks for using the Apple Support Communities.
    If your iPod nano is not being recognized in iTunes on your Windows computer, then I'd like you to please follow the directions in the link below.
    Apple - Support - iPod - iPod nano Troubleshooting
    Cheers,
    Alex H.

  • Quicklook doesn't work with .avi files

    Hello, i've got a little problem right here on my mac. The thing is that I used to have Snow Leopard as a OS and quicklook used to work great, it opened all the extensions I used to work with. The thing change when I format my HDD and installed a clean copy of Lion OS. Now quicklook works fine as it used to but not any more with .avi files. I remember that this feature was working great on my previous OS, and it's really important for me to find a solution because quicklook is an absolutely amazing feature of our Macs.
    I've tryed to download plugins, restoring permissions or even trying it with a guest user, but no success.
    Please help me. If you need more info about specs or something i'll be glad to give them to you.
    Thank you!!!

    Also doesn't work with Grapher (.gcx) documents (an Apple format).

  • The Bluetooth on my 2012 Lexus doesn't work with my iPhone 5.  My old android phone worked perfectly with my car.  Even the tech guy at Lexus couldn't get it to work.  What is apple doing to fix this.

    The Bluetooth on my 2012 Lexus doesn't work with my iPhone 5.  My old android worked perfectly with my car.  Even the tech specialist at Lexus couldn't get it to work.  Lexus said that other iPhone 5s were having the same problem.  What is apple doing to fix this?

    Going to the local Apple store this morning...
    My problem is not uncommon as the board is showing signs of this happening to many others as well. That is where I found the restore and reboot information to try to solve the issue of crashing apps.
    I understand that Apple will not "give away the cow", but letting iPhone users know that the problems they are having are being addressed by Apple is a little more comforting than nothing at all. Other wise, all the apps in world are useless and even more importantly worthless, if a person has to reset/reboot/reload just to get them to work.
    IF Apple can not address the basic problems with todays iPhone apps, why should one believe that the iPhone 3.0 OS is any better? Using a PC comparison, which is better, XP or Vista. If the current iPhone OS of 2.2. what ever is not working that well (as related to down loaded apps and iTunes), will OS 3.0 be any better?
    The waste of time I refer to is in going to the apps store and downloading the apps... Again why by apps if the free version does not work?

  • Satellite M40-129: PCMCIA Card doesn't work with Linux

    I have D-Link DWL-G650 with Atheros Chipset which is good supported under linux (madwifi). But if I boot Linux the card is not found. I tested the card with an Fujitsu Siemens Notebook and it worked out of the box!
    Any idea why it doesn't work with my M40-129 ?

    Hi
    Like you know Toshiba doesnt support the Linux and there are no Toshiba drivers for the Linux OS but I was able to find this useful Toshiba page about the notebook configuration with Linux:
    http://newsletter.toshiba-tro.de/main/
    You should check the OS machine compatibility and the other areas.
    Im sure you will find many useful tips.
    Good luck

  • HT5706 I am trying to set up Apple TV with my Uverse WiFi, but I get errors when entering my password.  One site said that Apple TV doesn't work with WPA which Uverse uses.  Is there anyway around this or will Uverse and Apple TV just not work together.

    Trying to set up Apple TV with ATT Uverse.  I get errors when trying to enter my WiFi password.  One site says that Apple TV doesn't work with Uverse because it uses WPA for encryption.  If true, does that mean Uverse subscribers cannot use Apple TV?

    Spurs63 wrote:
    does that mean Uverse subscribers cannot use Apple TV?
    No, that's a rather silly conclusion.
    There are two options:
    stop using the crappy router provided by the ISP.
    Physically connect the ATV to the router via Ethernet.

  • My cellcom line doesn't work with my iPhone here in Israel, why? Is there any way I can solve this issue?

    My cellcom line doesn't work with my iPhone here in Israel, why? Is there any way I can solve this issue?

    Please explain.
    What does "cellcom line doesn't work with my iPhone" mean?
    What are you trying?  What is happening?
    Where did you buy the iphone?
    Any info abnout your issue at all?

  • Media Encoder CS4 doesn't work with Premiere (pic related)

    Oh hai!
    I just got Adobe Master Collection CS4 and my Media Encoder doesn't work with Premiere CS4. When I try to export the file, Encoder starts normally. Then I click "Start queue" and Encoder starts loading. Loading takes almost five minutes, which is a long time, because my project is very simple. After that nothing happens, just a warning sign appears. When I click it open, some kind of log file open and it says:
    Encoding failed
    Could not read from the source. Please check if it has moved or been deleted.
    And I didn't deleted anything. So what does that mean? Why that "Source Name's" path is different than my project files path? Can this problem relate that somehow?
    I have also another problem with Premiere CS4, maybe there's a link between these two problems. I can't get Premiere projects linked to open in Premiere CS4. When I right-click the project icon, and click “Open with…”, I can't find Premiere from the list. When I click "Browse", I can find Premiere.exe from my computer, but if i doubel-clicked it, nothing happens. It won't appear to the list or anywhere else. Or have I missed something? So now the project files are linked to open in After Effects. Of course I can open projects from Premiere, but how do I get them open straight from file?
    I have long experience using Adobe Premiere and this is the first time I got this kind of problems. I have also downloaded new updates for Premiere and Encoder, this didn't help. Does that matter, that I didn't installed Premiere in C-drive? However it's in my computers internal drive, I have divided my hard drive for five parts, one part contains all of my softwares. My scratch disks are in different hard drive (external), does that matter? I tried different location, but that didn't help.
    Please help, I can't do any video editing, because of this problem. And sorry for my english, ask if you didn't understand something. =)

    Hello, this is terrible problem, which i found in CS 6 softwares ...
    solution i found only working, is uninstall and reinstall full package.. but it is not all,
    you need to do BRAND NEW admin account in windows, and install it there.
    that means, i could not export after repair from encoder in my original account never more (!!)   .. this is really terrible way how to repair this issue, because :
    1.by reinstalling of software, client WASTE HIS TIME
    2.by necessity to begin work in another windows profile you again WASTE YOUR TIME because of learning and migrating all other profile modifications, which i see really unaccpetable. Adobe means, this solution of repair is ok, and they did not do till today any steps of creating some "clever" solution.
    I ask everybody, who will meet this issue in future, guys, please, complain about this situation, give "BUG Report" to them, and write "feature request" to them , in the way of creating some repair tool, which check actual  "broken" connections between encoder and premiere, which refuses to "take material" from it and encode, and REPAIR it automatically..  
       I am not IT, but ..does it seems so hard to create this ? Adobe IT developers should know their systems, and should create such utility tool really easy.
    History of this problem and detailed description, HOW i did "repair" this. With wasting of app 2,5 days of my working time :
    1. after repairing "error 5" problem , i solved it by reinstalling the suite from the new admin user profile (profile B) . 
    I continued my work on my normal working windows profile . (profile A)
    Every cooperation (AE+Pr, export media via "queue" to Encoder) was working fine . . .
    2. suddenly it stop working (without knowing any possible reason - i did not do installations )
    and showed in error export log file :
    "Could not read from the source. Please check if it has moved or been deleted."
    3.repair via procedure(procedure "a"):
    i did this procedure on the profile B (profile from last time installation of repairing problem error 5)
    I did these steps :
    a-uninstall master coll suite
    b-i used Adobe cleaner tool (remove ALL)
    c-removed raw directories in locations
    •C:\Program Files\Adobe
    •C:\Program Files(x86)\Adobe
    •C:\Program Files\Common Files\Adobe
    •C:\Program Files(x86)\Common Files\Adobe
    •C:\ProgramData\Adobe
    d-removed these links from registry file
    •HKEY_LOCAL_MACHINE\SOFTWARE\Adobe
    •HKEY_CURRENT_USER\Software\Adobe
    •HKEY_LOCAL_MACH INE\SOFTWARE\Wow6432Node\Adobe
    •HKEY_CURRENT_USER \Software\Wow6432Node\Adobe
    e-restarted the PC
    f- newly installed the Master Coll CS6
    g-update the software
    result of repair of "3" : problem still exists
    4.Ok i find out after coordination with support, it should have been created  ANOTHER NEW admin account.
    4a:so i did the same procedure (uninstalling) in profile B
    4b: and then i created brand new admin profile (profile C)for INSTALLATION of software
    4c: restarted the pc (and did not updated it yet)
    result :
    ==exporting of any sequence/raw/AE link video material from premiere via "queue" (Encoder) (profile C) : export WORKS
    ==exporting of any sequence/raw/AE link video material from premiere via "queue" (Encoder) (profile B) : export WORKS
    ==exporting of any sequence/raw/AE link video material from premiere via "queue" (Encoder) (profile A) : export DOES NOT WORK ! ! !
    (in profile A, is possible to export some raw video material in encoder which is imported to it via "drag and drop)
    problem i see:, i have my basic profile A, which i am interested to work, because of all my directory modifications are in there..
    this issue should be some "broken" connections between encoder and premiere, which refuses to "take material" from it and encode.
    what i expect :
    to get from Adobe some repair tool, which automatically checks these connections and repair if necessary, without necessity of founding the new profile and reinstallation of whole software.. this is madness !
    what i do NOT expect from Adobe:
    to get from Adobe advice of kind : you have to reinstall full software in new admin profile. sorry , we do not know the solution, because we do not know, how do behave our software.

Maybe you are looking for

  • LC Process in SAP

    Dear All, any one can tell me in detail how LC process can run in SAP, like i know a little that PO should be IV based not GR-IV based. regards, qsm sap

  • Query related to Calling Zreport after Std ME21N Transaction

    Hi all, I m looking for the transaction or any way by which i can call my Zreport (having Purchase Order number as selection Criteria) After ME21N / ME22N / ME23N transaction. pls. note: i do not want to run my Zreport Explicitly. Regards, S Anand

  • Director 10.1.1

    I am trying to update to 10.1.1 from 10.1.0 in order to install swf files. With 10.1.0 I keep getting a 1 frame swf that doesn't play. Reading this forum I found that I may need 10.1.1 for Flash 8 files. This is the link I went to: 10.1.1updateAfter

  • Adobe Audition 3 Errors

    Hi When I started Adobe audition 3 today I encountered an error and on searching forums my problem is the same as described by others. The cut and paste below is from 2008, but same problems If you have advice Thankyou I don't know what caused this,

  • Problem using TaskService

    Hi, I'm trying to update a task programatically using taskservice. When I execute this lines: ITaskService taskSvc = this.getWorkflowServiceClient().getTaskService(); taskSvc.updateTask(this.getWorkflowContext(),task); I get the following stacktrace: