Example usage for java.security Provider getName

List of usage examples for java.security Provider getName

Introduction

In this page you can find the example usage for java.security Provider getName.

Prototype

public String getName() 

Source Link

Document

Returns the name of this provider.

Usage

From source file:org.cesecore.keys.token.p11.Pkcs11SlotLabel.java

/**
 * Get the IAIK provider./*from  w  ww .  j  av  a2  s  .co  m*/
 * @param slot Slot list index or slot ID.
 * @param libFile P11 module so file.
 * @param isIndex true if first parameter is a slot list index, false if slot ID.
 * @return the provider
 */
private static Provider getIAIKP11Provider(final long slot, final File libFile,
        final Pkcs11SlotLabelType type) {
    // Properties for the IAIK PKCS#11 provider
    final Properties prop = new Properties();
    try {
        prop.setProperty("PKCS11_NATIVE_MODULE", libFile.getCanonicalPath());
    } catch (IOException e) {
        throw new RuntimeException("Could for unknown reason not construct canonical filename.", e);
    }
    // If using Slot Index it is denoted by brackets in iaik
    prop.setProperty("SLOT_ID",
            type.equals(Pkcs11SlotLabelType.SLOT_INDEX) ? ("[" + slot + "]") : Long.toString(slot));
    if (log.isDebugEnabled()) {
        log.debug(prop.toString());
    }
    Provider ret = null;
    try {
        @SuppressWarnings("unchecked")
        final Class<? extends Provider> implClass = (Class<? extends Provider>) Class
                .forName(IAIK_PKCS11_CLASS);
        log.info("Using IAIK PKCS11 provider: " + IAIK_PKCS11_CLASS);
        // iaik PKCS11 has Properties as constructor argument
        ret = implClass.getConstructor(Properties.class).newInstance(new Object[] { prop });
        // It's not enough just to add the p11 provider. Depending on algorithms we may have to install the IAIK JCE provider as well in order
        // to support algorithm delegation
        @SuppressWarnings("unchecked")
        final Class<? extends Provider> jceImplClass = (Class<? extends Provider>) Class
                .forName(IAIK_JCEPROVIDER_CLASS);
        Provider iaikProvider = jceImplClass.getConstructor().newInstance();
        if (Security.getProvider(iaikProvider.getName()) == null) {
            log.info("Adding IAIK JCE provider for Delegation: " + IAIK_JCEPROVIDER_CLASS);
            Security.addProvider(iaikProvider);
        }
    } catch (InvocationTargetException e) {
        // NOPMD: Ignore, reflection related errors are handled elsewhere
    } catch (InstantiationException e) {
        // NOPMD: Ignore, reflection related errors are handled elsewhere
    } catch (IllegalAccessException e) {
        // NOPMD: Ignore, reflection related errors are handled elsewhere
    } catch (IllegalArgumentException e) {
        // NOPMD: Ignore, reflection related errors are handled elsewhere
    } catch (NoSuchMethodException e) {
        // NOPMD: Ignore, reflection related errors are handled elsewhere
    } catch (SecurityException e) {
        // NOPMD: Ignore, reflection related errors are handled elsewhere
    } catch (ClassNotFoundException e) {
        // NOPMD: Ignore, reflection related errors are handled elsewhere
    }
    return ret;
}

From source file:org.ejbca.core.model.ca.catoken.BaseCAToken.java

