runtime: The remote certificate is invalid according to the validation procedure
Running a dotnet core 2.2 web api on Ubuntu 18.04 Docker image (mcr.microsoft.com/dotnet/core/aspnet:2.2-bionic). I am using MailKit (https://github.com/jstedfast/MailKit) to send an email and it works fine when I run locally on Windows 10 but fails on Linux:
System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure
Since it works on Windows OK, it seems that there is perhaps an OpenSSL issue, maybe due to 1.0 vs 1.1? MailKit calls into SslStream.AuthenticateAsClient, which is the start of the stack that fails. Since this is an email relay, I need some other way of debugging that rather than just that https works generally (which it does with curl).
I have tried the following to no avail:
- Downloaded and updated the root CA stack using update-ca-certificates (no difference)
- Used curl from the container itself to access the hello world lets encrypt web site to see if there is a problem with LE specifically (works fine)
- Set environment variables for SSL_CERT_DIR (/usr/lib/ssl/certs) and SSL_CERT_FILE (/usr/lib/ssl/cert.pem) after symlinking the downloaded CA file into /usr/lib/ssl (no difference).
Can someone please give me some more debugging tips? Thanks.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 8
- Comments: 26 (15 by maintainers)
Landed here after finding that this dotnet/aspnetcore issue and its resolutions (not its Stack Overflow thread on
dotnet dev-certs https --trust) did not yet work for me on Ubuntu 20.04.Adding some info here, as it might help with an easy repro. What I did was:
--versiongives3.1.300)IdentityModelEventSource.ShowPII = true; // DEV ONLY!!toConfigure(...)dotnet dev-certs https --trustdotnet runhttps://localhost:5001in FirefoxBecause the instructions in Stack Overflow did not (yet) work for me somehow (even after
sudo update-ca-certificatesthe verificationopenssl verify localhost.crtkeeps giving me the same error as before), the story continues like this for me:GET /endpoint-specific-security/admin-role-only”Then:
https://localhost:5001but this fails with:To my limited understanding it seems that my API is calling another “server” and is not trusting that server’s SSL certificate. So I presume this is the same problem as OP has, only in their case it is “MailKit” that is running a cert that’s not okay for the calling client (similar to my ‘client’ calling into IDS4)?
I’m adding this information because:
I truly hope all this information in my post helps and is not completely off topic. If it is off-topic, then please ignore!
What I did (to no avail) to try and fix the certificate (might be a valid workaround for OP even though it didn’t work for me?):
cdto~/tmplocalhost.conffrom this gistopenssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout localhost.key -out localhost.crt -config localhost.confopenssl pkcs12 -export -out localhost.pfx -inkey localhost.key -in localhost.crtsudo cp localhost.crt /usr/local/share/ca-certificatessudo update-ca-certificates(“1 added”)export ASPNETCORE_Kestrel__Certificates__Default__Password=passwordexport ASPNETCORE_Kestrel__Certificates__Default__Path=~/tmp/localhost.pfxThen
dotnet runmy repository again (it picks up the.pfxbecause it’ll give an error if the password is wrong), but still get the certificate warnings, both in Mozilla Firefox 76.0.1 and in Google Chrome 83.0.I’m still gettting following errors targeting netcoreapp3.1 :
unable to get certificate CRLunable to get local issuer certificateSubject: CN=smtp.gmail.com, O=Google LLC, L=Mountain View, S=California, C=USIssuer: CN=GTS CA 1O1, O=Google Trust Services, C=USMinimal code example for repro with MailKit:
when checking against openssl everything is fine with the certs
help(?)
This issue was ultimately that OpenSSL’s hostname validation routine doesn’t allow underscores.
While underscores are permitted in DNS entries, they’re not legal for hostnames (https://datatracker.ietf.org/doc/html/rfc1034#section-3.5), which is why OpenSSL doesn’t consider it valid.
The CA/Browser forum doubled down on that when they issued a rule that public CAs can’t issue certs that contain underscores in SAN dNSName entries (and had to revoke any there were already so issued): https://cabforum.org/2018/11/12/ballot-sc-12-sunset-of-underscores-in-dnsnames/.