MCPcopy Create free account
hub / github.com/TrsstProject/trsst / enableAnonymousSSL

Method enableAnonymousSSL

src/main/java/com/trsst/Common.java:790–832  ·  view source on GitHub ↗

Most trsst nodes run with self-signed certificates, so by default we accept them. While posts are still signed and/or encrypted, a MITM can still refuse our out-going posts and suppress incoming new ones, but this the reason to relay with many trsst servers. Use the -strict option to require CA-sign

()

Source from the content-addressed store, hash-verified

788 * guarantee either.
789 */
790 public static void enableAnonymousSSL() {
791 TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
792 public java.security.cert.X509Certificate[] getAcceptedIssuers() {
793 return null;
794 }
795
796 public void checkClientTrusted(X509Certificate[] certs,
797 String authType) {
798 }
799
800 public void checkServerTrusted(X509Certificate[] certs,
801 String authType) {
802 }
803
804 } };
805
806 SSLContext sc;
807 try {
808 sc = SSLContext.getInstance("SSL");
809 sc.init(null, trustAllCerts, new java.security.SecureRandom());
810 HttpsURLConnection
811 .setDefaultSSLSocketFactory(sc.getSocketFactory());
812 } catch (NoSuchAlgorithmException e) {
813 log.error("Can't get SSL context", e);
814 } catch (KeyManagementException e) {
815 log.error("Can't set SSL socket factory", e);
816 }
817
818 // Create all-trusting host name verifier
819 HostnameVerifier allHostsValid = new HostnameVerifier() {
820 public boolean verify(String hostname, SSLSession session) {
821 return true;
822 }
823 };
824
825 // Install the all-trusting host verifier
826 HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
827
828 // For apache http client
829 Protocol anonhttps = new Protocol("https",
830 (ProtocolSocketFactory) new AnonymSSLSocketFactory(), 443); //
831 Protocol.registerProtocol("https", anonhttps);
832 }
833}

Callers 2

doBeginMethod · 0.95
mainMethod · 0.95

Calls 2

getInstanceMethod · 0.80
initMethod · 0.80

Tested by

no test coverage detected