3.3. OpenSSL을 사용하여 TLS 서버 인증서의 개인 키와 CSR 생성

TLS 암호화 통신 채널은 CA(인증 기관)의 유효한 TLS 인증서가 있는 경우에만 사용할 수 있습니다. 인증서를 받으려면 먼저 서버의 개인 키와 CSR(인증서 서명 요청)을 만들어야 합니다.

절차

  1. 서버 시스템에서 개인 키를 생성합니다. 예를 들면 다음과 같습니다.

    $ openssl genpkey -algorithm ec -pkeyopt ec_paramgen_curve:P-256 -out <server-private.key>
  2. 선택 사항: 선택한 텍스트 편집기를 사용하여 CSR 생성을 간소화하는 구성 파일을 준비합니다. 예를 들면 다음과 같습니다.

    $ vim <example_server.cnf>
    [server-cert]
    keyUsage = critical, digitalSignature, keyEncipherment, keyAgreement
    extendedKeyUsage = serverAuth
    subjectAltName = @alt_name
    
    [req]
    distinguished_name = dn
    prompt = no
    
    [dn]
    C = <US>
    O = <Example Organization>
    CN = <server.example.com>
    
    [alt_name]
    DNS.1 = <example.com>
    DNS.2 = <server.example.com>
    IP.1 = <192.168.0.1>
    IP.2 = <::1>
    IP.3 = <127.0.0.1>

    extendedKeyUsage = serverAuth 옵션은 인증서 사용을 제한합니다.

  3. 이전에 생성한 개인 키를 사용하여 CSR을 생성합니다.

    $ openssl req -key <server-private.key> -config <example_server.cnf> -new -out <server-cert.csr>

    -config 옵션을 생략하면 req 유틸리티에서 추가 정보를 입력하라는 메시지를 표시합니다. 예를 들면 다음과 같습니다.

    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) [XX]: <US>
    State or Province Name (full name) []: <Washington>
    Locality Name (eg, city) [Default City]: <Seattle>
    Organization Name (eg, company) [Default Company Ltd]: <Example Organization>
    Organizational Unit Name (eg, section) []:
    Common Name (eg, your name or your server's hostname) []: <server.example.com>
    Email Address []: <server@example.com>

다음 단계

검증

  1. CA에서 요청된 인증서를 가져온 후 인증서의 사람이 읽을 수 있는 부분이 요구 사항과 일치하는지 확인합니다.

    $ openssl x509 -text -noout -in <server-cert.crt>
    Certificate:
    …
            Issuer: CN = Example CA
            Validity
                Not Before: Feb  2 20:27:29 2023 GMT
                Not After : Feb  2 20:27:29 2024 GMT
            Subject: C = US, O = Example Organization, CN = server.example.com
            Subject Public Key Info:
                Public Key Algorithm: id-ecPublicKey
                    Public-Key: (256 bit)
    …
            X509v3 extensions:
                X509v3 Key Usage: critical
                    Digital Signature, Key Encipherment, Key Agreement
                X509v3 Extended Key Usage:
                    TLS Web Server Authentication
                X509v3 Subject Alternative Name:
                    DNS:example.com, DNS:server.example.com, IP Address:192.168.0.1, IP
    …

추가 리소스

  • openssl(1), x509(1), genpkey(1), req(1), and config(5) man pages