Skip to content

Commit

Permalink
support ca crt
Browse files Browse the repository at this point in the history
  • Loading branch information
Abimbola Idowu committed May 7, 2023
1 parent c791a8b commit 1022ec7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
18 changes: 17 additions & 1 deletion TeslaSolarCharger/Server/Services/SolarMqttService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using TeslaSolarCharger.Shared.Dtos.Contracts;
using TeslaSolarCharger.Shared.Dtos.BaseConfiguration;
using TeslaSolarCharger.Shared.Enums;
using System.Security.Cryptography.X509Certificates;

namespace TeslaSolarCharger.Server.Services;

Expand Down Expand Up @@ -40,10 +41,25 @@ public async Task ConnectMqttClient()
{
_logger.LogDebug("No Mqtt Options defined for solar power. Do not connect MQTT Client.");
}

var caCert = new X509Certificate2("/app/venus-ca.crt");

var mqttClientOptions = new MqttClientOptionsBuilder()
.WithClientId(mqqtClientId)
.WithTimeout(TimeSpan.FromSeconds(5))
.WithTcpServer(mqttServer, mqttServerPort)
.WithTls(new MqttClientOptionsBuilderTlsParameters
{
UseTls = true,
AllowUntrustedCertificates = true,
IgnoreCertificateChainErrors = true,
IgnoreCertificateRevocationErrors = true,
CertificateValidationHandler = (context) =>
{
return true;
},
Certificates = new List<X509Certificate> { caCert }
})
.Build();

if(!string.IsNullOrWhiteSpace(_configurationWrapper.SolarMqttUsername()) && !string.IsNullOrEmpty(_configurationWrapper.SolarMqttPassword()))
Expand Down Expand Up @@ -120,7 +136,7 @@ public async Task ConnectMqttClient()
{
_logger.LogWarning("Received value does not match a topic");
}

return Task.CompletedTask;
};

Expand Down
24 changes: 24 additions & 0 deletions TeslaSolarCharger/Server/venus-ca.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-----BEGIN CERTIFICATE-----
MIIECTCCAvGgAwIBAgIJAM+t3iC8ybEHMA0GCSqGSIb3DQEBCwUAMIGZMQswCQYD
VQQGEwJOTDESMBAGA1UECAwJR3JvbmluZ2VuMRIwEAY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