Search in sources :

Example 1 with LoadStoreParameter

use of java.security.KeyStore.LoadStoreParameter in project coprhd-controller by CoprHD.

the class KeystoreTest method setup.

@Before
public void setup() throws URISyntaxException, IOException {
    ApplicationContextUtil.initContext(System.getProperty("buildType"), ApplicationContextUtil.SECURITY_CONTEXTS);
    List<URI> uri = new ArrayList<URI>();
    uri.add(URI.create(coordinatorServer));
    ZkConnection connection = new ZkConnection();
    connection.setServer(uri);
    connection.build();
    coordinatorClient.setZkConnection(connection);
    CoordinatorClientInetAddressMap map = new CoordinatorClientInetAddressMap();
    map.setNodeId("standalone");
    DualInetAddress localAddress = DualInetAddress.fromAddresses("127.0.0.1", "::1");
    map.setDualInetAddress(localAddress);
    Map<String, DualInetAddress> controllerNodeIPLookupMap = new HashMap<String, DualInetAddress>();
    controllerNodeIPLookupMap.put("localhost", localAddress);
    map.setControllerNodeIPLookupMap(controllerNodeIPLookupMap);
    coordinatorClient.setInetAddessLookupMap(map);
    coordinatorClient.start();
    FileInputStream is = new FileInputStream(defaultOvfPropsLocation);
    Properties defaultProp = new Properties();
    defaultProp.load(is);
    is.close();
    is = new FileInputStream(ovfPropsLocation);
    Properties ovfProps = new Properties();
    ovfProps.load(is);
    is.close();
    CoordinatorClientImpl.setDefaultProperties(defaultProp);
    CoordinatorClientImpl.setOvfProperties(ovfProps);
    loadStoreParam = new DistributedLoadKeyStoreParam();
    loadStoreParam.setCoordinator(coordinatorClient);
    invalidLoadStoreParam = new LoadStoreParameter() {

        @Override
        public ProtectionParameter getProtectionParameter() {
            return null;
        }
    };
    gen = new KeyCertificatePairGenerator();
    KeyCertificateAlgorithmValuesHolder values = new KeyCertificateAlgorithmValuesHolder(coordinatorClient);
    gen.setKeyCertificateAlgorithmValuesHolder(values);
}
Also used : HashMap(java.util.HashMap) DistributedLoadKeyStoreParam(com.emc.storageos.security.keystore.impl.DistributedLoadKeyStoreParam) ArrayList(java.util.ArrayList) Properties(java.util.Properties) URI(java.net.URI) ZkConnection(com.emc.storageos.coordinator.common.impl.ZkConnection) FileInputStream(java.io.FileInputStream) LoadStoreParameter(java.security.KeyStore.LoadStoreParameter) KeyCertificateAlgorithmValuesHolder(com.emc.storageos.security.keystore.impl.KeyCertificateAlgorithmValuesHolder) KeyCertificatePairGenerator(com.emc.storageos.security.keystore.impl.KeyCertificatePairGenerator) CoordinatorClientInetAddressMap(com.emc.storageos.coordinator.client.service.impl.CoordinatorClientInetAddressMap) DualInetAddress(com.emc.storageos.coordinator.client.service.impl.DualInetAddress) ProtectionParameter(java.security.KeyStore.ProtectionParameter) Before(org.junit.Before)

Example 2 with LoadStoreParameter

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

the class TestJseProvider method testProviderWithCustomConnection.

static void testProviderWithCustomConnection() throws Exception {
    final Provider p = new DnieProvider(new SmartcardIoConnection());
    Security.addProvider(p);
    // $NON-NLS-1$
    final KeyStore ks = KeyStore.getInstance("DNI");
    final CallbackHandler callbackHandler;
    // $NON-NLS-1$
    callbackHandler = (CallbackHandler) Class.forName("es.gob.jmulticard.ui.passwordcallback.gui.DnieCallbackHandler").getConstructor().newInstance();
    final LoadStoreParameter lsp = new LoadStoreParameter() {

        @Override
        public ProtectionParameter getProtectionParameter() {
            return new KeyStore.CallbackHandlerProtection(callbackHandler);
        }
    };
    ks.load(lsp);
    final Enumeration<String> aliases = ks.aliases();
    while (aliases.hasMoreElements()) {
        System.out.println(aliases.nextElement());
    }
    // $NON-NLS-1$
    final Signature signature = Signature.getInstance("SHA1withRSA");
    // $NON-NLS-1$
    signature.initSign((PrivateKey) ks.getKey("CertFirmaDigital", PASSWORD));
    // $NON-NLS-1$
    signature.update("Hola Mundo!!".getBytes());
    signature.sign();
    // $NON-NLS-1$
    System.out.println("Firma generada correctamente");
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) DnieProvider(es.gob.jmulticard.jse.provider.DnieProvider) Signature(java.security.Signature) SmartcardIoConnection(es.gob.jmulticard.jse.smartcardio.SmartcardIoConnection) KeyStore(java.security.KeyStore) Provider(java.security.Provider) DnieProvider(es.gob.jmulticard.jse.provider.DnieProvider) LoadStoreParameter(java.security.KeyStore.LoadStoreParameter)

Example 3 with LoadStoreParameter

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

the class KeyStoreTest method test_KeyStore_load_LoadStoreParameter.

public void test_KeyStore_load_LoadStoreParameter() throws Exception {
    for (KeyStore keyStore : keyStores()) {
        keyStore.load(null);
        if (isPersistentStorage(keyStore)) {
            assertTrue("Should be able to query size: " + keyStore.getType(), keyStore.size() >= 0);
        } else if (hasDefaultContents(keyStore)) {
            assertTrue("Should have non-empty store: " + keyStore.getType(), keyStore.size() > 0);
        } else {
            assertEquals("Should have empty store: " + keyStore.getType(), 0, keyStore.size());
        }
    }
    for (KeyStore keyStore : keyStores()) {
        try {
            keyStore.load(new LoadStoreParameter() {

                public ProtectionParameter getProtectionParameter() {
                    return null;
                }
            });
            fail(keyStore.getType());
        } catch (UnsupportedOperationException expected) {
        }
    }
}
Also used : KeyStore(java.security.KeyStore) LoadStoreParameter(java.security.KeyStore.LoadStoreParameter) ProtectionParameter(java.security.KeyStore.ProtectionParameter)

Aggregations

LoadStoreParameter (java.security.KeyStore.LoadStoreParameter)3 KeyStore (java.security.KeyStore)2 ProtectionParameter (java.security.KeyStore.ProtectionParameter)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 DnieProvider (es.gob.jmulticard.jse.provider.DnieProvider)1 SmartcardIoConnection (es.gob.jmulticard.jse.smartcardio.SmartcardIoConnection)1 FileInputStream (java.io.FileInputStream)1 URI (java.net.URI)1 Provider (java.security.Provider)1 Signature (java.security.Signature)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 CallbackHandler (javax.security.auth.callback.CallbackHandler)1 Before (org.junit.Before)1