Java Code Examples for java.security.Provider#getName()

The following examples show how to use java.security.Provider#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestKGParity.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private void run() throws Exception {
    Provider[] providers = Security.getProviders();
    for (Provider p : providers) {
        String prvName = p.getName();
        if (prvName.startsWith("SunJCE")
                || prvName.startsWith("SunPKCS11-")) {
            for (String algorithm : ALGORITHM_ARR) {
                if (!runTest(p, algorithm)) {
                    throw new RuntimeException(
                            "Test failed with provider/algorithm:"
                                    + p.getName() + "/" + algorithm);
                } else {
                    out.println("Test passed with provider/algorithm:"
                            + p.getName() + "/" + algorithm);
                }
            }
        }
    }
}
 
Example 2
Source File: TestKGParity.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void run() throws Exception {
    Provider[] providers = Security.getProviders();
    for (Provider p : providers) {
        String prvName = p.getName();
        if (prvName.startsWith("SunJCE")
                || prvName.startsWith("SunPKCS11-")) {
            for (String algorithm : ALGORITHM_ARR) {
                if (!runTest(p, algorithm)) {
                    throw new RuntimeException(
                            "Test failed with provider/algorithm:"
                                    + p.getName() + "/" + algorithm);
                } else {
                    out.println("Test passed with provider/algorithm:"
                            + p.getName() + "/" + algorithm);
                }
            }
        }
    }
}
 
Example 3
Source File: ProviderList.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
synchronized public void addProviderAtEnd(Provider p, Oid mechOid)
    throws GSSException {

    PreferencesEntry newEntry = new PreferencesEntry(p, mechOid);
    PreferencesEntry oldEntry;
    boolean foundSomeMech;

    Iterator<PreferencesEntry> list = preferences.iterator();
    while (list.hasNext()) {
        oldEntry = list.next();
        if (oldEntry.implies(newEntry))
            return;
    }

    // System.out.println("addProviderAtEnd: No it is not redundant");

    if (mechOid == null)
        foundSomeMech = addAllMechsFromProvider(p);
    else {
        String oidStr = mechOid.toString();
        if (p.getProperty(PROV_PROP_PREFIX + oidStr) == null)
            throw new GSSExceptionImpl(GSSException.BAD_MECH,
                                   "Provider " + p.getName()
                                   + " does not support "
                                   + oidStr);
        mechs.add(mechOid);
        foundSomeMech = true;
    }

    if (foundSomeMech) {
        preferences.add(newEntry);
    }
}
 
Example 4
Source File: ProviderList.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Helper routine that uses a preferences entry to obtain an
 * implementation of a MechanismFactory from it.
 * @param e the preferences entry that contains the provider and
 * either a null of an explicit oid that matched the oid of the
 * desired mechanism.
 * @param mechOid the oid of the desired mechanism
 * @throws GSSException If the application explicitly requested
 * this entry's provider to be used for the desired mechanism but
 * some problem is encountered
 */
private MechanismFactory getMechFactory(PreferencesEntry e, Oid mechOid)
    throws GSSException {
    Provider p = e.getProvider();

    /*
     * See if a MechanismFactory was previously instantiated for
     * this provider and mechanism combination.
     */
    PreferencesEntry searchEntry = new PreferencesEntry(p, mechOid);
    MechanismFactory retVal = factories.get(searchEntry);
    if (retVal == null) {
        /*
         * Apparently not. Now try to instantiate this class from
         * the provider.
         */
        String prop = PROV_PROP_PREFIX + mechOid.toString();
        String className = p.getProperty(prop);
        if (className != null) {
            retVal = getMechFactoryImpl(p, className, mechOid, caller);
            factories.put(searchEntry, retVal);
        } else {
            /*
             * This provider does not support this mechanism.
             * If the application explicitly requested that
             * this provider be used for this mechanism, then
             * throw an exception
             */
            if (e.getOid() != null) {
                throw new GSSExceptionImpl(GSSException.BAD_MECH,
                     "Provider " + p.getName() +
                     " does not support mechanism " + mechOid);
            }
        }
    }
    return retVal;
}
 
Example 5
Source File: ProviderList.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Helper routine that uses a preferences entry to obtain an
 * implementation of a MechanismFactory from it.
 * @param e the preferences entry that contains the provider and
 * either a null of an explicit oid that matched the oid of the
 * desired mechanism.
 * @param mechOid the oid of the desired mechanism
 * @throws GSSException If the application explicitly requested
 * this entry's provider to be used for the desired mechanism but
 * some problem is encountered
 */
