CryptoSys Home > xmlsq > Query a signed XML-DSIG document

Query a signed XML-DSIG document


Use the command line to query a signed XML-DSIG document

Input file: example-obj-signed.xml

Get the CanonicalizationMethod and SignatureMethod algorithms
> xmlsq "//ds:CanonicalizationMethod/@Algorithm" example-obj-signed.xml
http://www.w3.org/TR/2001/REC-xml-c14n-20010315

> xmlsq "//ds:SignatureMethod/@Algorithm" example-obj-signed.xml
http://www.w3.org/2000/09/xmldsig#rsa-sha1
How many Reference elements?
> xmlsq --count "//ds:Reference" example-obj-signed.xml
2
Extract the digest values
> xmlsq  "(//ds:Reference)[1]/ds:DigestValue" example-obj-signed.xml
J+9NBdXdULEOhvdxSRtx5f+QUBE=

> xmlsq  "(//ds:Reference)[2]/ds:DigestValue" example-obj-signed.xml
qznsyVqM2sgMCpKnQnqhsnL8wDU=
Extract the second URI reference
> xmlsq "(//ds:Reference)[2]/@URI" example-obj-signed.xml
#obj-b
Extract the contents of the reference
> xmlsq //*[@Id='obj-b'] example-obj-signed.xml
More content.
Extract the first URI reference, URI=""
> xmlsq "(//ds:Reference)[1]/@URI" example-obj-signed.xml
 
Oh! This is an attribute with an empty value. Use the --delim option to see the result more clearly.
> xmlsq  --delim=' "(//ds:Reference)[1]/@URI" example-obj-signed.xml
''
> xmlsq  --delim=[] "(//ds:Reference)[1]/@URI" example-obj-signed.xml
[]
Check the full query result.
> xmlsq -f "(//ds:Reference)[1]/@URI" example-obj-signed.xml
URI=""
Extract the SignatureValue
> xmlsq //ds:SignatureValue example-obj-signed.xml
xgYGwedYZKJ0QhBJ9XdB0XekSqIk+HYdH+leK4plE6PEt49cTK+t0AwIt7Q/ctn/vHTVC/pirFf+KrcmIxPsvP
FMQDEpx+Rx7RyN7RlvWeeyHYvf64Uk20refVdnja4PVNCXNmiQtFTQrgbBcK/WVS0NnJdAYmq6yzLDDDcKYTc=
Use the "local-name" predicate.
> xmlsq --count "//*[local-name()='Reference']" example-obj-signed.xml
2

Contact us

To contact us or comment on this page, please send us a message.

This page last updated 2 June 2020

[Go to top]