{"action":"closed","issue":{"url":"https://api.github.com/repos/Sustainsys/Saml2/issues/1046","repository_url":"https://api.github.com/repos/Sustainsys/Saml2","labels_url":"https://api.github.com/repos/Sustainsys/Saml2/issues/1046/labels{/name}","comments_url":"https://api.github.com/repos/Sustainsys/Saml2/issues/1046/comments","events_url":"https://api.github.com/repos/Sustainsys/Saml2/issues/1046/events","html_url":"https://github.com/Sustainsys/Saml2/issues/1046","id":392129673,"node_id":"MDU6SXNzdWUzOTIxMjk2NzM=","number":1046,"title":"Object reference exception at Sustainsys.Saml2.Saml2P.Saml2Response.ValidateSignature(IOptions options)","user":{"login":"bsunilkumar","id":8065615,"node_id":"MDQ6VXNlcjgwNjU2MTU=","avatar_url":"https://avatars3.githubusercontent.com/u/8065615?v=4","gravatar_id":"","url":"https://api.github.com/users/bsunilkumar","html_url":"https://github.com/bsunilkumar","followers_url":"https://api.github.com/users/bsunilkumar/followers","following_url":"https://api.github.com/users/bsunilkumar/following{/other_user}","gists_url":"https://api.github.com/users/bsunilkumar/gists{/gist_id}","starred_url":"https://api.github.com/users/bsunilkumar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bsunilkumar/subscriptions","organizations_url":"https://api.github.com/users/bsunilkumar/orgs","repos_url":"https://api.github.com/users/bsunilkumar/repos","events_url":"https://api.github.com/users/bsunilkumar/events{/privacy}","received_events_url":"https://api.github.com/users/bsunilkumar/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-12-18T12:14:26Z","updated_at":"2018-12-24T09:52:47Z","closed_at":"2018-12-24T09:52:47Z","author_association":"NONE","body":"\r\nWe are upgraded our solutions to .NetFramework 4.7.2 and DotnetCore 2.1 iam getting the below object reference exception with SAML\r\n\r\nWe using the SAML2 version 0.23.0.0\r\nSustainsys.Saml2.Saml2P.Saml2Response, Sustainsys.Saml2, Version=0.23.0.0, Culture=neutral, PublicKeyToken=null\r\n\r\nObject reference not set to an instance of an object.\r\n   at Sustainsys.Saml2.Saml2P.Saml2Response.ValidateSignature(IOptions options)\r\n   at Sustainsys.Saml2.Saml2P.Saml2Response.<CreateClaims>d__57.MoveNext()\r\n   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)\r\n   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)\r\n   at Sustainsys.Saml2.Saml2P.Saml2Response.GetClaims(IOptions options)\r\n\r\nSAML Response:\r\n\r\n<saml2p:Response \r\n    Destination=\"http://test.localhost:5000/Saml/Acs\" \r\n    ID=\"id1795ceab9f394340bb25600fccd06bd3\" \r\n    Version=\"2.0\" \r\n    IssueInstant=\"2018-12-17T11:26:38Z\" \r\n    xmlns:saml2p=\"urn:oasis:names:tc:SAML:2.0:protocol\">\r\n    <saml2:Issuer \r\n        xmlns:saml2=\"urn:oasis:names:tc:SAML:2.0:assertion\">http://stubidp.sustainsys.com/Metadata\r\n    </saml2:Issuer>\r\n    <Signature \r\n        xmlns=\"http://www.w3.org/2000/09/xmldsig#\">\r\n        <SignedInfo>\r\n            <CanonicalizationMethod \r\n                Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\" />\r\n            <SignatureMethod \r\n                Algorithm=\"http://www.w3.org/2001/04/xmldsig-more#rsa-sha256\" />\r\n            <Reference \r\n                URI=\"#id1795ceab9f394340bb25600fccd06bd3\">\r\n                <Transforms>\r\n                    <Transform \r\n                        Algorithm=\"http://www.w3.org/2000/09/xmldsig#enveloped-signature\" />\r\n                    <Transform \r\n                        Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\" />\r\n                </Transforms>\r\n                <DigestMethod \r\n                    Algorithm=\"http://www.w3.org/2001/04/xmlenc#sha256\" />\r\n                <DigestValue>\r\n                    tayCxJOmqWnnTlSsVFstsESRdqdCTjGh5aqLGecUB7s=\r\n                </DigestValue>\r\n            </Reference>\r\n        </SignedInfo>\r\n        <SignatureValue>iOlIFvkqFvuu3aGre9SvT90a4NMzGqdLeHgL5P4slpIjQDupfMwPGqnVwXjK36AIy5o2v/YnoJjgVLYppUbZneY4it10Hm+RSkBbRJsA+RqlrGs4JyS7FEScdORV/\r\n            t4fbGp8Y3DNGch27WqB4LnH2cBLEOx9DNz3PRJFXAZgWvs=\r\n        </SignatureValue>\r\n        <KeyInfo>\r\n            <X509Data>\r\n                <X509Certificate>MIICFTCCAYKgAwIBAgIQzfcJCkM1YahDtRGYsLphrDAJBgUrDgMCHQUAMCExHzAdBgNVBAMTFnN0dWJpZHAuc3VzdGFpbnN5cy5jb20wHhcNMTcxMjE0MTE1NDUwWhcNMzkxMjMxMjM1OTU5WjAhMR8wHQYDVQQDExZzdHViaWRwLnN1c3RhaW5zeXMuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDSSq8EX46J1yprfaBdh4pWII+/E7ypHM1NjG7mCwFwbkjq2tpSBuoASrQftbjIKqjVzxtxETw802VJu5CJR4d3Zdy5jD8NRTesfaQDazX7iiqisfnxmIdDhtJS0lXeBlj4MipoUW6l8Qsjx7ltZSwdfFLyh+bMqIrwOhMWGs82vQIDAQABo1YwVDBSBgNVHQEESzBJgBCBBNba7KNF5wnXqmYcejn6oSMwITEfMB0GA1UEAxMWc3R1YmlkcC5zdXN0YWluc3lzLmNvbYIQzfcJCkM1YahDtRGYsLphrDAJBgUrDgMCHQUAA4GBAHonBGahlldp7kcN5HGGnvogT8a0nNpM7GMdKhtzpLO3Uk3HyT3AAIKWiSoEv2n1BTalJ/CY/+te/JZPVGhWVzoi5JYytpj5gM0O7RH0a3/yUE8S8YLV2h0a2gsdoMvTRTnTm9CnXezCKqhjYjwsmOZtiCIYuFqX71d/pg5uoJfs</X509Certificate>\r\n            </X509Data>\r\n        </KeyInfo>\r\n    </Signature>\r\n    <saml2p:Status>\r\n        <saml2p:StatusCode \r\n            Value=\"urn:oasis:names:tc:SAML:2.0:status:Success\" />\r\n    </saml2p:Status>\r\n    <saml2:Assertion \r\n        xmlns:saml2=\"urn:oasis:names:tc:SAML:2.0:assertion\" \r\n        Version=\"2.0\" \r\n        ID=\"_56e9a121-c7b2-4afb-af7b-0807578b8d41\" \r\n        IssueInstant=\"2018-12-17T11:26:38Z\">\r\n        <saml2:Issuer>http://stubidp.sustainsys.com/Metadata</saml2:Issuer>\r\n        <saml2:Subject>\r\n            <saml2:NameID \r\n                Format=\"urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified\">kodos\r\n            </saml2:NameID>\r\n            <saml2:SubjectConfirmation \r\n                Method=\"urn:oasis:names:tc:SAML:2.0:cm:bearer\">\r\n                <saml2:SubjectConfirmationData \r\n                    NotOnOrAfter=\"2018-12-17T11:28:38Z\" \r\n                    Recipient=\"http://test.localhost:5000/Saml/Acs\" />\r\n            </saml2:SubjectConfirmation>\r\n        </saml2:Subject>\r\n        <saml2:Conditions \r\n            NotOnOrAfter=\"2018-12-17T11:28:38Z\" />\r\n        <saml2:AuthnStatement \r\n            AuthnInstant=\"2018-12-17T11:26:38Z\" \r\n            SessionIndex=\"42\">\r\n            <saml2:AuthnContext>\r\n                <saml2:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified</saml2:AuthnContextClassRef>\r\n            </saml2:AuthnContext>\r\n        </saml2:AuthnStatement>\r\n    </saml2:Assertion>\r\n</saml2p:Response>\r\n\r\n\r\nSammple Code:\r\n\r\nprivate const string _SamlNameIdentifierTypeNs = \"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier\";\r\n\r\n        private Lazy<AuthServicesOptions> _Options;\r\n        public AuthServicesOptions Options => _Options.Value;\r\n        private SPOptions SpOptions { get; set; }\r\n\t\t\r\n\t\t\r\n\t\t\r\n\t\t Saml2Binding binding = Options.Notifications.GetBinding(httpRequestData);\r\n            validationResults = new List<ValidationResult>();\r\n\r\n            if (binding == null)\r\n            {\r\n                validationResults = ValidationResultFactory.NewValidationResultAsList(\"Could not get saml binding for Http Request Data\", nameof(httpRequestData));\r\n                return null;\r\n            }\r\n\r\n            string username = null;\r\n\r\n            try\r\n            {\r\n                UnbindResult unbindResult = binding.Unbind(httpRequestData, null);\r\n                Options.Notifications.MessageUnbound(unbindResult);\r\n                \r\n                Saml2Response samlResponse = new Saml2Response(unbindResult.Data, httpRequestData.StoredRequestState?.MessageId);\r\n                // Get Claims can only be called once, with the same options. Otherwise it will throw an error.\r\n                ClaimsPrincipal principal = new ClaimsPrincipal(samlResponse.GetClaims(Options));\r\n                Options.SPOptions.SystemIdentityModelIdentityConfiguration.ClaimsAuthenticationManager.Authenticate(null, principal);\r\n\r\n                username = principal.Claims.SingleOrDefault(c => c.Type == _SamlNameIdentifierTypeNs)?.Value;\r\n\r\n                if (principal.Claims.SingleOrDefault(c => c.Type == _SamlNameIdentifierTypeNs)?.Value == null)\r\n                    validationResults = ValidationResultFactory.NewValidationResultAsList(\"Could not find Identifier in SAML\", nameof(httpRequestData));\r\n            }\r\n            catch (FormatException)\r\n            {\r\n                validationResults = ValidationResultFactory.NewValidationResultAsList(\"The SAML Response did not contain valid BASE64 encoded data.\", nameof(httpRequestData));\r\n            }\r\n            catch (XmlException)\r\n            {\r\n                // Difficult to unit test this as we can't sign an invalid xml...\r\n                validationResults = ValidationResultFactory.NewValidationResultAsList(\"The SAML response contains incorrect XML.\", nameof(httpRequestData));\r\n            }\r\n            catch (Exception ex)\r\n            {\r\n                // TODO: Once we have properly error logging implemented, we should log this exception.\r\n                //validationResults = ValidationResultFactory.NewValidationResultAsList(ex.Message, nameof(httpRequestData));\r\n                //Log to console for debugging\r\n                Console.WriteLine(ex.Message);\r\n                Console.WriteLine(ex.StackTrace);\r\n                validationResults = ValidationResultFactory.NewValidationResultAsList(\"There was an unexpected error logging in via SAML\", nameof(httpRequestData));\r\n                Console.WriteLine(\"*** UNHANDLED EXCEPTION OCCURRED ***\");\r\n                Console.WriteLine(ex.ToString());\r\n            }\r\n\r\nThanks,\r\nSunil Kumar B"}}
{"actor":{"display_login":"bsunilkumar"}}