Reputation: 71
.NET version is 4.6.2 and The version of VaultSharp package being used is VaultSharp.1.4.0.1
Code:
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 |
SecurityProtocolType.Tls12 |
SecurityProtocolType.Tls11 |
SecurityProtocolType.Tls | (SecurityProtocolType)3072 |
(SecurityProtocolType)768 |
(SecurityProtocolType)192; ;
string certificatePath = "cert.pfx";
string secretServerAddress = "https://vaultHotName:443";
var certificate = new X509Certificate2(certificatePath, "Password", X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet);
HttpClient httpClient = null;
IVaultClient vaultClient = null;
bool enableProxy = true;
if (enableProxy)
{
HttpClientHandler handler = new HttpClientHandler
{
Proxy = new WebProxy("proxyHostName", "443"),
UseProxy = true
};
httpClient = new HttpClient(handler);
}
IAuthMethodInfo authMethod = new CertAuthMethodInfo(clientCertificate: certificate, roleName: vaultRole);
var vaultClientSettings = new VaultClientSettings(secretServerAddress, authMethod);
if (httpClient == null){
vaultClient = new VaultClient(vaultClientSettings);
}
else
{
vaultClient = new VaultClient(vaultClientSettings, httpClient);
}
var vaultClientRequired = vaultClient;
secretFullPath = "RandomPath"
Task<Secret<Dictionary<string, object>>> fetchSecretTask = vaultClientRequired.V1.Secrets.KeyValue.V1
.ReadSecretAsync(path: secretFullPath);
Error: System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
Stack Trace:
-> (Inner Exception #0) System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context)
at System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar)
--- End of inner exception stack trace ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Net.Http.HttpClient.<FinishSendAsyncBuffered>d__58.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at VaultSharp.Core.Polymath.<MakeRequestAsync>d__16`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at VaultSharp.Core.Polymath.<MakeVaultApiRequest>d__14`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at VaultSharp.V1.AuthMethods.Cert.CertAuthMethodLoginProvider.<GetVaultTokenAsync>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at VaultSharp.Core.Polymath.<MakeVaultApiRequest>d__14`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at VaultSharp.V1.SecretsEngines.KeyValue.V1.KeyValueSecretsEngineV1Provider.<ReadSecretAsync>d__3`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at VaultSharp.V1.SecretsEngines.KeyValue.V1.KeyValueSecretsEngineV1Provider.<ReadSecretAsync>d__2.MoveNext()<---
Debugging Details
I was trying to hit Vault to read secret from C# code, but it is showing me this error. I already tried whatever I could find on internet, but still I am at same the state.
As a result it should be successfully reading secret.
This code is working fine on local, but on QA/Prod it is not.
This code is working via curl command successfully. With C# code, i am seeing error.
Upvotes: 0
Views: 1294