Search in sources :

Example 56 with Service

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

the class Mac method chooseFirstProvider.

/**
     * Choose the Spi from the first provider available. Used if
     * delayed provider selection is not possible because init()
     * is not the first method called.
     */
void chooseFirstProvider() {
    if ((spi != null) || (serviceIterator == null)) {
        return;
    }
    synchronized (lock) {
        if (spi != null) {
            return;
        }
        if (debug != null) {
            int w = --warnCount;
            if (w >= 0) {
                debug.println("Mac.init() not first method " + "called, disabling delayed provider selection");
                if (w == 0) {
                    debug.println("Further warnings of this type will " + "be suppressed");
                }
                new Exception("Call trace").printStackTrace();
            }
        }
        Exception lastException = null;
        while ((firstService != null) || serviceIterator.hasNext()) {
            Service s;
            if (firstService != null) {
                s = firstService;
                firstService = null;
            } else {
                s = serviceIterator.next();
            }
            if (JceSecurity.canUseProvider(s.getProvider()) == false) {
                continue;
            }
            try {
                Object obj = s.newInstance(null);
                if (obj instanceof MacSpi == false) {
                    continue;
                }
                spi = (MacSpi) obj;
                provider = s.getProvider();
                // not needed any more
                firstService = null;
                serviceIterator = null;
                return;
            } catch (NoSuchAlgorithmException e) {
                lastException = e;
            }
        }
        ProviderException e = new ProviderException("Could not construct MacSpi instance");
        if (lastException != null) {
            e.initCause(lastException);
        }
        throw e;
    }
}
Also used : Service(java.security.Provider.Service)

Example 57 with Service

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

the class JceSecurity method getInstance.

static Instance getInstance(String type, Class<?> clazz, String algorithm, Provider provider) throws NoSuchAlgorithmException {
    Service s = GetInstance.getService(type, algorithm, provider);
    Exception ve = JceSecurity.getVerificationResult(provider);
    if (ve != null) {
        String msg = "JCE cannot authenticate the provider " + provider.getName();
        throw new SecurityException(msg, ve);
    }
    return GetInstance.getInstance(s, clazz);
}
Also used : Service(java.security.Provider.Service)

Example 58 with Service

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

the class KeyAgreement method getInstance.

/**
     * Returns a <code>KeyAgreement</code> object that implements the
     * specified key agreement algorithm.
     *
     * <p> This method traverses the list of registered security Providers,
     * starting with the most preferred Provider.
     * A new KeyAgreement object encapsulating the
     * KeyAgreementSpi implementation from the first
     * Provider that supports the specified algorithm is returned.
     *
     * <p> Note that the list of registered providers may be retrieved via
     * the {@link Security#getProviders() Security.getProviders()} method.
     *
     * @param algorithm the standard name of the requested key agreement
     * algorithm.
     * See the KeyAgreement section in the <a href=
     * "{@docRoot}/../technotes/guides/security/StandardNames.html#KeyAgreement">
     * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
     * for information about standard algorithm names.
     *
     * @return the new <code>KeyAgreement</code> object.
     *
     * @exception NullPointerException if the specified algorithm
     *          is null.
     *
     * @exception NoSuchAlgorithmException if no Provider supports a
     *          KeyAgreementSpi implementation for the
     *          specified algorithm.
     *
     * @see java.security.Provider
     */
public static final KeyAgreement getInstance(String algorithm) throws NoSuchAlgorithmException {
    List<Service> services = GetInstance.getServices("KeyAgreement", algorithm);
    // make sure there is at least one service from a signed provider
    Iterator<Service> t = services.iterator();
    while (t.hasNext()) {
        Service s = t.next();
        if (JceSecurity.canUseProvider(s.getProvider()) == false) {
            continue;
        }
        return new KeyAgreement(s, t, algorithm);
    }
    throw new NoSuchAlgorithmException("Algorithm " + algorithm + " not available");
}
Also used : Service(java.security.Provider.Service)

Example 59 with Service

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

the class KeyAgreement method chooseFirstProvider.

/**
     * Choose the Spi from the first provider available. Used if
     * delayed provider selection is not possible because init()
     * is not the first method called.
     */
