Disable RSA key exchange in test
import java.security.PrivateKey;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
+import java.util.Vector;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLServerSocket;
import javax.net.ssl.SSLServerSocketFactory;
import javax.net.ssl.SSLSocket;
+import javax.net.ssl.TrustManagerFactory;
import org.bouncycastle.tls.crypto.impl.jcajce.JcaTlsCertificate;
import org.bouncycastle.tls.crypto.impl.jcajce.JcaTlsCrypto;
@@ -74,14 +76,37 @@ SSLContext createSSLContext()
serverStore.load(null, null);
serverStore.setKeyEntry("server", privateKey, SERVER_PASSWORD, new X509Certificate[]{ certificate });
+ KeyStore trustStore = KeyStore.getInstance("JKS");
+ trustStore.load(null, null);
+
KeyManagerFactory mgrFact = TlsTestUtils.getSunX509KeyManagerFactory();
mgrFact.init(serverStore, SERVER_PASSWORD);
+ TrustManagerFactory trustFact = TlsTestUtils.getSunX509TrustManagerFactory();
+ trustFact.init(trustStore);
+
SSLContext sslContext = SSLContext.getInstance("TLS");
- sslContext.init(mgrFact.getKeyManagers(), null, null);
+ sslContext.init(mgrFact.getKeyManagers(), trustFact.getTrustManagers(), null);
return sslContext;
}
+ void disableRSAKeyExchange(SSLSocket s)
+ {
+ String[] cipherSuites = s.getEnabledCipherSuites();
+
+ Vector v = new Vector();
+ for (String cipherSuite : cipherSuites)
+ {
+ if (!cipherSuite.regionMatches(true, 0, "SSL_RSA_", 0, "SSL_RSA_".length()) &&
+ !cipherSuite.regionMatches(true, 0, "TLS_RSA_", 0, "TLS_RSA_".length()))
+ {
+ v.addElement(cipherSuite);
+ }
+ }
+
+ s.setEnabledCipherSuites((String[])v.toArray(new String[0]));
+ }
+
public void run()
{
try
@@ -91,6 +116,7 @@ public void run()
SSLServerSocket sSock = (SSLServerSocket)fact.createServerSocket(PORT_NO);
SSLSocket sslSock = (SSLSocket)sSock.accept();
+ disableRSAKeyExchange(sslSock);
sslSock.setUseClientMode(false);
readRequest(sslSock.getInputStream());
