@@ -44,13 +44,15 @@ public class RangerHSM implements RangerKMSMKI {
4444
4545 private static final String MK_CIPHER = "AES" ;
4646 private static final int MK_KeySize = 128 ;
47+ private static final String MK_ALIAS = "ranger.ks.hsm.masterkey.alias" ;
4748 private static final String PARTITION_PASSWORD = "ranger.ks.hsm.partition.password" ;
4849 private static final String PARTITION_NAME = "ranger.ks.hsm.partition.name" ;
4950 private static final String HSM_TYPE = "ranger.ks.hsm.type" ;
50- private static final String ALIAS = "RangerKMSKey" ;
51+ private static final String DEFAULT_ALIAS = "RangerKMSKey" ;
5152
5253 private KeyStore myStore ;
5354 private String hsmKeystore ;
55+ private String alias ;
5456
5557 public RangerHSM () {
5658 }
@@ -66,6 +68,7 @@ public RangerHSM(Configuration conf) {
6668 String errorMsg = StringUtils .EMPTY ;
6769
6870 hsmKeystore = conf .get (HSM_TYPE );
71+ this .alias = conf .get (MK_ALIAS , DEFAULT_ALIAS );
6972
7073 try {
7174 ByteArrayInputStream is1 = new ByteArrayInputStream (("tokenlabel:" + partitionName ).getBytes ());
@@ -98,7 +101,7 @@ public RangerHSM(Configuration conf) {
98101 public boolean generateMasterKey (String password ) throws Throwable {
99102 logger .debug ("==> RangerHSM.generateMasterKey()" );
100103
101- if (!this .myStore .containsAlias (ALIAS )) {
104+ if (!this .myStore .containsAlias (alias )) {
102105 try {
103106 logger .info ("Generating AES Master Key for '{}' HSM Provider" , hsmKeystore );
104107
@@ -108,14 +111,14 @@ public boolean generateMasterKey(String password) throws Throwable {
108111
109112 SecretKey aesKey = keyGen .generateKey ();
110113
111- myStore .setKeyEntry (ALIAS , aesKey , password .toCharArray (), (java .security .cert .Certificate []) null );
114+ myStore .setKeyEntry (alias , aesKey , password .toCharArray (), (java .security .cert .Certificate []) null );
112115
113116 return true ;
114117 } catch (Exception e ) {
115118 logger .error ("generateMasterKey : Exception during Ranger Master Key Generation - {}" , e .getMessage ());
116119 }
117120 } else {
118- logger .info ("Master key with alias - '{}' already exists!" , ALIAS );
121+ logger .info ("Master key with alias - '{}' already exists!" , alias );
119122 }
120123
121124 logger .debug ("<== RangerHSM.generateMasterKey()" );
@@ -131,12 +134,12 @@ public String getMasterKey(String password) throws Throwable {
131134 try {
132135 logger .debug ("Searching for Ranger Master Key in Luna Keystore" );
133136
134- boolean result = myStore .containsAlias (ALIAS );
137+ boolean result = myStore .containsAlias (alias );
135138
136139 if (result ) {
137140 logger .debug ("Ranger Master Key is present in Keystore" );
138141
139- SecretKey key = (SecretKey ) myStore .getKey (ALIAS , password .toCharArray ());
142+ SecretKey key = (SecretKey ) myStore .getKey (alias , password .toCharArray ());
140143
141144 return Base64 .encode (key .getEncoded ());
142145 }
@@ -155,7 +158,7 @@ public boolean setMasterKey(String password, byte[] key) {
155158 try {
156159 Key aesKey = new SecretKeySpec (key , MK_CIPHER );
157160
158- myStore .setKeyEntry (ALIAS , aesKey , password .toCharArray (), (java .security .cert .Certificate []) null );
161+ myStore .setKeyEntry (alias , aesKey , password .toCharArray (), (java .security .cert .Certificate []) null );
159162
160163 return true ;
161164 } catch (KeyStoreException e ) {
0 commit comments