Re: Changing the SSL socket factory for https:// URLs

"Wolfgang Fahl" <[email protected]> Tue, 18 Aug 2009 19:23:48 +0200
Newsgroups gmane.comp.web.httpunit.devel
Organization BITPlan GmbH
Message-ID <[email protected]>
Dear Florian,

I have just looked in the Subversion repository with the 
intention to add your changes.
Subversion revision 1038 
https://httpunit.svn.sourceforge.net/svnroot/httpunit/trunk/httpunit/src/com/meterware/httpunit/HttpsProtocolSupport.java

has some comparable changes to what you suggest. Your 
patch is based on revision 3326 which seems to be from 
CVS or another repository.

Could you please check whether the useProvider function 
in the code above does what you'd like to get?

The test cases for the above function are in
HttpsProtocolSupportTest

which were added in December 2007 (pre httpunit 1.7 ...)
http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=801


Please add a test to show your point in where your code 
is necessary.

Yours
  Wolfgang

To:             	[email protected]
From:           	Florian Weimer <[email protected]>
Date sent:      	Tue, 07 Jul 2009 16:17:44 +0000
Subject:        	[Httpunit-develop] Changing the SSL 
socket factory for https:// URLs
Send reply to:  	Discussion of use and development of 
HttpUnit
	<httpunit-
[email protected]>
	<httpunit-
develop.lists.sourceforge.net>
	<mailto:httpunit-develop-
[email protected]?subject=unsubscribe>
	<mailto:httpunit-develop-
[email protected]?subject=subscribe>

> I don't quite understand why httpunit defaults to an old collection of
> protocol handlers with a different inheritance hierarchy.
> 
> If I change the following line:
> 
> Index: src/com/meterware/httpunit/HttpsProtocolSupport.java
> ===================================================================
> --- src/com/meterware/httpunit/HttpsProtocolSupport.java	(revision 3326)
> +++ src/com/meterware/httpunit/HttpsProtocolSupport.java	(working copy)
> @@ -48,7 +48,7 @@
>      /** The name of the JSSE class which provides support for SSL. **/
>      private static String JSSE_PROVIDER_CLASS=SunJSSE_PROVIDER_CLASS;
>      /** The name of the JSSE class which supports the https protocol. **/
> -    private static String SSL_PROTOCOL_HANDLER   = SunSSL_PROTOCOL_HANDLER ;
> +    private static String SSL_PROTOCOL_HANDLER   = "sun.net.ssl.internal.www.protocol";
>  
>      private static Class _httpsProviderClass;
>  
> 
> the URLConnection object returned by URL#openConnection() is of the
> right type (a subclass of the public class
> javax.net.ssl.HttpsURLConnection), so that it's possible to apply the
> following patch to add a new client property which permits changing
> the SSL socket factory (thus providing a way to enable client-side
> certificates or to disable server certificate checking):
> 
> Index: src/com/meterware/httpunit/ClientProperties.java
> ===================================================================
> --- src/com/meterware/httpunit/ClientProperties.java	(revision 3326)
> +++ src/com/meterware/httpunit/ClientProperties.java	(working copy)
> @@ -1,4 +1,6 @@
>  package com.meterware.httpunit;
> +
> +import javax.net.ssl.SSLSocketFactory;
>  /********************************************************************************************************************
>   * $Id: ClientProperties.java 797 2007-12-28 15:16:07Z wolfgang_fahl $
>   *
> @@ -237,7 +239,6 @@
>          _dnsListener = dnsListener;
>      }
>  
> -
>      /**
>       * Returns the listener for DNS requests to be used by the client.
>       * @return the currently specified DNS listener, or null if none is specified.
> @@ -246,6 +247,14 @@
>          return _dnsListener;
>      }
>      
> +    public void setSSLSocketFactory( SSLSocketFactory sslSocketFactory ) {
> +    _sslSocketFactory = sslSocketFactory;
> +    }
> +    
> +    public SSLSocketFactory getSSLSocketFactory() {
> +    return _sslSocketFactory;
> +    }
> +
> 		/**
> 			 * @return the whether Referer information should be stripped from the
>  			    * header
> @@ -285,6 +294,7 @@
>      private boolean _autoRefresh   = false;
>  
>      private DNSListener _dnsListener;
> +    private SSLSocketFactory _sslSocketFactory;
>      private boolean _sendReferer;
>  
>      private static ClientProperties _defaultProperties = new ClientProperties();
> 
> Index: src/com/meterware/httpunit/WebConversation.java
> ===================================================================
> --- src/com/meterware/httpunit/WebConversation.java	(revision 3326)
> +++ src/com/meterware/httpunit/WebConversation.java	(working copy)
> @@ -30,7 +30,9 @@
>  import java.util.Enumeration;
>  import java.util.Properties;
>  
> +import javax.net.ssl.HttpsURLConnection;
>  
> +
>  /**
>   * The context for a series of HTTP requests. This class manages cookies used to maintain
>   * session context, computes relative URLs, and generally emulates the browser behavior
> @@ -163,7 +165,12 @@
>       * @param url - the url to use
>       */
>      private URLConnection openConnection( URL url ) throws MalformedURLException, IOException {
> -        URLConnection connection = url.openConnection();
> +	 URLConnection connection = url.openConnection();
> +        if (connection instanceof HttpsURLConnection 
> +           && getClientProperties().getSSLSocketFactory() != null) {
> +            ((HttpsURLConnection) connection).setSSLSocketFactory(
> +                getClientProperties().getSSLSocketFactory());
> +        }
>          if (connection instanceof HttpURLConnection) ((HttpURLConnection) connection).setInstanceFollowRedirects( false );
>          connection.setUseCaches( false );
>          return connection;
> 
> Are there really still JVMs where SSL/TLS doesn't work out of the box
> for https:// URLs?  Is it still necessary to tamper with URL protocol
> handlers?
> 
> -- 
> Florian Weimer                <[email protected]>
> BFK edv-consulting GmbH       http://www.bfk.de/
> Kriegsstraße 100              tel: +49-721-96201-1
> D-76133 Karlsruhe             fax: +49-721-96201-99
> 
> ------------------------------------------------------------------------------
> Enter the BlackBerry Developer Challenge  
> This is your chance to win up to $100,000 in prizes! For a limited time, 
> vendors submitting new applications to BlackBerry App World(TM) will have 
> the opportunity to enter the BlackBerry Developer Challenge. See full prize 
> details at: http://p.sf.net/sfu/blackberry
> _______________________________________________
> Httpunit-develop mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/httpunit-develop
> 



BITPlan - smart solutions
Pater-Delp-Str. 1, D-47877 Willich Schiefbahn
Tel. +49 2154 811-480, Fax +49 2154 811-481
Web: http://www.bitplan.de
bitplan GmbH, Willich - HRB 6820 Krefeld, VAT-ID: 10258040548, 
Geschäftsführer: Wolfgang Fahl

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july

_______________________________________________
Httpunit-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/httpunit-develop