Search in sources :

Example 56 with Provider

use of java.security.Provider in project jdk8u_jdk by JetBrains.

the class TestEC method main0.

public static void main0(String[] args) throws Exception {
    Provider p = Security.getProvider("SunEC");
    if (p == null) {
        throw new NoSuchProviderException("Can't get SunEC provider");
    }
    System.out.println("Running tests with " + p.getName() + " provider...\n");
    long start = System.currentTimeMillis();
    /*
         * The entry point used for each test is its instance method
         * called main (not its static method called main).
         */
    new TestECDH().main(p);
    new TestECDSA().main(p);
    new TestCurves().main(p);
    new TestKeyFactory().main(p);
    new TestECGenSpec().main(p);
    new ReadPKCS12().main(p);
    new ReadCertificates().main(p);
    // ClientJSSEServerJSSE fails on Solaris 11 when both SunEC and
    // SunPKCS11-Solaris providers are enabled.
    // Workaround:
    // Security.removeProvider("SunPKCS11-Solaris");
    new ClientJSSEServerJSSE().main(p);
    long stop = System.currentTimeMillis();
    System.out.println("\nCompleted tests with " + p.getName() + " provider (" + ((stop - start) / 1000.0) + " seconds).");
}
Also used : NoSuchProviderException(java.security.NoSuchProviderException) Provider(java.security.Provider)

Example 57 with Provider

use of java.security.Provider in project android_frameworks_base by AOSPA.

the class ZygoteInit method warmUpJcaProviders.

/**
     * Register AndroidKeyStoreProvider and warm up the providers that are already registered.
     *
     * By doing it here we avoid that each app does it when requesting a service from the
     * provider for the first time.
     */
private static void warmUpJcaProviders() {
    long startTime = SystemClock.uptimeMillis();
    Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "Starting installation of AndroidKeyStoreProvider");
    // AndroidKeyStoreProvider.install() manipulates the list of JCA providers to insert
    // preferred providers. Note this is not done via security.properties as the JCA providers
    // are not on the classpath in the case of, for example, raw dalvikvm runtimes.
    AndroidKeyStoreProvider.install();
    Log.i(TAG, "Installed AndroidKeyStoreProvider in " + (SystemClock.uptimeMillis() - startTime) + "ms.");
    Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
    startTime = SystemClock.uptimeMillis();
    Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "Starting warm up of JCA providers");
    for (Provider p : Security.getProviders()) {
        p.warmUpServiceProvision();
    }
    Log.i(TAG, "Warmed up JCA providers in " + (SystemClock.uptimeMillis() - startTime) + "ms.");
    Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
}
Also used : AndroidKeyStoreProvider(android.security.keystore.AndroidKeyStoreProvider) Provider(java.security.Provider)

Example 58 with Provider

use of java.security.Provider in project android_frameworks_base by AOSPA.

the class AndroidKeyStoreProvider method install.

/**
     * Installs a new instance of this provider (and the
     * {@link AndroidKeyStoreBCWorkaroundProvider}).
     */
public static void install() {
    Provider[] providers = Security.getProviders();
    int bcProviderIndex = -1;
    for (int i = 0; i < providers.length; i++) {
        Provider provider = providers[i];
        if ("BC".equals(provider.getName())) {
            bcProviderIndex = i;
            break;
        }
    }
    Security.addProvider(new AndroidKeyStoreProvider());
    Provider workaroundProvider = new AndroidKeyStoreBCWorkaroundProvider();
    if (bcProviderIndex != -1) {
        // Bouncy Castle provider found -- install the workaround provider above it.
        // insertProviderAt uses 1-based positions.
        Security.insertProviderAt(workaroundProvider, bcProviderIndex + 1);
    } else {
        // Bouncy Castle provider not found -- install the workaround provider at lowest
        // priority.
        Security.addProvider(workaroundProvider);
    }
}
Also used : Provider(java.security.Provider)

Example 59 with Provider

use of java.security.Provider in project poi by apache.

the class RelationshipTransformService method registerDsigProvider.

/**
     * Register the provider for this TransformService
     * 
     * @see javax.xml.crypto.dsig.TransformService
     */
