Cannot get CloudFlare origin SSL cert to work

What is the name of the domain?

What is the issue you’re encountering

Can’t get origin server cert to work with Win2016+IIS 10

What steps have you taken to resolve the issue?

Obfuscating hostname, IPs, etc for security

Using Windows Server 2016+IIS. Created a CF origin server SSL cert for example.contoso.org. Imported that cert into Personal and verified it shows/looks right. Imported CF Origin Root (both ECC and ESA to be safe) and verified they both show in Intermediate Certification Authorities. Restarted entire server, bound the new origin cert to IIS (tried with no hostname and hostname and also with/without SNI). Restarted again to be safe. Verified I can load INTERNALIP on https from the web server, of course with the expected invalid cert warnings. Same with EXTERNALPUBLICIP on https from random public machine, again with expected cert warnings. However, when I set CF SSL to Full or Strict, get error 520. With CF SSL to Flexible, loads fine.

I’ve got a Config Rule for this specific site so I’ve turn off security level, browser check, etc.

What am I missing? This is driving me nuts!

What is the current SSL/TLS setting?

Full (strict)

Hello, error 520 is unlikely associate with SSL issue. Does your Config Rule for this site also set the SSL setting to full ?

Hello, for reference, for testing, I have 80/http and 443/https allowed to the origin server currently. When I have the config rule set to flexible, I can hit the CF FQDN (ie, proxy through CF) – SSL from client to CF, no SSL CF to origin. If I change the config rule to full or strict, I get the error mentioned after maybe 10 seconds. However, if I browse to the direct public IP on https (can’t give a redacted URL example due to community limits), I get served the page (with the expected SSL cert warnings since I’m using the CF origin on the webserver and not a public cert). In other words, the web server will serve HTTPS directly via its public IP, but for reasons I can’t see, something does NOT work with HTTPS when CF is the “client”.

A bit more info – with the CR set to flexible, the site loads via FQDN via CF proxy and I get the expected IIS log file entries for hits in (ie, on server port 80). With CR on full, FQDN gives the CF 520 error and I don’t get any IIS log file entry. If I hit the origin web server’s public IP on https, I get the expected IIS log file entries (on port 443).

This is the origin cert being used for SSL, but I assume this is expected due to there not being a publicly trusted cert chain?

I remember a year ago, I’ve had some issues at first sight with 2012 R2 where ciphers weren’t compatible, therefore I have had to go with RSA origin cert + Authenticated Origin Pulls RSA/Root CA RSA as well.
Never the less, have had to bind both 80 and 443 the public IP.
Check firewall rules.
Have had the redirection from HTTP to HTTPS as well on IIS.

At the end, after trying everything, I end-up paying for an SSL certificate.
Putting that one, and it worked like a charm with Full (Strict) SSL.

However, I cannot remember at the moment, but later again I replaced the paid SSL from Namecheap, tried with new generated Origin CA from the CF dashboard, and it worked - was some :poop: I missed in between.

Can update in few days after I check again for feedback, if interested and hopefully would help you as well.

1 Like

I remember I’ve posted about this since before, hope it helps a bit:

1 Like

Thanks fritex, I am running Windows Server 2016 (IIS 10). I did the CSR from IIS using 2048-bit key etc. And again, if I go directly to the server’s public IP on 443/https, it servers up the page securely. Of course, since the origin web server is not using a publicly trusted cert chain, I get that warning, but the page loads and it’s encrypted. FWIW, I also have had no problems in this same scenario using a regular publicly trusted cert on the origin server, even from one of the cheap providers. But a huge advantage to CF is not having to do new public certs every year, and the hassle and cost that comes along with it. But I don’t really want to run Flexible mode where the traffic between CF and my origin web server is clear text http.

Any help on this? I still can’t figure out what’s going on here!

@someguyUSA Hope below helps in your case. Worked for me 1-2 hours ago and still working.

