java.security.Provider.Service Java Examples
The following examples show how to use
java.security.Provider.Service.
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: Signature.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
private static Signature getInstanceRSA(Provider p) throws NoSuchAlgorithmException { // try Signature first Service s = p.getService("Signature", RSA_SIGNATURE); if (s != null) { Instance instance = GetInstance.getInstance(s, SignatureSpi.class); return getInstance(instance, RSA_SIGNATURE); } // check Cipher try { Cipher c = Cipher.getInstance(RSA_CIPHER, p); return new Delegate(new CipherAdapter(c), RSA_SIGNATURE); } catch (GeneralSecurityException e) { // throw Signature style exception message to avoid confusion, // but append Cipher exception as cause throw new NoSuchAlgorithmException("no such algorithm: " + RSA_SIGNATURE + " for provider " + p.getName(), e); } }
Example #2
Source File: JceSecurity.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
static Instance getInstance(String type, Class<?> clazz, String algorithm) throws NoSuchAlgorithmException { List<Service> services = GetInstance.getServices(type, algorithm); NoSuchAlgorithmException failure = null; for (Service s : services) { if (canUseProvider(s.getProvider()) == false) { // allow only signed providers continue; } try { Instance instance = GetInstance.getInstance(s, clazz); return instance; } catch (NoSuchAlgorithmException e) { failure = e; } } throw new NoSuchAlgorithmException("Algorithm " + algorithm + " not available", failure); }
Example #3
Source File: Signature.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
private static Signature getInstanceRSA(Provider p) throws NoSuchAlgorithmException { // try Signature first Service s = p.getService("Signature", RSA_SIGNATURE); if (s != null) { Instance instance = GetInstance.getInstance(s, SignatureSpi.class); return getInstance(instance, RSA_SIGNATURE); } // check Cipher try { Cipher c = Cipher.getInstance(RSA_CIPHER, p); return new Delegate(new CipherAdapter(c), RSA_SIGNATURE); } catch (GeneralSecurityException e) { // throw Signature style exception message to avoid confusion, // but append Cipher exception as cause throw new NoSuchAlgorithmException("no such algorithm: " + RSA_SIGNATURE + " for provider " + p.getName(), e); } }
Example #4
Source File: GetInstance.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
public static Service getService(String type, String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException { if ((provider == null) || (provider.length() == 0)) { throw new IllegalArgumentException("missing provider"); } Provider p = Providers.getProviderList().getProvider(provider); if (p == null) { throw new NoSuchProviderException("no such provider: " + provider); } Service s = p.getService(type, algorithm); if (s == null) { throw new NoSuchAlgorithmException("no such algorithm: " + algorithm + " for provider " + provider); } return s; }
Example #5
Source File: Signature.java From JDKSourceCode1.8 with MIT License | 6 votes |
private static SignatureSpi newInstance(Service s) throws NoSuchAlgorithmException { if (s.getType().equals("Cipher")) { // must be NONEwithRSA try { Cipher c = Cipher.getInstance(RSA_CIPHER, s.getProvider()); return new CipherAdapter(c); } catch (NoSuchPaddingException e) { throw new NoSuchAlgorithmException(e); } } else { Object o = s.newInstance(null); if (o instanceof SignatureSpi == false) { throw new NoSuchAlgorithmException ("Not a SignatureSpi: " + o.getClass().getName()); } return (SignatureSpi)o; } }
Example #6
Source File: ProviderList.java From Bytecoder with Apache License 2.0 | 6 votes |
public Iterator<Service> iterator() { return new Iterator<Service>() { int index; public boolean hasNext() { return tryGet(index) != null; } public Service next() { Service s = tryGet(index); if (s == null) { throw new NoSuchElementException(); } index++; return s; } public void remove() { throw new UnsupportedOperationException(); } }; }
Example #7
Source File: Signature.java From j2objc with Apache License 2.0 | 6 votes |
private static SignatureSpi newInstance(Service s) throws NoSuchAlgorithmException { if (s.getType().equals("Cipher")) { // must be NONEwithRSA try { Cipher c = Cipher.getInstance(RSA_CIPHER, s.getProvider()); return new CipherAdapter(c); } catch (NoSuchPaddingException e) { throw new NoSuchAlgorithmException(e); } } else { Object o = s.newInstance(null); if (o instanceof SignatureSpi == false) { throw new NoSuchAlgorithmException ("Not a SignatureSpi: " + o.getClass().getName()); } return (SignatureSpi)o; } }
Example #8
Source File: Signature.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
private static Signature getInstanceRSA(Provider p) throws NoSuchAlgorithmException { // try Signature first Service s = p.getService("Signature", RSA_SIGNATURE); if (s != null) { Instance instance = GetInstance.getInstance(s, SignatureSpi.class); return getInstance(instance, RSA_SIGNATURE); } // check Cipher try { Cipher c = Cipher.getInstance(RSA_CIPHER, p); return new Delegate(new CipherAdapter(c), RSA_SIGNATURE); } catch (GeneralSecurityException e) { // throw Signature style exception message to avoid confusion, // but append Cipher exception as cause throw new NoSuchAlgorithmException("no such algorithm: " + RSA_SIGNATURE + " for provider " + p.getName(), e); } }
Example #9
Source File: GetInstance.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static Instance getInstance(String type, Class<?> clazz, String algorithm, Object param) throws NoSuchAlgorithmException { List<Service> services = getServices(type, algorithm); NoSuchAlgorithmException failure = null; for (Service s : services) { try { return getInstance(s, clazz, param); } catch (NoSuchAlgorithmException e) { failure = e; } } if (failure != null) { throw failure; } else { throw new NoSuchAlgorithmException (algorithm + " " + type + " not available"); } }
Example #10
Source File: SSLSecurity.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
/** * Returns an array of objects: the first object in the array is * an instance of an implementation of the requested algorithm * and type, and the second object in the array identifies the provider * of that implementation. * The <code>provName</code> argument can be null, in which case all * configured providers will be searched in order of preference. */ static Object[] getImpl(String algName, String engineType, String provName) throws NoSuchAlgorithmException, NoSuchProviderException { Service service; if (provName != null) { ProviderList list = Providers.getProviderList(); Provider prov = list.getProvider(provName); if (prov == null) { throw new NoSuchProviderException("No such provider: " + provName); } service = prov.getService(engineType, algName); } else { service = getService(engineType, algName); } if (service == null) { throw new NoSuchAlgorithmException("Algorithm " + algName + " not available"); } return getImpl1(algName, engineType, service); }
Example #11
Source File: JceSecurity.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
static Instance getInstance(String type, Class<?> clazz, String algorithm) throws NoSuchAlgorithmException { List<Service> services = GetInstance.getServices(type, algorithm); NoSuchAlgorithmException failure = null; for (Service s : services) { if (canUseProvider(s.getProvider()) == false) { // allow only signed providers continue; } try { Instance instance = GetInstance.getInstance(s, clazz); return instance; } catch (NoSuchAlgorithmException e) { failure = e; } } throw new NoSuchAlgorithmException("Algorithm " + algorithm + " not available", failure); }
Example #12
Source File: ProviderList.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Return a Service describing an implementation of the specified * algorithm from the Provider with the highest precedence that * supports that algorithm. Return null if no Provider supports this * algorithm. */ public Service getService(String type, String name) { for (int i = 0; i < configs.length; i++) { Provider p = getProvider(i); Service s = p.getService(type, name); if (s != null) { return s; } } return null; }
Example #13
Source File: Cipher.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
private static Transform getTransform(Service s, List<Transform> transforms) { String alg = s.getAlgorithm().toUpperCase(Locale.ENGLISH); for (Transform tr : transforms) { if (alg.endsWith(tr.suffix)) { return tr; } } return null; }
Example #14
Source File: GetInstance.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Check is subClass is a subclass of superClass. If not, * throw a NoSuchAlgorithmException. */ public static void checkSuperClass(Service s, Class<?> subClass, Class<?> superClass) throws NoSuchAlgorithmException { if (superClass == null) { return; } if (superClass.isAssignableFrom(subClass) == false) { throw new NoSuchAlgorithmException ("class configured for " + s.getType() + ": " + s.getClassName() + " not a " + s.getType()); } }
Example #15
Source File: JceSecurity.java From j2objc with Apache License 2.0 | 5 votes |
static Instance getInstance(String type, Class<?> clazz, String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException { Service s = GetInstance.getService(type, algorithm, provider); /* ----- BEGIN j2objc ----- Exception ve = getVerificationResult(s.getProvider()); if (ve != null) { String msg = "JCE cannot authenticate the provider " + provider; throw (NoSuchProviderException) new NoSuchProviderException(msg).initCause(ve); } ----- END j2objc ----- */ return GetInstance.getInstance(s, clazz); }
Example #16
Source File: KeyFactory.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private KeyFactory(String algorithm) throws NoSuchAlgorithmException { this.algorithm = algorithm; List<Service> list = GetInstance.getServices("KeyFactory", algorithm); serviceIterator = list.iterator(); // fetch and instantiate initial spi if (nextSpi(null) == null) { throw new NoSuchAlgorithmException (algorithm + " KeyFactory not available"); } }
Example #17
Source File: SecretKeyFactory.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private SecretKeyFactory(String algorithm) throws NoSuchAlgorithmException { this.algorithm = algorithm; List<Service> list = GetInstance.getServices("SecretKeyFactory", algorithm); serviceIterator = list.iterator(); // fetch and instantiate initial spi if (nextSpi(null) == null) { throw new NoSuchAlgorithmException (algorithm + " SecretKeyFactory not available"); } }
Example #18
Source File: ProviderList.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Return a Service describing an implementation of the specified * algorithm from the Provider with the highest precedence that * supports that algorithm. Return null if no Provider supports this * algorithm. */ public Service getService(String type, String name) { for (int i = 0; i < configs.length; i++) { Provider p = getProvider(i); Service s = p.getService(type, name); if (s != null) { return s; } } return null; }
Example #19
Source File: Turkish.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
private static void check(Service s1, Service s2) throws Exception { System.out.println(s1); if (s1 == null) { throw new Exception("service is null"); } if ((s2 != null) && (s1 != s2)) { throw new Exception("service does not match"); } }
Example #20
Source File: ProviderList.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * Return a Service describing an implementation of the specified * algorithm from the Provider with the highest precedence that * supports that algorithm. Return null if no Provider supports this * algorithm. */ public Service getService(String type, String name) { for (int i = 0; i < configs.length; i++) { Provider p = getProvider(i); Service s = p.getService(type, name); if (s != null) { return s; } } return null; }
Example #21
Source File: KeyPairGenerator.java From Java8CN with Apache License 2.0 | 5 votes |
/** * Returns a KeyPairGenerator object that generates public/private * key pairs for the specified algorithm. * * <p> This method traverses the list of registered security Providers, * starting with the most preferred Provider. * A new KeyPairGenerator object encapsulating the * KeyPairGeneratorSpi 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 string name of the algorithm. * See the KeyPairGenerator section in the <a href= * "{@docRoot}/../technotes/guides/security/StandardNames.html#KeyPairGenerator"> * Java Cryptography Architecture Standard Algorithm Name Documentation</a> * for information about standard algorithm names. * * @return the new KeyPairGenerator object. * * @exception NoSuchAlgorithmException if no Provider supports a * KeyPairGeneratorSpi implementation for the * specified algorithm. * * @see Provider */ public static KeyPairGenerator getInstance(String algorithm) throws NoSuchAlgorithmException { List<Service> list = GetInstance.getServices("KeyPairGenerator", algorithm); Iterator<Service> t = list.iterator(); if (t.hasNext() == false) { throw new NoSuchAlgorithmException (algorithm + " KeyPairGenerator not available"); } // find a working Spi or KeyPairGenerator subclass NoSuchAlgorithmException failure = null; do { Service s = t.next(); try { Instance instance = GetInstance.getInstance(s, KeyPairGeneratorSpi.class); if (instance.impl instanceof KeyPairGenerator) { return getInstance(instance, algorithm); } else { return new Delegate(instance, t, algorithm); } } catch (NoSuchAlgorithmException e) { if (failure == null) { failure = e; } } } while (t.hasNext()); throw failure; }
Example #22
Source File: Cipher.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
int supportsModePadding(Service s) { int smode = supportsMode(s); if (smode == S_NO) { return smode; } int spad = supportsPadding(s); // our constants are defined so that Math.min() is a tri-valued AND return Math.min(smode, spad); }
Example #23
Source File: KeyFactory.java From Bytecoder with Apache License 2.0 | 5 votes |
private KeyFactory(String algorithm) throws NoSuchAlgorithmException { this.algorithm = algorithm; List<Service> list = GetInstance.getServices("KeyFactory", algorithm); serviceIterator = list.iterator(); // fetch and instantiate initial spi if (nextSpi(null) == null) { throw new NoSuchAlgorithmException (algorithm + " KeyFactory not available"); } }
Example #24
Source File: TransformService.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Returns a <code>TransformService</code> that supports the specified * algorithm URI (ex: {@link Transform#XPATH2}) and mechanism type * (ex: DOM) as supplied by the specified provider. The specified provider * must be registered in the security provider list. * * <p>Note that the list of registered providers may be retrieved via * the {@link Security#getProviders() Security.getProviders()} method. * * @param algorithm the URI of the algorithm * @param mechanismType the type of the XML processing mechanism and * representation * @param provider the string name of the provider * @return a new <code>TransformService</code> * @throws NoSuchProviderException if the specified provider is not * registered in the security provider list * @throws NullPointerException if <code>provider</code>, * <code>mechanismType</code>, or <code>algorithm</code> is * <code>null</code> * @throws NoSuchAlgorithmException if a <code>TransformService</code> * implementation for the specified algorithm and mechanism type is not * available from the specified provider * @see Provider */ public static TransformService getInstance (String algorithm, String mechanismType, String provider) throws NoSuchAlgorithmException, NoSuchProviderException { if (mechanismType == null || algorithm == null || provider == null) { throw new NullPointerException(); } else if (provider.length() == 0) { throw new NoSuchProviderException(); } boolean dom = false; if (mechanismType.equals("DOM")) { dom = true; } Service s = GetInstance.getService ("TransformService", algorithm, provider); String value = s.getAttribute("MechanismType"); if ((value == null && dom) || (value != null && value.equals(mechanismType))) { Instance instance = GetInstance.getInstance(s, null); TransformService ts = (TransformService) instance.impl; ts.algorithm = algorithm; ts.mechanism = mechanismType; ts.provider = instance.provider; return ts; } throw new NoSuchAlgorithmException (algorithm + " algorithm and " + mechanismType + " mechanism not available"); }
Example #25
Source File: Signature.java From JDKSourceCode1.8 with MIT License | 5 votes |
Delegate(Service service, Iterator<Service> iterator, String algorithm) { super(algorithm); this.firstService = service; this.serviceIterator = iterator; this.lock = new Object(); }
Example #26
Source File: TransformService.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Returns a <code>TransformService</code> that supports the specified * algorithm URI (ex: {@link Transform#XPATH2}) and mechanism 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 algorithm the URI of the algorithm * @param mechanismType the type of the XML processing mechanism and * representation * @param provider the <code>Provider</code> object * @return a new <code>TransformService</code> * @throws NullPointerException if <code>provider</code>, * <code>algorithm</code>, or <code>mechanismType</code> is * <code>null</code> * @throws NoSuchAlgorithmException if a <code>TransformService</code> * implementation for the specified algorithm and mechanism type is not * available from the specified <code>Provider</code> object * @see Provider */ public static TransformService getInstance (String algorithm, String mechanismType, Provider provider) throws NoSuchAlgorithmException { if (mechanismType == null || algorithm == null || provider == null) { throw new NullPointerException(); } boolean dom = false; if (mechanismType.equals("DOM")) { dom = true; } Service s = GetInstance.getService ("TransformService", algorithm, provider); String value = s.getAttribute("MechanismType"); if ((value == null && dom) || (value != null && value.equals(mechanismType))) { Instance instance = GetInstance.getInstance(s, null); TransformService ts = (TransformService) instance.impl; ts.algorithm = algorithm; ts.mechanism = mechanismType; ts.provider = instance.provider; return ts; } throw new NoSuchAlgorithmException (algorithm + " algorithm and " + mechanismType + " mechanism not available"); }
Example #27
Source File: JceSecurity.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
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); }
Example #28
Source File: ProviderList.java From hottub with GNU General Public License v2.0 | 5 votes |
private void addService(Service s) { if (firstService == null) { firstService = s; } else { if (services == null) { services = new ArrayList<Service>(4); services.add(firstService); } services.add(s); } }
Example #29
Source File: TransformService.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * Returns a <code>TransformService</code> that supports the specified * algorithm URI (ex: {@link Transform#XPATH2}) and mechanism type * (ex: DOM) as supplied by the specified provider. The specified provider * must be registered in the security provider list. * * <p>Note that the list of registered providers may be retrieved via * the {@link Security#getProviders() Security.getProviders()} method. * * @param algorithm the URI of the algorithm * @param mechanismType the type of the XML processing mechanism and * representation * @param provider the string name of the provider * @return a new <code>TransformService</code> * @throws NoSuchProviderException if the specified provider is not * registered in the security provider list * @throws NullPointerException if <code>provider</code>, * <code>mechanismType</code>, or <code>algorithm</code> is * <code>null</code> * @throws NoSuchAlgorithmException if a <code>TransformService</code> * implementation for the specified algorithm and mechanism type is not * available from the specified provider * @see Provider */ public static TransformService getInstance (String algorithm, String mechanismType, String provider) throws NoSuchAlgorithmException, NoSuchProviderException { if (mechanismType == null || algorithm == null || provider == null) { throw new NullPointerException(); } else if (provider.length() == 0) { throw new NoSuchProviderException(); } boolean dom = false; if (mechanismType.equals("DOM")) { dom = true; } Service s = GetInstance.getService ("TransformService", algorithm, provider); String value = s.getAttribute("MechanismType"); if ((value == null && dom) || (value != null && value.equals(mechanismType))) { Instance instance = GetInstance.getInstance(s, null); TransformService ts = (TransformService) instance.impl; ts.algorithm = algorithm; ts.mechanism = mechanismType; ts.provider = instance.provider; return ts; } throw new NoSuchAlgorithmException (algorithm + " algorithm and " + mechanismType + " mechanism not available"); }
Example #30
Source File: ProviderList.java From j2objc with Apache License 2.0 | 5 votes |
private void addService(Service s) { if (firstService == null) { firstService = s; } else { if (services == null) { services = new ArrayList<Service>(4); services.add(firstService); } services.add(s); } }