Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

(시리즈 글이 10개 있습니다.)
개발 환경 구성: 555. openssl - CA로부터 인증받은 새로운 인증서를 생성하는 방법
; https://www.sysnet.pe.kr/2/0/12570

개발 환경 구성: 565. PowerShell - New-SelfSignedCertificate를 사용해 CA 인증서 생성 및 인증서 서명 방법
; https://www.sysnet.pe.kr/2/0/12588

개발 환경 구성: 654. openssl - CA로부터 인증받은 새로운 인증서를 생성하는 방법 (2)
; https://www.sysnet.pe.kr/2/0/13187

개발 환경 구성: 662. openssl - 윈도우 환경의 명령행에서 SAN 적용하는 방법
; https://www.sysnet.pe.kr/2/0/13235

개발 환경 구성: 663. openssl을 이용해 인트라넷 IIS 사이트의 SSL 인증서 생성
; https://www.sysnet.pe.kr/2/0/13236

개발 환경 구성: 681. openssl - 인증서 버전(V1 / V3)
; https://www.sysnet.pe.kr/2/0/13371

개발 환경 구성: 686. 비주얼 스튜디오로 실행한 ASP.NET Core 사이트를 WSL 2 인스턴스에서 https로 접속하는 방법
; https://www.sysnet.pe.kr/2/0/13442

개발 환경 구성: 687. OpenSSL로 생성한 사용자 인증서를 ASP.NET Core 웹 사이트에 적용하는 방법
; https://www.sysnet.pe.kr/2/0/13443

Linux: 62. 리눅스/WSL에서 CA 인증서를 저장하는 방법
; https://www.sysnet.pe.kr/2/0/13445

닷넷: 2162. ASP.NET Core 웹 사이트의 SSL 설정을 코드로 하는 방법
; https://www.sysnet.pe.kr/2/0/13447




OpenSSL로 생성한 사용자 인증서를 ASP.NET Core 웹 사이트에 적용하는 방법

이번 글은 IIS 버전을 새롭게 정리한 것입니다.

openssl을 이용해 인트라넷 IIS 사이트의 SSL 인증서 생성
; https://www.sysnet.pe.kr/2/0/13236




지난 글에서,

비주얼 스튜디오로 실행한 ASP.NET Core 사이트를 WSL 2 인스턴스에서 https로 접속하는 방법
; https://www.sysnet.pe.kr/2/0/13442

호스팅하는 ASP.NET 웹 사이트는 기본적으로 "ASP.NET Core HTTPS development certificate" 테스트 인증서를 사용하기 때문에 "localhost"로만 (매끄럽게) 접속할 수 있습니다.

이번엔, (vcpkg로 쉽게 빌드할 수 있는) openssl로 만든 인증서 파일을 활용해 그럴싸하게 호스팅 해보겠습니다. ^^




자, 그럼 우선 CA 인증서와 그것으로 서명한 "테스트 웹 사이트용 인증서"를 openssl로,

openssl - CA로부터 인증받은 새로운 인증서를 생성하는 방법 (2)
; https://www.sysnet.pe.kr/2/0/13187

이렇게 만들어 줍니다.

// 참고로, 공인 CA 업체로부터 인증서를 받는다면 아래에서 1~2번 작업만 사용자가 하고, 3번부터는 CA 측에서 담당합니다.

// 1) 웹 사이트 개인키 생성
c:\temp\cert> openssl genrsa -out test_site_cert.key 2048
// 2) CA에서 서명 받아 생성할 인증서의 요청 파일 생성
c:\temp\cert> openssl req -key test_site_cert.key -new -out test_site_cert.csr -subj "/CN=test.testhvpc.com"

// 3) CA 측에서 해당 인증서에 추가할 SAN 이름을 갖는 설정 파일 준비
c:\temp\cert> type ssl_conf.txt
subjectAltName=DNS:test.testhvpc.com,DNS:localhost,IP:127.0.0.1,IP:172.18.208.1

