From 8b0de5ff85ceb52cfc71d9ac95ff2a211f7e2873 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sun, 5 Apr 2020 22:26:18 +0200 Subject: [PATCH] Introduce TLSUtils.setEnabledTlsProtocolsToRecommended(B builder) And deprecate no longer recommended methods. Thanks to Milan Kral for the initial PR which triggered this commit. --- .../org/jivesoftware/smack/util/TLSUtils.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/TLSUtils.java b/smack-core/src/main/java/org/jivesoftware/smack/util/TLSUtils.java index cba78280f..60c644320 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/TLSUtils.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/TLSUtils.java @@ -61,6 +61,20 @@ public class TLSUtils { public static final String PROTO_TLSV1 = TLS + "v1"; public static final String PROTO_TLSV1_1 = TLS + "v1.1"; public static final String PROTO_TLSV1_2 = TLS + "v1.2"; + public static final String PROTO_TLSV1_3 = TLS + "v1.3"; + + /** + * Enable the recommended TLS protocols. + * + * @param builder the configuration builder to apply this setting to + * @param Type of the ConnectionConfiguration builder. + * + * @return the given builder + */ + public static > B setEnabledTlsProtocolsToRecommended(B builder) { + builder.setEnabledSSLProtocols(new String[] { PROTO_TLSV1_3, PROTO_TLSV1_2 }); + return builder; + } /** * Enable only TLS. Connections created with the given ConnectionConfiguration will only support TLS. @@ -76,7 +90,10 @@ public class TLSUtils { * @param Type of the ConnectionConfiguration builder. * * @return the given builder + * @deprecated use {@link #setEnabledTlsProtocolsToRecommended(org.jivesoftware.smack.ConnectionConfiguration.Builder)} instead. */ + // TODO: Remove in Smack 4.5. + @Deprecated public static > B setTLSOnly(B builder) { builder.setEnabledSSLProtocols(new String[] { PROTO_TLSV1_2, PROTO_TLSV1_1, PROTO_TLSV1 }); return builder; @@ -96,7 +113,10 @@ public class TLSUtils { * @param Type of the ConnectionConfiguration builder. * * @return the given builder + * @deprecated use {@link #setEnabledTlsProtocolsToRecommended(org.jivesoftware.smack.ConnectionConfiguration.Builder)} instead. */ + // TODO: Remove in Smack 4.5. + @Deprecated public static > B setSSLv3AndTLSOnly(B builder) { builder.setEnabledSSLProtocols(new String[] { PROTO_TLSV1_2, PROTO_TLSV1_1, PROTO_TLSV1, PROTO_SSL3 }); return builder;