성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
아티클
외부 아티클
유용한 코드
온라인 기능
MathJax 입력기
최근 덧글
[정성태] Working with Rust Libraries from C#...
[정성태] Detecting blocking calls using asyn...
[정성태] 아쉽게도, 커뮤니티는 아니고 개인 블로그입니다. ^^
[정성태] 질문이 잘 이해가 안 됩니다. 우선, 해당 소스코드에서 ILis...
[양승조
] var대신 dinamic으로 선언해서 해결은 했습니다. 맞는 해...
[양승조
] 또 막혔습니다. ㅠㅠ var list = props[i].Ge...
[양승조
] 아. 감사합니다. 어제는 안됐던것 같은데....정신을 차려야겠네...
[정성태] "props[i].GetValue(props[i])" 코드에서 ...
[정성태] 저렇게 조각 코드 말고, 실제로 재현이 되는 예제 프로젝트를 압...
[정성태] Modules 창(Ctrl+Shift+U)을 띄워서, 해당 Op...
글쓰기
제목
이름
암호
전자우편
HTML
홈페이지
유형
제니퍼 .NET
닷넷
COM 개체 관련
스크립트
VC++
VS.NET IDE
Windows
Team Foundation Server
디버깅 기술
오류 유형
개발 환경 구성
웹
기타
Linux
Java
DDK
Math
Phone
Graphics
사물인터넷
부모글 보이기/감추기
내용
<div style='display: inline'> <h1 style='font-family: Malgun Gothic, Consolas; font-size: 20pt; color: #006699; text-align: center; font-weight: bold'>PowerShell - New-SelfSignedCertificate를 사용해 CA 인증서 생성 및 인증서 서명 방법</h1> <p> 예전에 openssl을 이용해 CA로부터 서명한 인증서를 생성하는 방법에 대해 알아봤는데요,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > openssl - CA로부터 인증받은 새로운 인증서를 생성하는 방법 ; <a target='tab' href='https://www.sysnet.pe.kr/2/0/12570'>https://www.sysnet.pe.kr/2/0/12570</a> </pre> <br /> 이번에는 PowerShell을 통해 알아보겠습니다. ^^<br /> <br /> <hr style='width: 50%' /><br /> <br /> "<a target='tab' href='https://www.sysnet.pe.kr/2/0/12570'>openssl - CA로부터 인증받은 새로운 인증서를 생성하는 방법</a>" 글에서는 기존에 있었던 CA 인증서를 이용했는데, 이번에는 CA 인증서도 새롭게 생성하는 방법도 알아보겠습니다.<br /> <br /> 간단하게 다음과 같이 실행하면 CA 인증서가 생성됩니다.<br /> <br /> <div style='BACKGROUND-COLOR: #ccffcc; padding: 10px 10px 5px 10px; MARGIN: 0px 10px 10px 10px; FONT-FAMILY: Malgun Gothic, Consolas, Verdana; COLOR: #005555'> New-SelfSignedCertificate -Type Custom -Subject "CATest" -KeyUsage CertSign,DigitalSignature,KeyEncipherment -CertStoreLocation "Cert:\LocalMachine\My" -TextExtension @("2.5.29.19={critical}{text}ca=TRUE") -SerialNumber 00 -NotAfter (Get-Date).AddYears(10)<br /> </div><br /> <br /> 참고로 위의 인증서 옵션은 <a target='tab' href='https://www.sysnet.pe.kr/2/0/12578#cert_path'>k8s에서 생성한 ca.crt</a>와 동일한 출력을 갖습니다. 자, 그럼 이 CA 인증서로 서명한 새로운 인증서를 생성할 텐데요, 이를 위해 PowerShell에서는 CA 인증서의 참조 값을 가져야 하므로 다음과 같이 Get-ChildItem으로 미리 변수에 저장해 둡니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > $rootCA = Get-ChildItem -Path Cert:\LocalMachine\My | Where-Object { $_.Subject -eq "CN=CATest" } // 혹은 -Path 경로에 해당 인증서의 Thumbprint 값을 알고 있다면, (예를 들어 "be28fa76285084cf6c88d4eb432b517f8add6f14") // $rootCA = Get-ChildItem -Path Cert:\LocalMachine\My\be28fa76285084cf6c88d4eb432b517f8add6f14 // $rootCA = Get-ChildItem -Path (Join-Path Cert:\LocalMachine\My $rootCA.Thumbprint) // 혹은 CA 인증서 생성 당시 New-SelfSignedCertificate의 반환 값으로 받거나, // $rootCA = New-SelfSignedCertificate ... </pre> <br /> 이후 해당 참조를 -Signer 인자로 넘겨 주면 새롭게 인증서를 생성할 수 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > New-SelfSignedCertificate -Signer $rootCA -NotAfter (Get-Date).AddYears(10) -Subject "CASigned" -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.3","2.5.29.19={text}") -CertStoreLocation "Cert:\CurrentUser\My" -KeyUsage DigitalSignature // 혹은 CA 인증서를 생성하지 않았다면 "-TestRoot" 옵션을 사용하면 "Intermediate Certification Authorities" 경로에 있는 "CertReq Test Root"를 사용 </pre> <br /> 참고로, <a target='tab' href='https://www.sysnet.pe.kr/2/0/12570'>이전 글</a>에서는 실제 CA 인증 기관이 동작하는 것처럼 CSR까지 생성하는 등의 과정을 거쳤던 반면 이번 글에서는 그냥 개발자가 사용할 목적의 인증서를 빠르게 생성한 것이므로 그 CSR 요청 과정은 생략하였습니다.<br /> <br /> <hr style='width: 50%' /><br /> <br /> <a target='tab' href='openssl의 경우 명령행 인자와 cnf 파일을 이용해 다양한 옵션 설정'>openssl의 경우 명령행 인자와 cnf 파일을 이용해 다양한 옵션 설정</a>을 했는데요, New-SelfSignedCertificate의 경우 이에 대한 옵션을 대략 다음과 같은 설정으로 할 수 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > New-SelfSignedCertificate ; <a target='tab' href='https://learn.microsoft.com/en-us/powershell/module/pkiclient/new-selfsignedcertificate'>https://learn.microsoft.com/en-us/powershell/module/pkiclient/new-selfsignedcertificate</a> Serial Number 00 <span style='color: blue; font-weight: bold'>-SerialNumber 00</span> Valid to 10년 <span style='color: blue; font-weight: bold'>-NotAfter (Get-Date).AddYears(10)</span> Enhanced Key Usage: -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.3", "2.5.29.19={text}") Secure Email <span style='color: blue; font-weight: bold'>-TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.4")</span> Client Authentication (default) <span style='color: blue; font-weight: bold'>-TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.2")</span> Server Authentication (default) <span style='color: blue; font-weight: bold'>-TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.1")</span> Code Sigining <span style='color: blue; font-weight: bold'>-TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.3")</span> Timestamp Sigining <span style='color: blue; font-weight: bold'>-TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.8")</span> Any Purpose <span style='color: blue; font-weight: bold'>-TextExtension @("2.5.29.37={text}2.5.29.37.0")</span> (empty) <span style='color: blue; font-weight: bold'>-Type Custom</span> Basic Constraints: Subject Type=End Entity Path Length Constraint=None <span style='color: blue; font-weight: bold'>-TextExtension @("2.5.29.19={text}")</span> Subject Type=CA Path Length Constraint=None <span style='color: blue; font-weight: bold'>-TextExtension @("2.5.29.19={critical}{text}ca=TRUE")</span> Subject Alternative Name Other Name: Principal Name=pattifuller@contoso.com <span style='color: blue; font-weight: bold'>-TextExtension @("2.5.29.17={text}upn=pattifuller@contoso.com")</span> DNS Name=localhost, IP Address=127.0.0.1, IP Address=0000:0000:0000:0000:0000:0000:0000:0001 <span style='color: blue; font-weight: bold'>-TextExtension @("2.5.29.17={text}DNS=localhost&IPAddress=127.0.0.1&IPAddress=::1")</span> Key Usage Digital Signature (80) <span style='color: blue; font-weight: bold'>-KeyUsage DigitalSignature</span> Digital Signature, Key Encipherment (a0) (default) <span style='color: blue; font-weight: bold'>-KeyUsage DigitalSignature,KeyEncipherment</span> Certificate Signing <span style='color: blue; font-weight: bold'>-KeyUsage CertSign</span> CRL Signing <span style='color: blue; font-weight: bold'>-KeyUsage CRLSign</span> Data Encipherment <span style='color: blue; font-weight: bold'>-KeyUsage DataEncipherment</span> Subject CN = Patti Fuller OU = UserAccounts DC = corp DC = contoso DC = com <span style='color: blue; font-weight: bold'>-Subject "CN=Patti Fuller,OU=UserAccounts,DC=corp,DC=contoso,DC=com"</span> Public key RSA (2048 Bits) (default) <span style='color: blue; font-weight: bold'>-KeyAlgorithm RSA -KeyLength 2048</span> ECC (256 Bits) <span style='color: blue; font-weight: bold'>-KeyAlgorithm ECDSA_nistP256 -CurveExport CurveName</span> Signature algorithm sha256RSA (default) <span style='color: blue; font-weight: bold'>-KeyAlgorithm RSA</span> sha256ECDSA <span style='color: blue; font-weight: bold'>-KeyAlgorithm ECDSA_nistP256 -CurveExport CurveName</span> Public key parameters 05 00 (default) <span style='color: blue; font-weight: bold'>-KeyAlgorithm RSA</span> ECDSA_P256 <span style='color: blue; font-weight: bold'>-KeyAlgorithm ECDSA_nistP256 -CurveExport CurveName</span> SMIME Capabilities [1]SMIME Capability Object ID=2.16.840.1.101.3.4.1.42 [2]SMIME Capability Object ID=2.16.840.1.101.3.4.1.45 [3]SMIME Capability Object ID=2.16.840.1.101.3.4.1.22 [4]SMIME Capability Object ID=2.16.840.1.101.3.4.1.25 [5]SMIME Capability Object ID=2.16.840.1.101.3.4.1.2 [6]SMIME Capability Object ID=2.16.840.1.101.3.4.1.5 [7]SMIME Capability Object ID=1.2.840.113549.3.7 [8]SMIME Capability Object ID=1.3.14.3.2.7 [9]SMIME Capability Object ID=1.2.840.113549.3.2 Parameters=02 02 00 80 [10]SMIME Capability Object ID=1.2.840.113549.3.4 Parameters=02 02 02 00 <span style='color: blue; font-weight: bold'>-SmimeCapabilities</span> 인증서 등록 위치 Local Machine/My <span style='color: blue; font-weight: bold'>-CertStoreLocation "Cert:\LocalMachine\My"</span> Local Machine/Trusted Root Certification Authorities <span style='color: blue; font-weight: bold'>-CertStoreLocation "Cert:\LocalMachine\Root"</span> Current User/My <span style='color: blue; font-weight: bold'>-CertStoreLocation "Cert:\CurrentUser\My"</span> 개인키 exportable 여부 지정 Exportable (default) <span style='color: blue; font-weight: bold'>-KeyExportPolicy Exportable</span> NonExportable <span style='color: blue; font-weight: bold'>-KeyExportPolicy NonExportable</span> </pre> <br /> <hr style='width: 50%' /><br /> <br /> 새로 생성한 인증서가 등록될 위치를 My 이외의 경로를 지정하면 다음과 같은 오류가 발생합니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > PS C:\temp> <span style='color: blue; font-weight: bold'>New-SelfSignedCertificate -Type Custom -Subject "CATest" -CertStoreLocation "Cert:\LocalMachine\Root" ...[생략]...</span> New-SelfSignedCertificate : A new certificate can only be installed into MY store. At line:1 char:1 + New-SelfSignedCertificate -Type Custom -Subject "CATest" -CertStoreLocation "Ce ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [New-SelfSignedCertificate], ParameterBindingException + FullyQualifiedErrorId : RuntimeException,Microsoft.CertificateServices.Commands.NewSelfSignedCertificateCommand" </pre> <br /> 그러니까, 안 되는 것은 안 되는 겁니다. ^^ 이를 우회하기 위해 해당 인증서를 일단 My에 생성한 다음 Root로 이동하는 작업을 별도로 해야 합니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > $newCertPath = New-SelfSignedCertificate -Type Custom -Subject "CATest" -CertStoreLocation "Cert:\LocalMachine\My" Move-Item $newCertPath -Destination Cert:\LocalMachine\Root </pre> <br /> 참고로 예전에 C# 코드를 이용해 인증서를 등록하는 방법도 있고. ^^<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > C# - 인증서를 윈도우에 설치하는 방법 ; <a target='tab' href='https://www.sysnet.pe.kr/2/0/11719'>https://www.sysnet.pe.kr/2/0/11719</a> </pre> </p><br /> <br /><hr /><span style='color: Maroon'>[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]</span> </div>
첨부파일
스팸 방지용 인증 번호
1224
(왼쪽의 숫자를 입력해야 합니다.)