TLS 1.2 issue on Windows Server 2012 R2 and -NET Framework 4.8

Marco Tomatis 71 Reputation points
2022-06-22T09:31:11.823+00:00

Good morning everyone,

we have a problem concerning the consumption of a REST service via POST call, which works with Postman from the machine itself, from a Windows Server 2012 R2 and .NET Framework 4.8 server with TLS 1.2.

The error returned is this:

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)

Instead, the code is this:

ServicePointManager.SecurityProtocol | = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

      using (HttpClient client = new HttpClient ())  

      {  

        client.BaseAddress = new Uri (this.Settings.Request.BaseAddress);  

        if (this.Settings.Authentication.Required)  

        {  

          byte [] bytes = Encoding.ASCII.GetBytes (this.Settings.Authentication.UserName + ":" + this.Settings.Authentication.Password);  

          client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue ("Basic", Convert.ToBase64String (bytes));  

        }  

        client.DefaultRequestHeaders.Accept.Add (new MediaTypeWithQualityHeaderValue ("application / json"));  

        string jsonContent = File.ReadAllText (file.FullName, encoding);  

        this.Logs.Add ("Sending the file:" + jsonContent, false);  

        StringContent content = new StringContent (jsonContent, encoding, "application / json");  

        HttpResponseMessage response = await client.PostAsync (this.Settings.Request.Endpoint, content);  

        if (response.IsSuccessStatusCode)  

        {  

          ResponseResult responseResult = JsonSerializer.Deserialize <ResponseResult> (response.Content.ReadAsStringAsync (). Result);  

          switch (responseResult.ResponseType)  

          {  

            case ResponseResult.eResponseType.OK:  

              this.Logs.Add ("File" + file.Name + "sent successfully:" + responseResult.detail, false);  

              break;  

            case ResponseResult.eResponseType.KO:  

              internalResult.SetError (responseResult.detail, (eTypeResult) 8);  

              this.Logs.Add ("File" + file.Name + "not sent:" + responseResult.detail, true);  

              break;  

            case ResponseResult.eResponseType.WARNING:  

              this.Logs.Add ("File" + file.Name + "sent (WARNING)  

: "+ responseResult.detail, false);

              break;  

          }  

        }  

        else  

        {  

          string responseContent = await response.Content.ReadAsStringAsync ();  

          if (string.IsNullOrWhiteSpace (responseContent))  

          {  

            responseContent = response.ToString ();  

          }  

          internalResult.SetError (responseContent, (eTypeResult) 8);  

        }  

      }  

The exact same software works on Windows Server 2016.

We have tried to change the various registry keys as indicated in the different documents found online, but nothing changes and the error remains.

We would like to understand if there is some way to manage this connection on Server 2012 R2 or not.

Thank you,

Marco Tomatis

Windows for business Windows Server User experience Other
{count} votes

2 answers

Sort by: Most helpful
  1. Cédric Boivin 1 Reputation point
    2022-06-22T14:52:49.157+00:00

    I got the same issue has you.

    Test multiple registry key without any positive results.

    I was in .net framework 4.7.2 before update code to 4.8 and get the same issue. It's seen to be a default cipher on the server with the client that is not set correctly.

    0 comments No comments

  2. Limitless Technology 39,916 Reputation points
    2022-06-23T07:37:18.277+00:00

    Hello

    Thank you for your question and reaching out. I can understand you are having issues related to REST service via POST call.

    It can be connection issue or TLS 1.1 or TLS 1.2 may be blocked on your 2012 R2 Server.

    1. Please download IISCrypo tool and run on both 2012 R2 and 2016 Server , and you can enable Ciphers or Protocol which are missing in 2012 R2.
    2. Disable any Antivirus program or Windows firewall you may have for temporary purpose.

    -----------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept as answer--

    0 comments No comments

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.