Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to disable RemoteCertificateNameMismatch for self-signed certificates #196

Closed
kalyankrishna1 opened this issue Sep 7, 2022 · 6 comments

Comments

@kalyankrishna1
Copy link

kalyankrishna1 commented Sep 7, 2022

Which version of Duende IdentityServer are you using? 4 (identityModel 6.0.0)

Which version of .NET are you using? 6.0

Describe the bug
I am trying to use a self-signed certificate in a docker compose set up with nginx for ssl. the call to the discovery metadata doc using https works fine in browser (https://mylocalserver.com:44395/.well-known/openid-configuration) after I added the cert created using openssl to the Local machine's "trusted root certification authorities".

the certificate is issued to
mylocalserver.com

I also the following line of code in the Main()

ServicePointManager.ServerCertificateValidationCallback += (o, c, ch, er) => true;

A clear and concise description of what the bug is.

I get the following exception when I run the aspnetcore web app of mine

[08:57:46 ERR] HTTP GET /Login responded 500 in 219.3944 ms
System.InvalidOperationException: IDX20803: Unable to obtain configuration from: 'https://mylocalserver.com:44395/.well-known/openid-configuration'.
 ---> System.IO.IOException: IDX20804: Unable to retrieve document from: 'https://mylocalserver.com:44395/.well-known/openid-configuration'.
 ---> System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
 ---> System.Security.Authentication.AuthenticationException: **The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch**

when
To Reproduce

Steps to reproduce the behavior.

Try using a self-signed certificate in a docker compose environment with a aspnetcore web app

Expected behavior

The C# code that switches off the certificate validation should have suppressed this check

A clear and concise description of what you expected to happen.

Log output/exception with stacktrace

Code from startup.cs (happy to provide more if that helps

        private void AddOidcSettingsFromConfig(OpenIdConnectOptions options)
        {
            options.Authority = Configuration.GetValue<string>("AuthN:Authority");
            options.ClientId = Configuration.GetValue<string>("AuthN:ClientId");
            options.ClientSecret = Configuration.GetValue<string>("AuthN:ClientSecret");
            options.Scope.Clear();
         
            var allScopes = Configuration.GetValue<string>("AuthN:Scopes");
            foreach (var scope in allScopes.Split(' '))
            {
                options.Scope.Add(scope);
            }
        }

Additional context

Add any other context about the problem here.

@brockallen
Copy link
Member

It sounds like the host name being used does not match the cert name you have configured. Beyond that, I'm not sure.

@kalyankrishna1
Copy link
Author

cert with subject, "CN = id-local.globomantics.com" is placed in trusted root certification authorities

Call to "https://id-local.globomantics.com:44395/.well-known/openid-configuration" via browser has no issues. Note that the port 443 in the container is mapped to 44395 on host

services: reverseproxy: build: context: . dockerfile: nginx/nginx.Dockerfile depends_on: - globomantics.identityserver ports: - "44395:443"

image
image

code is present on the aspnet core 6.0 web app to ignore cert validation errors

image

Not sure what else can I do?

@brockallen
Copy link
Member

All set on this issue -- can we close?

@kalyankrishna1
Copy link
Author

It was a docker port mapping issue and a missing update-ca-certificates command. its fixed. Thanks fot your patience

@hojatallahkazemi
Copy link

Hello, I have the same problem as yours. Can you please explain exactly how your problem was solved? I don't have docker

@josephdecock
Copy link
Member

@hojatallahkazemi could you please open a new issue to describe your symptoms and environment in more detail?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants