@@ 3,11 3,18 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.ajtjp</groupId>
<artifactId>GeminiClient</artifactId>
- <version>1.0-SNAPSHOT</version>
+ <version>0.5.1</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.5</maven.compiler.source>
<maven.compiler.target>1.5</maven.compiler.target>
</properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.bouncycastle</groupId>
+ <artifactId>bctls-jdk15on</artifactId>
+ <version>1.66</version>
+ </dependency>
+ </dependencies>
</project>
No newline at end of file
@@ 8,17 8,24 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
+import java.security.KeyStore;
+import java.security.Provider;
+import java.security.Security;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.List;
import javax.net.SocketFactory;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
+import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
+import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
+import org.bouncycastle.jsse.provider.BouncyCastleJsseProvider;
/**
*
@@ 40,6 47,11 @@ public class GeminiClient {
Socket s = basicSocketFactory.createSocket(host, port);
s = sslSocketFactory.createSocket(s, host, port, true);
+ String[] ciphers = ((SSLSocket)s).getEnabledCipherSuites();
+ for (String str : ciphers) {
+ ;
+ }
+
OutputStream os = s.getOutputStream();
os.write((url + "\r\n").getBytes());
os.flush();
@@ 178,8 190,29 @@ public class GeminiClient {
}
};
- SSLContext sc = SSLContext.getInstance("TLSv1.2");
+// SSLContext sc = SSLContext.getInstance("TLSv1.2");
+
+ Provider[] providers = Security.getProviders();
+ Security.removeProvider("SunJCE");
+
+ Security.addProvider(new BouncyCastleJsseProvider());
+ providers = Security.getProviders();
+
+ SSLContext sc = SSLContext.getInstance("TLSv1.2", new BouncyCastleJsseProvider());
+
+// TrustManagerFactory trustMgrFact = TrustManagerFactory.getInstance(
+// "PKIX", "BCJSSE");
+// trustMgrFact.init(KeyStore.getInstance(KeyStore.getDefaultType()));
+
+ //Could use trustMgrFact.getTrustManagers() instead of trustAllCerts...
+
+// KeyManagerFactory keyMgrFact = KeyManagerFactory.getInstance("PKIX", "BCJSSE");
+// keyMgrFact.init(KeyStore.getInstance(KeyStore.getDefaultType()), new char[0]);
+// sc.init(keyMgrFact.getKeyManagers(), trustAllCerts, new java.security.SecureRandom());
+
+
sc.init(null, trustAllCerts, new java.security.SecureRandom());
+
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
//adj also set it here