sudhiremmadi commented on code in PR #2610:
URL: https://github.com/apache/arrow-adbc/pull/2610#discussion_r1991589525


##########
csharp/src/Drivers/Apache/Hive2/HiveServer2TlsImpl.cs:
##########
@@ -0,0 +1,106 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License.  You may obtain a copy of the License at
+*
+*    http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.IO;
+using System.Collections.Generic;
+using System.Net.Security;
+using System.Security.Cryptography.X509Certificates;
+using System.Net.Http;
+
+namespace Apache.Arrow.Adbc.Drivers.Apache.Hive2
+{
+    class TlsProperties
+    {
+        public bool IsSslEnabled { get; set; }
+        public bool EnableServerCertificateValidation { get; set; }
+        public bool AllowHostnameMismatch { get; set; }
+        public bool AllowSelfSigned { get; set; }
+        public string? TrustedCertificatePath { get; set; }
+    }
+    static class HiveServer2TlsImpl
+    {
+        static internal TlsProperties 
GetTlsOptions(IReadOnlyDictionary<string, string> Properties)
+        {
+            TlsProperties tlsProperties = new TlsProperties();
+            Properties.TryGetValue(TlsOptions.IsSslEnabled, out string? 
isSslEnabled);
+            Properties.TryGetValue(AdbcOptions.Uri, out string? uri);
+            if (!string.IsNullOrWhiteSpace(uri))
+            {
+                var uriValue = new Uri(uri);
+                tlsProperties.IsSslEnabled = uriValue.Scheme == 
Uri.UriSchemeHttps || (bool.TryParse(isSslEnabled, out bool isSslEnabledBool) 
&& isSslEnabledBool);
+            }
+            else
+            {
+                tlsProperties.IsSslEnabled = bool.TryParse(isSslEnabled, out 
bool isSslEnabledBool) && isSslEnabledBool;
+            }
+            if (!tlsProperties.IsSslEnabled)
+            {
+                return tlsProperties;
+            }
+            tlsProperties.IsSslEnabled = true;
+            
Properties.TryGetValue(TlsOptions.EnableServerCertificateValidation, out 
string? enableServerCertificateValidation);
+            if (bool.TryParse(enableServerCertificateValidation, out bool 
enableServerCertificateValidationBool) && 
!enableServerCertificateValidationBool)
+            {
+                tlsProperties.EnableServerCertificateValidation = false;
+                return tlsProperties;
+            }
+            tlsProperties.EnableServerCertificateValidation = true;
+            Properties.TryGetValue(TlsOptions.AllowHostnameMismatch, out 
string? allowHostnameMismatch);
+            tlsProperties.AllowHostnameMismatch = 
bool.TryParse(allowHostnameMismatch, out bool allowHostnameMismatchBool) && 
allowHostnameMismatchBool;
+            Properties.TryGetValue(TlsOptions.AllowSelfSigned, out string? 
allowSelfSigned);
+            tlsProperties.AllowSelfSigned = bool.TryParse(allowSelfSigned, out 
bool allowSelfSignedBool) && allowSelfSignedBool;
+            if (tlsProperties.AllowSelfSigned)
+            {
+                Properties.TryGetValue(TlsOptions.TrustedCertificatePath, out 
string? trustedCertificatePath);
+                if (trustedCertificatePath == null) return tlsProperties;
+                tlsProperties.TrustedCertificatePath = trustedCertificatePath 
!= "" && File.Exists(trustedCertificatePath) ? trustedCertificatePath : throw 
new FileNotFoundException("Trusted certificate path is invalid or file does not 
exist.");

Review Comment:
   The host of the service must have the certificate. We can add an input param 
that accepts certificate content as well but that can be considered an 
additional feature



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to