private OkHttpClient CreateOkHttpClientInstance() { var builder = new OkHttpClient.Builder() .ConnectTimeout(100, TimeUnit.Seconds) .WriteTimeout(100, TimeUnit.Seconds) .ReadTimeout(100, TimeUnit.Seconds) .CookieJar(new JavaNetCookieJar(new Java.Net.CookieManager())); if (_certificatePinnerBuilder.IsValueCreated) { builder.CertificatePinner(_certificatePinnerBuilder.Value.Build()); } if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop) { // Support TLS1.2 on Android versions before Lollipop builder.SslSocketFactory(new TlsSslSocketFactory(KeyManagers, TrustManagers), _x509TrustManager ?? TlsSslSocketFactory.GetSystemDefaultTrustManager()); } else if (_keyMgrFactory != null || _trustMgrFactory != null) { var context = SSLContext.GetInstance("TLS"); context.Init(KeyManagers, TrustManagers, null); builder.SslSocketFactory(context.SocketFactory, _x509TrustManager ?? TlsSslSocketFactory.GetSystemDefaultTrustManager()); } return(builder.Build()); }
private static SSLSocketFactory SelfSignedSocketFactory() { var trustManager = new SelfSignedTrustManager(); var sslContext = SSLContext.GetInstance("TLS"); sslContext.Init(null, new[] { trustManager }, null); return(sslContext.SocketFactory); }
/// <summary>Initializes the factory.</summary> /// <exception cref="GeneralSecurityException"> /// thrown if an SSL initialization error /// happened. /// </exception> /// <exception cref="System.IO.IOException"> /// thrown if an IO error happened while reading the SSL /// configuration. /// </exception> public virtual void Init() { keystoresFactory.Init(mode); context = SSLContext.GetInstance("TLS"); context.Init(keystoresFactory.GetKeyManagers(), keystoresFactory.GetTrustManagers (), null); context.GetDefaultSSLParameters().SetProtocols(enabledProtocols); hostnameVerifier = GetHostnameVerifier(conf); }
public TlsSslSocketFactory(IKeyManager[] keyManagers = null, ITrustManager[] trustManagers = null) { if (keyManagers != null || trustManagers != null) { var context = SSLContext.GetInstance("TLS"); context.Init(keyManagers, trustManagers, null); _factory = context.SocketFactory; } }
/// <summary> /// Sets up the socket factory and hostname verifier to allow all /// certificates for all servers. /// </summary> public static void SetupDangerous() { // we want to use a new trust manager (high risk!) var context = SSLContext.GetInstance("TLSv1.2"); context.Init(null, new ITrustManager[] { new NullX509TrustManager() }, new SecureRandom()); // apply the new context Setup(context.SocketFactory, new NullHostnameVerifier()); }
private SSLSocketFactory GetSocketFactory() { // Create an SSLContext that uses our TrustManager var context = SSLContext.GetInstance("TLSv1.2"); context.Init(null, new ITrustManager[] { new CustomX509TrustManager() }, null); // return the final socket factory return(context.SocketFactory); }
/// <exception cref="Sharpen.NoSuchAlgorithmException"></exception> /// <exception cref="Sharpen.KeyManagementException"></exception> public virtual SSLContext Build() { SSLContext sslcontext = SSLContext.GetInstance(this.protocol != null ? this.protocol : Tls); sslcontext.Init(!keymanagers.IsEmpty() ? Sharpen.Collections.ToArray(keymanagers, new KeyManager[keymanagers.Count]) : null, !trustmanagers.IsEmpty() ? Sharpen.Collections.ToArray (trustmanagers, new TrustManager[trustmanagers.Count]) : null, secureRandom); return(sslcontext); }
void SetupSSL(HttpsURLConnection httpsConnection) { if (httpsConnection == null) { return; } SSLSocketFactory socketFactory = ConfigureCustomSSLSocketFactory(httpsConnection); if (socketFactory != null) { httpsConnection.SSLSocketFactory = socketFactory; return; } KeyStore keyStore = KeyStore.GetInstance(KeyStore.DefaultType); keyStore.Load(null, null); bool gotCerts = TrustedCerts?.Count > 0; if (gotCerts) { for (int i = 0; i < TrustedCerts.Count; i++) { Certificate cert = TrustedCerts [i]; if (cert == null) { continue; } keyStore.SetCertificateEntry($"ca{i}", cert); } } keyStore = ConfigureKeyStore(keyStore); KeyManagerFactory kmf = ConfigureKeyManagerFactory(keyStore); TrustManagerFactory tmf = ConfigureTrustManagerFactory(keyStore); if (tmf == null) { // If there are no certs and no trust manager factory, we can't use a custom manager // because it will cause all the HTTPS requests to fail because of unverified trust // chain if (!gotCerts) { return; } tmf = TrustManagerFactory.GetInstance(TrustManagerFactory.DefaultAlgorithm); tmf.Init(keyStore); } SSLContext context = SSLContext.GetInstance("TLS"); context.Init(kmf?.GetKeyManagers(), tmf.GetTrustManagers(), null); httpsConnection.SSLSocketFactory = context.SocketFactory; }
/// <summary>Creates default SSL context based on system properties.</summary> /// <remarks> /// Creates default SSL context based on system properties. This method obtains /// default SSL context by calling <code>SSLContext.getInstance("Default")</code>. /// Please note that <code>Default</code> algorithm is supported as of Java 6. /// This method will fall back onto /// <see cref="CreateDefault()">CreateDefault()</see> /// when /// <code>Default</code> algorithm is not available. /// </remarks> /// <returns>default system SSL context</returns> /// <exception cref="Apache.Http.Conn.Ssl.SSLInitializationException"></exception> public static SSLContext CreateSystemDefault() { try { return(SSLContext.GetInstance("Default")); } catch (NoSuchAlgorithmException) { return(CreateDefault()); } }
public CallTrackerTask(string IpAddress, string deviceId) { _ipAddress = "https://" + IpAddress; _deviceId = deviceId; client.RetryOnConnectionFailure = true; SSLContext sslContext = SSLContext.GetInstance("SSL"); ITrustManager[] trustAllCerfs = new ITrustManager[] { new X509TrustManager() }; sslContext.Init(null, trustAllCerfs, new Java.Security.SecureRandom()); client.SetSslSocketFactory(sslContext.SocketFactory); client.SetHostnameVerifier(new HostNameVerifier()); }
public NativeMessageHandler(bool throwOnCaptiveNetwork, CustomSSLVerification customSSLVerification, NativeCookieHandler cookieHandler = null) { this.throwOnCaptiveNetwork = throwOnCaptiveNetwork; var clientBuilder = client.NewBuilder(); var specsBuilder = new ConnectionSpec.Builder(ConnectionSpec.ModernTls).TlsVersions(TlsVersion.Tls12); var specs = specsBuilder.Build(); clientBuilder.ConnectionSpecs(new List <ConnectionSpec>() { specs }); clientBuilder.Protocols(new[] { Protocol.Http11 }); // Required to avoid stream was reset: PROTOCOL_ERROR clientBuilder.HostnameVerifier(new HostnameVerifier(customSSLVerification.Pins)); this.CertificatePinnerBuilder = new CertificatePinner.Builder(); // Add Certificate Pins foreach (var pin in customSSLVerification.Pins) { this.CertificatePinnerBuilder.Add(pin.Hostname, pin.PublicKeys); } clientBuilder.CertificatePinner(CertificatePinnerBuilder.Build()); // Set client credentials SetClientCertificate(customSSLVerification.ClientCertificate); // Set SslSocketFactory if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop) { // Support TLS1.2 on Android versions before Lollipop clientBuilder.SslSocketFactory(new TlsSslSocketFactory(KeyManagers, null), TlsSslSocketFactory.GetSystemDefaultTrustManager()); } else { var sslContext = SSLContext.GetInstance("TLS"); sslContext.Init(KeyManagers, null, null); clientBuilder.SslSocketFactory(sslContext.SocketFactory, TlsSslSocketFactory.GetSystemDefaultTrustManager()); } if (cookieHandler != null) { clientBuilder.CookieJar(cookieHandler); } client = clientBuilder.Build(); }
private SSLSocketFactory GetFactory() { if (_factory != null) { return(_factory); } Android.Util.Log.Warn("ModernHttpClient", "ImprovedSSLSocketFactory : creating factory again"); var context = SSLContext.GetInstance("TLS"); context.Init(null, new[] { _trustManager }, null); _factory = context.SocketFactory; return(_factory); }
public Communicator() { trustAllSslContext = SSLContext.GetInstance("SSL"); trustAllSslContext.Init(null, new ITrustManager[] { new CustomX509TrustManager() }, new SecureRandom()); client = new OkHttpClient(); client.SetConnectTimeout(5, Java.Util.Concurrent.TimeUnit.Seconds); client.SetSslSocketFactory(trustAllSslContext.SocketFactory); client.SetHostnameVerifier(new CustomHostNameVerifier()); client.SetProtocols(new Protocol[] { Protocol.Http11 }); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().PermitAll().Build(); StrictMode.SetThreadPolicy(policy); }
private OkHttpClient GetUnsafeOkHttpClient() { ITrustManager[] trustAllCerts = new ITrustManager[] { new X509TrustManager() }; SSLContext sslContext = SSLContext.GetInstance("SSL"); sslContext.Init(null, trustAllCerts, null); SSLSocketFactory sslSocketFactory = sslContext.SocketFactory; OkHttpClient okHttpClient = new OkHttpClient(); okHttpClient.SetSslSocketFactory(sslSocketFactory); okHttpClient.SetHostnameVerifier(new UnsafeHostnameVerifier()); return(okHttpClient); }
//https://github.com/square/okhttp/issues/2372#issuecomment-244807676 public static OkHttpClient.Builder EnableTls12OnPreLollipopDevices(this OkHttpClient.Builder builder) { int currentVersion = (int)Build.VERSION.SdkInt; if (currentVersion >= 16 && currentVersion < 22) { try { //Creation of X509TrustManager : https://square.github.io/okhttp/3.x/okhttp/okhttp3/OkHttpClient.Builder.html#sslSocketFactory-javax.net.ssl.SSLSocketFactory-javax.net.ssl.X509TrustManager- var trustManagerFactory = TrustManagerFactory.GetInstance(TrustManagerFactory.DefaultAlgorithm); trustManagerFactory.Init((Java.Security.KeyStore)null); var trustManagers = trustManagerFactory.GetTrustManagers(); if (trustManagers.Length != 1) { throw new Java.Lang.IllegalStateException($"Unexpected default trust managers: {trustManagers}"); } var trustManager = trustManagers[0].JavaCast <IX509TrustManager>(); if (trustManager == null) { throw new Java.Lang.IllegalStateException($"Unexpected default trust managers: {trustManagers}"); } var context = SSLContext.GetInstance("TLS"); context.Init(null, new ITrustManager[] { trustManager }, null); builder.SslSocketFactory(new ImprovedSSLSocketFactory(context.SocketFactory, trustManager), trustManager); ConnectionSpec connectionSpec = new ConnectionSpec.Builder(ConnectionSpec.ModernTls) .TlsVersions(TlsVersion.Tls12) .Build(); List <ConnectionSpec> connexionSpecs = new List <ConnectionSpec> { new ConnectionSpec.Builder(ConnectionSpec.ModernTls).TlsVersions(TlsVersion.Tls12).Build(), ConnectionSpec.ModernTls, ConnectionSpec.CompatibleTls, ConnectionSpec.Cleartext, }; builder.ConnectionSpecs(connexionSpecs); } catch (Exception ex) { Android.Util.Log.Warn("ModernHttpClient", $"Unable to enable TLS 1.2 on okhttpclient: {ex}"); } } return(builder); }
public static void TrustEveryone() { try { HttpsURLConnection.DefaultHostnameVerifier = new HostnameVerifier(); SSLContext context = SSLContext.GetInstance("TLS"); context.Init(null, new ITrustManager[] { new MyX509TrustManager() }, new SecureRandom()); HttpsURLConnection.DefaultSSLSocketFactory = context.SocketFactory; } catch (Exception exc) { ToLog?.Invoke($"{nameof(TrustEveryone)}", $"{exc.Message}"); } }
private void SetHandler() { var algoritm = TrustManagerFactory.DefaultAlgorithm; var trustManagerFactory = TrustManagerFactory.GetInstance(algoritm); trustManagerFactory.Init((KeyStore)null); var tm = new ITrustManager[] { new PublicKeyManager() }; SSLContext sslContext = SSLContext.GetInstance("TLS"); sslContext.Init(null, tm, null); SSLContext.Default = sslContext; HttpsURLConnection.DefaultSSLSocketFactory = sslContext.SocketFactory; }
public void Open(string url, string protocol, IDictionary <string, string> headers) { try { var ssl = SSLContext.GetInstance("TLS"); ssl.Init(null, null, null); _controller = new BridgeController(ssl); _controller.Proxy = this; _controller.Open(url, protocol, headers); } catch (Exception ex) { OnError(ex.Message); } }
private static void trustAllHosts() { ITrustManager[] trustAllCerts = new TrustManager[] { }; try { SSLContext e = SSLContext.GetInstance("TLS"); e.Init((IKeyManager[])null, trustAllCerts, new SecureRandom()); HttpsURLConnection.DefaultSSLSocketFactory = e.SocketFactory; } catch (Java.Lang.Exception var2) { var2.PrintStackTrace(); } }
private void AllowAllHosts() { // Setting TrustAll trust manager and AllowAllHostNameVerifier ITrustManager[] trustAllCerts = new ITrustManager[] { new AllowAllTrustManager() }; try { SSLContext sc = SSLContext.GetInstance("SSL"); sc.Init(null, trustAllCerts, new Java.Security.SecureRandom()); HttpsURLConnection.DefaultSSLSocketFactory = sc.SocketFactory; HttpsURLConnection.DefaultHostnameVerifier = new AllowAllHostNameVerifier(); } catch (Exception e) { Log.Error(TAG, "Exception during setting TrustAll key manager", e); } }
/// <summary> /// Creates default factory based on the standard JSSE trust material /// (<code>cacerts</code> file in the security properties directory). /// </summary> /// <remarks> /// Creates default factory based on the standard JSSE trust material /// (<code>cacerts</code> file in the security properties directory). System properties /// are not taken into consideration. /// </remarks> /// <returns>the default SSL socket factory</returns> /// <exception cref="Apache.Http.Conn.Ssl.SSLInitializationException"></exception> public static SSLContext CreateDefault() { try { SSLContext sslcontext = SSLContext.GetInstance(SSLContextBuilder.Tls); sslcontext.Init(null, null, null); return(sslcontext); } catch (NoSuchAlgorithmException ex) { throw new SSLInitializationException(ex.Message, ex); } catch (KeyManagementException ex) { throw new SSLInitializationException(ex.Message, ex); } }
public static SSLSocketFactory createSSLSocketFactory() { SSLSocketFactory sSLSocketFactory = null; try { SSLContext sc = SSLContext.GetInstance("TLS"); sc.Init(null, new ITrustManager[] { new HttpsTrustManager() }, new SecureRandom()); sSLSocketFactory = sc.SocketFactory; } catch (Exception e) { } return(sSLSocketFactory); }
async Task <String> JavaConnectAndReceiveMessage() { var hostName = "192.168.1.103"; var port = 56111; // Build Java Keystore Stream keyin = Resources.OpenRawResource(Resource.Raw.ClientBKS); KeyStore ks = KeyStore.GetInstance("BKS"); ks.Load(keyin, "password".ToCharArray()); return(await Task.Run(() => { String defaultAlgorithm = KeyManagerFactory.DefaultAlgorithm; KeyManagerFactory keyManagerFactory = KeyManagerFactory.GetInstance(defaultAlgorithm); keyManagerFactory.Init(ks, "password".ToCharArray()); SSLContext sslContext = SSLContext.GetInstance("TLS"); sslContext.Init(keyManagerFactory.GetKeyManagers(), null, null); SSLSocketFactory sslSocketFactory = sslContext.SocketFactory; Javax.Net.Ssl.SSLSocket sslSocket = (Javax.Net.Ssl.SSLSocket)sslSocketFactory.CreateSocket(new Java.Net.Socket(hostName, port), hostName, port, false); sslSocket.AddHandshakeCompletedListener(this); sslSocket.NeedClientAuth = true; sslSocket.KeepAlive = true; sslSocket.StartHandshake(); // Exchange Messages Stream sslIS = sslSocket.InputStream; Stream sslOS = sslSocket.OutputStream; // Encode a test message into a byte array. // Signal the end of the message using the "<EOF>". byte[] messsage = Encoding.UTF8.GetBytes("Hello from the client.<EOF>"); sslOS.Write(messsage, 0, messsage.Length); sslOS.Flush(); string serverMessage = ReadMessage(sslIS); sslSocket.Close(); return serverMessage; })); }
/// <exception cref="System.IO.IOException"></exception> private void DisableSslVerify(URLConnection conn) { TrustManager[] trustAllCerts = new TrustManager[] { new TransportHttp.DummyX509TrustManager () }; try { SSLContext ctx = SSLContext.GetInstance("SSL"); ctx.Init(null, trustAllCerts, null); HttpsURLConnection sslConn = (HttpsURLConnection)conn; sslConn.SetSSLSocketFactory(ctx.GetSocketFactory()); } catch (KeyManagementException e) { throw new IOException(e.Message); } catch (NoSuchAlgorithmException e) { throw new IOException(e.Message); } }
private SSLContext GetSSLContext() { string protocol; if (SslProtocols == SslProtocols.Tls11) { protocol = "TLSv1.1"; } else if (SslProtocols == SslProtocols.Tls || SslProtocols == SslProtocols.Tls12) { protocol = "TLSv1.2"; } else { throw new IOException("unsupported ssl protocol: " + SslProtocols.ToString()); } SSLContext ctx = SSLContext.GetInstance(protocol); ctx.Init(keyManagers, trustManagers, null); return(ctx); }
protected override SSLSocketFactory ConfigureCustomSSLSocketFactory(HttpsURLConnection connection) { var algorithm = TrustManagerFactory.DefaultAlgorithm; var trustManagerFactory = TrustManagerFactory.GetInstance(algorithm); trustManagerFactory.Init((KeyStore)null); var trustManagers = trustManagerFactory.GetTrustManagers(); var context = SSLContext.GetInstance("TLS"); context.Init(null, trustManagers, null); SSLContext.Default = context; if (_trustManagerExt == null) { var x509TrustManager = trustManagers.FirstOrDefault(x => x is IX509TrustManager) as IX509TrustManager; _trustManagerExt = new X509TrustManagerExtensions(x509TrustManager); } return(context.SocketFactory); }
public CertificatePinning() { try { byte[] keyStoreBytes = Base64.Decode("H4sICIgmj1QAA2RlZmF1bHRfY2xpZW50X3RydXN0c3RvcmUuYmtzAN2aB1hUSbbHu5scJYPEBsnxNjlKziAgOSg0uQlNBgkiGVGyIogEQQQkqICIZBBQkSw5KxkRyQiI+BpBZ5xxxp19b+ftbn8fH9x7q4qqW+d3zv+cahAIBAaBQGRZ6Z6OVGc7OSWfRLZm21bvX5JmaQSBsFjBIIiQIKoNbBL3Fivo8INhxCsEiIFAEBkgBCIJhIDvQohcq2boiIY5BB+LvvRHa6+qBwgwcTgjVCI+EIDBEAwQYA7DA3Aw0fTRMUkh+rowSoD88AKXlNDAxh2hi7BDckNVkVa8MBFA6PABHimvvBPcwwMqANX2snRCWEG13RHOcHdfqLyNuyfCFmEF90S4IKGyXp72Lu4IT1+AnpJATBiA8YsBXz4mlAT8ooAo6oaAkJiQmMm/fgLBmb9eMxgDhBYcAwK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vQiHjU7rQ6XicBtFaFlbe6E3C3KF/chTdSyGh+vAKPn/WGNhJjXizkRuZuEcvG7vEUc8KNc+xYNboXas6aukLRjXr8WnMQNaGU1sUYV2u6jTpjoreWVuVU8dKT2ez4kW/uXyOnda2BavJRTSReXnAKNySmXgycZiXWy1a8oR/6EohaGBu6s8wZJH3J18bwNDnUFpsv6Vp9gTJfvlLyKsnUwVNcLp0577kKpYopgtz2/CYNY/2ouQVdM9q36auWFHh5reb4qxNPvTsffHBY35PNzRYga531s+rNsBTpD7fJIJzTZfakOU9Homv6nHs+VFWC/P4V+0rD5D9M0onJbjQWJmJ/kOZrLT2YMcm0nhhl1Iq4KegtbDjeTc7XUnyJnEHE0uN037x5JyXaqNAe1+h9CxxzevM4ZDWe1FsTUnp8C5fyhvJTTLxYeG33PNuUq+kaB+86tvO9kvukOp4X1aVbNQIyYa8PmdypIqXTjgj5FAvEcSg9pJcSGhG1pKBSK557rOM08cByCdxNz3zgF0dCTWL/5KPtTTIyRbP78/cRlMFcJiKt5zk3n01lmendytUDda2uNT5PAaglhClG7yDffioufTqyAlEmvdKwVgYr1qJ9o5X24AR++ocLBEObQgZBIxXOlHHp9MHWbw5aFKuKHStx/c5oqYe9V1+7OE4MqsDje/kgd8n78wklKwDo8r7rc1X0fwBxS2vGpDgAAA==", 0); KeyStore keyStore = KeyStore.GetInstance("BKS"); System.IO.MemoryStream ms = new System.IO.MemoryStream(keyStoreBytes); GZIPInputStream keyStoreInputStream = new GZIPInputStream(ms); //var readbytes = keyStoreInputStream.ToArray<byte>(); List <byte> values = new List <byte>(); bool notdone = true; while (notdone) { var input = keyStoreInputStream.Read(); if (input < 0 || input > 255) { break; } values.Add((byte)input); } try { keyStore.Load(new System.IO.MemoryStream(values.ToArray()), null); } finally { keyStoreInputStream.Close(); } TRUST_STORE = keyStore; String algorithm = TrustManagerFactory.DefaultAlgorithm; TrustManagerFactory trustManagerFactory = TrustManagerFactory.GetInstance(algorithm); trustManagerFactory.Init(keyStore); SSLContext context = SSLContext.GetInstance("TLS"); context.Init(null, trustManagerFactory.GetTrustManagers(), null); SSL_CONTEXT = context; } catch (Exception e) { } }
private OkHttpClient CreateOkHttpClientInstance() { var builder = new OkHttpClient.Builder() .ConnectTimeout(100, TimeUnit.Seconds) .WriteTimeout(100, TimeUnit.Seconds) .ReadTimeout(100, TimeUnit.Seconds) .FollowRedirects(AllowAutoRedirect) .AddInterceptor(new DecompressInterceptor(_logger)); if (UseCookies) { builder.CookieJar(new JavaNetCookieJar(new Java.Net.CookieManager())); } if (!UseProxy) { builder.Proxy(Java.Net.Proxy.NoProxy); } else if (Proxy is WebProxy webProxy) { var proxyAddress = new InetSocketAddress(webProxy.Address.Host, webProxy.Address.Port); builder.Proxy(new Proxy(Java.Net.Proxy.Type.Http, proxyAddress)); } if (_certificatePinnerBuilder.IsValueCreated) { builder.CertificatePinner(_certificatePinnerBuilder.Value.Build()); } if (_keyMgrFactory != null || _trustMgrFactory != null) { var context = SSLContext.GetInstance("TLS"); context.Init(KeyManagers, TrustManagers, null); builder.SslSocketFactory(context.SocketFactory, _x509TrustManager ?? TlsSslSocketFactory.GetSystemDefaultTrustManager()); } return(builder.Build()); }
protected override void OnCreate(Bundle bundle) { try { base.OnCreate(bundle); InputDialog.DisplayDialog += OnDisplayDialog; AndroidEnvironment.UnhandledExceptionRaiser += HandleUnhandledException; global::Xamarin.Forms.Forms.Init(this, bundle); context = ApplicationContext; // or activity.getApplicationContext() PackageManager packageManager = context.PackageManager; string packageName = context.PackageName; AppData.Version = new OnSiteVersion(string.Format("{0}", packageManager.GetPackageInfo(packageName, 0).VersionName)); LoadApplication(new App()); //AppContext.AppContext.ShowInput = () => //{ // InputMethodManager showinput = (InputMethodManager)GetSystemService(InputMethodService); // showinput.ToggleSoftInput(ShowFlags.Forced, 0); //}; if (Build.VERSION.SdkInt <= BuildVersionCodes.Kitkat) { ProviderInstaller.InstallIfNeeded(ApplicationContext); } SSLContext sslContext = SSLContext.GetInstance("TLSv1.2"); sslContext.Init(null, null, null); SSLEngine engine = sslContext.CreateSSLEngine(); } catch (Exception ex) { LogTracking.LogTrace(ex.ToString()); } }
public NativeMessageHandler() { var clientBuilder = _client.NewBuilder(); // tls var tlsSpecBuilder = new ConnectionSpec.Builder(ConnectionSpec.ModernTls).TlsVersions(new[] { TlsVersion.Tls12, TlsVersion.Tls13 }); var tlsSpec = tlsSpecBuilder.Build(); var specs = new List <ConnectionSpec>() { tlsSpec, ConnectionSpec.Cleartext }; clientBuilder.ConnectionSpecs(specs); // 始终有Http11避免PROTOCOL_ERROR clientBuilder.Protocols(new[] { Protocol.Http11, Protocol.Http2 }); // 信任所有服务器证书,支持自签名证书 var sslContext = SSLContext.GetInstance("TLS"); var trustManager = new CustomX509TrustManager(); sslContext.Init(null, new ITrustManager[] { trustManager }, new SecureRandom()); // Create an ssl socket factory with our all-trusting manager var sslSocketFactory = sslContext.SocketFactory; clientBuilder.SslSocketFactory(sslSocketFactory, trustManager); // 读始终不超时,配合服务器推送 clientBuilder.ReadTimeout(0, TimeUnit.Milliseconds); clientBuilder.WriteTimeout(0, TimeUnit.Milliseconds); clientBuilder.CallTimeout(0, TimeUnit.Milliseconds); // Hostname始终有效 clientBuilder.HostnameVerifier((name, ssl) => true); _client = clientBuilder.Build(); }