Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2007

Tip: Looking for answers? Try searching our database.

Subclassing SSLSocket

Thread view: 
Robert - 28 Jun 2007 14:38 GMT
Hi all,

I'd like to specialize a SSLSocket with the following functionality:
- after the 'normal' SSL Handshake phase, do some more stuff (as part
of an 'extended' handshake)

While trying to achieve this, I've stumbled upon the problem that the
javax.net.ssl.SSLSocket class is merely a proxy for a SocketImpl (e.g.
com.sun.net.ssl.internal.ssl.SSLSocketImpl).

The main thing I'm wondering right now is whether I really need to
subclass an Implementing class to achieve what I want to achieve? And
if so, where do I find any documentation on such an implementing
class? It seems the Java API docs only provide documentation for the
"proxy" classes...

I hope you can help me!

Best regards,
Robert
Oliver Wong - 28 Jun 2007 18:40 GMT
> Hi all,
>
[quoted text clipped - 13 lines]
>
> I hope you can help me!

   Maybe something like:

<pseudocode>
public class MySSLSocket extends SSLSocket{
 private final SSLSocket internalSocket;

 public MySSLSocket(SSLSocket ssls) {
   this.internalSocket = ssls;
 }

 @Override
 public void startHandshake() {
   this.internalSocket.startHandshake();
   doExtendedHandshake();
 }

 private void doExtendedHandshake() {
   /*Do something here*/
 }
}
</pseudocode>

   Basically, your class acts as a wrapper around another class which
does most of the work, and you just add your extra handshaking stuff at
the appropriate place.

   - Oliver
Esmond Pitt - 29 Jun 2007 05:27 GMT
> Hi all,
>
> I'd like to specialize a SSLSocket with the following functionality:
> - after the 'normal' SSL Handshake phase, do some more stuff (as part
> of an 'extended' handshake)

Don't bother with subclassing, it's too hard. Just add a
HandshakeCompletionListener and do what you have to do in there.
Robert - 29 Jun 2007 13:38 GMT
Thank you for your answers!

I realize that I should delegate instead of subclassing, and indeed,
implementing a HandshakeCompletionListener would suffice.
However, this still gives me a problematic situation:

I am not actually creating SSLSocketFactory / SSLSocket objects
myself, but I would like to hook my own factories / sockets into the
JSSE system, and I'm trying to do this using the
"ssl.SocketFactory.provider" security property. My socketfactory would
simply delegate its tasks to the default socketfactory, but add a
HandshakeCompletionListener to the created socket before returning it.

Now, I believe this is not possible since:
1. The "default" SSLSocketFactory implementation can be accessed
through the ssl.SocketFactory.provider property
2. If I override the ssl.SocketFactory.provider property, how do I
create a SSLSocketFactory within my custom Factory?

First retrieving the default SSLSocketFactory by calling
SSLSocketFactory.getDefault() and then creating my custom class does
not work: after the default socketfactory has been created, changing
the ssl.SocketFactory.provider property has no effect.

How can I solve this?

Thanks,
Robert
Esmond Pitt - 01 Jul 2007 09:34 GMT
> How can I solve this?

Save the old value of the provider property before you change it. You
can then get the default SSLContext via that provider via
SSLContext.getInstance(String protocol, Provider provider), at any time.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.