Search in sources :

Example 26 with PwmSecurityKey

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);
    }
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) PwmSecurityKey(password.pwm.util.secure.PwmSecurityKey) PasswordData(password.pwm.util.PasswordData) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

PwmSecurityKey (password.pwm.util.secure.PwmSecurityKey)26 Element (org.jdom2.Element)19 ArrayList (java.util.ArrayList)15 List (java.util.List)11 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)6 Map (java.util.Map)4 ErrorInformation (password.pwm.error.ErrorInformation)4 PasswordData (password.pwm.util.PasswordData)4 TreeMap (java.util.TreeMap)3 IOException (java.io.IOException)2 X509Certificate (java.security.cert.X509Certificate)2 LinkedHashMap (java.util.LinkedHashMap)2 PwmException (password.pwm.error.PwmException)2 PwmOperationalException (password.pwm.error.PwmOperationalException)2 PwmSessionBean (password.pwm.http.bean.PwmSessionBean)2 PwmBlockAlgorithm (password.pwm.util.secure.PwmBlockAlgorithm)2 TypeToken (com.google.gson.reflect.TypeToken)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 PrivateKey (java.security.PrivateKey)1 CertificateEncodingException (java.security.cert.CertificateEncodingException)1