diff --git a/.vs/MyCore/v15/Server/sqlite3/storage.ide b/.vs/MyCore/v15/Server/sqlite3/storage.ide index a5369d2..3303ca8 100644 Binary files a/.vs/MyCore/v15/Server/sqlite3/storage.ide and b/.vs/MyCore/v15/Server/sqlite3/storage.ide differ diff --git a/.vs/MyCore/v15/Server/sqlite3/storage.ide-wal b/.vs/MyCore/v15/Server/sqlite3/storage.ide-wal index 9b3cb90..6938aa0 100644 Binary files a/.vs/MyCore/v15/Server/sqlite3/storage.ide-wal and b/.vs/MyCore/v15/Server/sqlite3/storage.ide-wal differ diff --git a/MyCore/Services/MerossService.cs b/MyCore/Services/MerossService.cs index c3021db..41e2af5 100644 --- a/MyCore/Services/MerossService.cs +++ b/MyCore/Services/MerossService.cs @@ -197,21 +197,17 @@ namespace MyCore.Services _client = new MqttFactory().CreateMqttClient(); string stringForMD5 = resultToken.userid + resultToken.key; - string hashed_password = CreateMD5(stringForMD5); - - MqttClientOptionsBuilderTlsParameters tlsParameters = new MqttClientOptionsBuilderTlsParameters(); - tlsParameters.UseTls = true; - tlsParameters.SslProtocol = System.Security.Authentication.SslProtocols.Tls; + string hashed_password = CreateMD5(stringForMD5).ToLower(); _options = new MqttClientOptionsBuilder() - .WithClientId("app: 08d4c9f99da40203ebc798a79512ec14") + .WithClientId("app:ddddd9eb14407b666f559af5af9c1840") .WithTcpServer(domain, port) .WithCredentials(resultToken.userid, hashed_password) - .WithTls(tlsParameters) + .WithCleanSession() + .WithTls() .WithProtocolVersion(MqttProtocolVersion.V311) .Build(); - _client.ConnectAsync(_options, CancellationToken.None).ContinueWith(res => { if (res.Status == TaskStatus.RanToCompletion) { @@ -265,5 +261,54 @@ namespace MyCore.Services } } + + private static bool CertificateValidationCallBack( + object sender, + System.Security.Cryptography.X509Certificates.X509Certificate certificate, + System.Security.Cryptography.X509Certificates.X509Chain chain, + System.Net.Security.SslPolicyErrors sslPolicyErrors) + { + // If the certificate is a valid, signed certificate, return true. + if (sslPolicyErrors == System.Net.Security.SslPolicyErrors.None) + { + return true; + } + + // If there are errors in the certificate chain, look at each error to determine the cause. + if ((sslPolicyErrors & System.Net.Security.SslPolicyErrors.RemoteCertificateChainErrors) != 0) + { + if (chain != null && chain.ChainStatus != null) + { + foreach (System.Security.Cryptography.X509Certificates.X509ChainStatus status in chain.ChainStatus) + { + if ((certificate.Subject == certificate.Issuer) && + (status.Status == System.Security.Cryptography.X509Certificates.X509ChainStatusFlags.UntrustedRoot)) + { + // Self-signed certificates with an untrusted root are valid. + continue; + } + else + { + if (status.Status != System.Security.Cryptography.X509Certificates.X509ChainStatusFlags.NoError) + { + // If there are any other errors in the certificate chain, the certificate is invalid, + // so the method returns false. + return false; + } + } + } + } + + // When processing reaches this line, the only errors in the certificate chain are + // untrusted root errors for self-signed certificates. These certificates are valid + // for default Exchange server installations, so return true. + return true; + } + else + { + // In all other cases, return false. + return false; + } + } } }