< prev index next >

test/lib/security/SecurityUtils.java

Print this page
rev 14340 : 8202343: Disable TLS 1.0 and 1.1
Reviewed-by: xuelei, dfuchs, coffeys

*** 1,7 **** /* ! * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,7 ---- /* ! * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 22,31 **** --- 22,36 ---- */ import java.io.File; import java.io.FileInputStream; import java.security.KeyStore; + import java.security.Security; + import java.util.Arrays; + import java.util.Collections; + import java.util.List; + import java.util.stream.Collectors; /** * Common library for various security test helper functions. */ public final class SecurityUtils {
*** 50,56 **** --- 55,81 ---- ks.load(fis, null); } return ks; } + /** + * Removes the specified protocols from the jdk.tls.disabledAlgorithms + * security property. + */ + public static void removeFromDisabledTlsAlgs(String... protocols) { + List<String> protocolsList = Arrays.asList(protocols); + protocolsList = Collections.unmodifiableList(protocolsList); + removeFromDisabledAlgs("jdk.tls.disabledAlgorithms", + protocolsList); + } + + private static void removeFromDisabledAlgs(String prop, List<String> algs) { + String value = Security.getProperty(prop); + value = Arrays.stream(value.split(",")) + .map(s -> s.trim()) + .filter(s -> !algs.contains(s)) + .collect(Collectors.joining(",")); + Security.setProperty(prop, value); + } + private SecurityUtils() {} }
< prev index next >