Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create CryptographicHardwareIntrinsicsAnalyzer.cs #4005

Closed
wants to merge 12 commits into from
1 change: 1 addition & 0 deletions src/NetAnalyzers/Core/AnalyzerReleases.Unshipped.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ CA2355 | Security | Disabled | DataSetDataTableInSerializableObjectGraphAnalyzer
CA2356 | Security | Disabled | DataSetDataTableInWebSerializableObjectGraphAnalyzer, [Documentation](https://docs.microsoft.com/visualstudio/code-quality/ca2356)
CA2361 | Security | Disabled | DoNotUseDataSetReadXml, [Documentation](https://docs.microsoft.com/visualstudio/code-quality/ca2361)
CA2362 | Security | Disabled | DataSetDataTableInSerializableTypeAnalyzer, [Documentation](https://docs.microsoft.com/visualstudio/code-quality/ca2362)
CA5404 | Security | Info | CryptographicHardwareIntrinsicsAnalyzer, [Documentation](https://docs.microsoft.com/visualstudio/code-quality/ca5404)
Original file line number Diff line number Diff line change
Expand Up @@ -1266,4 +1266,13 @@
<data name="DataSetReadXmlAutogeneratedTitle" xml:space="preserve">
<value>Ensure autogenerated class containing DataSet.ReadXml() is not used with untrusted data</value>
</data>
<data name="DoNotUseCryptographicHardwareIntrinsicsDescription" xml:space="preserve">
<value>description</value>
</data>
<data name="DoNotUseCryptographicHardwareIntrinsicsMessage" xml:space="preserve">
<value>message</value>
</data>
<data name="DoNotUseCryptographicHardwareIntrinsicsTitle" xml:space="preserve">
<value>title</value>
</data>
</root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Immutable;
using Analyzer.Utilities;
using Analyzer.Utilities.Extensions;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Operations;

namespace Microsoft.NetCore.Analyzers.Security
{
[DiagnosticAnalyzer(LanguageNames.CSharp, LanguageNames.VisualBasic)]
public sealed class CryptographicHardwareIntrinsicsAnalyzer : DiagnosticAnalyzer
{
private static readonly LocalizableString s_localizableTitle = new LocalizableResourceString(nameof(MicrosoftNetCoreAnalyzersResources.DoNotUseCryptographicHardwareIntrinsicsTitle), MicrosoftNetCoreAnalyzersResources.ResourceManager, typeof(MicrosoftNetCoreAnalyzersResources));
private static readonly LocalizableString s_localizableMessage = new LocalizableResourceString(nameof(MicrosoftNetCoreAnalyzersResources.DoNotUseCryptographicHardwareIntrinsicsMessage), MicrosoftNetCoreAnalyzersResources.ResourceManager, typeof(MicrosoftNetCoreAnalyzersResources));
private static readonly LocalizableString s_localizableDescription = new LocalizableResourceString(nameof(MicrosoftNetCoreAnalyzersResources.DoNotUseCryptographicHardwareIntrinsicsDescription), MicrosoftNetCoreAnalyzersResources.ResourceManager, typeof(MicrosoftNetCoreAnalyzersResources));

internal static readonly DiagnosticDescriptor s_rule = DiagnosticDescriptorHelper.Create(
"CA5404",
s_localizableTitle,
s_localizableMessage,
DiagnosticCategory.Security,
RuleLevel.IdeSuggestion,
description: s_localizableDescription,
isPortedFxCopRule: false,
isDataflowRule: false);

public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(s_rule);

public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);

context.RegisterCompilationStartAction(
compilationStartContext =>
{
INamedTypeSymbol? symbol = compilationStartContext.Compilation.GetOrCreateTypeByMetadataName(WellKnownTypeNames.SystemRuntimeIntrinsicsX86Aes);
if (symbol is object)
{
compilationStartContext.RegisterOperationAction(
context => AnalyzeInvocation(context, symbol),
OperationKind.Invocation);

compilationStartContext.RegisterOperationAction(
context => AnalyzeMethodReference(context, symbol),
OperationKind.MethodReference);
}

});
}

private static void AnalyzeInvocation(OperationAnalysisContext context, INamedTypeSymbol symbol)
{
var operation = (IInvocationOperation)context.Operation;
var operationTargetSymbol = operation.TargetMethod.ContainingType;

if (Equals(symbol, operationTargetSymbol))
{
context.ReportDiagnostic(operation.CreateDiagnostic(s_rule));
}
}

private static void AnalyzeMethodReference(OperationAnalysisContext context, INamedTypeSymbol symbol)
{
var operation = (IMethodReferenceOperation)context.Operation;
var operationTargetSymbol = operation.Method.ContainingType;

if (Equals(symbol, operationTargetSymbol))
{
context.ReportDiagnostic(operation.CreateDiagnostic(s_rule));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,21 @@
<target state="translated">Symetrické šifrování by mělo vždy používat inicializační vektor, který nelze opakovat, aby se zabránilo slovníkovým útokům.</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsDescription">
<source>description</source>
<target state="new">description</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsMessage">
<source>message</source>
<target state="new">message</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsTitle">
<source>title</source>
<target state="new">title</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseDeprecatedSecurityProtocols">
<source>Do Not Use Deprecated Security Protocols</source>
<target state="translated">Nepoužívejte zastaralé protokoly zabezpečení.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,21 @@
<target state="translated">Für die symmetrische Verschlüsselung muss immer ein nicht wiederholbarer Initialisierungsvektor verwendet werden, um Wörterbuchangriffe zu verhindern.</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsDescription">
<source>description</source>
<target state="new">description</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsMessage">
<source>message</source>
<target state="new">message</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsTitle">
<source>title</source>
<target state="new">title</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseDeprecatedSecurityProtocols">
<source>Do Not Use Deprecated Security Protocols</source>
<target state="translated">Verwenden Sie keine veralteten Sicherheitsprotokolle.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,21 @@
<target state="translated">La clave de cifrado simétrica debe usar siempre un vector de inicialización que no se repita para evitar los ataques por diccionario.</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsDescription">
<source>description</source>
<target state="new">description</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsMessage">
<source>message</source>
<target state="new">message</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsTitle">
<source>title</source>
<target state="new">title</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseDeprecatedSecurityProtocols">
<source>Do Not Use Deprecated Security Protocols</source>
<target state="translated">No usar protocolos de seguridad en desuso</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,21 @@
<target state="translated">Le chiffrement symétrique doit toujours utiliser un vecteur d'initialisation non répétable pour empêcher les attaques par dictionnaire.</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsDescription">
<source>description</source>
<target state="new">description</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsMessage">
<source>message</source>
<target state="new">message</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsTitle">
<source>title</source>
<target state="new">title</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseDeprecatedSecurityProtocols">
<source>Do Not Use Deprecated Security Protocols</source>
<target state="translated">Ne pas utiliser de protocoles de sécurité dépréciés</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,21 @@
<target state="translated">La crittografia simmetrica deve usare sempre un vettore di inizializzazione non ripetibile per impedire attacchi con dizionario.</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsDescription">
<source>description</source>
<target state="new">description</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsMessage">
<source>message</source>
<target state="new">message</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsTitle">
<source>title</source>
<target state="new">title</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseDeprecatedSecurityProtocols">
<source>Do Not Use Deprecated Security Protocols</source>
<target state="translated">Non usare protocolli di sicurezza deprecati</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,21 @@
<target state="translated">対称暗号化では、辞書攻撃を防ぐために、反復不能な初期化ベクトルを常に使用する必要があります。</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsDescription">
<source>description</source>
<target state="new">description</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsMessage">
<source>message</source>
<target state="new">message</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsTitle">
<source>title</source>
<target state="new">title</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseDeprecatedSecurityProtocols">
<source>Do Not Use Deprecated Security Protocols</source>
<target state="translated">非推奨のセキュリティ プロトコルを使用しない</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,21 @@
<target state="translated">대칭형 암호화는 항상 반복할 수 없는 초기화 벡터를 사용하여 사전 공격을 방지해야 합니다.</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsDescription">
<source>description</source>
<target state="new">description</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsMessage">
<source>message</source>
<target state="new">message</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsTitle">
<source>title</source>
<target state="new">title</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseDeprecatedSecurityProtocols">
<source>Do Not Use Deprecated Security Protocols</source>
<target state="translated">사용되지 않는 보안 프로토콜을 사용하지 마세요.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,21 @@
<target state="translated">Szyfrowanie symetryczne powinno zawsze używać wektora inicjowania, który nie jest powtarzalny, aby zapobiec atakom słownikowym.</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsDescription">
<source>description</source>
<target state="new">description</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsMessage">
<source>message</source>
<target state="new">message</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsTitle">
<source>title</source>
<target state="new">title</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseDeprecatedSecurityProtocols">
<source>Do Not Use Deprecated Security Protocols</source>
<target state="translated">Nie używaj przestarzałych protokołów zabezpieczeń</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,21 @@
<target state="translated">A criptografia simétrica sempre deve usar um vetor de inicialização que não possa ser repetido para evitar ataques de dicionário.</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsDescription">
<source>description</source>
<target state="new">description</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsMessage">
<source>message</source>
<target state="new">message</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsTitle">
<source>title</source>
<target state="new">title</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseDeprecatedSecurityProtocols">
<source>Do Not Use Deprecated Security Protocols</source>
<target state="translated">Não Use Protocolos de Segurança Preteridos</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,21 @@
<target state="translated">Для предотвращения атак перебором по словарю в симметричном шифровании всегда нужно использовать невоспроизводимый вектор инициализации.</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsDescription">
<source>description</source>
<target state="new">description</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsMessage">
<source>message</source>
<target state="new">message</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsTitle">
<source>title</source>
<target state="new">title</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseDeprecatedSecurityProtocols">
<source>Do Not Use Deprecated Security Protocols</source>
<target state="translated">Не используйте нерекомендуемые протоколы безопасности</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,21 @@
<target state="translated">Simetrik şifrelemenin, sözlük saldırılarını önlemek için her zaman yinelenemeyen bir başlatma vektörü kullanması gerekir.</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsDescription">
<source>description</source>
<target state="new">description</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsMessage">
<source>message</source>
<target state="new">message</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsTitle">
<source>title</source>
<target state="new">title</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseDeprecatedSecurityProtocols">
<source>Do Not Use Deprecated Security Protocols</source>
<target state="translated">Kullanım Dışı Güvenlik Protokollerini Kullanmayın</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,21 @@
<target state="translated">对称加密应始终使用非可重复的初始化向量,以防止字典攻击。</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsDescription">
<source>description</source>
<target state="new">description</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsMessage">
<source>message</source>
<target state="new">message</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsTitle">
<source>title</source>
<target state="new">title</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseDeprecatedSecurityProtocols">
<source>Do Not Use Deprecated Security Protocols</source>
<target state="translated">请勿使用弃用的安全协议</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,21 @@
<target state="translated">對稱式加密應永遠使用不可重複的初始化向量以防止字典攻擊。</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsDescription">
<source>description</source>
<target state="new">description</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsMessage">
<source>message</source>
<target state="new">message</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseCryptographicHardwareIntrinsicsTitle">
<source>title</source>
<target state="new">title</target>
<note />
</trans-unit>
<trans-unit id="DoNotUseDeprecatedSecurityProtocols">
<source>Do Not Use Deprecated Security Protocols</source>
<target state="translated">請勿使用已淘汰的安全性通訊協定</target>
Expand Down
Loading