void chooseFirstProvider() {
    if (spi != null) {
        return;
    }
    synchronized (lock) {
        if (spi != null) {
            return;
        }
        if (debug != null) {
            int w = --warnCount;
            if (w >= 0) {
                debug.println("KeyAgreement.init() not first method " + "called, disabling delayed provider selection");
                if (w == 0) {
                    debug.println("Further warnings of this type will " + "be suppressed");
                }
                new Exception("Call trace").printStackTrace();
            }
        }
        Exception lastException = null;
        while ((firstService != null) || serviceIterator.hasNext()) {
            Service s;
            if (firstService != null) {
                s = firstService;
                firstService = null;
            } else {
                s = serviceIterator.next();
            }
            if (JceSecurity.canUseProvider(s.getProvider()) == false) {
                continue;
            }
            try {
                Object obj = s.newInstance(null);
                if (obj instanceof KeyAgreementSpi == false) {
                    continue;
                }
                spi = (KeyAgreementSpi) obj;
                provider = s.getProvider();
                // not needed any more
                firstService = null;
                serviceIterator = null;
                return;
            } catch (Exception e) {
                lastException = e;
            }
        }
        ProviderException e = new ProviderException("Could not construct KeyAgreementSpi instance");
        if (lastException != null) {
            e.initCause(lastException);
        }
        throw e;
    }
}
Also used : Service(java.security.Provider.Service)

Example 60 with Service

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

the class KeyGenerator method nextSpi.

/**
     * Update the active spi of this class and return the next
     * implementation for failover. If no more implemenations are
     * available, this method returns null. However, the active spi of
     * this class is never set to null.
     */
private KeyGeneratorSpi nextSpi(KeyGeneratorSpi oldSpi, boolean reinit) {
    synchronized (lock) {
        // try that spi now
        if ((oldSpi != null) && (oldSpi != spi)) {
            return spi;
        }
        if (serviceIterator == null) {
            return null;
        }
        while (serviceIterator.hasNext()) {
            Service s = serviceIterator.next();
            if (JceSecurity.canUseProvider(s.getProvider()) == false) {
                continue;
            }
            try {
                Object inst = s.newInstance(null);
                // ignore non-spis
                if (inst instanceof KeyGeneratorSpi == false) {
                    continue;
                }
                KeyGeneratorSpi spi = (KeyGeneratorSpi) inst;
                if (reinit) {
                    if (initType == I_SIZE) {
                        spi.engineInit(initKeySize, initRandom);
                    } else if (initType == I_PARAMS) {
                        spi.engineInit(initParams, initRandom);
                    } else if (initType == I_RANDOM) {
                        spi.engineInit(initRandom);
                    } else if (initType != I_NONE) {
                        throw new AssertionError("KeyGenerator initType: " + initType);
                    }
                }
                provider = s.getProvider();
                this.spi = spi;
                return spi;
            } catch (Exception e) {
            // ignore
            }
        }
        disableFailover();
        return null;
    }
}
Also used : Service(java.security.Provider.Service)

Aggregations

Service (java.security.Provider.Service)80 Provider (java.security.Provider)17 Instance (sun.security.jca.GetInstance.Instance)11 ReadOnlyBufferException (java.nio.ReadOnlyBufferException)9 InvalidParameterSpecException (java.security.spec.InvalidParameterSpecException)9 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 DefaultSet (de.carne.jfx.util.DefaultSet)3 Nullable (de.carne.check.Nullable)2 KeyPairGenerator (java.security.KeyPairGenerator)2 DSAPrivateKey (java.security.interfaces.DSAPrivateKey)2 DSAPublicKey (java.security.interfaces.DSAPublicKey)2 LinkedList (java.util.LinkedList)2 CoreException (org.eclipse.core.runtime.CoreException)2 KeyFactory (java.security.KeyFactory)1 KeyPair (java.security.KeyPair)1 PrivateKey (java.security.PrivateKey)1 PublicKey (java.security.PublicKey)1 DSAParams (java.security.interfaces.DSAParams)1 ECPrivateKey (java.security.interfaces.ECPrivateKey)1 AlgorithmParameterSpec (java.security.spec.AlgorithmParameterSpec)1