diff --git a/samples/aws-sample/aws-sample.csproj b/samples/aws-sample/aws-sample.csproj index f05375f..2b64f03 100644 --- a/samples/aws-sample/aws-sample.csproj +++ b/samples/aws-sample/aws-sample.csproj @@ -15,4 +15,13 @@ + + + + PreserveNewest + + + PreserveNewest + + diff --git a/samples/aws-sample/ridotest.cert.pem b/samples/aws-sample/ridotest.cert.pem new file mode 100644 index 0000000..3a3e7bb --- /dev/null +++ b/samples/aws-sample/ridotest.cert.pem @@ -0,0 +1,20 @@ +-----BEGIN CERTIFICATE----- +MIIDWjCCAkKgAwIBAgIVALqEepMGtu88f80cK6A5bQkwpJE4MA0GCSqGSIb3DQEB +CwUAME0xSzBJBgNVBAsMQkFtYXpvbiBXZWIgU2VydmljZXMgTz1BbWF6b24uY29t +IEluYy4gTD1TZWF0dGxlIFNUPVdhc2hpbmd0b24gQz1VUzAeFw0yNDA1MzAxNTQ5 +MjFaFw00OTEyMzEyMzU5NTlaMB4xHDAaBgNVBAMME0FXUyBJb1QgQ2VydGlmaWNh +dGUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDEFFSVsoAYYEW06YZg +2DV71UaZFeJ15HIl7PSFKv5Lz5l7/qR0KufEhqNCJ8X7KbqGEe1feSM69Z1tUmXs +eruWXw+eGudhmVYogNY7GsIBBNMr8Lzi8RCaSBOViHBQXzxN8vp7u7wTPrOwWwTZ +NY0jHPT7kjcYDEHvVQt1HUB831Zc9lV7kSXXiUeiezJ3WtivQ77dtGZN4j6i6qcJ +kFYxf0svyAxMBOwsgUbosmTpGBa+CEv7QsT94uv2ZbkkpDp0h1VvwY+e+9v9xzJD +d2Tg5TcJFcqkpqhKtNVkmaqkoQN1AgYwcCieRV3s4Uxyp9ElkBw2aM3+65ae1GZs +wjqDAgMBAAGjYDBeMB8GA1UdIwQYMBaAFFtqSrj/zrgoKnCaKqjaJGRaEQNmMB0G +A1UdDgQWBBSCWAJITMHxqeZAx155EjdaeArhoTAMBgNVHRMBAf8EAjAAMA4GA1Ud +DwEB/wQEAwIHgDANBgkqhkiG9w0BAQsFAAOCAQEAGfaI6IqxCmwo+Y+7bxeQ/8FO +AmwCxluomreigTVMgdnhG5XtJiOAeuWJqorzwFouTs3a5XQQiTU3Tjqwzp4VwntM +k1GGOjkk0VxsuYqxQYmGjpLgZ6UWBI6HFXJgKiropUv+NPekxNa2wPuFvHkcYku4 +F8aS+fuSZBAeL0uNixhgsO2ZzBPXFJTj28gcpYYOrevUAijoNsNLvLpx2XHwQSOT +uSiB0D4oD7JGHhXsgg7QMUvLnbt/Bdc9Cn1gBLYwShr6QhOjGxWxB8ReXVsQRiKb +G1ueKK1BUawFkR33LWsn5pUE2BekifAN+CcJoDtmBuf5E5rFdxeEgJ9Q+yEsfA== +-----END CERTIFICATE----- diff --git a/samples/memmon-protobuff/memmon-protobuff.csproj b/samples/memmon-protobuff/memmon-protobuff.csproj index 649be11..d9b789f 100644 --- a/samples/memmon-protobuff/memmon-protobuff.csproj +++ b/samples/memmon-protobuff/memmon-protobuff.csproj @@ -16,7 +16,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/samples/memmon/memmon.csproj b/samples/memmon/memmon.csproj index cde5241..07d07f6 100644 --- a/samples/memmon/memmon.csproj +++ b/samples/memmon/memmon.csproj @@ -22,7 +22,7 @@ - + diff --git a/samples/pi-sense-device/pi-sense-device.csproj b/samples/pi-sense-device/pi-sense-device.csproj index e26cc8d..bfd49f3 100644 --- a/samples/pi-sense-device/pi-sense-device.csproj +++ b/samples/pi-sense-device/pi-sense-device.csproj @@ -37,7 +37,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/src/MQTTnet.Extensions.MultiCloud.AzureIoTClient/HubDpsFactory.cs b/src/MQTTnet.Extensions.MultiCloud.AzureIoTClient/HubDpsFactory.cs index 6325edf..35dc4b6 100644 --- a/src/MQTTnet.Extensions.MultiCloud.AzureIoTClient/HubDpsFactory.cs +++ b/src/MQTTnet.Extensions.MultiCloud.AzureIoTClient/HubDpsFactory.cs @@ -23,7 +23,7 @@ public static async Task CreateFromConnectionSettingsAsync(Connecti var dpsRes = await dpsClient.ProvisionDeviceIdentity(); cs.HostName = dpsRes.RegistrationState.AssignedHub; cs.ClientId = dpsRes.RegistrationState.DeviceId; - await dpsMqtt.DisconnectAsync(new MqttClientDisconnectOptions() { Reason = MqttClientDisconnectReason.NormalDisconnection }, cancellationToken); + await dpsMqtt.DisconnectAsync(new MqttClientDisconnectOptions() { Reason = MqttClientDisconnectOptionsReason.NormalDisconnection }, cancellationToken); } var mqtt = new MqttFactory().CreateMqttClient(MqttNetTraceLogger.CreateTraceLogger()) as MqttClient; MqttClientConnectResult connAck; diff --git a/src/MQTTnet.Extensions.MultiCloud/Connections/WithTlsSettings.cs b/src/MQTTnet.Extensions.MultiCloud/Connections/WithTlsSettings.cs index 4804a76..b05cec8 100644 --- a/src/MQTTnet.Extensions.MultiCloud/Connections/WithTlsSettings.cs +++ b/src/MQTTnet.Extensions.MultiCloud/Connections/WithTlsSettings.cs @@ -8,10 +8,8 @@ public static partial class MqttNetExtensions { public static MqttClientOptionsBuilder WithTlsSettings(this MqttClientOptionsBuilder builder, ConnectionSettings cs) { - var tls = new MqttClientOptionsBuilderTlsParameters - { - UseTls = cs.UseTls - }; + + var tls = new MqttClientTlsOptionsBuilder(); if (cs.UseTls) { var certs = new List(); @@ -34,15 +32,16 @@ public static MqttClientOptionsBuilder WithTlsSettings(this MqttClientOptionsBui X509Certificate2Collection caCerts = new(); caCerts.ImportFromPemFile(cs.CaFile); certs.AddRange(caCerts); - tls.CertificateValidationHandler = ea => X509ChainValidator.ValidateChain(ea.Certificate, cs.CaFile); + tls.WithCertificateValidationHandler(ea => X509ChainValidator.ValidateChain(ea.Certificate, cs.CaFile)); + } else { - tls.CertificateValidationHandler += ea => X509ChainValidator.ValidateChain(ea.Certificate); + tls.WithCertificateValidationHandler(ea => X509ChainValidator.ValidateChain(ea.Certificate)); } - tls.Certificates = certs; - tls.IgnoreCertificateRevocationErrors = cs.DisableCrl; - builder.WithTls(tls); + tls.WithClientCertificates(certs); + tls.WithIgnoreCertificateRevocationErrors(cs.DisableCrl); + builder.WithTlsOptions(tls.Build()); } return builder; } diff --git a/src/MQTTnet.Extensions.MultiCloud/MQTTnet.Extensions.MultiCloud.csproj b/src/MQTTnet.Extensions.MultiCloud/MQTTnet.Extensions.MultiCloud.csproj index 691a9af..278414e 100644 --- a/src/MQTTnet.Extensions.MultiCloud/MQTTnet.Extensions.MultiCloud.csproj +++ b/src/MQTTnet.Extensions.MultiCloud/MQTTnet.Extensions.MultiCloud.csproj @@ -18,7 +18,7 @@ - + diff --git a/tests/MQTTnet.Extensions.MultiCloud.IntegrationTests/AzPubSubConnectionFixture.cs b/tests/MQTTnet.Extensions.MultiCloud.IntegrationTests/AzPubSubConnectionFixture.cs index 30a5f63..83f58b0 100644 --- a/tests/MQTTnet.Extensions.MultiCloud.IntegrationTests/AzPubSubConnectionFixture.cs +++ b/tests/MQTTnet.Extensions.MultiCloud.IntegrationTests/AzPubSubConnectionFixture.cs @@ -21,7 +21,7 @@ public async Task ConenctToAzPubSub() }; var mqtt = await BrokerClientFactory.CreateFromConnectionSettingsAsync(cs); Assert.True(mqtt.IsConnected); - await mqtt.DisconnectAsync(new Client.MqttClientDisconnectOptions() { Reason = Client.MqttClientDisconnectReason.NormalDisconnection}); + await mqtt.DisconnectAsync(new Client.MqttClientDisconnectOptions() { Reason = Client.MqttClientDisconnectOptionsReason.NormalDisconnection}); } } } diff --git a/tests/MQTTnet.Extensions.MultiCloud.IntegrationTests/HubDpsFactoryFixture.cs b/tests/MQTTnet.Extensions.MultiCloud.IntegrationTests/HubDpsFactoryFixture.cs index b620023..ac2018f 100644 --- a/tests/MQTTnet.Extensions.MultiCloud.IntegrationTests/HubDpsFactoryFixture.cs +++ b/tests/MQTTnet.Extensions.MultiCloud.IntegrationTests/HubDpsFactoryFixture.cs @@ -25,7 +25,7 @@ public async Task CheckComputedConnectionSettingsWhenUsingDPS() Assert.Equal("tests.azure-devices.net", HubDpsFactory.ComputedSettings!.HostName); await client.DisconnectAsync( new MqttClientDisconnectOptionsBuilder() - .WithReason(MqttClientDisconnectReason.NormalDisconnection) + .WithReason(MqttClientDisconnectOptionsReason.NormalDisconnection) .Build()); } @@ -43,7 +43,7 @@ public async Task DpsCert() Assert.Equal("tests.azure-devices.net", HubDpsFactory.ComputedSettings!.HostName); await client.DisconnectAsync( new MqttClientDisconnectOptionsBuilder() - .WithReason(MqttClientDisconnectReason.NormalDisconnection) + .WithReason(MqttClientDisconnectOptionsReason.NormalDisconnection) .Build()); } @@ -61,7 +61,7 @@ public async Task CheckComputedConnectionSettingsWhenNotUsingDPS() Assert.Equal(Environment.GetEnvironmentVariable("TestHubName"), HubDpsFactory.ComputedSettings!.HostName); await client.DisconnectAsync( new MqttClientDisconnectOptionsBuilder() - .WithReason(MqttClientDisconnectReason.NormalDisconnection) + .WithReason(MqttClientDisconnectOptionsReason.NormalDisconnection) .Build()); } } diff --git a/tests/MQTTnet.Extensions.MultiCloud.UnitTests/MockMqttClient.cs b/tests/MQTTnet.Extensions.MultiCloud.UnitTests/MockMqttClient.cs index 564b0b0..c637529 100644 --- a/tests/MQTTnet.Extensions.MultiCloud.UnitTests/MockMqttClient.cs +++ b/tests/MQTTnet.Extensions.MultiCloud.UnitTests/MockMqttClient.cs @@ -2,6 +2,7 @@ using MQTTnet.Diagnostics; using MQTTnet.Packets; using System; +using System.Collections.Generic; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -41,6 +42,7 @@ public MockMqttClient(string clientId) public event Func DisconnectedAsync; public event Func ApplicationMessageReceivedAsync; public event Func InspectPackage; + public event Func InspectPacketAsync; //public event EventHandler OnMqttClientDisconnected; //public event Func OnMessage; @@ -136,14 +138,15 @@ public Task SubscribeAsync(MqttClientSubscribeOptions { numSubscriptions++; //options.TopicFilters.ForEach(t => Trace.TraceInformation(t.Topic)); - var subAck = new MqttClientSubscribeResult(); + List results = new(); + var subAck = new MqttClientSubscribeResult(0, results, "", new List()); return Task.FromResult(subAck); } public Task UnsubscribeAsync(MqttClientUnsubscribeOptions options, CancellationToken cancellationToken = default) { numSubscriptions--; - return Task.FromResult(new MqttClientUnsubscribeResult()); + return Task.FromResult(new MqttClientUnsubscribeResult(0, new List(), "", new List())); } public Task PublishAsync(MqttApplicationMessage applicationMessage, CancellationToken cancellationToken = default) @@ -161,7 +164,7 @@ public Task PublishAsync(MqttApplicationMessage applica topicRecceived = applicationMessage.Topic; payloadReceived = jsonPayload!;// != null ? Encoding.UTF8.GetString(payload) : string.Empty; - return Task.FromResult(new MqttClientPublishResult()); + return Task.FromResult(new MqttClientPublishResult(0, MqttClientPublishReasonCode.Success, "", new List())); } public void Dispose()