Patch: Simple SSL Support using jdk1.4
Lars Brueckner <[email protected]>(by way of Lars Brueckner <[email protected]>) Fri, 24 May 2002 11:18:54 +0200
| Newsgroups | gmane.comp.web.jigsaw |
|---|---|
| Message-ID | <[email protected]> |
Hello, there has been some talk on this list about SSL support recently, so somebody may find the attached patch useful. It adds server-side support for SSL to jigsaw. <RoughDescription> * ssl_for_server_sockets.patch patches class /org/w3c/jigsaw/http/socket/SocketClientFactory.java Uses jdk1.4 javax.net.ssl.* to provide server-side ssl support set the property org.w3c.jigsaw.SSLHACK == true in server.props file You need to create a "keystore" with the keytool programm (part of jdk1.4) with at least a single self-signed certificate. (See http://java.sun.com/j2se/1.4/docs/tooldocs/solaris/keytool.html for examples) Add the relevant system properties to the Jigsaw start-script using the -Dproperty=value parameter . (At least javax.net.ssl.trustStore=keystorefile and javax.net.ssl.keyStore=keystorefile are required) </RoughDescription> I also tried to add SSL support for the client side to create an HTTPS proxy, however that does not work for me, maybe some else knows what's wrong? Please see the second patch ( for some classes in org/w3c/www/protocol/http ). Best regards, Lars -- Dipl.-Inform. Lars Brückner [email protected] IT Transfer Office, Darmstadt University of Technology PGP-Fingerprint: 8082 5A1B 6ED4 B400 7B53 3665 7EAD 1F4C DDA6 6DEB
ssl_for_server_sockets.patch
(text/x-java, 2.2 KB)
Index: SocketClientFactory.java
===================================================================
RCS file: /users/ito/projects/prima/PRIMA-CVSROOT/PRIMA/Jigsaw/src/classes/org/w3c/jigsaw/http/socket/SocketClientFactory.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -r1.1.1.1 -r1.2
0a1
> //
2c3,10
< // $Id: SocketClientFactory.java,v 1.1.1.1 2001/12/12 16:08:31 lars Exp $
---
> //
> // $Id: SocketClientFactory.java,v 1.2 2002/05/17 15:30:00 lars Exp $
> //
> //
> // Patched for PRIMA:
> // will create SSLSockets if property org.w3c.jigsaw.SSLHACK == true
> // uses jdk 1.4 SSL classes
> //
14a23,28
> // PRIMA
> import javax.net.ServerSocketFactory;
> import javax.net.ssl.SSLServerSocketFactory;
> import javax.net.ssl.SSLServerSocket;
> import java.lang.reflect.Array;
>
88a103,105
> // PRIMA
> private ServerSocketFactory socketFactory;
>
109a127,129
> // PRIMA
> public final static String
> PRIMA_SSL_HACK_P = "org.w3c.jigsaw.prima.SSLHACK";
849a870,873
>
> // PRIMA
> // use socketFactory instead of creating Socket directly
>
852c876
< return new ServerSocket (server.getPort(),
---
> return socketFactory.createServerSocket (server.getPort(),
855c879
< return new ServerSocket (server.getPort(),
---
> return socketFactory.createServerSocket (server.getPort(),
887a912,930
> // PRIMA: set socketFactory depending on property SSLHACK
> if (props.getBoolean(PRIMA_SSL_HACK_P,false)) {
> System.out.println("SocketClientFactory: Using SSL!");
> socketFactory = SSLServerSocketFactory.getDefault();
> SSLServerSocketFactory sfac = (SSLServerSocketFactory) socketFactory;
> /*
> System.out.println("Supported Cipher Suites: ");
> for (int i=0 ; i < Array.getLength(sfac.getSupportedCipherSuites()) ; i++){
> System.out.println(sfac.getSupportedCipherSuites()[i]);
> }
> System.out.println("Enabled Cipher Suites: ");
> for (int i=0 ; i < Array.getLength(sfac.getDefaultCipherSuites()) ; i++){
> System.out.println(sfac.getDefaultCipherSuites()[i]);
> }
> */
> } else {
> System.out.println("SocketClientFactory: NOT Using SSL!");
> socketFactory = ServerSocketFactory.getDefault();
> }
ssl_for_client_sockets_not_working_yet.patch
(text/x-diff, 4.7 KB)
Index: HttpBasicServer.java
===================================================================
RCS file: /users/ito/projects/prima/PRIMA-CVSROOT/PRIMA/Jigsaw/src/classes/org/w3c/www/protocol/http/HttpBasicServer.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -r1.1.1.1 -r1.2
2c2
< // $Id: HttpBasicServer.java,v 1.1.1.1 2001/12/12 16:08:24 lars Exp $
---
> // $Id: HttpBasicServer.java,v 1.2 2002/05/17 15:30:00 lars Exp $
58c58,59
< private static final boolean debug = false;
---
> //private static final boolean debug = false;
> private static final boolean debug = true;
97a99,104
> /**
> * PRIMA
> * wether use SSL or not
> **/
> private boolean SSL_HACK;
>
241a249,255
> //PRIMA
> //conn = new HttpBasicConnection(this
> // , connid++
> // , addr
> // , port
> // , timeout
> // , manager.getReplyFactory());
247c261,262
< , manager.getReplyFactory());
---
> , manager.getReplyFactory(),
> SSL_HACK);
416a432
> System.out.println("New HttpBasicServer: (Host,port)"+host+","+port);
424a441,450
> }
>
> public void initialize_with_ssl_hack(HttpManager manager
> , HttpServerState state
> , String host, int port, int timeout, boolean use_ssl)
> throws HttpException
> {
> System.out.println("New HttpBasicServer (SSL HACK): (Host,port)"+host+","+port);
> SSL_HACK=use_ssl;
> initialize(manager,state,host,port,timeout);
Index: HttpBasicConnection.java
===================================================================
RCS file: /users/ito/projects/prima/PRIMA-CVSROOT/PRIMA/Jigsaw/src/classes/org/w3c/www/protocol/http/HttpBasicConnection.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -r1.1.1.1 -r1.2
2c2
< // $Id: HttpBasicConnection.java,v 1.1.1.1 2001/12/12 16:08:24 lars Exp $
---
> // $Id: HttpBasicConnection.java,v 1.2 2002/05/17 15:30:00 lars Exp $
17a18,22
> //PRIMA
> import javax.net.SocketFactory;
> import javax.net.ssl.SSLSocket;
> import javax.net.ssl.SSLSocketFactory;
>
25c30,31
< private static final boolean debug = false;
---
> //private static final boolean debug = false;
> private static final boolean debug = true;
67a74,76
> private SocketFactory socketFactory;
> private boolean SSL_HACK;
>
170c179,183
< socket = new Socket(inetaddr, port);
---
> //PRIMA
> if (SSL_HACK) {System.out.println("opening socket (with SSL HACK)");}
> else { System.out.println("opening socket");}
> //socket = new Socket(inetaddr, port);
> socket = socketFactory.createSocket(inetaddr,port);
275a289
> System.out.println("New HttpBasicConnection UNPATCHED CONSTRUCTOR (Addr,Port,ID) "+addr+" "+port+" "+id);
281a296,328
>
> System.out.println("HttpBasicConnection: NOT using SSL");
> socketFactory = SocketFactory.getDefault();
>
> }
>
> HttpBasicConnection(HttpServer server
> , int id
> , InetAddress addr
> , int port
> , int timeout
> , MimeParserFactory reply_factory
> , boolean use_ssl)
> throws IOException
> {
> System.out.println("New HttpBasicConnection (WITH SSL_HACK)(Addr,Port,ID) "
> +addr+" "+port+" "+id);
> this.server = server;
> this.inetaddr = addr;
> this.port = port;
> this.id = id;
> this.timeout = timeout;
> this.reply_factory = reply_factory;
> this.SSL_HACK = use_ssl;
>
> if (use_ssl) {
> System.out.println("HttpBasicConnection: using SSL");
> socketFactory = SSLSocketFactory.getDefault();
> } else {
> System.out.println("HttpBasicConnection: NOT using SSL");
> socketFactory = SocketFactory.getDefault();
> }
>
Index: HttpManager.java
===================================================================
RCS file: /users/ito/projects/prima/PRIMA-CVSROOT/PRIMA/Jigsaw/src/classes/org/w3c/www/protocol/http/HttpManager.java,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -r1.1.1.2 -r1.2
2c2
< // $Id: HttpManager.java,v 1.1.1.2 2002/05/03 14:30:48 lars Exp $
---
> // $Id: HttpManager.java,v 1.2 2002/05/17 15:30:00 lars Exp $
163a164,170
> * PRIMA SSL HACK
> *
> **/
> public static final String PRIMA_SSL_HACK_P = "org.w3c.jigsaw.prima.SSLHACK";
> private boolean SSL_HACK;
>
> /**
429a437,447
>
> //
> // PRIMA
> //
> manager.SSL_HACK = props.getBoolean(PRIMA_SSL_HACK_P, false);
> if (manager.SSL_HACK) {
> System.out.println("HttpManager: using SSL HACK");
> } else{
> System.out.println("HttpManager: NOT using SSL HACK");
> }
>
513c531,533
< server.initialize(this, new HttpServerState(server), host, p, timeout);
---
> // PRIMA
> //server.initialize(this, new HttpServerState(server), host, p, timeout);
> server.initialize_with_ssl_hack(this, new HttpServerState(server), host, p, timeout, SSL_HACK);