xavierjohn / ClientCertificateMiddleware

Asp.net core Client Certificate Middleware
MIT License
57 stars 16 forks source link

How to add multi line Issuer & Subject to appsettings.json #3

Closed vbncmx closed 5 years ago

vbncmx commented 6 years ago

Hi Xavier,

thank you for a good intro to using client certification

I face the following issue:

An organization provided us with a certificate, with several lines in subject & issuer:

Subject:

CN = xxxxx SERIALNUMBER = xxxxx 7.1.3.24 = xxxxxx O = xxxxx ...

Issuer:

CN = xxxxx OU = xxxxx OU = xxxxx ...

Are you aware of the format to write that down in appsettings.json?

Another option would be adding client certs by thumbprint, but looks like it does not work

xavierjohn commented 6 years ago

Try the following code to get your subject. You can use linqpad.

var cert = new X509Certificate2(@"C:\temp\user.mylocalmachine.cer");

var snippet = @"
    {{
      ""Issuer"": ""{0}"",
      ""Subject"": ""{1}"",
      ""Roles"": [
        ""INSERT_ROLES""
      ]
    }},
";
Console.WriteLine(snippet, cert.Issuer, cert.Subject);
vbncmx commented 6 years ago

Thanks, indeed I could look at these field since the cert is loaded on the client side)

However I modified your code a bit to mark valid certs with the Thumbprint. It is just more handy in my case