Skip to content

Commit a9a5a85

Browse files
committed
Java client init: no "anon" among jdk.tls.disabledAlgorithms
JDK-8211883
1 parent 45e4f7a commit a9a5a85

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

Diff for: src/main/java/omero/client.java

+36
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.io.IOException;
2828
import java.nio.ByteBuffer;
2929
import java.nio.file.Files;
30+
import java.security.Security;
3031
import java.util.ArrayList;
3132
import java.util.Arrays;
3233
import java.util.Collections;
@@ -197,6 +198,41 @@ public void run() {
197198
// Creation
198199
// =========================================================================
199200

201+
/**
202+
* Ensure that anonymous cipher suites are enabled in the JRE.
203+
*/
204+
static {
205+
final String property = "jdk.tls.disabledAlgorithms";
206+
final String value = Security.getProperty(property);
207+
if (!(value == null || value.trim().isEmpty())) {
208+
final List<String> algorithms = new ArrayList<>();
209+
boolean isChanged = false;
210+
for (String algorithm : value.split(",")) {
211+
algorithm = algorithm.trim();
212+
if (algorithm.isEmpty()) {
213+
/* ignore */
214+
} else if ("anon".equals(algorithm.toLowerCase())) {
215+
isChanged = true;
216+
} else {
217+
algorithms.add(algorithm);
218+
}
219+
}
220+
if (isChanged) {
221+
boolean needsComma = false;
222+
final StringBuilder newValue = new StringBuilder();
223+
for (final String algorithm : algorithms) {
224+
if (needsComma) {
225+
newValue.append(", ");
226+
} else {
227+
needsComma = true;
228+
}
229+
newValue.append(algorithm);
230+
}
231+
Security.setProperty(property, newValue.toString());
232+
}
233+
}
234+
}
235+
200236
private static Properties defaultRouter(String host, int port) {
201237
Properties p = new Properties();
202238
p.setProperty("omero.host", host);

0 commit comments

Comments
 (0)