Share via


CA5398: 하드 코딩된 SslProtocols 값 방지

속성
규칙 ID CA5398
타이틀 SslProtocols 값을 하드 코딩하지 마세요.
범주 보안
수정 사항이 주요 변경인지 여부 주요 변경 아님
.NET 8에서 기본적으로 사용 아니요

원인

이 규칙은 다음 조건 중 하나가 충족될 때 발생합니다.

안전한 값:

  • Tls12
  • Tls13

규칙 설명

TLS(전송 계층 보안)는 가장 일반적으로 HTTPS(Hypertext Transfer Protocol Secure)를 사용하여 컴퓨터 간의 통신을 보호합니다. 프로토콜 버전 TLS 1.0 및 TLS 1.1은 사용되지 않으며 TLS 1.2 및 TLS 1.3은 최신 상태입니다. 나중에는 TLS 1.2 및 TLS 1.3도 사용되지 않을 수 있습니다. 애플리케이션을 안전하게 유지하려면 프로토콜 버전을 하드 코드하지 마세요. 자세한 내용은 .NET Framework를 사용한 TLS(전송 계층 보안) 모범 사례를 참조하세요.

위반 문제를 해결하는 방법

TLS 프로토콜 버전을 하드 코드하지 마세요.

경고를 표시하지 않는 경우

향후 TLS 프로토콜 버전을 사용하도록 업그레이드할 수 없는 레거시 서비스에 연결해야 하는 경우 경고를 표시하지 않아도 됩니다.

경고 표시 안 함

단일 위반만 표시하지 않으려면 원본 파일에 전처리기 지시문을 추가하여 규칙을 사용하지 않도록 설정한 후 다시 사용하도록 설정합니다.

#pragma warning disable CA5398
// The code that's violating the rule is on this line.
#pragma warning restore CA5398

파일, 폴더 또는 프로젝트에 대한 규칙을 사용하지 않도록 설정하려면 구성 파일에서 심각도를 none으로 설정합니다.

[*.{cs,vb}]
dotnet_diagnostic.CA5398.severity = none

자세한 내용은 방법: 코드 분석 경고 표시 안 함을 참조하세요.

의사 코드 예제

열거형 이름 위반

using System;
using System.Security.Authentication;

public class ExampleClass
{
    public void ExampleMethod()
    {
        // CA5398 violation
        SslProtocols sslProtocols = SslProtocols.Tls12;
    }
}
Imports System
Imports System.Security.Authentication

Public Class TestClass
    Public Function ExampleMethod() As SslProtocols
        ' CA5398 violation
        Return SslProtocols.Tls12
    End Function
End Class

정수 값 위반

using System;
using System.Security.Authentication;

public class ExampleClass
{
    public SslProtocols ExampleMethod()
    {
        // CA5398 violation
        return (SslProtocols) 3072;    // TLS 1.2
    }
}
Imports System
Imports System.Security.Authentication

Public Class TestClass
    Public Function ExampleMethod() As SslProtocols
        ' CA5398 violation
        Return CType(3072, SslProtocols)   ' TLS 1.2
    End Function
End Class

솔루션

using System;
using System.Security.Authentication;

public class TestClass
{
    public void Method()
    {
        // Let the operating system decide what TLS protocol version to use.
        // See https://learn.microsoft.com/dotnet/framework/network-programming/tls
        SslProtocols sslProtocols = SslProtocols.None;
    }
}
Imports System
Imports System.Security.Authentication

Public Class TestClass
    Public Sub ExampleMethod()
        ' Let the operating system decide what TLS protocol version to use.
        ' See https://learn.microsoft.com/dotnet/framework/network-programming/tls
        Dim sslProtocols As SslProtocols = SslProtocols.None
    End Sub
End Class

CA5364: 사용되지 않는 보안 프로토콜을 사용하지 마세요.

CA5386: SecurityProtocolType 값 하드코딩 방지

CA5397: 사용되지 않는 SslProtocols 값을 사용하지 마세요.