use of password.pwm.util.secure.PwmSecurityKey in project pwm by pwm-project.
the class Configuration method getSecurityKey.
public PwmSecurityKey getSecurityKey() throws PwmUnrecoverableException {
final PasswordData configValue = readSettingAsPassword(PwmSetting.PWM_SECURITY_KEY);
if (configValue == null || configValue.getStringValue().isEmpty()) {
final String errorMsg = "Security Key value is not configured,will generate temp value for use by runtime instance";
final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_INVALID_SECURITY_KEY, errorMsg);
LOGGER.warn(errorInfo.toDebugStr());
if (tempInstanceKey == null) {
tempInstanceKey = new PwmSecurityKey(PwmRandom.getInstance().alphaNumericString(256));
}
return tempInstanceKey;
}
final int minSecurityKeyLength = Integer.parseInt(readAppProperty(AppProperty.SECURITY_CONFIG_MIN_SECURITY_KEY_LENGTH));
if (configValue.getStringValue().length() < minSecurityKeyLength) {
final String errorMsg = "Security Key must be greater than 32 characters in length";
final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_INVALID_SECURITY_KEY, errorMsg);
throw new PwmUnrecoverableException(errorInfo);
}
try {
return new PwmSecurityKey(configValue.getStringValue());
} catch (Exception e) {
final String errorMsg = "unexpected error generating Security Key crypto: " + e.getMessage();
final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_INVALID_SECURITY_KEY, errorMsg);
LOGGER.error(errorInfo.toDebugStr(), e);
throw new PwmUnrecoverableException(errorInfo);
}
}
Aggregations