Search in sources :

Example 16 with PwmSecurityKey

use of password.pwm.util.secure.PwmSecurityKey in project pwm by pwm-project.

the class AbstractOtpOperator method decryptAttributeValue.

/**
 * Decrypt the given string using the PWM encryption key.
 */
public String decryptAttributeValue(final String encrypted) throws PwmUnrecoverableException, PwmOperationalException {
    final PwmBlockAlgorithm pwmBlockAlgorithm = figureBlockAlg();
    final PwmSecurityKey pwmSecurityKey = pwmApplication.getConfig().getSecurityKey();
    return SecureEngine.decryptStringValue(encrypted, pwmSecurityKey, pwmBlockAlgorithm);
}
Also used : PwmSecurityKey(password.pwm.util.secure.PwmSecurityKey) PwmBlockAlgorithm(password.pwm.util.secure.PwmBlockAlgorithm)

Example 17 with PwmSecurityKey

use of password.pwm.util.secure.PwmSecurityKey in project pwm by pwm-project.

the class AbstractOtpOperator method encryptAttributeValue.

/**
 * Encrypt the given string using the PWM encryption key.
 */
public String encryptAttributeValue(final String unencrypted) throws PwmUnrecoverableException, PwmOperationalException {
    final PwmBlockAlgorithm pwmBlockAlgorithm = figureBlockAlg();
    final PwmSecurityKey pwmSecurityKey = pwmApplication.getConfig().getSecurityKey();
    return SecureEngine.encryptToString(unencrypted, pwmSecurityKey, pwmBlockAlgorithm);
}
Also used : PwmSecurityKey(password.pwm.util.secure.PwmSecurityKey) PwmBlockAlgorithm(password.pwm.util.secure.PwmBlockAlgorithm)

Example 18 with PwmSecurityKey

use of password.pwm.util.secure.PwmSecurityKey in project pwm by pwm-project.

the class CustomLinkValue method factory.

public static StoredValueFactory factory() {
    return new StoredValueFactory() {

        public CustomLinkValue fromJson(final String input) {
            if (input == null) {
                return new CustomLinkValue(Collections.emptyList());
            } else {
                List<CustomLinkConfiguration> srcList = JsonUtil.deserialize(input, new TypeToken<List<CustomLinkConfiguration>>() {
                });
                srcList = srcList == null ? Collections.emptyList() : srcList;
                while (srcList.contains(null)) {
                    srcList.remove(null);
                }
                return new CustomLinkValue(Collections.unmodifiableList(srcList));
            }
        }

        public CustomLinkValue fromXmlElement(final Element settingElement, final PwmSecurityKey key) throws PwmOperationalException {
            final List valueElements = settingElement.getChildren("value");
            final List<CustomLinkConfiguration> values = new ArrayList<>();
            for (final Object loopValue : valueElements) {
                final Element loopValueElement = (Element) loopValue;
                final String value = loopValueElement.getText();
                if (value != null && value.length() > 0 && loopValueElement.getAttribute("locale") == null) {
                    values.add(JsonUtil.deserialize(value, CustomLinkConfiguration.class));
                }
            }
            return new CustomLinkValue(values);
        }
    };
}
Also used : PwmSecurityKey(password.pwm.util.secure.PwmSecurityKey) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) CustomLinkConfiguration(password.pwm.config.CustomLinkConfiguration) ArrayList(java.util.ArrayList) List(java.util.List)

Example 19 with PwmSecurityKey

use of password.pwm.util.secure.PwmSecurityKey in project pwm by pwm-project.

the class FileValue method factory.

public static StoredValueFactory factory() {
    return new StoredValueFactory() {

        public FileValue fromXmlElement(final Element settingElement, final PwmSecurityKey input) throws PwmOperationalException {
            final List valueElements = settingElement.getChildren("value");
            final Map<FileInformation, FileContent> values = new LinkedHashMap<>();
            for (final Object loopValue : valueElements) {
                final Element loopValueElement = (Element) loopValue;
                final Element loopFileInformation = loopValueElement.getChild("FileInformation");
                if (loopFileInformation != null) {
                    final String loopFileInformationJson = loopFileInformation.getText();
                    final FileInformation fileInformation = JsonUtil.deserialize(loopFileInformationJson, FileInformation.class);
                    final Element loopFileContentElement = loopValueElement.getChild("FileContent");
                    if (loopFileContentElement != null) {
                        final String fileContentString = loopFileContentElement.getText();
                        final FileContent fileContent;
                        try {
                            fileContent = FileContent.fromEncodedString(fileContentString);
                            values.put(fileInformation, fileContent);
                        } catch (IOException e) {
                            LOGGER.error("error reading file contents item: " + e.getMessage(), e);
                        }
                    }
                }
            }
            return new FileValue(values);
        }

        public StoredValue fromJson(final String input) {
            throw new IllegalStateException("not implemented");
        }
    };
}
Also used : Element(org.jdom2.Element) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) PwmSecurityKey(password.pwm.util.secure.PwmSecurityKey) ArrayList(java.util.ArrayList) List(java.util.List)

Example 20 with PwmSecurityKey

use of password.pwm.util.secure.PwmSecurityKey in project pwm by pwm-project.

the class NumericValue method factory.

public static StoredValueFactory factory() {
    return new StoredValueFactory() {

        public NumericValue fromJson(final String value) {
            return new NumericValue(JsonUtil.deserialize(value, Long.class));
        }

        public NumericValue fromXmlElement(final Element settingElement, final PwmSecurityKey input) {
            final Element valueElement = settingElement.getChild("value");
            final String value = valueElement.getText();
            return new NumericValue(Long.parseLong(value));
        }
    };
}
Also used : PwmSecurityKey(password.pwm.util.secure.PwmSecurityKey) Element(org.jdom2.Element)

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