본문 바로가기
Linux/Web Server

CentOS 7 자체 서명 SSL 인증서 생성 및 적용 - tomcat9.0

by PeterC 2020. 9. 16.

petersec.tistory.com/entry/CentOS-7-%EC%9E%90%EC%B2%B4-%EC%84%9C%EB%AA%85-SSL-%EC%9D%B8%EC%A6%9D%EC%84%9C-%EC%83%9D%EC%84%B1-%EB%B0%8F-%EC%A0%81%EC%9A%A9

 

CentOS 7 자체 서명 SSL 인증서 생성 및 적용

SSL과 SSL 인증서 인터넷 상에서 클라이언트와 웹서버간의 데이터를 안전하게 주고 받기 위해서는 서로 암호화하여 통신하여야 한다. SSL(Secure Socket Layer)는 웹브라우저와 서버간 암호화 통신을 위

petersec.tistory.com

 

위 게시글에서 생성한 SSL 인증서를 사용.

 

개인키(apache-selfsigned.crt)와 인증서(apache-selfsigned.crt)는 생성되어있다.

인증서와 개인키가 DER 방식으로 encoding 되어 있으면 openssl에서 pkcs12로 변환하지 못한다. 따라서 PEM 형식으로 변환하는 과정을 거쳐야한다.

 

openssl로 pkcs12 파일을 생성후 keytool을 이용하여 KeyStore로 변환한다.

[root@localhost mgmt]# openssl pkcs12 -export -in apache-selfsigned.crt -inkey apache-selfsigned.key -out keystore.p12 -name "tomcat"
[root@localhost mgmt]# keytool -importkeystore -deststorepass <password> -destkeypass <password> -destkeystore keystore.jks -srckeystore keystore.p12 -srcstoretype PKCS12 -srcstorepass <password> -alias "tomcat"

 

tomcat의 server.xml을 수정한다. tomcat의 버전별로 수정사항이 다르니 유의하도록 한다.

( <!-- .... --> 주석을 제거한 후 Certificate 구문 영역을 수정합니다.)

[root@localhost conf]# pwd
/var/www/apache-tomcat-9.0.0.M18/conf
[root@localhost conf]# vi server.xml
....
....
    <!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443
         This connector uses the NIO implementation. The default
         SSLImplementation will depend on the presence of the APR/native
         library and the useOpenSSL attribute of the
         AprLifecycleListener.
         Either JSSE or OpenSSL style configuration may be used regardless of
         the SSLImplementation selected. JSSE style configuration is used below.
    -->

    <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxThreads="150" SSLEnabled="true" >
        <SSLHostConfig>
            <Certificate certificateKeystoreFile="/etc/ssl/private/keystore.jks"
                         certificateKeystorePassword="<passwrod input>"
                         certificateKeyAlias="tomcat"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>

    <!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2
....
....

 

iptables를 이용하여 8080으로 접근시 8443으로 라우팅되도록 테이블 설정

http 프로토콜 https로 변환 (web.xml 설정파일에 아래 코드의 <security-constraint> 구문영역 추가)

[root@localhost conf]# iptables -A PREROUTING -t nat -i ens160 -p tcp --dport 8080 -j REDIRECT --to-port 8443
[root@localhost conf]# tail -30 web.xml
....
....
  <!-- here, so be sure to include any of the default values that you wish  -->
  <!-- to use within your application.                                       -->

    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Protected Context</web-resource-name>
            <url-pattern>/*</url-pattern>
        </web-resource-collection>
    <!-- auth-constraint goes here if you requre authentication -->
        <user-data-constraint>
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
        </user-data-constraint>
    </security-constraint>

</web-app>

 

 

References

1. lesstif - "java keytool 사용법 - Keystore 생성, 키쌍 생성, 인증서 등록 및 관리"

www.lesstif.com/java/java-keytool-keystore-20775436.html

 

java keytool 사용법 - Keystore 생성, 키쌍 생성, 인증서 등록 및 관리

-----BEGIN RSA PRIVATE KEY----- MIIEpAIBAAKCAQEA6KLO6jGTx1NMZsN3QJh/YCrVgmZsHlaD8sSFIFUcc5wH0gy6 oKggrOD7gE9CPRb3MQG53hx29c92ih/cFKrN1IoeSPj0ftxZPhKUczfot2CAH3GX BWh0OYeuCIv088aKhSMJJLP9ZruC6Zhb01HYJiWdpOMX53fSMRJZYgjlIHZMi76u ofLnvuP2Ry8VJntw2RFJeei0Z+6+Y

www.lesstif.com

2. lesstif - "apache tomcat 에서 SSL(HTTPS) 서비스 가능하게 설정"

www.lesstif.com/java/apache-tomcat-ssl-https-17105864.html

 

apache tomcat 에서 SSL(HTTPS) 서비스 가능하게 설정

8443이 아닌 다른 Port(ex: 9443) 를 사용할 경우 다른 Connector 에서 사용하는 8443 포트를 변경한 Port 번호(9443) 으로 수정해야 함

www.lesstif.com

3. 한국전자인증 - "Tomcat - SSL 인증서 설치 메뉴얼"

cert.crosscert.com/tomcat-ssl%EC%9D%B8%EC%A6%9D%EC%84%9C-%EC%84%A4%EC%B9%98-%EB%A9%94%EB%89%B4%EC%96%BC/

 

Tomcat - SSL인증서 설치 메뉴얼 - SSL 인증서 발급,종류,가격비교 | 한국전자인증

SSL인증서 설치 메뉴얼 (Tomcat) 백업된 인증서 설치 ※ 본 문서에 안내된 버전 이외의 다른 버전을 사용하시는 경우 안내 내용과 차이가 있을 수 있습니다.※ 본 문서는 기본적인 참고용 자료이며,

cert.crosscert.com

4. Mr콩랑 - "Tomcat9 + SSL 인증서 설치 후기"

srzero.tistory.com/entry/Tomcat9-SSL-%EC%9D%B8%EC%A6%9D%EC%84%9C-%EC%84%A4%EC%B9%98-%ED%9B%84%EA%B8%B0

 

Tomcat9 + SSL 인증서 설치 후기

인터넷에 Tomcat9 기준으로 인증서 설치한 후기가 너무 없어서 고생해서 하나 남겨본다. (1) 인증서 구매 - 우선 인증서가 있어야 한다. 인증서를 어디서 살까 하다가 공짜사서 괜히 고생하기 싫어�

srzero.tistory.com

5. BROADCOM - "Configure Tomcat to redirect all HTTP requests to HTTPS for Enforce UI"

knowledge.broadcom.com/external/article/162130/configure-tomcat-to-redirect-all-http-re.html

 

Configure Tomcat to redirect all HTTP requests to HTTPS for Enforce UI

Article Id: 162130 Status: Published Updated On: 07-02-2020 16:19 Legacy Id: TECH231476

knowledge.broadcom.com