diff --git a/src/System Application/App/Cryptography Management/src/Xml/SignedXml.Codeunit.al b/src/System Application/App/Cryptography Management/src/Xml/SignedXml.Codeunit.al index 8cdfc4662a3..91ae99397a4 100644 --- a/src/System Application/App/Cryptography Management/src/Xml/SignedXml.Codeunit.al +++ b/src/System Application/App/Cryptography Management/src/Xml/SignedXml.Codeunit.al @@ -91,6 +91,15 @@ codeunit 1460 SignedXml SignedXmlImpl.InitializeReference(Uri); end; + /// + /// Sets the type Uniform Resource Identifier (URI) of the current Reference. + /// + /// The type URI of the current Reference. + procedure SetReferenceType(Type: Text) + begin + SignedXmlImpl.SetReferenceType(Type); + end; + /// /// Sets the digest method Uniform Resource Identifier (URI) of the current Reference. /// diff --git a/src/System Application/App/Cryptography Management/src/Xml/SignedXmlImpl.Codeunit.al b/src/System Application/App/Cryptography Management/src/Xml/SignedXmlImpl.Codeunit.al index c93a14a4fe2..06d85664452 100644 --- a/src/System Application/App/Cryptography Management/src/Xml/SignedXmlImpl.Codeunit.al +++ b/src/System Application/App/Cryptography Management/src/Xml/SignedXmlImpl.Codeunit.al @@ -47,6 +47,11 @@ codeunit 1461 "SignedXml Impl." DotNetReference := DotNetReference.Reference(Uri); end; + procedure SetReferenceType(Type: Text) + begin + DotNetReference.Type := Type; + end; + procedure SetDigestMethod(DigestMethod: Text) begin DotNetReference.DigestMethod := DigestMethod; diff --git a/src/System Application/Test/Cryptography Management/src/Xml/SignedXmlModuleTest.Codeunit.al b/src/System Application/Test/Cryptography Management/src/Xml/SignedXmlModuleTest.Codeunit.al index 035fedc4702..cdb19869a45 100644 --- a/src/System Application/Test/Cryptography Management/src/Xml/SignedXmlModuleTest.Codeunit.al +++ b/src/System Application/Test/Cryptography Management/src/Xml/SignedXmlModuleTest.Codeunit.al @@ -81,6 +81,43 @@ codeunit 132612 "Signed Xml Module Test" LibraryAssert.IsTrue(SignedXml.CheckSignature(CertBase64Data, Password, true), 'Failed to verify the xml signature.'); end; + [Test] + procedure SetReferenceType() + var + SignatureKey: Codeunit "Signature Key"; + XmlToSign: XmlDocument; + KeyText: SecretText; + Signature: XmlElement; + NamespaceMgr: XmlNamespaceManager; + Node: XmlNode; + SignatureNamespaceUriTok: Label 'http://www.w3.org/2000/09/xmldsig#', Locked = true; + ReferenceTypeTok: Label 'http://uri.etsi.org/01903#SignedProperties', Locked = true; + begin + XmlDocument.ReadFrom('This is a document', XmlToSign); + GetSignatureKeyXmlString(KeyText); + SignatureKey.FromXmlString(KeyText); + + SignedXml.InitializeSignedXml(XmlToSign); + SignedXml.SetSigningKey(SignatureKey); + SignedXml.InitializeReference('#ID01'); + SignedXml.SetReferenceType(ReferenceTypeTok); + SignedXml.AddReferenceToSignedXML(); + + SignedXml.ComputeSignature(); + Signature := SignedXml.GetXml(); + + NamespaceMgr.AddNamespace('ns', SignatureNamespaceUriTok); + Signature.SelectSingleNode( + './ns:SignedInfo/ns:Reference/@Type', + NamespaceMgr, + Node); + + LibraryAssert.AreEqual( + ReferenceTypeTok, + Node.AsXmlAttribute().Value, + 'Incorrect reference type was applied.'); + end; + [Test] procedure SetXmlDSigC14NTranform() var