// 4) CA 인증서와 개인키 생성
c:\temp\cert> openssl req -newkey rsa:2048 -nodes -keyout test_ca.key -x509 -days 365 -out test_ca.crt  -subj "/CN=testca"

// 5) CA의 개인키로 인증서 요청을 승인(서명)해 인증서 생성
c:\temp\cert> openssl x509 -req -days 3650 -extfile ssl_conf.txt -in test_site_cert.csr -CA test_ca.crt -CAkey test_ca.key -CAcreateserial -out test_site_cert.crt

subjectAltName으로 다양한 값을 주었는데요, (여러분들의 환경에 맞게) 원하는 값을 다중으로 저렇게 넣으면 됩니다. 여기까지 완료했으면, 이제 생성된 파일 중 의미 있는 파일은 다음과 같습니다.

test_site_cert.crt  // 테스트 사이트 인증서 (Web 사이트에서 사용)
test_site_cert.key  // 테스트 사이트 개인키 (Web 사이트에서 사용)

test_ca.crt  // CA 인증서 (클라이언트 측에서 사용)
test_ca.key  // CA 개인키 (향후, 또 다른 인증서 요청을 수락하기 위해 사용)




ASP.NET 웹 프로젝트에 test_site_cert.crt, test_site_cert.key 파일을 복사하고 빌드 시 복사되도록 csproj에 다음과 같이 추가합니다.

<Project Sdk="Microsoft.NET.Sdk.Web">

    <PropertyGroup>
        <TargetFramework>net7.0</TargetFramework>
        <Nullable>enable</Nullable>
        <ImplicitUsings>enable</ImplicitUsings>
    </PropertyGroup>

    <ItemGroup>
        <None Update="test_site_cert.crt">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </None>
        <None Update="test_site_cert.key">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </None>
    </ItemGroup>

</Project>

그다음 appsettings.json 파일에 SSL 통신을 위한 인증서/개인키 파일과 Url 정보를 추가합니다.

{
    "Logging": {
        "LogLevel": {
            "Default": "Information",
            "Microsoft.AspNetCore": "Warning"
        }
    },
    "AllowedHosts": "*",
    "Kestrel": {
        "EndPoints": {
            "Http": {
                "Url": "http://0.0.0.0:5001"
            },
            "HttpsFromPem": {
                "Url": "https://0.0.0.0:7252",
                "Certificate": {
                    "Path": "test_site_cert.crt",
                    "KeyPath": "test_site_cert.key"
                }
            }
        }
    }
}

일단, 서비스하는 측에서의 준비는 끝났습니다. 마지막으로, 연결하려는 측, 예를 들어 웹 브라우저로 접속한다면 그것이 실행될 컴퓨터에 "test_ca.crt" CA 공개키 인증서를 복사해 "Trusted Root Certification Authorities"에 등록해 줍니다.

여기까지 잘 마쳤으면, ^^ 이제 Visual Studio에서 F5 키를 눌러 웹 사이트를 실행한 후,

warn: Microsoft.AspNetCore.Server.Kestrel[0]
      Overriding address(es) 'https://localhost:7252, http://localhost:5001'. Binding to endpoints defined via IConfiguration and/or UseKestrel() instead.
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://0.0.0.0:5001
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: https://0.0.0.0:7252
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: C:\temp\WebApplication1\WebApplication1

