ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject [2/2] incubator-ranger git commit: Trivial cleanup II
Date Thu, 04 Aug 2016 11:19:58 GMT
Trivial cleanup II


Project: http://git-wip-us.apache.org/repos/asf/incubator-ranger/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ranger/commit/8411c64a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ranger/tree/8411c64a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ranger/diff/8411c64a

Branch: refs/heads/master
Commit: 8411c64a6ffefba4332e9f0c74b90d1204fd53c7
Parents: 6116f91
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Thu Aug 4 12:19:40 2016 +0100
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Thu Aug 4 12:19:40 2016 +0100

----------------------------------------------------------------------
 .../hadoop/crypto/key/RangerMasterKey.java      | 36 +++++++-------------
 1 file changed, 12 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/8411c64a/kms/src/main/java/org/apache/hadoop/crypto/key/RangerMasterKey.java
----------------------------------------------------------------------
diff --git a/kms/src/main/java/org/apache/hadoop/crypto/key/RangerMasterKey.java b/kms/src/main/java/org/apache/hadoop/crypto/key/RangerMasterKey.java
index b701193..337b82c 100755
--- a/kms/src/main/java/org/apache/hadoop/crypto/key/RangerMasterKey.java
+++ b/kms/src/main/java/org/apache/hadoop/crypto/key/RangerMasterKey.java
@@ -70,8 +70,7 @@ public class RangerMasterKey implements RangerKMSMKI{
 		logger.info("Getting Master Key");
 		byte masterKeyByte[] = getEncryptedMK();
 		if(masterKeyByte != null && masterKeyByte.length > 0){
-			String masterKey = decryptMasterKey(masterKeyByte, password);		
-			return masterKey;
+			return decryptMasterKey(masterKeyByte, password);		
 		}else{
 			throw new Exception("No Master Key Found");
 		}			
@@ -145,8 +144,7 @@ public class RangerMasterKey implements RangerKMSMKI{
 				  }else {
 					  XXRangerMasterKey rangerMasterKey = rangerKMSDao.getById(lstRangerMasterKey.get(0).getId());
 					  String masterKeyStr = rangerMasterKey.getMasterKey();
-					  byte[] masterKeyFromDBEncrypted = Base64.decode(masterKeyStr) ;
-					  return masterKeyFromDBEncrypted;
+					  return Base64.decode(masterKeyStr) ;
 				  }
 			  }			  
 		  }catch(Exception e){
@@ -181,16 +179,14 @@ public class RangerMasterKey implements RangerKMSMKI{
 			Key secretKey = generateMasterKey();
 			PBEKeySpec pbeKeySpec = getPBEParameterSpec(password);
 			byte[] masterKeyToDB = encryptKey(secretKey.getEncoded(), pbeKeySpec);
-			String masterKey = Base64.encode(masterKeyToDB) ;
-			return masterKey;
+			return Base64.encode(masterKeyToDB) ;
 	}
 	
 	private String encryptMasterKey(String password, byte[] secretKey) throws Throwable {
 		logger.debug("Encrypting Master Key");
 		PBEKeySpec pbeKeySpec = getPBEParameterSpec(password);
 		byte[] masterKeyToDB = encryptKey(secretKey, pbeKeySpec);
-		String masterKey = Base64.encode(masterKeyToDB) ;
-		return masterKey;
+		return Base64.encode(masterKeyToDB) ;
 	}
 	
 	private Key generateMasterKey() throws NoSuchAlgorithmException{
@@ -205,34 +201,28 @@ public class RangerMasterKey implements RangerKMSMKI{
 		byte[] salt = new byte[SALT_SIZE] ;		 
 		System.arraycopy(saltGen, 0, salt, 0, SALT_SIZE);		 
 		int iteration = password.toCharArray().length + 1 ;
-		PBEKeySpec spec = new PBEKeySpec(password.toCharArray(), salt, iteration) ;		 
-		return spec ;
+		return new PBEKeySpec(password.toCharArray(), salt, iteration) ;		 
 	}
 	private byte[] encryptKey(byte[] data, PBEKeySpec keyspec) throws Throwable {
 		SecretKey key = getPasswordKey(keyspec) ;
 		PBEParameterSpec paramSpec = new PBEParameterSpec(keyspec.getSalt(), keyspec.getIterationCount())
;
 		Cipher c = Cipher.getInstance(key.getAlgorithm()) ;
 		c.init(Cipher.ENCRYPT_MODE, key,paramSpec);
-		byte[] encrypted = c.doFinal(data) ;
-		 
-		return encrypted ;
+		return c.doFinal(data) ;
 	}
 	private SecretKey getPasswordKey(PBEKeySpec keyspec) throws Throwable {
 		SecretKeyFactory factory = SecretKeyFactory.getInstance(PBE_ALGO) ;
-		SecretKey PbKey = factory.generateSecret(keyspec) ;
-		return PbKey ;
+		return factory.generateSecret(keyspec) ;
 	}
 	private byte[] decryptKey(byte[] encrypted, PBEKeySpec keyspec) throws Throwable {
 		SecretKey key = getPasswordKey(keyspec) ;
 		PBEParameterSpec paramSpec = new PBEParameterSpec(keyspec.getSalt(), keyspec.getIterationCount())
;
 		Cipher c = Cipher.getInstance(key.getAlgorithm()) ;
 		c.init(Cipher.DECRYPT_MODE, key, paramSpec);
-		byte[] data = c.doFinal(encrypted) ;
-		return data ;
+		return c.doFinal(encrypted) ;
 	}
 	private SecretKey getMasterKeyFromBytes(byte[] keyData) throws Throwable {
-		SecretKeySpec sks = new SecretKeySpec(keyData, MK_CIPHER) ;
-		return sks ;
+		return new SecretKeySpec(keyData, MK_CIPHER) ;
 	}
 	
 	public Map<String, String> getPropertiesWithPrefix(Properties props, String prefix)
{
@@ -249,11 +239,9 @@ public class RangerMasterKey implements RangerKMSMKI{
 				if(key.startsWith(prefix)) {
 					key = key.substring(prefix.length());
 
-					if(key == null) {
-						continue;
-					}
-
-					prefixedProperties.put(key, val);
+					if(key != null) {
+					    prefixedProperties.put(key, val);
+                    }
 				}
 			}
 		}


Mime
View raw message