SV.WEAK.TLS
Weak SSL/TLS protocols should not be used.
Klocwork reports an SV.WEAK.TLS defect if a weak TLS protocol such as 1.0 or 1.1 is used.
Vulnerability and risk
Security experts widely recommend enforcing TLS 1.2 as the minimum protocol version; they recommend disallowing older versions, such as TLS 1.0 or 1.1. Failure to do so can open the door to downgrade attacks where a malicious actor who is able to intercept the connection could modify the requested protocol version and downgrade it to a less secure version.
Mitigation and prevention
More secure protocols like TLS 1.2 and later versions should be used.
Vulnerable code example 1
import javax.net.ssl.*;
public class Test {
public void test() throws Exception {
SSLContext context = SSLContext.getInstance("TLSv1.1");
}
}
Klocwork reports an SV.WEAK.TLS defect on line 4, indicating, "Recommended to enforce TLS 1.2 as the minimum protocol version and to disallow older versions like TLS 1.0/1.1 as it is less secure."
Fixed code example 1
import javax.net.ssl.*;
public class Test {
public void test() throws Exception {
SSLContext context = SSLContext.getInstance("TLSv1.2");
}
}
Klocwork no longer reports a defect because TLS 1.2 is used.
Vulnerable code example 2
import javax.net.ssl.*;
public class Test {
public void test() {
SSLSocket socket = null;
try {
SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault();
socket = (SSLSocket) factory.createSocket("abc.com", 443);
socket.setEnabledProtocols(new String[] {"TLSv1.0"});
socket.startHandshake();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (socket != null) {
socket.close();
}
}
}
}
Klocwork reports an SV.WEAK.TLS defect on line 7, indicating, "Recommended to enforce TLS 1.2 as the minimum protocol version and to disallow older versions like TLS 1.0/1.1 as it is less secure."
Fixed code example 2
import javax.net.ssl.*;
public class Test {
public void test() {
SSLSocket socket = null;
try {
SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault();
socket = (SSLSocket) factory.createSocket("abc.com", 443);
socket.setEnabledProtocols(new String[] {"TLSv1.2"});
socket.startHandshake();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (socket != null) {
socket.close();
}
}
}
}
Klocwork no longer reports a defect because TLS 1.2 is used.
Vulnerable code example 3
import javax.net.ssl.*;
public class Test {
public void test() {
SSLServerSocket serverSocket = null;
try {
SSLServerSocketFactory factory = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
serverSocket = (SSLServerSocket) factory.createServerSocket(8980);
SSLParameters params = new SSLParameters();
params.setProtocols(new String[] {"TLSv1.1"});
serverSocket.setSSLParameters(params);
SSLSocket sslSocket = (SSLSocket) serverSocket.accept();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (serverSocket != null) {
serverSocket.close();
}
}
}
}
Klocwork reports an SV.WEAK.TLS defect on line 9, indicating, "Recommended to enforce TLS 1.2 as the minimum protocol version and to disallow older versions like TLS 1.0/1.1 as it is less secure."
Fixed code example 3
import javax.net.ssl.*;
public class Test {
public void test() {
SSLServerSocket serverSocket = null;
try {
SSLServerSocketFactory factory = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
serverSocket = (SSLServerSocket) factory.createServerSocket(8980);
SSLParameters params = new SSLParameters();
params.setProtocols(new String[] {"TLSv1.3"});
serverSocket.setSSLParameters(params);
SSLSocket sslSocket = (SSLSocket) serverSocket.accept();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (serverSocket != null) {
serverSocket.close();
}
}
}
}
Klocwork no longer reports a defect because TLS 1.3 is used.
External guidance
- CERT MSC00-J: Use SSLSocket rather than Socket for secure data exchange
- CWE-326: Inadequate Encryption Strength
- CWE-327: Use of a Broken or Risky Cryptographic Algorithm
- OWASP A3:2017 Sensitive Data Exposure
- OWASP A6:2017 Security Misconfiguration
- OWASP A2:2021 Cryptographic Failures
- OWASP A7:2021 Identification and Authentication Failures
- V-222555 (APSC-DV-001860): The application must use mechanisms meeting the requirements of applicable federal laws, Executive Orders, directives, policies, regulations, standards, and guidance for authentication to a cryptographic module.
Security training
Application security training materials provided by Secure Code Warrior.