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)
12760정성태8/8/20216157개발 환경 구성: 594. 전용 "Command Prompt for ..." 단축 아이콘 만들기
12759정성태8/8/20219315Java: 26. IntelliJ + Spring Framework + 새로운 Controller 추가 [2]파일 다운로드1
12758정성태8/7/20218670오류 유형: 751. Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)
12757정성태8/7/20219345Java: 25. IntelliJ + Spring Framework 프로젝트 생성
12756정성태8/6/20218108.NET Framework: 1084. C# - .NET Core Web API 단위 테스트 방법 [1]파일 다운로드1
12755정성태8/5/20217257개발 환경 구성: 593. MSTest - 단위 테스트에 static/instance 유형의 private 멤버 접근 방법파일 다운로드1
12754정성태8/5/20218149오류 유형: 750. manage.py - Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
12753정성태8/5/20218399오류 유형: 749. PyCharm - Error: Django is not importable in this environment
12752정성태8/4/20216500개발 환경 구성: 592. JetBrains의 IDE(예를 들어, PyCharm)에서 Visual Studio 키보드 매핑 적용
12751정성태8/4/20219594개발 환경 구성: 591. Windows 10 WSL2 환경에서 docker-compose 빌드하는 방법
12750정성태8/3/20216375디버깅 기술: 181. windbg - 콜 스택의 "Call Site" 오프셋 값이 가리키는 위치
12749정성태8/2/20215794개발 환경 구성: 590. Visual Studio 2017부터 단위 테스트에 DataRow 특성 지원
12748정성태8/2/20216388개발 환경 구성: 589. Azure Active Directory - tenant의 관리자(admin) 계정 로그인 방법
12747정성태8/1/20216985오류 유형: 748. 오류 기록 - MICROSOFT GRAPH – HOW TO IMPLEMENT IAUTHENTICATIONPROVIDER파일 다운로드1
12746정성태7/31/20219043개발 환경 구성: 588. 네트워크 장비 환경을 시뮬레이션하는 Packet Tracer 프로그램 소개
12745정성태7/31/20216871개발 환경 구성: 587. Azure Active Directory - tenant의 관리자 계정 로그인 방법
12744정성태7/30/20217483개발 환경 구성: 586. Azure Active Directory에 연결된 App 목록을 확인하는 방법?
12743정성태7/30/20218151.NET Framework: 1083. Azure Active Directory - 외부 Token Cache 저장소를 사용하는 방법파일 다운로드1
12742정성태7/30/20217420개발 환경 구성: 585. Azure AD 인증을 위한 사용자 인증 유형
12741정성태7/29/20218621.NET Framework: 1082. Azure Active Directory - Microsoft Graph API 호출 방법파일 다운로드1
12740정성태7/29/20217278오류 유형: 747. SharePoint - InvalidOperationException 0x80131509
12739정성태7/28/20217255오류 유형: 746. Azure Active Directory - IDW10106: The 'ClientId' option must be provided.
12738정성태7/28/20217863오류 유형: 745. Azure Active Directory - Client credential flows must have a scope value with /.default suffixed to the resource identifier (application ID URI).
12737정성태7/28/20216791오류 유형: 744. Azure Active Directory - The resource principal named api://...[client_id]... was not found in the tenant
12736정성태7/28/20217332오류 유형: 743. Active Azure Directory에서 "API permissions"의 권한 설정이 "Not granted for ..."로 나오는 문제
12735정성태7/27/20217836.NET Framework: 1081. C# - Azure AD 인증을 지원하는 데스크톱 애플리케이션 예제(Windows Forms) [2]파일 다운로드1
... 31  32  33  34  [35]  36  37  38  39  40  41  42  43  44  45  ...