private MechanismFactory getMechFactory(PreferencesEntry e, Oid mechOid)
    throws GSSException {
    Provider p = e.getProvider();

    /*
     * See if a MechanismFactory was previously instantiated for
     * this provider and mechanism combination.
     */
    PreferencesEntry searchEntry = new PreferencesEntry(p, mechOid);
    MechanismFactory retVal = factories.get(searchEntry);
    if (retVal == null) {
        /*
         * Apparently not. Now try to instantiate this class from
         * the provider.
         */
        String prop = PROV_PROP_PREFIX + mechOid.toString();
        String className = p.getProperty(prop);
        if (className != null) {
            retVal = getMechFactoryImpl(p, className, mechOid, caller);
            factories.put(searchEntry, retVal);
        } else {
            /*
             * This provider does not support this mechanism.
             * If the application explicitly requested that
             * this provider be used for this mechanism, then
             * throw an exception
             */
            if (e.getOid() != null) {
                throw new GSSExceptionImpl(GSSException.BAD_MECH,
                     "Provider " + p.getName() +
                     " does not support mechanism " + mechOid);
            }
        }
    }
    return retVal;
}
 
Example 6
Source File: ProviderList.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
synchronized public void addProviderAtFront(Provider p, Oid mechOid)
    throws GSSException {

    PreferencesEntry newEntry = new PreferencesEntry(p, mechOid);
    PreferencesEntry oldEntry;
    boolean foundSomeMech;

    Iterator<PreferencesEntry> list = preferences.iterator();
    while (list.hasNext()) {
        oldEntry = list.next();
        if (newEntry.implies(oldEntry))
            list.remove();
    }

    if (mechOid == null) {
        foundSomeMech = addAllMechsFromProvider(p);
    } else {
        String oidStr = mechOid.toString();
        if (p.getProperty(PROV_PROP_PREFIX + oidStr) == null)
            throw new GSSExceptionImpl(GSSException.BAD_MECH,
                                       "Provider " + p.getName()
                                       + " does not support "
                                       + oidStr);
        mechs.add(mechOid);
        foundSomeMech = true;
    }

    if (foundSomeMech) {
        preferences.add(0, newEntry);
    }
}
 
Example 7
Source File: ProviderList.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static GSSException createGSSException(Provider p,
                                               String className,
                                               String trailingMsg,
                                               Exception cause) {
    String errClassInfo = className + " configured by " +
        p.getName() + " for GSS-API Mechanism Factory ";
    return new GSSExceptionImpl(GSSException.BAD_MECH,
                                errClassInfo + trailingMsg,
                                cause);
}
 
Example 8
Source File: ProviderList.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Helper routine that uses a preferences entry to obtain an
 * implementation of a MechanismFactory from it.
 * @param e the preferences entry that contains the provider and
 * either a null of an explicit oid that matched the oid of the
 * desired mechanism.
 * @param mechOid the oid of the desired mechanism
 * @throws GSSException If the application explicitly requested
 * this entry's provider to be used for the desired mechanism but
 * some problem is encountered
 */
private MechanismFactory getMechFactory(PreferencesEntry e, Oid mechOid)
    throws GSSException {
    Provider p = e.getProvider();

    /*
     * See if a MechanismFactory was previously instantiated for
     * this provider and mechanism combination.
     */
    PreferencesEntry searchEntry = new PreferencesEntry(p, mechOid);
    MechanismFactory retVal = factories.get(searchEntry);
    if (retVal == null) {
        /*
         * Apparently not. Now try to instantiate this class from
         * the provider.
         */
        String prop = PROV_PROP_PREFIX + mechOid.toString();
        String className = p.getProperty(prop);
        if (className != null) {
            retVal = getMechFactoryImpl(p, className, mechOid, caller);
            factories.put(searchEntry, retVal);
        } else {
            /*
             * This provider does not support this mechanism.
             * If the application explicitly requested that
             * this provider be used for this mechanism, then
             * throw an exception
             */
            if (e.getOid() != null) {
                throw new GSSExceptionImpl(GSSException.BAD_MECH,
                     "Provider " + p.getName() +
                     " does not support mechanism " + mechOid);
            }
        }
    }
    return retVal;
}
 
