Microsoft MVP성태의 닷넷 이야기
Linux: 62. 리눅스/WSL에서 CA 인증서를 저장하는 방법 [링크 복사], [링크+제목 복사],
조회: 2919
글쓴 사람
정성태 (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




리눅스/WSL에서 CA 인증서를 저장하는 방법

지난 글에서 openssl로 생성한 인증서를 적용한 웹 사이트를,

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

(간단하게는 WSL 환경의) Ubuntu에서 접근해 보면,

$ cat /etc/resolv.conf
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 172.18.208.1

$ curl https://172.18.208.1:7252
curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: https://curl.haxx.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

당연히, CA 인증서가 해당 Ubuntu 환경에는 없으므로 인증서 검증에 실패합니다. (인증서 검증 단계를 생략하도록 --insecure 옵션을 추가하면 됩니다.)

따라서, Ubuntu 환경에도 test_ca.crt 인증서를 설치해야 하는데요,

Install CA certificates on Linux systems
; https://www.hs-schmalkalden.de/en/university/faculties/faculty-of-electrical-engineering/studium/use-of-it/install-ca-certificates-on-linux-systems

위의 글에서 소개하는 방법에 따라 (제 경우에는 Ubuntu이므로) ca-certificates 디렉터리에 복사해 둔 후,

$ sudo cp /mnt/c/temp/cert/test_ca.crt /usr/local/share/ca-certificates

update-ca-certificates 명령어를 실행하면,

$ sudo update-ca-certificates 

/usr/local/share/ca-certificates 디렉터리에 복사했던 인증서가 /etc/ssl/certs/ca-certificates.crt 파일에 추가됩니다. 해당 파일에는 BEGIN/END CERTIFICATE 문자열이 잔뜩 들어가 있는데, 이것을 쉽게 해석하기 위해서는 다음의 명령어를 사용할 수 있습니다.

// List all available ssl ca certificates
// https://unix.stackexchange.com/questions/97244/list-all-available-ssl-ca-certificates

$ awk -v cmd='openssl x509 -noout -subject' '/BEGIN/{close(cmd)};{print | cmd}' < /etc/ssl/certs/ca-certificates.crt
...[생략]...
subject=CN = testca

그렇다면, 당연히 이제부터는 curl 명령어가 정상적으로 동작하게 됩니다. 만약 그래도 문제가 있다면, SSL과 관련한 상세 정보를 얻기 위해 openssl을 이용하는 것도 좋습니다.

$ openssl s_client -showcerts -connect 172.18.208.1:7252




지난 글에서 만든 인증서는 "DNS:test.testhvpc.com" 항목도 포함하고 있는데요, 당연히 리눅스에도 (윈도우의 HOSTS 파일에 해당하는) "/etc/hosts" 파일을 편집해 해당 DNS를 설정하면,

$ cat /etc/hosts
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateHosts = false
172.18.208.1   test.testhvpc.com
...[생략]...

이렇게 테스트할 수 있습니다.

$ curl https://test.testhvpc.com:7252

참고로, WSL 환경의 /etc/hosts 파일은 해당 우분투 인스턴스가 재시작하면 윈도우의 HOSTS 파일로부터 재작성되므로, 지속성을 위해서라면 윈도우의 HOSTS 파일에 저 항목을 넣어두어야 합니다.

그런데, 재미있는 현상이 하나 있습니다. WSL 2 환경이라면 Google Chrome 브라우저를 설치해 실행하는 것도 가능한데요,

How to Install Firefox and Google Chrome in WSL2 on Windows 10
; https://www.freshtechtips.com/2022/12/install-firefox-google-chrome-in-wsl.html

$ sudo apt update && sudo apt upgrade -y

$ sudo wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

$ sudo dpkg -i google-chrome-stable_current_amd64.deb

$ sudo apt install --fix-broken -y

$ sudo dpkg -i google-chrome-stable_current_amd64.deb

$ google-chrome

그렇게 실행한 브라우저에서 "https://test.testhvpc.com:7252" 주소를 방문하면 "NET::ERR_CERT_AUTHORITY_INVALID" 오류가 발생합니다.

Your connection is not private
Attackers might be trying to steal your information from test.testhvpc.com (for example, passwords, messages, or credit cards). Learn more
NET::ERR_CERT_AUTHORITY_INVALID

This server could not prove that it is test.testhvpc.com; its security certificate is not trusted by your computer's operating system. This may be caused by a misconfiguration or an attacker intercepting your connection.

Proceed to test.testhvpc.com (unsafe)

왜냐하면, 크롬의 경우에는 인증서 저장소를 별도 관리하기 때문인데,

SSL certificate in system store not trusted by Chrome
; https://serverfault.com/questions/946756/ssl-certificate-in-system-store-not-trusted-by-chrome

따라서 "settings -> privacy and security -> security -> manage certificates" 설정에 들어가 "Authorities" 탭에서 CA 인증서를 "Trust this certificate for identifying websites" 옵션으로 추가하면 됩니다.

만약 "Authorities"가 아닌 다른 탭, 예를 들어 "Your certificates" 탭에서 추가하려고 시도하면 이런 오류가 발생합니다.

Certificate Import Error
The Private Key for this Client Certificate is missing or invalid




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







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

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

비밀번호

댓글 작성자
 




... 16  17  18  19  20  21  22  23  24  25  26  [27]  28  29  30  ...
NoWriterDateCnt.TitleFile(s)
12956정성태2/4/20226966.NET Framework: 1148. C# - ffmpeg(FFmpeg.AutoGen) - decoding 과정 [2]파일 다운로드1
12955정성태2/4/20226381개발 환경 구성: 635. 비주얼 스튜디오에서 실행하던 ASP.NET Core (.NET Framework) 응용 프로그램을 명령행에서 실행하는 방법 (2)
12954정성태2/4/20226239VS.NET IDE: 173. 비주얼 스튜디오 - Output 창에 색상이 지정된 출력 결과가 "[39m[22m" 식의 문자로 나오는 문제
12953정성태2/2/20226493Linux: 48. Windows 11 + WSL 우분투 GUI 환경에서 한글 출력
12952정성태2/2/20226946.NET Framework: 1148. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 오디오 필터 예제(filter_audio.c)파일 다운로드1
12951정성태2/2/20226934.NET Framework: 1147. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 오디오 필터링 예제(filtering_audio.c)파일 다운로드1
12950정성태2/1/20226546.NET Framework: 1146. .NET 6에 추가되지 않은 Generic Math (예: INumber<T>)
12949정성태2/1/20226407.NET Framework: 1145. C# - ffmpeg(FFmpeg.AutoGen) - Codec 정보 열람 및 사용 준비파일 다운로드1
12948정성태1/30/20226496.NET Framework: 1144. C# - ffmpeg(FFmpeg.AutoGen) AVFormatContext를 이용해 ffprobe처럼 정보 출력파일 다운로드1
12947정성태1/30/20227650개발 환경 구성: 634. ffmpeg.exe - 기존 동영상 컨테이너에 다중 스트림을 추가하는 방법
12946정성태1/28/20226143오류 유형: 792. .NET Core - 로컬 개발 중에 docker 호스팅으로 바꾸는 경우 SQL 서버 접근 방법
12945정성태1/28/20226392오류 유형: 791. SQL 서버 로그인 시 localhost는 되고, 127.0.0.1로는 안 되는 문제
12944정성태1/28/20228803.NET Framework: 1143. C# - Entity Framework Core 6 개요
12943정성태1/27/20227721.NET Framework: 1142. .NET 5+로 포팅 시 플랫폼 호환성 경고 메시지(SYSLIB0006, SYSLIB0011, CA1416)파일 다운로드1
12942정성태1/27/20227994.NET Framework: 1141. XmlSerializer와 Dictionary 타입파일 다운로드1
12941정성태1/26/20229369오류 유형: 790. AKS/k8s - pod 상태가 Pending으로 지속되는 경우
12940정성태1/26/20226748오류 유형: 789. AKS에서 hpa에 따른 autoscale 기능이 동작하지 않는다면?
12939정성태1/25/20227471.NET Framework: 1140. C# - ffmpeg(FFmpeg.AutoGen)를 이용해 MP3 오디오 파일 인코딩/디코딩하는 예제파일 다운로드1
12938정성태1/24/20229796개발 환경 구성: 633. Docker Desktop + k8s 환경에서 local 이미지를 사용하는 방법
12937정성태1/24/20227604.NET Framework: 1139. C# - ffmpeg(FFmpeg.AutoGen)를 이용해 오디오(mp2) 인코딩하는 예제(encode_audio.c) [2]파일 다운로드1
12936정성태1/22/20227547.NET Framework: 1138. C# - ffmpeg(FFmpeg.AutoGen)를 이용해 멀티미디어 파일의 메타데이터를 보여주는 예제(metadata.c)파일 다운로드1
12935정성태1/22/20227749.NET Framework: 1137. ffmpeg의 파일 해시 예제(ffhash.c)를 C#으로 포팅파일 다운로드1
12934정성태1/22/20227312오류 유형: 788. Warning C6262 Function uses '65564' bytes of stack: exceeds /analyze:stacksize '16384'. Consider moving some data to heap. [2]
12933정성태1/21/20227871.NET Framework: 1136. C# - ffmpeg(FFmpeg.AutoGen)를 이용해 MP2 오디오 파일 디코딩 예제(decode_audio.c)파일 다운로드1
12932정성태1/20/20228295.NET Framework: 1135. C# - ffmpeg(FFmpeg.AutoGen)로 하드웨어 가속기를 이용한 비디오 디코딩 예제(hw_decode.c) [2]파일 다운로드1
12931정성태1/20/20226413개발 환경 구성: 632. ASP.NET Core 프로젝트를 AKS/k8s에 올리는 과정
... 16  17  18  19  20  21  22  23  24  25  26  [27]  28  29  30  ...