summaryrefslogtreecommitdiff
path: root/java/src/IceSSL/Util.java
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2006-04-26 19:23:50 +0000
committerMark Spruiell <mes@zeroc.com>2006-04-26 19:23:50 +0000
commita9422ebadae79458a2a6af9015397ca031b15914 (patch)
tree1635adc02d202d9284f15a396ae7f21ce98ff328 /java/src/IceSSL/Util.java
parentminor fix (diff)
downloadice-a9422ebadae79458a2a6af9015397ca031b15914.tar.bz2
ice-a9422ebadae79458a2a6af9015397ca031b15914.tar.xz
ice-a9422ebadae79458a2a6af9015397ca031b15914.zip
adding ConnectionInfo
Diffstat (limited to 'java/src/IceSSL/Util.java')
-rw-r--r--java/src/IceSSL/Util.java67
1 files changed, 67 insertions, 0 deletions
diff --git a/java/src/IceSSL/Util.java b/java/src/IceSSL/Util.java
new file mode 100644
index 00000000000..c8192cf9706
--- /dev/null
+++ b/java/src/IceSSL/Util.java
@@ -0,0 +1,67 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+package IceSSL;
+
+public final class Util
+{
+ public static ConnectionInfo
+ getConnectionInfo(Ice.Connection connection)
+ {
+ Ice.ConnectionI con = (Ice.ConnectionI)connection;
+ assert(con != null);
+
+ //
+ // Lock the connection directly. This is done because the only
+ // thing that prevents the transceiver from being closed during
+ // the duration of the invocation is the connection.
+ //
+ synchronized(con)
+ {
+ IceInternal.Transceiver transceiver = con.getTransceiver();
+ if(transceiver == null)
+ {
+ ConnectionInvalidException ex = new ConnectionInvalidException();
+ ex.reason = "connection closed";
+ throw ex;
+ }
+
+ try
+ {
+ TransceiverI sslTransceiver = (TransceiverI)transceiver;
+ return sslTransceiver.getConnectionInfo();
+ }
+ catch(ClassCastException ex)
+ {
+ ConnectionInvalidException e = new ConnectionInvalidException();
+ e.reason = "not ssl connection";
+ throw e;
+ }
+ }
+ }
+
+ static ConnectionInfo
+ populateConnectionInfo(javax.net.ssl.SSLSocket fd)
+ {
+ ConnectionInfo info = new ConnectionInfo();
+ javax.net.ssl.SSLSession session = fd.getSession();
+ try
+ {
+ info.certs = session.getPeerCertificates();
+ }
+ catch(javax.net.ssl.SSLPeerUnverifiedException ex)
+ {
+ // No peer certificates.
+ }
+ info.cipher = session.getCipherSuite();
+ info.localAddr = (java.net.InetSocketAddress)fd.getLocalSocketAddress();
+ info.remoteAddr = (java.net.InetSocketAddress)fd.getRemoteSocketAddress();
+ return info;
+ }
+}