이 전 포스팅에서 Nexus 내부 Jetty를 https로 구동할 준비를 끝냈다면,
이제 Self Signed SSL ( 스스로 발급한 SSL 인증서 ) 를 생성할 준비가 끝났다.
인증서의 위치는 nexus-default.properties 파일의 ssl.etc 경로에 설정된 폴더에 있어야 한다. 기본 위치는 /opt/sonatype/nexus/etc/ssl 이다. Container에 접속하여 위치로 이동하자.
## root 계정 접속
docker exec -it -u root nexus bash
cd /opt/sonatype/nexus/etc/ssl
모든 인증서는 CA 가 존재하지만 최상위 인증기관 (Root CA)은 상위의 인증기관이 없기 때문에 Root CA 의 개인키로 스스로의 인증서에 서명을 하여 최상위 인증기관의 인증서 (Root CA 인증서) 로 사용하게 된다.
이렇게 스스로 서명한 Root CA 인증서를 Self Signed Certificate (SSC) 라고 한다.
## AES-256 비트로 암호화된 개인키 파일을 생성. 길이는 2048비트
## 명령어를 실행시키면, ssl 인증서에 사용할 password를 입력하게 된다.
## 반드시 기억해두도록 하자.
openssl genrsa -aes256 -out example-rootca.key 2048
키를 생성한 후에는, 보안을 강화하기 위하여 권한을 재설정해주자.
chmod 600 example-rootca.key
CSR 파일 (인증서를 생성하기 위해 필요한 데이터와 서명 요청을 포함하는 파일) 생성을 위한 example-rootca.conf 파일 생성
## 파일 생성후 vim 에디터로 접속
touch example-rootca.conf
vim example-rootca.conf
##CSR 파일 생성을 위한 conf 파일 작성
[ req ]
default_bits = 2048
default_md = sha1
default_keyfile = example-rootca.key
distinguished_name = req_distinguished_name
extensions = v3_ca
req_extensions = v3_ca
[ v3_ca ]
basicConstraints = critical, CA:TRUE, pathlen:0
subjectKeyIdentifier = hash
##authorityKeyIdentifier = keyid:always, issuer:always
keyUsage = keyCertSign, cRLSign
nsCertType = sslCA, emailCA, objCA
[req_distinguished_name ]
countryName = Country Name (2 letter code)
countryName_default = KR
countryName_min = 2
countryName_max = 2
# 회사명 입력
organizationName = Organization Name (eg, company)
organizationName_default = exampleCompany
# 부서 입력
organizationalUnitName = Organizational Unit Name (eg, section)
organizationalUnitName_default = exampleUnit
# SSL 서비스할 domain 명 입력
commonName = Common Name (eg, your name or your servers hostname)
commonName_default = exampleDomain
commonName_max = 64
# CSR 파일 생성
openssl req -new -key example-rootca.key -out example-rootca.csr -config example-rootca.conf
만약 SSC로 생성한 인증서가 아니었다면, 인증 기관에 csr 파일을 보내어 인증서를 발급받게 된다.
# 10년짜리 인증서 생성
openssl x509 -req \
-days 3650 \
-extensions v3_ca \
-set_serial 1 \
-in example-rootca.csr \
-signkey example-rootca.key \
-out example-rootca.crt \
-extfile geo2-rootca.conf
examole-rootca.crt 라는 이름의 인증서가 생성되게 된다.
이 경우에,
example-rootca.key 는 Root CA의 개인키,
example-rootca.crt 는 Root CA의 공개키 역할을 한다.
이제 앞에서 생성한 Root CA 개인키를 이용하여 SSL 인증서를 발급받아 보자.
## AES-256 비트로 암호화된 개인키 파일을 생성. 길이는 2048비트
## 명령어를 실행시키면 password를 요구한다.
openssl genrsa -aes256 -out example.com.key 2048
이 password는 원하지 않는다면 제거해도 무방하다.
mv indienote.com.key example.com.key.enc
openssl rsa -in example.com.key.enc -out example.com.key
키를 생성한 후에는, 보안을 강화하기 위하여 권한을 재설정해주자.
chmod 600 example.com.key
SSL 인증서 발급을 위해서 내가 생성한 Root CA 에 제출한 CSR 파일을 생성해주자.
## CSR 파일 생성을 위한 conf 파일 생성
touch geo2.com.conf
vim geo2.com.conf
##CSR 파일 생성을 위한 conf 파일 작성
[ req ]
default_bits = 2048
default_md = sha1
default_keyfile = example-rootca.key
distinguished_name = req_distinguished_name
extensions = v3_user
## 인증서 요청시에도 extension 이 들어가면 authorityKeyIdentifier 를 찾지 못해 에러가 나므로 막아둔다.
## req_extensions = v3_user
[ v3_user ]
# Extensions to add to a certificate request
basicConstraints = CA:FALSE
authorityKeyIdentifier = keyid,issuer
subjectKeyIdentifier = hash
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
## SSL 용 확장키 필드
extendedKeyUsage = serverAuth,clientAuth
subjectAltName = @alt_names
[ alt_names]
## Subject AltName의 DNSName field 에 SSL Host 의 도메인 이름을 적어준다.
## 멀티 도메인일 경우 *.indienote.com 처럼 쓸 수 있다.
DNS.1 = myIpAddress or Domain
DNS.2 =
DNS.3 =
[req_distinguished_name ]
countryName = Country Name (2 letter code)
countryName_default = KR
countryName_min = 2
countryName_max = 2
# 회사명 입력
organizationName = Organization Name (eg, company)
organizationName_default = exampleCompany
# 부서 입력
organizationalUnitName = Organizational Unit Name (eg, section)
organizationalUnitName_default = exampleUnit
# SSL 서비스할 domain 명 입력
commonName = Common Name (eg, your name or your servers hostname)
commonName_default = exampleDomain
commonName_max = 64
openssl req -new -key example.com.key -out example.com.csr -config example.com.conf
example.com 용 SSL 인증서를 RootCA 의 개인키로 서명하여 발급한다.
openssl x509 -req -days 3650 -extensions v3_user -in example.com.csr \
-CA example-rootca.crt -CAcreateserial \
-CAkey example-rootca.key \
-out example.com.crt -extfile example.com.conf
이상으로, ssl 파일의 생성을 완료하였다.
마지막으로, JDK의 keytool을 이용하여 SSL 인증서를 신뢰하는 인증서로 등록하자.
keytool -import -alias example -keystore cacerts -file example.com.crt