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

System.NotSupportedException: cannot decode public key from unknown oid '1.2.840.10045.2.1' #71

Open
Alex-Dobrynin opened this issue Jun 30, 2020 · 27 comments
Labels

Comments

@Alex-Dobrynin
Copy link

when I use modernhttpclient.nativemessagehandler and trying to get access trough this link: https://restcountries.eu/data/ala.svg I get an exception mentioned in title of this issue. If I use httpclient without nativemessagehandler it is ok

@YuliaLoyko
Copy link

YuliaLoyko commented Oct 7, 2020

same issue here. plugin does not support ECDSA, which is a big issue

@alexrainman
Copy link
Owner

Let me se what i can do.

@danieljgmaclean
Copy link

Having the same problem. But I worked around it by setting TLSConfig and SSL Pinning. Not sure why this works.

@YuliaLoyko
Copy link

@alexrainman thank you!
do you have any ETA for this? or do you need some help?

@alexrainman
Copy link
Owner

Is this iOS only?

@Alex-Dobrynin
Copy link
Author

Is this iOS only?

no, it`s both

@alexrainman
Copy link
Owner

Well, i am facing this issue too so, i have to fix it :)

@alexrainman
Copy link
Owner

I cannot reproduce this. I can get https://restcountries.eu/data/ala.svg without any issues as soon as i provide the public key in the TLSConfig.

@alexrainman
Copy link
Owner

You can get that server public key running this code in Android:

var hostname = "restcountries.eu";

var certificatePinner = new Square.OkHttp3.CertificatePinner.Builder()
    .Add(hostname, "sha256/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=")
    .Build();

var client = new OkHttpClient.Builder()
    .CertificatePinner(certificatePinner)
    .Build();

var request = new Request.Builder()
    .Url("https://" + hostname)
    .Build();

var call = client.NewCall(request);

var response = await call.ExecuteAsync();

Then provide it in the TLSConfig:

readonly HttpClient client = new HttpClient(new NativeMessageHandler(false, new TLSConfig()
{
    Pins = new List<Pin>()
    {
        new Pin()
        {
            Hostname = "restcountries.eu",
            PublicKeys = new string []
            {
                "sha256/wxgZ6Jx5WaNt5zAgUSDnLsK8E5uy+DUumAogHk4P7R8="
            }
        }
    },
    DangerousAcceptAnyServerCertificateValidator = false
})
{
    DisableCaching = true,
    Timeout = new TimeSpan(0, 0, 9)
});

@Alex-Dobrynin
Copy link
Author

what about ios?
and i provide this handler to FF Image Loading once at app startup, so i need to have universal approach. because the user may have different images or svgs from different hosts and from our backend during runtime.

so what i did, i just left default http client

image

@alexrainman
Copy link
Owner

It is universal.

You get the Public Key using that trick in Android, then configure TLS for both platforms in your shared code.

Also, i found where the library fails and this is not something i can fix unless i replace this piece of code:

if (!chain.Build(root))
{
    errors = SslPolicyErrors.RemoteCertificateChainErrors;
    PinningFailureMessage = FailureMessages.ChainError;
    goto sslErrorVerify;
}

With something like this:

var valid = chain.ChainElements.Cast<X509ChainElement>().All(x => x.Certificate.Thumbprint == root.Thumbprint);

if (!valid)
{
    errors = SslPolicyErrors.RemoteCertificateChainErrors;
    PinningFailureMessage = FailureMessages.ChainError;
    goto sslErrorVerify;
}

chain.Build(root) fails with ECDSA because it is not supported by Mono:

https://github.com/mono/mono/blob/1547af6a278321d5dbc56a63f18b2380c757608e/mcs/class/System/System.Security.Cryptography.X509Certificates/PublicKey.cs#L141

@alexrainman
Copy link
Owner

By the way, i have exactly the same use case where i need to share my single HttpClient instance with FFImageLoading but i want to use native handlers to make it faster so, i may apply this fix and release a new version.

@alexrainman
Copy link
Owner

same issue here. plugin does not support ECDSA, which is a big issue

chain.Build(root) fails with ECDSA because it is not supported by Mono:

https://github.com/mono/mono/blob/1547af6a278321d5dbc56a63f18b2380c757608e/mcs/class/System/System.Security.Cryptography.X509Certificates/PublicKey.cs#L141

@Alex-Dobrynin
Copy link
Author

but why the default http client works well?

@alexrainman
Copy link
Owner

Because it doesn’t use PublicKey at all.

@alexrainman
Copy link
Owner

As i said, use Android to get server certificate public key, and once you have it, configure modernhttpclient with it for both platforms.

@michelinaFolino
Copy link

michelinaFolino commented Jan 14, 2021

hi,

i have same problem.
Is there any news on the update that fixes this crash?

thank you so much

@InquisitorJax
Copy link

Also ran into this issue.
@alexrainman thanks for the code to discover the public keys!
Interestingly enough - for me - this was only crashing on iOS.

@AlonRom
Copy link

AlonRom commented Sep 18, 2022

Hi @alexrainman Can you estimate when there will be a fix for this in iOS?

@NoamMani
Copy link

NoamMani commented Nov 8, 2022

Hi @alexrainman, we get this exception all the time, is there an update regarding this issue?

@AlonRom
Copy link

AlonRom commented Nov 21, 2022

@alexrainman ??

@alexrainman
Copy link
Owner

I have been out for most of the year. Still recovering from surgery. But a new revamped version of the plugin will be out soon.

@gcadmes-extron
Copy link

Glad you’re on the mend!!
When you do revamp the library, can you make it a . NET MAUI class library project as opposed to the classic xam plugin model

@alexrainman
Copy link
Owner

That's the plan. All my plugins will be out for .NET MAUI

@AlonRom
Copy link

AlonRom commented Nov 21, 2022

@alexrainman Hope you are feeling well!
Happy to hear that a version with fixes will be released soon, we have been waiting for it for quite a long time.
a Xamarin.Forms version with this fix will be released as well, right?

@alexrainman
Copy link
Owner

Yes, XF will be released in a minor version while .NET MAUI will be a major release.

@NoamMani
Copy link

@alexrainman any update?

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

No branches or pull requests

9 participants