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 check if PublicKey is type of EC and p-256 curve? #1

Closed
abergs opened this issue Jun 1, 2018 · 2 comments
Closed

How to check if PublicKey is type of EC and p-256 curve? #1

abergs opened this issue Jun 1, 2018 · 2 comments

Comments

@abergs
Copy link
Collaborator

abergs commented Jun 1, 2018

I'm able to check that a PubKey is of type ECC (same as EC as far as I understand) by checking the Name property, e.g.

var x5c = o.AttestionObject.AttStmt["x5c"];
var sig= o.AttestionObject.AttStmt["sig"];
var cert = new X509Certificate2(x5c.Values.First().GetByteString());
var pubkeyType = cert.PublicKey.Oid.FriendlyName; // ECC

But how do I check the Curve type, as required by the spec: https://www.w3.org/TR/webauthn/#fido-u2f-attestation

Let attCert be the value of the first element of x5c. Let certificate public key be the public key conveyed by attCert. If certificate public key is not an Elliptic Curve (EC) public key over the P-256 curve, terminate this algorithm and return an appropriate error.

@aseigler
Copy link
Collaborator

aseigler commented Aug 1, 2018

The PublicKey property of X509Certificate2 seems somewhat deprecated, particularly for EC.

You can validate this public key as follows:

var pubKey = (ECDsaCng) cert.GetECDsaPublicKey();
if (CngAlgorithm.ECDsaP256 != pubKey.Key.Algorithm) throw new Fido2VerificationException();

@abergs
Copy link
Collaborator Author

abergs commented Aug 1, 2018 via email

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

No branches or pull requests

2 participants