public MqttClientOptionsBuilder WithTls() { _tlsOptions = new MqttClientTlsOptions { UseTls = true }; return(this); }
public MqttClientOptions Build() { if (_tcpOptions == null && _webSocketOptions == null) { throw new InvalidOperationException("A channel must be set."); } if (_tlsParameters != null) { if (_tlsParameters?.UseTls == true) { var tlsOptions = new MqttClientTlsOptions { UseTls = true, SslProtocol = _tlsParameters.SslProtocol, AllowUntrustedCertificates = _tlsParameters.AllowUntrustedCertificates, CertificateValidationHandler = _tlsParameters.CertificateValidationHandler, IgnoreCertificateChainErrors = _tlsParameters.IgnoreCertificateChainErrors, IgnoreCertificateRevocationErrors = _tlsParameters.IgnoreCertificateRevocationErrors, #if WINDOWS_UWP Certificates = _tlsParameters.Certificates?.Select(c => c.ToArray()).ToList(), #else Certificates = _tlsParameters.Certificates?.ToList(), #endif #if NETCOREAPP3_1 || NET5_0_OR_GREATER ApplicationProtocols = _tlsParameters.ApplicationProtocols, #endif }; if (_tcpOptions != null) { _tcpOptions.TlsOptions = tlsOptions; } else if (_webSocketOptions != null) { _webSocketOptions.TlsOptions = tlsOptions; } } } if (_proxyOptions != null) { if (_webSocketOptions == null) { throw new InvalidOperationException("Proxies are only supported for WebSocket connections."); } _webSocketOptions.ProxyOptions = _proxyOptions; } _options.ChannelOptions = (IMqttClientChannelOptions)_tcpOptions ?? _webSocketOptions; return(_options); }
public IMqttClientOptions Build() { if (_tcpOptions == null && _webSocketOptions == null) { throw new InvalidOperationException("A channel must be set."); } if (_tlsParameters != null) { if (_tlsParameters?.UseTls == true) { var tlsOptions = new MqttClientTlsOptions { UseTls = true, SslProtocol = _tlsParameters.SslProtocol, AllowUntrustedCertificates = _tlsParameters.AllowUntrustedCertificates, Certificates = _tlsParameters.Certificates?.Select(c => c.ToArray()).ToList(), CertificateValidationCallback = _tlsParameters.CertificateValidationCallback, IgnoreCertificateChainErrors = _tlsParameters.IgnoreCertificateChainErrors, IgnoreCertificateRevocationErrors = _tlsParameters.IgnoreCertificateRevocationErrors }; if (_tcpOptions != null) { _tcpOptions.TlsOptions = tlsOptions; } else if (_webSocketOptions != null) { _webSocketOptions.TlsOptions = tlsOptions; } } } if (_proxyOptions != null) { if (_webSocketOptions == null) { throw new InvalidOperationException("Proxies are only supported for WebSocket connections."); } _webSocketOptions.ProxyOptions = _proxyOptions; } _options.ChannelOptions = (IMqttClientChannelOptions)_tcpOptions ?? _webSocketOptions; return(_options); }
public MqttClientOptionsBuilder WithTls( bool allowUntrustedCertificates = false, bool ignoreCertificateChainErrors = false, bool ignoreCertificateRevocationErrors = false, params byte[][] certificates) { _tlsOptions = new MqttClientTlsOptions { UseTls = true, AllowUntrustedCertificates = allowUntrustedCertificates, IgnoreCertificateChainErrors = ignoreCertificateChainErrors, IgnoreCertificateRevocationErrors = ignoreCertificateRevocationErrors, Certificates = certificates?.ToList() }; return(this); }