The underlying connection was closed: Could not establish trust relationship with remote server.

Posted on 2014-04-30
Last Modified: 2014-05-02
I have a website that uses SSL certificate. The website sends a request to an external website and receives a response that it has to process. All this was working fine until we renewed the SSL certificate on the server. Now after we send the request to the external website, it does not send a response but throws the error

The underlying connection was closed: Could not establish trust relationship with remote System.Net.HttpWebRequest.CheckFinalStatus() at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult) at System.Net.HttpWebRequest.GetRequestStream()

I made changes in the code by implementing System.Net.ICertificatePolicy but it still does not work. I have attached my code. Please advise.
Question by:Angel02
  • 3
  • 2
  • 2
LVL 29

Expert Comment

ID: 40032571
Can you compare the cert chain of the new cert and the old one.

It is possible that the chain of the certificate might have been changed, also have any changes been made to the name / friendly name of the certificate ?

Compare the expired cert to the new one for :
1. certificate chain
2. Subject
3. Friendly Name

Accepted Solution

xaichen earned 350 total points
ID: 40032768
Hi Angel,

It is probably not your code that is at fault if the only thing that changed was the SSL cert being renewed.

I'd check that the new certificate has been selected in the website's binding settings on the web server.

Best regards.

Author Comment

ID: 40032889
Where will I find these details (certificate name, subject, friendly name)? I saw the ones in IIS for the current certificate and they look fine. I don'f have the details of the older/expired certificate.
Does it matter if they are different?

How can I check the website's binding settings on the web server?

I checked the IIS and clicked on View Certificate. I certificate listed was the right one as it had the correct expiry date. But it said
"The integrity of this certificate cannot be guaranteed. The certificate may be corrupted or may have been altered"

Can this be a reason? The website however loads fine and everything is normal except accepting responses from external website.

Will it help if I remove the current certificate and add the same one back? Or will it create more problems?
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

LVL 29

Assisted Solution

becraig earned 150 total points
ID: 40032909
Ok so based on the information you just posted, can you do these two things:

1. Double click the certificate itself in the mmc and click on details you can find the values I specified there.

2. I would suggest you reinstall the certificate, but you need to verify the chain of the certificate as I said earlier is valid so when you click on the details tab do the following steps.

However did you request the certificate from this computer  ?

If so I would probably suggest to install each certificate in the chain in the appropriate store, then simply repair the store.

Expert Comment

ID: 40032924
Hi Angel,

Do you know what version of IIS or Windows Server the website is running on? If is is Server 2003 / IIS6 it is possible the new certificate is using a hashing method that the older IIS6 version can't understand. See more info in MS article KB938397.

In IIS7 you can check the binding if you select the website in the left hand tree and then select Bindings... in the right hand actions pane. You can then edit the binding to see what certificate is being used for that site.

In IIS6 you can right click the site to get to Properties > Directory Security tab > View  Certificate

Best regards.

Author Comment

ID: 40034792
Thank you Xaichen. The issue was actually hashing algorithm. We reinstalled the SSL certificate with SHA-1 and it started working. We are able to receive response from the external website now.

Other than the response from the external website everything was working fine with SHA-2 before. Does this mean the external website was not compatible with SHA-2 afterall?

I would like to know this to know if I need to do something on my end so we can use SHA-2. Please advise. Thanks!

Expert Comment

ID: 40035218
Hi Angel,

I'm glad to hear it is working. In respect to the SHA-2 working before. I've read up a bit since my last post and it appears there are 4 or more flavours of SHA-2. It is possible you were using one type that was compatible and then the renewal process selected a different type that could not be supported. I'm not entirely sure where you see what type of SHA-2 is in use, or how to go about changing it, but the different versions are called SHA-224, SHA-256, SHA-384, SHA-512.

In terms of continuing to use SHA-1, it is possibly easier to exploit it, though these days everything seem to have weaknesses. But if you has working SHA-2 solution before it would be worth some effort to try to return to that. But you may find SHA-1is the only workable solution to maintain backwards compatibility in some scenarios. For some real world comparison, I checked out the SSL certificate that Gmail's web interface uses when I make a connection and it is SHA-1.

I hope that helps.

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Imagine a situation that you have installed SSL ( Certificate on your Cisco ASA (Cisco Adaptive Security Appliance) firewall. Installation of SSL certificate on ASA is an another topic for which you …
Microservice architecture adoption brings many advantages, but can add intricacy. Selecting the right orchestration tool is most important for business specific needs.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
In a recent question ( here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now