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

NullReferenceExceotion når brukes i .Net6 applikasjon #28

Open
teilin opened this issue Oct 12, 2022 · 0 comments
Open

NullReferenceExceotion når brukes i .Net6 applikasjon #28

teilin opened this issue Oct 12, 2022 · 0 comments

Comments

@teilin
Copy link

teilin commented Oct 12, 2022

Har oppdatert ett prosjekt som har brukt en gammel versjon av denne pakken. Når jeg da bruker nuget-pakken i .net6 applikasjonen, så ender jeg opp med en nullreference exception i System.Security.Cryptography.Xml.SignedXml. Er dette ett kjent problem?

    System.Security.Cryptography.Xml.SignedXml.IsKeyTheCorrectAlgorithm(System.Security.Cryptography.AsymmetricAlgorithm, System.Type) in SignedXml.cs
    System.Security.Cryptography.Xml.SignedXml.CheckSignedInfo(System.Security.Cryptography.AsymmetricAlgorithm) in SignedXml.cs
    System.Security.Cryptography.Xml.SignedXml.CheckSignature(System.Security.Cryptography.AsymmetricAlgorithm) in SignedXml.cs
    System.Security.Cryptography.Xml.SignedXml.CheckSignatureReturningKey(out System.Security.Cryptography.AsymmetricAlgorithm) in SignedXml.cs
    Difi.SikkerDigitalPost.Klient.XmlValidering.ResponseValidator.ValidateSignatureAndCertificate(string, string)
    Difi.SikkerDigitalPost.Klient.XmlValidering.ResponseValidator.ValidateHeaderSignature()
    Difi.SikkerDigitalPost.Klient.XmlValidering.ResponseValidator.ValidateEmptyQueueReceipt()
    Difi.SikkerDigitalPost.Klient.Api.SikkerDigitalPostKlient.SecurityValidationOfEmptyQueueReceipt(System.Xml.XmlDocument, System.Xml.XmlDocument)
    Difi.SikkerDigitalPost.Klient.Api.SikkerDigitalPostKlient.HentKvitteringOgBekreftForrigeAsync(Difi.SikkerDigitalPost.Klient.Domene.Entiteter.Kvitteringer.Kvitteringsforespørsel, Difi.SikkerDigitalPost.Klient.Domene.Entiteter.Kvitteringer.Forretning.Forretningskvittering)

I SignedXml.cs ender det opp med at expectedType er null.

private static bool IsKeyTheCorrectAlgorithm(AsymmetricAlgorithm key, Type expectedType)
        {
            Type actualType = key.GetType();

            if (actualType == expectedType)
                return true;

            // This check exists solely for compatibility with 4.6. Normally, we would expect "expectedType" to be the superclass type and
            // the actualType to be the subclass.
            if (expectedType.IsSubclassOf(actualType))
                return true;

            //
            // "expectedType" comes from the KeyAlgorithm property of a SignatureDescription. The BCL SignatureDescription classes have historically
            // denoted provider-specific implementations ("RSACryptoServiceProvider") rather than the base class for the algorithm ("RSA"). We could
            // change those (at the risk of creating other compat problems) but we have no control over third party SignatureDescriptions.
            //
            // So, in the absence of a better approach, walk up the parent hierarchy until we find the ancestor that's a direct subclass of
            // AsymmetricAlgorithm and treat that as the algorithm identifier.
            //
            while (expectedType != null && expectedType.BaseType != typeof(AsymmetricAlgorithm))
            {
                expectedType = expectedType.BaseType;
            }

            if (expectedType == null)
                return false;   // SignatureDescription specified something that isn't even a subclass of AsymmetricAlgorithm. For compatibility with 4.6, return false rather throw.

            if (actualType.IsSubclassOf(expectedType))
                return true;

            return false;
        }
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

1 participant