/// <summary> /// Default constructor /// </summary> public MqttTlsOptions() { m_certificates = null; m_SslProtocolVersion = SslProtocols.None; m_allowUntrustedCertificates = false; m_ignoreCertificateChainErrors = false; m_ignoreRevocationListErrors = false; m_trustedIssuerCertificates = null; m_trustedPeerCertificates = null; m_rejectedCertificateStore = null; }
/// <summary> /// Constructor /// </summary> /// <param name="kvpMqttOptions">The key value pairs representing the values from which to construct MqttTlsOptions</param> public MqttTlsOptions(KeyValuePairCollection kvpMqttOptions) { m_certificates = new MqttTlsCertificates(kvpMqttOptions); QualifiedName qSslProtocolVersion = EnumMqttClientConfigurationParameters.TlsProtocolVersion.ToString(); m_SslProtocolVersion = (SslProtocols)Convert.ToInt32(kvpMqttOptions.Find(kvp => kvp.Key.Name.Equals(qSslProtocolVersion.Name))?.Value.Value); QualifiedName qAllowUntrustedCertificates = EnumMqttClientConfigurationParameters.TlsAllowUntrustedCertificates.ToString(); m_allowUntrustedCertificates = Convert.ToBoolean(kvpMqttOptions.Find(kvp => kvp.Key.Name.Equals(qAllowUntrustedCertificates.Name))?.Value.Value); QualifiedName qIgnoreCertificateChainErrors = EnumMqttClientConfigurationParameters.TlsIgnoreCertificateChainErrors.ToString(); m_ignoreCertificateChainErrors = Convert.ToBoolean(kvpMqttOptions.Find(kvp => kvp.Key.Name.Equals(qIgnoreCertificateChainErrors.Name))?.Value.Value); QualifiedName qIgnoreRevocationListErrors = EnumMqttClientConfigurationParameters.TlsIgnoreRevocationListErrors.ToString(); m_ignoreRevocationListErrors = Convert.ToBoolean(kvpMqttOptions.Find(kvp => kvp.Key.Name.Equals(qIgnoreRevocationListErrors.Name))?.Value.Value); QualifiedName qTrustedIssuerCertificatesStoreType = EnumMqttClientConfigurationParameters.TrustedIssuerCertificatesStoreType.ToString(); string issuerCertificatesStoreType = kvpMqttOptions.Find(kvp => kvp.Key.Name.Equals(qTrustedIssuerCertificatesStoreType.Name))?.Value.Value as string; QualifiedName qTrustedIssuerCertificatesStorePath = EnumMqttClientConfigurationParameters.TrustedIssuerCertificatesStorePath.ToString(); string issuerCertificatesStorePath = kvpMqttOptions.Find(kvp => kvp.Key.Name.Equals(qTrustedIssuerCertificatesStorePath.Name))?.Value.Value as string; m_trustedIssuerCertificates = new CertificateTrustList { StoreType = issuerCertificatesStoreType, StorePath = issuerCertificatesStorePath }; QualifiedName qTrustedPeerCertificatesStoreType = EnumMqttClientConfigurationParameters.TrustedPeerCertificatesStoreType.ToString(); string peerCertificatesStoreType = kvpMqttOptions.Find(kvp => kvp.Key.Name.Equals(qTrustedPeerCertificatesStoreType.Name))?.Value.Value as string; QualifiedName qTrustedPeerCertificatesStorePath = EnumMqttClientConfigurationParameters.TrustedPeerCertificatesStorePath.ToString(); string peerCertificatesStorePath = kvpMqttOptions.Find(kvp => kvp.Key.Name.Equals(qTrustedPeerCertificatesStorePath.Name))?.Value.Value as string; m_trustedPeerCertificates = new CertificateTrustList { StoreType = peerCertificatesStoreType, StorePath = peerCertificatesStorePath }; QualifiedName qRejectedCertificateStoreStoreType = EnumMqttClientConfigurationParameters.RejectedCertificateStoreStoreType.ToString(); string rejectedCertificateStoreStoreType = kvpMqttOptions.Find(kvp => kvp.Key.Name.Equals(qRejectedCertificateStoreStoreType.Name))?.Value.Value as string; QualifiedName qRejectedCertificateStoreStorePath = EnumMqttClientConfigurationParameters.RejectedCertificateStoreStorePath.ToString(); string rejectedCertificateStoreStorePath = kvpMqttOptions.Find(kvp => kvp.Key.Name.Equals(qRejectedCertificateStoreStorePath.Name))?.Value.Value as string; m_rejectedCertificateStore = new CertificateTrustList { StoreType = rejectedCertificateStoreStoreType, StorePath = rejectedCertificateStoreStorePath }; m_keyValuePairs = kvpMqttOptions; }
/// <summary> /// Constructor /// </summary> /// <param name="certificates">The certificates used for encrypted communication including the CA certificate</param> /// <param name="sslProtocolVersion">The preferred version of SSL protocol</param> /// <param name="allowUntrustedCertificates">Specifies if untrusted certificates should be accepted in the process of certificate validation</param> /// <param name="ignoreCertificateChainErrors">Specifies if Certificate Chain errors should be validated in the process of certificate validation</param> /// <param name="ignoreRevocationListErrors">Specifies if Certificate Revocation List errors should be validated in the process of certificate validation</param> /// <param name="trustedIssuerCertificates">The trusted issuer certifficates store identifier</param> /// <param name="trustedPeerCertificates">The trusted peer certifficates store identifier</param> /// <param name="rejectedCertificateStore">The rejected certifficates store identifier</param> public MqttTlsOptions(MqttTlsCertificates certificates = null, SslProtocols sslProtocolVersion = SslProtocols.Tls12, bool allowUntrustedCertificates = false, bool ignoreCertificateChainErrors = false, bool ignoreRevocationListErrors = false, CertificateStoreIdentifier trustedIssuerCertificates = null, CertificateStoreIdentifier trustedPeerCertificates = null, CertificateStoreIdentifier rejectedCertificateStore = null ) { m_certificates = certificates; m_SslProtocolVersion = sslProtocolVersion; m_allowUntrustedCertificates = allowUntrustedCertificates; m_ignoreCertificateChainErrors = ignoreCertificateChainErrors; m_ignoreRevocationListErrors = ignoreRevocationListErrors; m_trustedIssuerCertificates = trustedIssuerCertificates; m_trustedPeerCertificates = trustedPeerCertificates; m_rejectedCertificateStore = rejectedCertificateStore; m_keyValuePairs = new KeyValuePairCollection(); if (m_certificates != null) { m_keyValuePairs.AddRange(m_certificates.KeyValuePairs); } KeyValuePair kvpTlsProtocolVersion = new KeyValuePair(); kvpTlsProtocolVersion.Key = EnumMqttClientConfigurationParameters.TlsProtocolVersion.ToString(); kvpTlsProtocolVersion.Value = (int)m_SslProtocolVersion; m_keyValuePairs.Add(kvpTlsProtocolVersion); KeyValuePair kvpAllowUntrustedCertificates = new KeyValuePair(); kvpAllowUntrustedCertificates.Key = EnumMqttClientConfigurationParameters.TlsAllowUntrustedCertificates.ToString(); kvpAllowUntrustedCertificates.Value = m_allowUntrustedCertificates; m_keyValuePairs.Add(kvpAllowUntrustedCertificates); KeyValuePair kvpIgnoreCertificateChainErrors = new KeyValuePair(); kvpIgnoreCertificateChainErrors.Key = EnumMqttClientConfigurationParameters.TlsIgnoreCertificateChainErrors.ToString(); kvpIgnoreCertificateChainErrors.Value = m_ignoreCertificateChainErrors; m_keyValuePairs.Add(kvpIgnoreCertificateChainErrors); KeyValuePair kvpIgnoreRevocationListErrors = new KeyValuePair(); kvpIgnoreRevocationListErrors.Key = EnumMqttClientConfigurationParameters.TlsIgnoreRevocationListErrors.ToString(); kvpIgnoreRevocationListErrors.Value = m_ignoreRevocationListErrors; m_keyValuePairs.Add(kvpIgnoreRevocationListErrors); KeyValuePair kvpTrustedIssuerCertificatesStoreType = new KeyValuePair(); kvpTrustedIssuerCertificatesStoreType.Key = EnumMqttClientConfigurationParameters.TrustedIssuerCertificatesStoreType.ToString(); kvpTrustedIssuerCertificatesStoreType.Value = m_trustedIssuerCertificates?.StoreType; m_keyValuePairs.Add(kvpTrustedIssuerCertificatesStoreType); KeyValuePair kvpTrustedIssuerCertificatesStorePath = new KeyValuePair(); kvpTrustedIssuerCertificatesStorePath.Key = EnumMqttClientConfigurationParameters.TrustedIssuerCertificatesStorePath.ToString(); kvpTrustedIssuerCertificatesStorePath.Value = m_trustedIssuerCertificates?.StorePath; m_keyValuePairs.Add(kvpTrustedIssuerCertificatesStorePath); KeyValuePair kvpTrustedPeerCertificatesStoreType = new KeyValuePair(); kvpTrustedPeerCertificatesStoreType.Key = EnumMqttClientConfigurationParameters.TrustedPeerCertificatesStoreType.ToString(); kvpTrustedPeerCertificatesStoreType.Value = m_trustedPeerCertificates?.StoreType; m_keyValuePairs.Add(kvpTrustedPeerCertificatesStoreType); KeyValuePair kvpTrustedPeerCertificatesStorePath = new KeyValuePair(); kvpTrustedPeerCertificatesStorePath.Key = EnumMqttClientConfigurationParameters.TrustedPeerCertificatesStorePath.ToString(); kvpTrustedPeerCertificatesStorePath.Value = m_trustedPeerCertificates?.StorePath; m_keyValuePairs.Add(kvpTrustedPeerCertificatesStorePath); KeyValuePair kvpRejectedCertificateStoreStoreType = new KeyValuePair(); kvpRejectedCertificateStoreStoreType.Key = EnumMqttClientConfigurationParameters.RejectedCertificateStoreStoreType.ToString(); kvpRejectedCertificateStoreStoreType.Value = m_rejectedCertificateStore?.StoreType; m_keyValuePairs.Add(kvpRejectedCertificateStoreStoreType); KeyValuePair kvpRejectedCertificateStoreStorePath = new KeyValuePair(); kvpRejectedCertificateStoreStorePath.Key = EnumMqttClientConfigurationParameters.RejectedCertificateStoreStorePath.ToString(); kvpRejectedCertificateStoreStorePath.Value = m_rejectedCertificateStore?.StorePath; m_keyValuePairs.Add(kvpRejectedCertificateStoreStorePath); }