From a62878f5c54791ec0a4176ffaa66d300c09fcaae Mon Sep 17 00:00:00 2001 From: rido-min Date: Thu, 30 May 2024 09:35:48 -0700 Subject: [PATCH 1/2] upd nugets --- samples/aws-sample/aws-sample.csproj | 9 +++++++ samples/aws-sample/ridotest.cert.pem | 20 ++++++++++++++ samples/aws-sample/ridotest.private.key | 27 +++++++++++++++++++ .../memmon-protobuff/memmon-protobuff.csproj | 2 +- samples/memmon/memmon.csproj | 2 +- .../pi-sense-device/pi-sense-device.csproj | 2 +- .../HubDpsFactory.cs | 2 +- .../Connections/WithTlsSettings.cs | 17 ++++++------ .../MQTTnet.Extensions.MultiCloud.csproj | 2 +- .../AzPubSubConnectionFixture.cs | 2 +- .../HubDpsFactoryFixture.cs | 6 ++--- .../MockMqttClient.cs | 9 ++++--- 12 files changed, 79 insertions(+), 21 deletions(-) create mode 100644 samples/aws-sample/ridotest.cert.pem create mode 100644 samples/aws-sample/ridotest.private.key 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/aws-sample/ridotest.private.key b/samples/aws-sample/ridotest.private.key new file mode 100644 index 0000000..db499f6 --- /dev/null +++ b/samples/aws-sample/ridotest.private.key @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEowIBAA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D547ocjJzlmdIR28uoQcCgYAO3DqbgFRsvzo/tygdQOXk +JGfBuqHc1TrA8rzdoozwKTZ6c347yEgtN9CLDCYN8I2i+72iWKH1Ab3pUfjoP8p2 +ExFaIOGTnL52G5mCxLmMbvveCnTUr57tuJuEc4XCTN/xP1HiRJcy18WaLl/BgyuC +1dAQC01fldYCOe5XB/5HkQKBgEKpWqUShpPgV3xkmZElKYlcVQKQBL69Sje0pgRb +mbv8DN2g2cKNz+uIc2Ekq2LIP8KNdgGTmoC8RMPduYmB9rjqypcA/w0/Xq+UwagK +eS23eQor0bqtrre568Yn4o4Kh9o65c7EfHqiBR5aSGbug2cCiyLtXH279fMNeYHW +ouEZAoGBAMIq2s+n2yzhfth01v+gqxkZ9ejSqPuIZEof/iJzafSlML8wPumHxKH0 +zXXo6LQf+U05LVZ7ef/hQgenTxmVKbcuX2HXVi/1zar0IFK1SP+f6U0bcICRwD95 +uUn5i4UWSdd1/DOijOxm0Vzw0dr2WEP3GNJSS3knl2hEjBdIKubl +-----END RSA PRIVATE KEY----- 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() From b55e3617c2bfbda674b1a351543a678ae237f560 Mon Sep 17 00:00:00 2001 From: rido-min Date: Thu, 30 May 2024 09:37:52 -0700 Subject: [PATCH 2/2] rm priv key --- samples/aws-sample/ridotest.private.key | 27 ------------------------- 1 file changed, 27 deletions(-) delete mode 100644 samples/aws-sample/ridotest.private.key diff --git a/samples/aws-sample/ridotest.private.key b/samples/aws-sample/ridotest.private.key deleted file mode 100644 index db499f6..0000000 --- a/samples/aws-sample/ridotest.private.key +++ /dev/null @@ -1,27 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEowIBAAKCAQEAxBRUlbKAGGBFtOmGYNg1e9VGmRXideRyJez0hSr+S8+Ze/6k -dCrnxIajQifF+ym6hhHtX3kjOvWdbVJl7Hq7ll8PnhrnYZlWKIDWOxrCAQTTK/C8 -4vEQmkgTlYhwUF88TfL6e7u8Ez6zsFsE2TWNIxz0+5I3GAxB71ULdR1AfN9WXPZV -e5El14lHonsyd1rYr0O+3bRmTeI+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