Skip to content

Commit 27f9656

Browse files
RANGER-5320:Handling unsupported cipher key creation (#672)
1 parent 32288bb commit 27f9656

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

kms/src/main/java/org/apache/hadoop/crypto/key/RangerKeyStoreProvider.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.apache.commons.lang.StringUtils;
2121
import org.apache.hadoop.classification.InterfaceAudience;
2222
import org.apache.hadoop.conf.Configuration;
23+
import org.apache.hadoop.crypto.CipherSuite;
2324
import org.apache.hadoop.fs.Path;
2425
import org.apache.ranger.credentialapi.CredentialReader;
2526
import org.apache.ranger.kms.dao.DaoManager;
@@ -442,6 +443,7 @@ public KeyVersion createKey(String name, byte[] material, Options options) throw
442443
logger.debug("==> createKey({})", name);
443444

444445
KeyVersion ret;
446+
validateKeyCiphers(options.getCipher());
445447

446448
try (AutoClosableWriteLock ignored = new AutoClosableWriteLock(lock)) {
447449
reloadKeys();
@@ -597,6 +599,16 @@ private static Configuration getConfiguration(boolean loadHadoopDefaults, String
597599
return conf;
598600
}
599601

602+
private void validateKeyCiphers(String ciphers) throws IOException {
603+
if (StringUtils.isNotEmpty(ciphers)) {
604+
try {
605+
CipherSuite.convert(ciphers);
606+
} catch (Exception e) {
607+
throw new IOException("Invalid ciphers: " + ciphers, e);
608+
}
609+
}
610+
}
611+
600612
private static void getFromJceks(Configuration conf, String path, String alias, String key) {
601613
logger.debug("==> getFromJceks()");
602614

0 commit comments

Comments
 (0)