/** Sets both signature and encryption providers. If encryption provider is the same as signature provider this 
 * class name can be null./* w w w .ja  v  a  2 s . c o  m*/
 * @param jcaProviderClassName signature provider class name
 * @param jceProviderClassName encryption provider class name, can be null
 * @throws ClassNotFoundException 
 * @throws IllegalAccessException 
 * @throws InstantiationException
 * @see {@link #setJCAProvider(Provider)} 
 */
protected void setProviders(String jcaProviderClassName, String jceProviderClassName)
        throws InstantiationException, IllegalAccessException, ClassNotFoundException {
    Provider jcaProvider = (Provider) Class.forName(jcaProviderClassName).newInstance();
    setProvider(jcaProvider);
    this.mJcaProviderName = jcaProvider.getName();
    if (jceProviderClassName != null) {
        try {
            Provider jceProvider = (Provider) Class.forName(jceProviderClassName).newInstance();
            setProvider(jceProvider);
            this.mJceProviderName = jceProvider.getName();
        } catch (Exception e) {
            log.error(intres.getLocalizedMessage("catoken.jceinitfail"), e);
        }
    } else {
        this.mJceProviderName = null;
    }
}

From source file:org.ejbca.core.model.ca.catoken.BaseCAToken.java

private void setProvider(Provider prov) {
    if (prov != null) {
        String pName = prov.getName();
        if (pName.startsWith("LunaJCA")) {
            // Luna Java provider does not contain support for RSA/ECB/PKCS1Padding but this is 
            // the same as the alias below on small amounts of data  
            prov.put("Alg.Alias.Cipher.RSA/NONE/NoPadding", "RSA//NoPadding");
            prov.put("Alg.Alias.Cipher.1.2.840.113549.1.1.1", "RSA//NoPadding");
            prov.put("Alg.Alias.Cipher.RSA/ECB/PKCS1Padding", "RSA//PKCS1v1_5");
            prov.put("Alg.Alias.Cipher.1.2.840.113549.3.7", "DES3/CBC/PKCS5Padding");
        }/*  ww  w.  ja  va2  s  . co  m*/
        if (Security.getProvider(pName) == null) {
            Security.addProvider(prov);
        }
        if (Security.getProvider(pName) == null) {
            throw new ProviderException("Not possible to install provider: " + pName);
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("No provider passed to setProvider()");
        }
    }
}

From source file:org.ejbca.util.keystore.KeyTools.java

/**
 * /*from  w  w w .j ava2  s .c  o  m*/
 * @param is for the SUN PKCS#11 provider
 * @param prop for the IAIK PKCS#11 provider
 * @return Java security Provider for a PCKS#11 token
 * @throws IOException if neither the IAIK or the SUN provider can be created
 */
private static Provider getP11Provider(final InputStream is, final Properties prop) throws IOException {

    // We will construct the PKCS11 provider (sun.security..., or iaik...) using reflection, because 
    // the sun class does not exist on all platforms in jdk5, and we want to be able to compile everything.
    // The below code replaces the single line (for the SUN provider):
    //   return new SunPKCS11(new ByteArrayInputStream(baos.toByteArray()));

    // We will first try to construct the more competent IAIK provider, if it exists in the classpath
    // if that does not exist, we will revert back to use the SUN provider
    Provider ret = null;
    if (prop != null) {
        try {
            final Class implClass = Class.forName(IAIKPKCS11CLASS);
            log.info("Using IAIK PKCS11 provider: " + IAIKPKCS11CLASS);
            // iaik PKCS11 has Properties as constructor argument
            ret = (Provider) implClass.getConstructor(Properties.class).newInstance(new Object[] { prop });
            // It's not enough just to add the p11 provider. Depending on algorithms we may have to install the IAIK JCE provider as well in order to support algorithm delegation
            final Class jceImplClass = Class.forName(KeyTools.IAIKJCEPROVIDERCLASS);
            Provider iaikProvider = (Provider) jceImplClass.getConstructor().newInstance();
            if (Security.getProvider(iaikProvider.getName()) == null) {
                log.info("Adding IAIK JCE provider for Delegation: " + KeyTools.IAIKJCEPROVIDERCLASS);
                Security.addProvider(iaikProvider);
            }
        } catch (Exception e) {
            // do nothing here. Sun provider is tested below.
        }
    }
    if (ret == null) {
        try {
            // Sun PKCS11 has InputStream as constructor argument
            final Class implClass = Class.forName(SUNPKCS11CLASS);
            log.info("Using SUN PKCS11 provider: " + SUNPKCS11CLASS);
            ret = (Provider) implClass.getConstructor(InputStream.class).newInstance(new Object[] { is });
        } catch (Exception e) {
            log.error("Error constructing pkcs11 provider: " + e.getMessage());
            final IOException ioe = new IOException("Error constructing pkcs11 provider: " + e.getMessage());
            ioe.initCause(e);
            throw ioe;
        }
    }
    return ret;
}

From source file:org.jenkinsci.plugins.relution_publisher.configuration.jobs.ArtifactPublisher.java

private void logProviderInformation(final Log log) {
    log.write(this, "Available security providers:");

    final Provider[] providers = Security.getProviders();
    for (final Provider provider : providers) {
        log.write(this, "%s %s", provider.getName(), String.valueOf(provider.getVersion()));
    }/*from w  w w  .  j  a v  a 2  s.  co m*/
    log.write();
}

From source file:org.mule.providers.ldap.LdapSASLConnector.java

protected void doInitialise() throws InitialisationException {

    // if (isForceJDK14())
    // {/*from   w w w  . j ava2  s.  c om*/
    // logger.debug("forcing JDK 1.4 SASL mode");
    Security.addProvider(new com.novell.sasl.client.SaslProvider());
    // }
    /*
     * else { Provider sunSASL = Security.getProvider("SunSASL");
     * 
     * if (sunSASL != null) { logger .debug("SunSASL implementation (JDK >=
     * 1.5) detected. Use it."); try { Sasl.setSaslClientFactory(new
     * SaslBridgeClientFactory()); } catch (RuntimeException e) {
     * logger.warn(e.toString()); } } else { logger .debug("No SunSASL
     * implementation (JDK >= 1.5 detected. Fall back to JDK 1.4 mode");
     * Security.addProvider(new com.novell.sasl.client.SaslProvider()); } }
     */

    if (logger.isDebugEnabled()) {

        Provider[] ps = Security.getProviders();
        for (int i = 0; i < ps.length; i++) {
            Provider provider = ps[i];
            logger.debug(provider.getClass() + "/" + provider.getName() + "/" + provider.getVersion() + "/"
                    + provider.getInfo());

        }
    }

    if (MECHANISM_DIGEST_EXTERNAL.equals(mechanism)) {

        try {
            if (trustAll) {
                SSLContext context = SSLContext.getInstance("TLS");
                context.init(null, trustAll ? TrustAllCertsManager.getTrustAllCertsManager() : null, null);

                // certificate_unknown
                ssf = new LDAPJSSESecureSocketFactory(context.getSocketFactory());
            } else {
                if (StringUtils.isEmpty(trustStore)) {
                    throw new InitialisationException(new IllegalArgumentException(
                            "Either trustAll value must be true or the trustStore parameter must be set"),
                            this);
                }

                File trustStoreFile = new File(trustStore);

                if (!trustStoreFile.exists() || !trustStoreFile.canRead()) {
                    throw new InitialisationException(new IllegalArgumentException("truststore file "
                            + trustStoreFile.getAbsolutePath() + " do not exist or is not readable"), this);
                }

                System.setProperty("javax.net.ssl.trustStore", trustStore);

                logger.debug("truststore set to " + trustStoreFile.getAbsolutePath());

                ssf = new LDAPJSSESecureSocketFactory();
            }
            // pix path
            // ssf = new LDAPJSSESecureSocketFactory((SSLSocketFactory)
            // SSLSocketFactory.getDefault());

            // TODO SSL<->TLS (TLS maybe require startTLS() call on lc
            // ssf = new LDAPJSSEStartTLSFactory();
        } catch (KeyManagementException e) {
            throw new InitialisationException(e, this);
        } catch (NoSuchAlgorithmException e) {
            throw new InitialisationException(e, this);
        }

    }

    super.doInitialise();
}

From source file:org.wildfly.security.credential.store.KeystorePasswordStoreTest.java

/**
 * Remove security provider./*from ww w  .j a v a 2s.c o  m*/
 */
@AfterClass
public static void remove() {
    for (Provider provider : providers) {
        Security.removeProvider(provider.getName());
    }
}

From source file:org.wildfly.security.tool.Command.java

protected Supplier<Provider[]> getProvidersSupplier(final String providersList) {
    return () -> {
        if (providersList != null && !providersList.isEmpty()) {
            final String[] providerNames = providersList.split(",");
            List<Provider> providers = new ArrayList<>(providerNames.length);
            for (String p : providerNames) {
                Provider provider = Security.getProvider(p.trim());
                if (provider != null) {
                    providers.add(provider);
                }//from   w ww  .  j  a va2  s  .c om
            }
            ServiceLoader<Provider> providerLoader = ServiceLoader.load(Provider.class);
            for (Provider provider : providerLoader) {
                for (String p : providerNames) {
                    if (provider.getName().equals(p)) {
                        providers.add(provider);
                        break;
                    }
                }
            }
            if (providers.isEmpty()) {
                throw ElytronToolMessages.msg.unknownProvider(providersList);
            }
            return providers.toArray(new Provider[providers.size()]);
        } else {
            // when no provider list is specified, load all Providers from service loader except WildFlyElytron Provider
            ServiceLoader<Provider> providerLoader = ServiceLoader.load(Provider.class);
            Iterator<Provider> providerIterator = providerLoader.iterator();
            List<Provider> providers = new ArrayList<>();
            while (providerIterator.hasNext()) {
                Provider provider = providerIterator.next();
                if (provider.getName().equals("WildFlyElytron"))
                    continue;
                providers.add(provider);
            }
            return providers.toArray(new Provider[providers.size()]);
        }
    };
}

From source file:org.xdi.oxauth.model.util.JwtUtil.java

public static void printAlgorithmsAndProviders() {
    Set<String> algorithms = Security.getAlgorithms("Signature");
    for (String algorithm : algorithms) {
        log.trace("Algorithm (Signature): " + algorithm);
    }/*from ww  w .ja  va  2  s.com*/
    algorithms = Security.getAlgorithms("MessageDigest");
    for (String algorithm : algorithms) {
        log.trace("Algorithm (MessageDigest): " + algorithm);
    }
    algorithms = Security.getAlgorithms("Cipher");
    for (String algorithm : algorithms) {
        log.trace("Algorithm (Cipher): " + algorithm);
    }
    algorithms = Security.getAlgorithms("Mac");
    for (String algorithm : algorithms) {
        log.trace("Algorithm (Mac): " + algorithm);
    }
    algorithms = Security.getAlgorithms("KeyStore");
    for (String algorithm : algorithms) {
        log.trace("Algorithm (KeyStore): " + algorithm);
    }
    Provider[] providers = Security.getProviders();
    for (Provider provider : providers) {
        log.trace("Provider: " + provider.getName());
    }
}

From source file:test.be.fedict.eid.applet.RSATest.java

@Test
public void testListSecurityProviders() throws Exception {
    Provider[] providers = Security.getProviders();
    for (Provider provider : providers) {
        LOG.debug("provider name: " + provider.getName());
        LOG.debug("provider info: " + provider.getInfo());
        Set<Service> services = provider.getServices();
        for (Service service : services) {
            LOG.debug("\tservice type: " + service.getType());
            LOG.debug("\tservice algo: " + service.getAlgorithm());
        }//from   w w w .  j  a v  a2 s  .co  m
    }
}