Example 9
Source File: ProviderList.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static GSSException createGSSException(Provider p,
                                               String className,
                                               String trailingMsg,
                                               Exception cause) {
    String errClassInfo = className + " configured by " +
        p.getName() + " for GSS-API Mechanism Factory ";
    return new GSSExceptionImpl(GSSException.BAD_MECH,
                                errClassInfo + trailingMsg,
                                cause);
}
 
Example 10
Source File: XMLSignatureFactory.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns an <code>XMLSignatureFactory</code> that supports the
 * requested XML processing mechanism and representation type (ex: "DOM"),
 * as supplied by the specified provider. Note that the specified
 * <code>Provider</code> object does not have to be registered in the
 * provider list.
 *
 * @param mechanismType the type of the XML processing mechanism and
 *    representation. See the {@extLink security_guide_xmldsig_provider
 *    Service Providers} section of the API overview for a list of
 *    standard mechanism types.
 * @param provider the <code>Provider</code> object
 * @return a new <code>XMLSignatureFactory</code>
 * @throws NullPointerException if <code>provider</code> or
 *    <code>mechanismType</code> is <code>null</code>
 * @throws NoSuchMechanismException if an <code>XMLSignatureFactory</code>
 *   implementation for the specified mechanism is not available
 *   from the specified <code>Provider</code> object
 * @see Provider
 */
public static XMLSignatureFactory getInstance(String mechanismType,
    Provider provider) {
    if (mechanismType == null) {
        throw new NullPointerException("mechanismType cannot be null");
    } else if (provider == null) {
        throw new NullPointerException("provider cannot be null");
    }

    Service s = provider.getService("XMLSignatureFactory", mechanismType);
    if (s != null) {
        Object obj = null;
        try {
            obj = s.newInstance(null);
        } catch (NoSuchAlgorithmException nsae) {
            throw new NoSuchMechanismException(nsae);
        }

        if (obj instanceof XMLSignatureFactory) {
            XMLSignatureFactory factory = (XMLSignatureFactory) obj;
            factory.mechanismType = mechanismType;
            factory.provider = provider;
            return factory;
        }
    }
    throw new NoSuchMechanismException
        ("Mechanism " + mechanismType + " not available from " +
         provider.getName());
}
 
Example 11
Source File: ProviderList.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static GSSException createGSSException(Provider p,
                                               String className,
                                               String trailingMsg,
                                               Exception cause) {
    String errClassInfo = className + " configured by " +
        p.getName() + " for GSS-API Mechanism Factory ";
    return new GSSExceptionImpl(GSSException.BAD_MECH,
                                errClassInfo + trailingMsg,
                                cause);
}
 
Example 12
Source File: ProviderList.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
synchronized public void addProviderAtEnd(Provider p, Oid mechOid)
    throws GSSException {

    PreferencesEntry newEntry = new PreferencesEntry(p, mechOid);
    PreferencesEntry oldEntry;
    boolean foundSomeMech;

    Iterator<PreferencesEntry> list = preferences.iterator();
    while (list.hasNext()) {
        oldEntry = list.next();
        if (oldEntry.implies(newEntry))
            return;
    }

    // System.out.println("addProviderAtEnd: No it is not redundant");

    if (mechOid == null)
        foundSomeMech = addAllMechsFromProvider(p);
    else {
        String oidStr = mechOid.toString();
        if (p.getProperty(PROV_PROP_PREFIX + oidStr) == null)
            throw new GSSExceptionImpl(GSSException.BAD_MECH,
                                   "Provider " + p.getName()
                                   + " does not support "
                                   + oidStr);
        mechs.add(mechOid);
        foundSomeMech = true;
    }

    if (foundSomeMech) {
        preferences.add(newEntry);
    }
}
 
Example 13
Source File: ProviderList.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
synchronized public void addProviderAtFront(Provider p, Oid mechOid)
    throws GSSException {

    PreferencesEntry newEntry = new PreferencesEntry(p, mechOid);
    PreferencesEntry oldEntry;
    boolean foundSomeMech;

    Iterator<PreferencesEntry> list = preferences.iterator();
    while (list.hasNext()) {
        oldEntry = list.next();
        if (newEntry.implies(oldEntry))
            list.remove();
    }

    if (mechOid == null) {
        foundSomeMech = addAllMechsFromProvider(p);
    } else {
        String oidStr = mechOid.toString();
        if (p.getProperty(PROV_PROP_PREFIX + oidStr) == null)
            throw new GSSExceptionImpl(GSSException.BAD_MECH,
                                       "Provider " + p.getName()
                                       + " does not support "
                                       + oidStr);
        mechs.add(mechOid);
        foundSomeMech = true;
    }

    if (foundSomeMech) {
        preferences.add(0, newEntry);
    }
}
 