public static synchronized void registerDsigProvider() {
    // the xml signature classes will try to find a special TransformerService,
    // which is ofcourse unknown to JCE before ...
    final String dsigProvider = "POIXmlDsigProvider";
    if (Security.getProperty(dsigProvider) == null) {
        Provider p = new Provider(dsigProvider, 1.0, dsigProvider) {

            static final long serialVersionUID = 1L;
        };
        p.put("TransformService." + TRANSFORM_URI, RelationshipTransformService.class.getName());
        p.put("TransformService." + TRANSFORM_URI + " MechanismType", "DOM");
        Security.addProvider(p);
    }
}
Also used : Provider(java.security.Provider)

Example 60 with Provider

use of java.security.Provider in project poi by apache.

the class SignatureFacet method brokenJvmWorkaround.

// helper method ... will be removed soon
public static void brokenJvmWorkaround(final Reference reference) {
    final DigestMethod digestMethod = reference.getDigestMethod();
    final String digestMethodUri = digestMethod.getAlgorithm();
    final Provider bcProv = Security.getProvider("BC");
    if (bcProv != null && !DigestMethod.SHA1.equals(digestMethodUri)) {
        // workaround for https://bugzilla.redhat.com/show_bug.cgi?id=1155012
        // overwrite standard message digest, if a digest <> SHA1 is used
        AccessController.doPrivileged(new PrivilegedAction<Void>() {

            @Override
            @SuppressForbidden("Workaround for a bug, needs access to private JDK members (may fail in Java 9): https://bugzilla.redhat.com/show_bug.cgi?id=1155012")
            public Void run() {
                try {
                    Method m = DOMDigestMethod.class.getDeclaredMethod("getMessageDigestAlgorithm");
                    m.setAccessible(true);
                    String mdAlgo = (String) m.invoke(digestMethod);
                    MessageDigest md = MessageDigest.getInstance(mdAlgo, bcProv);
                    Field f = DOMReference.class.getDeclaredField("md");
                    f.setAccessible(true);
                    f.set(reference, md);
                } catch (Exception e) {
                    LOG.log(POILogger.WARN, "Can't overwrite message digest (workaround for https://bugzilla.redhat.com/show_bug.cgi?id=1155012)", e);
                }
                // Void
                return null;
            }
        });
    }
}
Also used : DOMDigestMethod(org.apache.jcp.xml.dsig.internal.dom.DOMDigestMethod) DigestMethod(javax.xml.crypto.dsig.DigestMethod) DOMDigestMethod(org.apache.jcp.xml.dsig.internal.dom.DOMDigestMethod) Method(java.lang.reflect.Method) DigestMethod(javax.xml.crypto.dsig.DigestMethod) DOMReference(org.apache.jcp.xml.dsig.internal.dom.DOMReference) MarshalException(javax.xml.crypto.MarshalException) GeneralSecurityException(java.security.GeneralSecurityException) XMLSignatureException(javax.xml.crypto.dsig.XMLSignatureException) Provider(java.security.Provider) Field(java.lang.reflect.Field) DOMDigestMethod(org.apache.jcp.xml.dsig.internal.dom.DOMDigestMethod) SuppressForbidden(org.apache.poi.util.SuppressForbidden) MessageDigest(java.security.MessageDigest)

Aggregations

Provider (java.security.Provider)243 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)49 ArrayList (java.util.ArrayList)26 MessageDigest (java.security.MessageDigest)21 List (java.util.List)20 Key (java.security.Key)19 KeyStore (java.security.KeyStore)19 Service (java.security.Provider.Service)15 ExemptionMechanism (javax.crypto.ExemptionMechanism)14 SpiEngUtils (org.apache.harmony.security.tests.support.SpiEngUtils)14 InvalidKeyException (java.security.InvalidKeyException)13 SecureRandom (java.security.SecureRandom)13 IOException (java.io.IOException)12 NoSuchProviderException (java.security.NoSuchProviderException)12 SecretKey (javax.crypto.SecretKey)12 KeyStoreException (java.security.KeyStoreException)11 CertificateException (java.security.cert.CertificateException)11 Cipher (javax.crypto.Cipher)11 KeyGenerator (javax.crypto.KeyGenerator)11 MyExemptionMechanismSpi.tmpKey (org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi.tmpKey)11