-
IIS HTTPS 세팅하기 및 C# 사설 SSL 인증서 호출 사용하기 OPENSSL 사용하기.NET/C# Basic 2023. 3. 14. 14:09반응형
1. OPEN SSL 다운로드
Win32/Win64 OpenSSL Installer for Windows - Shining Light Productions (slproweb.com)
2. 자체 서명 SSL 인증서만들기
개인 키 생성: OpenSSL을 사용하여 개인 키를 생성하세요. 개인 키는 공개 키와 쌍을 이루며, 인증서를 발급받을 때 사용됩니다. 다음 명령을 사용하여 개인 키를 생성할 수 있습니다.
openssl genrsa -out key.pem 2048
이 명령은 2048비트 RSA 개인 키를 생성하고, "key.pem" 파일에 저장합니다.
CSR 생성: OpenSSL을 사용하여 인증서 서명 요청(CSR)을 생성하세요. CSR은 인증 기관에 제출하여 인증서를 발급받을 때 사용됩니다. 다음 명령을 사용하여 CSR을 생성할 수 있습니다.
openssl req -new -key key.pem -out csr.pem
이 명령은 "key.pem" 파일에서 개인 키를 가져와 CSR을 생성하고, "csr.pem" 파일에 저장합니다. CSR 생성 중에는 인증서를 발급받을 도메인 이름과 회사 정보 등의 정보를 입력해야 합니다.
인증서 서명: 자체 서명 SSL 인증서를 생성하기 위해 CSR을 서명하세요. 다음 명령을 사용하여 CSR을 서명하고, 인증서 파일을 생성할 수 있습니다.
openssl x509 -req -days 365 -in csr.pem -signkey key.pem -out cert.pem
openssl pkcs12 -export -out cert.pfx -inkey key.pem -in cert.pem
이 명령은 CSR 파일("csr.pem")에서 요청한 정보를 가져와 개인 키("key.pem")로 서명합니다. 인증서는 365일 동안 유효하며, "cert.pem" 파일에 저장됩니다.추가로 PFX 파일을 .cer 파일로 변환 방법
openssl pkcs12 -in cert.pfx -out cert.cer -nodes
3. 생성된 인증서 설치 탐색기에서 실행하여 설치4. IIS의 Server Certificates에서 설치된 인증서 확인
5. IIS 사이트 추가시 SSL 인증서 선택
6. 테스터 인증서 사설인증서 경고 무시 로직 추가 feat C#
HttpWebRequest request = null;
// SSL 모드 HTTPS
if (SSLMode == true)
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
// https 인증서 무시 로직 적용
var callback = ServicePointManager.ServerCertificateValidationCallback;
var invocationList = callback?.GetInvocationList();
if (invocationList != null)
{
foreach (var handler in invocationList)
{
ServicePointManager.ServerCertificateValidationCallback -= (System.Net.Security.RemoteCertificateValidationCallback)handler;
}
}// https 인증서 무시
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
}// SSL 모드 HTTPS
if (SSLMode == true)
{
X509Certificate2 cert = new X509Certificate2();
request = (HttpWebRequest)WebRequest.Create(uri);
request.ClientCertificates.Add(cert);
}
else //HTTP
{
request = (HttpWebRequest)WebRequest.Create(uri);
}반응형'.NET > C# Basic' 카테고리의 다른 글
C# CallerMemberNameAttribute Class 소개 (0) 2016.02.29 C# Custom Sort Null 널값이 제일 아래로 IComparer IComparable (2) 2013.08.23 DLL Ressource 에서 BitmapImage 불러오기 Method (1) 2013.01.11 Visual Studio 2005의 원격 디버깅 설정(http://www.hoonsbara.com/) (1) 2010.06.14 [C#] String.Format 을 이용한 문자정렬 왼쪽 오른쪽 가운데 | String alignment Left Right Center (0) 2010.03.20 [C#] char[] + char[] = char[]?? | char[] Merge (0) 2010.02.09 [C#] Thread를 정복해 보자 (0) 2010.02.06 사용예) StringCollection 과 string[] int[] converterMethod (0) 2010.02.02