
org.sonar.python.checks.WeakSSLProtocolCheck Maven / Gradle / Ivy
/*
* SonarQube Python Plugin
* Copyright (C) 2011-2020 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.python.checks;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Nullable;
import org.sonar.check.Rule;
import org.sonar.plugins.python.api.PythonSubscriptionCheck;
import org.sonar.plugins.python.api.tree.Name;
import org.sonar.plugins.python.api.tree.Tree;
import org.sonar.plugins.python.api.symbols.Symbol;
@Rule(key = "S4423")
public class WeakSSLProtocolCheck extends PythonSubscriptionCheck {
private static final List WEAK_PROTOCOL_CONSTANTS = Arrays.asList(
"ssl.PROTOCOL_SSLv2",
"ssl.PROTOCOL_SSLv3",
"ssl.PROTOCOL_SSLv23",
"ssl.PROTOCOL_TLS",
"ssl.PROTOCOL_TLSv1",
"ssl.PROTOCOL_TLSv1_1",
"OpenSSL.SSL.SSLv2_METHOD",
"OpenSSL.SSL.SSLv3_METHOD",
"OpenSSL.SSL.SSLv23_METHOD",
"OpenSSL.SSL.TLSv1_METHOD",
"OpenSSL.SSL.TLSv1_1_METHOD"
);
@Override
public void initialize(Context context) {
context.registerSyntaxNodeConsumer(Tree.Kind.NAME, ctx -> {
Name pyNameTree = (Name) ctx.syntaxNode();
if (isWeakProtocol(pyNameTree.symbol())) {
ctx.addIssue(pyNameTree, "Change this code to use a stronger protocol.");
}
});
}
private static boolean isWeakProtocol(@Nullable Symbol symbol) {
return symbol != null && WEAK_PROTOCOL_CONSTANTS.contains(symbol.fullyQualifiedName());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy