Page History
...
| Code Block | ||
|---|---|---|
| ||
public static async TaskTask<Assertion> LoginToGateway(IdCard idCard, X509Certificate2 userCert) { var sosiGwAssertion = idCard.GetAssertion<AssertionType>(); var security = new GW.Security { Timestamp = new GW.Timestamp { Created = DateTimeEx.UtcNowRound - TimeSpan.FromMinutes(5) }, Assertion = sosiGwAssertion }; const string endpointAddress = "http://test1.ekstern-test.nspop.dk:8080/sosigw/service/sosigw"; await using var gwClient = new SosiGWFacadeClient(SosiGWSoapBinding, endpointAddress); var dig = (await gwClient.requestIdCardDigestForSigningAsync(security, "whatever")).requestIdCardDigestForSigningResponse; var digestHash = SHA1.HashData(dig.DigestValue); var signature = userCert.GetRSAPrivateKey().SignHash(digestHash, HashAlgorithmName.SHA1, RSASignaturePadding.Pkcs1); var cardRequestBody = new signIdCardRequestBody { SignatureValue = signature, KeyInfo = new GW.KeyInfo { Item = new GW.X509Data { Item = userCert.Export(X509ContentType.Cert) } } }; // The STS signed card is saved in the sosiGw cache and is used for future calls through the proxy var res = (await gwClient.signIdCardAsync(security, cardRequestBody)).signIdCardResponse; if (res != signIdCardResponse.ok) { throw new Exception("Gateway logon error"); } // Convert the GW Assertion to a dgwsType Assertion var sosiGwAssertionDocument = SerializerUtil.Serialize(sosiGwAssertion).Root; return SerializerUtil.Deserialize<dk.nsi.seal.dgwstypes.Assertion>(sosiGwAssertionDocument, nameof(AssertionType)); } |
...