0

I just renewed our SSL Certs for our websites. I've been doing this for a years w/o issues.

After this last SSL update I'm getting errors when my websites are talking to each other, however no errors when I browse each site individually through chrome or other browsers.

If I browse Site A or Site B through a browser, there are no errors. However, if I go to a page where Site A needs to access Site B through an HTTPRequest, I get the following error:

  "message": "An error has occurred.",
      "exceptionMessage": "The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.",
      "exceptionType": "System.Net.WebException",
      "stackTrace": "   at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context)\r\n   at System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar)",
      "innerException": {
        "message": "An error has occurred.",
        "exceptionMessage": "The remote certificate is invalid according to the validation procedure.",
        "exceptionType": "System.Security.Authentication.AuthenticationException",
        "stackTrace": "   at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)\r\n   at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)"
      }
  • Both sites reside on the same server
  • Both sites have the same root domain name.
    (ex. SiteA.foo.com, siteB.foo.com)
  • Server 2012.
  • I performed the SSL Request from the Production server and finished it on the production server.
  • I do not have this problem on my local dev or our other stacks (with the same certificate)
  • Removed the new cert from all stores (MMC), restarted. Installed the PFX onto both the user/computer accounts. Re-binded all sites in IIS. Every site in a browser "works" but when you try to get one backend to call another website I get the same error.

.NET framework - v4.0.30319, Pipeline - Integrated

Look at the 2017-2018 certificate there are no changes except for what you would expect. Subject, Domain, etc. are all the same.

Here's a section of code that's blowing up.

            using (var handler = new HttpClientHandler())
            {
                HttpResponseMessage message = null;
                handler.CookieContainer = _cookieContainer;
                handler.UseDefaultCredentials = false;
                handler.UseCookies = true;
                using (var client = new HttpClient(handler))
                {
                    var attempt = 0;
                    client.Timeout = _requestTimeout;
                    var uri = BuildActionUri(baseUri, action);
                    while (attempt++ < retryAttempts)
                    {
                        HttpContent httpContent;
                        switch (actionType)
                        {
                            case ActionType.Put:
                                httpContent = authenticationProvider.SignRequest(client, request, grantResponse);
                                message = client.PutAsync(uri, httpContent).Result;
                                break;
                            case ActionType.PostAsJson:
                                authenticationProvider.SignRequest(client, new EntityJsonRequest {Entity = data}, grantResponse);
                                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));//ACCEPT header
                                message = client.PostAsJsonAsync(uri, data).Result;
                                break;
                            case ActionType.Post:
                                httpContent = authenticationProvider.SignRequest(client, request, grantResponse);
                                message = client.PostAsync(uri, httpContent).Result;
                                break;
                            case ActionType.PutAsJson:
                                authenticationProvider.SignRequest(client, new EntityJsonRequest {Entity = data},
                                    grantResponse);
                                message = client.PutAsJsonAsync(uri, data).Result;
                                break;
                            case ActionType.Get:
                                authenticationProvider.SignRequest(client, null, grantResponse);
                                message = client.GetAsync(uri).Result;
                                break;
Ryan Ternier
  • 8,714
  • 4
  • 46
  • 69
  • Sounds like your certificate is not valid, there is a hack available here (https://stackoverflow.com/questions/12624841/web-client-exception-the-underlying-connection-was-closed-could-not-establish) but it opens you up to man in the middle attacks – Ryan Wilson Aug 14 '18 at 19:56
  • When I go to each individual site, it's valid. IE, Chrome, FireFox, everything accepts the certificate, and fully trusts it (Go Daddy Cert). However, When two of my sites try to talk to each other, then i get this error. – Ryan Ternier Aug 14 '18 at 20:00
  • I had something like this happening to me, in my case I was having a website call out to an API which were both on the same server, I went through all kinds of articles trying this and that, I ended up moving my API to it's own dedicated server and that cleared up my issues. – Ryan Wilson Aug 14 '18 at 20:02
  • The code hasn't changed in months, and we've switched certs multiple times. Not sure why this is happening now. The only thing I can think of is I'm forcing TLS for our services and the SSL Cert might not work with that? – Ryan Ternier Aug 14 '18 at 22:24
  • 1) Check the .NET Framework versions used on this machine, and which versions are used by the two sites. 2) Compare the two certificates (old and new) to see if there are obvious differences in properties. Edit your question to include such. – Lex Li Aug 15 '18 at 00:06

1 Answers1

0

After a lot of testing and research something I tried fixed everything. It seems that something in .NET was caching the SSL Cert.

Steps I did:

  • Run windows Update (had a few updates to run). This gave me a different error message than above, but it still contained the error regarding SSL trust issues.
  • Checked that SSL and TLS were enabled in the registry (they were). Restarted, same error,
  • cleared .net cache, re-deployed, but it still failed.
  • re-installed ASP.NET, deleted cert from MMC (Computer/User), ran a few PS scripts to kill IIS cache, added cert as a PFX rather than a .CER, and it worked.
Ryan Ternier
  • 8,714
  • 4
  • 46
  • 69