diff options
Diffstat (limited to 'x-net/src')
92 files changed, 1326 insertions, 2062 deletions
diff --git a/x-net/src/main/java/javax/net/DefaultServerSocketFactory.java b/x-net/src/main/java/javax/net/DefaultServerSocketFactory.java index 0b309df..9e31be4 100644 --- a/x-net/src/main/java/javax/net/DefaultServerSocketFactory.java +++ b/x-net/src/main/java/javax/net/DefaultServerSocketFactory.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Boris V. Kuznetsov -* @version $Revision$ -*/ - package javax.net; import java.io.IOException; @@ -27,24 +22,27 @@ import java.net.InetAddress; import java.net.ServerSocket; /** - * Default implementation of javax.net.ServerSocketFactory. - * - * @since Android 1.0 - * + * Default implementation of {@link javax.net.ServerSocketFactory} */ -class DefaultServerSocketFactory extends ServerSocketFactory { +final class DefaultServerSocketFactory extends ServerSocketFactory { + + DefaultServerSocketFactory() { + super(); + } + @Override public ServerSocket createServerSocket(int port) throws IOException { return new ServerSocket(port); } - public ServerSocket createServerSocket(int port, int backlog) - throws IOException { + @Override + public ServerSocket createServerSocket(int port, int backlog) throws IOException { return new ServerSocket(port, backlog); } - public ServerSocket createServerSocket(int port, int backlog, - InetAddress iAddress) throws IOException { + @Override + public ServerSocket createServerSocket(int port, int backlog, InetAddress iAddress) + throws IOException { return new ServerSocket(port, backlog, iAddress); } diff --git a/x-net/src/main/java/javax/net/DefaultSocketFactory.java b/x-net/src/main/java/javax/net/DefaultSocketFactory.java index 8aa82d9..010c720 100644 --- a/x-net/src/main/java/javax/net/DefaultSocketFactory.java +++ b/x-net/src/main/java/javax/net/DefaultSocketFactory.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Boris V. Kuznetsov -* @version $Revision$ -*/ - package javax.net; import java.io.IOException; @@ -28,32 +23,38 @@ import java.net.Socket; import java.net.UnknownHostException; /** - * Default implementation of javax.net.SocketFactory - * - * @since Android 1.0 + * Default implementation of {@link javax.net.SocketFactory} */ -class DefaultSocketFactory extends SocketFactory { +final class DefaultSocketFactory extends SocketFactory { + + DefaultSocketFactory() { + super(); + } + @Override public Socket createSocket() throws IOException { return new Socket(); } - public Socket createSocket(String host, int port) throws IOException, - UnknownHostException { + @Override + public Socket createSocket(String host, int port) throws IOException, UnknownHostException { return new Socket(host, port); } - public Socket createSocket(String host, int port, InetAddress localHost, - int localPort) throws IOException, UnknownHostException { + @Override + public Socket createSocket(String host, int port, InetAddress localHost, int localPort) + throws IOException, UnknownHostException { return new Socket(host, port, localHost, localPort); } + @Override public Socket createSocket(InetAddress host, int port) throws IOException { return new Socket(host, port); } - public Socket createSocket(InetAddress address, int port, - InetAddress localAddress, int localPort) throws IOException { + @Override + public Socket createSocket(InetAddress address, int port, InetAddress localAddress, + int localPort) throws IOException { return new Socket(address, port, localAddress, localPort); } } diff --git a/x-net/src/main/java/javax/net/ServerSocketFactory.java b/x-net/src/main/java/javax/net/ServerSocketFactory.java index 28a79f6..f2d2c0d 100644 --- a/x-net/src/main/java/javax/net/ServerSocketFactory.java +++ b/x-net/src/main/java/javax/net/ServerSocketFactory.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Boris V. Kuznetsov -* @version $Revision$ -*/ - package javax.net; import java.io.IOException; @@ -30,66 +25,59 @@ import java.net.SocketException; /** * This abstract class defines methods to create server sockets. It can be * subclassed to create specific server socket types. - * - * @since Android 1.0 */ public abstract class ServerSocketFactory { - static ServerSocketFactory defaultFactory; - - /** - * Creates a new {@code ServerSocketFactory} instance. - * - * @since Android 1.0 - */ - protected ServerSocketFactory() { - } + private static ServerSocketFactory defaultFactory; /** * Gets the default server socket factory of the system which can be used to * create new server sockets without creating a subclass of this factory. - * + * * @return the system default server socket factory. - * @since Android 1.0 */ public static synchronized ServerSocketFactory getDefault() { if (defaultFactory == null) { - defaultFactory = new DefaultServerSocketFactory(); + defaultFactory = new DefaultServerSocketFactory(); } return defaultFactory; } /** + * Creates a new {@code ServerSocketFactory} instance. + */ + protected ServerSocketFactory() { + super(); + } + + /** * Creates a new server socket which is not bound to any local address. This * method has to be overridden by a subclass otherwise a {@code * SocketException} is thrown. - * + * * @return the created unbound server socket. * @throws IOException * if an error occurs while creating a new server socket. - * @since Android 1.0 */ public ServerSocket createServerSocket() throws IOException { - // follow RI's behavior + // follow RI's behavior throw new SocketException("Unbound server sockets not implemented"); } /** * Creates a new server socket which is bound to the given port. - * + * * @param port * the port on which the created socket has to listen. * @return the created bound server socket. * @throws IOException * if an error occurs while creating a new server socket. - * @since Android 1.0 */ - public abstract ServerSocket createServerSocket(int port) - throws IOException; + public abstract ServerSocket createServerSocket(int port) throws IOException; /** * Creates a new server socket which is bound to the given port and * configures its maximum of queued connections. - * + * * @param port * the port on which the created socket has to listen. * @param backlog @@ -97,15 +85,13 @@ public abstract class ServerSocketFactory { * @return the created bound server socket. * @throws IOException * if an error occurs while creating a new server socket. - * @since Android 1.0 */ - public abstract ServerSocket createServerSocket(int port, int backlog) - throws IOException; + public abstract ServerSocket createServerSocket(int port, int backlog) throws IOException; /** * Creates a new server socket which is bound to the given address on the * specified port and configures its maximum of queued connections. - * + * * @param port * the port on which the created socket has to listen. * @param backlog @@ -116,9 +102,8 @@ public abstract class ServerSocketFactory { * @return the created bound server socket. * @throws IOException * if an error occurs while creating a new server socket. - * @since Android 1.0 */ - public abstract ServerSocket createServerSocket(int port, int backlog, - InetAddress iAddress) throws IOException; + public abstract ServerSocket createServerSocket(int port, int backlog, InetAddress iAddress) + throws IOException; -}
\ No newline at end of file +} diff --git a/x-net/src/main/java/javax/net/SocketFactory.java b/x-net/src/main/java/javax/net/SocketFactory.java index 6e5017e..eb0cfcb 100644 --- a/x-net/src/main/java/javax/net/SocketFactory.java +++ b/x-net/src/main/java/javax/net/SocketFactory.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Boris V. Kuznetsov -* @version $Revision$ -*/ - package javax.net; import java.io.IOException; @@ -31,27 +26,16 @@ import java.net.UnknownHostException; /** * This abstract class defines methods to create sockets. It can be subclassed * to create specific socket types with additional socket-level functionality. - * - * @since Android 1.0 */ public abstract class SocketFactory { - static SocketFactory defaultFactory; - - /** - * Creates a new {@code SocketFactory} instance. - * - * @since Android 1.0 - */ - protected SocketFactory() { - } + private static SocketFactory defaultFactory; /** * Gets the default socket factory of the system which can be used to create * new sockets without creating a subclass of this factory. - * + * * @return the system default socket factory. - * @since Android 1.0 */ public static synchronized SocketFactory getDefault() { if (defaultFactory == null) { @@ -61,17 +45,23 @@ public abstract class SocketFactory { } /** + * Creates a new {@code SocketFactory} instance. + */ + protected SocketFactory() { + super(); + } + + /** * Creates a new socket which is not connected to any remote host. This * method has to be overridden by a subclass otherwise a {@code * SocketException} is thrown. - * + * * @return the created unconnected socket. * @throws IOException * if an error occurs while creating a new socket. - * @since Android 1.0 */ public Socket createSocket() throws IOException { - // follow RI's behavior + // follow RI's behavior throw new SocketException("Unconnected sockets not implemented"); } @@ -79,7 +69,7 @@ public abstract class SocketFactory { * Creates a new socket which is connected to the remote host specified by * the parameters {@code host} and {@code port}. The socket is bound to any * available local address and port. - * + * * @param host * the remote host address the socket has to be connected to. * @param port @@ -91,17 +81,16 @@ public abstract class SocketFactory { * @throws UnknownHostException * if the specified host is unknown or the IP address could not * be resolved. - * @since Android 1.0 */ - public abstract Socket createSocket(String host, int port) - throws IOException, UnknownHostException; + public abstract Socket createSocket(String host, int port) throws IOException, + UnknownHostException; /** * Creates a new socket which is connected to the remote host specified by * the parameters {@code host} and {@code port}. The socket is bound to the * local network interface specified by the InetAddress {@code localHost} on * port {@code localPort}. - * + * * @param host * the remote host address the socket has to be connected to. * @param port @@ -118,17 +107,15 @@ public abstract class SocketFactory { * @throws UnknownHostException * if the specified host is unknown or the IP address could not * be resolved. - * @since Android 1.0 */ - public abstract Socket createSocket(String host, int port, - InetAddress localHost, int localPort) throws IOException, - UnknownHostException; + public abstract Socket createSocket(String host, int port, InetAddress localHost, int localPort) + throws IOException, UnknownHostException; /** * Creates a new socket which is connected to the remote host specified by * the InetAddress {@code host}. The socket is bound to any available local * address and port. - * + * * @param host * the host address the socket has to be connected to. * @param port @@ -137,17 +124,16 @@ public abstract class SocketFactory { * @return the created connected socket. * @throws IOException * if an error occurs while creating a new socket. - * @since Android 1.0 */ - public abstract Socket createSocket(InetAddress host, int port) - throws IOException; + public abstract Socket createSocket(InetAddress host, int port) throws IOException; + /** * Creates a new socket which is connected to the remote host specified by * the InetAddress {@code address}. The socket is bound to the local network * interface specified by the InetAddress {@code localHost} on port {@code * localPort}. - * + * * @param address * the remote host address the socket has to be connected to. * @param port @@ -161,8 +147,7 @@ public abstract class SocketFactory { * @return the created connected socket. * @throws IOException * if an error occurs while creating a new socket. - * @since Android 1.0 */ - public abstract Socket createSocket(InetAddress address, int port, - InetAddress localAddress, int localPort) throws IOException; + public abstract Socket createSocket(InetAddress address, int port, InetAddress localAddress, + int localPort) throws IOException; } diff --git a/x-net/src/main/java/javax/net/ssl/CertPathTrustManagerParameters.java b/x-net/src/main/java/javax/net/ssl/CertPathTrustManagerParameters.java index 5903663..dcf7a4d 100644 --- a/x-net/src/main/java/javax/net/ssl/CertPathTrustManagerParameters.java +++ b/x-net/src/main/java/javax/net/ssl/CertPathTrustManagerParameters.java @@ -22,11 +22,12 @@ import java.security.cert.CertPathParameters; /** * Certification path parameters to provide to certification path * based {@link TrustManager}. - * @since Android 1.0 + * + * @since 1.5 */ public class CertPathTrustManagerParameters implements ManagerFactoryParameters { - private CertPathParameters param; + private final CertPathParameters param; /** * Creates a new {@code CertPathTrustManagerParameters} with the specified @@ -34,7 +35,6 @@ public class CertPathTrustManagerParameters implements ManagerFactoryParameters * * @param parameters * the certification path parameters. - * @since Android 1.0 */ public CertPathTrustManagerParameters(CertPathParameters parameters) { param = (CertPathParameters) parameters.clone(); @@ -44,10 +44,9 @@ public class CertPathTrustManagerParameters implements ManagerFactoryParameters * Returns a copy of the certification path parameters. * * @return a copy of the certification path parameters. - * @since Android 1.0 */ public CertPathParameters getParameters() { return (CertPathParameters) param.clone(); } -}
\ No newline at end of file +} diff --git a/x-net/src/main/java/javax/net/ssl/ContextImpl.java b/x-net/src/main/java/javax/net/ssl/ContextImpl.java deleted file mode 100644 index 096cbba..0000000 --- a/x-net/src/main/java/javax/net/ssl/ContextImpl.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package javax.net.ssl; - -import java.security.Provider; - -/** - * Support class for this package. - * - * @since Android 1.0 - */ - -class ContextImpl extends SSLContext { - public ContextImpl(SSLContextSpi contextSpi, Provider provider, - String protocol) { - super(contextSpi, provider, protocol); - } -}
\ No newline at end of file diff --git a/x-net/src/main/java/javax/net/ssl/DefaultSSLContext.java b/x-net/src/main/java/javax/net/ssl/DefaultSSLContext.java index d2ab2f4..a12d385 100644 --- a/x-net/src/main/java/javax/net/ssl/DefaultSSLContext.java +++ b/x-net/src/main/java/javax/net/ssl/DefaultSSLContext.java @@ -19,28 +19,24 @@ package javax.net.ssl; import java.io.FileInputStream; import java.security.AccessController; +import java.security.KeyStore; +import java.security.PrivilegedAction; import java.security.Provider; import java.security.Security; -import java.security.KeyStore; -import java.util.Iterator; import org.apache.harmony.security.fortress.Engine; import org.apache.harmony.security.fortress.Services; - /** * Support class for this package. - * - * @since Android 1.0 */ - -class DefaultSSLContext { +final class DefaultSSLContext { private static SSLContext defaultSSLContext; - public static SSLContext getContext() { + static synchronized SSLContext getContext() { if (defaultSSLContext == null) { defaultSSLContext = AccessController - .doPrivileged(new java.security.PrivilegedAction<SSLContext>() { + .doPrivileged(new PrivilegedAction<SSLContext>() { public SSLContext run() { return findDefault(); } @@ -51,40 +47,37 @@ class DefaultSSLContext { private static SSLContext findDefault() { // FIXME EXPORT CONTROL - Provider.Service service; - for (Iterator it1 = Services.getProvidersList().iterator(); it1 - .hasNext();) { - service = Engine.door.getService((Provider) it1.next(), - "SSLContext"); + for (Provider provider : Services.getProvidersList()) { + final Provider.Service service = Engine.door.getService(provider, "SSLContext"); if (service != null) { try { - SSLContext con = new ContextImpl( - (SSLContextSpi) service.newInstance(null), - service.getProvider(), - service.getAlgorithm()); + SSLContext con = new SSLContext((SSLContextSpi) service.newInstance(null), + service.getProvider(), service.getAlgorithm()); - //TODO javax.net.ssl.keyStoreProvider, javax.net.ssl.trustStoreProvider system property + /* + * TODO + * javax.net.ssl.keyStoreProvider, + * javax.net.ssl.trustStoreProvider system property + */ + // find KeyStore, KeyManagers KeyManager[] keyManagers = null; - KeyStore ks = KeyStore.getInstance(KeyStore - .getDefaultType()); - String keystore = System - .getProperty("javax.net.ssl.keyStore"); - String keystorepwd = System - .getProperty("javax.net.ssl.keyStorePassword"); + KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); + String keystore = System.getProperty("javax.net.ssl.keyStore"); + String keystorepwd = System.getProperty("javax.net.ssl.keyStorePassword"); char[] pwd = null; if (keystorepwd != null) { pwd = keystorepwd.toCharArray(); } if (keystore != null) { - FileInputStream fis = new java.io.FileInputStream( - keystore); - ks.load(fis, pwd); - fis.close(); - + FileInputStream fis = new FileInputStream(keystore); + try { + ks.load(fis, pwd); + } finally { + fis.close(); + } KeyManagerFactory kmf; - String kmfAlg = Security - .getProperty("ssl.KeyManagerFactory.algorithm"); + String kmfAlg = Security.getProperty("ssl.KeyManagerFactory.algorithm"); if (kmfAlg == null) { kmfAlg = "SunX509"; } @@ -96,21 +89,21 @@ class DefaultSSLContext { // find TrustStore, TrustManagers TrustManager[] trustManagers = null; keystore = System.getProperty("javax.net.ssl.trustStore"); - keystorepwd = System - .getProperty("javax.net.ssl.trustStorePassword"); + keystorepwd = System.getProperty("javax.net.ssl.trustStorePassword"); pwd = null; if (keystorepwd != null) { pwd = keystorepwd.toCharArray(); } - //TODO Defaults: jssecacerts; cacerts + // TODO Defaults: jssecacerts; cacerts if (keystore != null) { - FileInputStream fis = new java.io.FileInputStream( - keystore); - ks.load(fis, pwd); - fis.close(); + FileInputStream fis = new FileInputStream(keystore); + try { + ks.load(fis, pwd); + } finally { + fis.close(); + } TrustManagerFactory tmf; - String tmfAlg = Security - .getProperty("ssl.TrustManagerFactory.algorithm"); + String tmfAlg = Security.getProperty("ssl.TrustManagerFactory.algorithm"); if (tmfAlg == null) { tmfAlg = "PKIX"; } @@ -122,7 +115,6 @@ class DefaultSSLContext { con.init(keyManagers, trustManagers, null); return con; } catch (Exception e) { - // e.printStackTrace(); // ignore and try another } } diff --git a/x-net/src/main/java/javax/net/ssl/DefaultSSLServerSocketFactory.java b/x-net/src/main/java/javax/net/ssl/DefaultSSLServerSocketFactory.java index c41f61a..6620841 100644 --- a/x-net/src/main/java/javax/net/ssl/DefaultSSLServerSocketFactory.java +++ b/x-net/src/main/java/javax/net/ssl/DefaultSSLServerSocketFactory.java @@ -29,33 +29,36 @@ import java.net.SocketException; */ class DefaultSSLServerSocketFactory extends SSLServerSocketFactory { - private String errMessage; - + private final String errMessage; + + DefaultSSLServerSocketFactory(String mes) { + errMessage = mes; + } + + @Override public String[] getDefaultCipherSuites() { return new String[0]; } + @Override public String[] getSupportedCipherSuites() { return new String[0]; } + @Override public ServerSocket createServerSocket(int port) throws IOException { throw new SocketException(errMessage); } - - public ServerSocket createServerSocket(int port, int backlog) - throws IOException { + @Override + public ServerSocket createServerSocket(int port, int backlog) throws IOException { throw new SocketException(errMessage); } - public ServerSocket createServerSocket(int port, int backlog, - InetAddress iAddress) throws IOException { + @Override + public ServerSocket createServerSocket(int port, int backlog, InetAddress iAddress) + throws IOException { throw new SocketException(errMessage); } - - DefaultSSLServerSocketFactory(String mes) { - errMessage = mes; - } } diff --git a/x-net/src/main/java/javax/net/ssl/DefaultSSLSocketFactory.java b/x-net/src/main/java/javax/net/ssl/DefaultSSLSocketFactory.java index fc4e340..4035a0e 100644 --- a/x-net/src/main/java/javax/net/ssl/DefaultSSLSocketFactory.java +++ b/x-net/src/main/java/javax/net/ssl/DefaultSSLSocketFactory.java @@ -26,61 +26,51 @@ import java.net.UnknownHostException; /** * Default inoperative implementation of javax.net.ssl.SSLSocketFactory * - * @since Android 1.0 */ class DefaultSSLSocketFactory extends SSLSocketFactory { - - private String errMessage; - + + private final String errMessage; + + DefaultSSLSocketFactory(String mes) { + errMessage = mes; + } + + @Override public String[] getDefaultCipherSuites() { return new String[0]; } + @Override public String[] getSupportedCipherSuites() { return new String[0]; } - /** - * @see javax.net.ssl.SSLSocketFactory#createSocket(java.net.Socket, java.lang.String, int, boolean) - */ - public Socket createSocket(Socket s, String host, int port, - boolean autoClose) throws IOException { + @Override + public Socket createSocket(Socket s, String host, int port, boolean autoClose) + throws IOException { throw new SocketException(errMessage); } - /** - * @see javax.net.SocketFactory#createSocket(java.lang.String, int) - */ - public Socket createSocket(String host, int port) throws IOException, - UnknownHostException { + @Override + public Socket createSocket(String host, int port) throws IOException, UnknownHostException { throw new SocketException(errMessage); } - /** - * @see javax.net.SocketFactory#createSocket(java.lang.String, int, java.net.InetAddress, int) - */ - public Socket createSocket(String host, int port, InetAddress localHost, - int localPort) throws IOException, UnknownHostException { + @Override + public Socket createSocket(String host, int port, InetAddress localHost, int localPort) + throws IOException, UnknownHostException { throw new SocketException(errMessage); } - /** - * @see javax.net.SocketFactory#createSocket(java.net.InetAddress, int) - */ + @Override public Socket createSocket(InetAddress host, int port) throws IOException { throw new SocketException(errMessage); } - /** - * @see javax.net.SocketFactory#createSocket(java.net.InetAddress, int, java.net.InetAddress, int) - */ - public Socket createSocket(InetAddress address, int port, - InetAddress localAddress, int localPort) throws IOException { + @Override + public Socket createSocket(InetAddress address, int port, InetAddress localAddress, + int localPort) throws IOException { throw new SocketException(errMessage); } - - DefaultSSLSocketFactory(String mes) { - errMessage = mes; - } } diff --git a/x-net/src/main/java/javax/net/ssl/HandshakeCompletedEvent.java b/x-net/src/main/java/javax/net/ssl/HandshakeCompletedEvent.java index 5ec5666..4618280 100644 --- a/x-net/src/main/java/javax/net/ssl/HandshakeCompletedEvent.java +++ b/x-net/src/main/java/javax/net/ssl/HandshakeCompletedEvent.java @@ -26,11 +26,8 @@ import java.util.EventObject; /** * The event object encapsulating the information about a completed SSL * handshake on a SSL connection. - * - * @since Android 1.0 */ -public class HandshakeCompletedEvent extends EventObject implements - Serializable { +public class HandshakeCompletedEvent extends EventObject implements Serializable { /** * The 5.0 spec. doesn't declare this serialVersionUID field In order to be @@ -43,12 +40,11 @@ public class HandshakeCompletedEvent extends EventObject implements /** * Creates a new {@code HandshakeCompletedEvent} with the specified SSL * socket and SSL session. - * + * * @param sock * the SSL socket. * @param s * the SSL session. - * @since Android 1.0 */ public HandshakeCompletedEvent(SSLSocket sock, SSLSession s) { super(sock); @@ -57,9 +53,8 @@ public class HandshakeCompletedEvent extends EventObject implements /** * Returns the SSL session associated with this event. - * + * * @return the SSL session associated with this event. - * @since Android 1.0 */ public SSLSession getSession() { return session; @@ -67,9 +62,8 @@ public class HandshakeCompletedEvent extends EventObject implements /** * Returns the name of the cipher suite negotiated during this handshake. - * + * * @return the name of the cipher suite negotiated during this handshake. - * @since Android 1.0 */ public String getCipherSuite() { return session.getCipherSuite(); @@ -78,11 +72,10 @@ public class HandshakeCompletedEvent extends EventObject implements /** * Returns the list of local certificates used during the handshake. These * certificates were sent to the peer. - * + * * @return Returns the list of certificates used during the handshake with * the local identity certificate followed by CAs, or {@code null} * if no certificates were used during the handshake. - * @since Android 1.0 */ public Certificate[] getLocalCertificates() { return session.getLocalCertificates(); @@ -91,15 +84,13 @@ public class HandshakeCompletedEvent extends EventObject implements /** * Return the list of certificates identifying the peer during the * handshake. - * + * * @return the list of certificates identifying the peer with the peer's * identity certificate followed by CAs. * @throws SSLPeerUnverifiedException * if the identity of the peer has not been verified. - * @since Android 1.0 */ - public Certificate[] getPeerCertificates() - throws SSLPeerUnverifiedException { + public Certificate[] getPeerCertificates() throws SSLPeerUnverifiedException { return session.getPeerCertificates(); } @@ -109,48 +100,42 @@ public class HandshakeCompletedEvent extends EventObject implements * certificates. * <p> * <b>Replaced by:</b> {@link #getPeerCertificates()} - * </p> - * + * * @return the list of certificates identifying the peer * @throws SSLPeerUnverifiedException * if the identity of the peer has not been verified. - * @since Android 1.0 */ - public X509Certificate[] getPeerCertificateChain() - throws SSLPeerUnverifiedException { + public X509Certificate[] getPeerCertificateChain() throws SSLPeerUnverifiedException { return session.getPeerCertificateChain(); } /** * Returns the {@code Principal} identifying the peer. - * + * * @return the {@code Principal} identifying the peer. * @throws SSLPeerUnverifiedException * if the identity of the peer has not been verified. - * @since Android 1.0 */ public Principal getPeerPrincipal() throws SSLPeerUnverifiedException { return session.getPeerPrincipal(); } - + /** * Returns the {@code Principal} used to identify during the handshake. - * + * * @return the {@code Principal} used to identify during the handshake. - * @since Android 1.0 */ public Principal getLocalPrincipal() { return session.getLocalPrincipal(); } - + /** * Returns the SSL socket that produced this event. - * + * * @return the SSL socket that produced this event. - * @since Android 1.0 */ public SSLSocket getSocket() { - return (SSLSocket)this.source; + return (SSLSocket) this.source; } -}
\ No newline at end of file +} diff --git a/x-net/src/main/java/javax/net/ssl/HandshakeCompletedListener.java b/x-net/src/main/java/javax/net/ssl/HandshakeCompletedListener.java index 9ffcbc1..5032c63 100644 --- a/x-net/src/main/java/javax/net/ssl/HandshakeCompletedListener.java +++ b/x-net/src/main/java/javax/net/ssl/HandshakeCompletedListener.java @@ -22,17 +22,13 @@ import java.util.EventListener; /** * The listener to be implemented to receive event notifications on completion * of SSL handshake on an SSL connection. - * - * @since Android 1.0 */ public interface HandshakeCompletedListener extends EventListener { - /** * The callback method that is invoked when a SSL handshake is completed. - * + * * @param event * the information on the completed SSL handshake event. - * @since Android 1.0 */ - public void handshakeCompleted(HandshakeCompletedEvent event); -}
\ No newline at end of file + void handshakeCompleted(HandshakeCompletedEvent event); +} diff --git a/x-net/src/main/java/javax/net/ssl/HostnameVerifier.java b/x-net/src/main/java/javax/net/ssl/HostnameVerifier.java index fe767ef..805762e 100644 --- a/x-net/src/main/java/javax/net/ssl/HostnameVerifier.java +++ b/x-net/src/main/java/javax/net/ssl/HostnameVerifier.java @@ -23,23 +23,18 @@ package javax.net.ssl; * This is an extended verification option that implementers can provide. It is to be used * during a handshake if the URL's hostname does not match the peer's * identification hostname. - * </p> - * - * @since Android 1.0 */ public interface HostnameVerifier { - /** * Verifies that the specified hostname is allowed within the specified SSL * session. - * + * * @param hostname * the hostname. * @param session * the SSL session of the connection. * @return {@code true} if the specified hostname is allowed, otherwise * {@code false}. - * @since Android 1.0 */ - public boolean verify(String hostname, SSLSession session); -}
\ No newline at end of file + boolean verify(String hostname, SSLSession session); +} diff --git a/x-net/src/main/java/javax/net/ssl/HttpsURLConnection.java b/x-net/src/main/java/javax/net/ssl/HttpsURLConnection.java index 0a95fb1..8c49690 100644 --- a/x-net/src/main/java/javax/net/ssl/HttpsURLConnection.java +++ b/x-net/src/main/java/javax/net/ssl/HttpsURLConnection.java @@ -26,8 +26,6 @@ import java.security.cert.X509Certificate; /** * This abstract subclass of {@code HttpURLConnection} defines methods for * managing HTTPS connections according to the description given by RFC 2818. - * - * @since Android 1.0 */ public abstract class HttpsURLConnection extends HttpURLConnection { @@ -37,140 +35,149 @@ public abstract class HttpsURLConnection extends HttpURLConnection { .getDefault(); /** + * Sets the default hostname verifier to be used by new instances. + * + * @param v + * the new default hostname verifier + * @throws IllegalArgumentException + * if the specified verifier is {@code null}. + */ + public static void setDefaultHostnameVerifier(HostnameVerifier v) { + if (v == null) { + throw new IllegalArgumentException("HostnameVerifier is null"); + } + defaultHostnameVerifier = v; + } + + /** + * Returns the default hostname verifier. + * + * @return the default hostname verifier. + */ + public static HostnameVerifier getDefaultHostnameVerifier() { + return defaultHostnameVerifier; + } + + /** + * Sets the default SSL socket factory to be used by new instances. + * + * @param sf + * the new default SSL socket factory. + * @throws IllegalArgumentException + * if the specified socket factory is {@code null}. + */ + public static void setDefaultSSLSocketFactory(SSLSocketFactory sf) { + if (sf == null) { + throw new IllegalArgumentException("SSLSocketFactory is null"); + } + defaultSSLSocketFactory = sf; + } + + /** + * Returns the default SSL socket factory for new instances. + * + * @return the default SSL socket factory for new instances. + */ + public static SSLSocketFactory getDefaultSSLSocketFactory() { + return defaultSSLSocketFactory; + } + + /** * The host name verifier used by this connection. It is initialized from * the default hostname verifier * {@link #setDefaultHostnameVerifier(HostnameVerifier)} or * {@link #getDefaultHostnameVerifier()}. - * - * @since Android 1.0 */ protected HostnameVerifier hostnameVerifier; - private static SSLSocketFactory socketFactory; + private SSLSocketFactory sslSocketFactory; /** * Creates a new {@code HttpsURLConnection} with the specified {@code URL}. - * + * * @param url * the {@code URL} to connect to. - * @since Android 1.0 */ protected HttpsURLConnection(URL url) { super(url); hostnameVerifier = defaultHostnameVerifier; - socketFactory = defaultSSLSocketFactory; + sslSocketFactory = defaultSSLSocketFactory; } /** * Returns the name of the cipher suite negotiated during the SSL handshake. - * + * * @return the name of the cipher suite negotiated during the SSL handshake. * @throws IllegalStateException * if no connection has been established yet. - * @since Android 1.0 */ public abstract String getCipherSuite(); /** * Returns the list of local certificates used during the handshake. These * certificates were sent to the peer. - * + * * @return Returns the list of certificates used during the handshake with * the local identity certificate followed by CAs, or {@code null} * if no certificates were used during the handshake. * @throws IllegalStateException * if no connection has been established yet. - * @since Android 1.0 - */ + */ public abstract Certificate[] getLocalCertificates(); /** * Return the list of certificates identifying the peer during the * handshake. - * + * * @return the list of certificates identifying the peer with the peer's * identity certificate followed by CAs. * @throws SSLPeerUnverifiedException * if the identity of the peer has not been verified.. * @throws IllegalStateException * if no connection has been established yet. - * @since Android 1.0 - */ - public abstract Certificate[] getServerCertificates() - throws SSLPeerUnverifiedException; + */ + public abstract Certificate[] getServerCertificates() throws SSLPeerUnverifiedException; /** * Returns the {@code Principal} identifying the peer. - * + * * @return the {@code Principal} identifying the peer. * @throws SSLPeerUnverifiedException * if the identity of the peer has not been verified. * @throws IllegalStateException * if no connection has been established yet. - * @since Android 1.0 */ public Principal getPeerPrincipal() throws SSLPeerUnverifiedException { Certificate[] certs = getServerCertificates(); - if (certs == null || certs.length == 0 || - (!(certs[0] instanceof X509Certificate))) { - throw new SSLPeerUnverifiedException( - "No server's end-entity certificate"); + if (certs == null || certs.length == 0 || (!(certs[0] instanceof X509Certificate))) { + throw new SSLPeerUnverifiedException("No server's end-entity certificate"); } return ((X509Certificate) certs[0]).getSubjectX500Principal(); } /** * Returns the {@code Principal} used to identify the local host during the handshake. - * + * * @return the {@code Principal} used to identify the local host during the handshake, or * {@code null} if none was used. * @throws IllegalStateException * if no connection has been established yet. - * @since Android 1.0 - */ + */ public Principal getLocalPrincipal() { Certificate[] certs = getLocalCertificates(); - if (certs == null || certs.length == 0 - || (!(certs[0] instanceof X509Certificate))) { + if (certs == null || certs.length == 0 || (!(certs[0] instanceof X509Certificate))) { return null; } return ((X509Certificate) certs[0]).getSubjectX500Principal(); } /** - * Sets the default hostname verifier to be used by new instances. - * - * @param v - * the new default hostname verifier - * @throws IllegalArgumentException - * if the specified verifier is {@code null}. - * @since Android 1.0 - */ - public static void setDefaultHostnameVerifier(HostnameVerifier v) { - if (v == null) { - throw new IllegalArgumentException("HostnameVerifier is null"); - } - defaultHostnameVerifier = v; - } - - /** - * Returns the default hostname verifier. - * - * @return the default hostname verifier. - * @since Android 1.0 - */ - public static HostnameVerifier getDefaultHostnameVerifier() { - return defaultHostnameVerifier; - } - - /** * Sets the hostname verifier for this instance. - * + * * @param v * the hostname verifier for this instance. * @throws IllegalArgumentException * if the specified verifier is {@code null}. - * @since Android 1.0 */ public void setHostnameVerifier(HostnameVerifier v) { if (v == null) { @@ -181,64 +188,35 @@ public abstract class HttpsURLConnection extends HttpURLConnection { /** * Returns the hostname verifier used by this instance. - * + * * @return the hostname verifier used by this instance. - * @since Android 1.0 */ public HostnameVerifier getHostnameVerifier() { return hostnameVerifier; } /** - * Sets the default SSL socket factory to be used by new instances. - * - * @param sf - * the new default SSL socket factory. - * @throws IllegalArgumentException - * if the specified socket factory is {@code null}. - * @since Android 1.0 - */ - public static void setDefaultSSLSocketFactory(SSLSocketFactory sf) { - if (sf == null) { - throw new IllegalArgumentException("SSLSocketFactory is null"); - } - defaultSSLSocketFactory = sf; - } - - /** - * Returns the default SSL socket factory for new instances. - * - * @return the default SSL socket factory for new instances. - * @since Android 1.0 - */ - public static SSLSocketFactory getDefaultSSLSocketFactory() { - return defaultSSLSocketFactory; - } - - /** * Sets the SSL socket factory for this instance. - * + * * @param sf * the SSL socket factory to be used by this instance. * @throws IllegalArgumentException * if the specified socket factory is {@code null}. - * @since Android 1.0 */ public void setSSLSocketFactory(SSLSocketFactory sf) { if (sf == null) { throw new IllegalArgumentException("SSLSocketFactory is null"); } - socketFactory = sf; + sslSocketFactory = sf; } /** * Returns the SSL socket factory used by this instance. - * + * * @return the SSL socket factory used by this instance. - * @since Android 1.0 */ public SSLSocketFactory getSSLSocketFactory() { - return socketFactory; + return sslSocketFactory; } } diff --git a/x-net/src/main/java/javax/net/ssl/KeyManager.java b/x-net/src/main/java/javax/net/ssl/KeyManager.java index 08939f7..30c8032 100644 --- a/x-net/src/main/java/javax/net/ssl/KeyManager.java +++ b/x-net/src/main/java/javax/net/ssl/KeyManager.java @@ -18,12 +18,10 @@ package javax.net.ssl; /** - * This is the interface to implement in order to mark a class as a JSSE key managers - * so that key managers can be easily grouped. - * The key managers are responsible for handling the keys used to - * authenticate the local side to its peer, - * - * @since Android 1.0 + * This is the interface to implement in order to mark a class as a JSSE key + * managers so that key managers can be easily grouped. The key managers are + * responsible for handling the keys used to authenticate the local side to its + * peer, */ public interface KeyManager { -}
\ No newline at end of file +} diff --git a/x-net/src/main/java/javax/net/ssl/KeyManagerFactory.java b/x-net/src/main/java/javax/net/ssl/KeyManagerFactory.java index a47d736..99a37a8 100644 --- a/x-net/src/main/java/javax/net/ssl/KeyManagerFactory.java +++ b/x-net/src/main/java/javax/net/ssl/KeyManagerFactory.java @@ -17,23 +17,21 @@ package javax.net.ssl; -import org.apache.harmony.security.fortress.Engine; - import java.security.AccessController; import java.security.InvalidAlgorithmParameterException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; +import java.security.PrivilegedAction; import java.security.Provider; import java.security.Security; import java.security.UnrecoverableKeyException; +import org.apache.harmony.security.fortress.Engine; /** * The public API for {@code KeyManagerFactory} implementations. - * - * @since Android 1.0 */ public class KeyManagerFactory { // Store KeyManagerFactory service name @@ -45,47 +43,26 @@ public class KeyManagerFactory { // Store default property name private static final String PROPERTY_NAME = "ssl.KeyManagerFactory.algorithm"; - // Store used provider - private final Provider provider; - - // Store used KeyManagerFactorySpi implementation - private final KeyManagerFactorySpi spiImpl; - - // Store used algorithm - private final String algorithm; - - /** - * Creates a new {@code KeyManagerFactory}. - * - * @param factorySpi - * the implementation delegate. - * @param provider - * the provider. - * @param algorithm - * the key management algorithm name. - * @since Android 1.0 - */ - protected KeyManagerFactory(KeyManagerFactorySpi factorySpi, - Provider provider, String algorithm) { - this.provider = provider; - this.algorithm = algorithm; - this.spiImpl = factorySpi; - } - /** - * Returns the name of the key management algorithm. - * - * @return the name of the key management algorithm. - * @since Android 1.0 + * Returns the default key manager factory algorithm name. + * <p> + * The default algorithm name is specified by the security property: + * {@code 'ssl.KeyManagerFactory.algorithm'}. + * + * @return the default algorithm name. */ - public final String getAlgorithm() { - return algorithm; + public static final String getDefaultAlgorithm() { + return AccessController.doPrivileged(new PrivilegedAction<String>() { + public String run() { + return Security.getProperty(PROPERTY_NAME); + } + }); } /** * Creates a new {@code KeyManagerFactory} instance for the specified key * management algorithm. - * + * * @param algorithm * the name of the requested key management algorithm. * @return a key manager factory for the requested algorithm. @@ -94,24 +71,23 @@ public class KeyManagerFactory { * @throws NullPointerException * if {@code algorithm} is {@code null} (instead of * NoSuchAlgorithmException as in 1.4 release) - * @since Android 1.0 */ public static final KeyManagerFactory getInstance(String algorithm) throws NoSuchAlgorithmException { if (algorithm == null) { - throw new NullPointerException("algorith is null"); + throw new NullPointerException("algorithm is null"); } synchronized (engine) { engine.getInstance(algorithm, null); - return new KeyManagerFactory((KeyManagerFactorySpi) engine.spi, - engine.provider, algorithm); + return new KeyManagerFactory((KeyManagerFactorySpi) engine.spi, engine.provider, + algorithm); } } /** * Creates a new {@code KeyManagerFactory} instance for the specified key * management algorithm from the specified provider. - * + * * @param algorithm * the name of the requested key management algorithm name. * @param provider @@ -126,11 +102,9 @@ public class KeyManagerFactory { * @throws NullPointerException * if {@code algorithm} is {@code null} (instead of * NoSuchAlgorithmException as in 1.4 release) - * @since Android 1.0 */ - 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) || (provider.length() == 0)) { throw new IllegalArgumentException("Provider is null or empty"); } @@ -144,7 +118,7 @@ public class KeyManagerFactory { /** * Creates a new {@code KeyManagerFactory} instance for the specified key * management algorithm from the specified provider. - * + * * @param algorithm * the name of the requested key management algorithm name. * @param provider @@ -156,28 +130,60 @@ public class KeyManagerFactory { * @throws NullPointerException * if {@code algorithm} is {@code null} (instead of * NoSuchAlgorithmException as in 1.4 release) - * @since Android 1.0 */ - 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"); } if (algorithm == null) { - throw new NullPointerException("algorith is null"); + throw new NullPointerException("algorithm is null"); } synchronized (engine) { engine.getInstance(algorithm, provider, null); - return new KeyManagerFactory((KeyManagerFactorySpi) engine.spi, - provider, algorithm); + return new KeyManagerFactory((KeyManagerFactorySpi) engine.spi, provider, algorithm); } } + // Store used provider + private final Provider provider; + + // Store used KeyManagerFactorySpi implementation + private final KeyManagerFactorySpi spiImpl; + + // Store used algorithm + private final String algorithm; + + /** + * Creates a new {@code KeyManagerFactory}. + * + * @param factorySpi + * the implementation delegate. + * @param provider + * the provider. + * @param algorithm + * the key management algorithm name. + */ + protected KeyManagerFactory(KeyManagerFactorySpi factorySpi, Provider provider, String algorithm) { + super(); + this.provider = provider; + this.algorithm = algorithm; + this.spiImpl = factorySpi; + } + + /** + * Returns the name of the key management algorithm. + * + * @return the name of the key management algorithm. + */ + public final String getAlgorithm() { + return algorithm; + } + /** * Returns the provider for this {@code KeyManagerFactory} instance. - * + * * @return the provider for this {@code KeyManagerFactory} instance. - * @since Android 1.0 */ public final Provider getProvider() { return provider; @@ -185,7 +191,7 @@ public class KeyManagerFactory { /** * Initializes this instance with the specified key store and password. - * + * * @param ks * the key store or {@code null} to use the default key store. * @param password @@ -197,55 +203,31 @@ public class KeyManagerFactory { * if a required algorithm is not available. * @throws UnrecoverableKeyException * if a key cannot be recovered. - * @since Android 1.0 */ - public final void init(KeyStore ks, char[] password) - throws KeyStoreException, NoSuchAlgorithmException, - UnrecoverableKeyException { + public final void init(KeyStore ks, char[] password) throws KeyStoreException, + NoSuchAlgorithmException, UnrecoverableKeyException { spiImpl.engineInit(ks, password); } /** * Initializes this instance with the specified factory parameters. - * + * * @param spec * the factory parameters. * @throws InvalidAlgorithmParameterException * if an error occurs. - * @since Android 1.0 */ - public final void init(ManagerFactoryParameters spec) - throws InvalidAlgorithmParameterException { + public final void init(ManagerFactoryParameters spec) throws InvalidAlgorithmParameterException { spiImpl.engineInit(spec); } /** * Returns a list of key managers, one instance for each type of key in the * key store. - * + * * @return a list of key managers. - * @since Android 1.0 */ public final KeyManager[] getKeyManagers() { return spiImpl.engineGetKeyManagers(); } - - /** - * Returns the default key manager factory algorithm name. - * <p> - * The default algorithm name is specified by the security property: - * {@code 'ssl.KeyManagerFactory.algorithm'}. - * </p> - * - * @return the default algorithm name. - * @since Android 1.0 - */ - public static final String getDefaultAlgorithm() { - return AccessController - .doPrivileged(new java.security.PrivilegedAction<String>() { - public String run() { - return Security.getProperty(PROPERTY_NAME); - } - }); - } -}
\ No newline at end of file +} diff --git a/x-net/src/main/java/javax/net/ssl/KeyManagerFactorySpi.java b/x-net/src/main/java/javax/net/ssl/KeyManagerFactorySpi.java index 7cdccf8..39925f9 100644 --- a/x-net/src/main/java/javax/net/ssl/KeyManagerFactorySpi.java +++ b/x-net/src/main/java/javax/net/ssl/KeyManagerFactorySpi.java @@ -26,23 +26,19 @@ import java.security.UnrecoverableKeyException; /** * The <i>Service Provider Interface</i> (SPI) for the * {@code KeyManagerFactory} class. - * - * @since Android 1.0 */ - public abstract class KeyManagerFactorySpi { - + /** * Creates a new {@code KeyManagerFactorySpi} instance. - * - * @since Android 1.0 */ public KeyManagerFactorySpi() { + super(); } /** * Initializes this instance with the specified key store and password. - * + * * @param ks * the key store or {@code null} to use the default key store. * @param password @@ -53,20 +49,17 @@ public abstract class KeyManagerFactorySpi { * if a required algorithm is not available. * @throws UnrecoverableKeyException * if a key cannot be recovered. - * @since Android 1.0 */ - protected abstract void engineInit(KeyStore ks, char[] password) - throws KeyStoreException, NoSuchAlgorithmException, - UnrecoverableKeyException; + protected abstract void engineInit(KeyStore ks, char[] password) throws KeyStoreException, + NoSuchAlgorithmException, UnrecoverableKeyException; /** * Initializes this instance with the specified factory parameters. - * + * * @param spec * the factory parameters. * @throws InvalidAlgorithmParameterException * if an error occurs. - * @since Android 1.0 */ protected abstract void engineInit(ManagerFactoryParameters spec) throws InvalidAlgorithmParameterException; @@ -74,9 +67,8 @@ public abstract class KeyManagerFactorySpi { /** * Returns a list of key managers, one instance for each type of key in the * key store. - * + * * @return a list of key managers. - * @since Android 1.0 */ protected abstract KeyManager[] engineGetKeyManagers(); -}
\ No newline at end of file +} diff --git a/x-net/src/main/java/javax/net/ssl/KeyStoreBuilderParameters.java b/x-net/src/main/java/javax/net/ssl/KeyStoreBuilderParameters.java index b000fd5..d30cc8a 100644 --- a/x-net/src/main/java/javax/net/ssl/KeyStoreBuilderParameters.java +++ b/x-net/src/main/java/javax/net/ssl/KeyStoreBuilderParameters.java @@ -25,12 +25,13 @@ import java.security.KeyStore; /** * The parameters for {@code KeyManager}s. The parameters are a list of * {@code KeyStore.Builder}s. - * - * @since Android 1.0 + * + * @since 1.5 + * @see KeyStore.Builder */ public class KeyStoreBuilderParameters implements ManagerFactoryParameters { - private List ksbuilders; + private final List<KeyStore.Builder> ksbuilders; /** * Creates a new {@code KeyStoreBuilderParameters} with the specified key @@ -38,13 +39,10 @@ public class KeyStoreBuilderParameters implements ManagerFactoryParameters { * * @param builder * the key store builder. - * @since Android 1.0 */ public KeyStoreBuilderParameters(KeyStore.Builder builder) { - ksbuilders = new ArrayList(); - if (builder != null) { - ksbuilders.add(builder); - } + super(); + ksbuilders = Collections.singletonList(builder); } /** @@ -55,16 +53,17 @@ public class KeyStoreBuilderParameters implements ManagerFactoryParameters { * the list of key store builders * @throws IllegalArgumentException * if the specified list is empty. - * @since Android 1.0 */ + @SuppressWarnings("unchecked") public KeyStoreBuilderParameters(List parameters) { + super(); if (parameters == null) { throw new NullPointerException("Builders list is null"); } if (parameters.isEmpty()) { throw new IllegalArgumentException("Builders list is empty"); } - ksbuilders = new ArrayList(parameters); + ksbuilders = Collections.unmodifiableList(new ArrayList<KeyStore.Builder>(parameters)); } /** @@ -72,9 +71,9 @@ public class KeyStoreBuilderParameters implements ManagerFactoryParameters { * with this parameters instance. * * @return the unmodifiable list of {@code KeyStore.Builder}s. - * @since Android 1.0 */ + @SuppressWarnings("unchecked") public List getParameters() { - return Collections.unmodifiableList(ksbuilders); + return ksbuilders; } } diff --git a/x-net/src/main/java/javax/net/ssl/ManagerFactoryParameters.java b/x-net/src/main/java/javax/net/ssl/ManagerFactoryParameters.java index 8909e62..b90deeb 100644 --- a/x-net/src/main/java/javax/net/ssl/ManagerFactoryParameters.java +++ b/x-net/src/main/java/javax/net/ssl/ManagerFactoryParameters.java @@ -20,8 +20,8 @@ package javax.net.ssl; /** * The marker interface for key manager factory parameters. Its purpose is to * group key manager factory parameters objects. - * - * @since Android 1.0 + * + * @since 1.4 */ public interface ManagerFactoryParameters { -}
\ No newline at end of file +} diff --git a/x-net/src/main/java/javax/net/ssl/SSLContext.java b/x-net/src/main/java/javax/net/ssl/SSLContext.java index 10d3a60..8a0a157 100644 --- a/x-net/src/main/java/javax/net/ssl/SSLContext.java +++ b/x-net/src/main/java/javax/net/ssl/SSLContext.java @@ -30,10 +30,7 @@ import org.apache.harmony.security.fortress.Engine; /** * The public API for secure socket protocol implementations. It acts as factory * for {@code SSLSocketFactory}'s and {@code SSLEngine}s. - * - * @since Android 1.0 */ - public class SSLContext { // StoreSSLContext service name private static final String SERVICE = "SSLContext"; @@ -41,36 +38,9 @@ public class SSLContext { // Used to access common engine functionality private static Engine engine = new Engine(SERVICE); - // Storeused provider - private final Provider provider; - - // Storeused SSLContextSpi implementation - private final SSLContextSpi spiImpl; - - // Storeused protocol - private final String protocol; - - /** - * Creates a new {@code SSLContext}. - * - * @param contextSpi - * the implementation delegate. - * @param provider - * the provider. - * @param protocol - * the protocol name. - * @since Android 1.0 - */ - protected SSLContext(SSLContextSpi contextSpi, Provider provider, - String protocol) { - this.provider = provider; - this.protocol = protocol; - this.spiImpl = contextSpi; - } - /** * Creates a new {@code SSLContext} instance for the specified protocol. - * + * * @param protocol * the requested protocol to create a context for. * @return the created {@code SSLContext} instance. @@ -79,24 +49,21 @@ public class SSLContext { * @throws NullPointerException * if {@code protocol} is {@code null} (instead of * NoSuchAlgorithmException as in 1.4 release) - * @since Android 1.0 */ - public static SSLContext getInstance(String protocol) - throws NoSuchAlgorithmException { + public static SSLContext getInstance(String protocol) throws NoSuchAlgorithmException { if (protocol == null) { throw new NullPointerException("protocol is null"); } synchronized (engine) { engine.getInstance(protocol, null); - return new SSLContext((SSLContextSpi) engine.spi, engine.provider, - protocol); + return new SSLContext((SSLContextSpi) engine.spi, engine.provider, protocol); } } /** * Creates a new {@code SSLContext} instance for the specified protocol from * the specified provider. - * + * * @param protocol * the requested protocol to create a context for. * @param provider @@ -110,7 +77,6 @@ public class SSLContext { * @throws NullPointerException * if {@code protocol} is {@code null} (instead of * NoSuchAlgorithmException as in 1.4 release) - * @since Android 1.0 */ public static SSLContext getInstance(String protocol, String provider) throws NoSuchAlgorithmException, NoSuchProviderException { @@ -130,7 +96,7 @@ public class SSLContext { /** * Creates a new {@code SSLContext} instance for the specified protocol from * the specified provider. - * + * * @param protocol * the requested protocol to create a context for * @param provider @@ -142,7 +108,6 @@ public class SSLContext { * @throws NullPointerException * if {@code protocol} is {@code null} (instead of * NoSuchAlgorithmException as in 1.4 release) - * @since Android 1.0 */ public static SSLContext getInstance(String protocol, Provider provider) throws NoSuchAlgorithmException { @@ -158,11 +123,32 @@ public class SSLContext { } } + private final Provider provider; + + private final SSLContextSpi spiImpl; + + private final String protocol; + + /** + * Creates a new {@code SSLContext}. + * + * @param contextSpi + * the implementation delegate. + * @param provider + * the provider. + * @param protocol + * the protocol name. + */ + protected SSLContext(SSLContextSpi contextSpi, Provider provider, String protocol) { + this.provider = provider; + this.protocol = protocol; + this.spiImpl = contextSpi; + } + /** * Returns the name of the secure socket protocol of this instance. - * + * * @return the name of the secure socket protocol of this instance. - * @since Android 1.0 */ public final String getProtocol() { return protocol; @@ -170,9 +156,8 @@ public class SSLContext { /** * Returns the provider of this {@code SSLContext} instance. - * + * * @return the provider of this {@code SSLContext} instance. - * @since Android 1.0 */ public final Provider getProvider() { return provider; @@ -182,7 +167,7 @@ public class SSLContext { * Initializes this {@code SSLContext} instance. All of the arguments are * optional, and the security providers will be searched for the required * implementations of the needed algorithms. - * + * * @param km * the key sources or {@code null}. * @param tm @@ -191,7 +176,6 @@ public class SSLContext { * the randomness source or {@code null.} * @throws KeyManagementException * if initializing this instance fails. - * @since Android 1.0 */ public final void init(KeyManager[] km, TrustManager[] tm, SecureRandom sr) throws KeyManagementException { @@ -200,9 +184,8 @@ public class SSLContext { /** * Returns a socket factory for this instance. - * + * * @return a socket factory for this instance. - * @since Android 1.0 */ public final SSLSocketFactory getSocketFactory() { return spiImpl.engineGetSocketFactory(); @@ -210,9 +193,8 @@ public class SSLContext { /** * Returns a server socket factory for this instance. - * + * * @return a server socket factory for this instance. - * @since Android 1.0 */ public final SSLServerSocketFactory getServerSocketFactory() { return spiImpl.engineGetServerSocketFactory(); @@ -220,11 +202,10 @@ public class SSLContext { /** * Creates an {@code SSLEngine} instance from this context. - * + * * @return an {@code SSLEngine} instance from this context. * @throws UnsupportedOperationException * if the provider does not support the operation. - * @since Android 1.0 */ public final SSLEngine createSSLEngine() { return spiImpl.engineCreateSSLEngine(); @@ -233,7 +214,7 @@ public class SSLContext { /** * Creates an {@code SSLEngine} instance from this context with the * specified hostname and port. - * + * * @param peerHost * the name of the host * @param peerPort @@ -241,7 +222,6 @@ public class SSLContext { * @return an {@code SSLEngine} instance from this context. * @throws UnsupportedOperationException * if the provider does not support the operation. - * @since Android 1.0 */ public final SSLEngine createSSLEngine(String peerHost, int peerPort) { return spiImpl.engineCreateSSLEngine(peerHost, peerPort); @@ -250,11 +230,10 @@ public class SSLContext { /** * Returns the SSL session context that encapsulates the set of SSL sessions * that can be used for handshake of server-side SSL sockets. - * + * * @return the SSL server session context for this context or {@code null} * if the underlying provider does not provide an implementation of * the {@code SSLSessionContext} interface. - * @since Android 1.0 */ public final SSLSessionContext getServerSessionContext() { return spiImpl.engineGetServerSessionContext(); @@ -263,13 +242,12 @@ public class SSLContext { /** * Returns the SSL session context that encapsulates the set of SSL sessions * that can be used for handshake of client-side SSL sockets. - * + * * @return the SSL client session context for this context or {@code null} * if the underlying provider does not provide an implementation of * the {@code SSLSessionContext} interface. - * @since Android 1.0 */ public final SSLSessionContext getClientSessionContext() { return spiImpl.engineGetClientSessionContext(); } -}
\ No newline at end of file +} diff --git a/x-net/src/main/java/javax/net/ssl/SSLContextSpi.java b/x-net/src/main/java/javax/net/ssl/SSLContextSpi.java index 6b2a60e..44d2c59 100644 --- a/x-net/src/main/java/javax/net/ssl/SSLContextSpi.java +++ b/x-net/src/main/java/javax/net/ssl/SSLContextSpi.java @@ -20,28 +20,23 @@ package javax.net.ssl; import java.security.KeyManagementException; import java.security.SecureRandom; - /** * The <i>Service Provider Interface</i> (SPI) for the {@code SSLContext} class. - * - * @since Android 1.0 */ - public abstract class SSLContextSpi { /** * Creates a new {@code SSLContextSpi} instance. - * - * @since Android 1.0 */ public SSLContextSpi() { + super(); } /** * Initializes this {@code SSLContext} instance. All of the arguments are * optional, and the security providers will be searched for the required * implementations of the needed algorithms. - * + * * @param km * the key sources or {@code null}. * @param tm @@ -50,31 +45,28 @@ public abstract class SSLContextSpi { * the randomness source or {@code null.} * @throws KeyManagementException * if initializing this instance fails. - * @since Android 1.0 - */ - protected abstract void engineInit(KeyManager[] km, TrustManager[] tm, - SecureRandom sr) throws KeyManagementException; + */ + protected abstract void engineInit(KeyManager[] km, TrustManager[] tm, SecureRandom sr) + throws KeyManagementException; /** * Returns a socket factory for this instance. - * + * * @return a socket factory for this instance. - * @since Android 1.0 */ protected abstract SSLSocketFactory engineGetSocketFactory(); /** * Returns a server socket factory for this instance. - * + * * @return a server socket factory for this instance. - * @since Android 1.0 */ protected abstract SSLServerSocketFactory engineGetServerSocketFactory(); /** * Creates an {@code SSLEngine} instance from this context with the * specified hostname and port. - * + * * @param host * the name of the host * @param port @@ -82,40 +74,36 @@ public abstract class SSLContextSpi { * @return an {@code SSLEngine} instance from this context. * @throws UnsupportedOperationException * if the provider does not support the operation. - * @since Android 1.0 */ protected abstract SSLEngine engineCreateSSLEngine(String host, int port); /** * Creates an {@code SSLEngine} instance from this context. - * + * * @return an {@code SSLEngine} instance from this context. * @throws UnsupportedOperationException * if the provider does not support the operation. - * @since Android 1.0 */ protected abstract SSLEngine engineCreateSSLEngine(); /** * Returns the SSL session context that encapsulates the set of SSL sessions * that can be used for the server side of the SSL handshake. - * + * * @return the SSL server session context for this context or {@code null} * if the underlying provider does not provide an implementation of * the {@code SSLSessionContext} interface. - * @since Android 1.0 */ protected abstract SSLSessionContext engineGetServerSessionContext(); /** * Returns the SSL session context that encapsulates the set of SSL sessions * that can be used for the client side of the SSL handshake. - * + * * @return the SSL client session context for this context or {@code null} * if the underlying provider does not provide an implementation of * the {@code SSLSessionContext} interface. - * @since Android 1.0 */ protected abstract SSLSessionContext engineGetClientSessionContext(); -}
\ No newline at end of file +} diff --git a/x-net/src/main/java/javax/net/ssl/SSLEngine.java b/x-net/src/main/java/javax/net/ssl/SSLEngine.java index be5d266..46e11a4 100644 --- a/x-net/src/main/java/javax/net/ssl/SSLEngine.java +++ b/x-net/src/main/java/javax/net/ssl/SSLEngine.java @@ -15,48 +15,62 @@ * limitations under the License. */ - package javax.net.ssl; +package javax.net.ssl; import java.nio.ByteBuffer; -import java.nio.ReadOnlyBufferException; /** * The abstract implementation of secure communications using SSL, TLS, or other - * protocols. It includes the setup, handshake, and encrypt/decrypt functionality - * needed to create a secure connection. - * - * @since Android 1.0 + * protocols. It includes the setup, handshake, and encrypt/decrypt + * functionality needed to create a secure connection. + * + * @since 1.5 */ public abstract class SSLEngine { - // Store host value - private final String host; - - // Store port value - private final int port; + private final String peerHost; + private final int peerPort; /** * Creates a new {@code SSLEngine} instance. - * - * @since Android 1.0 */ protected SSLEngine() { - host = null; - port = -1; + super(); + peerHost = null; + peerPort = -1; } /** * Creates a new {@code SSLEngine} instance with the specified host and * port. - * + * * @param host * the name of the host. * @param port * the port of the host. - * @since Android 1.0 */ protected SSLEngine(String host, int port) { - this.host = host; - this.port = port; + super(); + this.peerHost = host; + this.peerPort = port; + } + + /** + * Returns the name of the peer host. + * + * @return the name of the peer host, or {@code null} if none is available. + */ + public String getPeerHost() { + return peerHost; + } + + /** + * Returns the port number of the peer host. + * + * @return the port number of the peer host, or {@code -1} is none is + * available. + */ + public int getPeerPort() { + return peerPort; } /** @@ -65,33 +79,28 @@ public abstract class SSLEngine { * Calling this method is not needed for the initial handshake: it will be * called by {@code wrap} or {@code unwrap} if the initial handshake has not * been started yet. - * </p> - * + * * @throws SSLException * if starting the handshake fails. * @throws IllegalStateException * if the engine does not have all the needed settings (e.g. * client/server mode not set). - * @since Android 1.0 */ public abstract void beginHandshake() throws SSLException; /** * Notifies this engine instance that no more inbound network data will be * sent to this engine. - * + * * @throws SSLException * if this engine did not receive a needed protocol specific * close notification message from the peer. - * @since Android 1.0 */ public abstract void closeInbound() throws SSLException; /** * Notifies this engine instance that no more outbound application data will * be sent to this engine. - * - * @since Android 1.0 */ public abstract void closeOutbound(); @@ -102,84 +111,56 @@ public abstract class SSLEngine { * that a delegated task result is needed. In this case the * {@link Runnable#run() run} method of the returned {@code Runnable} * delegated task must be called. - * + * * @return a delegate task, or {@code null} if none are available. - * @since Android 1.0 */ public abstract Runnable getDelegatedTask(); /** * Returns the SSL cipher suite names that are enabled in this engine * instance. - * + * * @return the SSL cipher suite names that are enabled in this engine * instance. - * @since Android 1.0 */ public abstract String[] getEnabledCipherSuites(); /** * Returns the protocol version names that are enabled in this engine * instance. - * + * * @return the protocol version names that are enabled in this engine * instance. - * @since Android 1.0 */ public abstract String[] getEnabledProtocols(); /** * Returns whether new SSL sessions may be established by this engine. - * + * * @return {@code true} if new session may be established, {@code false} if * existing sessions must be reused. - * @since Android 1.0 */ public abstract boolean getEnableSessionCreation(); /** * Returns the status of the handshake of this engine instance. - * + * * @return the status of the handshake of this engine instance. - * @since Android 1.0 */ public abstract SSLEngineResult.HandshakeStatus getHandshakeStatus(); /** * Returns whether this engine instance will require client authentication. - * + * * @return {@code true} if this engine will require client authentication, * {@code false} if no client authentication is needed. - * @since Android 1.0 */ public abstract boolean getNeedClientAuth(); /** - * Returns the name of the peer host. - * - * @return the name of the peer host, or {@code null} if none is available. - * @since Android 1.0 - */ - public String getPeerHost() { - return host; - } - - /** - * Returns the port number of the peer host. - * - * @return the port number of the peer host, or {@code -1} is none is - * available. - * @since Android 1.0 - */ - public int getPeerPort() { - return port; - } - - /** * Returns the SSL session for this engine instance. - * + * * @return the SSL session for this engine instance. - * @since Android 1.0 */ public abstract SSLSession getSession(); @@ -187,55 +168,49 @@ public abstract class SSLEngine { * Returns the SSL cipher suite names that are supported by this engine. * These cipher suites can be enabled using * {@link #setEnabledCipherSuites(String[])}. - * + * * @return the SSL cipher suite names that are supported by this engine. - * @since Android 1.0 */ public abstract String[] getSupportedCipherSuites(); /** * Returns the protocol names that are supported by this engine. These * protocols can be enables using {@link #setEnabledProtocols(String[])}. - * + * * @return the protocol names that are supported by this engine. - * @since Android 1.0 */ public abstract String[] getSupportedProtocols(); /** * Returns whether this engine is set to act in client mode when * handshaking. - * + * * @return {@code true} if the engine is set to do handshaking in client * mode. - * @since Android 1.0 */ public abstract boolean getUseClientMode(); /** * Returns whether this engine will request client authentication. - * + * * @return {@code true} if client authentication will be requested, * {@code false} otherwise. - * @since Android 1.0 */ public abstract boolean getWantClientAuth(); /** * Returns whether no more inbound data will be accepted by this engine. - * + * * @return {@code true} if no more inbound data will be accepted by this * engine, {@code false} otherwise. - * @since Android 1.0 */ public abstract boolean isInboundDone(); /** * Returns whether no more outbound data will be produced by this engine. - * + * * @return {@code true} if no more outbound data will be producted by this * engine, {@code otherwise} false. - * @since Android 1.0 */ public abstract boolean isOutboundDone(); @@ -243,13 +218,12 @@ public abstract class SSLEngine { * Sets the SSL cipher suite names that should be enabled in this engine * instance. Only cipher suites listed by {@code getSupportedCipherSuites()} * are allowed. - * + * * @param suites * the SSL cipher suite names to be enabled. * @throws IllegalArgumentException * if one of the specified cipher suites is not supported, or if * {@code suites} is {@code null}. - * @since Android 1.0 */ public abstract void setEnabledCipherSuites(String[] suites); @@ -257,23 +231,21 @@ public abstract class SSLEngine { * Sets the protocol version names that should be enabled in this engine * instance. Only protocols listed by {@code getSupportedProtocols()} are * allowed. - * + * * @param protocols * the protocol version names to be enabled. * @throws IllegalArgumentException * if one of the protocol version names is not supported, or if * {@code protocols} is {@code null}. - * @since Android 1.0 */ public abstract void setEnabledProtocols(String[] protocols); /** * Sets whether new SSL sessions may be established by this engine instance. - * + * * @param flag * {@code true} if new SSL sessions may be established, * {@code false} if existing SSL sessions must be reused. - * @since Android 1.0 */ public abstract void setEnableSessionCreation(boolean flag); @@ -286,25 +258,23 @@ public abstract class SSLEngine { * <li>no authentication needed</li> * </ul> * This method overrides the setting of {@link #setWantClientAuth(boolean)}. - * + * * @param need * {@code true} if client authentication is required, * {@code false} if no authentication is needed. - * @since Android 1.0 */ public abstract void setNeedClientAuth(boolean need); /** * Sets whether this engine should act in client (or server) mode when * handshaking. - * + * * @param mode * {@code true} if this engine should act in client mode, * {@code false} if not. * @throws IllegalArgumentException * if this method is called after starting the initial * handshake. - * @since Android 1.0 */ public abstract void setUseClientMode(boolean mode); @@ -317,11 +287,10 @@ public abstract class SSLEngine { * <li>no authentication needed</li> * </ul> * This method overrides the setting of {@link #setNeedClientAuth(boolean)}. - * + * * @param want * {@code true} if client authentication should be requested, * {@code false} if no authentication is needed. - * @since Android 1.0 */ public abstract void setWantClientAuth(boolean want); @@ -329,7 +298,7 @@ public abstract class SSLEngine { * Decodes the incoming network data buffer into application data buffers. * If a handshake has not been started yet, it will automatically be * started. - * + * * @param src * the buffer with incoming network data * @param dsts @@ -339,14 +308,14 @@ public abstract class SSLEngine { * the offset in the array of destination buffers to which data * is to be transferred. * @param length - * the maximum number of destination buffers to be used. + * the maximum number of destination buffers to be used. * @return the result object of this operation. * @throws SSLException * if a problem occurred while processing the data. * @throws IndexOutOfBoundsException * if {@code length} is greater than * {@code dsts.length - offset}. - * @throws ReadOnlyBufferException + * @throws java.nio.ReadOnlyBufferException * if one of the destination buffers is read-only. * @throws IllegalArgumentException * if {@code src}, {@code dsts}, or one of the entries in @@ -354,16 +323,15 @@ public abstract class SSLEngine { * @throws IllegalStateException * if the engine does not have all the needed settings (e.g. * client/server mode not set). - * @since Android 1.0 */ - public abstract SSLEngineResult unwrap(ByteBuffer src, ByteBuffer[] dsts, - int offset, int length) throws SSLException; + public abstract SSLEngineResult unwrap(ByteBuffer src, ByteBuffer[] dsts, int offset, int length) + throws SSLException; /** * Encodes the outgoing application data buffers into the network data * buffer. If a handshake has not been started yet, it will automatically be * started. - * + * * @param srcs * the array of source buffers of outgoing application data. * @param offset @@ -379,7 +347,7 @@ public abstract class SSLEngine { * @throws IndexOutOfBoundsException * if {@code length} is greater than * {@code srcs.length - offset}. - * @throws ReadOnlyBufferException + * @throws java.nio.ReadOnlyBufferException * if the destination buffer is readonly. * @throws IllegalArgumentException * if {@code srcs}, {@code dst}, or one the entries in @@ -387,10 +355,9 @@ public abstract class SSLEngine { * @throws IllegalStateException * if the engine does not have all the needed settings (e.g. * client/server mode not set). - * @since Android 1.0 */ - public abstract SSLEngineResult wrap(ByteBuffer[] srcs, int offset, - int length, ByteBuffer dst) throws SSLException; + public abstract SSLEngineResult wrap(ByteBuffer[] srcs, int offset, int length, ByteBuffer dst) + throws SSLException; /** * Decodes the incoming network data buffer into the application data @@ -404,26 +371,15 @@ public abstract class SSLEngine { * @return the result object of this operation. * @throws SSLException * if a problem occurred while processing the data. - * @throws ReadOnlyBufferException + * @throws java.nio.ReadOnlyBufferException * if one of the destination buffers is read-only. * @throws IllegalArgumentException * if {@code src} or {@code dst} is {@code null}. * @throws IllegalStateException * if the engine does not have all the needed settings (e.g. * client/server mode not set). - * @since Android 1.0 - */ - public SSLEngineResult unwrap(ByteBuffer src, ByteBuffer dst) - throws SSLException { -// if (src == null) { -// throw new IllegalArgumentException("Byte buffer src is null"); -// } -// if (dst == null) { -// throw new IllegalArgumentException("Byte buffer dst is null"); -// } -// if (dst.isReadOnly()) { -// throw new ReadOnlyBufferException(); -// } + */ + public SSLEngineResult unwrap(ByteBuffer src, ByteBuffer dst) throws SSLException { return unwrap(src, new ByteBuffer[] { dst }, 0, 1); } @@ -431,7 +387,7 @@ public abstract class SSLEngine { * Decodes the incoming network data buffer into the application data * buffers. If a handshake has not been started yet, it will automatically * be started. - * + * * @param src * the buffer with incoming network data * @param dsts @@ -440,32 +396,18 @@ public abstract class SSLEngine { * @return the result object of this operation. * @throws SSLException * if a problem occurred while processing the data. - * @throws ReadOnlyBufferException + * @throws java.nio.ReadOnlyBufferException * if one of the destination buffers is read-only. * @throws IllegalArgumentException * if {@code src} or {@code dsts} is {@code null}. * @throws IllegalStateException * if the engine does not have all the needed settings (e.g. * client/server mode not set). - * @since Android 1.0 */ - public SSLEngineResult unwrap(ByteBuffer src, ByteBuffer[] dsts) - throws SSLException { -// if (src == null) { -// throw new IllegalArgumentException("Byte buffer src is null"); -// } + public SSLEngineResult unwrap(ByteBuffer src, ByteBuffer[] dsts) throws SSLException { if (dsts == null) { throw new IllegalArgumentException("Byte buffer array dsts is null"); } -// for (int i = 0; i < dsts.length; i++) { -// if (dsts[i] == null) { -// throw new IllegalArgumentException("Byte buffer dsts[" + i -// + "] is null"); -// } -// if (dsts[i].isReadOnly()) { -// throw new ReadOnlyBufferException(); -// } -// } return unwrap(src, dsts, 0, dsts.length); } @@ -481,32 +423,18 @@ public abstract class SSLEngine { * @return the result object of this operation. * @throws SSLException * if a problem occurred while processing the data. - * @throws ReadOnlyBufferException + * @throws java.nio.ReadOnlyBufferException * if the destination buffer is readonly. * @throws IllegalArgumentException * if {@code srcs} or {@code dst} is {@code null}. * @throws IllegalStateException * if the engine does not have all the needed settings (e.g. * client/server mode not set). - * @since Android 1.0 */ - public SSLEngineResult wrap(ByteBuffer[] srcs, ByteBuffer dst) - throws SSLException { + public SSLEngineResult wrap(ByteBuffer[] srcs, ByteBuffer dst) throws SSLException { if (srcs == null) { throw new IllegalArgumentException("Byte buffer array srcs is null"); } -// for (int i = 0; i < srcs.length; i++) { -// if (srcs[i] == null) { -// throw new IllegalArgumentException("Byte buffer srcs[" + i -// + "] is null"); -// } -// } -// if (dst == null) { -// throw new IllegalArgumentException("Byte buffer array dst is null"); -// } -// if (dst.isReadOnly()) { -// throw new ReadOnlyBufferException(); -// } return wrap(srcs, 0, srcs.length, dst); } @@ -522,26 +450,15 @@ public abstract class SSLEngine { * @return the result object of this operation. * @throws SSLException * if a problem occurred while processing the data. - * @throws ReadOnlyBufferException + * @throws java.nio.ReadOnlyBufferException * if the destination buffer is readonly. * @throws IllegalArgumentException * if {@code src} or {@code dst} is {@code null}. * @throws IllegalStateException * if the engine does not have all the needed settings (e.g. * client/server mode not set). - * @since Android 1.0 - */ - public SSLEngineResult wrap(ByteBuffer src, ByteBuffer dst) - throws SSLException { -// if (src == null) { -// throw new IllegalArgumentException("Byte buffer src is null"); -// } -// if (dst == null) { -// throw new IllegalArgumentException("Byte buffer dst is null"); -// } -// if (dst.isReadOnly()) { -// throw new ReadOnlyBufferException(); -// } + */ + public SSLEngineResult wrap(ByteBuffer src, ByteBuffer dst) throws SSLException { return wrap(new ByteBuffer[] { src }, 0, 1, dst); } } diff --git a/x-net/src/main/java/javax/net/ssl/SSLEngineResult.java b/x-net/src/main/java/javax/net/ssl/SSLEngineResult.java index dc55836..8a98831 100644 --- a/x-net/src/main/java/javax/net/ssl/SSLEngineResult.java +++ b/x-net/src/main/java/javax/net/ssl/SSLEngineResult.java @@ -20,11 +20,64 @@ package javax.net.ssl; /** * The result object describing the state of the {@code SSLEngine} produced * by the {@code wrap()} and {@code unwrap()} operations. - * - * @since Android 1.0 */ public class SSLEngineResult { - + + /** + * The {@code enum} describing the state of the current handshake. + */ + public enum HandshakeStatus { + /** + * No handshake in progress. + */ + NOT_HANDSHAKING, + /** + * The handshake is finished. + */ + FINISHED, + /** + * The results of one (or more) delegated tasks are needed to continue + * the handshake. + */ + NEED_TASK, + /** + * The engine must send data to the remote side to continue the + * handshake. + */ + NEED_WRAP, + /** + * The engine needs to receive data from the remote side to continue the + * handshake. + */ + NEED_UNWRAP + } + + /** + * The {@code enum} describing the result of the {@code SSLEngine} + * operation. + */ + public static enum Status { + /** + * The size of the destination buffer is too small to hold the result of + * the current operation. + */ + BUFFER_OVERFLOW, + /** + * There were not enough bytes available in the source buffer to + * complete the current operation. + */ + BUFFER_UNDERFLOW, + /** + * The operation closed this side of the communication or was already + * closed. + */ + CLOSED, + /** + * The operation completed successfully. + */ + OK + } + // Store Status object private final SSLEngineResult.Status status; @@ -40,7 +93,7 @@ public class SSLEngineResult { /** * Creates a new {@code SSLEngineResult} instance with the specified state * values. - * + * * @param status * the return value of the {@code SSLEngine} operation. * @param handshakeStatus @@ -53,11 +106,9 @@ public class SSLEngineResult { * if {@code status} or {@code handshakeStatus} is {@code null}, * or if {@code bytesConsumed} or {@code bytesProduces} are * negative. - * @since Android 1.0 */ public SSLEngineResult(SSLEngineResult.Status status, - SSLEngineResult.HandshakeStatus handshakeStatus, int bytesConsumed, - int bytesProduced) { + SSLEngineResult.HandshakeStatus handshakeStatus, int bytesConsumed, int bytesProduced) { if (status == null) { throw new IllegalArgumentException("status is null"); } @@ -78,9 +129,8 @@ public class SSLEngineResult { /** * Returns the return value of the {@code SSLEngine} operation. - * + * * @return the return value of the {@code SSLEngine} operation. - * @since Android 1.0 */ public final Status getStatus() { return status; @@ -88,9 +138,8 @@ public class SSLEngineResult { /** * Returns the status of the current handshake. - * + * * @return the status of the current handshake. - * @since Android 1.0 */ public final HandshakeStatus getHandshakeStatus() { return handshakeStatus; @@ -98,9 +147,8 @@ public class SSLEngineResult { /** * Returns the number of bytes retrieved from the source buffer(s). - * + * * @return the number of bytes retrieved from the source buffer(s). - * @since Android 1.0 */ public final int bytesConsumed() { return bytesConsumed; @@ -108,106 +156,17 @@ public class SSLEngineResult { /** * Returns the number of bytes transferred to the destination buffer(s). - * + * * @return the number of bytes transferred to the destination buffer(s). - * @since Android 1.0 */ public final int bytesProduced() { return bytesProduced; } - /** - * Returns a string representation of this instance. - * - * @return a string representation of this instance. - * @since Android 1.0 - */ + @Override public String toString() { - StringBuffer sb = new StringBuffer("SSLEngineReport: Status = "); - sb.append(status.toString()); - sb.append(" HandshakeStatus = "); - sb.append(handshakeStatus.toString()); - sb.append("\n bytesConsumed = "); - sb.append(Integer.toString(bytesConsumed)); - sb.append(" bytesProduced = "); - sb.append(Integer.toString(bytesProduced)); - return sb.toString(); - } - - /** - * The {@code enum} describing the state of the current handshake. - * - * @since Android 1.0 - */ - public enum HandshakeStatus { - /** - * No handshake in progress. - * - * @since Android 1.0 - */ - NOT_HANDSHAKING, - /** - * The handshake is finished. - * - * @since Android 1.0 - */ - FINISHED, - /** - * The results of one (or more) delegated tasks are needed to continue - * the handshake. - * - * @since Android 1.0 - */ - NEED_TASK, - /** - * The engine must send data to the remote side to continue the - * handshake. - * - * @since Android 1.0 - */ - NEED_WRAP, - /** - * The engine needs to receive data from the remote side to continue the - * handshake. - * - * @since Android 1.0 - */ - NEED_UNWRAP - } - - /** - * The {@code enum} describing the result of the {@code SSLEngine} - * operation. - * - * @since Android 1.0 - */ - public static enum Status { - /** - * The size of the destination buffer is too small to hold the result of - * the current operation. - * - * @since Android 1.0 - */ - BUFFER_OVERFLOW, - /** - * There were not enough bytes available in the source buffer to - * complete the current operation. - * - * @since Android 1.0 - */ - BUFFER_UNDERFLOW, - /** - * The operation closed this side of the communication or was already - * closed. - * - * @since Android 1.0 - */ - CLOSED, - /** - * The operation completed successfully. - * - * @since Android 1.0 - */ - OK + return "SSLEngineReport: Status = " + status + " HandshakeStatus = " + handshakeStatus + + "\n bytesConsumed = " + bytesConsumed + " bytesProduced = " + + bytesProduced; } -}
\ No newline at end of file +} diff --git a/x-net/src/main/java/javax/net/ssl/SSLException.java b/x-net/src/main/java/javax/net/ssl/SSLException.java index 43ba493..5d716f7 100644 --- a/x-net/src/main/java/javax/net/ssl/SSLException.java +++ b/x-net/src/main/java/javax/net/ssl/SSLException.java @@ -21,19 +21,15 @@ import java.io.IOException; /** * The base class for all SSL related exceptions. - * - * @since Android 1.0 */ public class SSLException extends IOException { - private static final long serialVersionUID = 4511006460650708967L; /** * Creates a new {@code SSLException} with the specified reason. - * + * * @param reason * the reason for the exception. - * @since Android 1.0 */ public SSLException(String reason) { super(reason); @@ -41,12 +37,11 @@ public class SSLException extends IOException { /** * Creates a new {@code SSLException} with the specified message and cause. - * + * * @param message * the detail message for the exception. * @param cause * the cause. - * @since Android 1.0 */ public SSLException(String message, Throwable cause) { super(message); @@ -55,10 +50,9 @@ public class SSLException extends IOException { /** * Creates a new {@code SSLException} with the specified cause. - * + * * @param cause * the cause - * @since Android 1.0 */ public SSLException(Throwable cause) { super(cause == null ? null : cause.toString()); diff --git a/x-net/src/main/java/javax/net/ssl/SSLHandshakeException.java b/x-net/src/main/java/javax/net/ssl/SSLHandshakeException.java index 81e44dc..1c17ae7 100644 --- a/x-net/src/main/java/javax/net/ssl/SSLHandshakeException.java +++ b/x-net/src/main/java/javax/net/ssl/SSLHandshakeException.java @@ -20,19 +20,16 @@ package javax.net.ssl; /** * The exception that is thrown when a handshake could not be completed * successfully. - * - * @since Android 1.0 */ public class SSLHandshakeException extends SSLException { - + private static final long serialVersionUID = -5045881315018326890L; /** * Creates a new {@code SSLHandshakeException} with the specified message. - * + * * @param reason * the detail message for the exception. - * @since Android 1.0 */ public SSLHandshakeException(String reason) { super(reason); diff --git a/x-net/src/main/java/javax/net/ssl/SSLKeyException.java b/x-net/src/main/java/javax/net/ssl/SSLKeyException.java index cc4bc84..6d81676 100644 --- a/x-net/src/main/java/javax/net/ssl/SSLKeyException.java +++ b/x-net/src/main/java/javax/net/ssl/SSLKeyException.java @@ -18,22 +18,19 @@ package javax.net.ssl; /** - * The exception that is thrown when an invalid SSL key is encountered. - * - * @since Android 1.0 + * The exception that is thrown when an invalid SSL key is encountered. */ public class SSLKeyException extends SSLException { private static final long serialVersionUID = -8071664081941937874L; - + /** * Creates a new {@code SSLKeyException} with the specified message. - * + * * @param reason * the detail message for the exception. - * @since Android 1.0 */ public SSLKeyException(String reason) { super(reason); } -}
\ No newline at end of file +} diff --git a/x-net/src/main/java/javax/net/ssl/SSLPeerUnverifiedException.java b/x-net/src/main/java/javax/net/ssl/SSLPeerUnverifiedException.java index 6e5734a..bb5bd64 100644 --- a/x-net/src/main/java/javax/net/ssl/SSLPeerUnverifiedException.java +++ b/x-net/src/main/java/javax/net/ssl/SSLPeerUnverifiedException.java @@ -20,22 +20,19 @@ package javax.net.ssl; /** * The exception that is thrown when the identity of a peer has not beed * verified. - * - * @since Android 1.0 */ public class SSLPeerUnverifiedException extends SSLException { - + private static final long serialVersionUID = -8919512675000600547L; /** * Creates a new {@code SSLPeerUnverifiedException} with the specified * message. - * + * * @param reason * the detail message for the exception. - * @since Android 1.0 */ public SSLPeerUnverifiedException(String reason) { super(reason); } -}
\ No newline at end of file +} diff --git a/x-net/src/main/java/javax/net/ssl/SSLPermission.java b/x-net/src/main/java/javax/net/ssl/SSLPermission.java index afc1abb..5b5c76f 100644 --- a/x-net/src/main/java/javax/net/ssl/SSLPermission.java +++ b/x-net/src/main/java/javax/net/ssl/SSLPermission.java @@ -23,26 +23,22 @@ import java.security.BasicPermission; * The class representing a network permission. * <p> * The following permissions are defined, allowing the specified action: - * </p> * <dl> * <dt> {@code "setHostnameVerifier"} </dt> - * <dd> setting a callback object for additional verification of a hostname mismatch.</dd> + * <dd> setting a callback object for additional verification of a hostname mismatch.</dd> * <dt> {@code "getSSLSessionContext"} </dt> * <dd> getting the {@code SSLSessionContext} of an {@code SSLSession}.</dd> - * </dl> - * - * @since Android 1.0 + * </dl> */ public final class SSLPermission extends BasicPermission { - + private static final long serialVersionUID = -3456898025505876775L; - + /** * Creates a new {@code SSLPermission} with the specified name. - * + * * @param name * the permission name. - * @since Android 1.0 */ public SSLPermission(String name) { super(name); @@ -50,14 +46,13 @@ public final class SSLPermission extends BasicPermission { /** * Creates a new {@code SSLPermission} with the specified name. - * + * * @param name * the permission name. * @param actions * is ignored and should be {@code null}. - * @since Android 1.0 */ public SSLPermission(String name, String actions) { super(name, actions); } -}
\ No newline at end of file +} diff --git a/x-net/src/main/java/javax/net/ssl/SSLProtocolException.java b/x-net/src/main/java/javax/net/ssl/SSLProtocolException.java index ef49ced..50ed74d 100644 --- a/x-net/src/main/java/javax/net/ssl/SSLProtocolException.java +++ b/x-net/src/main/java/javax/net/ssl/SSLProtocolException.java @@ -20,21 +20,18 @@ package javax.net.ssl; /** * The exception that is thrown when an error in the operation of the SSL * protocol is encountered. - * - * @since Android 1.0 */ public class SSLProtocolException extends SSLException { - + private static final long serialVersionUID = 5445067063799134928L; /** * Creates a new {@code SSLProtocolException} with the specified message. - * + * * @param reason * the detail message for the exception. - * @since Android 1.0 */ public SSLProtocolException(String reason) { super(reason); } -}
\ No newline at end of file +} diff --git a/x-net/src/main/java/javax/net/ssl/SSLServerSocket.java b/x-net/src/main/java/javax/net/ssl/SSLServerSocket.java index dc41556..8bd8918 100644 --- a/x-net/src/main/java/javax/net/ssl/SSLServerSocket.java +++ b/x-net/src/main/java/javax/net/ssl/SSLServerSocket.java @@ -24,20 +24,16 @@ import java.net.ServerSocket; /** * The extension of {@code ServerSocket} which provides secure server sockets * based on protocols like SSL, TLS, or others. - * - * @since Android 1.0 */ public abstract class SSLServerSocket extends ServerSocket { - + /** * Only to be used by subclasses. * <p> * Creates a TCP server socket with the default authentication context. - * </p> - * + * * @throws IOException * if creating the socket fails. - * @since Android 1.0 */ protected SSLServerSocket() throws IOException { super(); @@ -49,12 +45,10 @@ public abstract class SSLServerSocket extends ServerSocket { * Creates a TCP server socket on the specified port with the default * authentication context. The connection's default backlog size is 50 * connections. - * </p> * @param port * the port to listen on. * @throws IOException * if creating the socket fails. - * @since Android 1.0 */ protected SSLServerSocket(int port) throws IOException { super(port); @@ -65,14 +59,13 @@ public abstract class SSLServerSocket extends ServerSocket { * <p> * Creates a TCP server socket on the specified port using the specified * backlog and the default authentication context. - * + * * @param port * the port to listen on. * @param backlog * the number of pending connections to queue. * @throws IOException * if creating the socket fails. - * @since Android 1.0 */ protected SSLServerSocket(int port, int backlog) throws IOException { super(port, backlog); @@ -84,8 +77,7 @@ public abstract class SSLServerSocket extends ServerSocket { * Creates a TCP server socket on the specified port, using the specified * backlog, listening on the specified interface, and using the default * authentication context. - * </p> - * + * * @param port * the port the listen on. * @param backlog @@ -94,20 +86,17 @@ public abstract class SSLServerSocket extends ServerSocket { * the address of the interface to accept connections on. * @throws IOException * if creating the socket fails. - * @since Android 1.0 */ - protected SSLServerSocket(int port, int backlog, InetAddress address) - throws IOException { + protected SSLServerSocket(int port, int backlog, InetAddress address) throws IOException { super(port, backlog, address); } - + /** * Returns the names of the enabled cipher suites to be used for new * connections. - * + * * @return the names of the enabled cipher suites to be used for new * connections. - * @since Android 1.0 */ public abstract String[] getEnabledCipherSuites(); @@ -115,50 +104,45 @@ public abstract class SSLServerSocket extends ServerSocket { * Sets the names of the cipher suites to be enabled for new connections. * Only cipher suites returned by {@link #getSupportedCipherSuites()} are * allowed. - * + * * @param suites * the names of the to be enabled cipher suites. * @throws IllegalArgumentException * if one of the cipher suite names is not supported. - * @since Android 1.0 */ public abstract void setEnabledCipherSuites(String[] suites); /** * Returns the names of the supported cipher suites. - * + * * @return the names of the supported cipher suites. - * @since Android 1.0 */ public abstract String[] getSupportedCipherSuites(); /** * Returns the names of the supported protocols. - * + * * @return the names of the supported protocols. - * @since Android 1.0 */ public abstract String[] getSupportedProtocols(); /** * Returns the names of the enabled protocols to be used for new * connections. - * + * * @return the names of the enabled protocols to be used for new * connections. - * @since Android 1.0 */ public abstract String[] getEnabledProtocols(); /** * Sets the names of the protocols to be enabled for new connections. Only * protocols returned by {@link #getSupportedProtocols()} are allowed. - * + * * @param protocols * the names of the to be enabled protocols. * @throws IllegalArgumentException * if one of the protocols is not supported. - * @since Android 1.0 */ public abstract void setEnabledProtocols(String[] protocols); @@ -171,21 +155,19 @@ public abstract class SSLServerSocket extends ServerSocket { * <li>no authentication needed</li> * </ul> * This method overrides the setting of {@link #setWantClientAuth(boolean)}. - * + * * @param need * {@code true} if client authentication is required, * {@code false} if no authentication is needed. - * @since Android 1.0 */ public abstract void setNeedClientAuth(boolean need); /** * Returns whether server-mode connections will be configured to require * client authentication. - * + * * @return {@code true} if client authentication is required, {@code false} * if no client authentication is needed. - * @since Android 1.0 */ public abstract boolean getNeedClientAuth(); @@ -198,59 +180,53 @@ public abstract class SSLServerSocket extends ServerSocket { * <li>no authentication needed</li> * </ul> * This method overrides the setting of {@link #setNeedClientAuth(boolean)}. - * + * * @param want * {@code true} if client authentication should be requested, * {@code false} if no authentication is needed. - * @since Android 1.0 */ public abstract void setWantClientAuth(boolean want); /** * Returns whether server-mode connections will be configured to request * client authentication. - * + * * @return {@code true} is client authentication will be requested, * {@code false} if no client authentication is needed. - * @since Android 1.0 */ public abstract boolean getWantClientAuth(); /** * Sets whether new connections should act in client mode when handshaking. - * + * * @param mode * {@code true} if new connections should act in client mode, * {@code false} if not. - * @since Android 1.0 */ public abstract void setUseClientMode(boolean mode); /** * Returns whether new connection will act in client mode when handshaking. - * + * * @return {@code true} if new connections will act in client mode when * handshaking, {@code false} if not. - * @since Android 1.0 */ public abstract boolean getUseClientMode(); /** * Sets whether new SSL sessions may be established for new connections. - * + * * @param flag * {@code true} if new SSL sessions may be established, * {@code false} if existing SSL sessions must be reused. - * @since Android 1.0 */ public abstract void setEnableSessionCreation(boolean flag); - + /** * Returns whether new SSL sessions may be established for new connections. - * + * * @return {@code true} if new SSL sessions may be established, * {@code false} if existing SSL sessions must be reused. - * @since Android 1.0 */ public abstract boolean getEnableSessionCreation(); } diff --git a/x-net/src/main/java/javax/net/ssl/SSLServerSocketFactory.java b/x-net/src/main/java/javax/net/ssl/SSLServerSocketFactory.java index 14f467c..ccb2c5d 100644 --- a/x-net/src/main/java/javax/net/ssl/SSLServerSocketFactory.java +++ b/x-net/src/main/java/javax/net/ssl/SSLServerSocketFactory.java @@ -18,59 +18,46 @@ package javax.net.ssl; import java.security.AccessController; +import java.security.PrivilegedAction; import java.security.Security; import javax.net.ServerSocketFactory; /** * The factory for SSL server sockets. - * - * @since Android 1.0 */ public abstract class SSLServerSocketFactory extends ServerSocketFactory { -// TODO EXPORT CONTROL - + // TODO EXPORT CONTROL + // The default SSL socket factory private static ServerSocketFactory defaultServerSocketFactory; private static String defaultName; - - /** - * Creates a new {@code SSLServerSocketFactory} instance. - * - * @since Android 1.0 - */ - protected SSLServerSocketFactory() { - super(); - } /** * Returns the default {@code SSLServerSocketFactory} instance. The default * implementation is defined by the security property * "ssl.ServerSocketFactory.provider". - * + * * @return the default {@code SSLServerSocketFactory} instance. - * @since Android 1.0 */ - public static ServerSocketFactory getDefault() { + public static synchronized ServerSocketFactory getDefault() { if (defaultServerSocketFactory != null) { return defaultServerSocketFactory; } if (defaultName == null) { - AccessController.doPrivileged(new java.security.PrivilegedAction(){ - public Object run() { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { defaultName = Security.getProperty("ssl.ServerSocketFactory.provider"); - if (defaultName != null) { + if (defaultName != null) { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl == null) { cl = ClassLoader.getSystemClassLoader(); } try { - defaultServerSocketFactory = (ServerSocketFactory) Class - .forName(defaultName, true, cl) - .newInstance(); + final Class<?> ssfc = Class.forName(defaultName, true, cl); + defaultServerSocketFactory = (ServerSocketFactory) ssfc.newInstance(); } catch (Exception e) { - return e; } } return null; @@ -81,31 +68,36 @@ public abstract class SSLServerSocketFactory extends ServerSocketFactory { // Try to find in providers SSLContext context = DefaultSSLContext.getContext(); if (context != null) { - defaultServerSocketFactory = context.getServerSocketFactory(); + defaultServerSocketFactory = context.getServerSocketFactory(); } } if (defaultServerSocketFactory == null) { // Use internal dummy implementation - defaultServerSocketFactory = new DefaultSSLServerSocketFactory("No ServerSocketFactory installed"); - } + defaultServerSocketFactory = new DefaultSSLServerSocketFactory( + "No ServerSocketFactory installed"); + } return defaultServerSocketFactory; } - + + /** + * Creates a new {@code SSLServerSocketFactory} instance. + */ + protected SSLServerSocketFactory() { + super(); + } + /** * Returns the names of the cipher suites that are enabled by default. - * + * * @return the names of the cipher suites that are enabled by default - * @since Android 1.0 */ public abstract String[] getDefaultCipherSuites(); - + /** * Returns the list of supported cipher suites that could be enabled for an * SSL connection created by this factory. - * + * * @return the list of supported cipher suites - * @since Android 1.0 */ public abstract String[] getSupportedCipherSuites(); - } diff --git a/x-net/src/main/java/javax/net/ssl/SSLSession.java b/x-net/src/main/java/javax/net/ssl/SSLSession.java index 553d74f..14a312a 100644 --- a/x-net/src/main/java/javax/net/ssl/SSLSession.java +++ b/x-net/src/main/java/javax/net/ssl/SSLSession.java @@ -15,7 +15,6 @@ * limitations under the License. */ - package javax.net.ssl; import java.security.Principal; @@ -24,78 +23,68 @@ import javax.security.cert.X509Certificate; /** * The interface representing an SSL session. - * - * @since Android 1.0 */ public interface SSLSession { /** * Returns the maximum size that an application buffer can be for this * session. - * + * * @return the maximum application buffer size. - * @since Android 1.0 */ public int getApplicationBufferSize(); /** * Returns the name of the cipher suite used in this session. - * + * * @return the name of the cipher suite used in this session. - * @since Android 1.0 */ public String getCipherSuite(); /** * Returns the time this session was created, in milliseconds since midnight * January 1st 1970 UTC. - * + * * @return the time the session was created. - * @since Android 1.0 */ public long getCreationTime(); /** * Returns this sessions identifier. - * + * * @return this sessions identifier. - * @since Android 1.0 */ public byte[] getId(); /** * Returns the time this session was last accessed, in milliseconds since * midnight January 1st 1970 UTC. - * + * * @return the time this session was last accessed. - * @since Android 1.0 */ public long getLastAccessedTime(); /** * Returns the list of certificates that were used to identify the local * side to the peer during the handshake. - * + * * @return the list of certificates, ordered from local certificate to * CA's certificates. - * @since Android 1.0 */ public Certificate[] getLocalCertificates(); /** * Returns the principal used to identify the local side to the peer during * the handshake. - * + * * @return the principal used to identify the local side. - * @since Android 1.0 */ public Principal getLocalPrincipal(); /** * Returns the maximum size that a network buffer can be for this session. - * + * * @return the maximum network buffer size. - * @since Android 1.0 */ public int getPacketBufferSize(); @@ -105,67 +94,58 @@ public interface SSLSession { * <p> * Note: this method exists for compatility reasons, use * {@link #getPeerCertificates()} instead. - * </p> - * + * * @return the list of certificates, ordered from the identity certificate to * the CA's certificates * @throws SSLPeerUnverifiedException * if the identity of the peer is not verified. - * @since Android 1.0 */ - public X509Certificate[] getPeerCertificateChain() - throws SSLPeerUnverifiedException; + public X509Certificate[] getPeerCertificateChain() throws SSLPeerUnverifiedException; /** * Returns the list of certificates the peer used to identify itself during * the handshake. - * + * * @return the list of certificates, ordered from the identity certificate to * the CA's certificates. * @throws SSLPeerUnverifiedException * if the identity of the peer is not verified. - * @since Android 1.0 */ - public Certificate[] getPeerCertificates() - throws SSLPeerUnverifiedException; + public Certificate[] getPeerCertificates() throws SSLPeerUnverifiedException; /** * Returns the host name of the peer of this session. The host name is not * authenticated. - * + * * @return the host name of the peer of this session, or {@code null} if no * host name is available. - * @since Android 1.0 */ public String getPeerHost(); /** * Returns the port number of the peer of this session. The port number is * not authenticated. - * + * * @return the port number of the peer, of {@code -1} is no port number is * available. - * @since Android 1.0 */ public int getPeerPort(); /** * Returns the principal identifying the peer during the handshake. - * + * * @return the principal identifying the peer. * @throws SSLPeerUnverifiedException * if the identity of the peer has not been verified. - * @since Android 1.0 */ public Principal getPeerPrincipal() throws SSLPeerUnverifiedException; /** * Returns the protocol name that is used for all connections in this * session. - * + * * @return the protocol name that is used for all connections in this * session. - * @since Android 1.0 */ public String getProtocol(); @@ -174,17 +154,16 @@ public interface SSLSession { * security manager is installed, the * {@code SSLPermission("getSSLSessionContext"} is checked with the security * manager. - * + * * @return the context of this session or {@code null} if no context is * available. - * @since Android 1.0 */ public SSLSessionContext getSessionContext(); /** * Returns the object bound to the specified name in this session's * application layer data. - * + * * @param name * the name of the bound value. * @return the value bound to the specified name, or {@code null} if the @@ -192,7 +171,6 @@ public interface SSLSession { * access control context. * @throws IllegalArgumentException * if {@code name} is {@code null}. - * @since Android 1.0 */ public Object getValue(String name); @@ -202,11 +180,9 @@ public interface SSLSession { * <p> * Depending on the current access control context, the list of object names * may be different. - * </p> - * + * * @return the list of the object names bound to this session's application * layer data. - * @since Android 1.0 */ public String[] getValueNames(); @@ -215,17 +191,13 @@ public interface SSLSession { * <p> * No new connections can be created, but any existing connection remains * valid until it is closed. - * </p> - * - * @since Android 1.0 */ public void invalidate(); /** * Returns whether this session is valid. - * + * * @return {@code true} if this session is valid, otherwise {@code false}. - * @since Android 1.0 */ public boolean isValid(); @@ -235,15 +207,13 @@ public interface SSLSession { * <p> * For bindings (new or existing) implementing the * {@code SSLSessionBindingListener} interface the object will be notified. - * </p> - * + * * @param name * the name to bind the object to. * @param value * the object to bind. * @throws IllegalArgumentException * if either {@code name} or {@code value} is {@code null}. - * @since Android 1.0 */ public void putValue(String name, Object value); @@ -251,12 +221,11 @@ public interface SSLSession { * Removes the binding for the specified name in this session's application * layer data. If the existing binding implements the * {@code SSLSessionBindingListener} interface the object will be notified. - * + * * @param name * the binding to remove. * @throws IllegalArgumentException * if {@code name} is {@code null}. - * @since Android 1.0 */ public void removeValue(String name); -}
\ No newline at end of file +} diff --git a/x-net/src/main/java/javax/net/ssl/SSLSessionBindingEvent.java b/x-net/src/main/java/javax/net/ssl/SSLSessionBindingEvent.java index dbda787..19ae835 100644 --- a/x-net/src/main/java/javax/net/ssl/SSLSessionBindingEvent.java +++ b/x-net/src/main/java/javax/net/ssl/SSLSessionBindingEvent.java @@ -22,54 +22,54 @@ import java.util.EventObject; /** * The event sent to an {@code SSLSessionBindingListener} when the listener - * object is bound ({@link SSLSession#putValue(String, Object)}) or unbound + * object is bound ({@link SSLSession#putValue(String, Object)}) or unbound * ({@link SSLSession#removeValue(String)}) to an {@code SSLSession}. - * - * @since Android 1.0 */ public class SSLSessionBindingEvent extends EventObject implements Serializable { + /** + * The 5.0 spec. doesn't declare this serialVersionUID field In order to be compatible it is + * explicitly declared here + */ private static final long serialVersionUID = 3989172637106345L; - private String name; + /** + * @serial include + */ + private final String name; /** * Creates a new {@code SSLSessionBindingEvent} for the specified session * indicating a binding event for the specified name. - * + * * @param session * the session for which the event occurs. * @param name * the name of the object being (un)bound. - * @since Android 1.0 */ public SSLSessionBindingEvent(SSLSession session, String name) { super(session); this.name = name; } - + /** * Returns the name of the binding being added or removed. - * + * * @return the name of the binding. - * @since Android 1.0 */ public String getName() { return name; } - + /** * Returns the session to which the binding is added or from which it is * removed. - * + * * @return the session to which the binding is added or from which it is * removed. - * @since Android 1.0 */ public SSLSession getSession() { - return (SSLSession)this.source; + return (SSLSession) this.source; } - - -}
\ No newline at end of file +} diff --git a/x-net/src/main/java/javax/net/ssl/SSLSessionBindingListener.java b/x-net/src/main/java/javax/net/ssl/SSLSessionBindingListener.java index 7781c53..43ad745 100644 --- a/x-net/src/main/java/javax/net/ssl/SSLSessionBindingListener.java +++ b/x-net/src/main/java/javax/net/ssl/SSLSessionBindingListener.java @@ -21,28 +21,24 @@ import java.util.EventListener; /** * The interface to be implemented by any object that requires notification when - * data objects are bound to (or unbound from) an {@code SSLSession}. - * - * @since Android 1.0 + * data objects are bound to (or unbound from) an {@code SSLSession}. */ public interface SSLSessionBindingListener extends EventListener { /** * Notifies this listener when a value is bound to an {@code SSLSession}. - * + * * @param event * the event data. - * @since Android 1.0 */ public void valueBound(SSLSessionBindingEvent event); /** * Notifies this listener when a value is unbound from an {@code SSLSession}. - * + * * @param event * the event data. - * @since Android 1.0 */ public void valueUnbound(SSLSessionBindingEvent event); -}
\ No newline at end of file +} diff --git a/x-net/src/main/java/javax/net/ssl/SSLSessionContext.java b/x-net/src/main/java/javax/net/ssl/SSLSessionContext.java index 9d831f3..154376e 100644 --- a/x-net/src/main/java/javax/net/ssl/SSLSessionContext.java +++ b/x-net/src/main/java/javax/net/ssl/SSLSessionContext.java @@ -20,72 +20,63 @@ package javax.net.ssl; import java.util.Enumeration; /** - * A collection of {@code SSLSession}s. - * - * @since Android 1.0 + * A collection of {@code SSLSession}s. */ public interface SSLSessionContext { - /** * Returns an iterable of all session identifiers in this session context. - * + * * @return an iterable of all session identifiers in this session context. - * @since Android 1.0 */ + @SuppressWarnings("unchecked") public Enumeration getIds(); /** * Returns the session for the specified session identifier. - * + * * @param sessionId * the session identifier of the session to look up. * @return the session for the specified session identifier, or {@code null} * if the specified session identifier does not refer to a session * in this context. - * @since Android 1.0 */ public SSLSession getSession(byte[] sessionId); /** * Returns the size of the session cache for this session context. - * + * * @return the size of the session cache for this session context, or * {@code zero} if unlimited. - * @since Android 1.0 */ public int getSessionCacheSize(); /** * Returns the timeout for sessions in this session context. Sessions * exceeding the timeout are invalidated. - * + * * @return the timeout in seconds, or {@code zero} if unlimited. - * @since Android 1.0 */ public int getSessionTimeout(); /** * Sets the size of the session cache for this session context. - * + * * @param size * the size of the session cache, or {@code zero} for unlimited * cache size. * @throws IllegalArgumentException * if {@code size} is negative. - * @since Android 1.0 */ public void setSessionCacheSize(int size) throws IllegalArgumentException; /** * Sets the timeout for sessions in this context. Sessions exceeding the * timeout are invalidated. - * + * * @param seconds * the timeout in seconds, or {@code zero} if unlimited. * @throws IllegalArgumentException * if {@code seconds} is negative. - * @since Android 1.0 */ public void setSessionTimeout(int seconds) throws IllegalArgumentException; - -}
\ No newline at end of file +} diff --git a/x-net/src/main/java/javax/net/ssl/SSLSocket.java b/x-net/src/main/java/javax/net/ssl/SSLSocket.java index 7320416..4a70843 100644 --- a/x-net/src/main/java/javax/net/ssl/SSLSocket.java +++ b/x-net/src/main/java/javax/net/ssl/SSLSocket.java @@ -24,19 +24,14 @@ import java.net.UnknownHostException; /** * The extension of {@code Socket} providing secure protocols like SSL (Secure - * Socket Layer") or TLS (Transport Layer Security). - * - * @since Android 1.0 + * Socket Layer") or TLS (Transport Layer Security). */ public abstract class SSLSocket extends Socket { - + /** * Only to be used by subclasses. * <p> * Creates a TCP socket. - * </p> - * - * @since Android 1.0 */ protected SSLSocket() { super(); @@ -47,8 +42,7 @@ public abstract class SSLSocket extends Socket { * <p> * Creates a TCP socket connection to the specified host at the specified * port. - * </p> - * + * * @param host * the host name to connect to. * @param port @@ -57,10 +51,8 @@ public abstract class SSLSocket extends Socket { * if creating the socket fails. * @throws UnknownHostException * if the specified host is not known. - * @since Android 1.0 */ - protected SSLSocket(String host, int port) throws IOException, - UnknownHostException { + protected SSLSocket(String host, int port) throws IOException, UnknownHostException { super(host, port); } @@ -69,15 +61,13 @@ public abstract class SSLSocket extends Socket { * <p> * Creates a TCP socket connection to the specified address at the specified * port. - * </p> - * + * * @param address * the address to connect to. * @param port * the port number to connect to. * @throws IOException * if creating the socket fails. - * @since Android 1.0 */ protected SSLSocket(InetAddress address, int port) throws IOException { super(address, port); @@ -88,8 +78,7 @@ public abstract class SSLSocket extends Socket { * <p> * Creates a TCP socket connection to the specified host at the specified * port with the client side bound to the specified address and port. - * </p> - * + * * @param host * the host name to connect to. * @param port @@ -102,10 +91,9 @@ public abstract class SSLSocket extends Socket { * if creating the socket fails. * @throws UnknownHostException * if the specified host is not known. - * @since Android 1.0 */ - protected SSLSocket(String host, int port, InetAddress clientAddress, - int clientPort) throws IOException, UnknownHostException { + protected SSLSocket(String host, int port, InetAddress clientAddress, int clientPort) + throws IOException, UnknownHostException { super(host, port, clientAddress, clientPort); } @@ -114,8 +102,7 @@ public abstract class SSLSocket extends Socket { * <p> * Creates a TCP socket connection to the specified address at the specified * port with the client side bound to the specified address and port. - * </p> - * + * * @param address * the address to connect to. * @param port @@ -126,132 +113,119 @@ public abstract class SSLSocket extends Socket { * the client port number to bind to. * @throws IOException * if creating the socket fails. - * @since Android 1.0 */ - protected SSLSocket(InetAddress address, int port, - InetAddress clientAddress, int clientPort) throws IOException { + protected SSLSocket(InetAddress address, int port, InetAddress clientAddress, int clientPort) + throws IOException { super(address, port, clientAddress, clientPort); } - + /** * Returns the names of the supported cipher suites. - * + * * @return the names of the supported cipher suites. - * @since Android 1.0 */ public abstract String[] getSupportedCipherSuites(); - + /** * Returns the names of the enabled cipher suites. - * + * * @return the names of the enabled cipher suites. - * @since Android 1.0 */ public abstract String[] getEnabledCipherSuites(); - + /** * Sets the names of the cipher suites to be enabled. * Only cipher suites returned by {@link #getSupportedCipherSuites()} are * allowed. - * + * * @param suites * the names of the to be enabled cipher suites. * @throws IllegalArgumentException * if one of the cipher suite names is not supported. - * @since Android 1.0 */ public abstract void setEnabledCipherSuites(String[] suites); - + /** * Returns the names of the supported protocols. - * + * * @return the names of the supported protocols. - * @since Android 1.0 */ public abstract String[] getSupportedProtocols(); - + /** * Returns the names of the enabled protocols. - * + * * @return the names of the enabled protocols. - * @since Android 1.0 */ public abstract String[] getEnabledProtocols(); - + /** * Sets the names of the protocols to be enabled. Only * protocols returned by {@link #getSupportedProtocols()} are allowed. - * + * * @param protocols * the names of the to be enabled protocols. * @throws IllegalArgumentException * if one of the protocols is not supported. - * @since Android 1.0 */ public abstract void setEnabledProtocols(String[] protocols); - + /** * Returns the {@code SSLSession} for this connection. If necessary, a * handshake will be initiated, in which case this method will block until the handshake * has been established. If the handshake fails, an invalid session object * will be returned. - * + * * @return the session object. - * @since Android 1.0 */ public abstract SSLSession getSession(); - + /** * Registers the specified listener to receive notification on completion of a * handshake on this connection. - * + * * @param listener * the listener to register. * @throws IllegalArgumentException * if {@code listener} is {@code null}. - * @since Android 1.0 */ public abstract void addHandshakeCompletedListener(HandshakeCompletedListener listener); - + /** * Removes the specified handshake completion listener. - * + * * @param listener * the listener to remove. * @throws IllegalArgumentException * if the specified listener is not registered or {@code null}. - * @since Android 1.0 */ public abstract void removeHandshakeCompletedListener(HandshakeCompletedListener listener); - + /** * Starts a new SSL handshake on this connection. - * + * * @throws IOException * if an error occurs. - * @since Android 1.0 */ public abstract void startHandshake() throws IOException; - + /** * Sets whether this connection should act in client mode when handshaking. - * + * * @param mode * {@code true} if this connection should act in client mode, * {@code false} if not. - * @since Android 1.0 */ public abstract void setUseClientMode(boolean mode); - + /** * Returns whether this connection will act in client mode when handshaking. - * + * * @return {@code true} if this connections will act in client mode when * handshaking, {@code false} if not. - * @since Android 1.0 */ public abstract boolean getUseClientMode(); - + /** * Sets whether this connection should require client authentication. This * is only useful for sockets in server mode. The client authentication is @@ -262,24 +236,22 @@ public abstract class SSLSocket extends Socket { * <li>no authentication needed</li> * </ul> * This method overrides the setting of {@link #setWantClientAuth(boolean)}. - * + * * @param need * {@code true} if client authentication is required, * {@code false} if no authentication is needed. - * @since Android 1.0 */ public abstract void setNeedClientAuth(boolean need); - + /** * Returns whether this connection requires client authentication. * This is only useful for sockets in server mode. - * + * * @return {@code true} if client authentication is required, {@code false} * if no client authentication is needed. - * @since Android 1.0 */ public abstract boolean getNeedClientAuth(); - + /** * Sets whether this connections should request client authentication. This * is only useful for sockets in server mode. The client authentication is @@ -290,42 +262,38 @@ public abstract class SSLSocket extends Socket { * <li>no authentication needed</li> * </ul> * This method overrides the setting of {@link #setNeedClientAuth(boolean)}. - * + * * @param want * {@code true} if client authentication should be requested, * {@code false} if not authentication is needed. - * @since Android 1.0 */ public abstract void setWantClientAuth(boolean want); - + /** * Returns whether this connections will request client authentication. - * + * * @return {@code true} is client authentication will be requested, * {@code false} if no client authentication is needed. - * @since Android 1.0 */ public abstract boolean getWantClientAuth(); - + /** * Sets whether new SSL sessions may be created by this socket or if * existing sessions must be reused. - * + * * @param flag * {@code true} if new sessions may be created, otherwise * {@code false}. - * @since Android 1.0 */ public abstract void setEnableSessionCreation(boolean flag); - + /** * Returns whether new SSL sessions may be created by this socket or if * existing sessions must be reused. - * + * * @return {@code true} if new sessions may be created, otherwise * {@code false}. - * @since Android 1.0 */ public abstract boolean getEnableSessionCreation(); - -}
\ No newline at end of file + +} diff --git a/x-net/src/main/java/javax/net/ssl/SSLSocketFactory.java b/x-net/src/main/java/javax/net/ssl/SSLSocketFactory.java index 2b7c03e..d9db099 100644 --- a/x-net/src/main/java/javax/net/ssl/SSLSocketFactory.java +++ b/x-net/src/main/java/javax/net/ssl/SSLSocketFactory.java @@ -20,10 +20,9 @@ package javax.net.ssl; import java.io.IOException; import java.net.Socket; import java.security.AccessController; +import java.security.PrivilegedAction; import java.security.Security; // BEGIN android-added -import java.lang.reflect.Method; -import java.net.UnknownHostException; import java.util.logging.Logger; // END android-added @@ -31,10 +30,9 @@ import javax.net.SocketFactory; /** * The abstract factory implementation to create {@code SSLSocket}s. - * - * @since Android 1.0 */ public abstract class SSLSocketFactory extends SocketFactory { + // FIXME EXPORT CONTROL // The default SSL socket factory private static SocketFactory defaultSocketFactory; @@ -42,66 +40,53 @@ public abstract class SSLSocketFactory extends SocketFactory { private static String defaultName; /** - * Creates a new {@code SSLSocketFactory}. - * - * @since Android 1.0 - */ - public SSLSocketFactory() { - super(); - } - - /** * Returns the default {@code SSLSocketFactory} instance. The default is * defined by the security property {@code 'ssl.SocketFactory.provider'}. - * + * * @return the default ssl socket factory instance. - * @since Android 1.0 */ - public static SocketFactory getDefault() { - synchronized (SSLSocketFactory.class) { - if (defaultSocketFactory != null) { - // BEGIN android-added - log("SSLSocketFactory", "Using factory " + defaultSocketFactory); - // END android-added - return defaultSocketFactory; - } - if (defaultName == null) { - AccessController.doPrivileged(new java.security.PrivilegedAction(){ - public Object run() { - defaultName = Security.getProperty("ssl.SocketFactory.provider"); - if (defaultName != null) { - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - if (cl == null) { - cl = ClassLoader.getSystemClassLoader(); - } - try { - defaultSocketFactory = (SocketFactory) Class.forName( - defaultName, true, cl).newInstance(); - } catch (Exception e) { - return e; - } + public static synchronized SocketFactory getDefault() { + if (defaultSocketFactory != null) { + // BEGIN android-added + log("SSLSocketFactory", "Using factory " + defaultSocketFactory); + // END android-added + return defaultSocketFactory; + } + if (defaultName == null) { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { + defaultName = Security.getProperty("ssl.SocketFactory.provider"); + if (defaultName != null) { + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + if (cl == null) { + cl = ClassLoader.getSystemClassLoader(); + } + try { + final Class<?> sfc = Class.forName(defaultName, true, cl); + defaultSocketFactory = (SocketFactory) sfc.newInstance(); + } catch (Exception e) { } - return null; } - }); - } - - if (defaultSocketFactory == null) { - // Try to find in providers - SSLContext context = DefaultSSLContext.getContext(); - if (context != null) { - defaultSocketFactory = context.getSocketFactory(); + return null; } + }); + } + + if (defaultSocketFactory == null) { + // Try to find in providers + SSLContext context = DefaultSSLContext.getContext(); + if (context != null) { + defaultSocketFactory = context.getSocketFactory(); } - if (defaultSocketFactory == null) { - // Use internal implementation - defaultSocketFactory = new DefaultSSLSocketFactory("No SSLSocketFactory installed"); - } + } + if (defaultSocketFactory == null) { + // Use internal implementation + defaultSocketFactory = new DefaultSSLSocketFactory("No SSLSocketFactory installed"); + } // BEGIN android-added log("SSLSocketFactory", "Using factory " + defaultSocketFactory); // END android-added - return defaultSocketFactory; - } + return defaultSocketFactory; } // BEGIN android-added @@ -112,26 +97,31 @@ public abstract class SSLSocketFactory extends SocketFactory { // END android-added /** + * Creates a new {@code SSLSocketFactory}. + */ + public SSLSocketFactory() { + super(); + } + + /** * Returns the names of the cipher suites that are enabled by default. - * + * * @return the names of the cipher suites that are enabled by default. - * @since Android 1.0 */ public abstract String[] getDefaultCipherSuites(); /** * Returns the names of the cipher suites that are supported and could be * enabled for an SSL connection. - * + * * @return the names of the cipher suites that are supported. - * @since Android 1.0 */ public abstract String[] getSupportedCipherSuites(); /** * Creates an {@code SSLSocket} over the specified socket that is connected * to the specified host at the specified port. - * + * * @param s * the socket. * @param host @@ -145,11 +135,9 @@ public abstract class SSLSocketFactory extends SocketFactory { * @return the creates ssl socket. * @throws IOException * if creating the socket fails. - * @throws UnknownHostException + * @throws java.net.UnknownHostException * if the host is unknown. - * @since Android 1.0 */ - public abstract Socket createSocket(Socket s, String host, int port, - boolean autoClose) throws IOException; - + public abstract Socket createSocket(Socket s, String host, int port, boolean autoClose) + throws IOException; } diff --git a/x-net/src/main/java/javax/net/ssl/TrustManager.java b/x-net/src/main/java/javax/net/ssl/TrustManager.java index 5d8afcd..9bdb16b 100644 --- a/x-net/src/main/java/javax/net/ssl/TrustManager.java +++ b/x-net/src/main/java/javax/net/ssl/TrustManager.java @@ -20,11 +20,9 @@ package javax.net.ssl; /** * The marker interface for JSSE trust managers. The purpose is to group trust * managers. The responsibility a trust manager is to handle the trust data used to - * make trust decisions for deciding whether credentials of a peer should be + * make trust decisions for deciding whether credentials of a peer should be * accepted, * @see TrustManagerFactory - * - * @since Android 1.0 */ public interface TrustManager { -}
\ No newline at end of file +} diff --git a/x-net/src/main/java/javax/net/ssl/TrustManagerFactory.java b/x-net/src/main/java/javax/net/ssl/TrustManagerFactory.java index 480eb26..6d9e4c9 100644 --- a/x-net/src/main/java/javax/net/ssl/TrustManagerFactory.java +++ b/x-net/src/main/java/javax/net/ssl/TrustManagerFactory.java @@ -23,18 +23,15 @@ import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; +import java.security.PrivilegedAction; import java.security.Provider; import java.security.Security; import org.apache.harmony.security.fortress.Engine; - - /** * The factory for {@code TrustManager}s based on {@code KeyStore} or provider * specific implementation. - * - * @since Android 1.0 */ public class TrustManagerFactory { // Store TrustManager service name @@ -46,49 +43,25 @@ public class TrustManagerFactory { // Store default property name private static final String PROPERTYNAME = "ssl.TrustManagerFactory.algorithm"; - // Store used provider - private final Provider provider; - - // Storeused TrustManagerFactorySpi implementation - private final TrustManagerFactorySpi spiImpl; - - // Store used algorithm - private final String algorithm; - - /** - * Creates a new {@code TrustManagerFactory} instance. - * - * @param factorySpi - * the implementation delegate. - * @param provider - * the provider - * @param algorithm - * the algorithm name. - * @since Android 1.0 - */ - protected TrustManagerFactory(TrustManagerFactorySpi factorySpi, - Provider provider, String algorithm) { - this.provider = provider; - this.algorithm = algorithm; - this.spiImpl = factorySpi; - } - /** - * Returns the name of this {@code TrustManagerFactory} algorithm - * implementation. - * - * @return the name of this {@code TrustManagerFactory} algorithm - * implementation. - * @since Android 1.0 + * Returns the default algorithm name for the {@code TrustManagerFactory}. The + * default algorithm name is specified by the security property + * {@code 'ssl.TrustManagerFactory.algorithm'}. + * + * @return the default algorithm name. */ - public final String getAlgorithm() { - return algorithm; + public static final String getDefaultAlgorithm() { + return AccessController.doPrivileged(new PrivilegedAction<String>() { + public String run() { + return Security.getProperty(PROPERTYNAME); + } + }); } /** * Creates a new {@code TrustManagerFactory} instance for the specified * trust management algorithm. - * + * * @param algorithm * the name of the requested trust management algorithm. * @return a trust manager factory for the requested algorithm. @@ -97,7 +70,6 @@ public class TrustManagerFactory { * @throws NullPointerException * if {@code algorithm} is {@code null} (instead of * NoSuchAlgorithmException as in 1.4 release) - * @since Android 1.0 */ public static final TrustManagerFactory getInstance(String algorithm) throws NoSuchAlgorithmException { @@ -106,15 +78,15 @@ public class TrustManagerFactory { } synchronized (engine) { engine.getInstance(algorithm, null); - return new TrustManagerFactory((TrustManagerFactorySpi) engine.spi, - engine.provider, algorithm); + return new TrustManagerFactory((TrustManagerFactorySpi) engine.spi, engine.provider, + algorithm); } } /** * Creates a new {@code TrustManagerFactory} instance for the specified * trust management algorithm from the specified provider. - * + * * @param algorithm * the name of the requested trust management algorithm name. * @param provider @@ -129,11 +101,9 @@ public class TrustManagerFactory { * @throws NullPointerException * if {@code algorithm} is {@code null} (instead of * NoSuchAlgorithmException as in 1.4 release) - * @since Android 1.0 */ - public static final TrustManagerFactory getInstance(String algorithm, - String provider) throws NoSuchAlgorithmException, - NoSuchProviderException { + public static final TrustManagerFactory getInstance(String algorithm, String provider) + throws NoSuchAlgorithmException, NoSuchProviderException { if ((provider == null) || (provider.length() == 0)) { throw new IllegalArgumentException("Provider is null oe empty"); } @@ -147,7 +117,7 @@ public class TrustManagerFactory { /** * Creates a new {@code TrustManagerFactory} instance for the specified * trust management algorithm from the specified provider. - * + * * @param algorithm * the name of the requested key management algorithm name. * @param provider @@ -159,10 +129,9 @@ public class TrustManagerFactory { * @throws NullPointerException * if {@code algorithm} is {@code null} (instead of * NoSuchAlgorithmException as in 1.4 release) - * @since Android 1.0 */ - public static final TrustManagerFactory getInstance(String algorithm, - Provider provider) throws NoSuchAlgorithmException { + public static final TrustManagerFactory getInstance(String algorithm, Provider provider) + throws NoSuchAlgorithmException { if (provider == null) { throw new IllegalArgumentException("Provider is null"); } @@ -171,16 +140,51 @@ public class TrustManagerFactory { } synchronized (engine) { engine.getInstance(algorithm, provider, null); - return new TrustManagerFactory((TrustManagerFactorySpi) engine.spi, - provider, algorithm); + return new TrustManagerFactory((TrustManagerFactorySpi) engine.spi, provider, algorithm); } } + // Store used provider + private final Provider provider; + + // Store used TrustManagerFactorySpi implementation + private final TrustManagerFactorySpi spiImpl; + + // Store used algorithm + private final String algorithm; + + /** + * Creates a new {@code TrustManagerFactory} instance. + * + * @param factorySpi + * the implementation delegate. + * @param provider + * the provider + * @param algorithm + * the algorithm name. + */ + protected TrustManagerFactory(TrustManagerFactorySpi factorySpi, Provider provider, + String algorithm) { + this.provider = provider; + this.algorithm = algorithm; + this.spiImpl = factorySpi; + } + + /** + * Returns the name of this {@code TrustManagerFactory} algorithm + * implementation. + * + * @return the name of this {@code TrustManagerFactory} algorithm + * implementation. + */ + public final String getAlgorithm() { + return algorithm; + } + /** * Returns the provider for this {@code TrustManagerFactory} instance. - * + * * @return the provider for this {@code TrustManagerFactory} instance. - * @since Android 1.0 */ public final Provider getProvider() { return provider; @@ -189,12 +193,11 @@ public class TrustManagerFactory { /** * Initializes this factory instance with the specified keystore as source * of certificate authorities and trust material. - * + * * @param ks * the keystore or {@code null}. * @throws KeyStoreException * if the initialization fails. - * @since Android 1.0 */ public final void init(KeyStore ks) throws KeyStoreException { spiImpl.engineInit(ks); @@ -203,43 +206,24 @@ public class TrustManagerFactory { /** * Initializes this factory instance with the specified provider-specific * parameters for a source of trust material. - * + * * @param spec * the provider-specific parameters. * @throws InvalidAlgorithmParameterException * if the initialization fails. - * @since Android 1.0 */ - public final void init(ManagerFactoryParameters spec) - throws InvalidAlgorithmParameterException { + public final void init(ManagerFactoryParameters spec) throws InvalidAlgorithmParameterException { spiImpl.engineInit(spec); } /** * Returns the list of {@code TrustManager}s with one entry for each type * of trust material. - * + * * @return the list of {@code TrustManager}s - * @since Android 1.0 */ public final TrustManager[] getTrustManagers() { return spiImpl.engineGetTrustManagers(); } - /** - * Returns the default algorithm name for the {@code TrustManagerFactory}. The - * default algorithm name is specified by the security property - * {@code 'ssl.TrustManagerFactory.algorithm'}. - * - * @return the default algorithm name. - * @since Android 1.0 - */ - public static final String getDefaultAlgorithm() { - return AccessController - .doPrivileged(new java.security.PrivilegedAction<String>() { - public String run() { - return Security.getProperty(PROPERTYNAME); - } - }); - } -}
\ No newline at end of file +} diff --git a/x-net/src/main/java/javax/net/ssl/TrustManagerFactorySpi.java b/x-net/src/main/java/javax/net/ssl/TrustManagerFactorySpi.java index 08e213e..1b04c5b 100644 --- a/x-net/src/main/java/javax/net/ssl/TrustManagerFactorySpi.java +++ b/x-net/src/main/java/javax/net/ssl/TrustManagerFactorySpi.java @@ -24,40 +24,35 @@ import java.security.KeyStoreException; /** * The <i>Service Provider Interface</i> (SPI) for the * {@code TrustManagerFactory} class. - * - * @since Android 1.0 */ public abstract class TrustManagerFactorySpi { /** * Creates a new {@code TrustManagerFactorySpi} instance. - * - * @since Android 1.0 */ public TrustManagerFactorySpi() { + super(); } /** * Initializes this factory instance with the specified keystore as source * of certificate authorities and trust material. - * + * * @param ks * the keystore or {@code null}. * @throws KeyStoreException * if the initialization fails. - * @since Android 1.0 */ protected abstract void engineInit(KeyStore ks) throws KeyStoreException; /** * Initializes this factory instance with the specified provider-specific * parameters for a source of trust material. - * + * * @param spec * the provider-specific parameters. * @throws InvalidAlgorithmParameterException * if the initialization fails. - * @since Android 1.0 */ protected abstract void engineInit(ManagerFactoryParameters spec) throws InvalidAlgorithmParameterException; @@ -65,9 +60,8 @@ public abstract class TrustManagerFactorySpi { /** * Returns the list of {@code TrustManager}s with one entry for each type * of trust material. - * + * * @return the list of {@code TrustManager}s - * @since Android 1.0 */ protected abstract TrustManager[] engineGetTrustManagers(); -}
\ No newline at end of file +} diff --git a/x-net/src/main/java/javax/net/ssl/X509ExtendedKeyManager.java b/x-net/src/main/java/javax/net/ssl/X509ExtendedKeyManager.java index bd5570d..3298d8e 100644 --- a/x-net/src/main/java/javax/net/ssl/X509ExtendedKeyManager.java +++ b/x-net/src/main/java/javax/net/ssl/X509ExtendedKeyManager.java @@ -21,27 +21,22 @@ import java.security.Principal; /** * The abstract extension for the {@code X509KeyManager} interface. - * - * @since Android 1.0 */ public abstract class X509ExtendedKeyManager implements X509KeyManager { - + /** * To be used by subclasses only. * <p> * Creates a new {@code X509ExtendedKeyManager} instance. - * </p> - * - * @since Android 1.0 */ protected X509ExtendedKeyManager() { super(); } /** - * Chooses a alias for the client side of an SSL connection to authenticate + * Chooses an alias for the client side of an SSL connection to authenticate * it with the specified public key type and certificate issuers. - * + * * @param keyType * the list of public key algorithm names. * @param issuers @@ -52,7 +47,6 @@ public abstract class X509ExtendedKeyManager implements X509KeyManager { * no engine is predefined. * @return the alias name of a matching key or {@code null} if there are no * matches. - * @since Android 1.0 */ public String chooseEngineClientAlias(String[] keyType, Principal[] issuers, SSLEngine engine) { @@ -60,9 +54,9 @@ public abstract class X509ExtendedKeyManager implements X509KeyManager { } /** - * Chooses a alias for the server side of an SSL connection to authenticate + * Chooses an alias for the server side of an SSL connection to authenticate * it with the specified public key type and certificate issuers. - * + * * @param keyType * the list of public key algorithm names. * @param issuers @@ -73,11 +67,10 @@ public abstract class X509ExtendedKeyManager implements X509KeyManager { * no engine is predefined. * @return the alias name of a matching key or {@code null} if there are no * matches. - * @since Android 1.0 */ public String chooseEngineServerAlias(String keyType, Principal[] issuers, SSLEngine engine) { return null; } -}
\ No newline at end of file +} diff --git a/x-net/src/main/java/javax/net/ssl/X509KeyManager.java b/x-net/src/main/java/javax/net/ssl/X509KeyManager.java index f65ae4e..aebc427 100644 --- a/x-net/src/main/java/javax/net/ssl/X509KeyManager.java +++ b/x-net/src/main/java/javax/net/ssl/X509KeyManager.java @@ -24,15 +24,13 @@ import java.security.cert.X509Certificate; /** * A Key Manager for X509 certificate-based key pairs. - * - * @since Android 1.0 */ public interface X509KeyManager extends KeyManager { /** * Chooses an alias for the client side of an SSL connection to authenticate * it with the specified public key type and certificate issuers. - * + * * @param keyType * the list of public key algorithm names. * @param issuers @@ -43,7 +41,6 @@ public interface X509KeyManager extends KeyManager { * the alias selected does not depend on a specific socket. * @return the alias name of a matching key or {@code null} if there are no * matches. - * @since Android 1.0 */ public String chooseClientAlias(String[] keyType, Principal[] issuers, Socket socket); @@ -51,7 +48,7 @@ public interface X509KeyManager extends KeyManager { /** * Chooses an alias for the server side of an SSL connection to authenticate * it with the specified public key type and certificate issuers. - * + * * @param keyType * the list of public key algorithm type names. * @param issuers @@ -62,26 +59,24 @@ public interface X509KeyManager extends KeyManager { * the alias selected does not depend on a specific socket. * @return the alias name of a matching key or {@code null} if there are no * matches. - * @since Android 1.0 */ public String chooseServerAlias(String keyType, Principal[] issuers, Socket socket); /** * Returns the certificate chain for the specified alias. - * + * * @param alias * the alias to get the certificate chain for. * @return the certificate chain for the specified alias, or {@code null} if * the alias cannot be found. - * @since Android 1.0 */ public X509Certificate[] getCertificateChain(String alias); /** * Returns the client aliases for the specified public key type and list of * certificate issuers. - * + * * @param keyType * the public key algorithm type name. * @param issuers @@ -89,14 +84,13 @@ public interface X509KeyManager extends KeyManager { * will do. * @return the client aliases for the specified public key type, or * {@code null} if there are no matching aliases. - * @since Android 1.0 */ public String[] getClientAliases(String keyType, Principal[] issuers); /** * Returns the server aliases for the specified public key type and list of * certificate issuers. - * + * * @param keyType * the public key algorithm type name. * @param issuers @@ -104,18 +98,16 @@ public interface X509KeyManager extends KeyManager { * will do. * @return the client aliases for the specified public key type, or * {@code null} if there are no matching aliases. - * @since Android 1.0 */ public String[] getServerAliases(String keyType, Principal[] issuers); /** * Returns the private key for the specified alias. - * + * * @param alias * the alias to get the private key for. * @return the private key for the specified alias, or {@code null} if the * alias cannot be found. - * @since Android 1.0 */ public PrivateKey getPrivateKey(String alias); -}
\ No newline at end of file +} diff --git a/x-net/src/main/java/javax/net/ssl/X509TrustManager.java b/x-net/src/main/java/javax/net/ssl/X509TrustManager.java index 135c0e7..7d7827e 100644 --- a/x-net/src/main/java/javax/net/ssl/X509TrustManager.java +++ b/x-net/src/main/java/javax/net/ssl/X509TrustManager.java @@ -22,9 +22,7 @@ import java.security.cert.X509Certificate; /** * The trust manager for X509 certificates to be used to perform authentication - * for secure sockets. - * - * @since Android 1.0 + * for secure sockets. */ public interface X509TrustManager extends TrustManager { @@ -32,7 +30,7 @@ public interface X509TrustManager extends TrustManager { * Checks whether the specified certificate chain (partial or complete) can * be validated and is trusted for client authentication for the specified * authentication type. - * + * * @param chain * the certificate chain to validate. * @param authType @@ -43,7 +41,6 @@ public interface X509TrustManager extends TrustManager { * if the specified certificate chain is empty or {@code null}, * or if the specified authentication type is {@code null} or an * empty string. - * @since Android 1.0 */ public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException; @@ -53,7 +50,7 @@ public interface X509TrustManager extends TrustManager { * Checks whether the specified certificate chain (partial or complete) can * be validated and is trusted for server authentication for the specified * key exchange algorithm. - * + * * @param chain * the certificate chain to validate. * @param authType @@ -64,7 +61,6 @@ public interface X509TrustManager extends TrustManager { * if the specified certificate chain is empty or {@code null}, * or if the specified authentication type is {@code null} or an * empty string. - * @since Android 1.0 */ public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException; @@ -72,10 +68,9 @@ public interface X509TrustManager extends TrustManager { /** * Returns the list of certificate issuer authorities which are trusted for * authentication of peers. - * + * * @return the list of certificate issuer authorities which are trusted for * authentication of peers. - * @since Android 1.0 */ public X509Certificate[] getAcceptedIssuers(); -}
\ No newline at end of file +} diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/AlertException.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/AlertException.java index edf7638..f607364 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/AlertException.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/AlertException.java @@ -15,21 +15,17 @@ * limitations under the License. */ -/** - * @author Alexander Y. Kleymenov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; import javax.net.ssl.SSLException; /** - * This exception is used to signalize the fatal alert - * occured during the work of protocol. + * This exception is used to signal that a fatal alert has occurred while working through the + * protocol. */ public class AlertException extends RuntimeException { + private static final long serialVersionUID = -4448327177165687581L; // SSLException to be thrown to application side private final SSLException reason; // alert description code @@ -37,11 +33,11 @@ public class AlertException extends RuntimeException { /** * Constructs the instance. - * @param description: The alert description code. - * @see org.apache.harmony.xnet.provider.jsse.AlertProtocol - * @param reason: The SSLException to be thrown to application - * side after alert processing (sending the record with alert, - * shoutdown work, etc). + * + * @param description The alert description code from {@link AlertProtocol} + * @param reason The SSLException to be thrown to application side after alert processing + * (sending the record with alert, shutdown work, etc). + * @see AlertProtocol */ protected AlertException(byte description, SSLException reason) { super(reason); @@ -50,8 +46,8 @@ public class AlertException extends RuntimeException { } /** - * Returns the reason of alert. This reason should be rethrown - * after alert protcessin. + * Returns the reason of alert. This reason should be rethrown after alert processing. + * * @return the reason of alert. */ protected SSLException getReason() { @@ -60,9 +56,9 @@ public class AlertException extends RuntimeException { /** * Returns alert's description code. - * @return byte value describing the occured alert. - * @see org.apache.harmony.xnet.provider.jsse.AlertProtocol for more information about possible - * reason codes. + * + * @return alert description code from {@link AlertProtocol} + * @see AlertProtocol for more information about possible reason codes. */ protected byte getDescriptionCode() { return description; diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/AlertProtocol.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/AlertProtocol.java index 8f10875..a12d00a 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/AlertProtocol.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/AlertProtocol.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** - * @author Alexander Y. Kleymenov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; import org.apache.harmony.xnet.provider.jsse.SSLRecordProtocol; @@ -136,8 +131,6 @@ public class AlertProtocol { * Defines the description code of the no_renegotiation alert */ protected static final byte NO_RENEGOTIATION = 100; - - // holds level and description codes private final byte[] alert = new byte[2]; // record protocol to be used to wrap the alerts @@ -271,7 +264,7 @@ public class AlertProtocol { /** * Returns the record with reported alert message. * The returned array of bytes is ready to be sent to another peer. - * Note, that this method does not automatically set the state of allert + * Note, that this method does not automatically set the state of alert * protocol in "no alert" state, so after wrapping the method setProcessed * should be called. */ @@ -281,7 +274,7 @@ public class AlertProtocol { } /** - * Shutdownes the protocol. It will be impossiblke to use the instance + * Shutdown the protocol. It will be impossible to use the instance * after the calling of this method. */ protected void shutdown() { diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/Appendable.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/Appendable.java index 1485bae..070f42a 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/Appendable.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/Appendable.java @@ -15,24 +15,19 @@ * limitations under the License. */ -/** - * @author Alexander Y. Kleymenov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; /** - * This interface represents the ability of the input stream related - * classes to provide additianal data to be read. + * This interface represents the ability of the input stream related classes to provide additional + * data to be read. */ public interface Appendable { /** * Provides the additional data to be read. - * @param src: the source data to be appended. + * + * @param src the source data to be appended. */ public void append(byte[] src); } - diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/CertificateMessage.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/CertificateMessage.java index 6aac128..8065860 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/CertificateMessage.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/CertificateMessage.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** - * @author Boris Kuznetsov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; import org.apache.harmony.xnet.provider.jsse.Message; @@ -28,6 +23,7 @@ import org.apache.harmony.xnet.provider.jsse.HandshakeIODataStream; import org.apache.harmony.xnet.provider.jsse.AlertProtocol; import java.io.IOException; +import java.security.cert.Certificate; import java.security.cert.CertificateEncodingException; import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; @@ -35,7 +31,6 @@ import java.security.cert.X509Certificate; import java.util.Vector; /** - * * Represents server/client certificate message * @see <a href="http://www.ietf.org/rfc/rfc2246.txt">TLS * 1.0 spec., 7.4.2. Server certificate; 7.4.6. Client certificate</a> @@ -80,7 +75,7 @@ public class CertificateMessage extends Message { fatalAlert(AlertProtocol.INTERNAL_ERROR, "INTERNAL ERROR", e); return; } - Vector certs_vector = new Vector(); + Vector<Certificate> certs_vector = new Vector<Certificate>(); int size = 0; int enc_size = 0; while (l > 0) { @@ -141,6 +136,7 @@ public class CertificateMessage extends Message { * * @param out */ + @Override public void send(HandshakeIODataStream out) { int total_length = 0; @@ -172,6 +168,7 @@ public class CertificateMessage extends Message { * * @return */ + @Override public int getType() { return Handshake.CERTIFICATE; } diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/CertificateRequest.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/CertificateRequest.java index 8bedccd..7b27787 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/CertificateRequest.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/CertificateRequest.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** - * @author Boris Kuznetsov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; import org.apache.harmony.xnet.provider.jsse.Message; @@ -110,7 +105,7 @@ public class CertificateRequest extends Message { certificate_authorities = new X500Principal[size]; int totalPrincipalsLength = 0; int principalLength = 0; - Vector principals = new Vector(); + Vector<X500Principal> principals = new Vector<X500Principal>(); while (totalPrincipalsLength < size) { principalLength = in.readUint16(); // encoded X500Principal size principals.add(new X500Principal(in)); @@ -119,7 +114,7 @@ public class CertificateRequest extends Message { } certificate_authorities = new X500Principal[principals.size()]; for (int i = 0; i < certificate_authorities.length; i++) { - certificate_authorities[i] = (X500Principal) principals.elementAt(i); + certificate_authorities[i] = principals.elementAt(i); } this.length = 3 + certificate_types.length + totalPrincipalsLength; if (this.length != length) { @@ -134,6 +129,7 @@ public class CertificateRequest extends Message { * * @param out */ + @Override public void send(HandshakeIODataStream out) { out.writeUint8(certificate_types.length); @@ -156,6 +152,7 @@ public class CertificateRequest extends Message { * * @return */ + @Override public int getType() { return Handshake.CERTIFICATE_REQUEST; } diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/CertificateVerify.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/CertificateVerify.java index 183b8aa..9b18ecb 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/CertificateVerify.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/CertificateVerify.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** - * @author Boris Kuznetsov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; import org.apache.harmony.xnet.provider.jsse.Message; @@ -30,7 +25,6 @@ import org.apache.harmony.xnet.provider.jsse.AlertProtocol; import java.io.IOException; /** - * * Represents certificate verify message * @see <a href="http://www.ietf.org/rfc/rfc2246.txt">TLS 1.0 spec., 7.4.8. * Certificate verify</a> @@ -83,6 +77,7 @@ public class CertificateVerify extends Message { * * @param out */ + @Override public void send(HandshakeIODataStream out) { if (signedHash.length != 0) { out.writeUint16(signedHash.length); @@ -95,6 +90,7 @@ public class CertificateVerify extends Message { * * @return */ + @Override public int getType() { return Handshake.CERTIFICATE_VERIFY; } diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/CipherSuite.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/CipherSuite.java index 8352386..f084195 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/CipherSuite.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/CipherSuite.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** - * @author Boris Kuznetsov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; import java.security.GeneralSecurityException; @@ -277,29 +272,29 @@ public class CipherSuite { }; // hash for quick access to cipher suite by name - private static Hashtable cuitesByName; + private static Hashtable<String, CipherSuite> cuitesByName; /** - * array of supported sipher suites. + * array of supported cipher suites. * Set of supported suites is defined at the moment provider's start */ -// TODO Dinamical supported suites: new providers may be dynamically -// added/removed and the set of supportes suites may be changed +// TODO Dynamically supported suites: new providers may be dynamically +// added/removed and the set of supported suites may be changed static CipherSuite[] supportedCipherSuites; /** - * array of supported sipher suites names + * array of supported cipher suites names */ static String[] supportedCipherSuiteNames; /** - * default sipher suites + * default cipher suites */ static CipherSuite[] defaultCipherSuites; static { int count = 0; - cuitesByName = new Hashtable(); + cuitesByName = new Hashtable<String, CipherSuite>(); for (int i = 0; i < cuitesByCode.length; i++) { cuitesByName.put(cuitesByCode[i].getName(), cuitesByCode[i]); if (cuitesByCode[i].supported) { @@ -353,7 +348,7 @@ public class CipherSuite { * @return */ public static CipherSuite getByName(String name) { - return (CipherSuite) cuitesByName.get(name); + return cuitesByName.get(name); } /** @@ -364,8 +359,8 @@ public class CipherSuite { * @return */ public static CipherSuite getByCode(byte b1, byte b2) { - if (b1 != 0 || b2 > cuitesByCode.length) { - // Unknoun + if (b1 != 0 || (b2 & 0xFF) > cuitesByCode.length) { + // Unknown return new CipherSuite("UNKNOUN_" + b1 + "_" + b2, false, 0, "", "", new byte[] { b1, b2 }); } @@ -383,7 +378,7 @@ public class CipherSuite { */ public static CipherSuite getByCode(byte b1, byte b2, byte b3) { if (b1 == 0 && b2 == 0) { - if (b3 <= cuitesByCode.length) { + if ((b3 & 0xFF) <= cuitesByCode.length) { return cuitesByCode[b3]; } } @@ -523,7 +518,7 @@ public class CipherSuite { * @return */ public static String[] getSupportedCipherSuiteNames() { - return (String[]) supportedCipherSuiteNames.clone(); + return supportedCipherSuiteNames.clone(); } /** @@ -545,6 +540,7 @@ public class CipherSuite { /** * Returns cipher suite description */ + @Override public String toString() { return name + ": " + cipherSuiteCode[0] + " " + cipherSuiteCode[1]; } @@ -552,6 +548,7 @@ public class CipherSuite { /** * Compares this cipher suite to the specified object. */ + @Override public boolean equals(Object obj) { if (obj instanceof CipherSuite && this.cipherSuiteCode[0] == ((CipherSuite) obj).cipherSuiteCode[0] @@ -610,3 +607,4 @@ public class CipherSuite { } } + diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientHandshakeImpl.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientHandshakeImpl.java index 55a06f5..b488a0e 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientHandshakeImpl.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientHandshakeImpl.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** - * @author Boris Kuznetsov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; import java.io.IOException; @@ -52,7 +47,7 @@ import javax.net.ssl.X509ExtendedKeyManager; * Handshake protocol operates on top of the Record Protocol. * It is responsible for session negotiating. * - * The implementation proceses inbound server handshake messages, + * The implementation processes inbound server handshake messages, * creates and sends respond messages. Outbound messages are supplied * to Record Protocol. Detected errors are reported to the Alert protocol. * @@ -75,6 +70,7 @@ public class ClientHandshakeImpl extends HandshakeProtocol { * Starts handshake * */ + @Override public void start() { if (session == null) { // initial handshake session = findSessionToResume(); @@ -139,9 +135,10 @@ public class ClientHandshakeImpl extends HandshakeProtocol { } /** - * Proceses inbound handshake messages + * Processes inbound handshake messages * @param bytes */ + @Override public void unwrap(byte[] bytes) { if (this.delegatedTaskErr != null) { Exception e = this.delegatedTaskErr; @@ -248,7 +245,7 @@ public class ClientHandshakeImpl extends HandshakeProtocol { session.protocol = servProt; recordProtocol.setVersion(session.protocol.version); session.cipherSuite = serverHello.cipher_suite; - session.id = (byte[]) serverHello.session_id.clone(); + session.id = serverHello.session_id.clone(); session.serverRandom = serverHello.random; break; case 11: // CERTIFICATE @@ -285,15 +282,12 @@ public class ClientHandshakeImpl extends HandshakeProtocol { } serverHelloDone = new ServerHelloDone(io_stream, length); if (this.nonBlocking) { - delegatedTasks.add(new DelegatedTask( - new PrivilegedExceptionAction(){ - public Object run() throws Exception { + delegatedTasks.add(new DelegatedTask(new PrivilegedExceptionAction<Void>() { + public Void run() throws Exception { processServerHelloDone(); return null; - } - }, - this, - AccessController.getContext())); + } + }, this, AccessController.getContext())); return; } processServerHelloDone(); @@ -338,6 +332,7 @@ public class ClientHandshakeImpl extends HandshakeProtocol { * @ see TLS 1.0 spec., E.1. Version 2 client hello * @param bytes */ + @Override public void unwrapSSLv2(byte[] bytes) { unexpectedMessage(); } @@ -345,6 +340,7 @@ public class ClientHandshakeImpl extends HandshakeProtocol { /** * Creates and sends Finished message */ + @Override protected void makeFinished() { byte[] verify_data; if (serverHello.server_version[1] == 1) { @@ -591,8 +587,9 @@ public class ClientHandshakeImpl extends HandshakeProtocol { } /** - * Proceses ChangeCipherSpec message + * Processes ChangeCipherSpec message */ + @Override public void receiveChangeCipherSpec() { if (isResuming) { if (serverHello == null) { @@ -628,3 +625,4 @@ public class ClientHandshakeImpl extends HandshakeProtocol { } } + diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientHello.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientHello.java index aa811fb..5764105 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientHello.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientHello.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Boris Kuznetsov -* @version $Revision$ -*/ - package org.apache.harmony.xnet.provider.jsse; import java.io.IOException; @@ -27,7 +22,6 @@ import java.security.SecureRandom; import java.util.Arrays; /** - * * Represents Client Hello message * @see <a href="http://www.ietf.org/rfc/rfc2246.txt">TLS 1.0 spec., 7.4.1.2. * Client hello</a> @@ -176,6 +170,7 @@ public class ClientHello extends Message { * Sends message * @param out */ + @Override public void send(HandshakeIODataStream out) { out.write(client_version); out.write(random); @@ -204,6 +199,7 @@ public class ClientHello extends Message { * Returns message type * @return */ + @Override public int getType() { return Handshake.CLIENT_HELLO; } diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientKeyExchange.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientKeyExchange.java index a208456..af751c2 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientKeyExchange.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientKeyExchange.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Boris Kuznetsov -* @version $Revision$ -*/ - package org.apache.harmony.xnet.provider.jsse; import org.apache.harmony.xnet.provider.jsse.Message; @@ -30,7 +25,6 @@ import java.io.IOException; import java.math.BigInteger; /** - * * Represents client key exchange message * @see <a href="http://www.ietf.org/rfc/rfc2246.txt">TLS 1.0 spec., 7.4.7. * Client key exchange message</a> @@ -129,6 +123,7 @@ public class ClientKeyExchange extends Message { * Sends message * @param out */ + @Override public void send(HandshakeIODataStream out) { if (exchange_keys.length != 0) { if (!isRSA || isTLS) {// DH or TLSv1 RSA @@ -142,6 +137,7 @@ public class ClientKeyExchange extends Message { * Returns message type * @return */ + @Override public int getType() { return Handshake.CLIENT_KEY_EXCHANGE; } diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ConnectionState.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ConnectionState.java index 63bad5d..49a7af9 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ConnectionState.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ConnectionState.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** - * @author Alexander Y. Kleymenov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; import org.apache.harmony.xnet.provider.jsse.Logger; diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ConnectionStateSSLv3.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ConnectionStateSSLv3.java index 078bf58..07bd340 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ConnectionStateSSLv3.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ConnectionStateSSLv3.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** - * @author Alexander Y. Kleymenov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; import java.security.GeneralSecurityException; @@ -31,7 +26,7 @@ import javax.crypto.spec.SecretKeySpec; import javax.net.ssl.SSLProtocolException; /** - * This class incapsulates the operating environment of the SSL v3 + * This class encapsulates the operating environment of the SSL v3 * (http://wp.netscape.com/eng/ssl3) Record Protocol and provides * relating encryption/decryption functionality. * The work functionality is based on the security @@ -218,8 +213,9 @@ public class ConnectionStateSSLv3 extends ConnectionState { /** * Creates the GenericStreamCipher or GenericBlockCipher * data structure for specified data of specified type. - * @throws org.apache.harmony.xnet.provider.jsse.AlertException if alert was occured. + * @throws AlertException if alert was occurred. */ + @Override protected byte[] encrypt(byte type, byte[] fragment, int offset, int len) { try { int content_mac_length = len + hash_size; @@ -282,6 +278,7 @@ public class ConnectionStateSSLv3 extends ConnectionState { * the specified type from the provided data. * @throws AlertException if alert was occured. */ + @Override protected byte[] decrypt(byte type, byte[] fragment, int offset, int len) { // plain data of the Generic[Stream|Block]Cipher structure @@ -344,9 +341,10 @@ public class ConnectionStateSSLv3 extends ConnectionState { } /** - * Shutdownes the protocol. It will be impossiblke to use the instance + * Shutdown the protocol. It will be impossible to use the instance * after the calling of this method. */ + @Override protected void shutdown() { Arrays.fill(mac_write_secret, (byte) 0); Arrays.fill(mac_read_secret, (byte) 0); diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ConnectionStateTLS.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ConnectionStateTLS.java index 1b21b17..949e655 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ConnectionStateTLS.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ConnectionStateTLS.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** - * @author Alexander Y. Kleymenov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; import org.apache.harmony.xnet.provider.jsse.AlertException; @@ -36,7 +31,7 @@ import javax.crypto.spec.SecretKeySpec; import javax.net.ssl.SSLProtocolException; /** - * This class incapsulates the operating environment of the TLS v1 + * This class encapsulates the operating environment of the TLS v1 * (http://www.ietf.org/rfc/rfc2246.txt) Record Protocol and provides * relating encryption/decryption functionality. * The work functionality is based on the security @@ -44,7 +39,7 @@ import javax.net.ssl.SSLProtocolException; */ public class ConnectionStateTLS extends ConnectionState { - // Precomputed prf label values: + // Pre-calculated prf label values: // "key expansion".getBytes() private static byte[] KEY_EXPANSION_LABEL = { (byte) 0x6B, (byte) 0x65, (byte) 0x79, (byte) 0x20, (byte) 0x65, @@ -235,8 +230,9 @@ public class ConnectionStateTLS extends ConnectionState { /** * Creates the GenericStreamCipher or GenericBlockCipher * data structure for specified data of specified type. - * @throws org.apache.harmony.xnet.provider.jsse.AlertException if alert was occured. + * @throws AlertException if alert was occurred. */ + @Override protected byte[] encrypt(byte type, byte[] fragment, int offset, int len) { try { int content_mac_length = len + hash_size; @@ -298,8 +294,9 @@ public class ConnectionStateTLS extends ConnectionState { * Retrieves the fragment of the Plaintext structure of * the specified type from the provided data representing * the Generic[Stream|Block]Cipher structure. - * @throws org.apache.harmony.xnet.provider.jsse.AlertException if alert was occured. + * @throws AlertException if alert was occurred. */ + @Override protected byte[] decrypt(byte type, byte[] fragment, int offset, int len) { // plain data of the Generic[Stream|Block]Cipher structure diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ContentType.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ContentType.java index dedfe64..69704f5 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ContentType.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ContentType.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** - * @author Alexander Y. Kleymenov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; /** diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/DHParameters.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/DHParameters.java index 1a441a5..441fc5f 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/DHParameters.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/DHParameters.java @@ -14,11 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/** - * @author Boris Kuznetsov - * @version $Revision$ - */ package org.apache.harmony.xnet.provider.jsse; /** diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/DataStream.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/DataStream.java index b52b838..ffc8612 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/DataStream.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/DataStream.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** - * @author Alexander Y. Kleymenov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; /** diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/DelegatedTask.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/DelegatedTask.java index ea6ba78..3b2e103 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/DelegatedTask.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/DelegatedTask.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** - * @author Boris Kuznetsov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; import org.apache.harmony.xnet.provider.jsse.HandshakeProtocol; @@ -35,7 +30,7 @@ import java.security.PrivilegedExceptionAction; public class DelegatedTask implements Runnable { private final HandshakeProtocol handshaker; - private final PrivilegedExceptionAction action; + private final PrivilegedExceptionAction<Void> action; private final AccessControlContext context; /** @@ -44,7 +39,7 @@ public class DelegatedTask implements Runnable { * @param handshaker * @param context */ - public DelegatedTask(PrivilegedExceptionAction action, HandshakeProtocol handshaker, AccessControlContext context) { + public DelegatedTask(PrivilegedExceptionAction<Void> action, HandshakeProtocol handshaker, AccessControlContext context) { this.action = action; this.handshaker = handshaker; this.context = context; diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/DigitalSignature.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/DigitalSignature.java index a8794df..a0f18b4 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/DigitalSignature.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/DigitalSignature.java @@ -14,26 +14,26 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/** - * @author Boris Kuznetsov - * @version $Revision$ - */ package org.apache.harmony.xnet.provider.jsse; -import org.apache.harmony.xnet.provider.jsse.AlertException; - +import java.security.DigestException; +import java.security.InvalidKeyException; import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; import java.security.Signature; +import java.security.SignatureException; import java.security.cert.Certificate; import java.util.Arrays; +import javax.crypto.BadPaddingException; import javax.crypto.Cipher; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; import javax.net.ssl.SSLException; /** - * This class represents Signature type, as descrybed in TLS v 1.0 Protocol + * This class represents Signature type, as described in TLS v 1.0 Protocol * specification, 7.4.3. It allow to init, update and sign hash. Hash algorithm * depends on SignatureAlgorithm. * @@ -56,10 +56,10 @@ import javax.net.ssl.SSLException; */ public class DigitalSignature { - private MessageDigest md5 = null; - private MessageDigest sha = null; - private Signature signature = null; - private Cipher cipher = null; + private final MessageDigest md5; + private final MessageDigest sha; + private final Signature signature; + private final Cipher cipher; private byte[] md5_hash; private byte[] sha_hash; @@ -69,33 +69,35 @@ public class DigitalSignature { * @param keyExchange */ public DigitalSignature(int keyExchange) { - try { + try { + sha = MessageDigest.getInstance("SHA-1"); + if (keyExchange == CipherSuite.KeyExchange_RSA_EXPORT || keyExchange == CipherSuite.KeyExchange_RSA || keyExchange == CipherSuite.KeyExchange_DHE_RSA || keyExchange == CipherSuite.KeyExchange_DHE_RSA_EXPORT) { // SignatureAlgorithm is rsa md5 = MessageDigest.getInstance("MD5"); - sha = MessageDigest.getInstance("SHA-1"); cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); + signature = null; } else if (keyExchange == CipherSuite.KeyExchange_DHE_DSS || keyExchange == CipherSuite.KeyExchange_DHE_DSS_EXPORT ) { // SignatureAlgorithm is dsa - sha = MessageDigest.getInstance("SHA-1"); signature = Signature.getInstance("NONEwithDSA"); -// The Signature should be empty in case of anonimous signature algorithm: -// } else if (keyExchange == CipherSuite.KeyExchange_DH_anon || -// keyExchange == CipherSuite.KeyExchange_DH_anon_EXPORT) { -// + cipher = null; + md5 = null; + } else { + cipher = null; + signature = null; + md5 = null; } - } catch (Exception e) { - throw new AlertException( - AlertProtocol.INTERNAL_ERROR, - new SSLException( - "INTERNAL ERROR: Unexpected exception on digital signature", - e)); - } - + } catch (NoSuchAlgorithmException e) { + // this should never happen + throw new AssertionError(e); + } catch (NoSuchPaddingException e) { + // this should never happen + throw new AssertionError(e); + } } /** @@ -109,8 +111,9 @@ public class DigitalSignature { } else if (cipher != null) { cipher.init(Cipher.ENCRYPT_MODE, key); } - } catch (Exception e){ - e.printStackTrace(); + } catch (InvalidKeyException e){ + throw new AlertException(AlertProtocol.BAD_CERTIFICATE, + new SSLException("init - invalid private key", e)); } } @@ -125,8 +128,9 @@ public class DigitalSignature { } else if (cipher != null) { cipher.init(Cipher.DECRYPT_MODE, cert); } - } catch (Exception e){ - e.printStackTrace(); + } catch (InvalidKeyException e){ + throw new AlertException(AlertProtocol.BAD_CERTIFICATE, + new SSLException("init - invalid certificate", e)); } } @@ -135,16 +139,12 @@ public class DigitalSignature { * @param data */ public void update(byte[] data) { - try { - if (sha != null) { - sha.update(data); - } - if (md5 != null) { - md5.update(data); - } - } catch (Exception e){ - e.printStackTrace(); - } + if (sha != null) { + sha.update(data); + } + if (md5 != null) { + md5.update(data); + } } /** @@ -197,10 +197,15 @@ public class DigitalSignature { return cipher.doFinal(); } return new byte[0]; - } catch (Exception e){ - e.printStackTrace(); + } catch (DigestException e){ + return new byte[0]; + } catch (SignatureException e){ + return new byte[0]; + } catch (BadPaddingException e){ return new byte[0]; - } + } catch (IllegalBlockSizeException e){ + return new byte[0]; + } } /** @@ -209,34 +214,40 @@ public class DigitalSignature { * @return true if verified */ public boolean verifySignature(byte[] data) { - try { - if (signature != null) { + if (signature != null) { + try { return signature.verify(data); - } else if (cipher != null) { - byte[] decrypt = cipher.doFinal(data); - byte[] md5_sha; - if (md5_hash != null && sha_hash != null) { - md5_sha = new byte[md5_hash.length + sha_hash.length]; - System.arraycopy(md5_hash, 0, md5_sha, 0, md5_hash.length); - System.arraycopy(sha_hash, 0, md5_sha, md5_hash.length, sha_hash.length); - } else if (md5_hash != null) { - md5_sha = md5_hash; - } else { - md5_sha = sha_hash; - } - if (Arrays.equals(decrypt, md5_sha)) { - return true; - } else { - return false; - } - } else if (data == null || data.length == 0) { - return true; - } else { + } catch (SignatureException e) { return false; } - } catch (Exception e){ - e.printStackTrace(); + } + + if (cipher != null) { + final byte[] decrypt; + try { + decrypt = cipher.doFinal(data); + } catch (IllegalBlockSizeException e) { + return false; + } catch (BadPaddingException e) { return false; + } + + final byte[] md5_sha; + if (md5_hash != null && sha_hash != null) { + md5_sha = new byte[md5_hash.length + sha_hash.length]; + System.arraycopy(md5_hash, 0, md5_sha, 0, md5_hash.length); + System.arraycopy(sha_hash, 0, md5_sha, md5_hash.length, sha_hash.length); + } else if (md5_hash != null) { + md5_sha = md5_hash; + } else { + md5_sha = sha_hash; + } + + return Arrays.equals(decrypt, md5_sha); + } else if (data == null || data.length == 0) { + return true; + } else { + return false; } } diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/EndOfBufferException.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/EndOfBufferException.java index b2bcafe..1dcdd20 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/EndOfBufferException.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/EndOfBufferException.java @@ -15,25 +15,18 @@ * limitations under the License. */ -/** - * @author Alexander Y. Kleymenov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; import java.io.IOException; /** - * This class represents the exception signalizing that - * data could not be read from the stream because - * underlying input stream reached its end. + * This exception indicates that data could not be read from the stream because the underlying input + * stream reached its end. */ public class EndOfBufferException extends IOException { - /** - * Constructor - */ + private static final long serialVersionUID = 1838636631255369519L; + public EndOfBufferException() { super(); } diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/EndOfSourceException.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/EndOfSourceException.java index fbc1eaf..631679a 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/EndOfSourceException.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/EndOfSourceException.java @@ -15,28 +15,20 @@ * limitations under the License. */ -/** - * @author Alexander Y. Kleymenov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; import java.io.IOException; /** - * This class represents the exception signalizing that - * data could not be read from the buffered stream because - * underlying data buffer was exhausted. + * This exception indicates that data could not be read from the buffered stream because underlying + * data buffer was exhausted. */ public class EndOfSourceException extends IOException { - /** - * Constructor - */ + private static final long serialVersionUID = -4673611435974054413L; + public EndOfSourceException() { super(); } } - diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/Finished.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/Finished.java index d0f1fe1..6b555c6 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/Finished.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/Finished.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Boris Kuznetsov -* @version $Revision$ -*/ - package org.apache.harmony.xnet.provider.jsse; import org.apache.harmony.xnet.provider.jsse.Message; @@ -63,6 +58,7 @@ public class Finished extends Message { } } + @Override public void send(HandshakeIODataStream out) { out.write(data); } @@ -71,6 +67,7 @@ public class Finished extends Message { * Returns message type * @return */ + @Override public int getType() { return Handshake.FINISHED; } diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/Handshake.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/Handshake.java index 4668b8c..64e73dd 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/Handshake.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/Handshake.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** - * @author Boris Kuznetsov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; /** diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/HandshakeIODataStream.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/HandshakeIODataStream.java index b5c4553..74cc27d 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/HandshakeIODataStream.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/HandshakeIODataStream.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** - * @author Alexander Y. Kleymenov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; import org.apache.harmony.xnet.provider.jsse.AlertException; @@ -101,14 +96,17 @@ public class HandshakeIODataStream // position of the last byte to read + 1 private int read_pos_end; + @Override public int available() { return read_pos_end - read_pos; } + @Override public boolean markSupported() { return true; } + @Override public void mark(int limit) { marked_pos = read_pos; } @@ -117,6 +115,7 @@ public class HandshakeIODataStream marked_pos = read_pos; } + @Override public void reset() { read_pos = marked_pos; } @@ -138,6 +137,7 @@ public class HandshakeIODataStream * @param byte: byte * @return */ + @Override public int read() throws IOException { if (read_pos == read_pos_end) { //return -1; @@ -151,6 +151,7 @@ public class HandshakeIODataStream * @param new: long * @return */ + @Override public byte[] read(int length) throws IOException { if (length > available()) { throw new EndOfBufferException(); @@ -161,6 +162,7 @@ public class HandshakeIODataStream return res; } + @Override public int read(byte[] dest, int offset, int length) throws IOException { if (length > available()) { throw new EndOfBufferException(); @@ -174,7 +176,7 @@ public class HandshakeIODataStream /** * Appends the income data to be read by handshake protocol. - * The attempts to overflow the buffer by meens of this methos + * The attempts to overflow the buffer by means of this methods * seem to be futile because of: * 1. The SSL protocol specifies the maximum size of the record * and record protocol does not pass huge messages. diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/HandshakeProtocol.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/HandshakeProtocol.java index 606e5c7..6579398 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/HandshakeProtocol.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/HandshakeProtocol.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** - * @author Boris Kuznetsov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; import java.math.BigInteger; @@ -89,7 +84,7 @@ public abstract class HandshakeProtocol { /** * Delegated tasks for this handshake implementation */ - protected Vector delegatedTasks = new Vector(); + protected Vector<DelegatedTask> delegatedTasks = new Vector<DelegatedTask>(); /** * Indicates non-blocking handshake @@ -169,13 +164,13 @@ public abstract class HandshakeProtocol { if (owner instanceof SSLEngineImpl) { engineOwner = (SSLEngineImpl) owner; nonBlocking = true; - this.parameters = (SSLParameters) engineOwner.sslParameters; + this.parameters = engineOwner.sslParameters; } // BEGIN android-removed // else if (owner instanceof SSLSocketImpl) { // socketOwner = (SSLSocketImpl) owner; // nonBlocking = false; - // this.parameters = (SSLParameters) socketOwner.sslParameters; + // this.parameters = socketOwner.sslParameters; // } // END android-removed } @@ -482,11 +477,8 @@ public abstract class HandshakeProtocol { public Runnable getTask() { if (delegatedTasks.isEmpty()) { return null; - } else { - Runnable task = (Runnable)delegatedTasks.firstElement(); - delegatedTasks.remove(0); - return task; } + return delegatedTasks.remove(0); } /** @@ -523,7 +515,7 @@ public abstract class HandshakeProtocol { mod = ((RSAKey) pk).getModulus(); } else { KeyFactory kf = KeyFactory.getInstance("RSA"); - mod = ((RSAPublicKeySpec) kf.getKeySpec(pk, RSAPublicKeySpec.class)) + mod = kf.getKeySpec(pk, RSAPublicKeySpec.class) .getModulus(); } return mod.bitLength(); diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/HelloRequest.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/HelloRequest.java index 2ce4061..40d4a71 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/HelloRequest.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/HelloRequest.java @@ -15,10 +15,6 @@ * limitations under the License. */ -/** -* @author Boris Kuznetsov -* @version $Revision$ -*/ package org.apache.harmony.xnet.provider.jsse; import org.apache.harmony.xnet.provider.jsse.Message; @@ -60,9 +56,11 @@ public class HelloRequest extends Message { * Sends message * @param out */ + @Override public void send(HandshakeIODataStream out) { } + @Override public int length() { return 0; } @@ -71,6 +69,7 @@ public class HelloRequest extends Message { * Returns message type * @return */ + @Override public int getType() { return Handshake.HELLO_REQUEST; } diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/JSSEProvider.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/JSSEProvider.java index e65f832..33b0a45 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/JSSEProvider.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/JSSEProvider.java @@ -15,14 +15,10 @@ * limitations under the License. */ -/** - * @author Alexander Y. Kleymenov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; import java.security.AccessController; +import java.security.PrivilegedAction; import java.security.Provider; /** @@ -67,7 +63,7 @@ import java.security.Provider; * TLS_DH_anon_WITH_DES_CBC_SHA * TLS_DH_anon_WITH_3DES_EDE_CBC_SHA * - * The real set of availible cipher suites depends on set of availible + * The real set of available cipher suites depends on set of available * crypto algorithms. These algorithms must be provided by some crypto * provider. * @@ -108,17 +104,16 @@ import java.security.Provider; */ public final class JSSEProvider extends Provider { + private static final long serialVersionUID = 3075686092260669675L; + public JSSEProvider() { super("HarmonyJSSE", 1.0, "Harmony JSSE Provider"); - AccessController.doPrivileged(new java.security.PrivilegedAction<Void>() { + AccessController.doPrivileged(new PrivilegedAction<Void>() { public Void run() { - put("SSLContext.TLS", - "org.apache.harmony.xnet.provider.jsse.SSLContextImpl"); + put("SSLContext.TLS", SSLContextImpl.class.getName()); put("Alg.Alias.SSLContext.TLSv1", "TLS"); - put("KeyManagerFactory.X509", - "org.apache.harmony.xnet.provider.jsse.KeyManagerFactoryImpl"); - put("TrustManagerFactory.X509", - "org.apache.harmony.xnet.provider.jsse.TrustManagerFactoryImpl"); + put("KeyManagerFactory.X509", KeyManagerFactoryImpl.class.getName()); + put("TrustManagerFactory.X509", TrustManagerFactoryImpl.class.getName()); // BEGIN android-added put("MessageDigest.SHA-1", "org.apache.harmony.xnet.provider.jsse.OpenSSLMessageDigestJDK$SHA1"); put("Alg.Alias.MessageDigest.SHA1", "SHA-1"); @@ -138,4 +133,3 @@ public final class JSSEProvider extends Provider { }); } } - diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/KeyManagerFactoryImpl.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/KeyManagerFactoryImpl.java index 1daf80c..3b55299 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/KeyManagerFactoryImpl.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/KeyManagerFactoryImpl.java @@ -14,11 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/** - * @author Boris Kuznetsov - * @version $Revision$ - */ package org.apache.harmony.xnet.provider.jsse; import java.io.File; @@ -53,13 +48,14 @@ public class KeyManagerFactoryImpl extends KeyManagerFactorySpi { * @see javax.net.ssl.KeyManagerFactorySpi#engineInit(KeyStore ks, char[] * password) */ + @Override public void engineInit(KeyStore ks, char[] password) throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException { if (ks != null) { keyStore = ks; if (password != null) { - pwd = (char[]) password.clone(); + pwd = password.clone(); } else { pwd = new char[0]; } @@ -115,6 +111,7 @@ public class KeyManagerFactoryImpl extends KeyManagerFactorySpi { * @see javax.net.ssl.KeyManagerFactorySpi#engineInit(ManagerFactoryParameters * spec) */ + @Override public void engineInit(ManagerFactoryParameters spec) throws InvalidAlgorithmParameterException { throw new InvalidAlgorithmParameterException( @@ -125,6 +122,7 @@ public class KeyManagerFactoryImpl extends KeyManagerFactorySpi { /** * @see javax.net.ssl.KeyManagerFactorySpi#engineGetKeyManagers() */ + @Override public KeyManager[] engineGetKeyManagers() { if (keyStore == null) { throw new IllegalStateException("KeyManagerFactory is not initialized"); diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/KeyManagerImpl.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/KeyManagerImpl.java index b7451d5..f63170f 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/KeyManagerImpl.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/KeyManagerImpl.java @@ -14,11 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/** - * @author Boris Kuznetsov - * @version $Revision$ - */ package org.apache.harmony.xnet.provider.jsse; import java.net.Socket; @@ -28,6 +23,7 @@ import java.security.NoSuchAlgorithmException; import java.security.Principal; import java.security.PrivateKey; import java.security.UnrecoverableEntryException; +import java.security.KeyStore.PrivateKeyEntry; import java.security.cert.Certificate; import java.security.cert.X509Certificate; import java.util.Enumeration; @@ -40,11 +36,11 @@ import javax.security.auth.x500.X500Principal; /** * KeyManager implementation. - * This implementation uses hashed key store information. - * It works faster than retrieving all of the data from the key store. - * Any key store changes, that happen after key manager was created, have no effect. - * The implementation does not use peer information (host, port) - * that may be obtained from socket or engine. + * + * This implementation uses hashed key store information. It works faster than retrieving all of the + * data from the key store. Any key store changes, that happen after key manager was created, have + * no effect. The implementation does not use peer information (host, port) that may be obtained + * from socket or engine. * * @see javax.net.ssl.KeyManager * @@ -52,7 +48,7 @@ import javax.security.auth.x500.X500Principal; public class KeyManagerImpl extends X509ExtendedKeyManager { // hashed key store information - private final Hashtable hash = new Hashtable(); + private final Hashtable<String, PrivateKeyEntry> hash; /** * Creates Key manager @@ -61,21 +57,20 @@ public class KeyManagerImpl extends X509ExtendedKeyManager { * @param pwd */ public KeyManagerImpl(KeyStore keyStore, char[] pwd) { - String alias; - KeyStore.PrivateKeyEntry entry; - Enumeration aliases; + super(); + this.hash = new Hashtable<String, PrivateKeyEntry>(); + final Enumeration<String> aliases; try { aliases = keyStore.aliases(); } catch (KeyStoreException e) { return; } for (; aliases.hasMoreElements();) { - alias = (String) aliases.nextElement(); + final String alias = aliases.nextElement(); try { - if (keyStore.entryInstanceOf(alias, - KeyStore.PrivateKeyEntry.class)) { - entry = (KeyStore.PrivateKeyEntry) keyStore.getEntry(alias, - new KeyStore.PasswordProtection(pwd)); + if (keyStore.entryInstanceOf(alias, KeyStore.PrivateKeyEntry.class)) { + final KeyStore.PrivateKeyEntry entry = (KeyStore.PrivateKeyEntry) keyStore + .getEntry(alias, new KeyStore.PasswordProtection(pwd)); hash.put(alias, entry); } } catch (KeyStoreException e) { @@ -86,41 +81,18 @@ public class KeyManagerImpl extends X509ExtendedKeyManager { continue; } } - } - /** - * @see javax.net.ssl.X509ExtendedKeyManager#chooseClientAlias(String[] - * keyType, Principal[] issuers, Socket socket) - */ - public String chooseClientAlias(String[] keyType, Principal[] issuers, - Socket socket) { - String[] al = chooseAlias(keyType, issuers); - if (al != null) { - return al[0]; - } else { - return null; - } + public String chooseClientAlias(String[] keyType, Principal[] issuers, Socket socket) { + final String[] al = chooseAlias(keyType, issuers); + return (al == null ? null : al[0]); } - /** - * @see javax.net.ssl.X509ExtendedKeyManager#chooseServerAlias(String - * keyType, Principal[] issuers, Socket socket) - */ - public String chooseServerAlias(String keyType, Principal[] issuers, - Socket socket) { - String[] al = chooseAlias(new String[] { keyType }, issuers); - if (al != null) { - return al[0]; - } else { - return null; - } + public String chooseServerAlias(String keyType, Principal[] issuers, Socket socket) { + final String[] al = chooseAlias(new String[] { keyType }, issuers); + return (al == null ? null : al[0]); } - /** - * @see javax.net.ssl.X509ExtendedKeyManager#getCertificateChain(String - * alias) - */ public X509Certificate[] getCertificateChain(String alias) { // BEGIN android-changed if (alias == null) { @@ -128,8 +100,7 @@ public class KeyManagerImpl extends X509ExtendedKeyManager { } // END android-changed if (hash.containsKey(alias)) { - Certificate[] certs = ((KeyStore.PrivateKeyEntry) hash.get(alias)) - .getCertificateChain(); + Certificate[] certs = hash.get(alias).getCertificateChain(); if (certs[0] instanceof X509Certificate) { X509Certificate[] xcerts = new X509Certificate[certs.length]; for (int i = 0; i < certs.length; i++) { @@ -142,25 +113,14 @@ public class KeyManagerImpl extends X509ExtendedKeyManager { } - /** - * @see javax.net.ssl.X509ExtendedKeyManager#getClientAliases(String - * keyType, Principal[] issuers) - */ public String[] getClientAliases(String keyType, Principal[] issuers) { return chooseAlias(new String[] { keyType }, issuers); } - /** - * @see javax.net.ssl.X509ExtendedKeyManager#getServerAliases(String - * keyType, Principal[] issuers) - */ public String[] getServerAliases(String keyType, Principal[] issuers) { return chooseAlias(new String[] { keyType }, issuers); } - /** - * @see javax.net.ssl.X509ExtendedKeyManager#getPrivateKey(String alias) - */ public PrivateKey getPrivateKey(String alias) { // BEGIN android-changed if (alias == null) { @@ -168,53 +128,33 @@ public class KeyManagerImpl extends X509ExtendedKeyManager { } // END android-changed if (hash.containsKey(alias)) { - return ((KeyStore.PrivateKeyEntry) hash.get(alias)).getPrivateKey(); + return hash.get(alias).getPrivateKey(); } return null; } - /** - * @see javax.net.ssl.X509ExtendedKeyManager#chooseEngineClientAlias(String[] - * keyType, Principal[] issuers, SSLEngine engine) - */ - public String chooseEngineClientAlias(String[] keyType, - Principal[] issuers, SSLEngine engine) { - String[] al = chooseAlias(keyType, issuers); - if (al != null) { - return al[0]; - } else { - return null; - } + @Override + public String chooseEngineClientAlias(String[] keyType, Principal[] issuers, SSLEngine engine) { + final String[] al = chooseAlias(keyType, issuers); + return (al == null ? null : al[0]); } - /** - * @see javax.net.ssl.X509ExtendedKeyManager#chooseEngineServerAlias(String - * keyType, Principal[] issuers, SSLEngine engine) - */ - public String chooseEngineServerAlias(String keyType, Principal[] issuers, - SSLEngine engine) { - String[] al = chooseAlias(new String[] { keyType }, issuers); - if (al != null) { - return al[0]; - } else { - return null; - } + @Override + public String chooseEngineServerAlias(String keyType, Principal[] issuers, SSLEngine engine) { + final String[] al = chooseAlias(new String[] { keyType }, issuers); + return (al == null ? null : al[0]); } private String[] chooseAlias(String[] keyType, Principal[] issuers) { - String alias; - KeyStore.PrivateKeyEntry entry; - if (keyType == null || keyType.length == 0) { return null; } - Vector found = new Vector(); - int count = 0; - for (Enumeration aliases = hash.keys(); aliases.hasMoreElements();) { - alias = (String) aliases.nextElement(); - entry = (KeyStore.PrivateKeyEntry) hash.get(alias); - Certificate[] certs = entry.getCertificateChain(); - String alg = certs[0].getPublicKey().getAlgorithm(); + Vector<String> found = new Vector<String>(); + for (Enumeration<String> aliases = hash.keys(); aliases.hasMoreElements();) { + final String alias = aliases.nextElement(); + final KeyStore.PrivateKeyEntry entry = hash.get(alias); + final Certificate[] certs = entry.getCertificateChain(); + final String alg = certs[0].getPublicKey().getAlgorithm(); for (int i = 0; i < keyType.length; i++) { if (alg.equals(keyType[i])) { if (issuers != null && issuers.length != 0) { @@ -226,7 +166,6 @@ public class KeyManagerImpl extends X509ExtendedKeyManager { for (int iii = 0; iii < issuers.length; iii++) { if (issuer.equals(issuers[iii])) { found.add(alias); - count++; break loop; } } @@ -235,18 +174,13 @@ public class KeyManagerImpl extends X509ExtendedKeyManager { } } else { found.add(alias); - count++; } } } } - if (count > 0) { - String[] result = new String[count]; - found.toArray(result); - return result; - } else { - return null; + if (!found.isEmpty()) { + return found.toArray(new String[found.size()]); } + return null; } - } diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/Logger.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/Logger.java index 5b7ba2c..c06aa7e 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/Logger.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/Logger.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** - * @author Alexander Y. Kleymenov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; import java.io.PrintStream; @@ -41,6 +36,7 @@ public class Logger { prefix = name + "["+Thread.currentThread().getName()+"] "; } + @Override public void print(String msg) { for (int i=0; i<indent; i++) { super.print(" "); @@ -56,6 +52,7 @@ public class Logger { indent --; } + @Override public void println(String msg) { print(prefix); super.println(msg); diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/Message.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/Message.java index cf99d6e..f1b2515 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/Message.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/Message.java @@ -15,10 +15,6 @@ * limitations under the License. */ -/** -* @author Boris Kuznetsov -* @version $Revision$ -*/ package org.apache.harmony.xnet.provider.jsse; import org.apache.harmony.xnet.provider.jsse.AlertException; diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImplWrapper.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImplWrapper.java index e3451aa..959f2a0 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImplWrapper.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImplWrapper.java @@ -1,17 +1,18 @@ /* - * Copyright (C) 2008 The Android Open Source Project + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.harmony.xnet.provider.jsse; @@ -38,132 +39,164 @@ public class OpenSSLSocketImplWrapper extends OpenSSLSocketImpl { this.socket = socket; } + @Override public void connect(SocketAddress sockaddr, int timeout) throws IOException { throw new IOException("Underlying socket is already connected."); } + @Override public void connect(SocketAddress sockaddr) throws IOException { throw new IOException("Underlying socket is already connected."); } + @Override public void bind(SocketAddress sockaddr) throws IOException { throw new IOException("Underlying socket is already connected."); } + @Override public SocketAddress getRemoteSocketAddress() { return socket.getRemoteSocketAddress(); } + @Override public SocketAddress getLocalSocketAddress() { return socket.getLocalSocketAddress(); } + @Override public InetAddress getLocalAddress() { return socket.getLocalAddress(); } + @Override public InetAddress getInetAddress() { return socket.getInetAddress(); } + @Override public String toString() { return "SSL socket over " + socket.toString(); } + @Override public void setSoLinger(boolean on, int linger) throws SocketException { socket.setSoLinger(on, linger); } + @Override public void setTcpNoDelay(boolean on) throws SocketException { socket.setTcpNoDelay(on); } + @Override public void setReuseAddress(boolean on) throws SocketException { socket.setReuseAddress(on); } + @Override public void setKeepAlive(boolean on) throws SocketException { socket.setKeepAlive(on); } + @Override public void setTrafficClass(int tos) throws SocketException { socket.setTrafficClass(tos); } + @Override public void setSoTimeout(int to) throws SocketException { socket.setSoTimeout(to); super.setSoTimeout(to); } + @Override public void setSendBufferSize(int size) throws SocketException { socket.setSendBufferSize(size); } + @Override public void setReceiveBufferSize(int size) throws SocketException { socket.setReceiveBufferSize(size); } + @Override public boolean getTcpNoDelay() throws SocketException { return socket.getTcpNoDelay(); } + @Override public boolean getReuseAddress() throws SocketException { return socket.getReuseAddress(); } + @Override public boolean getOOBInline() throws SocketException { return socket.getOOBInline(); } + @Override public boolean getKeepAlive() throws SocketException { return socket.getKeepAlive(); } + @Override public int getTrafficClass() throws SocketException { return socket.getTrafficClass(); } + @Override public int getSoTimeout() throws SocketException { return socket.getSoTimeout(); } + @Override public int getSoLinger() throws SocketException { return socket.getSoLinger(); } + @Override public int getSendBufferSize() throws SocketException { return socket.getSendBufferSize(); } + @Override public int getReceiveBufferSize() throws SocketException { return socket.getReceiveBufferSize(); } + @Override public boolean isConnected() { return socket.isConnected(); } + @Override public boolean isClosed() { return socket.isClosed(); } + @Override public boolean isBound() { return socket.isBound(); } + @Override public boolean isOutputShutdown() { return socket.isOutputShutdown(); } + @Override public boolean isInputShutdown() { return socket.isInputShutdown(); } + @Override public int getPort() { return socket.getPort(); } + @Override public int getLocalPort() { return socket.getLocalPort(); } diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/PRF.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/PRF.java index 3ed9b2a..c2f91a3 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/PRF.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/PRF.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** - * @author Alexander Y. Kleymenov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; import org.apache.harmony.xnet.provider.jsse.AlertException; diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ProtocolVersion.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ProtocolVersion.java index 1343c3b..def27f9 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ProtocolVersion.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ProtocolVersion.java @@ -14,11 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/** - * @author Boris Kuznetsov - * @version $Revision$ - */ package org.apache.harmony.xnet.provider.jsse; import java.util.Hashtable; @@ -28,41 +23,13 @@ import java.util.Hashtable; * Represents Protocol Version */ public class ProtocolVersion { - /** - * Protocol name - */ - public final String name; - - /** - * Protocol version as byte array - */ - public final byte[] version; - - /** - * Protocols supported by this provider implementaton + * Protocols supported by this provider implementation */ public static final String[] supportedProtocols = new String[] { "TLSv1", "SSLv3" }; - private static Hashtable protocolsByName = new Hashtable(4); - - private ProtocolVersion(String name, byte[] version) { - this.name = name; - this.version = version; - } - - /** - * Compares this ProtocolVersion to the specified object. - */ - public boolean equals(Object o) { - if (o instanceof ProtocolVersion - && this.version[0] == ((ProtocolVersion) o).version[0] - && this.version[1] == ((ProtocolVersion) o).version[1]) { - return true; - } - return false; - } + private static Hashtable<String, ProtocolVersion> protocolsByName = new Hashtable<String, ProtocolVersion>(4); /** * @@ -112,7 +79,7 @@ public class ProtocolVersion { * @return */ public static ProtocolVersion getByName(String name) { - return (ProtocolVersion) protocolsByName.get(name); + return protocolsByName.get(name); } /** @@ -161,4 +128,31 @@ public class ProtocolVersion { protocolsByName.put("TLS", TLSv1); } + /** + * Protocol name + */ + public final String name; + + /** + * Protocol version as byte array + */ + public final byte[] version; + + private ProtocolVersion(String name, byte[] version) { + this.name = name; + this.version = version; + } + + /** + * Compares this ProtocolVersion to the specified object. + */ + @Override + public boolean equals(Object o) { + if (o instanceof ProtocolVersion + && this.version[0] == ((ProtocolVersion) o).version[0] + && this.version[1] == ((ProtocolVersion) o).version[1]) { + return true; + } + return false; + } }
\ No newline at end of file diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLBufferedInput.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLBufferedInput.java index 44009b9..a150470 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLBufferedInput.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLBufferedInput.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** - * @author Alexander Y. Kleymenov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; import org.apache.harmony.xnet.provider.jsse.SSLInputStream; @@ -57,6 +52,7 @@ public class SSLBufferedInput extends SSLInputStream { /** * Returns the number of bytes available for reading. */ + @Override public int available() throws IOException { // in assumption that the buffer has been set return in.remaining(); @@ -73,6 +69,7 @@ public class SSLBufferedInput extends SSLInputStream { * Reads the following byte value. If there are no bytes in the source * buffer, method throws java.nio.BufferUnderflowException. */ + @Override public int read() throws IOException { // TODO: implement optimized read(int) // and read(byte[], int, int) methods diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLContextImpl.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLContextImpl.java index 2e4de04..c39e3ff 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLContextImpl.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLContextImpl.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** - * @author Alexander Y. Kleymenov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; import org.apache.harmony.xnet.provider.jsse.SSLEngineImpl; @@ -61,6 +56,7 @@ public class SSLContextImpl extends SSLContextSpi { super(); } + @Override public void engineInit(KeyManager[] kms, TrustManager[] tms, SecureRandom sr) throws KeyManagementException { engineInit(kms, tms, sr, null, null); @@ -96,6 +92,7 @@ public class SSLContextImpl extends SSLContextSpi { return new OpenSSLSocketFactoryImpl(sslParameters); } + @Override public SSLServerSocketFactory engineGetServerSocketFactory() { if (sslParameters == null) { throw new IllegalStateException("SSLContext is not initiallized."); @@ -103,6 +100,7 @@ public class SSLContextImpl extends SSLContextSpi { return new OpenSSLServerSocketFactoryImpl(sslParameters); } + @Override public SSLEngine engineCreateSSLEngine(String host, int port) { if (sslParameters == null) { throw new IllegalStateException("SSLContext is not initiallized."); @@ -111,6 +109,7 @@ public class SSLContextImpl extends SSLContextSpi { (SSLParameters) sslParameters.clone()); } + @Override public SSLEngine engineCreateSSLEngine() { if (sslParameters == null) { throw new IllegalStateException("SSLContext is not initiallized."); @@ -118,10 +117,12 @@ public class SSLContextImpl extends SSLContextSpi { return new SSLEngineImpl((SSLParameters) sslParameters.clone()); } + @Override public ServerSessionContext engineGetServerSessionContext() { return serverSessionContext; } + @Override public ClientSessionContext engineGetClientSessionContext() { return clientSessionContext; } diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLEngineAppData.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLEngineAppData.java index 698723b..9a2cb5e 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLEngineAppData.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLEngineAppData.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** - * @author Alexander Y. Kleymenov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; import org.apache.harmony.xnet.provider.jsse.AlertException; @@ -77,11 +72,10 @@ public class SSLEngineAppData implements org.apache.harmony.xnet.provider.jsse.A pos = len; // data was written, exit break; - } else { - // write chunk of data - dsts[i].put(buffer, pos, rem); - pos += rem; } + // write chunk of data + dsts[i].put(buffer, pos, rem); + pos += rem; } if (pos != len) { // The data did not feet into the buffers, diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLEngineDataStream.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLEngineDataStream.java index bc13577..e209dd1 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLEngineDataStream.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLEngineDataStream.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** - * @author Alexander Y. Kleymenov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; import java.nio.ByteBuffer; diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLEngineImpl.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLEngineImpl.java index 383e146..c28a311 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLEngineImpl.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLEngineImpl.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** - * @author Alexander Y. Kleymenov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; import org.apache.harmony.xnet.provider.jsse.AlertException; @@ -114,6 +109,7 @@ public class SSLEngineImpl extends SSLEngine { * @see javax.net.ssl.SSLEngine#beginHandshake() method documentation * for more information */ + @Override public void beginHandshake() throws SSLException { if (engine_was_closed) { throw new SSLException("Engine has already been closed."); @@ -143,6 +139,7 @@ public class SSLEngineImpl extends SSLEngine { * @see javax.net.ssl.SSLEngine#closeInbound() method documentation * for more information */ + @Override public void closeInbound() throws SSLException { if (logger != null) { logger.println("closeInbound() "+isInboundDone); @@ -173,6 +170,7 @@ public class SSLEngineImpl extends SSLEngine { * @see javax.net.ssl.SSLEngine#closeOutbound() method documentation * for more information */ + @Override public void closeOutbound() { if (logger != null) { logger.println("closeOutbound() "+isOutboundDone); @@ -199,6 +197,7 @@ public class SSLEngineImpl extends SSLEngine { * @see javax.net.ssl.SSLEngine#getDelegatedTask() method documentation * for more information */ + @Override public Runnable getDelegatedTask() { return handshakeProtocol.getTask(); } @@ -209,6 +208,7 @@ public class SSLEngineImpl extends SSLEngine { * @see javax.net.ssl.SSLEngine#getSupportedCipherSuites() method * documentation for more information */ + @Override public String[] getSupportedCipherSuites() { return CipherSuite.getSupportedCipherSuiteNames(); } @@ -220,6 +220,7 @@ public class SSLEngineImpl extends SSLEngine { * @see javax.net.ssl.SSLEngine#getEnabledCipherSuites() method * documentation for more information */ + @Override public String[] getEnabledCipherSuites() { return sslParameters.getEnabledCipherSuites(); } @@ -229,6 +230,7 @@ public class SSLEngineImpl extends SSLEngine { * @see javax.net.ssl.SSLEngine#setEnabledCipherSuites(String[]) method * documentation for more information */ + @Override public void setEnabledCipherSuites(String[] suites) { sslParameters.setEnabledCipherSuites(suites); } @@ -238,8 +240,9 @@ public class SSLEngineImpl extends SSLEngine { * @see javax.net.ssl.SSLEngine#getSupportedProtocols() method * documentation for more information */ + @Override public String[] getSupportedProtocols() { - return (String[]) ProtocolVersion.supportedProtocols.clone(); + return ProtocolVersion.supportedProtocols.clone(); } /** @@ -247,6 +250,7 @@ public class SSLEngineImpl extends SSLEngine { * @see javax.net.ssl.SSLEngine#getEnabledProtocols() method * documentation for more information */ + @Override public String[] getEnabledProtocols() { return sslParameters.getEnabledProtocols(); } @@ -256,6 +260,7 @@ public class SSLEngineImpl extends SSLEngine { * @see javax.net.ssl.SSLEngine#setEnabledProtocols(String[]) method * documentation for more information */ + @Override public void setEnabledProtocols(String[] protocols) { sslParameters.setEnabledProtocols(protocols); } @@ -265,6 +270,7 @@ public class SSLEngineImpl extends SSLEngine { * @see javax.net.ssl.SSLEngine#setUseClientMode(boolean) method * documentation for more information */ + @Override public void setUseClientMode(boolean mode) { if (handshake_started) { throw new IllegalArgumentException( @@ -279,6 +285,7 @@ public class SSLEngineImpl extends SSLEngine { * @see javax.net.ssl.SSLEngine#getUseClientMode() method * documentation for more information */ + @Override public boolean getUseClientMode() { return sslParameters.getUseClientMode(); } @@ -288,6 +295,7 @@ public class SSLEngineImpl extends SSLEngine { * @see javax.net.ssl.SSLEngine#setNeedClientAuth(boolean) method * documentation for more information */ + @Override public void setNeedClientAuth(boolean need) { sslParameters.setNeedClientAuth(need); } @@ -297,6 +305,7 @@ public class SSLEngineImpl extends SSLEngine { * @see javax.net.ssl.SSLEngine#getNeedClientAuth() method * documentation for more information */ + @Override public boolean getNeedClientAuth() { return sslParameters.getNeedClientAuth(); } @@ -306,6 +315,7 @@ public class SSLEngineImpl extends SSLEngine { * @see javax.net.ssl.SSLEngine#setWantClientAuth(boolean) method * documentation for more information */ + @Override public void setWantClientAuth(boolean want) { sslParameters.setWantClientAuth(want); } @@ -315,6 +325,7 @@ public class SSLEngineImpl extends SSLEngine { * @see javax.net.ssl.SSLEngine#getWantClientAuth() method * documentation for more information */ + @Override public boolean getWantClientAuth() { return sslParameters.getWantClientAuth(); } @@ -324,6 +335,7 @@ public class SSLEngineImpl extends SSLEngine { * @see javax.net.ssl.SSLEngine#setEnableSessionCreation(boolean) method * documentation for more information */ + @Override public void setEnableSessionCreation(boolean flag) { sslParameters.setEnableSessionCreation(flag); } @@ -333,6 +345,7 @@ public class SSLEngineImpl extends SSLEngine { * @see javax.net.ssl.SSLEngine#getEnableSessionCreation() method * documentation for more information */ + @Override public boolean getEnableSessionCreation() { return sslParameters.getEnableSessionCreation(); } @@ -344,6 +357,7 @@ public class SSLEngineImpl extends SSLEngine { * @see javax.net.ssl.SSLEngine#getHandshakeStatus() method * documentation for more information */ + @Override public SSLEngineResult.HandshakeStatus getHandshakeStatus() { if (!handshake_started || engine_was_shutteddown) { // initial handshake has not been started yet @@ -365,12 +379,12 @@ public class SSLEngineImpl extends SSLEngine { * @see javax.net.ssl.SSLEngine#getSession() method * documentation for more information */ + @Override public SSLSession getSession() { if (session != null) { return session; - } else { - return SSLSessionImpl.NULL_SESSION; } + return SSLSessionImpl.NULL_SESSION; } /** @@ -378,6 +392,7 @@ public class SSLEngineImpl extends SSLEngine { * @see javax.net.ssl.SSLEngine#isInboundDone() method * documentation for more information */ + @Override public boolean isInboundDone() { return isInboundDone || engine_was_closed; } @@ -387,6 +402,7 @@ public class SSLEngineImpl extends SSLEngine { * @see javax.net.ssl.SSLEngine#isOutboundDone() method * documentation for more information */ + @Override public boolean isOutboundDone() { return isOutboundDone; } @@ -402,6 +418,7 @@ public class SSLEngineImpl extends SSLEngine { * @see javax.net.ssl.SSLEngine#unwrap(ByteBuffer,ByteBuffer[],int,int) * method documentation for more information */ + @Override public SSLEngineResult unwrap(ByteBuffer src, ByteBuffer[] dsts, int offset, int length) throws SSLException { if (engine_was_shutteddown) { @@ -566,6 +583,7 @@ public class SSLEngineImpl extends SSLEngine { * @see javax.net.ssl.SSLEngine#wrap(ByteBuffer[],int,int,ByteBuffer) method * documentation for more information */ + @Override public SSLEngineResult wrap(ByteBuffer[] srcs, int offset, int len, ByteBuffer dst) throws SSLException { if (engine_was_shutteddown) { diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLInputStream.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLInputStream.java index bd9b6cf..6c23a91 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLInputStream.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLInputStream.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** - * @author Alexander Y. Kleymenov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; import java.io.IOException; @@ -37,6 +32,7 @@ public abstract class SSLInputStream extends InputStream { /** * @see java.io.InputStream#available() */ + @Override public abstract int available() throws IOException; /** @@ -49,11 +45,13 @@ public abstract class SSLInputStream extends InputStream { * @see org.apache.harmony.xnet.provider.jsse.SSLBufferedInput#read() * @see org.apache.harmony.xnet.provider.jsse.HandshakeIODataStream#read() */ + @Override public abstract int read() throws IOException; /** * @see java.io.InputStream#skip(long) */ + @Override public long skip(long n) throws IOException { long skept = n; while (n > 0) { @@ -119,6 +117,7 @@ public abstract class SSLInputStream extends InputStream { /** * @see java.io.InputStream#read(byte[],int,int) */ + @Override public int read(byte[] b, int off, int len) throws IOException { int read_b; int i = 0; diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLParameters.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLParameters.java index d91388a..89916de 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLParameters.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLParameters.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** - * @author Alexander Y. Kleymenov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; import java.security.KeyManagementException; @@ -317,7 +312,7 @@ public class SSLParameters implements Cloneable { enabledCipherSuiteNames[i] = enabledCipherSuites[i].getName(); } } - return (String[]) enabledCipherSuiteNames.clone(); + return enabledCipherSuiteNames.clone(); } /** @@ -345,7 +340,7 @@ public class SSLParameters implements Cloneable { * @return the set of enabled protocols */ protected String[] getEnabledProtocols() { - return (String[]) enabledProtocols.clone(); + return enabledProtocols.clone(); } /** @@ -436,6 +431,7 @@ public class SSLParameters implements Cloneable { * Returns the clone of this object. * @return the clone. */ + @Override protected Object clone() { // BEGIN android-changed try { diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLRecordProtocol.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLRecordProtocol.java index 4428820..423a817 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLRecordProtocol.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLRecordProtocol.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** - * @author Alexander Y. Kleymenov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; import org.apache.harmony.xnet.provider.jsse.AlertException; @@ -33,7 +28,7 @@ import javax.net.ssl.SSLProtocolException; * This class performs functionality dedicated to SSL record layer. * It unpacks and routes income data to the appropriate * client protocol (handshake, alert, application data protocols) - * and paketizes outcome data into SSL/TLS records. + * and packages outcome data into SSL/TLS records. * Initially created object has null connection state and does not * perform any cryptography computations over the income/outcome data. * After handshake protocol agreed upon security parameters they are placed @@ -179,14 +174,13 @@ public class SSLRecordProtocol { } if (activeReadState == null) { return record_size; - } else { - return activeReadState.getContentSize(record_size); } + return activeReadState.getContentSize(record_size); } /** * Depending on the Connection State (Session) encrypts and compress - * the provided data, and packs it into TLSCiphertext structute. + * the provided data, and packs it into TLSCiphertext structure. * @param content_type: int * @param fragment: byte[] * @return ssl packet created over the current connection state @@ -198,7 +192,7 @@ public class SSLRecordProtocol { /** * Depending on the Connection State (Session) encrypts and compress - * the provided data, and packs it into TLSCiphertext structute. + * the provided data, and packs it into TLSCiphertext structure. * @param content_type: int * @param fragment: byte[] * @return ssl packet created over the current connection state @@ -374,7 +368,7 @@ public class SSLRecordProtocol { type)); } } else { - in.skip((long) 2); // just skip the version number + in.skip(2); // just skip the version number } int length = in.readUint16(); if (logger != null) { diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSessionImpl.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSessionImpl.java index 4510c96..5d46568 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSessionImpl.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSessionImpl.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** - * @author Boris Kuznetsov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; import java.security.AccessControlContext; @@ -29,7 +24,8 @@ import java.security.SecureRandom; import java.security.cert.Certificate; import java.security.cert.CertificateEncodingException; import java.security.cert.X509Certificate; -import java.util.Iterator; +import java.util.HashMap; +import java.util.Map; import java.util.Vector; import javax.net.ssl.SSLPeerUnverifiedException; @@ -39,25 +35,67 @@ import javax.net.ssl.SSLSessionBindingEvent; import javax.net.ssl.SSLSessionBindingListener; import javax.net.ssl.SSLSessionContext; -import org.apache.harmony.luni.util.TwoKeyHashMap; - /** * * SSLSession implementation - * + * * @see javax.net.ssl.SSLSession */ -public class SSLSessionImpl implements SSLSession { +public class SSLSessionImpl implements SSLSession, Cloneable { /** - * Session object reporting an invalid cipher suite of - * "SSL_NULL_WITH_NULL_NULL" + * Session object reporting an invalid cipher suite of "SSL_NULL_WITH_NULL_NULL" */ public static final SSLSessionImpl NULL_SESSION = new SSLSessionImpl(null); + /** + * Container class for the 'value' map's keys. + */ + private static final class ValueKey { + final String name; + final AccessControlContext acc; + + ValueKey(String name) { + super(); + this.name = name; + this.acc = AccessController.getContext(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((acc == null) ? 0 : acc.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (!(obj instanceof ValueKey)) + return false; + ValueKey other = (ValueKey) obj; + if (acc == null) { + if (other.acc != null) + return false; + } else if (!acc.equals(other.acc)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } + } + private long creationTime; private boolean isValid = true; - private TwoKeyHashMap values = new TwoKeyHashMap(); + private Map<ValueKey, Object> values = new HashMap<ValueKey, Object>(); /** * ID of the session @@ -65,7 +103,7 @@ public class SSLSessionImpl implements SSLSession { byte[] id; /** - * Last time the session was accessed + * Last time the session was accessed */ long lastAccessedTime; @@ -87,7 +125,7 @@ public class SSLSessionImpl implements SSLSession { // END android-changed /** - * certificates were sent to the peer + * certificates were sent to the peer */ X509Certificate[] localCertificates; @@ -97,21 +135,20 @@ public class SSLSessionImpl implements SSLSession { X509Certificate[] peerCertificates; /** - * Peer host name + * Peer host name */ - String peerHost; + private String peerHost; /** * Peer port number */ - int peerPort = -1; + private int peerPort = -1; /** * Master secret */ byte[] master_secret; - /** * clientRandom */ @@ -125,10 +162,11 @@ public class SSLSessionImpl implements SSLSession { /** * True if this entity is considered the server */ - boolean isServer = false; + final boolean isServer; /** * Creates SSLSession implementation + * * @param cipher_suite * @param sr */ @@ -143,11 +181,11 @@ public class SSLSessionImpl implements SSLSession { this.cipherSuite = cipher_suite; id = new byte[32]; sr.nextBytes(id); - long time = new java.util.Date().getTime() / 1000; + long time = creationTime / 1000; id[28] = (byte) ((time & 0xFF000000) >>> 24); - id[29] = (byte) ((time & 0xFF0000) >>> 16); - id[30] = (byte) ((time & 0xFF00) >>> 8); - id[31] = (byte) (time & 0xFF); + id[29] = (byte) ((time & 0x00FF0000) >>> 16); + id[30] = (byte) ((time & 0x0000FF00) >>> 8); + id[31] = (byte) ((time & 0x000000FF)); isServer = true; } @@ -155,78 +193,48 @@ public class SSLSessionImpl implements SSLSession { /** * Creates SSLSession implementation + * * @param sr */ public SSLSessionImpl(SecureRandom sr) { this(null, sr); } - private SSLSessionImpl() { - } - - /** - * @see javax.net.ssl.SSLSession#getApplicationBufferSize() - */ public int getApplicationBufferSize() { return SSLRecordProtocol.MAX_DATA_LENGTH; } - /** - * @see javax.net.ssl.SSLSession#getCipherSuite() - */ public String getCipherSuite() { return cipherSuite.getName(); } - /** - * @see javax.net.ssl.SSLSession#getCreationTime() - */ public long getCreationTime() { return creationTime; } - /** - * @see javax.net.ssl.SSLSession#getId() - */ public byte[] getId() { return id; } - /** - * @see javax.net.ssl.SSLSession#getLastAccessedTime() - */ public long getLastAccessedTime() { return lastAccessedTime; } - /** - * @see javax.net.ssl.SSLSession#getLocalCertificates() - */ public Certificate[] getLocalCertificates() { return localCertificates; } - /** - * @see javax.net.ssl.SSLSession#getLocalPrincipal() - */ public Principal getLocalPrincipal() { if (localCertificates != null && localCertificates.length > 0) { return localCertificates[0].getSubjectX500Principal(); - } else { - return null; } + return null; } - /** - * @see javax.net.ssl.SSLSession#getPacketBufferSize() - */ public int getPacketBufferSize() { return SSLRecordProtocol.MAX_SSL_PACKET_SIZE; } - /** - * @see javax.net.ssl.SSLSession#getPeerCertificateChain() - */ public javax.security.cert.X509Certificate[] getPeerCertificateChain() throws SSLPeerUnverifiedException { if (peerCertificates == null) { @@ -235,8 +243,8 @@ public class SSLSessionImpl implements SSLSession { javax.security.cert.X509Certificate[] certs = new javax.security.cert.X509Certificate[peerCertificates.length]; for (int i = 0; i < certs.length; i++) { try { - certs[i] = javax.security.cert.X509Certificate - .getInstance(peerCertificates[i].getEncoded()); + certs[i] = javax.security.cert.X509Certificate.getInstance(peerCertificates[i] + .getEncoded()); } catch (javax.security.cert.CertificateException e) { } catch (CertificateEncodingException e) { } @@ -244,34 +252,21 @@ public class SSLSessionImpl implements SSLSession { return certs; } - /** - * @see javax.net.ssl.SSLSession#getPeerCertificates() - */ - public Certificate[] getPeerCertificates() - throws SSLPeerUnverifiedException { + public Certificate[] getPeerCertificates() throws SSLPeerUnverifiedException { if (peerCertificates == null) { throw new SSLPeerUnverifiedException("No peer certificate"); } return peerCertificates; } - /** - * @see javax.net.ssl.SSLSession#getPeerHost() - */ public String getPeerHost() { return peerHost; } - /** - * @see javax.net.ssl.SSLSession#getPeerPort() - */ public int getPeerPort() { return peerPort; } - /** - * @see javax.net.ssl.SSLSession#getPeerPrincipal() - */ public Principal getPeerPrincipal() throws SSLPeerUnverifiedException { if (peerCertificates == null) { throw new SSLPeerUnverifiedException("No peer certificate"); @@ -279,16 +274,10 @@ public class SSLSessionImpl implements SSLSession { return peerCertificates[0].getSubjectX500Principal(); } - /** - * @see javax.net.ssl.SSLSession#getProtocol() - */ public String getProtocol() { return protocol.name; } - /** - * @see javax.net.ssl.SSLSession#getSessionContext() - */ public SSLSessionContext getSessionContext() { SecurityManager sm = System.getSecurityManager(); if (sm != null) { @@ -297,109 +286,71 @@ public class SSLSessionImpl implements SSLSession { return context; } - /** - * @see javax.net.ssl.SSLSession#getValue(String name) - */ public Object getValue(String name) { if (name == null) { throw new IllegalArgumentException("Parameter is null"); } - return values.get(name, AccessController.getContext()); + return values.get(new ValueKey(name)); } - /** - * @see javax.net.ssl.SSLSession#getValueNames() - */ public String[] getValueNames() { - Vector v = new Vector(); - AccessControlContext current = AccessController.getContext(); - AccessControlContext cont; - for (Iterator it = values.entrySet().iterator(); it.hasNext();) { - TwoKeyHashMap.Entry entry = (TwoKeyHashMap.Entry) it.next(); - cont = (AccessControlContext) entry.getKey2(); - if ((current == null && cont == null) - || (current != null && current.equals(cont))) { - v.add(entry.getKey1()); + final Vector<String> v = new Vector<String>(); + final AccessControlContext currAcc = AccessController.getContext(); + for (ValueKey key : values.keySet()) { + if ((currAcc == null && key.acc == null) + || (currAcc != null && currAcc.equals(key.acc))) { + v.add(key.name); } } - return (String[]) v.toArray(new String[0]); + return v.toArray(new String[v.size()]); } - /** - * @see javax.net.ssl.SSLSession#invalidate() - */ public void invalidate() { isValid = false; } - /** - * @see javax.net.ssl.SSLSession#isValid() - */ public boolean isValid() { - if (isValid - && context != null - && context.getSessionTimeout() != 0 - && lastAccessedTime + context.getSessionTimeout() > System - .currentTimeMillis()) { + if (isValid && context != null && context.getSessionTimeout() != 0 + && lastAccessedTime + context.getSessionTimeout() > System.currentTimeMillis()) { isValid = false; } return isValid; } - /** - * @see javax.net.ssl.SSLSession#putValue(String name, Object value) - */ public void putValue(String name, Object value) { if (name == null || value == null) { throw new IllegalArgumentException("Parameter is null"); } - Object old = values.put(name, AccessController.getContext(), value); + Object old = values.put(new ValueKey(name), value); if (value instanceof SSLSessionBindingListener) { - ((SSLSessionBindingListener) value) - .valueBound(new SSLSessionBindingEvent(this, name)); + ((SSLSessionBindingListener) value).valueBound(new SSLSessionBindingEvent(this, name)); } if (old != null && old instanceof SSLSessionBindingListener) { - ((SSLSessionBindingListener) old) - .valueUnbound(new SSLSessionBindingEvent(this, name)); + ((SSLSessionBindingListener) old).valueUnbound(new SSLSessionBindingEvent(this, name)); } } - /** - * @see javax.net.ssl.SSLSession#removeValue(String name) - */ public void removeValue(String name) { if (name == null) { throw new IllegalArgumentException("Parameter is null"); } - values.remove(name, AccessController.getContext()); + values.remove(new ValueKey(name)); } + @Override public Object clone() { - SSLSessionImpl ses = new SSLSessionImpl(); - ses.id = this.id; - ses.creationTime = this.creationTime; - ses.lastAccessedTime = this.lastAccessedTime; - ses.isValid = this.isValid; - ses.cipherSuite = this.cipherSuite; - ses.localCertificates = this.localCertificates; - ses.peerCertificates = this.peerCertificates; - ses.master_secret = this.master_secret; - ses.clientRandom = this.clientRandom; - ses.serverRandom = this.serverRandom; - ses.peerHost = this.peerHost; - ses.peerPort = this.peerPort; - ses.isServer = this.isServer; - ses.context = this.context; - ses.protocol = this.protocol; - ses.values = this.values; - return ses; + try { + return super.clone(); + } catch (CloneNotSupportedException e) { + throw new AssertionError(e); + } } - /** * Sets the address of the peer + * * @param peerHost * @param peerPort */ diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLStreamedInput.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLStreamedInput.java index efabef8..c040653 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLStreamedInput.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLStreamedInput.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** - * @author Alexander Y. Kleymenov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; import java.io.IOException; @@ -37,6 +32,7 @@ public class SSLStreamedInput extends SSLInputStream { this.in = in; } + @Override public int available() throws IOException { return in.available(); } @@ -49,6 +45,7 @@ public class SSLStreamedInput extends SSLInputStream { * @throws org.apache.harmony.xnet.provider.jsse.EndOfSourceException if the end of the underlying * stream has been reached. */ + @Override public int read() throws IOException { int res = in.read(); if (res < 0) { diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLv3Constants.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLv3Constants.java index 1a03f7f..07aaca8 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLv3Constants.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLv3Constants.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** - * @author Boris Kuznetsov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; /** diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ServerHandshakeImpl.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ServerHandshakeImpl.java index f6eef23..3bb096b 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ServerHandshakeImpl.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ServerHandshakeImpl.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Boris Kuznetsov -* @version $Revision$ -*/ - package org.apache.harmony.xnet.provider.jsse; import org.apache.harmony.xnet.provider.jsse.SSLv3Constants; @@ -56,7 +51,7 @@ import javax.net.ssl.X509TrustManager; * Handshake protocol operates on top of the Record Protocol. * It responsible for negotiating a session. * - * The implementation proceses inbound client handshake messages, + * The implementation processes inbound client handshake messages, * creates and sends respond messages. Outbound messages are supplied * to Record Protocol. Detected errors are reported to the Alert protocol. * @@ -82,6 +77,7 @@ public class ServerHandshakeImpl extends HandshakeProtocol { /** * Start session negotiation */ + @Override public void start() { if (session == null) { // initial handshake status = NEED_UNWRAP; @@ -101,6 +97,7 @@ public class ServerHandshakeImpl extends HandshakeProtocol { * Proceses inbound handshake messages * @param bytes */ + @Override public void unwrap(byte[] bytes) { io_stream.append(bytes); @@ -128,15 +125,12 @@ public class ServerHandshakeImpl extends HandshakeProtocol { needSendHelloRequest = false; clientHello = new ClientHello(io_stream, length); if (nonBlocking) { - delegatedTasks.add(new DelegatedTask( - new PrivilegedExceptionAction(){ - public Object run() throws Exception { + delegatedTasks.add(new DelegatedTask(new PrivilegedExceptionAction<Void>() { + public Void run() throws Exception { processClientHello(); return null; - } - }, - this, - AccessController.getContext())); + } + }, this, AccessController.getContext())); return; } processClientHello(); @@ -152,7 +146,7 @@ public class ServerHandshakeImpl extends HandshakeProtocol { if (clientCert.certs.length == 0) { if (parameters.getNeedClientAuth()) { fatalAlert(AlertProtocol.HANDSHAKE_FAILURE, - "HANDSHAKE FAILURE: no client certificate recived"); + "HANDSHAKE FAILURE: no client certificate received"); } } else { String authType = clientCert.certs[0].getPublicKey() @@ -324,32 +318,27 @@ public class ServerHandshakeImpl extends HandshakeProtocol { * @ see TLS 1.0 spec., E.1. Version 2 client hello * @param bytes */ + @Override public void unwrapSSLv2(byte[] bytes) { + io_stream.append(bytes); + io_stream.mark(); try { - io_stream.append(bytes); - io_stream.mark(); - try { - clientHello = new ClientHello(io_stream); - } catch (IOException e) { - io_stream.reset(); - return; - } - if (nonBlocking) { - delegatedTasks.add(new DelegatedTask( - new PrivilegedExceptionAction(){ - public Object run() throws Exception { - processClientHello(); - return null; + clientHello = new ClientHello(io_stream); + } catch (IOException e) { + io_stream.reset(); + return; + } + if (nonBlocking) { + delegatedTasks.add(new DelegatedTask( + new PrivilegedExceptionAction<Void>() { + public Void run() throws Exception { + processClientHello(); + return null; } - }, - this, - AccessController.getContext())); - return; - } - processClientHello(); - } catch (Exception e) { - fatalAlert(AlertProtocol.INTERNAL_ERROR, "INTERNAL ERROR", e); + }, this, AccessController.getContext())); + return; } + processClientHello(); } /** @@ -407,10 +396,9 @@ public class ServerHandshakeImpl extends HandshakeProtocol { status = NOT_HANDSHAKING; clearMessages(); return; - } else { - fatalAlert(AlertProtocol.HANDSHAKE_FAILURE, - "SSL Session may not be created"); } + // throw AlertException + fatalAlert(AlertProtocol.HANDSHAKE_FAILURE, "SSL Session may not be created"); } session = null; } else { @@ -569,7 +557,7 @@ public class ServerHandshakeImpl extends HandshakeProtocol { } catch (NoSuchAlgorithmException e) { kf = KeyFactory.getInstance("DiffieHellman"); } - dhkeySpec = (DHPublicKeySpec) kf.getKeySpec(dhkey, + dhkeySpec = kf.getKeySpec(dhkey, DHPublicKeySpec.class); } if (!cipher_suite.isAnonymous()) { // calculate signed_params @@ -654,6 +642,7 @@ public class ServerHandshakeImpl extends HandshakeProtocol { /** * Creates and sends finished message */ + @Override protected void makeFinished() { byte[] verify_data; boolean isTLS = (serverHello.server_version[1] == 1); // TLS 1.0 protocol @@ -702,8 +691,9 @@ public class ServerHandshakeImpl extends HandshakeProtocol { } /** - * Proceses inbound ChangeCipherSpec message + * Processes inbound ChangeCipherSpec message */ + @Override public void receiveChangeCipherSpec() { if (isResuming) { if (serverFinished == null) { diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ServerHello.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ServerHello.java index 0365288..1cd9624 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ServerHello.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ServerHello.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Boris Kuznetsov -* @version $Revision$ -*/ - package org.apache.harmony.xnet.provider.jsse; import org.apache.harmony.xnet.provider.jsse.Message; @@ -112,6 +107,7 @@ public class ServerHello extends Message { * Sends message * @param out */ + @Override public void send(HandshakeIODataStream out) { out.write(server_version); out.write(random); @@ -134,6 +130,7 @@ public class ServerHello extends Message { * Returns message type * @return */ + @Override public int getType() { return Handshake.SERVER_HELLO; } diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ServerHelloDone.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ServerHelloDone.java index e794ed9..73b6a81 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ServerHelloDone.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ServerHelloDone.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Boris Kuznetsov -* @version $Revision$ -*/ - package org.apache.harmony.xnet.provider.jsse; import org.apache.harmony.xnet.provider.jsse.Message; @@ -59,6 +54,7 @@ public class ServerHelloDone extends Message { * Sends message * @param out */ + @Override public void send(HandshakeIODataStream out) { } @@ -66,6 +62,7 @@ public class ServerHelloDone extends Message { * Returns message length * @return */ + @Override public int length() { return 0; } @@ -74,6 +71,7 @@ public class ServerHelloDone extends Message { * Returns message type * @return */ + @Override public int getType() { return Handshake.SERVER_HELLO_DONE; } diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ServerKeyExchange.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ServerKeyExchange.java index 1d93ece..446b7b4 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ServerKeyExchange.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ServerKeyExchange.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** -* @author Boris Kuznetsov -* @version $Revision$ -*/ - package org.apache.harmony.xnet.provider.jsse; import org.apache.harmony.xnet.provider.jsse.Message; @@ -150,6 +145,7 @@ public class ServerKeyExchange extends Message { * Sends message * @param out */ + @Override public void send(HandshakeIODataStream out) { out.writeUint16(bytes1.length); out.write(bytes1); @@ -189,6 +185,7 @@ public class ServerKeyExchange extends Message { * Returns message type * @return */ + @Override public int getType() { return Handshake.SERVER_KEY_EXCHANGE; } diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/TrustManagerFactoryImpl.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/TrustManagerFactoryImpl.java index b96d1ab..c473864 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/TrustManagerFactoryImpl.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/TrustManagerFactoryImpl.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** - * @author Boris Kuznetsov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; import java.io.File; @@ -50,6 +45,7 @@ public class TrustManagerFactoryImpl extends TrustManagerFactorySpi { /** * @see javax.net.ssl.TrustManagerFactorySpi#engineInit(KeyStore) */ + @Override public void engineInit(KeyStore ks) throws KeyStoreException { if (ks != null) { keyStore = ks; @@ -117,6 +113,7 @@ public class TrustManagerFactoryImpl extends TrustManagerFactorySpi { /** * @see javax.net.ssl#engineInit(ManagerFactoryParameters) */ + @Override public void engineInit(ManagerFactoryParameters spec) throws InvalidAlgorithmParameterException { throw new InvalidAlgorithmParameterException( @@ -126,6 +123,7 @@ public class TrustManagerFactoryImpl extends TrustManagerFactorySpi { /** * @see javax.net.ssl#engineGetTrustManagers() */ + @Override public TrustManager[] engineGetTrustManagers() { if (keyStore == null) { throw new IllegalStateException( diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/TrustManagerImpl.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/TrustManagerImpl.java index 15756bd..5c40b4e 100644 --- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/TrustManagerImpl.java +++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/TrustManagerImpl.java @@ -15,11 +15,6 @@ * limitations under the License. */ -/** - * @author Boris Kuznetsov - * @version $Revision$ - */ - package org.apache.harmony.xnet.provider.jsse; import org.bouncycastle.jce.provider.IndexedPKIXParameters; @@ -75,13 +70,11 @@ public class TrustManagerImpl implements X509TrustManager { try { validator = CertPathValidator.getInstance("PKIX"); factory = CertificateFactory.getInstance("X509"); - String alias; - X509Certificate cert; byte[] nameConstrains = null; - Set trusted = new HashSet(); - for (Enumeration en = ks.aliases(); en.hasMoreElements();) { - alias = (String) en.nextElement(); - cert = (X509Certificate) ks.getCertificate(alias); + Set<TrustAnchor> trusted = new HashSet<TrustAnchor>(); + for (Enumeration<String> en = ks.aliases(); en.hasMoreElements();) { + final String alias = en.nextElement(); + final X509Certificate cert = (X509Certificate) ks.getCertificate(alias); if (cert != null) { trusted.add(new TrustAnchor(cert, nameConstrains)); } @@ -222,11 +215,11 @@ public class TrustManagerImpl implements X509TrustManager { if (params == null) { return new X509Certificate[0]; } - Set anchors = params.getTrustAnchors(); + Set<TrustAnchor> anchors = params.getTrustAnchors(); X509Certificate[] certs = new X509Certificate[anchors.size()]; int i = 0; - for (Iterator it = anchors.iterator(); it.hasNext();) { - certs[i++] = ((TrustAnchor) it.next()).getTrustedCert(); + for (Iterator<TrustAnchor> it = anchors.iterator(); it.hasNext();) { + certs[i++] = it.next().getTrustedCert(); } return certs; } |