성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
아티클
외부 아티클
유용한 코드
온라인 기능
MathJax 입력기
최근 덧글
[정성태] Get Started with Milvus Vector DB i...
[정성태] cyberark/PipeViewer - A tool that...
[정성태] WinForms in a 64-Bit world – our st...
[정성태] 예제에서 SELECT_SQL도 내부적으로는 SqlCommand/...
[victor] SELECT_LINQ SELECT_SQL 같은 쿼리인...
[victor] 답변 갑사합니다. 예외(Exception)가 났습니다. ...
[정성태] 일단, 위의 방식대로 하면 예외(Exception) 없이 잘 동...
[정성태] Windows 10 (버전 1809)에 이런 기능이 ^^ 추가되...
[정성태] pde windbg extension ; https://lea...
[정성태] // GetEnumerator extensions for Ran...
글쓰기
제목
이름
암호
전자우편
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'>openssl - CA로부터 인증받은 새로운 인증서를 생성하는 방법</h1> <p> self-signed 인증서가 있다면 그것을 인증 기관(CA: certificate authority)의 루트 인증서라고 봐도 됩니다. <br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > How to Create Your Own SSL Certificate Authority for Local HTTPS Development - Becoming a (tiny) Certificate Authority ; <a target='tab' href='https://deliciousbrains.com/ssl-certificate-authority-for-local-https-development/'>https://deliciousbrains.com/ssl-certificate-authority-for-local-https-development/</a> OpenSSL Essentials: Working with SSL Certificates, Private Keys and CSRs ; <a target='tab' href='https://www.digitalocean.com/community/tutorials/openssl-essentials-working-with-ssl-certificates-private-keys-and-csrs'>https://www.digitalocean.com/community/tutorials/openssl-essentials-working-with-ssl-certificates-private-keys-and-csrs</a> </pre> <br /> 위의 글에서는 CA 인증서 생성 후, 다른 개인키를 만들어 앞서의 CA로부터 서명을 받아내는 방법("Creating CA-Signed Certificates for Your Dev Sites")도 설명합니다.<br /> <br /> 이와 관련해서 간단하게 정리를 해볼까요? ^^<br /> <br /> 기존에 ca.crt, ca.key 파일이 있다고 가정하고, 새롭게 apiserver.key라는 개인키 파일을 하나 만들었다고 가정해보겠습니다. 그럼 해당 개인키에 대한 인증서 요청 파일을 만들 수 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > // <a target='tab' href='https://www.openssl.org/docs/manmaster/man1/openssl-req.html'>openssl-req</a> c:\temp\wsl> <span style='color: blue; font-weight: bold'>openssl req -key apiserver.key -new -out apiserver.csr</span> You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]: State or Province Name (full name) [Some-State]: Locality Name (eg, city) []: Organization Name (eg, company) [Internet Widgits Pty Ltd]: Organizational Unit Name (eg, section) []: Common Name (e.g. server FQDN or YOUR name) []:<span style='color: blue; font-weight: bold'>kube-apiserver</span> Email Address []: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: </pre> <br /> "Common Name"을 kube-apiserver로 지정한 것을 제외하고는 모두 기본 값을 사용하고 있습니다. 이렇게 생성된 apiserver.csr 파일은 다음과 같은 양식을 가집니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > -----BEGIN CERTIFICATE REQUEST----- MIICozCCAYsCAQAwXjELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUx ...[생략]... dffpjAc4Xw== -----END CERTIFICATE REQUEST----- </pre> <br /> 이걸로 모든 준비는 끝입니다. 이제 CA 인증 기관의 개인키 파일 및 인증서를 가지고 다음과 같이 해당 인증서 요청에 대해 서명을 해 새로운 인증서를 만들 수 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > // <a target='tab' href='https://www.openssl.org/docs/manmaster/man1/openssl-x509.html'>openssl-x509</a> c:\temp\wsl> <span style='color: blue; font-weight: bold'>openssl x509 -req -days 3650 -in apiserver.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server-cert.crt</span> </pre> <br /> 서명 후 생성된 server-cert.crt 파일은 이런 양식을 가지며,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > -----BEGIN CERTIFICATE----- MIIC+jCCAeICFEsnOV4njaMmxkP9X+5leLdWtL0KMA0GCSqGSIb3DQEBCwUAMBUx ...[생략]... cYvuYo6gg4XKMHsR6RILj+6/WMJ7ptLSF5M5ZQLDwuKwYjbZc57+72hrHYopFw== -----END CERTIFICATE----- </pre> <br /> 탐색기로 보면 다음과 같이 해석 결과를 보여줍니다.<br /> <br /> <img alt='sign_from_ca_1.png' src='/SysWebRes/bbs/sign_from_ca_1.png' /><br /> <br /> <hr style='width: 50%' /><br /> <a name='openssl_cnf'></a> <br /> 기본 과정은 저렇지만, 하나씩 사용자 정의를 추가해보겠습니다.<br /> <br /> 우선 "Common Name" (속성 창에서는 Subject) 값이 "kube-apiserver, Internet Widgits Pty Ltd"라고 나옵니다. 이것은, "openssl req ..." 명령어 실행 중 기본값으로 지정된 "Organization Name" 때문에 그런 것입니다. "Common Name"에 기재한 값만 나오게 하고 싶다면 "Organization Name" 질문에 그냥 엔터만 치지 말고 콤마(.)를 입력한 후 엔터를 치면 됩니다. 또는, 아예 명령어에서 제공하는 -subj 옵션을 활용하면 그런 귀찮은 질문 단계를 없앨 수 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > C:\temp\wsl> openssl req -key apiserver.key -new -out apiserver.csr <span style='color: blue; font-weight: bold'>-subj "/CN=kube-apiserver"</span> </pre> <br /> 위와 같이 해주면, "Subject"에 해당하는 값이 "CN = kube-apisevrer"로 나오게 됩니다. 하지만, 대체로 위와 같이 명령행에 지정하기보다는 이러한 구성을 가지고 있는 cnf 파일을 만드는 것이 더 편리합니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > How to create a CSR with OpenSSL ; <a target='tab' href='https://www.switch.ch/pki/manage/request/csr-openssl/'>https://www.switch.ch/pki/manage/request/csr-openssl/</a> </pre> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > # apiserver.cnf <span style='color: blue; font-weight: bold'>FQDN = kube-apiserver</span> [ req ] default_bits = 2048 default_md = sha256 prompt = no encrypt_key = no <span style='color: blue; font-weight: bold'>distinguished_name = dn</span> <span style='color: blue; font-weight: bold'>[ dn ] CN = $FQDN</span> </pre> <br /> 이렇게 만든 cnf 파일을 "openssl req ..." 수행 시 "-config" 옵션으로 지정하면 됩니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > C:\temp\wsl> openssl req -key apiserver.key -new -out apiserver.csr <span style='color: blue; font-weight: bold'>-config apiserver.cnf</span> </pre> <br /> 필드 설정이 원하는 대로 반영이 되었는지는 crt 파일까지 생성할 필요 없이, CSR 파일을 대상으로 "opensssl req ..." 명령어를 이용해 이렇게 해석할 수 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > C:\temp\wsl> <span style='color: blue; font-weight: bold'>openssl req -in apiserver.csr -noout -text -nameopt sep_multiline</span> Certificate Request: Data: Version: 1 (0x0) <span style='color: blue; font-weight: bold'>Subject: CN=kube-apiserver</span> Subject Public Key Info: Public Key Algorithm: rsaEncryption RSA Public-Key: (2048 bit) Modulus: 00:a5:e6:1d:1b:41:15:f2:c4:b6:24:73:b4:ad:59: ...[생략]... 1a:8f:ae:2c:de:fd:e5:7f:ac:78:b2:b2:30:ca:05: 17:55 Exponent: 65537 (0x10001) Signature Algorithm: sha256WithRSAEncryption a2:d5:a6:37:56:8e:39:ec:c8:4b:03:71:5e:bd:50:b7:45:14: ...[생략]... 11:12:ae:53:62:bd:4c:75:35:ec:28:d5:8c:5d:28:c6:32:38: ef:7c:48:33 </pre> <br /> <hr style='width: 50%' /><br /> <a name='san'></a> <br /> 그다음, "Subject Alternative Name"을 지정하는 방법입니다. 이를 위해 cnf 파일에 다음의 내용을 추가하고,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > # apiserver.cnf FQDN = kube-apiserver <span style='color: blue; font-weight: bold'>ALTNAMES = DNS:docker-for-desktop,DNS:kubernetes,DNS:kubernetes.default,DNS:kubernetes.default.svc,DNS:kubernetes.default.svc.cluster.local,DNS:kubernetes.docker.internal,DNS:vm.docker.internal,DNS:localhost</span> [ req ] default_bits = 2048 default_md = sha256 prompt = no encrypt_key = no distinguished_name = dn <span style='color: blue; font-weight: bold'>req_extensions = req_ext</span> [ dn ] CN = $FQDN <span style='color: blue; font-weight: bold'>[ req_ext ] subjectAltName = $ALTNAMES</span> </pre> <br /> "openssl req ..." 명령을 실행하면 되는데,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > openssl req -key apiserver.key -new -out apiserver.csr -config apiserver.cnf </pre> <br /> 재미있는 것은, 이렇게 만들어진 csr 파일을 "openssl req -in apiserver.csr -noout -text -nameopt sep_multiline" 명령어로 살펴보면 분명히 다음과 같이 "X509v3 Subject Alternative Name" 항목으로 확인이 되는데,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > ...[생략]... Attributes: Requested Extensions: <span style='color: blue; font-weight: bold'>X509v3 Subject Alternative Name: DNS:docker-for-desktop, DNS:kubernetes, DNS:kubernetes.default, DNS:kubernetes.default.svc, DNS:kubernetes.default.svc.cluster.local, DNS:kubernetes.docker.internal, DNS:vm.docker.internal, DNS:localhost</span> ...[생략]... </pre> <br /> 정작 "openssl x509 ..." 명령어를 실행해 crt 인증서를 만들었을 때는 SAN 항목의 출력이 누락됩니다. 왜냐하면, "openssl x509 ..." 명령에서도 -extfile과 -extension 옵션을 이용해 cnf(이 글에서는 apiserver.cnf)의 확장 항목을 지정해야 하기 때문입니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > openssl x509 <span style='color: blue; font-weight: bold'>-extfile apiserver.cnf -extensions req_ext</span> -req -days 3650 -in apiserver.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server-cert.crt </pre> <br /> 이렇게 만들어진 server-cert.crt를 보면,<br /> <br /> <img alt='sign_from_ca_2.png' src='/SysWebRes/bbs/sign_from_ca_2.png' /><br /> <br /> 의도했던 대로 "Subject Alternative Name" 값이 들어가 있습니다.<br /> <br /> <hr style='width: 50%' /><br /> <br /> 다음으로 "Key Usage" 항목을 설정해 보겠습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > # apiserver.cnf FQDN = kube-apiserver ALTNAMES = DNS:docker-for-desktop,DNS:kubernetes,DNS:kubernetes.default,DNS:kubernetes.default.svc,DNS:kubernetes.default.svc.cluster.local,DNS:kubernetes.docker.internal,DNS:vm.docker.internal,DNS:localhost,<span style='color: blue; font-weight: bold'>IP:10.96.0.1,IP:0.0.0.0,IP:192.168.65.3,IP:127.0.0.1</span> [ req ] default_bits = 2048 default_md = sha256 prompt = no encrypt_key = no distinguished_name = dn req_extensions = req_ext [ dn ] CN = $FQDN [ req_ext ] subjectAltName = $ALTNAMES <span style='color: blue; font-weight: bold'>keyUsage = digitalSignature,keyEncipherment</span> </pre> <br /> 이 설정으로 "openssl req ...", "openssl x509 ..."를 실행하면, 인증서에는 "Key Usage" 값이 "Digital Signature, Key Enhancement (a0)" 항목이 나옵니다.<br /> <br /> <hr style='width: 50%' /><br /> <br /> 그렇다면, Enhanced Key Usage 값도 설정해 보겠습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > # apiserver.cnf FQDN = kube-apiserver ALTNAMES = DNS:docker-for-desktop,DNS:kubernetes,DNS:kubernetes.default,DNS:kubernetes.default.svc,DNS:kubernetes.default.svc.cluster.local,DNS:kubernetes.docker.internal,DNS:vm.docker.internal,DNS:localhost,IP:10.96.0.1,IP:0.0.0.0,IP:192.168.65.3,IP:127.0.0.1 [ req ] default_bits = 2048 default_md = sha256 prompt = no encrypt_key = no distinguished_name = dn req_extensions = req_ext [ dn ] CN = $FQDN [ req_ext ] <span style='color: blue; font-weight: bold'>extendedKeyUsage = serverAuth</span> authorityKeyIdentifier = keyid, issuer subjectAltName = $ALTNAMES keyUsage = digitalSignature,keyEncipherment </pre> <br /> 이후 인증서를 생성하면 Enhanced Key Usage 값이 "Server Authentication (1.3.6.1.5.5.7.3.1)"로 설정이 됩니다.<br /> <br /> <hr style='width: 50%' /><br /> <br /> 하는 김에 AKID(Authority Key Identifier)까지 설정해 보겠습니다. 이 값은, CA 인증서의 "Subject Key Identifier"가 있다면 그 값을 "Authority Key Identifier"에 그대로 이어받을 수 있습니다.<br /> <br /> 그런데, 이 값의 설정은 "openssl req ..." 단계에서는 허용되지 않는 옵션이므로 이를 위해서는 openssl cnf의 설정 단계를 "openssl req"와 "openssl x509"를 위해 나누는 것이 필요합니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > # apiserver.cnf FQDN = kube-apiserver ALTNAMES = DNS:docker-for-desktop,DNS:kubernetes,DNS:kubernetes.default,DNS:kubernetes.default.svc,DNS:kubernetes.default.svc.cluster.local,DNS:kubernetes.docker.internal,DNS:vm.docker.internal,DNS:localhost,IP:10.96.0.1,IP:0.0.0.0,IP:192.168.65.3,IP:127.0.0.1,IP:192.168.65.4 [ req ] default_bits = 2048 default_md = sha256 prompt = no encrypt_key = no distinguished_name = dn req_extensions = req_ext [ dn ] CN = $FQDN [ req_ext ] extendedKeyUsage = serverAuth subjectAltName = $ALTNAMES keyUsage = digitalSignature,keyEncipherment <span style='color: blue; font-weight: bold'>[ x509_ext ]</span> extendedKeyUsage = serverAuth <span style='color: blue; font-weight: bold'>authorityKeyIdentifier = keyid,issuer</span> subjectAltName = $ALTNAMES keyUsage = digitalSignature,keyEncipherment </pre> <br /> 아울러, 이렇게 나뉜 설정을 각각 openssl req와 openssl x509 명령에서 다음과 같이 지정해 인증서를 생성할 수 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > C:\temp\wsl> openssl req -key apiserver.key -new -out apiserver.csr -config apiserver.cnf C:\temp\wsl> openssl x509 -extfile apiserver.cnf <span style='color: blue; font-weight: bold'>-extensions x509_ext</span> -req -days 3650 -in apiserver.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server-cert.crt Signature ok subject=CN = kube-apiserver Getting CA Private Key </pre> <br /> 다음은 이렇게 해서 반영된 AKID 값을 보여줍니다.<br /> <br /> <img onclick='toggle_img(this)' class='imgView' alt='sign_from_ca_3.png' src='/SysWebRes/bbs/sign_from_ca_3.png' /><br /> </p><br /> <br /><hr /><span style='color: Maroon'>[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]</span> </div>
첨부파일
스팸 방지용 인증 번호
2010
(왼쪽의 숫자를 입력해야 합니다.)