Search in sources :

Example 11 with StandardPBEStringEncryptor

use of org.jasypt.encryption.pbe.StandardPBEStringEncryptor in project divide by HiddenStage.

the class AuthTokenUtils method getEncryptor.

private static StandardPBEStringEncryptor getEncryptor(String key) {
    StandardPBEStringEncryptor encryptor;
    if (encryptors.containsKey(key))
        encryptor = encryptors.get(key);
    else {
        encryptor = new StandardPBEStringEncryptor();
        encryptor.setPassword(key);
    }
    return encryptor;
}
Also used : StandardPBEStringEncryptor(org.jasypt.encryption.pbe.StandardPBEStringEncryptor)

Example 12 with StandardPBEStringEncryptor

use of org.jasypt.encryption.pbe.StandardPBEStringEncryptor in project cloudstack by apache.

the class EncryptionSecretKeyChanger method migrateProperties.

private boolean migrateProperties(File dbPropsFile, Properties dbProps, String newMSKey, String newDBKey) {
    System.out.println("Migrating db.properties..");
    StandardPBEStringEncryptor msEncryptor = new StandardPBEStringEncryptor();
    ;
    initEncryptor(msEncryptor, newMSKey);
    try {
        PropertiesConfiguration newDBProps = new PropertiesConfiguration(dbPropsFile);
        if (newDBKey != null && !newDBKey.isEmpty()) {
            newDBProps.setProperty("db.cloud.encrypt.secret", "ENC(" + msEncryptor.encrypt(newDBKey) + ")");
        }
        String prop = dbProps.getProperty("db.cloud.password");
        if (prop != null && !prop.isEmpty()) {
            newDBProps.setProperty("db.cloud.password", "ENC(" + msEncryptor.encrypt(prop) + ")");
        }
        prop = dbProps.getProperty("db.usage.password");
        if (prop != null && !prop.isEmpty()) {
            newDBProps.setProperty("db.usage.password", "ENC(" + msEncryptor.encrypt(prop) + ")");
        }
        newDBProps.save(dbPropsFile.getAbsolutePath());
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    System.out.println("Migrating db.properties Done.");
    return true;
}
Also used : StandardPBEStringEncryptor(org.jasypt.encryption.pbe.StandardPBEStringEncryptor) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SQLException(java.sql.SQLException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) EncryptionOperationNotPossibleException(org.jasypt.exceptions.EncryptionOperationNotPossibleException)

Example 13 with StandardPBEStringEncryptor

use of org.jasypt.encryption.pbe.StandardPBEStringEncryptor in project cloudstack by apache.

the class EncryptionUtil method initialize.

private static void initialize(String key) {
    StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor();
    standardPBEStringEncryptor.setAlgorithm("PBEWITHSHA1ANDDESEDE");
    standardPBEStringEncryptor.setPassword(key);
    encryptor = standardPBEStringEncryptor;
}
Also used : StandardPBEStringEncryptor(org.jasypt.encryption.pbe.StandardPBEStringEncryptor)

Example 14 with StandardPBEStringEncryptor

use of org.jasypt.encryption.pbe.StandardPBEStringEncryptor in project cloudstack by apache.

the class DbProperties method getDbProperties.

public static synchronized Properties getDbProperties() {
    if (!loaded) {
        Properties dbProps = new Properties();
        InputStream is = null;
        try {
            File props = PropertiesUtil.findConfigFile("db.properties");
            if (props != null && props.exists()) {
                is = new FileInputStream(props);
            }
            if (is == null) {
                is = PropertiesUtil.openStreamFromURL("db.properties");
            }
            if (is == null) {
                System.err.println("Failed to find db.properties");
                log.error("Failed to find db.properties");
            }
            if (is != null) {
                dbProps.load(is);
            }
            EncryptionSecretKeyChecker checker = new EncryptionSecretKeyChecker();
            checker.check(dbProps);
            if (EncryptionSecretKeyChecker.useEncryption()) {
                StandardPBEStringEncryptor encryptor = EncryptionSecretKeyChecker.getEncryptor();
                EncryptableProperties encrDbProps = new EncryptableProperties(encryptor);
                encrDbProps.putAll(dbProps);
                dbProps = encrDbProps;
            }
        } catch (IOException e) {
            throw new IllegalStateException("Failed to load db.properties", e);
        } finally {
            IOUtils.closeQuietly(is);
        }
        properties = dbProps;
        loaded = true;
    }
    return properties;
}
Also used : StandardPBEStringEncryptor(org.jasypt.encryption.pbe.StandardPBEStringEncryptor) EncryptableProperties(org.jasypt.properties.EncryptableProperties) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) EncryptableProperties(org.jasypt.properties.EncryptableProperties) Properties(java.util.Properties) EncryptionSecretKeyChecker(com.cloud.utils.crypt.EncryptionSecretKeyChecker) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 15 with StandardPBEStringEncryptor

use of org.jasypt.encryption.pbe.StandardPBEStringEncryptor in project cloudstack by apache.

the class DBEncryptionUtil method initialize.

private static void initialize() {
    final Properties dbProps = DbProperties.getDbProperties();
    if (EncryptionSecretKeyChecker.useEncryption()) {
        String dbSecretKey = dbProps.getProperty("db.cloud.encrypt.secret");
        if (dbSecretKey == null || dbSecretKey.isEmpty()) {
            throw new CloudRuntimeException("Empty DB secret key in db.properties");
        }
        s_encryptor = new StandardPBEStringEncryptor();
        s_encryptor.setAlgorithm("PBEWithMD5AndDES");
        s_encryptor.setPassword(dbSecretKey);
    } else {
        throw new CloudRuntimeException("Trying to encrypt db values when encrytion is not enabled");
    }
}
Also used : StandardPBEStringEncryptor(org.jasypt.encryption.pbe.StandardPBEStringEncryptor) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Properties(java.util.Properties) DbProperties(com.cloud.utils.db.DbProperties)

Aggregations

StandardPBEStringEncryptor (org.jasypt.encryption.pbe.StandardPBEStringEncryptor)16 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)6 IOException (java.io.IOException)6 Properties (java.util.Properties)6 FileNotFoundException (java.io.FileNotFoundException)5 EncryptableProperties (org.jasypt.properties.EncryptableProperties)5 File (java.io.File)4 FileInputStream (java.io.FileInputStream)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 SQLException (java.sql.SQLException)4 ConfigurationException (org.apache.commons.configuration.ConfigurationException)4 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)4 EncryptionOperationNotPossibleException (org.jasypt.exceptions.EncryptionOperationNotPossibleException)4 BufferedWriter (java.io.BufferedWriter)2 FileWriter (java.io.FileWriter)2 PojoServiceRegistryFactoryImpl (org.apache.felix.connect.PojoServiceRegistryFactoryImpl)2 BundleDescriptor (org.apache.felix.connect.launch.BundleDescriptor)2 ClasspathScanner (org.apache.felix.connect.launch.ClasspathScanner)2 PojoServiceRegistry (org.apache.felix.connect.launch.PojoServiceRegistry)2 EnvironmentStringPBEConfig (org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig)2