internal static HttpClient CreateHttpClient(LndRestSettings settings) { var handler = new HttpClientHandler { SslProtocols = SslProtocols.Tls12 }; var expectedThumbprint = settings.CertificateThumbprint?.ToArray(); if (expectedThumbprint != null) { handler.ServerCertificateCustomValidationCallback = (request, cert, chain, errors) => { var actualCert = chain.ChainElements[chain.ChainElements.Count - 1].Certificate; var hash = actualCert.GetCertHash(System.Security.Cryptography.HashAlgorithmName.SHA256); return(hash.SequenceEqual(expectedThumbprint)); }; } if (settings.AllowInsecure) { handler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator; } else { if (settings.Uri.Scheme == "http") { throw new InvalidOperationException("AllowInsecure is set to false, but the URI is not using https"); } } return(new HttpClient(handler)); }
public LndSwaggerClient(LndRestSettings settings) { if (settings == null) { throw new ArgumentNullException(nameof(settings)); } _LndSettings = settings; _Authentication = settings.CreateLndAuthentication(); BaseUrl = settings.Uri.AbsoluteUri.TrimEnd('/'); _httpClient = CreateHttpClient(settings); _settings = new System.Lazy <Newtonsoft.Json.JsonSerializerSettings>(() => { var json = new Newtonsoft.Json.JsonSerializerSettings(); UpdateJsonSerializerSettings(json); return(json); }); }