Search in sources :

Example 1 with ProtectorImpl

use of com.evolveum.midpoint.prism.crypto.ProtectorImpl in project midpoint by Evolveum.

the class PrismInternalTestUtil method createProtector.

public static Protector createProtector(String xmlCipher) {
    ProtectorImpl protector = new ProtectorImpl();
    protector.setKeyStorePassword(KEYSTORE_PASSWORD);
    protector.setKeyStorePath(KEYSTORE_PATH);
    protector.setEncryptionAlgorithm(xmlCipher);
    protector.init();
    return protector;
}
Also used : ProtectorImpl(com.evolveum.midpoint.prism.crypto.ProtectorImpl)

Example 2 with ProtectorImpl

use of com.evolveum.midpoint.prism.crypto.ProtectorImpl in project midpoint by Evolveum.

the class ExpressionTestUtil method createInitializedProtector.

public static ProtectorImpl createInitializedProtector(PrismContext prismContext) {
    ProtectorImpl protector = new ProtectorImpl();
    protector.setKeyStorePath(MidPointTestConstants.KEYSTORE_PATH);
    protector.setKeyStorePassword(MidPointTestConstants.KEYSTORE_PASSWORD);
    protector.init();
    return protector;
}
Also used : ProtectorImpl(com.evolveum.midpoint.prism.crypto.ProtectorImpl)

Example 3 with ProtectorImpl

use of com.evolveum.midpoint.prism.crypto.ProtectorImpl in project midpoint by Evolveum.

the class KeyStoreDumper method execute.

public void execute() {
    try {
        ApplicationContext context = new ClassPathXmlApplicationContext(CONTEXTS);
        Protector protector = context.getBean("protector", Protector.class);
        KeyStore keyStore = protector.getKeyStore();
        System.out.println("###################################################");
        System.out.println("Printing keys from key store");
        if (protector instanceof ProtectorImpl) {
            ProtectorImpl aesProtector = (ProtectorImpl) protector;
            System.out.println("Using key store from location: " + aesProtector.getKeyStorePath());
        //			System.out.println("Cipher: " + aesProtector.getXmlCipher());
        }
        Enumeration<String> aliases = keyStore.aliases();
        while (aliases.hasMoreElements()) {
            String alias = aliases.nextElement();
            System.out.println("===== ALIAS: " + alias + "=====");
            System.out.println("Creation date: " + keyStore.getCreationDate(alias));
            System.out.println("Type: " + keyStore.getType());
            if (keyStore.getCertificate(alias) != null) {
                System.out.println("Certificate: " + keyStore.getCertificate(alias));
            }
            if (keyStore.getCertificateChain(alias) != null) {
                System.out.println("Certificate chain: " + keyStore.getCertificateChain(alias));
            }
            ProtectionParameter protParam = new KeyStore.PasswordProtection("midpoint".toCharArray());
            Entry entry = keyStore.getEntry(alias, protParam);
            if (entry instanceof SecretKeyEntry) {
                System.out.println("Secret key entry: ");
                SecretKeyEntry skEntry = (SecretKeyEntry) entry;
                SecretKey key = skEntry.getSecretKey();
                System.out.println("	Algorithm: " + key.getAlgorithm());
                System.out.println("	Format: " + key.getFormat());
                System.out.println("	Key length: " + key.getEncoded().length * 8);
                if (protector instanceof ProtectorImpl) {
                    System.out.println("	Key name: " + ((ProtectorImpl) protector).getSecretKeyDigest(key));
                }
            //				Cipher cipher = Cipher.getInstance(key.getAlgorithm());
            //				System.out.println("	Cipher algorithm" + cipher.getAlgorithm());
            }
            //TODO: add dump also for other types of keys
            Provider provider = keyStore.getProvider();
            System.out.println("Provder name: " + provider.getName() + "\n");
        }
        System.out.println("###################################################");
    } catch (KeyStoreException ex) {
        System.out.println("Failed to print information about keyStore. Reason: " + ex.getMessage());
        return;
    } catch (UnrecoverableEntryException ex) {
        System.out.println("Failed to print information about keyStore. Reason: " + ex.getMessage());
        return;
    } catch (NoSuchAlgorithmException ex) {
        System.out.println("Failed to print information about keyStore. Reason: " + ex.getMessage());
        return;
    } catch (EncryptionException ex) {
        System.out.println("Failed to print information about keyStore. Reason: " + ex.getMessage());
        return;
    }
}
Also used : ProtectorImpl(com.evolveum.midpoint.prism.crypto.ProtectorImpl) SecretKeyEntry(java.security.KeyStore.SecretKeyEntry) KeyStoreException(java.security.KeyStoreException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStore(java.security.KeyStore) Provider(java.security.Provider) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SecretKeyEntry(java.security.KeyStore.SecretKeyEntry) Entry(java.security.KeyStore.Entry) SecretKey(javax.crypto.SecretKey) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) UnrecoverableEntryException(java.security.UnrecoverableEntryException) Protector(com.evolveum.midpoint.prism.crypto.Protector) ProtectionParameter(java.security.KeyStore.ProtectionParameter)

