summaryrefslogtreecommitdiffstats
path: root/support/src
diff options
context:
space:
mode:
authorUrs Grob <>2009-03-24 18:13:27 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-24 18:13:27 -0700
commit3cde025355ca04d7030eb6acebe8d84c7eec9ac8 (patch)
treea1e3d2ad041822f6b225941479b25cc781b006da /support/src
parenteeb220adf9eea613d6cd97a131b0a9ef49e31a5b (diff)
downloadlibcore-3cde025355ca04d7030eb6acebe8d84c7eec9ac8.zip
libcore-3cde025355ca04d7030eb6acebe8d84c7eec9ac8.tar.gz
libcore-3cde025355ca04d7030eb6acebe8d84c7eec9ac8.tar.bz2
Automated import from //branches/cupcake/...@141706,141706
Diffstat (limited to 'support/src')
-rw-r--r--support/src/test/java/org/apache/harmony/xnet/tests/support/SSLSessionContextImpl.java52
-rw-r--r--support/src/test/java/org/apache/harmony/xnet/tests/support/TrustManagerFactorySpiImpl.java52
-rw-r--r--support/src/test/java/org/apache/harmony/xnet/tests/support/mySSLSession.java14
-rw-r--r--support/src/test/java/org/apache/harmony/xnet/tests/support/mySSLSocket.java159
4 files changed, 44 insertions, 233 deletions
diff --git a/support/src/test/java/org/apache/harmony/xnet/tests/support/SSLSessionContextImpl.java b/support/src/test/java/org/apache/harmony/xnet/tests/support/SSLSessionContextImpl.java
deleted file mode 100644
index c8d35e4..0000000
--- a/support/src/test/java/org/apache/harmony/xnet/tests/support/SSLSessionContextImpl.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package org.apache.harmony.xnet.tests.support;
-
-import java.util.*;
-import javax.net.ssl.SSLSession;
-import javax.net.ssl.SSLSessionContext;
-
-public class SSLSessionContextImpl implements SSLSessionContext {
-
- private int cashSize;
- private long sessionTimeout;
-
- public SSLSessionContextImpl() {
- cashSize = 0;
- sessionTimeout = 0;
- }
-
- public int getSessionCacheSize() {
- return cashSize;
- }
-
- public void setSessionCacheSize(int newSize) throws IllegalArgumentException {
- if(newSize < 0) throw new IllegalArgumentException();
- if (newSize < cashSize) {
- System.out.println("<--- Number of sessions will be changed");
- }
- cashSize = newSize;
- }
-
- public int getSessionTimeout()
- {
- return (int)(sessionTimeout / 1000L);
- }
-
- public void setSessionTimeout(int seconds) throws IllegalArgumentException {
- if(seconds < 0) {
- throw new IllegalArgumentException();
- } else {
- sessionTimeout = (long)seconds * 1000L;
- }
- }
-
- public SSLSession getSession(byte abyte0[])
- {
- return null;
- }
-
- public Enumeration getIds()
- {
- return null;
- }
-
-}
diff --git a/support/src/test/java/org/apache/harmony/xnet/tests/support/TrustManagerFactorySpiImpl.java b/support/src/test/java/org/apache/harmony/xnet/tests/support/TrustManagerFactorySpiImpl.java
index 068440d..a6de5b2 100644
--- a/support/src/test/java/org/apache/harmony/xnet/tests/support/TrustManagerFactorySpiImpl.java
+++ b/support/src/test/java/org/apache/harmony/xnet/tests/support/TrustManagerFactorySpiImpl.java
@@ -9,36 +9,44 @@ import javax.net.ssl.TrustManager;
public class TrustManagerFactorySpiImpl extends MyTrustManagerFactorySpi {
- private boolean isInitialized = false;
+ private static boolean isengineInitCalled = false;
+ private static boolean isEngineGetTrustManagersCalled = false;
+ private static KeyStore ks = null;
+ private static ManagerFactoryParameters spec = null;
public void engineInit(KeyStore ks) throws KeyStoreException {
- if (ks == null) {
- throw new KeyStoreException("Not supported operation for null KeyStore");
- }
- isInitialized = true;
+ isengineInitCalled = true;
+ this.ks = ks;
}
public void engineInit(ManagerFactoryParameters spec) throws InvalidAlgorithmParameterException {
- if (spec == null) {
- throw new InvalidAlgorithmParameterException("Null parameter");
- }
- if (spec instanceof Parameters) {
- try {
- engineInit(((Parameters)spec).getKeyStore());
- } catch (KeyStoreException e) {
- throw new RuntimeException(e);
- }
- } else {
- throw new InvalidAlgorithmParameterException("Invalid parameter");
- }
- isInitialized = true;
+ isengineInitCalled = true;
+ this.spec = spec;
}
public TrustManager[] engineGetTrustManagers() {
- if(!isInitialized)
- throw new IllegalStateException("TrustManagerFactorySpi is not initialized");
- else
- return null;
+ isEngineGetTrustManagersCalled = true;
+ return null;
}
+ public void reset() {
+ isengineInitCalled = false;
+ isEngineGetTrustManagersCalled = false;
+ }
+
+ public boolean isEngineGetTrustManagersCalled() {
+ return isEngineGetTrustManagersCalled;
+ }
+
+ public boolean isEngineInitCalled() {
+ return isengineInitCalled;
+ }
+
+ public Object getKs() {
+ return ks;
+ }
+
+ public Object getSpec() {
+ return spec;
+ }
}
diff --git a/support/src/test/java/org/apache/harmony/xnet/tests/support/mySSLSession.java b/support/src/test/java/org/apache/harmony/xnet/tests/support/mySSLSession.java
index 9d318fc..633990b 100644
--- a/support/src/test/java/org/apache/harmony/xnet/tests/support/mySSLSession.java
+++ b/support/src/test/java/org/apache/harmony/xnet/tests/support/mySSLSession.java
@@ -2,6 +2,7 @@ package org.apache.harmony.xnet.tests.support;
import java.security.Principal;
import java.security.cert.Certificate;
+import java.security.cert.CertificateEncodingException;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
@@ -10,6 +11,7 @@ import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSessionBindingEvent;
import javax.net.ssl.SSLSessionBindingListener;
import javax.net.ssl.SSLSessionContext;
+import javax.security.cert.CertificateException;
import javax.security.cert.X509Certificate;
import javax.net.ssl.SSLSession;
@@ -40,6 +42,18 @@ public class mySSLSession implements SSLSession {
xCerts = xc;
}
+ public mySSLSession(Certificate[] xc) throws CertificateEncodingException, CertificateException {
+ certs = xc;
+ xCerts = new X509Certificate[xc.length];
+ int i = 0;
+ for (Certificate cert : xc) {
+ xCerts[i++] = X509Certificate.getInstance(cert.getEncoded());
+ }
+ }
+
+ public mySSLSession() {
+ }
+
public int getApplicationBufferSize() {
return 1234567;
}
diff --git a/support/src/test/java/org/apache/harmony/xnet/tests/support/mySSLSocket.java b/support/src/test/java/org/apache/harmony/xnet/tests/support/mySSLSocket.java
deleted file mode 100644
index c4664f0..0000000
--- a/support/src/test/java/org/apache/harmony/xnet/tests/support/mySSLSocket.java
+++ /dev/null
@@ -1,159 +0,0 @@
-package org.apache.harmony.xnet.tests.support;
-
-import javax.net.ssl.SSLSession;
-import javax.net.ssl.SSLSocket;
-import javax.net.ssl.HandshakeCompletedListener;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-
-/**
- * Additional class for SSLSocket constructor verification
- */
-public class mySSLSocket extends SSLSocket {
-
- private boolean init = false;
- private boolean sslFlag = true;
- private boolean sslNeed = false;
- private boolean sslWant = false;
- private int sslMode;
- private String[] supportProtocol = null;
- private String[] supportSuites = null;
-
- public mySSLSocket(int mode){
- super();
- sslMode = mode;
- }
- public mySSLSocket(String[] protocol, String[] suites){
- super();
- supportProtocol = protocol;
- supportSuites = suites;
- }
- public mySSLSocket(int mode, String[] protocol, String[] suites){
- super();
- sslMode = mode;
- supportProtocol = protocol;
- supportSuites = suites;
- }
- public mySSLSocket(){
- super();
- }
- public mySSLSocket(InetAddress address, int port) throws IOException{
- super(address, port);
- }
- public mySSLSocket(InetAddress address, int port,
- InetAddress clientAddress, int clientPort) throws IOException{
- super(address, port, clientAddress, clientPort);
- }
- public mySSLSocket(String host, int port) throws IOException, UnknownHostException{
- super(host, port);
- }
- public mySSLSocket(String host, int port, InetAddress clientAddress,
- int clientPort) throws IOException, UnknownHostException{
- super(host, port, clientAddress, clientPort);
- }
-
- public void addHandshakeCompletedListener(HandshakeCompletedListener listener) {
- if(listener == null) throw new IllegalArgumentException("listener is null");
- }
- public String[] getEnabledCipherSuites() {
- return supportSuites;
- }
- public String[] getEnabledProtocols() {
- return supportProtocol;
- }
- public boolean getEnableSessionCreation() {
- return sslFlag;
- }
- public boolean getNeedClientAuth() {
- if (sslMode == 1) {
- throw new IllegalStateException("Incorrect mode");
- } else return sslNeed;
- }
- public SSLSession getSession() {
- return null;
- }
- public String[] getSupportedCipherSuites() {
- if (supportSuites == null) {
- throw new NullPointerException();
- }
- if (supportSuites.length == 0) {
- return null;
- } else return supportSuites;
- }
- public String[] getSupportedProtocols() {
- if (supportProtocol == null) {
- throw new NullPointerException();
- }
- if (supportProtocol.length == 0) {
- return null;
- } else return supportProtocol;
- }
- public boolean getUseClientMode() {
- if (sslMode == 1) {
- return true;
- } else return false;
- }
- public boolean getWantClientAuth() {
- if (sslMode == 1) {
- throw new IllegalStateException("Incorrect mode");
- } else return sslWant;
- }
- public void removeHandshakeCompletedListener(HandshakeCompletedListener listener) {
- if(listener == null) throw new IllegalArgumentException("listener is null");
- }
- public void setEnabledCipherSuites(String[] suites) {
- if (suites == null) {
- throw new IllegalArgumentException("null parameter");
- }
- if (!suites.equals(supportSuites)) {
- throw new IllegalArgumentException("incorrect suite");
- }
- }
- public void setEnabledProtocols(String[] protocols) {
- if (protocols == null) {
- throw new IllegalArgumentException("null protocol");
- }
- if (!protocols.equals(supportProtocol)) {
- throw new IllegalArgumentException("incorrect protocol");
- }
- }
- public void setEnableSessionCreation(boolean flag) {
- sslFlag = flag;
- }
- public void setNeedClientAuth(boolean need) {
- if (sslMode == 0) {
- sslNeed = need;
- } else {
- throw new IllegalStateException("Incorrect mode");
- }
- }
- public void setUseClientMode(boolean mode) {
- if (!init) {
- if (mode && sslMode == 0) {
- sslMode = 1;
- } else if (!mode && sslMode == 1) {
- sslMode = 0;
- }
- } else {
- throw new IllegalArgumentException();
- }
- }
- public void setWantClientAuth(boolean want) {
- if (sslMode == 0) {
- sslWant = want;
- } else {
- throw new IllegalStateException("Incorrect mode");
- }
- }
- public void startHandshake() throws IOException {
- for (int i = 0; i < supportProtocol.length; i++) {
- if (supportProtocol[i] == "Protocol_2") {
- throw new IOException();
- }
- }
- init = true;
- }
-}
-