Skip to content

Commit

Permalink
Java fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pepone committed May 7, 2024
1 parent cb98498 commit d8d8c89
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 119 deletions.
34 changes: 18 additions & 16 deletions java/src/Ice/src/main/java/com/zeroc/Ice/SSL/SSLEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public SSLEngine(com.zeroc.Ice.Communicator communicator) {
_communicator = communicator;
_logger = _communicator.getLogger();
_securityTraceLevel =
_communicator.getProperties().getPropertyAsIntWithDefault("Ice.SSL.Trace.Security", 0);
_communicator.getProperties().getPropertyAsIntWithDefault("IceSSL.Trace.Security", 0);
_securityTraceCategory = "Security";
_trustManager = new TrustManager(_communicator);
}

public void initialize() {
final String prefix = "Ice.SSL.";
final String prefix = "IceSSL.";
com.zeroc.Ice.Properties properties = communicator().getProperties();

//
Expand All @@ -45,7 +45,7 @@ public void initialize() {
// VerifyPeer determines whether certificate validation failures abort a
// connection.
//
_verifyPeer = properties.getPropertyAsIntWithDefault("Ice.SSL.VerifyPeer", 2);
_verifyPeer = properties.getPropertyAsIntWithDefault("IceSSL.VerifyPeer", 2);

//
// If the user doesn't supply an SSLContext, we need to create one based
Expand Down Expand Up @@ -121,7 +121,8 @@ public void initialize() {
} else {
keystoreStream = openResource(keystorePath);
if (keystoreStream == null) {
throw new InitializationException("Ice.SSL: keystore not found:\n" + keystorePath);
throw new InitializationException(
"SSL transport: keystore not found:\n" + keystorePath);
}
}

Expand All @@ -142,7 +143,7 @@ public void initialize() {
keystorePassword = null;
} catch (java.io.IOException ex) {
throw new InitializationException(
"Ice.SSL: unable to load keystore:\n" + keystorePath, ex);
"SSL transport: unable to load keystore:\n" + keystorePath, ex);
} finally {
if (keystoreStream != null) {
try {
Expand Down Expand Up @@ -192,7 +193,7 @@ public void initialize() {
//
if (!keys.isKeyEntry(alias)) {
throw new InitializationException(
"Ice.SSL: keystore does not contain an entry with alias `" + alias + "'");
"SSL trasnsport: keystore does not contain an entry with alias `" + alias + "'");
}

for (int i = 0; i < keyManagers.length; ++i) {
Expand Down Expand Up @@ -225,7 +226,7 @@ public void initialize() {
truststoreStream = openResource(truststorePath);
if (truststoreStream == null) {
throw new InitializationException(
"Ice.SSL: truststore not found:\n" + truststorePath);
"SSL transport: truststore not found:\n" + truststorePath);
}
}

Expand All @@ -247,7 +248,7 @@ public void initialize() {
truststorePassword = null;
} catch (java.io.IOException ex) {
throw new InitializationException(
"Ice.SSL: unable to load truststore:\n" + truststorePath, ex);
"SSL transport: unable to load truststore:\n" + truststorePath, ex);
} finally {
if (truststoreStream != null) {
try {
Expand All @@ -261,7 +262,7 @@ public void initialize() {
}

//
// Collect the trust managers. Use Ice.SSL.Truststore if
// Collect the trust managers. Use IceSSL.Truststore if
// specified, otherwise use the Java root CAs if
// Ice.Use.PlatformCAs is enabled. If none of these are enabled,
// use the keystore or a dummy trust manager which rejects any
Expand All @@ -275,7 +276,7 @@ public void initialize() {
java.security.KeyStore trustStore = null;
if (ts != null) {
trustStore = ts;
} else if (properties.getPropertyAsInt("Ice.SSL.UsePlatformCAs") <= 0) {
} else if (properties.getPropertyAsInt("IceSSL.UsePlatformCAs") <= 0) {
if (keys != null) {
trustStore = keys;
} else {
Expand Down Expand Up @@ -313,7 +314,7 @@ public X509Certificate[] getAcceptedIssuers() {
// must be non-empty
//
if (trustStore != null && trustStore.size() == 0) {
throw new InitializationException("Ice.SSL: truststore is empty");
throw new InitializationException("SSL transport: truststore is empty");
}

if (trustManagers == null) {
Expand All @@ -329,7 +330,7 @@ public X509Certificate[] getAcceptedIssuers() {
_context = javax.net.ssl.SSLContext.getInstance("TLS");
_context.init(keyManagers, trustManagers, null);
} catch (java.security.GeneralSecurityException ex) {
throw new InitializationException("Ice.SSL: unable to initialize context", ex);
throw new InitializationException("SSL transport: unable to initialize context", ex);
}
}

Expand Down Expand Up @@ -358,7 +359,7 @@ javax.net.ssl.SSLEngine createSSLEngine(boolean incoming, String host, int port)
}
engine.setUseClientMode(!incoming);
} catch (Exception ex) {
throw new com.zeroc.Ice.SecurityException("Ice.SSL: couldn't create SSL engine", ex);
throw new com.zeroc.Ice.SecurityException("SSL transport: couldn't create SSL engine", ex);
}

if (incoming) {
Expand Down Expand Up @@ -421,12 +422,13 @@ com.zeroc.Ice.Communicator communicator() {

void verifyPeer(String address, ConnectionInfo info, String desc) {
//
// Ice.SSL.VerifyPeer is translated into the proper SSLEngine configuration
// IceSSL.VerifyPeer is translated into the proper SSLEngine configuration
// for a server, but we have to do it ourselves for a client.
//
if (!info.incoming) {
if (_verifyPeer > 0 && !info.verified) {
throw new com.zeroc.Ice.SecurityException("Ice.SSL: server did not supply a certificate");
throw new com.zeroc.Ice.SecurityException(
"SSL trasnsport: server did not supply a certificate");
}
}

Expand Down Expand Up @@ -476,7 +478,7 @@ private java.io.InputStream openResource(String path) throws java.io.IOException
com.zeroc.IceInternal.Util.openResource(getClass().getClassLoader(), path);

//
// If the first attempt fails and Ice.SSL.DefaultDir is defined and the original
// If the first attempt fails and IceSSL.DefaultDir is defined and the original
// path is
// relative,
// we prepend the default directory and try again.
Expand Down
15 changes: 5 additions & 10 deletions java/src/Ice/src/main/java/com/zeroc/Ice/SSL/TransceiverI.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public int initialize(
_engine.beginHandshake();
} catch (javax.net.ssl.SSLException ex) {
_engine = null;
throw new com.zeroc.Ice.SecurityException("Ice.SSL: handshake error", ex);
throw new com.zeroc.Ice.SecurityException("SSL transport: handshake error", ex);
}

_appInput = ByteBuffer.allocate(_engine.getSession().getApplicationBufferSize() * 2);
Expand Down Expand Up @@ -121,12 +121,7 @@ public void close() {
}
}
} catch (SSLException ex) {
//
// We can't throw in close.
//
// Ice.SecurityException se = new Ice.SecurityException(
// "Ice.SSL: SSL failure while shutting down socket", ex);
//
}

try {
Expand All @@ -140,7 +135,7 @@ public void close() {
// We would probably need to wait for a response in shutdown() to avoid this.
// For now, we'll ignore this exception.
//
// _instance.logger().error("Ice.SSL: error during close\n" + ex.getMessage());
// _instance.logger().error("SSL transport: error during close\n" + ex.getMessage());
}
}

Expand Down Expand Up @@ -219,7 +214,7 @@ else if (status == Status.BUFFER_UNDERFLOW
// the buffer with a complete request which must be processed.
}
} catch (SSLException ex) {
throw new com.zeroc.Ice.SecurityException("Ice.SSL: error during read", ex);
throw new com.zeroc.Ice.SecurityException("SSL transport: error during read", ex);
}

//
Expand Down Expand Up @@ -399,7 +394,7 @@ private int handshakeNonBlocking() {
}
}
} catch (SSLException ex) {
throw new com.zeroc.Ice.SecurityException("Ice.SSL: handshake error", ex);
throw new com.zeroc.Ice.SecurityException("SSL transport: handshake error", ex);
}
return SocketOperation.None;
}
Expand Down Expand Up @@ -446,7 +441,7 @@ private int writeNonBlocking(ByteBuffer buf) {
}
}
} catch (SSLException ex) {
throw new com.zeroc.Ice.SecurityException("Ice.SSL: error while encoding message", ex);
throw new com.zeroc.Ice.SecurityException("SSL transport: error while encoding message", ex);
}

assert (_netOutput.b.position() == 0);
Expand Down
12 changes: 6 additions & 6 deletions java/src/Ice/src/main/java/com/zeroc/Ice/SSL/TrustManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ class TrustManager {
assert communicator != null;
_communicator = communicator;
com.zeroc.Ice.Properties properties = communicator.getProperties();
_traceLevel = properties.getPropertyAsInt("Ice.SSL.Trace.Security");
_traceLevel = properties.getPropertyAsInt("IceSSL.Trace.Security");
String key = null;
try {
key = "Ice.SSL.TrustOnly";
key = "IceSSL.TrustOnly";
parse(properties.getProperty(key), _rejectAll, _acceptAll);
key = "Ice.SSL.TrustOnly.Client";
key = "IceSSL.TrustOnly.Client";
parse(properties.getProperty(key), _rejectClient, _acceptClient);
key = "Ice.SSL.TrustOnly.Server";
key = "IceSSL.TrustOnly.Server";
parse(properties.getProperty(key), _rejectAllServer, _acceptAllServer);
java.util.Map<String, String> dict =
properties.getPropertiesForPrefix("Ice.SSL.TrustOnly.Server.");
properties.getPropertiesForPrefix("IceSSL.TrustOnly.Server.");
for (java.util.Map.Entry<String, String> p : dict.entrySet()) {
key = p.getKey();
String name = key.substring("Ice.SSL.TrustOnly.Server.".length());
String name = key.substring("IceSSL.TrustOnly.Server.".length());
java.util.List<java.util.List<RFC2253.RDNPair>> reject =
new java.util.LinkedList<java.util.List<RFC2253.RDNPair>>();
java.util.List<java.util.List<RFC2253.RDNPair>> accept =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,7 @@ private static com.zeroc.Ice.Communicator createSendLogCommunicator(
com.zeroc.Ice.Properties mainProps = communicator.getProperties();

copyProperties("Ice.Default.Locator", mainProps, initData.properties);
copyProperties("Ice.Plugin.Ice.SSL", mainProps, initData.properties);
copyProperties("Ice.SSL.", mainProps, initData.properties);
copyProperties("IceSSL.", mainProps, initData.properties);

String[] extraProps = mainProps.getPropertyAsList("Ice.Admin.Logger.Properties");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,11 @@ public ControllerHelperI(TestSuiteBundle bundle, String[] args) {

public void communicatorInitialized(Communicator communicator) {
com.zeroc.Ice.Properties properties = communicator.getProperties();
if (properties.getProperty("Ice.Plugin.Ice.SSL").equals("com.zeroc.Ice.SSL.PluginFactory")) {
if (properties.getProperty("Ice.Plugin.IceSSL").equals("com.zeroc.IceSSL.PluginFactory")) {
com.zeroc.Ice.SSL.Plugin plugin =
(com.zeroc.Ice.SSL.Plugin) communicator.getPluginManager().getPlugin("Ice.SSL");
String keystore = communicator.getProperties().getProperty("Ice.SSL.Keystore");
properties.setProperty("Ice.SSL.Keystore", "");
(com.zeroc.Ice.SSL.Plugin) communicator.getPluginManager().getPlugin("IceSSL");
String keystore = communicator.getProperties().getProperty("IceSSL.Keystore");
properties.setProperty("IceSSL.Keystore", "");
int resource = keystore.equals("client.bks") ? R.raw.client : R.raw.server;
java.io.InputStream certs = getResources().openRawResource(resource);
plugin.setKeystoreStream(certs);
Expand Down
6 changes: 3 additions & 3 deletions java/test/src/main/java/test/Ice/properties/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ public void run(String[] args) {
System.out.print("testing ice properties with unset default values...");
Properties properties = Util.createProperties();

String stringValue = properties.getIceProperty("Ice.SSL.CAs");
String stringValue = properties.getIceProperty("IceSSL.CAs");
test(stringValue.isEmpty());

int intValue = properties.getIcePropertyAsInt("Ice.SSL.CAs");
int intValue = properties.getIcePropertyAsInt("IceSSL.CAs");
test(intValue == 0);

String[] listValue = properties.getIcePropertyAsList("Ice.SSL.CAs");
String[] listValue = properties.getIcePropertyAsList("IceSSL.CAs");
test(listValue.length == 0);

System.out.println("ok");
Expand Down
Loading

0 comments on commit d8d8c89

Please sign in to comment.