Example 4 with ProtectorImpl

use of com.evolveum.midpoint.prism.crypto.ProtectorImpl in project midpoint by Evolveum.

the class ConfigurableProtectorFactory method getProtector.

public Protector getProtector() {
    ProtectorImpl protector = new ProtectorImpl();
    protector.setEncryptionKeyAlias(protectorConfig.getEncryptionKeyAlias());
    protector.setKeyStorePassword(protectorConfig.getKeyStorePassword());
    protector.setKeyStorePath(protectorConfig.getKeyStorePath());
    protector.setEncryptionAlgorithm(protectorConfig.getXmlCipher());
    protector.init();
    return protector;
}
Also used : ProtectorImpl(com.evolveum.midpoint.prism.crypto.ProtectorImpl)

Example 5 with ProtectorImpl

use of com.evolveum.midpoint.prism.crypto.ProtectorImpl in project midpoint by Evolveum.

the class AbstractScriptTest method setupFactory.

@BeforeClass
public void setupFactory() {
    PrismContext prismContext = PrismTestUtil.getPrismContext();
    ObjectResolver resolver = new DirectoryFileObjectResolver(OBJECTS_DIR);
    Protector protector = new ProtectorImpl();
    Collection<FunctionLibrary> functions = new ArrayList<FunctionLibrary>();
    functions.add(FunctionLibraryUtil.createBasicFunctionLibrary(prismContext, protector));
    scriptExpressionfactory = new ScriptExpressionFactory(resolver, prismContext, protector);
    scriptExpressionfactory.setFunctions(functions);
    evaluator = createEvaluator(prismContext, protector);
    String languageUrl = evaluator.getLanguageUrl();
    System.out.println("Expression test for " + evaluator.getLanguageName() + ": registering " + evaluator + " with URL " + languageUrl);
    scriptExpressionfactory.registerEvaluator(languageUrl, evaluator);
}
Also used : PrismContext(com.evolveum.midpoint.prism.PrismContext) ObjectResolver(com.evolveum.midpoint.schema.util.ObjectResolver) DirectoryFileObjectResolver(com.evolveum.midpoint.test.util.DirectoryFileObjectResolver) DirectoryFileObjectResolver(com.evolveum.midpoint.test.util.DirectoryFileObjectResolver) ArrayList(java.util.ArrayList) FunctionLibrary(com.evolveum.midpoint.model.common.expression.functions.FunctionLibrary) ProtectorImpl(com.evolveum.midpoint.prism.crypto.ProtectorImpl) Protector(com.evolveum.midpoint.prism.crypto.Protector) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

ProtectorImpl (com.evolveum.midpoint.prism.crypto.ProtectorImpl)8 Protector (com.evolveum.midpoint.prism.crypto.Protector)4 ObjectResolver (com.evolveum.midpoint.schema.util.ObjectResolver)3 DirectoryFileObjectResolver (com.evolveum.midpoint.test.util.DirectoryFileObjectResolver)3 FunctionLibrary (com.evolveum.midpoint.model.common.expression.functions.FunctionLibrary)2 PrismContext (com.evolveum.midpoint.prism.PrismContext)2 ArrayList (java.util.ArrayList)2 BeforeClass (org.testng.annotations.BeforeClass)2 BasicExpressionFunctions (com.evolveum.midpoint.model.common.expression.functions.BasicExpressionFunctions)1 Jsr223ScriptEvaluator (com.evolveum.midpoint.model.common.expression.script.jsr223.Jsr223ScriptEvaluator)1 EncryptionException (com.evolveum.midpoint.prism.crypto.EncryptionException)1 KeyStore (java.security.KeyStore)1 Entry (java.security.KeyStore.Entry)1 ProtectionParameter (java.security.KeyStore.ProtectionParameter)1 SecretKeyEntry (java.security.KeyStore.SecretKeyEntry)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Provider (java.security.Provider)1 UnrecoverableEntryException (java.security.UnrecoverableEntryException)1 SecretKey (javax.crypto.SecretKey)1