You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@ws.apache.org by Tristan King <tr...@gmail.com> on 2006/05/29 08:06:57 UTC

xmlrpc2 setting custom trust manager for SSL connections

Hi,

I'm trying to write a xmlrpc client that can connect to a https server which
doesn't have a known certificate.
I can do it with a normal HttpsURLConnection using the class at the end of
this email, but i haven't been able to figure out how to do a similar thing
with the apache xmlrpc2. can anyone help me with this, or point me towards
some documentation which would help me?
note that i'm using version 2.0.1, cause i'm using java 1.4. Is version 3
available for java 1.4? when i tried to use it to said something bout being
the wrong version. maybe i'm doing something wrong?

Thanks in advance
_tristan

public class HttpsClient {

    private static TrustManager[] alltms = new TrustManager[] {
        new X509TrustManager() {
            public X509Certificate[] getAcceptedIssuers() {
                return null;
            }
            public void checkClientTrusted(X509Certificate[] arg0, String
arg1) throws CertificateException {}
            public void checkServerTrusted(X509Certificate[] arg0, String
arg1) throws CertificateException {}
        }
    };

    public static void main(String[] args) {
        try {
            URL u = new URL(args[0]);

            HttpsURLConnection huc = (HttpsURLConnection)u.openConnection();
            SSLContext sslc = SSLContext.getInstance("TLS");
            sslc.init(null, alltms, null);

            huc.setSSLSocketFactory(sslc.getSocketFactory());

            BufferedReader br = new BufferedReader(new InputStreamReader(
huc.getInputStream()));
            String s = br.readLine();
            while (s != null) {
                System.out.print(s);
                s = br.readLine();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

Re: xmlrpc2 setting custom trust manager for SSL connections

Posted by Jochen Wiedmann <jo...@gmail.com>.
On 5/29/06, Tristan King <tr...@gmail.com> wrote:

> maybe i am getting confused here. which class are you refering to? I'm
> looking at
> org.apache.xmlrpc.secure.sunssl.SunSSLTransportFactory
> which contains the following imports:
> ....
> import com.sun.net.ssl.HostnameVerifier ;
> import com.sun.net.ssl.HttpsURLConnection;
> import com.sun.net.ssl.SSLContext;
> import com.sun.net.ssl.X509TrustManager;

First of all, the current version should use javax.net, so yours is
possibly outdated. Next, use the DefaultXmlRpcTransportFactory with an
https URL.


Jochen

-- 
Whenever you find yourself on the side of the
majority, it is time to pause and reflect.
(Mark Twain)

---------------------------------------------------------------------
To unsubscribe, e-mail: xmlrpc-user-unsubscribe@ws.apache.org
For additional commands, e-mail: xmlrpc-user-help@ws.apache.org


Re: xmlrpc2 setting custom trust manager for SSL connections

Posted by Tristan King <tr...@gmail.com>.
On 5/29/06, Jochen Wiedmann <jo...@gmail.com> wrote:
>
> On 5/29/06, Tristan King <tr...@gmail.com> wrote:
>
> > com.sun.net.ssl.HttpsURLConnection is depreciated. I'm
> > using javax.net.ssl.HttpsURLConnection. some of the
> > functions used by the sun transport are depreciated as well, so i would
> > prefer to avoid them if possible.
> > I might be able to modify these to use the javax classes tho.. i'll have
> to
> > play with that.
>
> I believe, you are confusing the SSL related stuff of XML-RPC and the
> sun transport.
>
> The sun transport depends solely on java.net. I see no reason for not
> using that?


maybe i am getting confused here. which class are you refering to? I'm
looking at org.apache.xmlrpc.secure.sunssl.SunSSLTransportFactory which
contains the following imports:
....
import com.sun.net.ssl.HostnameVerifier;
import com.sun.net.ssl.HttpsURLConnection;
import com.sun.net.ssl.SSLContext;
import com.sun.net.ssl.X509TrustManager;
....

Re: xmlrpc2 setting custom trust manager for SSL connections

Posted by Jochen Wiedmann <jo...@gmail.com>.
On 5/29/06, Tristan King <tr...@gmail.com> wrote:

> com.sun.net.ssl.HttpsURLConnection is depreciated. I'm
> using javax.net.ssl.HttpsURLConnection. some of the
> functions used by the sun transport are depreciated as well, so i would
> prefer to avoid them if possible.
> I might be able to modify these to use the javax classes tho.. i'll have to
> play with that.

I believe, you are confusing the SSL related stuff of XML-RPC and the
sun transport.

The sun transport depends solely on java.net. I see no reason for not
using that?


Jochen


-- 
Whenever you find yourself on the side of the
majority, it is time to pause and reflect.
(Mark Twain)

---------------------------------------------------------------------
To unsubscribe, e-mail: xmlrpc-user-unsubscribe@ws.apache.org
For additional commands, e-mail: xmlrpc-user-help@ws.apache.org


Re: xmlrpc2 setting custom trust manager for SSL connections

Posted by Tristan King <tr...@gmail.com>.
On 5/29/06, Jochen Wiedmann <jo...@gmail.com> wrote:
>
> On 5/29/06, Tristan King <tr...@gmail.com> wrote:
>
> > I can do it with a normal HttpsURLConnection using the class at the end
> of
> > this email, but i haven't been able to figure out how to do a similar
> thing
> > with the apache xmlrpc2. can anyone help me with this, or point me
> towards
> > some documentation which would help me?
>
> If you can do that with an HttpsURLConnection, why not use the Sun
> transport of XML-RPC2?


com.sun.net.ssl.HttpsURLConnection is depreciated. I'm using
javax.net.ssl.HttpsURLConnection. some of the functions used by the sun
transport are depreciated as well, so i would prefer to avoid them if
possible.
I might be able to modify these to use the javax classes tho.. i'll have to
play with that.

> note that i'm using version 2.0.1, cause i'm using java 1.4. Is version 3
> > available for java 1.4? when i tried to use it to said something bout
> being
> > the wrong version. maybe i'm doing something wrong?
>
> Version 3 should run with Java 1.2 and later. In particular, it should
> run with Java 1.4. If you receive a message like "wrong version" then
> something went wrong during creating the distribution.


I might have to play with this some more then. I simply included the jar
files downloaded from the web site and got this error on compile
    [javac] bad class file: /home/tristan/dart/lib/jar/xmlrpc-3.0a1.jar
(org/apache/xmlrpc/client/XmlRpcClient.class)
    [javac] class file has wrong version 49.0, should be 48.0

>From what i could tell from a quick google search this meant that the class
was compiled for java1.5

Jochen
>
>
> --
> Whenever you find yourself on the side of the
> majority, it is time to pause and reflect.
> (Mark Twain)
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xmlrpc-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: xmlrpc-user-help@ws.apache.org
>
>

Re: xmlrpc2 setting custom trust manager for SSL connections

Posted by Jochen Wiedmann <jo...@gmail.com>.
On 5/29/06, Tristan King <tr...@gmail.com> wrote:

> I can do it with a normal HttpsURLConnection using the class at the end of
> this email, but i haven't been able to figure out how to do a similar thing
> with the apache xmlrpc2. can anyone help me with this, or point me towards
> some documentation which would help me?

If you can do that with an HttpsURLConnection, why not use the Sun
transport of XML-RPC2?

> note that i'm using version 2.0.1, cause i'm using java 1.4. Is version 3
> available for java 1.4? when i tried to use it to said something bout being
> the wrong version. maybe i'm doing something wrong?

Version 3 should run with Java 1.2 and later. In particular, it should
run with Java 1.4. If you receive a message like "wrong version" then
something went wrong during creating the distribution.


Jochen


-- 
Whenever you find yourself on the side of the
majority, it is time to pause and reflect.
(Mark Twain)

---------------------------------------------------------------------
To unsubscribe, e-mail: xmlrpc-user-unsubscribe@ws.apache.org
For additional commands, e-mail: xmlrpc-user-help@ws.apache.org