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

비밀번호

댓글 작성자
 




... 31  32  33  34  35  36  [37]  38  39  40  41  42  43  44  45  ...
NoWriterDateCnt.TitleFile(s)
12708정성태7/14/202110301Linux: 41. 리눅스 환경에서 디스크 용량 부족 시 원인 분석 방법
12707정성태7/14/202177561오류 유형: 734. MySQL - Authentication method 'caching_sha2_password' not supported by any of the available plugins.
12706정성태7/14/20218742.NET Framework: 1076. C# - AsyncLocal 기능을 CallContext만으로 구현하는 방법 [2]파일 다운로드1
12705정성태7/13/20218915VS.NET IDE: 168. x64 DLL 프로젝트의 컨트롤이 Visual Studio의 Designer에서 보이지 않는 문제 - 두 번째 이야기
12704정성태7/12/20218053개발 환경 구성: 576. Azure VM의 서비스를 Azure Web App Service에서만 접근하도록 NSG 설정을 제한하는 방법
12703정성태7/11/202113688개발 환경 구성: 575. Azure VM에 (ICMP) ping을 허용하는 방법
12702정성태7/11/20218838오류 유형: 733. TaskScheduler에 등록된 wacs.exe의 Let's Encrypt 인증서 업데이트 문제
12701정성태7/9/20218476.NET Framework: 1075. C# - ThreadPool의 스레드는 반환 시 ThreadStatic과 AsyncLocal 값이 초기화 될까요?파일 다운로드1
12700정성태7/8/20218870.NET Framework: 1074. RuntimeType의 메모리 누수? [1]
12699정성태7/8/20217674VS.NET IDE: 167. Visual Studio 디버깅 중 GC Heap 상태를 보여주는 "Show Diagnostic Tools" 메뉴 사용법
12698정성태7/7/202111638오류 유형: 732. Windows 11 업데이트 시 3% 또는 0%에서 다운로드가 멈춘 경우
12697정성태7/7/20217524개발 환경 구성: 574. Windows 11 (Insider Preview) 설치하는 방법
12696정성태7/6/20218128VC++: 146. 운영체제의 스레드 문맥 교환(Context Switch)을 유사하게 구현하는 방법파일 다운로드2
12695정성태7/3/20218173VC++: 145. C 언어의 setjmp/longjmp 기능을 Thread Context를 이용해 유사하게 구현하는 방법파일 다운로드1
12694정성태7/2/202110115Java: 24. Azure - Spring Boot 앱을 Java SE(Embedded Web Server)로 호스팅 시 로그 파일 남기는 방법 [1]
12693정성태6/30/20217859오류 유형: 731. Azure Web App Site Extension - Failed to install web app extension [...]. {1}
12692정성태6/30/20217736디버깅 기술: 180. Azure - Web App의 비정상 종료 시 남겨지는 로그 확인
12691정성태6/30/20218593개발 환경 구성: 573. 테스트 용도이지만 테스트에 적합하지 않은 Azure D1 공유(shared) 요금제
12690정성태6/28/20219405Java: 23. Azure - 자바(Java)로 만드는 Web App Service - Tomcat 호스팅
12689정성태6/25/20219943오류 유형: 730. Windows Forms 디자이너 - The class Form1 can be designed, but is not the first class in the file. [1]
12688정성태6/24/20219626.NET Framework: 1073. C# - JSON 역/직렬화 시 리플렉션 손실을 없애는 JsonSrcGen [2]파일 다운로드1
12687정성태6/22/20217608오류 유형: 729. Invalid data: Invalid artifact, java se app service only supports .jar artifact
12686정성태6/21/202110060Java: 22. Azure - 자바(Java)로 만드는 Web App Service - Java SE (Embedded Web Server) 호스팅
12685정성태6/21/202110304Java: 21. Azure Web App Service에 배포된 Java 프로세스의 메모리 및 힙(Heap) 덤프 뜨는 방법
12684정성태6/19/20218759오류 유형: 728. Visual Studio 2022부터 DTE.get_Properties 속성 접근 시 System.MissingMethodException 예외 발생
12683정성태6/18/202110232VS.NET IDE: 166. Visual Studio 2022 - Windows Forms 프로젝트의 x86 DLL 컨트롤이 Designer에서 오류가 발생하는 문제 [1]파일 다운로드1
... 31  32  33  34  35  36  [37]  38  39  40  41  42  43  44  45  ...