Search in sources :

Example 1 with ProtectionParameter

use of java.security.KeyStore.ProtectionParameter in project robovm by robovm.

the class KeyStore4Test method testLoadLoadStoreParameter.

public void testLoadLoadStoreParameter() {
    try {
        keyStore.load(null);
        fail("expected NoSuchAlgorithmException");
    } catch (NoSuchAlgorithmException e) {
    // ok
    } catch (CertificateException e) {
        fail("unexpected exception: " + e);
    } catch (IOException e) {
        fail("unexpected exception: " + e);
    }
    try {
        keyStore.load(new KeyStore.LoadStoreParameter() {

            public ProtectionParameter getProtectionParameter() {
                return new KeyStore.PasswordProtection("PASSWORD".toCharArray());
            }
        });
    } catch (NoSuchAlgorithmException e) {
        fail("unexpected exception: " + e);
    } catch (CertificateException e) {
        fail("unexpected exception: " + e);
    } catch (IOException e) {
        fail("unexpected exception: " + e);
    }
    try {
        keyStore.load(new KeyStore.LoadStoreParameter() {

            public ProtectionParameter getProtectionParameter() {
                return null;
            }
        });
        fail("expected NoSuchAlgorithmException");
    } catch (NoSuchAlgorithmException e) {
    // ok
    } catch (CertificateException e) {
        fail("unexpected exception: " + e);
    } catch (IOException e) {
        fail("unexpected exception: " + e);
    }
    try {
        keyStore.load(new KeyStore.LoadStoreParameter() {

            public ProtectionParameter getProtectionParameter() {
                return new KeyStore.ProtectionParameter() {
                };
            }
        });
        fail("expected CertificateException");
    } catch (NoSuchAlgorithmException e) {
        fail("unexpected exception: " + e);
    } catch (CertificateException e) {
    // ok
    } catch (IOException e) {
        fail("unexpected exception: " + e);
    }
}
Also used : CertificateException(java.security.cert.CertificateException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) KeyStore(java.security.KeyStore) ProtectionParameter(java.security.KeyStore.ProtectionParameter) ProtectionParameter(java.security.KeyStore.ProtectionParameter)

Example 2 with ProtectionParameter

use of java.security.KeyStore.ProtectionParameter in project robovm by robovm.

the class PKCS12KeyStoreSpi method engineStore.

public void engineStore(LoadStoreParameter param) throws IOException, NoSuchAlgorithmException, CertificateException {
    if (param == null) {
        throw new IllegalArgumentException("'param' arg cannot be null");
    }
    if (!(param instanceof PKCS12StoreParameter || param instanceof JDKPKCS12StoreParameter)) {
        throw new IllegalArgumentException("No support for 'param' of type " + param.getClass().getName());
    }
    PKCS12StoreParameter bcParam;
    if (param instanceof PKCS12StoreParameter) {
        bcParam = (PKCS12StoreParameter) param;
    } else {
        bcParam = new PKCS12StoreParameter(((JDKPKCS12StoreParameter) param).getOutputStream(), param.getProtectionParameter(), ((JDKPKCS12StoreParameter) param).isUseDEREncoding());
    }
    char[] password;
    ProtectionParameter protParam = param.getProtectionParameter();
    if (protParam == null) {
        password = null;
    } else if (protParam instanceof KeyStore.PasswordProtection) {
        password = ((KeyStore.PasswordProtection) protParam).getPassword();
    } else {
        throw new IllegalArgumentException("No support for protection parameter of type " + protParam.getClass().getName());
    }
    doStore(bcParam.getOutputStream(), password, bcParam.isForDEREncoding());
}
Also used : PKCS12StoreParameter(org.bouncycastle.jcajce.provider.config.PKCS12StoreParameter) JDKPKCS12StoreParameter(org.bouncycastle.jce.provider.JDKPKCS12StoreParameter) JDKPKCS12StoreParameter(org.bouncycastle.jce.provider.JDKPKCS12StoreParameter) KeyStore(java.security.KeyStore) BCKeyStore(org.bouncycastle.jce.interfaces.BCKeyStore) ProtectionParameter(java.security.KeyStore.ProtectionParameter)

Example 3 with ProtectionParameter

use of java.security.KeyStore.ProtectionParameter 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 ProtectionParameter

use of java.security.KeyStore.ProtectionParameter in project jmulticard by ctt-gob-es.

the class SmartCafeKeyStoreImpl method engineLoad.

/**
 * {@inheritDoc}
 */
