Exemplo n.º 1
0
 /// <summary>
 /// Get or set a configuration value directly.
 ///
 /// See <see href="https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md">CONFIGURATION.md</see> for the full list of supported properties.
 /// </summary>
 /// <param name="name">The configuration property name.</param>
 /// <returns>The configuration property value.</returns>
 /// <exception cref="System.ArgumentException"><paramref name="value" /> is invalid.</exception>
 /// <exception cref="System.InvalidOperationException">Configuration property <paramref name="name" /> does not exist.</exception>
 public string this[string name]
 {
     set
     {
         handle.Set(name, value);
     }
     get
     {
         return(handle.Get(name));
     }
 }
        private static void ProcessInMemoryCertificatesIfConfigured(
            SafeConfigHandle configHandle,
            IntPtr configPtr,
            ManualConfigSettings ManualConfigSettings)
        {
            if (ManualConfigSettings.X509Certificate == null)
            {
                return;
            }

            X509Certificate2 caCertificate = ManualConfigSettings.CAX509Certificate;

            if (caCertificate == null)
            {
                caCertificate = AttemptToResolveCACertificateFromUserCertificate(ManualConfigSettings.X509Certificate);
            }

            if (caCertificate == null)
            {
                throw new InvalidOperationException("An accompanying in-memory CA certificate must be provided");
            }

            PrivateKeyAlgorithmAndBytes privateKeyAlgorithmAndBytes = ManualConfigSettings.PrivateKeyAlgorithmAndBytes;

            if (privateKeyAlgorithmAndBytes == null)
            {
                privateKeyAlgorithmAndBytes = AttemptToResolvePrivateKeyFromUserCertificate(ManualConfigSettings.X509Certificate);
            }

            if (privateKeyAlgorithmAndBytes == null)
            {
                throw new InvalidOperationException("A private key must accompany the in-memory certificate");
            }

            LibRdKafka.conf_set_bytes(
                configPtr,
                ManualConfigSettings.SettingNameSslCertificateLocationInMemory,
                ManualConfigSettings.X509Certificate.RawData);

            LibRdKafka.conf_set_bytes(
                configPtr,
                ManualConfigSettings.SettingNameSslCALocationInMemory,
                caCertificate.RawData);

            LibRdKafka.conf_set_bytes(
                configPtr,
                ManualConfigSettings.SettingNameSslKeyInMemory,
                privateKeyAlgorithmAndBytes.RawData);

            configHandle.Set(
                ManualConfigSettings.SettingNameSslKeyInMemoryType,
                privateKeyAlgorithmAndBytes.PrivateKeyAlgorithmInUse);
        }