4242public class RangerHSM implements RangerKMSMKI {
4343 static final Logger logger = LoggerFactory .getLogger (RangerHSM .class );
4444
45- private static final String MK_CIPHER = "AES" ;
46- private static final int MK_KeySize = 128 ;
47- private static final String PARTITION_PASSWORD = "ranger.ks.hsm.partition.password" ;
48- private static final String PARTITION_NAME = "ranger.ks.hsm.partition.name" ;
49- private static final String HSM_TYPE = "ranger.ks.hsm.type" ;
50- private static final String ALIAS = "RangerKMSKey" ;
45+ private static final String MK_CIPHER = "AES" ;
46+ private static final int DEFAULT_MK_KEY_SIZE = 256 ;
47+ private static final String PARTITION_PASSWORD = "ranger.ks.hsm.partition.password" ;
48+ private static final String PARTITION_NAME = "ranger.ks.hsm.partition.name" ;
49+ private static final String HSM_TYPE = "ranger.ks.hsm.type" ;
50+ private static final String MK_KEY_SIZE = "ranger.kms.hsm.masterkey.size" ;
51+ private static final String ALIAS = "RangerKMSKey" ;
5152
5253 private KeyStore myStore ;
5354 private String hsmKeystore ;
55+ private int mkKeySize ;
5456
5557 public RangerHSM () {
5658 }
@@ -63,6 +65,7 @@ public RangerHSM(Configuration conf) {
6365 */
6466 String passwd = conf .get (PARTITION_PASSWORD );
6567 String partitionName = conf .get (PARTITION_NAME );
68+ this .mkKeySize = conf .getInt (MK_KEY_SIZE , DEFAULT_MK_KEY_SIZE );
6669 String errorMsg = StringUtils .EMPTY ;
6770
6871 hsmKeystore = conf .get (HSM_TYPE );
@@ -98,19 +101,21 @@ public RangerHSM(Configuration conf) {
98101 public boolean generateMasterKey (String password ) throws Throwable {
99102 logger .debug ("==> RangerHSM.generateMasterKey()" );
100103
104+ boolean isMKGenerated = false ;
105+
101106 if (!this .myStore .containsAlias (ALIAS )) {
102107 try {
103- logger .info ("Generating AES Master Key for '{}' HSM Provider" , hsmKeystore );
108+ logger .info ("Generating AES Master Key for '{}' HSM Provider and keySize is {} " , hsmKeystore , this . mkKeySize );
104109
105110 KeyGenerator keyGen = KeyGenerator .getInstance (MK_CIPHER , hsmKeystore );
106111
107- keyGen .init (MK_KeySize );
112+ keyGen .init (this . mkKeySize );
108113
109114 SecretKey aesKey = keyGen .generateKey ();
110115
111116 myStore .setKeyEntry (ALIAS , aesKey , password .toCharArray (), (java .security .cert .Certificate []) null );
112117
113- return true ;
118+ isMKGenerated = true ;
114119 } catch (Exception e ) {
115120 logger .error ("generateMasterKey : Exception during Ranger Master Key Generation - {}" , e .getMessage ());
116121 }
@@ -120,7 +125,7 @@ public boolean generateMasterKey(String password) throws Throwable {
120125
121126 logger .debug ("<== RangerHSM.generateMasterKey()" );
122127
123- return false ;
128+ return isMKGenerated ;
124129 }
125130
126131 @ Override
0 commit comments