question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to cast object of type 'ECDsaSecurityTransforms' to type 'System.Security.Cryptography.ECDsaCng'.

See original GitHub issue

Description

Trying to register a YubiKey 4 as a 2FA throws an invalidcastexception.

Code Used

Code used to produce the exception:

var parsed = AuthenticatorAttestationResponse.Parse(attestationResponse);
var success = parsed.VerifyAsync(
	options,
	new Fido2Configuration {
		ServerName = "Fido 2 local test",
		ServerDomain = "localhost",
		Origin = "https://localhost:63536",
	},
	(x) => Task.FromResult(true), // callback,
	null,
	null);

OR

var success = await fidoLib.MakeNewCredentialAsync(attestationResponse, options, callback);

Parameter Values

AuthenticatorAttestationRawResponse attestationResponse as Json:

{
  "Extensions": {
    "appid": false,
    "authnSel": false,
    "biometricPerfBounds": false
  },
  "Id": "cgwCz28pJtwpIpYjxvkMYzxxJk279q2lWF_4K_EmTSMUGplrdCTv-KGn6glBrc1jd10dLuAJY2wVgy-Ct1xZrQ",
  "RawId": "cgwCz28pJtwpIpYjxvkMYzxxJk279q2lWF_4K_EmTSMUGplrdCTv-KGn6glBrc1jd10dLuAJY2wVgy-Ct1xZrQ",
  "Response": {
    "AttestationObject": "o2NmbXRoZmlkby11MmZnYXR0U3RtdKJjc2lnWEYwRAIgXH6YWrE9Qc7_q5UH0fRROUq6Rl1zqneHegP8oLx_RskCIDzK8tHqPbywvXMHihhTpWPNMCU-_iqIvWALrGNfouZuY3g1Y4FZAk4wggJKMIIBMqADAgECAgRXFvfAMA0GCSqGSIb3DQEBCwUAMC4xLDAqBgNVBAMTI1l1YmljbyBVMkYgUm9vdCBDQSBTZXJpYWwgNDU3MjAwNjMxMCAXDTE0MDgwMTAwMDAwMFoYDzIwNTAwOTA0MDAwMDAwWjAsMSowKAYDVQQDDCFZdWJpY28gVTJGIEVFIFNlcmlhbCAyNTA1NjkyMjYxN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h0dHBzOi8vbG9jYWxob3N0OjYzNTM2IiwidHlwZSI6IndlYmF1dGhuLmNyZWF0ZSJ9"
  },
  "Type": "public-key"
}

CredentialCreateOptions options as Json:

{
    "rp": {
        "id": "localhost",
        "name": "Fido 2 local test"
    },
    "user": {
        "name": "testing@evidos.nl",
        "id": "YjYzYzMyZDU1ODI5NDUzZmFlY2JhZDQ5NjdjMDRkYmM",
        "displayName": "testing@evidos.nl"
    },
    "challenge": "lr7HiuNiDw9ThdDpQhjpfA",
    "pubKeyCredParams": [
        {
            "type": "public-key",
            "alg": -7
        },
        {
            "type": "public-key",
            "alg": -257
        },
        {
            "type": "public-key",
            "alg": -37
        },
        {
            "type": "public-key",
            "alg": -35
        },
        {
            "type": "public-key",
            "alg": -258
        },
        {
            "type": "public-key",
            "alg": -38
        },
        {
            "type": "public-key",
            "alg": -36
        },
        {
            "type": "public-key",
            "alg": -259
        },
        {
            "type": "public-key",
            "alg": -39
        }
    ],
    "timeout": 60000,
    "attestation": "direct",
    "authenticatorSelection": {
        "requireResidentKey": false,
        "userVerification": "discouraged"
    },
    "excludeCredentials": [
        {
            "type": "public-key",
            "id": "AZMCIBCLkeohptOEnL3Y6irnVdcbnvro3X1PcifZdg2OG28tfq4raUhUmpjEIZh5MZm2BagibXhg6qcWNuqEklYPCnC8loXQ18DRmkRlTG85VRdr-IU7C7tAMi0diKQprU8rqaM"
        }
    ],
    "extensions": {
        "exts": true,
        "uvi": true,
        "loc": true,
        "uvm": true,
        "biometricPerfBounds": {
            "FAR": 3.40282347e+38,
            "FRR": 3.40282347e+38
        }
    },
    "status": "ok",
    "errorMessage": ""
}

Exception thrown

This throws an InvalidCastException:

Exception has occurred: CLR/System.AggregateException
Exception thrown: 'System.AggregateException' in System.Private.CoreLib.dll: 'One or more errors occurred.'
 Inner exceptions found, see $exception in variables window for more details.
 Innermost exception 	 System.InvalidCastException : Unable to cast object of type 'ECDsaSecurityTransforms' to type 'System.Security.Cryptography.ECDsaCng'.
   at Fido2NetLib.AttestationFormat.FidoU2f.Verify()
   at Fido2NetLib.AuthenticatorAttestationResponse.<VerifyAsync>d__10.MoveNext()

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12

github_iconTop GitHub Comments

1reaction
abergscommented, Oct 29, 2019

Great. scheduling a release in about 1 week to allow for feedback from others.

1reaction
WouterHDcommented, Oct 29, 2019

@abergs I was able to both register and verify my Yubikeys using the new release 🎉 Tested with firefox and chrome on MacOs

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to cast object of type 'ECDsaSecurityTransforms ...
Description Trying to register a YubiKey 4 as a 2FA throws an invalidcastexception. Code Used Code used to produce the exception: var parsed ......
Read more >
c# - Unable to cast object of type 'System.Security. ...
Just goes to show the amount of legacy assumptions in core libraries. It seems that you have to create your own extension of ......
Read more >
[IdP] Unable to cast object of type 'System.Security. ...
In the Sevice Center, I found: Unable to cast object of type 'System.Security.Cryptography.RSACng' to type 'System.Security.Cryptography.
Read more >
Unable to cast object of type 'System.Security. ...
When I use this certificate to sign saml response I get this error message. Unable to cast object of type 'System.Security.Cryptography.
Read more >
ECDsaCng Class (System.Security.Cryptography)
Provides a Cryptography Next Generation (CNG) implementation of the Elliptic ... a new instance of the ECDsaCng class by using the specified CngKey...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found