Example 14
Source File: ProviderList.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
synchronized public void addProviderAtEnd(Provider p, Oid mechOid)
    throws GSSException {

    PreferencesEntry newEntry = new PreferencesEntry(p, mechOid);
    PreferencesEntry oldEntry;
    boolean foundSomeMech;

    Iterator<PreferencesEntry> list = preferences.iterator();
    while (list.hasNext()) {
        oldEntry = list.next();
        if (oldEntry.implies(newEntry))
            return;
    }

    // System.out.println("addProviderAtEnd: No it is not redundant");

    if (mechOid == null)
        foundSomeMech = addAllMechsFromProvider(p);
    else {
        String oidStr = mechOid.toString();
        if (p.getProperty(PROV_PROP_PREFIX + oidStr) == null)
            throw new GSSExceptionImpl(GSSException.BAD_MECH,
                                   "Provider " + p.getName()
                                   + " does not support "
                                   + oidStr);
        mechs.add(mechOid);
        foundSomeMech = true;
    }

    if (foundSomeMech) {
        preferences.add(newEntry);
    }
}
 
Example 15
Source File: ProviderList.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static GSSException createGSSException(Provider p,
                                               String className,
                                               String trailingMsg,
                                               Exception cause) {
    String errClassInfo = className + " configured by " +
        p.getName() + " for GSS-API Mechanism Factory ";
    return new GSSExceptionImpl(GSSException.BAD_MECH,
                                errClassInfo + trailingMsg,
                                cause);
}
 
Example 16
Source File: ProviderList.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Helper routine that uses a preferences entry to obtain an
 * implementation of a MechanismFactory from it.
 * @param e the preferences entry that contains the provider and
 * either a null of an explicit oid that matched the oid of the
 * desired mechanism.
 * @param mechOid the oid of the desired mechanism
 * @throws GSSException If the application explicitly requested
 * this entry's provider to be used for the desired mechanism but
 * some problem is encountered
 */
private MechanismFactory getMechFactory(PreferencesEntry e, Oid mechOid)
    throws GSSException {
    Provider p = e.getProvider();

    /*
     * See if a MechanismFactory was previously instantiated for
     * this provider and mechanism combination.
     */
    PreferencesEntry searchEntry = new PreferencesEntry(p, mechOid);
    MechanismFactory retVal = factories.get(searchEntry);
    if (retVal == null) {
        /*
         * Apparently not. Now try to instantiate this class from
         * the provider.
         */
        String prop = PROV_PROP_PREFIX + mechOid.toString();
        String className = p.getProperty(prop);
        if (className != null) {
            retVal = getMechFactoryImpl(p, className, mechOid, caller);
            factories.put(searchEntry, retVal);
        } else {
            /*
             * This provider does not support this mechanism.
             * If the application explicitly requested that
             * this provider be used for this mechanism, then
             * throw an exception
             */
            if (e.getOid() != null) {
                throw new GSSExceptionImpl(GSSException.BAD_MECH,
                     "Provider " + p.getName() +
                     " does not support mechanism " + mechOid);
            }
        }
    }
    return retVal;
}
 
Example 17
Source File: ProviderList.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Helper routine that uses a preferences entry to obtain an
 * implementation of a MechanismFactory from it.
 * @param e the preferences entry that contains the provider and
 * either a null of an explicit oid that matched the oid of the
 * desired mechanism.
 * @param mechOid the oid of the desired mechanism
 * @throws GSSException If the application explicitly requested
 * this entry's provider to be used for the desired mechanism but
 * some problem is encountered
 */
private MechanismFactory getMechFactory(PreferencesEntry e, Oid mechOid)
    throws GSSException {
    Provider p = e.getProvider();

    /*
     * See if a MechanismFactory was previously instantiated for
     * this provider and mechanism combination.
     */
    PreferencesEntry searchEntry = new PreferencesEntry(p, mechOid);
    MechanismFactory retVal = factories.get(searchEntry);
    if (retVal == null) {
        /*
         * Apparently not. Now try to instantiate this class from
         * the provider.
         */
        String prop = PROV_PROP_PREFIX + mechOid.toString();
        String className = p.getProperty(prop);
        if (className != null) {
            retVal = getMechFactoryImpl(p, className, mechOid, caller);
            factories.put(searchEntry, retVal);
        } else {
            /*
             * This provider does not support this mechanism.
             * If the application explicitly requested that
             * this provider be used for this mechanism, then
             * throw an exception
             */
            if (e.getOid() != null) {
                throw new GSSExceptionImpl(GSSException.BAD_MECH,
                     "Provider " + p.getName() +
                     " does not support mechanism " + mechOid);
            }
        }
    }
    return retVal;
}
 