I am sharing what I’ve checked, tested and done in past hour-two.

Since my Namecheap Sectigo is expiring on Sept 22 this year (1 month), I’ve gone again through this and done it as follows to achieve it working (at least in my case).

You can download my converted and used Cloudflare Origin CA Root (RSA) and Authenticated Origin Pull (RSA) as .p7b from link below (step 22-23):

Sharing step-by-step and screenshoots:

  1. Port 80 and 443 are open for inbound and outbound traffic on Fortigate router in Firewall Policy along with other ports needed (custom RDP, etc.)
  2. Running Windows Server 2012 R2 x64
  3. Ports 80 and 443 allowed inbound and outbound on Windows Firewall
  4. Running IIS 8.5
  5. Under IIS, selected My Server → Server Certificates
  6. Right sidebar → Create Certificate Request
  7. Filled-in Common name (sub.domain.hr), Organization, unit, city, state country …
  8. Selected “Microsoft RSA” and “2048” bit
  9. Saved the CSR output to a csr.txt file
  10. Copied the output
  11. Went to CF Dashboard → SSL/TLS → Origin Server → Create Certificate
  12. Selected Use my private key and CSR, Hostnames → sub.domain.hr (only that one particular, nothing else), 15 years and hit “Create” button
  13. Saved the output as PKCS7
  14. Renamed it to the subdomainhr.cer
  15. Went to the IIS → selected my Server → Server Certificates → Complete Certificate Request from right sidebar
  16. Selected the subdomainhr.cer file, added friendly name and selected “Personal”
  17. Opened certlm (Certificates - Local Computer)
  18. Under “Personal” I can see my Cloudflare Origin CA certificate
  19. Under “Trusted Root Certification Authorities” I go to right click All Tasks → Import
  20. Selected “Local Machine”
  21. Downloaded:
    a) Cloudflare Origin RSA PEM (Origin CA certificates | Cloudflare SSL/TLS docs)
    b) Cloudflare Authenticated Origin Pull PEM (https://developers.cloudflare.com/ssl/static/authenticated_origin_pull_ca.pem)
  22. Converted both PEM certs via SSL Converter (SSL Converter - Convert SSL Certificates to different formats) from “Standard PEM” to “P7B/PKCS#7” (made sure to upload them one by one only under the field “Certificate File to Convert”)
  23. Downloaded the convereted ones as .p7b
  24. Went back to the “Certificates” → Trusted Root Certification Authorities
  25. Right Click → All Tasks → Import and imported each one by one here with double-checking to place them into the “Trusted Root Certification Authorities” certificate store
  26. Went to IIS, selected my Website sub.domain.hr
  27. Went to SSL Settings → Require SSL (not checked), Client Certificates is “Ignore”
  28. Right sidebar → Bindings
  29. Having http sub.domain.hr port 80 and public IP
  30. Added https sub.domain.hr port 443 and public IP
  31. Selected https and clicked “Edit”
  32. Type https, IP is IPv4, port is 443, host name is sub.domain.hr, “Require Server Name Indication” is checked and SSL certificate selected the one which I’ve added (only)
  33. Saved
  34. I got warning message “No default SSL site has been created. To support browser withoutn SNI capabilities …”
  35. Made sure Full (Strict) SSL is selected under the SSL/TLS tab of Cloudflare dashboard for the whole zone (no additional Rules configured to separate the sub-domain, except no cache)
  36. Made Sure Authenticate Origin Pulls is enabled
  37. Stopped and started (restart) Web server
  38. Checking HTTP and HTTPS via Chrome on Windows server gives HTTP 404 not found error, however loads fine without any issue and on the “lock icon” I can see Cloudflare Origin Certificate, Origin CA, expiring 2039. (15 years)
  39. Checking via hostname from my home network and mobile phone sub.domain.hr/some-path/phpinfo.php, it’s loading fine and working over HTTPS; no warning, no issue
  40. When I go check the SSL lock icon, since it’s proxied :orange:, it’s showing Let’s Encrypt Cloudflare certificate
  41. Nothing changed in the Apache config file for SSL.

In pictures:

07sni_warning

What I can offer is, voluntarily I could help you with this on demand, however remotely only or via AnyDesk or something if it’s easier for you also to see.

Thank you so much for the detailed instructions. That is pretty much exactly what I was already trying, except on Win2016/IIS10, I had been just directly importing the .PEM files for the chain/trust. Just to be sure, I deleted those certs and went back through the entire process again exactly following your instructions. The only extra/deviations are in the IIS bindings for 443/SSL. I had to specify the hostname (required to enable SNI) and my web server is behind a NAT firewall, so in binding address I put in the private (not internet routable) IP instead of the public IP (as specified in your instructions).

With SNI+hostname, on the local webserver at https://privateIP, I get this site can’t be reached (connection reset). If I disable SNI and remove the hostname, I get the (expected) warning about the cert mismatch (ie, cert is for xxxx.domain.com while I’m currently browsing privateIP). But if I then configure CF proxy with strict or full, I get the dreaded 520 error. When I check the web server’s IIS logs, there are no hits from that attempt.

1 Like

I have got a setup something also similar, had to do NATting (for some things as well from local network to get to the outside part earlier with RaspberryPi), however:

  • Mikrotik router (with a public static IP /29 for Internet + have another /28 IP public static space for the services → single physical port connected)
  • FortiGate router as firewall (has got the 2nd public static IP from Mikrotik /29, inner local network separated by the VLANs, connection to the main server with one of the 2nd /28 IP space, etc. → separate physical ports connected)
  • Dell Server (multiple ports used for local network and VLANs + public IP via port connection to the switch in between before FG router) - Windows Server with Hyper-V virtual machines (one of them is that old WS 2012 R2 with that and the needed VMs are assigned with available routing IPs from the 2nd /28 IP space)

In short: Mikrotik → Fortigate → Server → Virtual machine

However, yep, since I got the routable public IP space available so just assign them and make sure over the Fortigate port it’s added/forwarded further :thinking:

Hm, that’s quite strange. Sounds like something is blocking somewhere?
Could you check the firewall/router logs, if any incomming? :thinking:

One thing which I haven’t noted is, what I also have added are the Cloudflare IPs under the IIS server (main settings) and also under the particular site sub.domain.hr as well (same on both), as follows:

A list of IPv4 and IPv6 is available at the link from below:

1 Like

Eventually I will want to block all non-CF IPs on the PAT/NAT to the web server, but for troubleshooting (and to simplify and reduce potential problems) I am allowing all IPs incoming.

On the same web server, I stopped the original site, created a second IIS site with just the default simple IIS HTML, bound 443 using the same IP and same cert and it works fine on strict, showing the expected CF cert info on a client and the expected IIS logs on 443. What the heck?

This is getting weirder by the minute. Back to the original site. If I reset the IIS site, it will load the site on strict for the first external client. Any further separate external client gets the CF 520 error and then even the first client starts getting 520s. If I reset IIS again, client 1 and 2 can both refresh browsers and continue on until a client 3 tried to come in.

This behavior does NOT happen if I have CF set on flexible!

Quite interesting feedback :thinking:

Is the first one the “default” maybe and/or something with it could be wrong?

That’s really weird behaviour of a web server.

Ok, more testing done and amending some of my previous information, and I THINK, maybe a solution.

First, I did check the firewall logs and verified it is not in play for this problem. It is always passing SSL traffic incoming from CF to the web server in question.

The weirdness with IIS resets and multiple clients, plus some lack of hits to IIS logs got me thinking about cache issues. So I added a cache rule in CF to bypass the site/URL in question from all caching. So far, and with SSL on strict, I have not been able to break things despite actively trying to.

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.