Encrypt tomcat keystore password

前端 未结 6 981
北海茫月
北海茫月 2020-12-25 08:44

Is there an option to encrypt keystorePass value in tomcat server.xml? I don\'t want it to be a plain text

    

        
6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-25 09:09

    1) Create the CustomEncryptService to encrypt and decrypt your password.

    2) Override Http11Nio2Protocol class, something similar to the below code. (As mentioned above by user3675974)

    public class CustomHttp11Nio2Protocol extends org.apache.coyote.http11.Http11Nio2Protocol {
    
      @Override
      public void setKeystorePass(String s) {
        try {
          super.setKeystorePass(new CustomEncryptService().decrypt(s));
        } catch (final Exception e){
          super.setKeystorePass("");
        }
      }
    }
    
    

    3) Configure the overridden class in the protocol attribute in server.xml like below.

    
    

    4) Since this CustomHttp11Nio2Protocol class should be available during startup, create the Jar having the CustomHttp11Nio2Protocol and CustomEncryptService class, and put it inside your tomcat/lib.

    Hope this helps.

提交回复
热议问题