JAVA/Spring

tomcat ssl letsencrypt 적용

cocho/kuby 2018. 6. 1. 14:51

1. git clone https://github.com/letsencrypt/letsencrypt

2. ./letsencrypt-auto certonly --manual

3. { 안내 url 파일 생성 }

4. openssl pkcs12 -export -in cert.pem -inkey privkey.pem -out [ 내보낼 키스토어 파일명 ].p12 -name [ keystore alias ] -CAfile chain.pem -caname root

5. keytool -importkeystore -deststorepass [사용할 암호] -destkeypass [사용할 암호] -destkeystore [생성할 jks 파일명] -srckeystore cert_and_key.p12 -srcstoretype PKCS12 -srcstorepass [PKCS12에서 사용한 암호] -alias [openssl에서 -name 속성에 입력한 이름]

6. keytool -import -trustcacerts -alias root -file chain.pem -keystore [생성한 jks 파일명]

7. 톰캣 설정 $CATALINA_HOME/conf/server.xml


<Service ...>


.. 중략 ..

<Connector 

port="8443" // 8443 포트로 접근시킨다. aws 인 경우 그냥 443 으로 하려고 하는데 접근이 안됨. 결국엔 방화벽에서 443 -> 8443 으로 리다이렉트 시킴으로 처리

SSLEnabled="true" 

URIEncoding="UTF-8" 

clientAuth="false"

        keystoreFile="..."  // 6번에서 생성 한 jks 파일 톰캣이 해당 파일을 읽을 수 있어야 한다.

keystorePass="..." // 5번에서 생성 한 암호

maxThreads="200"

        protocol="org.apache.coyote.http11.Http11NioProtocol" 

scheme="https"

        secure="true" 

sslProtocol="TLS" />


.. 중략 ..

</Service>




혹시 4번 경우에 키 정책이 변경(?) 되었다는 안내가 나올 때도 있다. 그럴 땐 그냥 안내에 나와있는 커맨드를 실행 하면 됨.


참고

https://elfinlas.github.io/2018/03/19/spring-boot-tls-certbot/

https://elfinlas.github.io/2018/03/19/certbot-ssl/

https://www.comodossl.co.kr/certificate/ssl-installation-guides/Tomcat-privatekey-crt.aspx

https://blog.outsider.ne.kr/1178