Certificate Signing Requests (CSRs)

먼저 certificate authority (CA)로 부터 SSL certificate을 얻기 위해서는 CSR를 먼저 만들어야 합니다. CSR 은 public key와 약간의 정보로 이루어져 있으며, 이것을 기반으로 certificate이 만들어집니다. CSR을 만들때 certificate을 구분짓게 해주는 정보를 넣어야 하는데 이것을 Distinguised Name (DN)이라고 합니다.

DN에는 Common Name(CN) 이 들어가야 하는데 이것은 Fully Qualified Domain Name (FQDN)이며 또한 당신의 Business, Organization등의 정보를 함께 넣습니다.

Generating Private Key and CSR

https://www.digicert.com/easy-csr/openssl.htm에 들어가시면 쉽게 CSR을 만들수 있습니다.

openssl req -new -newkey rsa:2048 -nodes -out star_andersonjo_com.csr -keyout star_andersonjo_com.key -subj "/C=KR/ST=Seoul/L=Seoul/O=Anderson/OU=Development/CN=*.andersonjo.com"

Prompt Way

다른 방법으로 다음의 코드를 치면 Propt로 Private Key및 CSR을 만들수 있습니다.

opessl req -newkey rsa:2048 -nodes -keyout domain.key -out domain.csr
anderson:~>openssl req -newkey rsa:2048 -nodes -keyout x.key -out x.csr
Generating a 2048 bit RSA private key
...............+++
.................+++
writing new private key to 'x.key'
-----
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]:KR
State or Province Name (full name) [Some-State]:Seoul
Locality Name (eg, city) []:Seoul
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Anderson
Organizational Unit Name (eg, section) []:Development
Common Name (e.g. server FQDN or YOUR name) []:anderson.com
Email Address []:a141890@gmail.com

OpenSSL Options

req: Certificate 을 만들겠다는 Request

-new: 새로운 Certificate Request를 생성합니다. promp문이 나와서 필요한 사항들을 적을수 있게 해줍니다.

-newkey rsa:2048: newkey는 a new certificate request와 a new private key 두개를 동시에 만들겠다는 뜻입니다.
RSA Key 2048 bits 이상되는 키를 만들게됩니다.

-nodes: Private Key가 생성이 될때 encrypted가 되지 않습니다.

-keyout file.key: Private Key를 어느 파일에 저장할지 지정합니다.

-out file.csr: Certificate을 어느 파일에 저장할지 지정합니다.

-days n: 만약 -x509 옵션이 사용이 되었다면, Certificate의 유요한 시간을 지정합니다. 기본값은 30일. (-days 365)

-outform DER|PEM: output format 을 어떻게할지 정합니다.

더 자세한 욥션 내용은 링크를 눌러주세요.
https://www.openssl.org/docs/manmaster/apps/req.html

Generating a CSR from an Existing Private Key

openssl req  -key domain.key -new -out domain.csr

-key 는 이미 존재하는 private key를 가르킵니다.

Generate a CSR from an Existing Certificate and Private Key

이미 갖고 있는 certificate을 renew 하거나 또는 CA 원래의 CSR를 갖고있지 않을때 사용하면 됩니다. (흔치는 않죠)
이미 갖고 있는 certificate에서 정보를 추출하기 때문에 CSR를 다시 만들필요가 없습니다.

openssl x509 -in domain.crt -signkey domain.key -x509toreq -out domain.csr

Nginx with SSL

https://www.ssls.com 에서 먼저 SSL Certificate을 구입합니다.

Certificate을 구입하고나면은 다음과 같은 파일들을 받습니다. (순서가 중요)

STAR_amanda_co_kr.crt
COMODORSADomainValidationSecureServerCA.crt
COMODORSAAddTrustCA.crt
AddTrustExternalCARoot.crt

cat STAR_amanda_co_kr.crt COMODORSADomainValidationSecureServerCA.crt COMODORSAAddTrustCA.crt AddTrustExternalCARoot.crt > domain.pem

다음과 같이 Nginx를 설정해주면 됩니다.

server {
    listen         80;
    server_name    domain.co.kr;
    return         301 https://$server_name$request_uri;
}

server{
    listen 443 ssl;
    server_name domain.co.kr;
    charset utf-8;

    ssl on;
    ssl_certificate     /home/ubuntu/ssl/amanda.pem;
    ssl_certificate_key /home/ubuntu/ssl/star_amanda_co_kr.key;
}

AWS Elastic Load Balance

openssl rsa -in star_domain_com.key -outform PEM >aws.private.pem
openssl x509 -inform PEM -in STAR_domain_com.crt >aws.public.pem
cat COMODORSADomainValidationSecureServerCA.crt COMODORSAAddTrustCA.crt AddTrustExternalCARoot.crt > aws.chain.pem

만들어진 파일 내용들을 ELB 에다가 갖다 붙여넣기 하면 끝.