@Override
public void engineLoad(final KeyStore.LoadStoreParameter param) throws IOException {
    final ApduConnection conn = new es.gob.jmulticard.jse.smartcardio.SmartcardIoConnection();
    this.cryptoCard = new SmartCafePkcs15Applet(conn, new JseCryptoHelper());
    if (param != null) {
        final ProtectionParameter pp = param.getProtectionParameter();
        if (pp instanceof KeyStore.CallbackHandlerProtection) {
            if (((KeyStore.CallbackHandlerProtection) pp).getCallbackHandler() == null) {
                // $NON-NLS-1$
                throw new IllegalArgumentException("El CallbackHandler no puede ser nulo");
            }
            this.cryptoCard.setCallbackHandler(((KeyStore.CallbackHandlerProtection) pp).getCallbackHandler());
        } else if (pp instanceof KeyStore.PasswordProtection) {
            final PasswordCallback pwc = new CachePasswordCallback(((PasswordProtection) pp).getPassword());
            this.cryptoCard.setPasswordCallback(pwc);
        } else {
            LOGGER.warning(// $NON-NLS-1$ //$NON-NLS-2$
            "Se ha proporcionado un LoadStoreParameter de tipo no soportado, se ignorara: " + (pp != null ? pp.getClass().getName() : "NULO"));
        }
    }
    this.aliases = Arrays.asList(this.cryptoCard.getAliases());
}
Also used : SmartCafePkcs15Applet(es.gob.jmulticard.card.gide.smartcafe.SmartCafePkcs15Applet) PasswordProtection(java.security.KeyStore.PasswordProtection) KeyStore(java.security.KeyStore) PasswordCallback(javax.security.auth.callback.PasswordCallback) JseCryptoHelper(es.gob.jmulticard.JseCryptoHelper) ApduConnection(es.gob.jmulticard.apdu.connection.ApduConnection) PasswordProtection(java.security.KeyStore.PasswordProtection) ProtectionParameter(java.security.KeyStore.ProtectionParameter)

Example 5 with ProtectionParameter

use of java.security.KeyStore.ProtectionParameter in project jmulticard by ctt-gob-es.

the class CeresKeyStoreImpl method engineLoad.

/**
 * {@inheritDoc}
 */
@Override
public void engineLoad(final KeyStore.LoadStoreParameter param) throws IOException {
    if (param != null) {
        final ProtectionParameter pp = param.getProtectionParameter();
        if (pp instanceof KeyStore.CallbackHandlerProtection) {
            if (((KeyStore.CallbackHandlerProtection) pp).getCallbackHandler() == null) {
                // $NON-NLS-1$
                throw new IllegalArgumentException("El CallbackHandler no puede ser nulo");
            }
            this.cryptoCard = new Ceres(CeresProvider.getDefaultApduConnection(), new JseCryptoHelper());
            this.cryptoCard.setCallbackHandler(((KeyStore.CallbackHandlerProtection) pp).getCallbackHandler());
        } else if (pp instanceof KeyStore.PasswordProtection) {
            final PasswordCallback pwc = new CeresPasswordCallback((PasswordProtection) pp);
            this.cryptoCard = new Ceres(CeresProvider.getDefaultApduConnection(), new JseCryptoHelper());
            this.cryptoCard.setPasswordCallback(pwc);
        } else {
            // $NON-NLS-1$
            Logger.getLogger("es.gob.jmulticard").warning(// $NON-NLS-1$ //$NON-NLS-2$
            "Se ha proporcionado un LoadStoreParameter de tipo no soportado, se ignorara: " + (pp != null ? pp.getClass().getName() : "NULO"));
        }
    } else {
        this.cryptoCard = new Ceres(CeresProvider.getDefaultApduConnection(), new JseCryptoHelper());
    }
    userCertAliases = Arrays.asList(this.cryptoCard.getAliases());
}
Also used : Ceres(es.gob.jmulticard.card.fnmt.ceres.Ceres) PasswordProtection(java.security.KeyStore.PasswordProtection) PasswordCallback(javax.security.auth.callback.PasswordCallback) JseCryptoHelper(es.gob.jmulticard.JseCryptoHelper) KeyStore(java.security.KeyStore) PasswordProtection(java.security.KeyStore.PasswordProtection) ProtectionParameter(java.security.KeyStore.ProtectionParameter)

Aggregations

ProtectionParameter (java.security.KeyStore.ProtectionParameter)10 KeyStore (java.security.KeyStore)9 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 JseCryptoHelper (es.gob.jmulticard.JseCryptoHelper)2 IOException (java.io.IOException)2 Entry (java.security.KeyStore.Entry)2 LoadStoreParameter (java.security.KeyStore.LoadStoreParameter)2 PasswordProtection (java.security.KeyStore.PasswordProtection)2 CertificateException (java.security.cert.CertificateException)2 PasswordCallback (javax.security.auth.callback.PasswordCallback)2 BCKeyStore (org.bouncycastle.jce.interfaces.BCKeyStore)2 CoordinatorClientInetAddressMap (com.emc.storageos.coordinator.client.service.impl.CoordinatorClientInetAddressMap)1 DualInetAddress (com.emc.storageos.coordinator.client.service.impl.DualInetAddress)1 ZkConnection (com.emc.storageos.coordinator.common.impl.ZkConnection)1 DistributedLoadKeyStoreParam (com.emc.storageos.security.keystore.impl.DistributedLoadKeyStoreParam)1 KeyCertificateAlgorithmValuesHolder (com.emc.storageos.security.keystore.impl.KeyCertificateAlgorithmValuesHolder)1 KeyCertificatePairGenerator (com.emc.storageos.security.keystore.impl.KeyCertificatePairGenerator)1 EncryptionException (com.evolveum.midpoint.prism.crypto.EncryptionException)1 Protector (com.evolveum.midpoint.prism.crypto.Protector)1 ProtectorImpl (com.evolveum.midpoint.prism.crypto.ProtectorImpl)1