Veljko Radan

Language: SvenskaEN

← All articles

Field notes: Same error, two causes

"Could not establish trust relationship" on two machines. Once it was the certificate, the other time it was DNS.

Veljko Radan · · 2 min read

A script on an operator panel in the factory was supposed to fetch data from a production system. It ended with an error message most people who have worked with Windows have seen:

Could not establish trust relationship for the SSL/TLS secure channel.

First machine: the certificate

The error says the machine doesn't trust the server's certificate. The server had a certificate from the internal certificate authority, and on domain-joined computers the root certificate arrives automatically through Group Policy. The panel wasn't domain-joined. It had simply never been told the internal root existed.

The fix was simple: import the root certificate into LocalMachine\Root and the issuing CA into LocalMachine\CA. The script worked straight away.

Second machine: same symptom, different cause

On the next panel, "the same error" was reported. It wasn't. This time the output read:

  • Step 1: The remote name could not be resolved – the name couldn't be looked up. No token was fetched.
  • Step 2: (401) Unauthorized – a follow-on error. The call went out with an empty token.

Step 2 was the interesting part. The fact that the server answered at all meant TLS trust now worked – the certificate import had done its job. And in an earlier run in the same window, step 1 had hit the TLS error, so the name had resolved then.

A name that resolves sometimes and sometimes not points at the DNS servers. The panel had DNS set by hand, and it asked a mix of servers – one that knew the name and one that didn't. With DNS pointed at the right servers, the script worked.

Two machines, the same error message, two causes First machineSecond machineTLS errorCause: root certificate missingFix: import root + intermediate“Same error”Cause: DNS, mixed servers401 was only a knock-on error
The first error in the output is the one that counts. The 401 looked like permissions but came from the step before failing.
# How to check both causes (PowerShell, as administrator)
# 1. The certificates – machines outside the domain don't get them automatically
PS> Import-Certificate -FilePath .\root-ca.cer -CertStoreLocation Cert:\LocalMachine\Root
PS> Import-Certificate -FilePath .\issuing-ca.cer -CertStoreLocation Cert:\LocalMachine\CA
# 2. The name – ask each DNS server on its own
PS> Resolve-DnsName <servername> -Server <dns-1>
<servername>   A   3600   Answer   <address>
PS> Resolve-DnsName <servername> -Server <dns-2>
Resolve-DnsName : <servername> : DNS name does not exist
# no answer → the machine asks a mix of servers

The lesson

  • Read the first error, not the last. The 401 looked like a permissions problem but was a consequence of the step before failing.
  • "Same error" is a hypothesis. Ask for the actual output before applying the same fix again.
  • Machines outside the domain need a list. Certificates added by hand don't renew themselves. Write down which machines have them and when the CA expires – otherwise the same error returns in a few years, and nobody remembers why.