summaryrefslogtreecommitdiff
path: root/javax/net
diff options
context:
space:
mode:
Diffstat (limited to 'javax/net')
-rw-r--r--javax/net/ssl/KeyManagerFactory.java106
-rw-r--r--javax/net/ssl/SSLContext.java125
-rw-r--r--javax/net/ssl/TrustManagerFactory.java103
3 files changed, 179 insertions, 155 deletions
diff --git a/javax/net/ssl/KeyManagerFactory.java b/javax/net/ssl/KeyManagerFactory.java
index ab8abd626..33f2fda9c 100644
--- a/javax/net/ssl/KeyManagerFactory.java
+++ b/javax/net/ssl/KeyManagerFactory.java
@@ -132,49 +132,55 @@ public class KeyManagerFactory
}
/**
- * Get an instance of the named key manager factory, from the first
+ * Create an instance of the named key manager factory, from the first
* provider that implements it.
- *
+ *
* @param algorithm The type of key manager factory to get.
* @return An appropriate implementation of that algoritm.
- * @throws NoSuchAlgorithmException If no provider implements the
- * requested algorithm.
+ * @throws NoSuchAlgorithmException If no provider implements the requested
+ * algorithm.
+ * @throws IllegalArgumentException if <code>algorithm</code> is
+ * <code>null</code> or is an empty string.
*/
public static final KeyManagerFactory getInstance(String algorithm)
- throws NoSuchAlgorithmException
+ throws NoSuchAlgorithmException
{
- Provider[] provs = Security.getProviders();
- for (int i = 0; i < provs.length; i++)
- {
- try
- {
- return getInstance(algorithm, provs[i]);
- }
- catch (NoSuchAlgorithmException ignore)
- {
- }
- }
+ Provider[] p = Security.getProviders();
+ NoSuchAlgorithmException lastException = null;
+ for (int i = 0; i < p.length; i++)
+ try
+ {
+ return getInstance(algorithm, p[i]);
+ }
+ catch (NoSuchAlgorithmException x)
+ {
+ lastException = x;
+ }
+ if (lastException != null)
+ throw lastException;
throw new NoSuchAlgorithmException(algorithm);
}
/**
- * Get an instance of the named key manager factory, from the named
+ * Create an instance of the named key manager factory, from the named
* provider.
- *
+ *
* @param algorithm The type of key manager factory to get.
- * @param provider The name of the provider to get the
- * implementation from.
+ * @param provider The name of the provider to get the implementation from.
* @return An appropriate implementation of that algorithm.
- * @throws NoSuchAlgorithmException If the provider does not
- * implement the requested algorithm.
- * @throws NoSuchProviderException If the named provider does not
- * exist.
+ * @throws NoSuchAlgorithmException If the provider does not implement the
+ * requested algorithm.
+ * @throws NoSuchProviderException If the named provider does not exist.
+ * @throws IllegalArgumentException if either <code>algorithm</code> or
+ * <code>provider</code> is <code>null</code>, or if
+ * <code>algorithm</code> is an empty string.
*/
- public static final KeyManagerFactory getInstance(String algorithm, String provider)
- throws NoSuchAlgorithmException, NoSuchProviderException
+ public static final KeyManagerFactory getInstance(String algorithm,
+ String provider)
+ throws NoSuchAlgorithmException, NoSuchProviderException
{
if (provider == null)
- throw new IllegalArgumentException("provider is null");
+ throw new IllegalArgumentException("provider MUST NOT be null");
Provider p = Security.getProvider(provider);
if (p == null)
throw new NoSuchProviderException(provider);
@@ -182,40 +188,48 @@ public class KeyManagerFactory
}
/**
- * Get an instance of the named key manager factory, from the given
+ * Create an instance of the named key manager factory, from the given
* provider.
- *
+ *
* @param algorithm The type of key manager factory to get.
* @param provider The provider to get the implementation from.
* @return An appropriate implementation of that algorithm.
- * @throws NoSuchAlgorithmException If the provider does not
- * implement the requested algorithm.
- * @throws IllegalArgumentException If <i>provider</i> is null.
+ * @throws NoSuchAlgorithmException If the provider does not implement the
+ * requested algorithm.
+ * @throws IllegalArgumentException if either <code>algorithm</code> or
+ * <code>provider</code> is <code>null</code>, or if
+ * <code>algorithm</code> is an empty string.
*/
- public static final KeyManagerFactory getInstance(String algorithm, Provider provider)
- throws NoSuchAlgorithmException
+ public static final KeyManagerFactory getInstance(String algorithm,
+ Provider provider)
+ throws NoSuchAlgorithmException
{
- if (provider == null)
- throw new IllegalArgumentException("provider is null");
+ StringBuilder sb = new StringBuilder("KeyManagerFactory algorithm [")
+ .append(algorithm).append("] from provider[")
+ .append(provider).append("] could not be created");
+ Throwable cause;
try
{
- return new KeyManagerFactory((KeyManagerFactorySpi)
- Engine.getInstance(KEY_MANAGER_FACTORY, algorithm, provider),
- provider, algorithm);
+ Object spi = Engine.getInstance(KEY_MANAGER_FACTORY, algorithm, provider);
+ return new KeyManagerFactory((KeyManagerFactorySpi) spi, provider, algorithm);
}
- catch (InvocationTargetException ite)
+ catch (InvocationTargetException x)
{
- throw new NoSuchAlgorithmException(algorithm);
+ cause = x.getCause();
+ if (cause instanceof NoSuchAlgorithmException)
+ throw (NoSuchAlgorithmException) cause;
+ if (cause == null)
+ cause = x;
}
- catch (ClassCastException cce)
+ catch (ClassCastException x)
{
- throw new NoSuchAlgorithmException(algorithm);
+ cause = x;
}
+ NoSuchAlgorithmException x = new NoSuchAlgorithmException(sb.toString());
+ x.initCause(cause);
+ throw x;
}
- // Instance methods.
- // -------------------------------------------------------------------
-
/**
* Returns the name of this key manager factory algorithm.
*
diff --git a/javax/net/ssl/SSLContext.java b/javax/net/ssl/SSLContext.java
index 3f284ab1a..dcc850809 100644
--- a/javax/net/ssl/SSLContext.java
+++ b/javax/net/ssl/SSLContext.java
@@ -91,102 +91,103 @@ public class SSLContext
this.protocol = protocol;
}
- // Class methods.
- // ------------------------------------------------------------------
-
/**
- * Get an instance of a context for the specified protocol from the
- * first provider that implements it.
- *
+ * Get an instance of a context for the specified protocol from the first
+ * provider that implements it.
+ *
* @param protocol The name of the protocol to get a context for.
* @return The new context.
- * @throws NoSuchAlgorithm If no provider implements the given
- * protocol.
+ * @throws NoSuchAlgorithmException If no provider implements the given
+ * protocol.
+ * @throws IllegalArgumentException if <code>protocol</code> is
+ * <code>null</code> or is an empty string.
*/
public static final SSLContext getInstance(String protocol)
- throws NoSuchAlgorithmException
+ throws NoSuchAlgorithmException
{
- Provider[] provs = Security.getProviders();
- for (int i = 0; i < provs.length; i++)
- {
- try
- {
- return getInstance(protocol, provs[i]);
- }
- catch (NoSuchAlgorithmException ignore)
- {
- }
- }
+ Provider[] p = Security.getProviders();
+ NoSuchAlgorithmException lastException = null;
+ for (int i = 0; i < p.length; i++)
+ try
+ {
+ return getInstance(protocol, p[i]);
+ }
+ catch (NoSuchAlgorithmException x)
+ {
+ lastException = x;
+ }
+ if (lastException != null)
+ throw lastException;
throw new NoSuchAlgorithmException(protocol);
}
/**
- * Get an instance of a context for the specified protocol from the
- * named provider.
- *
+ * Get an instance of a context for the specified protocol from the named
+ * provider.
+ *
* @param protocol The name of the protocol to get a context for.
- * @param provider The name of the provider to get the
- * implementation from.
+ * @param provider The name of the provider to get the implementation from.
* @return The new context.
- * @throws NoSuchAlgorithmException If the provider does not
- * implement the given protocol.
- * @throws NoSuchProviderException If the named provider does not
- * exist.
- * @throws IllegalArgumentException If <i>provider</i> is null.
+ * @throws NoSuchAlgorithmException If the provider does not implement the
+ * given protocol.
+ * @throws NoSuchProviderException If the named provider does not exist.
+ * @throws IllegalArgumentException if either <code>protocol</code> or
+ * <code>provider</code> is <code>null</code>, or if
+ * <code>protocol</code> is an empty string.
*/
- public static final SSLContext getInstance(String protocol,
- String provider)
- throws NoSuchAlgorithmException, NoSuchProviderException
+ public static final SSLContext getInstance(String protocol, String provider)
+ throws NoSuchAlgorithmException, NoSuchProviderException
{
if (provider == null)
- {
- throw new IllegalArgumentException("null provider");
- }
+ throw new IllegalArgumentException("provider MUST NOT be null");
Provider p = Security.getProvider(provider);
if (p == null)
- {
- throw new NoSuchProviderException(provider);
- }
+ throw new NoSuchProviderException(provider);
return getInstance(protocol, p);
}
/**
- * Get an instance of a context for the specified protocol from the
- * specified provider.
- *
+ * Get an instance of a context for the specified protocol from the specified
+ * provider.
+ *
* @param protocol The name of the protocol to get a context for.
- * @param provider The name of the provider to get the
- * implementation from.
+ * @param provider The name of the provider to get the implementation from.
* @return The new context.
- * @throws NoSuchAlgorithmException If the provider does not
- * implement the given protocol.
- * @throws IllegalArgumentException If <i>provider</i> is null.
+ * @throws NoSuchAlgorithmException If the provider does not implement the
+ * given protocol.
+ * @throws IllegalArgumentException if either <code>protocol</code> or
+ * <code>provider</code> is <code>null</code>, or if
+ * <code>protocol</code> is an empty string.
*/
- public static final SSLContext getInstance(String protocol,
- Provider provider)
- throws NoSuchAlgorithmException
+ public static final SSLContext getInstance(String protocol, Provider provider)
+ throws NoSuchAlgorithmException
{
+ StringBuilder sb = new StringBuilder("SSLContext for protocol [")
+ .append(protocol).append("] from provider[")
+ .append(provider).append("] could not be created");
+ Throwable cause;
try
{
- return new SSLContext((SSLContextSpi)
- Engine.getInstance(SSL_CONTEXT, protocol, provider),
- provider, protocol);
+ Object spi = Engine.getInstance(SSL_CONTEXT, protocol, provider);
+ return new SSLContext((SSLContextSpi) spi, provider, protocol);
}
- catch (InvocationTargetException ite)
+ catch (InvocationTargetException x)
{
- NoSuchAlgorithmException nsae = new NoSuchAlgorithmException(protocol);
- throw (NoSuchAlgorithmException) nsae.initCause(ite);
+ cause = x.getCause();
+ if (cause instanceof NoSuchAlgorithmException)
+ throw (NoSuchAlgorithmException) cause;
+ if (cause == null)
+ cause = x;
}
- catch (ClassCastException cce)
+ catch (ClassCastException x)
{
- NoSuchAlgorithmException nsae = new NoSuchAlgorithmException(protocol);
- throw (NoSuchAlgorithmException) nsae.initCause(cce);
+ cause = x;
}
+ NoSuchAlgorithmException x = new NoSuchAlgorithmException(sb.toString());
+ x.initCause(cause);
+ throw x;
}
- // Instance methods.
- // -----------------------------------------------------------------
-
/**
* Creates a new {@link SSLEngine} for this context.
*
diff --git a/javax/net/ssl/TrustManagerFactory.java b/javax/net/ssl/TrustManagerFactory.java
index 62ab1c2df..f868ae75b 100644
--- a/javax/net/ssl/TrustManagerFactory.java
+++ b/javax/net/ssl/TrustManagerFactory.java
@@ -93,96 +93,105 @@ public class TrustManagerFactory
this.algorithm = algorithm;
}
- // Class methods.
- // -------------------------------------------------------------------------
-
/**
- * Returns an instance of a trust manager factory for the given algorithm
- * from the first provider that implements it.
- *
+ * Returns an instance of a trust manager factory for the given algorithm from
+ * the first provider that implements it.
+ *
* @param algorithm The name of the algorithm to get.
* @return The instance of the trust manager factory.
* @throws NoSuchAlgorithmException If no provider implements the given
- * algorithm.
+ * algorithm.
+ * @throws IllegalArgumentException if <code>algorithm</code> is
+ * <code>null</code> or is an empty string.
*/
public static final TrustManagerFactory getInstance(String algorithm)
- throws NoSuchAlgorithmException
+ throws NoSuchAlgorithmException
{
- Provider[] provs = Security.getProviders();
- for (int i = 0; i < provs.length; i++)
- {
- try
- {
- return getInstance(algorithm, provs[i]);
- }
- catch (NoSuchAlgorithmException ignore)
- {
- }
- }
+ Provider[] p = Security.getProviders();
+ NoSuchAlgorithmException lastException = null;
+ for (int i = 0; i < p.length; i++)
+ try
+ {
+ return getInstance(algorithm, p[i]);
+ }
+ catch (NoSuchAlgorithmException x)
+ {
+ lastException = x;
+ }
+ if (lastException != null)
+ throw lastException;
throw new NoSuchAlgorithmException(algorithm);
}
/**
- * Returns an instance of a trust manager factory for the given algorithm
- * from the named provider.
- *
+ * Returns an instance of a trust manager factory for the given algorithm from
+ * the named provider.
+ *
* @param algorithm The name of the algorithm to get.
* @param provider The name of the provider to get the instance from.
* @return The instance of the trust manager factory.
* @throws NoSuchAlgorithmException If the provider does not implement the
- * given algorithm.
+ * given algorithm.
* @throws NoSuchProviderException If there is no such named provider.
- * @throws IllegalArgumentException If the provider argument is null.
+ * @throws IllegalArgumentException if either <code>algorithm</code> or
+ * <code>provider</code> is <code>null</code>, or if
+ * <code>algorithm</code> is an empty string.
*/
public static final TrustManagerFactory getInstance(String algorithm,
String provider)
throws NoSuchAlgorithmException, NoSuchProviderException
{
if (provider == null)
- {
- throw new IllegalArgumentException();
- }
+ throw new IllegalArgumentException("provider MUST NOT be null");
Provider p = Security.getProvider(provider);
if (p == null)
- {
- throw new NoSuchProviderException(provider);
- }
+ throw new NoSuchProviderException(provider);
return getInstance(algorithm, p);
}
/**
- * Returns an instance of a trust manager factory for the given algorithm
- * from the specified provider.
- *
+ * Returns an instance of a trust manager factory for the given algorithm from
+ * the specified provider.
+ *
* @param algorithm The name of the algorithm to get.
* @param provider The provider to get the instance from.
* @return The instance of the trust manager factory.
* @throws NoSuchAlgorithmException If the provider does not implement the
- * given algorithm.
- * @throws IllegalArgumentException If the provider argument is null.
+ * given algorithm.
+ * @throws IllegalArgumentException if either <code>algorithm</code> or
+ * <code>provider</code> is <code>null</code>, or if
+ * <code>algorithm</code> is an empty string.
*/
public static final TrustManagerFactory getInstance(String algorithm,
Provider provider)
- throws NoSuchAlgorithmException
+ throws NoSuchAlgorithmException
{
- if (provider == null)
- {
- throw new IllegalArgumentException();
- }
+ StringBuilder sb = new StringBuilder("TrustManagerFactory algorithm [")
+ .append(algorithm).append("] from provider[")
+ .append(provider).append("] could not be created");
+ Throwable cause;
try
{
- return new TrustManagerFactory((TrustManagerFactorySpi)
- Engine.getInstance(TRUST_MANAGER_FACTORY, algorithm, provider),
- provider, algorithm);
+ Object spi = Engine.getInstance(TRUST_MANAGER_FACTORY, algorithm, provider);
+ return new TrustManagerFactory((TrustManagerFactorySpi) spi,
+ provider,
+ algorithm);
}
- catch (InvocationTargetException ite)
+ catch (InvocationTargetException x)
{
- throw new NoSuchAlgorithmException(algorithm);
+ cause = x.getCause();
+ if (cause instanceof NoSuchAlgorithmException)
+ throw (NoSuchAlgorithmException) cause;
+ if (cause == null)
+ cause = x;
}
- catch (ClassCastException cce)
+ catch (ClassCastException x)
{
- throw new NoSuchAlgorithmException(algorithm);
+ cause = x;
}
+ NoSuchAlgorithmException x = new NoSuchAlgorithmException(sb.toString());
+ x.initCause(cause);
+ throw x;
}
/**