01: /*
02: * JacORB - a free Java ORB
03: *
04: * Copyright (C) The JacORB project, 1997-2006.
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Library General Public
08: * License as published by the Free Software Foundation; either
09: * version 2 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Library General Public License for more details.
15: *
16: * You should have received a copy of the GNU Library General Public
17: * License along with this library; if not, write to the Free
18: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19: */
20:
21: package org.jacorb.orb.listener;
22:
23: import javax.net.ssl.HandshakeCompletedEvent;
24: import javax.net.ssl.HandshakeCompletedListener;
25:
26: import javax.security.cert.X509Certificate;
27: import javax.net.ssl.SSLPeerUnverifiedException;
28:
29: import java.net.InetAddress;
30: import java.net.UnknownHostException;
31:
32: import org.apache.avalon.framework.logger.Logger;
33:
34: /**
35: * <code>SSLHandshakeListener</code> implements the SSL Handshake Listener
36: * in order to detect a successful SSL connection. It then passes this information
37: * on to the external SSLListener.
38: *
39: * @author Nick Cross
40: * @version $Id: SSLHandshakeListener.java,v 1.2 2006/06/29 15:17:55 alphonse.bendt Exp $
41: */
42: public class SSLHandshakeListener implements HandshakeCompletedListener {
43: private final Logger logger;
44: private final SSLSessionListener sslListener;
45:
46: public SSLHandshakeListener(Logger logger,
47: SSLSessionListener listener) {
48: this .logger = logger;
49: this .sslListener = listener;
50: }
51:
52: /**
53: * <code>handshakeCompleted</code> is the implementation that is invoked
54: * when a SSL handshake is completed.
55: * The getPeerCertificateChain method is used to ensure backward
56: * compatibility with JDK 1.3
57: * @param event a <code>HandshakeCompletedEvent</code> value
58: */
59: public void handshakeCompleted(HandshakeCompletedEvent event) {
60: X509Certificate[] certs = null;
61: String localhost = null;
62:
63: try {
64: certs = event.getPeerCertificateChain();
65: } catch (SSLPeerUnverifiedException ex) {
66: if (logger.isDebugEnabled()) {
67: logger
68: .debug("handshakeCompleted - SSLPeerUnverifiedException");
69: }
70:
71: certs = new X509Certificate[0];
72: }
73:
74: try {
75: localhost = InetAddress.getLocalHost().getHostAddress();
76: } catch (UnknownHostException uhe) {
77: if (logger.isDebugEnabled()) {
78: logger
79: .debug("Unable to resolve local IP address - using default");
80: }
81:
82: localhost = "127.0.0.1";
83: }
84:
85: sslListener.sessionCreated(new SSLSessionEvent(event
86: .getSource(), event.getSocket().getInetAddress()
87: .getHostAddress(), event.getSocket().getPort(), certs,
88: event.getSocket().getLocalPort(), localhost, null));
89: }
90: }
|