Connect azure key vault getting error is "System.Net.Http.HttpRequestException: 'The SSL connection could not be established, see inner exception.'SocketException: An established connection was aborted by the software in your host machine."

Uppu, Taraka Rajesh 0 Reputation points
2023-04-21T18:32:42.9233333+00:00

Below code using to connect to azure key vault in local machine.

public static async Task PrivacyAsync()
        {

            string Client_Id = "xxxxxxxx";
            string Client_Secret = "xxxxxx";
            var kvUri = "xxxx";

            var client = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(
                async (string auth, string res, string scope) =>
                {
                    var authcontext = new AuthenticationContext(auth);
                    var credential = new ClientCredential(Client_Id, Client_Secret);
                    AuthenticationResult result = await authcontext.AcquireTokenAsync(res, credential);

                    if (res == null)
                    {
                        throw new InvalidOperationException("token failed");

                       
                    }
                    return result.AccessToken;
                }
                ));

            var secret = await client.GetSecretAsync(kvUri, "xxxxxx");
            Console.WriteLine("secret success full read"+secret.Value);
            Console.ReadLine();
        
            //var client = new SecretClient(new Uri(kvUri), new DefaultAzureCredential());
            //await client.SetSecretAsync("test0311", "hello");
            
        }
below is the error screen.
Azure Key Vault
Azure Key Vault
An Azure service that is used to manage and protect cryptographic keys and other secrets used by cloud apps and services.
1,452 questions
{count} votes

1 answer

Sort by: Most helpful
  1. JamesTran-MSFT 36,911 Reputation points Microsoft Employee Moderator
    2023-04-26T21:31:09.81+00:00

    @Uppu, Taraka Rajesh

    Thank you for your post and I apologize for the delayed response!

    Error Message:

    "System.Net.Http.HttpRequestException: 'The SSL connection could not be established, see inner exception.'SocketException: An established connection was aborted by the software in your host machine."

    From your error message, it seems like the connection is being cancelled or aborted by the software within your host machine, to troubleshoot the issue:

    • Capture a network trace using Fiddler to ensure your machine is able to connect to the Key Vault.
    • Confirm you don't have any VPN's, SSL certificate issues, or other networking settings that could be affecting your connection to the Key Vault.
    • Ensure that your local machine's firewall isn't terminating the SSL connection.

    If you're still having issues, can you share the documentation that you're following to set this up?


    Additional Links:

    I hope this helps!


    If you have any other questions, please let me know. Thank you for your time and patience throughout this issue.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.