private void PopulateXmlElements(XmlDocument xmlEnvelope) { Nsmgr = NamespaceManager.InitalizeNamespaceManager(xmlEnvelope); Envelope = xmlEnvelope; const string headerWsseSecurity = "/env:Envelope/env:Header/wsse:Security"; const string dsSignature = "./ds:Signature"; const string dsSignaturevalue = "./ds:SignatureValue"; const string bodyXencEncrypteddata = "/env:Envelope/env:Body/xenc:EncryptedData"; const string wsseBinarysecuritytoken = "./wsse:BinarySecurityToken"; const string ciphervalue = "/env:Envelope/env:Header/wsse:Security/xenc:EncryptedKey/xenc:CipherData/xenc:CipherValue"; const string wsuTimestamp = "./wsu:Timestamp"; const string body = "/env:Envelope/env:Body"; HeaderSecurityElement = Envelope.SelectSingleNode(headerWsseSecurity, Nsmgr) as XmlElement; HeaderSignatureElement = HeaderSecurityElement.SelectSingleNode(dsSignature, Nsmgr) as XmlElement; HeaderSignature = HeaderSignatureElement.SelectSingleNode(dsSignaturevalue, Nsmgr) as XmlElement; EncryptedBody = Envelope.SelectSingleNode(bodyXencEncrypteddata, Nsmgr) as XmlElement; HeaderBinarySecurityToken = HeaderSecurityElement.SelectSingleNode(wsseBinarysecuritytoken, Nsmgr) as XmlElement; Cipher = Envelope.SelectSingleNode(ciphervalue, Nsmgr).InnerText; TimestampElement = HeaderSecurityElement.SelectSingleNode(wsuTimestamp, Nsmgr); BodyElement = Envelope.SelectSingleNode(body, Nsmgr); }
protected void SjekkTimestamp(TimeSpan timeSpan) { var timestampElement = HeaderSecurityElement.SelectSingleNode("./wsu:Timestamp", Nsmgr); var created = DateTimeOffset.Parse(timestampElement["Created", Navnerom.WssecurityUtility10].InnerText); var expires = DateTimeOffset.Parse(timestampElement["Expires", Navnerom.WssecurityUtility10].InnerText); if (created > DateTimeOffset.Now.AddMinutes(5)) { throw new Exception("Motatt melding har opprettelsetidspunkt mer enn fem minutter inn i fremtiden." + created.ToString()); } if (created < DateTimeOffset.Now.Add(timeSpan.Negate())) { throw new Exception(string.Format("Motatt melding har opprettelsetidspunkt som er eldre enn {0} minutter.", timeSpan.Minutes)); } if (expires < DateTimeOffset.Now) { throw new Exception("Motatt melding har utgått på tid."); } }
public ResponseValidator(System.IO.Stream stream, SoapVersion version, XmlDocument sentEnvelope, X509Certificate2 xmlDekrypteringsSertifikat = null) { SentEnvelope = sentEnvelope; ResponseDocument = new XmlDocument(); ResponseDocument.Load(stream); Nsmgr = new XmlNamespaceManager(ResponseDocument.NameTable); Nsmgr.AddNamespace("env", version == SoapVersion.Soap11 ? Navnerom.SoapEnvelope : Navnerom.SoapEnvelopeEnv12); Nsmgr.AddNamespace("wsse", Navnerom.WssecuritySecext10); Nsmgr.AddNamespace("ds", Navnerom.XmlDsig); Nsmgr.AddNamespace("xenc", Navnerom.xenc); Nsmgr.AddNamespace("wsse11", Navnerom.WssecuritySecext11); Nsmgr.AddNamespace("wsu", Navnerom.WssecurityUtility10); HeaderSecurityElement = ResponseDocument.SelectSingleNode("/env:Envelope/env:Header/wsse:Security", Nsmgr) as XmlElement; HeaderSignatureElement = HeaderSecurityElement.SelectSingleNode("./ds:Signature", Nsmgr) as XmlElement; if (xmlDekrypteringsSertifikat != null) { DecryptDocument(xmlDekrypteringsSertifikat); } }