public class CryptoUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
private static String |
BOOTSTRAP_KEY_PREFIX |
static String |
ENCRYPTED_FSR_CLASS_NAME |
static String |
EWAFFR_CLASS_NAME |
static String |
FILE_BASED_KEY_PROVIDER_CLASS_NAME |
private static Pattern |
HEX_PATTERN |
static int |
IV_LENGTH |
static String |
LEGACY_FBKP_FQCN |
static String |
LEGACY_SKP_FQCN |
private static org.slf4j.Logger |
logger |
private static String |
RELATIVE_NIFI_PROPS_PATH |
static String |
STATIC_KEY_PROVIDER_CLASS_NAME |
private static List<Integer> |
UNLIMITED_KEY_LENGTHS |
| Constructor and Description |
|---|
CryptoUtils() |
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
concatByteArrays(byte[]... arrays)
Concatenates multiple byte[] into a single byte[].
|
static boolean |
constantTimeEquals(byte[] a,
byte[] b)
Returns true if the two parameters are equal.
|
static boolean |
constantTimeEquals(char[] a,
char[] b)
Returns true if the two parameters are equal.
|
static boolean |
constantTimeEquals(String a,
String b)
Returns true if the two parameters are equal.
|
private static byte[] |
convertCharsToBytes(char[] chars)
Returns a
byte[] containing the value of the provided char[] without using new String(chars).getBytes() which would put sensitive data (the password) in the String pool. |
static String |
extractKeyFromBootstrapFile()
Returns the key (if any) used to encrypt sensitive properties, extracted from
$NIFI_HOME/conf/bootstrap.conf. |
static String |
extractKeyFromBootstrapFile(String bootstrapPath)
Returns the key (if any) used to encrypt sensitive properties, extracted from
$NIFI_HOME/conf/bootstrap.conf. |
static SecretKey |
formKeyFromHex(String keyHex)
Returns a
SecretKey formed from the hexadecimal key bytes (validity is checked). |
static String |
getDefaultFilePath()
Returns the default file path to
$NIFI_HOME/conf/nifi.properties. |
static SecretKey |
getMasterKey()
Returns the master key from the
bootstrap.conf file used to encrypt various sensitive properties and data encryption keys. |
(package private) static String |
handleLegacyPackages(String implementationClassName) |
static boolean |
isEmpty(String src)
Utility method which returns true if the string is null, empty, or entirely whitespace.
|
static boolean |
isHexString(String hexString)
Returns true if the input is valid hexadecimal (does not enforce length and is case-insensitive).
|
static boolean |
isUnlimitedStrengthCryptoAvailable() |
static boolean |
isValidKeyProvider(String keyProviderImplementation,
String keyProviderLocation,
String keyId,
Map<String,String> encryptionKeys)
Returns true if the provided configuration values successfully define the specified
KeyProvider. |
static boolean |
isValidRepositoryEncryptionConfiguration(RepositoryEncryptionConfiguration rec)
Returns true if the provided configuration values are valid (shallow evaluation only; does not validate the keys
contained in a
FileBasedKeyProvider). |
static boolean |
keyIsValid(String encryptionKeyHex)
Returns true if the provided key is valid hex and is the correct length for the current system's JCE policies.
|
static Map<String,SecretKey> |
readKeys(String filepath,
SecretKey masterKey)
Returns a map containing the key IDs and the parsed key from a key provider definition file.
|
private static final org.slf4j.Logger logger
public static final String STATIC_KEY_PROVIDER_CLASS_NAME
public static final String FILE_BASED_KEY_PROVIDER_CLASS_NAME
public static final String LEGACY_SKP_FQCN
public static final String LEGACY_FBKP_FQCN
private static final String RELATIVE_NIFI_PROPS_PATH
private static final String BOOTSTRAP_KEY_PREFIX
private static final Pattern HEX_PATTERN
public static final int IV_LENGTH
public static final String ENCRYPTED_FSR_CLASS_NAME
public static final String EWAFFR_CLASS_NAME
public static boolean isUnlimitedStrengthCryptoAvailable()
public static boolean isEmpty(String src)
src - the string to evaluatepublic static byte[] concatByteArrays(byte[]... arrays)
throws IOException
arrays - the component byte[] in orderIOException - this should never be thrownpublic static boolean isValidRepositoryEncryptionConfiguration(RepositoryEncryptionConfiguration rec)
FileBasedKeyProvider).rec - the configuration to validatepublic static boolean isValidKeyProvider(String keyProviderImplementation, String keyProviderLocation, String keyId, Map<String,String> encryptionKeys)
KeyProvider.keyProviderImplementation - the FQ class name of the KeyProvider implementationkeyProviderLocation - the location of the definition (for FileBasedKeyProvider, etc.)keyId - the active key IDencryptionKeys - a map of key IDs to key material in hex formatstatic String handleLegacyPackages(String implementationClassName) throws KeyManagementException
KeyManagementExceptionpublic static boolean keyIsValid(String encryptionKeyHex)
encryptionKeyHex - the key in hexadecimalpublic static boolean isHexString(String hexString)
hexString - the string to evaluatepublic static SecretKey formKeyFromHex(String keyHex) throws KeyManagementException
SecretKey formed from the hexadecimal key bytes (validity is checked).keyHex - the key in hex formKeyManagementExceptionpublic static Map<String,SecretKey> readKeys(String filepath, SecretKey masterKey) throws KeyManagementException
KeyManagementException will be thrown.filepath - the key definition file pathmasterKey - the master key used to decrypt each key definitionKeyManagementException - if the file is missing or invalidpublic static SecretKey getMasterKey() throws KeyManagementException
bootstrap.conf file used to encrypt various sensitive properties and data encryption keys.KeyManagementException - if the key cannot be readpublic static String extractKeyFromBootstrapFile() throws IOException
$NIFI_HOME/conf/bootstrap.conf.IOException - if the file is not readablepublic static String extractKeyFromBootstrapFile(String bootstrapPath) throws IOException
$NIFI_HOME/conf/bootstrap.conf.bootstrapPath - the path to the bootstrap fileIOException - if the file is not readablepublic static String getDefaultFilePath()
$NIFI_HOME/conf/nifi.properties. If the system
property nifi.properties.file.path is not set, it will be set to the relative
path conf/nifi.properties.public static boolean constantTimeEquals(String a, String b)
a - a String to compareb - a String to comparepublic static boolean constantTimeEquals(char[] a,
char[] b)
Strings when converting to byte[]
to avoid putting sensitive data in the String pool.a - a char[] to compareb - a char[] to comparepublic static boolean constantTimeEquals(byte[] a,
byte[] b)
a - a byte[] to compareb - a byte[] to compareprivate static byte[] convertCharsToBytes(char[] chars)
byte[] containing the value of the provided char[] without using new String(chars).getBytes() which would put sensitive data (the password) in the String pool.chars - the characters to convertCopyright © 2020 Apache NiFi Project. All rights reserved.