(CA 공개키 인증서를 설치한 PC 측의) 웹 브라우저를 이용해 SAN에 설정했던 값, 제 경우에는 localhost의 IP가 172.18.208.1이기 때문에 "https://172.18.208.1:7252"로 접속하면 정상적으로 (아무 부가 작업 없이) SSL로 호스팅되는 것을 확인할 수 있습니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 11/14/2023]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 46  47  48  49  [50]  51  52  53  54  55  56  57  58  59  60  ...
NoWriterDateCnt.TitleFile(s)
12398정성태11/4/20209946오류 유형: 678. Windows Server 2008 R2 환경에서 Powershell을 psexec로 원격 실행할 때 hang이 발생하는 문제
12397정성태11/4/202010122.NET Framework: 960. C# - 조건 연산자(?:)를 사용하는 경우 달라지는 메서드 선택 사례파일 다운로드1
12396정성태11/3/20208416VS.NET IDE: 152. Visual Studio - "Tools" / "External Tools..."에 등록된 외부 명령어에 대한 단축키 설정 방법
12395정성태11/3/20209752오류 유형: 677. SSMS로 DB 접근 시 The server principal "..." is not able to access the database "..." under the current security context.
12394정성태11/3/20208155오류 유형: 676. cacls - The Recycle Bin on ... is corrupted. Do you want to empty the Recycle Bin for this drive?
12393정성태11/3/20208652오류 유형: 675. Visual Studio - 닷넷 응용 프로그램 디버깅 시 Disassembly 창에서 BP 설정할 때 "Error while processing breakpoint." 오류
12392정성태11/2/202012777.NET Framework: 959. C# 9.0 - (9) 레코드(Records) [4]파일 다운로드1
12390정성태11/1/202011034디버깅 기술: 173. windbg - System.Configuration.ConfigurationErrorsException 예외 분석 방법
12389정성태11/1/202010771.NET Framework: 958. C# 9.0 - (8) 정적 익명 함수 (static anonymous functions)파일 다운로드1
12388정성태10/29/202010224오류 유형: 674. 어느 순간부터 닷넷 응용 프로그램 실행 시 System.Configuration.ConfigurationErrorsException 예외가 발생한다면?
12387정성태10/28/202011011.NET Framework: 957. C# - static 필드의 정보가 GC Heap에 저장될까요? [3]파일 다운로드1
12386정성태10/28/202011256Linux: 34. 사용자 정보를 함께 출력하는 리눅스의 ps 명령어 사용 방법
12385정성태10/28/20209073오류 유형: 673. openssl - req: No value provided for Subject Attribute CN, skipped
12384정성태10/27/202010288오류 유형: 672. AllowPartiallyTrustedCallers 특성이 적용된 어셈블리의 struct 멤버 메서드를 재정의하면 System.Security.VerificationException 예외 발생
12383정성태10/27/202011164.NET Framework: 956. C# 9.0 - (7) 패턴 일치 개선 사항(Pattern matching enhancements) [3]파일 다운로드1
12382정성태10/26/20208891오류 유형: 671. dotnet build - The local source '...' doesn't exist
12381정성태10/26/202010549VC++: 137. C++ stl map의 사용자 정의 타입을 key로 사용하는 방법 [1]파일 다운로드1
12380정성태10/26/20207971오류 유형: 670. Visual Studio - Squash_FailureCommitsReset
12379정성태10/21/202010976.NET Framework: 955. .NET 메서드의 Signature 바이트 코드 분석 [1]파일 다운로드2
12378정성태10/15/202010391.NET Framework: 954. C# - x86/x64 환경에 따라 달라지는 P/Invoke 함수의 export 이름파일 다운로드1
12377정성태10/15/202011684디버깅 기술: 172. windbg - 파일 열기 시점에 bp를 걸어 파일명 알아내는 방법(Managed/Unmanaged)
12376정성태10/15/20208400오류 유형: 669. windbg - sos의 name2ee 명령어 실행 시 "Failed to request module list." 오류
12375정성태10/15/20209784Windows: 177. 윈도우 탐색기에서 띄우는 cmd.exe 창의 디렉터리 구분 문자가 'Yen(&#0165;)' 기호로 나오는 경우 [1]
12374정성태10/14/202014398.NET Framework: 953. C# 9.0 - (6) 함수 포인터(Function pointers) [1]파일 다운로드2
12373정성태10/14/20209687.NET Framework: 952. OpCodes.Box와 관련해 IL 형식으로 직접 코딩 시 유의할 점
12372정성태10/13/202011499.NET Framework: 951. C# 9.0 - (5) 로컬 함수에 특성 지정 가능(Attributes on local functions)파일 다운로드1
... 46  47  48  49  [50]  51  52  53  54  55  56  57  58  59  60  ...