System Compleat.

SSL Certificates on Nginx & Windows

Techs
( younjin.jeong@gmail.com , 정윤진 )

최근, 인증서 관련 이슈가 있어 간략하게 인증서를 다루는 법에 대해 소개하려고 한다.
이슈는,

1. nginx 에서 Intermediary SSL 을 설치하는 방법.
2. Windows 에서 certutil 을 사용하는 방법.

의 2가지 이다.

2가지 내용 모두 다음의 내용을 참고 하였다.
1. 이슈 : http://rubypond.com/blog/nginx-intermediary-ssl-certificates-and-passphrases
2. 이슈 : http://blogs.microsoft.co.il/blogs/applisec/archive/2008/04/08/creating-x-509-certificates-using-makecert-exe.aspx

급하신 분들은 위의 내용을 직접 참고 하셔도 되겠다.


1.  Nginx Intermediary SSL Certificates and Passphrases

Merging the site and intermediary SSL certificates

발급받은 사이트 인증서와 중개기관 인증서를 병합해야 한다.  아파치 및 IIS 에서는 두개의 인증서를 따로 지정하거나 별도로 설치가 가능하지만, nginx 는 무조건 1개의 파일로 설정해야 한다.  따라서, 다음과 같이 병합한다.

cat yourdomain.com.crt >> yourdomain.com.crt.merged
cat intermediate_bundle.crt >> yourdomain.com.crt.merged

Removing SSL Passpharse

다음단계는, key 파일에 걸려있는 암호를 제거해야 한다.  물론 남겨두는게 좋지만, 남겨두게 되면 오퍼레이터가 항상 재시작 할때마다 키를 넣어주어야 하기 때문에 자동으로 재시작이 불가능하다.  따라서, 백업을 먼저하고 다음과 같이 진행한다.

mv yourdomain.com.key  yourdomain.com.passphrased
openssl rsa -in yourdomain.key.passphrased -out yourdomain.key


Configuring Nginx to use your new SSL certificate

다음과 비슷한 모양으로 설정한다.

server {
  listen 443;
  server_name myserver.com; 

  ssl on;
  ssl_certificate /etc/nginx/certs/yourdomain.com.crt.merged;
  ssl_certificate_key /etc/nginx/certs/yourdomain.key ;

  # put the rest of your server configuration here.

  location / {
     proxy_set_header X-FORWARDED_PROTO https;
     # put your config here
  }
}

nginx 를 재시작 하면 된다.

2008 년 여름, 일본에서 서비스를 오픈다하가 이 문제로 인해 한참을 구글링 한 적이 있다.
날짜의 압박속에서, Reverse proxy 로 동작하는 nginx 에 키가 제대로 설치되지 않으면, 503 Bad Gateway 메세지를 떨구기 때문에, 반드시 처리 해야만 했던.

아무튼, 필요하신 분에게 좋은 도음이 되었으면 한다.


2. Creating X.509 Certificates using makecert.exe

x.509 인증서 생성은 매우 빈번한 작업이지만, 어떻게 하는 것인지 모르는경우가 종종 있다.
실제로는 신뢰된 인증기관을 통해서 구매해야 하지만, 다음의 툴로 혼자만의 Cert의 생성이 가능하다.
MakeCert.exe

다운로드 후에는, 다음의 진행을 따른다.


Creating a Root Certificate Authority  ( Root 인증서 생성 )
makecert.exe -n "CN=My Root CA,O=Organization,OU=Org Unit,L=San Diego,S=CA,C=US" -pe -ss my -sr LocalMachine -sky exchange -m 96 -a sha1 -len 2048 -r My_Root_CA.cer

Import Root Certificate Authority Certificate into Trusted Root Store ( 생성된 인증서를 Root 저장소로 Import )
certutil.exe -f -addstore Root My_Root_CA.cer

Create Backup (Export) PFX file of Root Certificate Authority Certificate ( 생성된 인증서를 pfx 로 백업 )
certutil.exe -privatekey -exportpfx "My Root CA" My_Root_CA.pfx

Create a Server Certificate issued from the previously created Certificate Authority  ( 기존에 생성된 인증을 바탕으로 서버 인증서 생성 )
makecert.exe -n "CN=Server" -pe -ss my -sr LocalMachine -sky exchange -m 96 -in "My Root CA" -is my -ir LocalMachine -a sha1 -eku 1.3.6.1.5.5.7.3.1,1.3.6.1.5.5.7.3.2 Server.cer

Create Backup (Export) PFX file of Server Certificate ( 생성된 서버 키를 pfx 로 백업 )
certutil.exe -privatekey -exportpfx "Server" Server.pfx

Create a Computer certificate issued from the previously created Certificate Authority ( 기존 생성된 인증을 바탕으로 "Computer" 인증서 생성 )
makecert.exe -n "CN=Computer" -pe -ss my -sr Localmachine -sky exchange -m 96 -in "My Root CA" -is my -ir LocalMachine -a sha1 -eku 1.3.6.1.5.5.7.3.2 Computer.cer

Create Backup (Export) PFX file of Computer Certificate ( 기존에 생성된 "Computer" 키를 pfx 로 백업 )
certutil.exe -privatekey -exportpfx "Computer" Computer.pfx

OID Reference

Encrypting File System (1.3.6.1.4.1.311.10.3.4)
Secure Email (1.3.6.1.5.5.7.3.4)
Smart Card Logon (1.3.6.1.4.1.311.20.2.2)
Client Authentication (1.3.6.1.5.5.7.3.2)
Server Authentication (1.3.6.1.5.5.7.3.1)
IP security IKE intermediate (1.3.6.1.5.5.8.2.2)



써놓고 보니 거의 날로먹은 포스팅..   미안하니까 몇가지 쓸모있는 URL 링크.

인증서 웹 변환 툴
https://www.sslshopper.com/ssl-converter.html

csr ( private key ) 및 certificate 비교
https://www.sslshopper.com/certificate-key-matcher.html

Verisign 의 Intermediate Certificate
https://www.verisign.co.jp/repository/intermediate/server/c3SecureServerCA_1024.html



( younjin.jeong@gmail.com , 정윤진 )