public PowerwallClient(string ipAddress, ushort port, HSPI hs, string email, string password) { _ipAddress = ipAddress; _port = port; HttpClientHandler handler = new HttpClientHandler(); _httpClient = new HttpClient(handler); _jsonSerializer = new JavaScriptSerializer(); _hs = hs; _email = email; _password = password; UpstreamIpAddress = ""; // Powerwall Gateway uses a self-signed certificate, so let's accept it unconditionally handler.ServerCertificateCustomValidationCallback = (sender, certificate, chain, sslPolicyErrors) => { if (certificate.SubjectName.Name != null) { try { string commonName = certificate.SubjectName.Name .Split(',') .Select(i => i.Trim()) .First(i => i.StartsWith("CN=")) .Substring(3); if (commonName.StartsWith("TLSPROXY:")) { string upstreamIp = commonName.Substring(9); if (upstreamIp != UpstreamIpAddress) { UpstreamIpAddress = upstreamIp; _hs.WriteLog(ELogType.Info, $"Detected TLS proxy for upstream address {UpstreamIpAddress}"); } } } catch (Exception) { // No CN, ignore } } // Trust certificate always return(true); }; handler.UseCookies = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; }
public static void Main(string[] args) { HSPI plugin = new HSPI(); plugin.Connect(args); }
public AnalyticsClient(HSPI plugin, IHsController hs) { _plugin = plugin; _hs = hs; }