diff options
author | Benoit Foucher <benoit@zeroc.com> | 2009-10-21 17:02:37 +0200 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2009-10-21 17:02:37 +0200 |
commit | a80b3c8cbb203c78b061e99e1a764685af4a93e9 (patch) | |
tree | 5448b1dd66499b8fc9e46c618aa65b6687855946 /java | |
parent | Bug 4311 - change Ice::Service::start signature (diff) | |
download | ice-a80b3c8cbb203c78b061e99e1a764685af4a93e9.tar.bz2 ice-a80b3c8cbb203c78b061e99e1a764685af4a93e9.tar.xz ice-a80b3c8cbb203c78b061e99e1a764685af4a93e9.zip |
- Removed old IceSSL::ConnectionInfo struct, it's now replaced with
IceSSL::NativeConnectionInfo.
- Removed Ice::ConnectionInfo endpoint attribute.
- Added Ice::Connection::getEndpoint() method.
- Added Ice::ConnectionInfo adapterName and incoming attributes.
- Replaced Tcp and Udp prefixes with TCP and UDP in endpoint/info classes.
- Added IPEndpointInfo and IPConnectionInfo intermediate classes.
- Fixed 2058: deprecate ice_hash for Ice.Object & Ice.LocalObject, added ice_getHash
- Fixed bug where Ice::Endpoint comparison would only compare the endpoint object addresses rather than the endpoint attributes like in Java and C#.
- Added ice_getHash implementation for endpoints and cleaned up Reference::hash to use HashUtil.h helper methods.
- Added test/Ice/info and removed endpoint info test from test/Ice/proxy.
Diffstat (limited to 'java')
32 files changed, 483 insertions, 309 deletions
diff --git a/java/allTests.py b/java/allTests.py index 94ce71eade5..0bbe5ea4b6a 100755 --- a/java/allTests.py +++ b/java/allTests.py @@ -36,6 +36,7 @@ tests = [ ("Ice/operations", ["core"]), ("Ice/seqMapping", ["core"]), ("Ice/exceptions", ["core"]), + ("Ice/info", ["core"]), ("Ice/inheritance", ["core"]), ("Ice/facets", ["core"]), ("Ice/objects", ["core"]), diff --git a/java/build.xml b/java/build.xml index 63baedf8144..bd4cd3da84d 100644 --- a/java/build.xml +++ b/java/build.xml @@ -279,6 +279,9 @@ <fileset dir="test/Ice/hold"> <include name="Test.ice" /> </fileset> + <fileset dir="test/Ice/info"> + <include name="Test.ice" /> + </fileset> <fileset dir="test/Ice/inheritance"> <include name="Test.ice" /> </fileset> diff --git a/java/src/Ice/ConnectionI.java b/java/src/Ice/ConnectionI.java index da2b0b1aab6..7fb693abf3c 100644 --- a/java/src/Ice/ConnectionI.java +++ b/java/src/Ice/ConnectionI.java @@ -832,6 +832,12 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne return _adapter; } + public Endpoint + getEndpoint() + { + return _endpoint; // No mutex protection necessary, _endpoint is immutable. + } + public ObjectPrx createProxy(Identity ident) { @@ -1203,22 +1209,11 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne throw (Ice.LocalException)_exception.fillInStackTrace(); } ConnectionInfo info = _transceiver.getInfo(); - info.endpoint = _endpoint.getInfo(); + info.adapterName = _adapter != null ? _adapter.getName() : ""; + info.incoming = _connector == null; return info; } - // - // Only used by the SSL plug-in. - // - // The external party has to synchronize the connection, since the - // connection is the object that protects the transceiver. - // - public IceInternal.Transceiver - getTransceiver() - { - return _transceiver; - } - public String _toString() { diff --git a/java/src/IceInternal/TcpConnector.java b/java/src/IceInternal/TcpConnector.java index ae5d618be99..cadc4335ffc 100644 --- a/java/src/IceInternal/TcpConnector.java +++ b/java/src/IceInternal/TcpConnector.java @@ -50,7 +50,7 @@ final class TcpConnector implements Connector public short type() { - return TcpEndpointI.TYPE; + return Ice.TCPEndpointType.value; } public String diff --git a/java/src/IceInternal/TcpEndpointFactory.java b/java/src/IceInternal/TcpEndpointFactory.java index 25bdfdb557a..48952c04e89 100644 --- a/java/src/IceInternal/TcpEndpointFactory.java +++ b/java/src/IceInternal/TcpEndpointFactory.java @@ -19,7 +19,7 @@ final class TcpEndpointFactory implements EndpointFactory public short type() { - return TcpEndpointI.TYPE; + return Ice.TCPEndpointType.value; } public String diff --git a/java/src/IceInternal/TcpEndpointI.java b/java/src/IceInternal/TcpEndpointI.java index 44fc624af8d..27618d8ccc5 100644 --- a/java/src/IceInternal/TcpEndpointI.java +++ b/java/src/IceInternal/TcpEndpointI.java @@ -11,8 +11,6 @@ package IceInternal; final class TcpEndpointI extends EndpointI { - final static short TYPE = 1; - public TcpEndpointI(Instance instance, String ho, int po, int ti, String conId, boolean co) { @@ -178,7 +176,7 @@ final class TcpEndpointI extends EndpointI public void streamWrite(BasicStream s) { - s.writeShort(TYPE); + s.writeShort(Ice.TCPEndpointType.value); s.startWriteEncaps(); s.writeString(_host); s.writeInt(_port); @@ -236,11 +234,11 @@ final class TcpEndpointI extends EndpointI public Ice.EndpointInfo getInfo() { - return new Ice.TcpEndpointInfo(_timeout, _compress, _host, _port) + return new Ice.TCPEndpointInfo(_timeout, _compress, _host, _port) { public short type() { - return TYPE; + return Ice.TCPEndpointType.value; } public boolean datagram() @@ -261,7 +259,7 @@ final class TcpEndpointI extends EndpointI public short type() { - return TYPE; + return Ice.TCPEndpointType.value; } // diff --git a/java/src/IceInternal/TcpTransceiver.java b/java/src/IceInternal/TcpTransceiver.java index fef0558e62c..cd4e325772e 100644 --- a/java/src/IceInternal/TcpTransceiver.java +++ b/java/src/IceInternal/TcpTransceiver.java @@ -225,7 +225,7 @@ final class TcpTransceiver implements Transceiver getInfo() { assert(_fd != null); - Ice.TcpConnectionInfo info = new Ice.TcpConnectionInfo(); + Ice.TCPConnectionInfo info = new Ice.TCPConnectionInfo(); java.net.Socket socket = _fd.socket(); info.localAddress = socket.getLocalAddress().getHostAddress(); info.localPort = socket.getLocalPort(); diff --git a/java/src/IceInternal/UdpConnector.java b/java/src/IceInternal/UdpConnector.java index edff81e92a2..f8f5c651ed9 100644 --- a/java/src/IceInternal/UdpConnector.java +++ b/java/src/IceInternal/UdpConnector.java @@ -27,7 +27,7 @@ final class UdpConnector implements Connector public short type() { - return UdpEndpointI.TYPE; + return Ice.UDPEndpointType.value; } public String diff --git a/java/src/IceInternal/UdpEndpointFactory.java b/java/src/IceInternal/UdpEndpointFactory.java index a92b443b1d8..1f08169199b 100644 --- a/java/src/IceInternal/UdpEndpointFactory.java +++ b/java/src/IceInternal/UdpEndpointFactory.java @@ -19,7 +19,7 @@ final class UdpEndpointFactory implements EndpointFactory public short type() { - return UdpEndpointI.TYPE; + return Ice.UDPEndpointType.value; } public String diff --git a/java/src/IceInternal/UdpEndpointI.java b/java/src/IceInternal/UdpEndpointI.java index 846b4f41c48..880eae25473 100644 --- a/java/src/IceInternal/UdpEndpointI.java +++ b/java/src/IceInternal/UdpEndpointI.java @@ -11,8 +11,6 @@ package IceInternal; final class UdpEndpointI extends EndpointI { - final static short TYPE = 3; - public UdpEndpointI(Instance instance, String ho, int po, String mif, int mttl, byte pma, byte pmi, byte ema, byte emi, boolean conn, String conId, boolean co) @@ -315,7 +313,7 @@ final class UdpEndpointI extends EndpointI public void streamWrite(BasicStream s) { - s.writeShort(TYPE); + s.writeShort(Ice.UDPEndpointType.value); s.startWriteEncaps(); s.writeString(_host); s.writeInt(_port); @@ -402,12 +400,12 @@ final class UdpEndpointI extends EndpointI public Ice.EndpointInfo getInfo() { - return new Ice.UdpEndpointInfo(-1, _compress, _host, _port, _protocolMajor, _protocolMinor, _encodingMajor, + return new Ice.UDPEndpointInfo(-1, _compress, _host, _port, _protocolMajor, _protocolMinor, _encodingMajor, _encodingMinor, _mcastInterface, _mcastTtl) { public short type() { - return TYPE; + return Ice.UDPEndpointType.value; } public boolean datagram() @@ -428,7 +426,7 @@ final class UdpEndpointI extends EndpointI public short type() { - return TYPE; + return Ice.UDPEndpointType.value; } // diff --git a/java/src/IceInternal/UdpTransceiver.java b/java/src/IceInternal/UdpTransceiver.java index 10f4c531935..bd18ad77678 100644 --- a/java/src/IceInternal/UdpTransceiver.java +++ b/java/src/IceInternal/UdpTransceiver.java @@ -234,7 +234,7 @@ final class UdpTransceiver implements Transceiver { assert(_fd != null); - Ice.UdpConnectionInfo info = new Ice.UdpConnectionInfo(); + Ice.UDPConnectionInfo info = new Ice.UDPConnectionInfo(); java.net.DatagramSocket socket = _fd.socket(); info.localAddress = socket.getLocalAddress().getHostAddress(); info.localPort = socket.getLocalPort(); diff --git a/java/src/IceSSL/CertificateVerifier.java b/java/src/IceSSL/CertificateVerifier.java index eae8cd936e5..b9e52fca064 100644 --- a/java/src/IceSSL/CertificateVerifier.java +++ b/java/src/IceSSL/CertificateVerifier.java @@ -22,5 +22,5 @@ public interface CertificateVerifier * @return <code>true</code> if the connection should be accepted; * <code>false</code>, otherwise. **/ - boolean verify(ConnectionInfo info); + boolean verify(NativeConnectionInfo info); } diff --git a/java/src/IceSSL/ConnectionInfo.java b/java/src/IceSSL/ConnectionInfo.java deleted file mode 100644 index 7f086722200..00000000000 --- a/java/src/IceSSL/ConnectionInfo.java +++ /dev/null @@ -1,52 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2009 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; - -/** - * This class provides information about a connection to applications - * that require information about a peer, for example, to implement - * a CertificateVerifier. - * - * @see CertificateVerifier - **/ -public class ConnectionInfo -{ - /** - * The certificate chain. This may be null if the peer did not - * supply a certificate. The peer's certificate (if any) is the - * first one in the chain. - **/ - public java.security.cert.Certificate[] certs; - - /** - * The name of the negotiated cipher. - **/ - public String cipher; - - /** - * The local TCP/IP host & port. - **/ - public java.net.InetSocketAddress localAddr; - - /** - * The remote TCP/IP host & port. - **/ - public java.net.InetSocketAddress remoteAddr; - - /** - * <code>true</code> if the connection is incoming; <code>false</code> otherwise. - **/ - public boolean incoming; - - /** - * The name of the object adapter that hosts this endpoint, if any. - **/ - public String adapterName; -} diff --git a/java/src/IceSSL/ConnectionInvalidException.java b/java/src/IceSSL/ConnectionInvalidException.java deleted file mode 100644 index 67751a6ea76..00000000000 --- a/java/src/IceSSL/ConnectionInvalidException.java +++ /dev/null @@ -1,49 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2009 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; - -/** - * Indicates that a connection is not an SSL connection. - **/ -public final class ConnectionInvalidException extends Ice.LocalException -{ - /** - * Creates an instance with a <code>null</code> <code>reason</code> field. - **/ - public ConnectionInvalidException() - { - } - - /** - * Creates an instance with the specified <code>reason</code>field. - * - * @param reason The reason why the connection is considered invalid. - **/ - public ConnectionInvalidException(String reason) - { - this.reason = reason; - } - - /** - * Returns the name of this exception. - * - * @return Returns <code>"Ice::ConnectionInvalidException"</code>. - **/ - public String - ice_name() - { - return "Ice::ConnectionInvalidException"; - } - - /** - * The reason why the connection is considered invalid. - **/ - public String reason; -} diff --git a/java/src/IceSSL/ConnectorI.java b/java/src/IceSSL/ConnectorI.java index 32e8d4cf817..282336b19f7 100644 --- a/java/src/IceSSL/ConnectorI.java +++ b/java/src/IceSSL/ConnectorI.java @@ -61,7 +61,7 @@ final class ConnectorI implements IceInternal.Connector public short type() { - return EndpointI.TYPE; + return EndpointType.value; } public String diff --git a/java/src/IceSSL/EndpointFactoryI.java b/java/src/IceSSL/EndpointFactoryI.java index 5e380ea6a24..3219de15596 100644 --- a/java/src/IceSSL/EndpointFactoryI.java +++ b/java/src/IceSSL/EndpointFactoryI.java @@ -19,7 +19,7 @@ final class EndpointFactoryI implements IceInternal.EndpointFactory public short type() { - return EndpointI.TYPE; + return EndpointType.value; } public String diff --git a/java/src/IceSSL/EndpointI.java b/java/src/IceSSL/EndpointI.java index 77e70e0671d..9c0282750da 100644 --- a/java/src/IceSSL/EndpointI.java +++ b/java/src/IceSSL/EndpointI.java @@ -11,8 +11,6 @@ package IceSSL; final class EndpointI extends IceInternal.EndpointI { - final static short TYPE = 2; - public EndpointI(Instance instance, String ho, int po, int ti, String conId, boolean co) { @@ -178,7 +176,7 @@ final class EndpointI extends IceInternal.EndpointI public void streamWrite(IceInternal.BasicStream s) { - s.writeShort(TYPE); + s.writeShort(EndpointType.value); s.startWriteEncaps(); s.writeString(_host); s.writeInt(_port); @@ -236,11 +234,11 @@ final class EndpointI extends IceInternal.EndpointI public Ice.EndpointInfo getInfo() { - return new IceSSL.SSLEndpointInfo(_timeout, _compress, _host, _port) + return new IceSSL.EndpointInfo(_timeout, _compress, _host, _port) { public short type() { - return TYPE; + return EndpointType.value; } public boolean datagram() @@ -261,7 +259,7 @@ final class EndpointI extends IceInternal.EndpointI public short type() { - return TYPE; + return EndpointType.value; } // diff --git a/java/src/IceSSL/Instance.java b/java/src/IceSSL/Instance.java index ee33751ae49..866d0d62821 100644 --- a/java/src/IceSSL/Instance.java +++ b/java/src/IceSSL/Instance.java @@ -869,15 +869,15 @@ class Instance } void - verifyPeer(ConnectionInfo info, java.nio.channels.SelectableChannel fd, String address, boolean incoming) + verifyPeer(NativeConnectionInfo info, java.nio.channels.SelectableChannel fd, String address) { // // For an outgoing connection, we compare the proxy address (if any) against // fields in the server's certificate (if any). // - if(info.certs != null && info.certs.length > 0 && address.length() > 0) + if(info.nativeCerts != null && info.nativeCerts.length > 0 && address.length() > 0) { - java.security.cert.X509Certificate cert = (java.security.cert.X509Certificate)info.certs[0]; + java.security.cert.X509Certificate cert = (java.security.cert.X509Certificate)info.nativeCerts[0]; // // Extract the IP addresses and the DNS names from the subject @@ -1005,10 +1005,10 @@ class Instance } } - if(_verifyDepthMax > 0 && info.certs != null && info.certs.length > _verifyDepthMax) + if(_verifyDepthMax > 0 && info.nativeCerts != null && info.nativeCerts.length > _verifyDepthMax) { - String msg = (incoming ? "incoming" : "outgoing") + " connection rejected:\n" + - "length of peer's certificate chain (" + info.certs.length + ") exceeds maximum of " + + String msg = (info.incoming ? "incoming" : "outgoing") + " connection rejected:\n" + + "length of peer's certificate chain (" + info.nativeCerts.length + ") exceeds maximum of " + _verifyDepthMax + "\n" + IceInternal.Network.fdToString(fd); if(_securityTraceLevel >= 1) @@ -1022,7 +1022,7 @@ class Instance if(!_trustManager.verify(info)) { - String msg = (incoming ? "incoming" : "outgoing") + " connection rejected by trust manager\n" + + String msg = (info.incoming ? "incoming" : "outgoing") + " connection rejected by trust manager\n" + IceInternal.Network.fdToString(fd); if(_securityTraceLevel >= 1) { @@ -1035,7 +1035,7 @@ class Instance if(_verifier != null && !_verifier.verify(info)) { - String msg = (incoming ? "incoming" : "outgoing") + " connection rejected by certificate verifier\n" + + String msg = (info.incoming ? "incoming" : "outgoing") + " connection rejected by certificate verifier\n" + IceInternal.Network.fdToString(fd); if(_securityTraceLevel >= 1) { diff --git a/java/src/IceSSL/NativeConnectionInfo.java b/java/src/IceSSL/NativeConnectionInfo.java new file mode 100644 index 00000000000..f84705fbd69 --- /dev/null +++ b/java/src/IceSSL/NativeConnectionInfo.java @@ -0,0 +1,28 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 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; + +/** + * + * This class is a native extension of the Slice local class + * IceSSL::ConnectionInfo. It provides access to the native Java + * certificates. + * + * @see CertificateVerifier + **/ +public class NativeConnectionInfo extends ConnectionInfo +{ + /** + * The certificate chain. This may be null if the peer did not + * supply a certificate. The peer's certificate (if any) is the + * first one in the chain. + **/ + public java.security.cert.Certificate[] nativeCerts; +} diff --git a/java/src/IceSSL/TransceiverI.java b/java/src/IceSSL/TransceiverI.java index 54687c5f052..05af29c35a6 100644 --- a/java/src/IceSSL/TransceiverI.java +++ b/java/src/IceSSL/TransceiverI.java @@ -277,44 +277,7 @@ final class TransceiverI implements IceInternal.Transceiver public Ice.ConnectionInfo getInfo() { - assert(_fd != null); - - IceSSL.SSLConnectionInfo info = new IceSSL.SSLConnectionInfo(); - java.net.Socket socket = _fd.socket(); - info.localAddress = socket.getLocalAddress().getHostAddress(); - info.localPort = socket.getLocalPort(); - if(socket.getInetAddress() != null) - { - info.remoteAddress = socket.getInetAddress().getHostAddress(); - info.remotePort = socket.getPort(); - } - else - { - info.remoteAddress = ""; - info.remotePort = -1; - } - SSLSession session = _engine.getSession(); - info.cipher = session.getCipherSuite(); - try - { - java.util.ArrayList<String> certs = new java.util.ArrayList<String>(); - for(java.security.cert.Certificate c : session.getPeerCertificates()) - { - StringBuffer s = new StringBuffer("-----BEGIN CERTIFICATE-----\n"); - s.append(IceUtilInternal.Base64.encode(c.getEncoded())); - s.append("\n-----END CERTIFICATE-----"); - certs.add(s.toString()); - } - info.certs = certs.toArray(new String[0]); - } - catch(java.security.cert.CertificateEncodingException ex) - { - } - catch(javax.net.ssl.SSLPeerUnverifiedException ex) - { - // No peer certificates. - } - return info; + return getNativeConnectionInfo(); } public void @@ -326,16 +289,6 @@ final class TransceiverI implements IceInternal.Transceiver } } - ConnectionInfo - getConnectionInfo() - { - // - // This can only be called on an open transceiver. - // - assert(_fd != null); - return _info; - } - // // Only for use by ConnectorI, AcceptorI. // @@ -388,6 +341,55 @@ final class TransceiverI implements IceInternal.Transceiver super.finalize(); } + private NativeConnectionInfo + getNativeConnectionInfo() + { + // + // This can only be called on an open transceiver. + // + assert(_fd != null); + + NativeConnectionInfo info = new NativeConnectionInfo(); + java.net.Socket socket = _fd.socket(); + info.localAddress = socket.getLocalAddress().getHostAddress(); + info.localPort = socket.getLocalPort(); + if(socket.getInetAddress() != null) + { + info.remoteAddress = socket.getInetAddress().getHostAddress(); + info.remotePort = socket.getPort(); + } + else + { + info.remoteAddress = ""; + info.remotePort = -1; + } + SSLSession session = _engine.getSession(); + info.cipher = session.getCipherSuite(); + try + { + java.util.ArrayList<String> certs = new java.util.ArrayList<String>(); + info.nativeCerts = session.getPeerCertificates(); + for(java.security.cert.Certificate c : info.nativeCerts) + { + StringBuffer s = new StringBuffer("-----BEGIN CERTIFICATE-----\n"); + s.append(IceUtilInternal.Base64.encode(c.getEncoded())); + s.append("\n-----END CERTIFICATE-----"); + certs.add(s.toString()); + } + info.certs = certs.toArray(new String[0]); + } + catch(java.security.cert.CertificateEncodingException ex) + { + } + catch(javax.net.ssl.SSLPeerUnverifiedException ex) + { + // No peer certificates. + } + info.adapterName = _adapterName; + info.incoming = _incoming; + return info; + } + private int handshakeNonBlocking() { @@ -535,8 +537,7 @@ final class TransceiverI implements IceInternal.Transceiver // // Additional verification. // - _info = Util.populateConnectionInfo(_engine.getSession(), _fd.socket(), _adapterName, _incoming); - _instance.verifyPeer(_info, _fd, _host, _incoming); + _instance.verifyPeer(getNativeConnectionInfo(), _fd, _host); if(_instance.networkTraceLevel() >= 1) { @@ -805,7 +806,6 @@ final class TransceiverI implements IceInternal.Transceiver private ByteBuffer _netInput; // Holds encrypted data read from the socket. private ByteBuffer _netOutput; // Holds encrypted data to be written to the socket. private static ByteBuffer _emptyBuffer = ByteBuffer.allocate(0); // Used during handshaking. - private ConnectionInfo _info; private static final int StateNeedConnect = 0; private static final int StateConnectPending = 1; diff --git a/java/src/IceSSL/TrustManager.java b/java/src/IceSSL/TrustManager.java index b54b18d16e9..46fdc3eabb5 100644 --- a/java/src/IceSSL/TrustManager.java +++ b/java/src/IceSSL/TrustManager.java @@ -55,7 +55,7 @@ class TrustManager } boolean - verify(ConnectionInfo info) + verify(NativeConnectionInfo info) { java.util.List<java.util.List<java.util.List<RFC2253.RDNPair> > > reject = new java.util.LinkedList<java.util.List<java.util.List<RFC2253.RDNPair> > >(), @@ -126,10 +126,10 @@ class TrustManager // // If there is no certificate then we match false. // - if(info.certs != null && info.certs.length > 0) + if(info.nativeCerts != null && info.nativeCerts.length > 0) { javax.security.auth.x500.X500Principal subjectDN = (javax.security.auth.x500.X500Principal) - ((java.security.cert.X509Certificate)info.certs[0]).getSubjectX500Principal(); + ((java.security.cert.X509Certificate)info.nativeCerts[0]).getSubjectX500Principal(); String subjectName = subjectDN.getName(javax.security.auth.x500.X500Principal.RFC2253); assert subjectName != null; try @@ -144,15 +144,15 @@ class TrustManager _communicator.getLogger().trace("Security", "trust manager evaluating client:\n" + "subject = " + subjectName + "\n" + "adapter = " + info.adapterName + "\n" + - "local addr = " + IceInternal.Network.addrToString(info.localAddr) + "\n" + - "remote addr = " + IceInternal.Network.addrToString(info.remoteAddr)); + "local addr = " + info.localAddress + ":" + info.localPort + "\n" + + "remote addr = " + info.remoteAddress + ":" + info.remotePort); } else { _communicator.getLogger().trace("Security", "trust manager evaluating server:\n" + "subject = " + subjectName + "\n" + - "local addr = " + IceInternal.Network.addrToString(info.localAddr) + "\n" + - "remote addr = " + IceInternal.Network.addrToString(info.remoteAddr)); + "local addr = " + info.localAddress + ":" + info.localPort + "\n" + + "remote addr = " + info.remoteAddress + ":" + info.remotePort); } } java.util.List<RFC2253.RDNPair> dn = RFC2253.parseStrict(subjectName); diff --git a/java/src/IceSSL/Util.java b/java/src/IceSSL/Util.java index ae3e5ced65f..05e3f5613a2 100644 --- a/java/src/IceSSL/Util.java +++ b/java/src/IceSSL/Util.java @@ -11,41 +11,6 @@ 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; - } - } - } - // // Create a certificate from a PEM-encoded string. // @@ -94,26 +59,6 @@ public final class Util return (java.security.cert.X509Certificate)cf.generateCertificate(in); } - static ConnectionInfo - populateConnectionInfo(javax.net.ssl.SSLSession session, java.net.Socket fd, String adapterName, boolean incoming) - { - ConnectionInfo info = new ConnectionInfo(); - 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(); - info.adapterName = adapterName; - info.incoming = incoming; - return info; - } - public final static String jdkTarget = "1.5"; // diff --git a/java/test/Ice/classLoader/CertificateVerifierI.java b/java/test/Ice/classLoader/CertificateVerifierI.java index b5439bd7e80..d29fd279732 100644 --- a/java/test/Ice/classLoader/CertificateVerifierI.java +++ b/java/test/Ice/classLoader/CertificateVerifierI.java @@ -11,7 +11,7 @@ package test.Ice.classLoader; public class CertificateVerifierI implements IceSSL.CertificateVerifier { - public boolean verify(IceSSL.ConnectionInfo info) + public boolean verify(IceSSL.NativeConnectionInfo info) { return true; } diff --git a/java/test/Ice/info/AllTests.java b/java/test/Ice/info/AllTests.java new file mode 100644 index 00000000000..6b26d81abf2 --- /dev/null +++ b/java/test/Ice/info/AllTests.java @@ -0,0 +1,169 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 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 test.Ice.info; + +import java.io.PrintWriter; + +import test.Ice.info.Test.TestIntfPrx; +import test.Ice.info.Test.TestIntfPrxHelper; + +public class AllTests +{ + private static void + test(boolean b) + { + if(!b) + { + throw new RuntimeException(); + } + } + + public static void + allTests(Ice.Communicator communicator, PrintWriter out) + { + out.print("testing proxy endpoint information... "); + out.flush(); + { + Ice.ObjectPrx p1 = communicator.stringToProxy("test -t:default -h tcphost -p 10000 -t 1200 -z:" + + "udp -h udphost -p 10001 --interface eth0 --ttl 5:" + + "opaque -t 100 -v ABCD"); + + Ice.Endpoint[] endps = p1.ice_getEndpoints(); + + + Ice.IPEndpointInfo ipEndpoint = (Ice.IPEndpointInfo)endps[0].getInfo(); + test(ipEndpoint.host.equals("tcphost")); + test(ipEndpoint.port == 10000); + test(ipEndpoint.timeout == 1200); + test(ipEndpoint.compress); + test(!ipEndpoint.datagram()); + test(ipEndpoint.type() == Ice.TCPEndpointType.value && !ipEndpoint.secure() || + ipEndpoint.type() == IceSSL.EndpointType.value && ipEndpoint.secure()); + + test(ipEndpoint.type() == Ice.TCPEndpointType.value && ipEndpoint instanceof Ice.TCPEndpointInfo || + ipEndpoint.type() == IceSSL.EndpointType.value && ipEndpoint instanceof IceSSL.EndpointInfo); + + Ice.UDPEndpointInfo udpEndpoint = (Ice.UDPEndpointInfo)endps[1].getInfo(); + test(udpEndpoint.host.equals("udphost")); + test(udpEndpoint.port == 10001); + test(udpEndpoint.mcastInterface.equals("eth0")); + test(udpEndpoint.mcastTtl == 5); + test(udpEndpoint.timeout == -1); + test(!udpEndpoint.compress); + test(!udpEndpoint.secure()); + test(udpEndpoint.datagram()); + test(udpEndpoint.type() == 3); + + Ice.OpaqueEndpointInfo opaqueEndpoint = (Ice.OpaqueEndpointInfo)endps[2].getInfo(); + } + out.println("ok"); + + String defaultHost = communicator.getProperties().getProperty("Ice.Default.Host"); + out.print("test object adapter endpoint information... "); + out.flush(); + { + communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -t 15000:udp"); + Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter"); + + Ice.Endpoint[] endpoints = adapter.getEndpoints(); + test(endpoints.length == 2); + Ice.Endpoint[] publishedEndpoints = adapter.getPublishedEndpoints(); + test(java.util.Arrays.equals(endpoints, publishedEndpoints)); + + Ice.IPEndpointInfo ipEndpoint = (Ice.IPEndpointInfo)endpoints[0].getInfo(); + test(ipEndpoint.type() == Ice.TCPEndpointType.value || ipEndpoint.type() == IceSSL.EndpointType.value); + test(ipEndpoint.host.equals(defaultHost)); + test(ipEndpoint.port > 0); + test(ipEndpoint.timeout == 15000); + + Ice.UDPEndpointInfo udpEndpoint = (Ice.UDPEndpointInfo)endpoints[1].getInfo(); + test(udpEndpoint.host.equals(defaultHost)); + test(udpEndpoint.datagram()); + test(udpEndpoint.port > 0); + + adapter.destroy(); + + communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -h * -p 12010"); + communicator.getProperties().setProperty("TestAdapter.PublishedEndpoints", "default -h 127.0.0.1 -p 12010"); + adapter = communicator.createObjectAdapter("TestAdapter"); + + endpoints = adapter.getEndpoints(); + test(endpoints.length >= 1); + publishedEndpoints = adapter.getPublishedEndpoints(); + test(publishedEndpoints.length == 1); + + for(Ice.Endpoint endpoint : endpoints) + { + ipEndpoint = (Ice.IPEndpointInfo)endpoint.getInfo(); + test(ipEndpoint.port == 12010); + } + + ipEndpoint = (Ice.IPEndpointInfo)publishedEndpoints[0].getInfo(); + test(ipEndpoint.host.equals("127.0.0.1")); + test(ipEndpoint.port == 12010); + + adapter.destroy(); + } + out.println("ok"); + + communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010:udp -p 12010"); + communicator.getProperties().setProperty("TestAdapter.PublishedEndpoints", ""); + Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter"); + Ice.ObjectPrx base = adapter.addWithUUID(new TestI()).ice_collocationOptimized(false); + adapter.activate(); + + TestIntfPrx test = TestIntfPrxHelper.uncheckedCast(base); + + out.print("test connection endpoint information... "); + out.flush(); + { + Ice.EndpointInfo info = base.ice_getConnection().getEndpoint().getInfo(); + Ice.IPEndpointInfo ipinfo = (Ice.IPEndpointInfo)info; + test(ipinfo.port == 12010); + test(!ipinfo.compress); + test(ipinfo.host.equals(defaultHost)); + + java.util.Map<String, String> ctx = test.getEndpointInfoAsContext(); + test(ctx.get("host").equals(ipinfo.host)); + test(ctx.get("compress").equals("false")); + int port = Integer.parseInt(ctx.get("port")); + test(port > 0); + + info = base.ice_datagram().ice_getConnection().getEndpoint().getInfo(); + Ice.UDPEndpointInfo udp = (Ice.UDPEndpointInfo)info; + test(udp.port == 12010); + test(udp.host.equals(defaultHost)); + } + out.println("ok"); + + out.print("testing connection information... "); + out.flush(); + { + Ice.IPConnectionInfo info = (Ice.IPConnectionInfo)base.ice_getConnection().getInfo(); + test(!info.incoming); + test(info.adapterName.length() == 0); + test(info.remotePort == 12010); + test(info.remoteAddress.equals(defaultHost)); + test(info.localAddress.equals(defaultHost)); + + java.util.Map<String, String> ctx = test.getConnectionInfoAsContext(); + test(ctx.get("incoming").equals("true")); + test(ctx.get("adapterName").equals("TestAdapter")); + test(ctx.get("remoteAddress").equals(info.localAddress)); + test(ctx.get("localAddress").equals(info.remoteAddress)); + test(ctx.get("remotePort").equals(Integer.toString(info.localPort))); + test(ctx.get("localPort").equals(Integer.toString(info.remotePort))); + } + out.println("ok"); + + communicator.shutdown(); + communicator.waitForShutdown(); + } +} diff --git a/java/test/Ice/info/Client.java b/java/test/Ice/info/Client.java new file mode 100644 index 00000000000..6da2d2fe6de --- /dev/null +++ b/java/test/Ice/info/Client.java @@ -0,0 +1,35 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 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 test.Ice.info; + +public class Client extends test.Util.Application +{ + public int run(String[] args) + { + AllTests.allTests(communicator(), getWriter()); + return 0; + } + + protected Ice.InitializationData getInitData(Ice.StringSeqHolder argsH) + { + Ice.InitializationData initData = new Ice.InitializationData(); + initData.properties = Ice.Util.createProperties(argsH); + initData.properties.setProperty("Ice.Package.Test", "test.Ice.info"); + return initData; + } + + public static void main(String[] args) + { + Client app = new Client(); + int result = app.main("Client", args); + System.gc(); + System.exit(result); + } +} diff --git a/java/test/Ice/info/Test.ice b/java/test/Ice/info/Test.ice new file mode 100644 index 00000000000..6b95fe13feb --- /dev/null +++ b/java/test/Ice/info/Test.ice @@ -0,0 +1,30 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 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. +// +// ********************************************************************** + +#ifndef TEST_ICE +#define TEST_ICE + +#include <Ice/Current.ice> + +[["java:package:test.Ice.info"]] +module Test +{ + +interface TestIntf +{ + void shutdown(); + + Ice::Context getEndpointInfoAsContext(); + + Ice::Context getConnectionInfoAsContext(); +}; + +}; + +#endif diff --git a/java/test/Ice/info/TestI.java b/java/test/Ice/info/TestI.java new file mode 100644 index 00000000000..23548cb1289 --- /dev/null +++ b/java/test/Ice/info/TestI.java @@ -0,0 +1,67 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 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 test.Ice.info; +import test.Ice.info.Test._TestIntfDisp; + +public class TestI extends _TestIntfDisp +{ + TestI() + { + } + + public void shutdown(Ice.Current current) + { + current.adapter.getCommunicator().shutdown(); + } + + public java.util.Map<String, String> getEndpointInfoAsContext(Ice.Current c) + { + java.util.Map<String, String> ctx = new java.util.HashMap<String, String>(); + Ice.EndpointInfo info = c.con.getEndpoint().getInfo(); + ctx.put("timeout", Integer.toString(info.timeout)); + ctx.put("compress", info.compress ? "true" : "false"); + ctx.put("datagram", info.datagram() ? "true" : "false"); + ctx.put("secure", info.datagram() ? "true" : "false"); + ctx.put("type", Integer.toString(info.type())); + + Ice.IPEndpointInfo ipinfo = (Ice.IPEndpointInfo)info; + ctx.put("host", ipinfo.host); + ctx.put("port", Integer.toString(ipinfo.port)); + + if(ipinfo instanceof Ice.UDPEndpointInfo) + { + Ice.UDPEndpointInfo udp = (Ice.UDPEndpointInfo)ipinfo; + ctx.put("protocolMajor", Byte.toString(udp.protocolMajor)); + ctx.put("protocolMinor", Byte.toString(udp.protocolMinor)); + ctx.put("encodingMajor", Byte.toString(udp.encodingMajor)); + ctx.put("encodingMinor", Byte.toString(udp.encodingMinor)); + ctx.put("mcastInterface", udp.mcastInterface); + ctx.put("mcastTtl", Integer.toString(udp.mcastTtl)); + } + + return ctx; + } + + public java.util.Map<String, String> getConnectionInfoAsContext(Ice.Current c) + { + java.util.Map<String, String> ctx = new java.util.HashMap<String, String>(); + Ice.ConnectionInfo info = c.con.getInfo(); + ctx.put("adapterName", info.adapterName); + ctx.put("incoming", info.incoming ? "true" : "false"); + + Ice.IPConnectionInfo ipinfo = (Ice.IPConnectionInfo)info; + ctx.put("localAddress", ipinfo.localAddress); + ctx.put("localPort", Integer.toString(ipinfo.localPort)); + ctx.put("remoteAddress", ipinfo.remoteAddress); + ctx.put("remotePort", Integer.toString(ipinfo.remotePort)); + + return ctx; + } +} diff --git a/java/test/Ice/info/run.py b/java/test/Ice/info/run.py new file mode 100755 index 00000000000..4ebbde42d9a --- /dev/null +++ b/java/test/Ice/info/run.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2009 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. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise "can't find toplevel directory!" +sys.path.append(os.path.join(path[0])) +from scripts import * + +print "starting client...", +clientProc = TestUtil.startClient("test.Ice.info.Client") +print "ok" + +clientProc.waitTestSuccess() + +TestUtil.cleanup() diff --git a/java/test/Ice/proxy/AllTests.java b/java/test/Ice/proxy/AllTests.java index 4d1f804e9c6..208cb87e32c 100644 --- a/java/test/Ice/proxy/AllTests.java +++ b/java/test/Ice/proxy/AllTests.java @@ -430,6 +430,11 @@ public class AllTests compObj2 = communicator.stringToProxy("foo@MyAdapter1"); test(!compObj1.equals(compObj2)); + Ice.Endpoint[] endpts1 = communicator.stringToProxy("foo:tcp -h 127.0.0.1 -p 10000").ice_getEndpoints(); + Ice.Endpoint[] endpts2 = communicator.stringToProxy("foo:tcp -h 127.0.0.1 -p 10001").ice_getEndpoints(); + test(!endpts1[0].equals(endpts2[0])); + test(endpts1[0].equals(communicator.stringToProxy("foo:tcp -h 127.0.0.1 -p 10000").ice_getEndpoints()[0])); + // // TODO: Ideally we should also test comparison of fixed proxies. // @@ -646,32 +651,6 @@ public class AllTests } out.println("ok"); - out.print("testing endpoint information... "); - out.flush(); - - Ice.ObjectPrx p = communicator.stringToProxy("test -t:tcp -h tcphost -p 10000 -t 1200 -z:udp -h udphost -p 10001 --interface eth0 --ttl 5:opaque -t 100 -v ABCD"); - Ice.Endpoint[] endps = p.ice_getEndpoints(); - - test(endps[0].getInfo() instanceof Ice.TcpEndpointInfo); - Ice.TcpEndpointInfo tcpEndpoint = (Ice.TcpEndpointInfo)endps[0].getInfo(); - test(tcpEndpoint.host.equals("tcphost")); - test(tcpEndpoint.port == 10000); - test(tcpEndpoint.timeout == 1200); - test(tcpEndpoint.compress); - - test(endps[1].getInfo() instanceof Ice.UdpEndpointInfo); - Ice.UdpEndpointInfo udpEndpoint = (Ice.UdpEndpointInfo)endps[1].getInfo(); - test(udpEndpoint.host.equals("udphost")); - test(udpEndpoint.port == 10001); - test(udpEndpoint.mcastInterface.equals("eth0")); - test(udpEndpoint.mcastTtl == 5); - test(udpEndpoint.timeout == -1); - test(!udpEndpoint.compress); - - test(endps[2].getInfo() instanceof Ice.OpaqueEndpointInfo); - - out.println("ok"); - return cl; } } diff --git a/java/test/IceSSL/configuration/AllTests.java b/java/test/IceSSL/configuration/AllTests.java index bf7fba3f762..6f8ad228f67 100644 --- a/java/test/IceSSL/configuration/AllTests.java +++ b/java/test/IceSSL/configuration/AllTests.java @@ -162,10 +162,10 @@ public class AllTests // try { - IceSSL.ConnectionInfo info = IceSSL.Util.getConnectionInfo(server.ice_getConnection()); - test(info.certs.length == 2); + IceSSL.NativeConnectionInfo info = (IceSSL.NativeConnectionInfo)server.ice_getConnection().getInfo(); + test(info.nativeCerts.length == 2); } - catch(IceSSL.ConnectionInvalidException ex) + catch(Ice.LocalException ex) { test(false); } @@ -317,12 +317,12 @@ public class AllTests java.security.cert.X509Certificate caCert = (java.security.cert.X509Certificate)serverKeystore.getCertificate("cacert"); - IceSSL.ConnectionInfo info = IceSSL.Util.getConnectionInfo(server.ice_getConnection()); + IceSSL.NativeConnectionInfo info = (IceSSL.NativeConnectionInfo)server.ice_getConnection().getInfo(); - test(info.certs.length == 2); + test(info.nativeCerts.length == 2); - test(caCert.equals(info.certs[1])); - test(serverCert.equals(info.certs[0])); + test(caCert.equals(info.nativeCerts[1])); + test(serverCert.equals(info.nativeCerts[0])); } catch(Exception ex) { @@ -584,7 +584,7 @@ public class AllTests { String cipherSub = "DH_anon"; server.checkCipher(cipherSub); - IceSSL.ConnectionInfo info = IceSSL.Util.getConnectionInfo(server.ice_getConnection()); + IceSSL.NativeConnectionInfo info = (IceSSL.NativeConnectionInfo)server.ice_getConnection().getInfo(); test(info.cipher.indexOf(cipherSub) >= 0); } catch(Ice.LocalException ex) diff --git a/java/test/IceSSL/configuration/CertificateVerifierI.java b/java/test/IceSSL/configuration/CertificateVerifierI.java index 570860ddbd4..ce25fad0d3e 100644 --- a/java/test/IceSSL/configuration/CertificateVerifierI.java +++ b/java/test/IceSSL/configuration/CertificateVerifierI.java @@ -19,14 +19,14 @@ public class CertificateVerifierI implements IceSSL.CertificateVerifier } public boolean - verify(IceSSL.ConnectionInfo info) + verify(IceSSL.NativeConnectionInfo info) { - if(info.certs != null) + if(info.nativeCerts != null) { try { java.util.Collection<java.util.List<?> > subjectAltNames = - ((java.security.cert.X509Certificate)info.certs[0]).getSubjectAlternativeNames(); + ((java.security.cert.X509Certificate)info.nativeCerts[0]).getSubjectAlternativeNames(); test(subjectAltNames != null); java.util.List<String> ipAddresses = new java.util.ArrayList<String>(); java.util.List<String> dnsNames = new java.util.ArrayList<String>(); @@ -53,7 +53,7 @@ public class CertificateVerifierI implements IceSSL.CertificateVerifier } } - _hadCert = info.certs != null; + _hadCert = info.nativeCerts != null; _invoked = true; return _returnValue; } diff --git a/java/test/IceSSL/configuration/ServerI.java b/java/test/IceSSL/configuration/ServerI.java index 8a6f5ce3816..91e60bebd85 100644 --- a/java/test/IceSSL/configuration/ServerI.java +++ b/java/test/IceSSL/configuration/ServerI.java @@ -22,10 +22,10 @@ class ServerI extends _ServerDisp { try { - IceSSL.ConnectionInfo info = IceSSL.Util.getConnectionInfo(current.con); + IceSSL.NativeConnectionInfo info = (IceSSL.NativeConnectionInfo)current.con.getInfo(); test(info.certs == null); } - catch(IceSSL.ConnectionInvalidException ex) + catch(Ice.LocalException ex) { test(false); } @@ -36,13 +36,13 @@ class ServerI extends _ServerDisp { try { - IceSSL.ConnectionInfo info = IceSSL.Util.getConnectionInfo(current.con); - java.security.cert.X509Certificate cert = (java.security.cert.X509Certificate)info.certs[0]; - test(info.certs.length == 2 && + IceSSL.NativeConnectionInfo info = (IceSSL.NativeConnectionInfo)current.con.getInfo(); + java.security.cert.X509Certificate cert = (java.security.cert.X509Certificate)info.nativeCerts[0]; + test(info.nativeCerts.length == 2 && cert.getSubjectDN().toString().equals(subjectDN) && cert.getIssuerDN().toString().equals(issuerDN)); } - catch(IceSSL.ConnectionInvalidException ex) + catch(Ice.LocalException ex) { test(false); } @@ -53,10 +53,10 @@ class ServerI extends _ServerDisp { try { - IceSSL.ConnectionInfo info = IceSSL.Util.getConnectionInfo(current.con); + IceSSL.NativeConnectionInfo info = (IceSSL.NativeConnectionInfo)current.con.getInfo(); test(info.cipher.indexOf(cipher) >= 0); } - catch(IceSSL.ConnectionInvalidException ex) + catch(Ice.LocalException ex) { test(false); } |