private void CheckSerialization(Envelope expected) { var xml = ObjectToXml.Serialize(expected); var actual = XmlToObject.Deserialize <Envelope>(xml); EnvelopeAssert.AreEqual(expected, actual); }
private void CheckEncryption(Envelope envelope, Attachment attachment) { var xml = ObjectToXml.Serialize(envelope); var certificate = Certificates.CreateSelfSigned(); var expected = Copy(attachment.Stream); var encrypter = new EbmsEncrypter { Xml = xml, Attachments = new [] { attachment }, PublicKeyInAsn1Format = certificate.GetPublicKey() }; encrypter.Encrypt(); var decrypter = new EbmsDecrypter { Xml = xml, Attachments = new [] { attachment }, Certificate = certificate }; decrypter.Decrypt(); var actual = Copy(attachment.Stream); Assert.IsTrue(expected.SequenceEqual(actual)); }
public void Sign() { var qualifyingProperties = GetQualifyingProperties(Certificate); var qualifyingPropertiesXml = ObjectToXml.Serialize(qualifyingProperties); var signedXml = new ExtendedSignedXml(Xml); signedXml.Signature.Id = qualifyingProperties.Target; signedXml.SigningKey = Certificate.GetRSAPrivateKey(); signedXml.SignedInfo.CanonicalizationMethod = SignedXml.XmlDsigExcC14NTransformUrl; signedXml.SignedInfo.SignatureMethod = SignedXml.XmlDsigRSASHA256Url; var documentReference = new Reference { Id = qualifyingProperties.SignedProperties.SignedDataObjectProperties.DataObjectFormat.ObjectReference, Type = null, Uri = "" }; documentReference.AddTransform(new XmlDsigEnvelopedSignatureTransform()); documentReference.DigestMethod = SignedXml.XmlDsigSHA256Url; signedXml.AddReference(documentReference); var signedProperties = new Reference { Type = Namespaces.SignedProperties, Uri = "#" + qualifyingProperties.SignedProperties.Id }; signedProperties.AddTransform(new XmlDsigExcC14NTransform()); signedProperties.DigestMethod = SignedXml.XmlDsigSHA256Url; signedXml.AddReference(signedProperties); var dataObject = new DataObject { Data = qualifyingPropertiesXml.ChildNodes }; signedXml.AddObject(dataObject); var certificateKeyInfo = new KeyInfo(); certificateKeyInfo.AddClause(new KeyInfoX509Data(Certificate)); signedXml.KeyInfo = certificateKeyInfo; signedXml.ComputeSignature(); var signature = signedXml.GetXml(); Insert(signature, Xml.DocumentElement); }
private void CheckSigning(Envelope envelope, params Attachment[] attachments) { var xml = ObjectToXml.Serialize(envelope); var ebmsSigner = new EbmsSigner { Xml = xml, Certificate = Certificates.CreateSelfSigned(), Uris = new [] { envelope.Header.Messaging.Id, envelope.Body.Id }, Attachments = attachments }; ebmsSigner.Sign(); var ebmsVerifier = new EbmsVerifier { Xml = xml, Attachments = attachments }; ebmsVerifier.Verify(); }
public void Set(Envelope envelope) { SoapEnvelope = ObjectToXml.Serialize(envelope); }
public void Sign() { var security = new AS4.Security.Security { BinarySecurityToken = new BinarySecurityToken { Id = Guid.NewGuid().ToString(), EncodingType = Soap.Namespaces.Base64Binary, ValueType = Soap.Namespaces.X509TokenProfile, Value = Certificate.GetRawCertData() } }; var securityXml = ObjectToXml.Serialize(security); var signedXml = new ExtendedSignedXml(Xml) { SigningKey = Certificate.GetRSAPrivateKey() }; foreach (var uri in Uris) { var reference = new Reference { Uri = "#" + uri, DigestMethod = SignedXml.XmlDsigSHA256Url }; reference.AddTransform(new XmlDsigExcC14NTransform()); signedXml.AddReference(reference); } foreach (var attachment in Attachments) { var reference = new Reference(new NonCloseableStream(attachment.Stream)) { Uri = "cid:" + attachment.ContentId, DigestMethod = SignedXml.XmlDsigSHA256Url }; reference.AddTransform(new AttachmentContentSignatureTransform()); signedXml.AddExternalReference(reference); } var keyInfo = new KeyInfo(); keyInfo.AddClause(new SecurityTokenReference(security.BinarySecurityToken.Id)); signedXml.KeyInfo = keyInfo; signedXml.SignedInfo.CanonicalizationMethod = SignedXml.XmlDsigExcC14NTransformUrl; signedXml.SignedInfo.SignatureMethod = SignedXml.XmlDsigRSASHA256Url; signedXml.ComputeSignature(); var signature = signedXml.GetXml(); Insert(signature, securityXml.DocumentElement); var namespaces = new XmlNamespaceManager(Xml.NameTable); namespaces.AddNamespace("s", Soap.Namespaces.SoapEnvelope); var header = Xml.SelectSingleNode("/s:Envelope/s:Header", namespaces); Insert(securityXml, header); }