Example 18
Source File: ProviderList.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static GSSException createGSSException(Provider p,
                                               String className,
                                               String trailingMsg,
                                               Exception cause) {
    String errClassInfo = className + " configured by " +
        p.getName() + " for GSS-API Mechanism Factory ";
    return new GSSExceptionImpl(GSSException.BAD_MECH,
                                errClassInfo + trailingMsg,
                                cause);
}
 
Example 19
Source File: ProviderList.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Helper routine that uses a preferences entry to obtain an
 * implementation of a MechanismFactory from it.
 * @param e the preferences entry that contains the provider and
 * either a null of an explicit oid that matched the oid of the
 * desired mechanism.
 * @param mechOid the oid of the desired mechanism
 * @throws GSSException If the application explicitly requested
 * this entry's provider to be used for the desired mechanism but
 * some problem is encountered
 */
private MechanismFactory getMechFactory(PreferencesEntry e, Oid mechOid)
    throws GSSException {
    Provider p = e.getProvider();

    /*
     * See if a MechanismFactory was previously instantiated for
     * this provider and mechanism combination.
     */
    PreferencesEntry searchEntry = new PreferencesEntry(p, mechOid);
    MechanismFactory retVal = factories.get(searchEntry);
    if (retVal == null) {
        /*
         * Apparently not. Now try to instantiate this class from
         * the provider.
         */
        String prop = PROV_PROP_PREFIX + mechOid.toString();
        String className = p.getProperty(prop);
        if (className != null) {
            retVal = getMechFactoryImpl(p, className, mechOid, caller);
            factories.put(searchEntry, retVal);
        } else {
            /*
             * This provider does not support this mechanism.
             * If the application explicitly requested that
             * this provider be used for this mechanism, then
             * throw an exception
             */
            if (e.getOid() != null) {
                throw new GSSExceptionImpl(GSSException.BAD_MECH,
                     "Provider " + p.getName() +
                     " does not support mechanism " + mechOid);
            }
        }
    }
    return retVal;
}
 
Example 20
Source File: TestCACerts.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void main(Provider p) throws Exception {

    /*
     * Use Solaris SPARC 11.2 or later to avoid an intermittent failure
     * when running SunPKCS11-Solaris (8044554)
     */
    if (p.getName().equals("SunPKCS11-Solaris") &&
        props.getProperty("os.name").equals("SunOS") &&
        props.getProperty("os.arch").equals("sparcv9") &&
        props.getProperty("os.version").compareTo("5.11") <= 0 &&
        getDistro().compareTo("11.2") < 0) {

        System.out.println("SunPKCS11-Solaris provider requires " +
            "Solaris SPARC 11.2 or later, skipping");
        return;
    }

    long start = System.currentTimeMillis();
    Providers.setAt(p, 1);
    try {
        String PROVIDER = p.getName();
        String javaHome = props.getProperty("java.home");
        String caCerts = javaHome + SEP + "lib" + SEP + "security" + SEP + "cacerts";
        KeyStore ks;
        try (InputStream in = new FileInputStream(caCerts)) {
            ks = KeyStore.getInstance(KeyStore.getDefaultType());
            ks.load(in, null);
        }
        for (Enumeration e = ks.aliases(); e.hasMoreElements(); ) {
            String alias = (String)e.nextElement();
            if (ks.isCertificateEntry(alias)) {
                System.out.println("* Testing " + alias + "...");
                X509Certificate cert = (X509Certificate)ks.getCertificate(alias);
                PublicKey key = cert.getPublicKey();
                String alg = key.getAlgorithm();
                if (alg.equals("RSA")) {
                    System.out.println("Signature algorithm: " + cert.getSigAlgName());
                    cert.verify(key, PROVIDER);
                } else {
                    System.out.println("Skipping cert with key: " + alg);
                }
            } else {
                System.out.println("Skipping alias " + alias);
            }
        }
        long stop = System.currentTimeMillis();
        System.out.println("All tests passed (" + (stop - start) + " ms).");
     } finally {
        Security.removeProvider(p.getName());
     }
}