Author: markt Date: Tue Jan 5 23:44:37 2016 New Revision: 1723199 URL: http://svn.apache.org/viewvc?rev=1723199&view=rev Log: Refactoring. Remove the CipherSuiteConverter as it duplicates a lot of info already in Cipher and OpenSSLCipherConfigurationParser.
Removed: tomcat/trunk/java/org/apache/tomcat/util/net/openssl/ciphers/CipherSuiteConverter.java tomcat/trunk/test/org/apache/tomcat/util/net/openssl/ciphers/TestCipherSuiteConverter.java Modified: tomcat/trunk/java/org/apache/tomcat/util/net/openssl/OpenSSLEngine.java tomcat/trunk/java/org/apache/tomcat/util/net/openssl/ciphers/Cipher.java tomcat/trunk/java/org/apache/tomcat/util/net/openssl/ciphers/OpenSSLCipherConfigurationParser.java Modified: tomcat/trunk/java/org/apache/tomcat/util/net/openssl/OpenSSLEngine.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/openssl/OpenSSLEngine.java?rev=1723199&r1=1723198&r2=1723199&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/openssl/OpenSSLEngine.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/openssl/OpenSSLEngine.java Tue Jan 5 23:44:37 2016 @@ -51,7 +51,7 @@ import org.apache.tomcat.jni.SSLContext; import org.apache.tomcat.util.buf.ByteBufferUtils; import org.apache.tomcat.util.net.Constants; import org.apache.tomcat.util.net.SSLUtil; -import org.apache.tomcat.util.net.openssl.ciphers.CipherSuiteConverter; +import org.apache.tomcat.util.net.openssl.ciphers.OpenSSLCipherConfigurationParser; import org.apache.tomcat.util.res.StringManager; /** @@ -85,7 +85,7 @@ public final class OpenSSLEngine extends if (c == null || c.length() == 0 || availableCipherSuites.contains(c)) { continue; } - availableCipherSuites.add(CipherSuiteConverter.toJava(c, "ALL")); + availableCipherSuites.add(OpenSSLCipherConfigurationParser.openSSLToJsse(c)); } } finally { SSL.freeSSL(ssl); @@ -700,7 +700,7 @@ public final class OpenSSLEngine extends return new String[0]; } else { for (int i = 0; i < enabled.length; i++) { - String mapped = toJavaCipherSuite(enabled[i]); + String mapped = OpenSSLCipherConfigurationParser.openSSLToJsse(enabled[i]); if (mapped != null) { enabled[i] = mapped; } @@ -719,7 +719,7 @@ public final class OpenSSLEngine extends if (cipherSuite == null) { break; } - String converted = CipherSuiteConverter.toOpenSsl(cipherSuite); + String converted = OpenSSLCipherConfigurationParser.jsseToOpenSSL(cipherSuite); if (converted != null) { cipherSuite = converted; } @@ -979,40 +979,6 @@ public final class OpenSSLEngine extends return SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING; } - /** - * Converts the specified OpenSSL cipher suite to the Java cipher suite. - */ - private String toJavaCipherSuite(String openSslCipherSuite) { - if (openSslCipherSuite == null) { - return null; - } - - String prefix = toJavaCipherSuitePrefix(SSL.getVersion(ssl)); - return CipherSuiteConverter.toJava(openSslCipherSuite, prefix); - } - - /** - * Converts the protocol version string returned by - * {@link SSL#getVersion(long)} to protocol family string. - */ - private static String toJavaCipherSuitePrefix(String protocolVersion) { - final char c; - if (protocolVersion == null || protocolVersion.length() == 0) { - c = 0; - } else { - c = protocolVersion.charAt(0); - } - - switch (c) { - case 'T': - return "TLS"; - case 'S': - return "SSL"; - default: - return "UNKNOWN"; - } - } - @Override public void setUseClientMode(boolean clientMode) { if (clientMode != this.clientMode) { @@ -1298,7 +1264,7 @@ public final class OpenSSLEngine extends return INVALID_CIPHER; } if (cipher == null) { - String c = toJavaCipherSuite(SSL.getCipherForSSL(ssl)); + String c = OpenSSLCipherConfigurationParser.openSSLToJsse(SSL.getCipherForSSL(ssl)); if (c != null) { cipher = c; } Modified: tomcat/trunk/java/org/apache/tomcat/util/net/openssl/ciphers/Cipher.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/openssl/ciphers/Cipher.java?rev=1723199&r1=1723198&r2=1723199&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/openssl/ciphers/Cipher.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/openssl/ciphers/Cipher.java Tue Jan 5 23:44:37 2016 @@ -21,6 +21,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; @@ -4652,7 +4653,7 @@ public enum Cipher { } else { this.openSSLAltNames = Collections.emptySet(); } - Set<String> jsseNames = new HashSet<>(); + Set<String> jsseNames = new LinkedHashSet<>(); if (jsseAltNames != null && jsseAltNames.length != 0) { jsseNames.addAll(Arrays.asList(jsseAltNames)); } Modified: tomcat/trunk/java/org/apache/tomcat/util/net/openssl/ciphers/OpenSSLCipherConfigurationParser.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/openssl/ciphers/OpenSSLCipherConfigurationParser.java?rev=1723199&r1=1723198&r2=1723199&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/openssl/ciphers/OpenSSLCipherConfigurationParser.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/openssl/ciphers/OpenSSLCipherConfigurationParser.java Tue Jan 5 23:44:37 2016 @@ -714,13 +714,45 @@ public class OpenSSLCipherConfigurationP return convertForJSSE(parse(expression)); } - public static String jsseToOpenSSL(String cipher) { + + /** + * Converts a JSSE cipher name to an OpenSSL cipher name. + * + * @param jsseCipherName The JSSE name for a cipher + * + * @return The OpenSSL name for the specified JSSE cipher + */ + public static String jsseToOpenSSL(String jsseCipherName) { if (!initialized) { init(); } - return jsseToOpenSSL.get(cipher); + return jsseToOpenSSL.get(jsseCipherName); } + + /** + * Converts an OpenSSL cipher name to a JSSE cipher name. + * + * @param opensslCipherName The OpenSSL name for a cipher + * + * @return The JSSE name for the specified OpenSSL cipher. If none is known, + * the IANA standard name will be returned instead + */ + public static String openSSLToJsse(String opensslCipherName) { + if (!initialized) { + init(); + } + List<Cipher> ciphers = aliases.get(opensslCipherName); + if (ciphers == null || ciphers.size() != 1) { + // Not an OpenSSL cipher name + return null; + } + Cipher cipher = ciphers.get(0); + // Each Cipher always has at least one JSSE name + return cipher.getJsseNames().iterator().next(); + } + + static String displayResult(Collection<Cipher> ciphers, boolean useJSSEFormat, String separator) { if (ciphers.isEmpty()) { return ""; --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org