java - configure SSL password like ${keystore.password} in tomcat server.xml -


i want configure ssl passwords ${keystore.password} in tomcat server.xml. tomcat 7, wrote code , it's working fine. in tomcat 8 it's not wokring because introspectionutils being moved tomcat-coyote.jar.

if has done same thing in tomcat 8 please tell me how proceed.

below code sample working in tomcat 7. run, create jar below code , in catalina.proerties add 2 lines:

org.apache.tomcat.util.digester.property_source=com.sumit.logic.decrypt
keystore.password=9gm4m64fg+jjhnbtk+buwg==

code:

package com.comviva.logic;  import java.io.ioexception; import javax.crypto.cipher; import org.apache.tomcat.util.introspectionutils; import javax.crypto.spec.secretkeyspec; import org.apache.commons.codec.binary.base64; import org.apache.commons.logging.log; import org.apache.commons.logging.logfactory;  import com.comviva.util.util;      public class decrypt implements introspectionutils.propertysource {          static log log = logfactory.getlog(decrypt.class);         static int count =0;         static string encrypted_password=null;         private static byte[] key = {             0x74, 0x68, 0x69, 0x73, 0x49, 0x73, 0x41, 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x4b, 0x65, 0x79         };//"thisisasecretkey";           public static string decrypt(string strtodecrypt)         {             try             {                 cipher cipher = cipher.getinstance("aes/ecb/pkcs5padding");                 final secretkeyspec secretkey = new secretkeyspec(key, "aes");                 cipher.init(cipher.decrypt_mode, secretkey);                 final string decryptedstring = new string(cipher.dofinal(base64.decodebase64(strtodecrypt)));                 return decryptedstring;             }             catch (exception e)             {                 log.error("error while decrypting", e);                 return null;             }          }          @override         public string getproperty(string arg0) {              system.out.println("count " + count++);              string fname=this.getclass().getclassloader().getresource("").getfile();             fname=fname.substring(0, fname.length()-4);             string os = system.getproperty("os.name").tolowercase();             if(os.indexof("win")>=0)             {                 log.info("system type :"+os);                 fname=fname.concat("conf\\catalina.properties\n");                 system.out.print("file name :"+fname);             }             else             {                 log.info("system type :"+os);                 fname=fname.concat("conf/catalina.properties\n");                 system.out.print("file name :"+fname);             }             log.info("file read successfully");             try {                 util utility=new util(fname);                 log.info("hello");                  encrypted_password=utility.getvalue(arg0);                 log.info("ecrypted password :" + encrypted_password);                 system.out.println("ecrypted password :" + encrypted_password);             } catch (ioexception e) {                 // todo auto-generated catch block                 e.printstacktrace();             }              return decrypt(encrypted_password);         }      } 

i able in tomcat 8 passing below parameter in catalina_opts

-dorg.apache.tomcat.util.digester.property_source=com.sumit.logic.decrypt  

and introspectionutils moved "tomcat-util.jar"


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -