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

Cannot reach endpoint that needs a (self-signed) client certificate to connect #75

Open
robsiera opened this issue Feb 22, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@robsiera
Copy link

I want to reach an OData endpoint on port 443 that uses a client-certificate to authenticate, a self-signed client certificate.
That fails with this message: Cannot access < endpoint >. Exception message: 'The remote server returned an error: (401) Unauthorized'

I guess this is not supported? There is no way to specify the thumbprint which would allow you to find the certificate from the local store and add it to the request?

Is this a feature I can help develop?
Fetching a certificate form the store is done like this:

`
public static X509Certificate2 GetCertificate(string thumbprint)
{

thumbprint = Regex.Replace(thumbprint, @"[^\da-zA-z]", string.Empty).ToUpper();
var store = new X509Store(StoreName.My, StoreLocation.LocalMachine);

try
{
    store.Open(OpenFlags.ReadOnly);
    var certCollection = store.Certificates;
    var signingCert = certCollection.Find(X509FindType.FindByThumbprint, thumbprint, false);
    if (signingCert.Count == 0)
    {
        throw new FileNotFoundException($"Certificate with thumbprint: '{thumbprint}' not found in local machine cert store.");
    }
    return signingCert[0];
}
finally
{
    store.Close();
}

}
`

But the XmlUrlResolver does not seem to support client certificates.
Although it seems to have a underlying WebRequest class, so in theory one should be able to call mywebRequest.ClientCertificates.Add(myClientCertificate).

Please advise

@robsiera robsiera added the bug Something isn't working label Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant