84
XML Signature Prabath Siriwardena Director, Security Architecture

XML Signature

Embed Size (px)

DESCRIPTION

XML Signature

Citation preview

Page 1: XML Signature

XML Signature

Prabath SiriwardenaDirector, Security Architecture

Page 2: XML Signature

XML Security• Integrity and non-repudiation

XML Signature by W3C http://www.w3.org/TR/xmldsig-core/

• Confidentiality of XML documents XML Encryption by W3C http://www.w3.org/TR/xmlenc-core/

Page 3: XML Signature

XML-Signature

• A joint standard by IETF and W3C for digitally signing all of an XML document, part of an XML document or even an external object.

• XML Signature applies to any resource addressable by an URI – including non-xml content.

• First security standard to reach recommendation status

• WS-Security, XKMS, SAML all depend on XML Signature

Page 4: XML Signature

XML-Signature

• Multiple XML Signatures can be able to exist over the static content of a web resource.

Page 5: XML Signature

XML-Signature

<Signature xmlns=“…../2000/09/xmldsig#”>

<SignedInfo /> <SignatureValue /> <KeyInfo /> <Object /> </Signature>

Page 6: XML Signature

QUESTION 1

What do we actually sign with an XML Signature ?

Page 7: XML Signature

XML-Signature - Types

– Enveloping Signature– Enveloped Signature– Detached Signature

Page 8: XML Signature

XML-Signature - Enveloping

- Wraps item that is being signed within the <Signature> element

- <Reference> element points to an element within the <Signature> element

Signature

Page 9: XML Signature

XML-Signature - Enveloping<Signature> <SignedInfo> <Reference URI=“#101” /> </SignedInfo> <SignatureValue>…. </SignatureValue> <KeyInfo>…. </KeyInfo> <Object> <SignedItem id=“101”> …….. </SignedItem> </Object><Signature>

Signature

Page 10: XML Signature

XML-Signature - Enveloping

Signature

<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"><ds:SignedInfo>

<ds:CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"></ds:CanonicalizationMethod><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#dsa-sha1"></ds:SignatureMethod><ds:Reference URI="#TheFirstObject">

<ds:Transforms><ds:Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"></ds:Transform>

</ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></ds:DigestMethod><ds:DigestValue>ipbs0UyafkdRIcfIo9zyZLce+CE=</ds:DigestValue>

</ds:Reference></ds:SignedInfo><ds:SignatureValue>BSChZzMdH1kHVbKL+EyNorZXcEZ9ekL+cf/VW8ejhItfZoXOZQVNnw==</ds:SignatureValue><ds:KeyInfo> ... </ds:KeyInfo><ds:Object Id="TheFirstObject">

<InsideObject>A text in a box</InsideObject></ds:Object>

</ds:Signature>

Page 11: XML Signature

XML-Signature - Enveloped

- <Reference> element points to a parent element outside the <Signature> element

Signed XML Content

Signature

Page 12: XML Signature

XML-Signature - Enveloped<SignedItem id=“101”><SignedElement1>Text</SignedElement1><Signature> <SignedInfo> <Reference URI=“#101” /> </SignedInfo> <SignatureValue>…. </SignatureValue> <KeyInfo>…. </KeyInfo><Signature></SignedItem>

Signature

Page 13: XML Signature

XML-Signature - Enveloped

Signature

<apache:RootElement xmlns:apache="http://www.apache.org/ns/#app1" xmlns:foo="http://example.org/#foo">Some simple text <Signature xmlns="http://www.w3.org/2000/09/xmldsig#"> <SignedInfo> <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"></CanonicalizationMethod>

<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#dsa-sha1"></SignatureMethod><Reference URI="">

<Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"></Transform><Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"></Transform>

</Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></DigestMethod><DigestValue>f+pDsT3LzyKV9Sg6rdK5bBrQlbo=</DigestValue>

</Reference></SignedInfo><SignatureValue>QNoLqAc0KYDmomJA3LvXhCf6vpuN/wh9R4y42QylvJCko9gRDhpHAA==</SignatureValue><KeyInfo>...</KeyInfo>

</Signature></apache:RootElement>

Page 14: XML Signature

XML-Signature - Detached

- Points to an XML element or binary file out side the <Signature> elements hierarchy

- <Reference> element points neither a child nor a parent

- Can point to an element within the same document or to another resource completely outside the current XML document.

Signature

Page 15: XML Signature

XML-Signature - Detached

Signed XML Content

Signature

Page 16: XML Signature

QUESTION 2

Which signature type is used in WS-Security?

Page 17: XML Signature

QUESTION 3

Provide a practical example for enveloped signature ? And why it’s needed there ?

Page 18: XML Signature

XML-Signature

<Signature xmlns=“…../2000/09/xmldsig#”>

<SignedInfo /> <SignatureValue /> <KeyInfo /> <Object /> </Signature>

Page 19: XML Signature

XML-Signature - <SignedInfo /><SignedInfo> <CanonicalizationMethod /> <SignatureMethod /> <Reference URI > <Transforms /> <DigestMethd /> <DigestValue /> </Reference></SignedInfo>

Page 20: XML Signature

XML-Signature - <SignedInfo /><SignedInfo> <CanonicalizationMethod /> <SignatureMethod /> <Reference URI > <Transforms /> <DigestMethd /> <DigestValue /> </Reference></SignedInfo>

Page 21: XML Signature

<CanonicalizationMethod />

XML syntax permits a number of options (e.g., which form of empty elements to use, whether

to use single or double quotes for attribute values, the order of attributes in a start tag,

places where white space is considered insignificant, etc.), it is quite easy to create

documents that are physically different and yet logically equivalent.

Page 22: XML Signature

<CanonicalizationMethod />

The purpose of Canonical XML is to define an algorithm by which a particular physical

representation of an XML document can be reliably and repeatedly reduced to its canonical

(simplest) form. When the same algorithm is applied to physically different representations to produce their canonical forms, documents can be

compared at this logical level.

Page 23: XML Signature

<CanonicalizationMethod />

• Canonical XML (or Inclusive XML Canonicalization)(XMLC14N)

• Exclusive XML Canonicalization(EXCC14N)

Page 24: XML Signature

<CanonicalizationMethod />

The Canonical XML is used for XML where the context doesn't change while the

Exclusive XML was designed for canonicalization where the context might

change.

Page 25: XML Signature

XML-Signature (Example)

Signature

<apache:RootElement xmlns:apache="http://www.apache.org/ns/#app1" xmlns:foo="http://example.org/#foo">Some simple text <Signature xmlns="http://www.w3.org/2000/09/xmldsig#"> <SignedInfo> <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"></CanonicalizationMethod>

<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#dsa-sha1"></SignatureMethod><Reference URI="">

<Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"></Transform><Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"></Transform>

</Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></DigestMethod><DigestValue>f+pDsT3LzyKV9Sg6rdK5bBrQlbo=</DigestValue>

</Reference></SignedInfo><SignatureValue>QNoLqAc0KYDmomJA3LvXhCf6vpuN/wh9R4y42QylvJCko9gRDhpHAA==</SignatureValue><KeyInfo>...</KeyInfo>

</Signature></apache:RootElement>

Page 26: XML Signature

QUESTION 4

How about JSON ? Can there be multiple physical representations of the same logical

JSON document ?

Page 27: XML Signature

QUESTION 5

What are the differences between Inclusive Canonicalization and Exclusive Canonicalization.

Page 28: XML Signature

XML-Signature - <SignedInfo /><SignedInfo> <CanonicalizationMethod /> <SignatureMethod /> <Reference URI > <Transforms /> <DigestMethd /> <DigestValue /> </Reference></SignedInfo>

Page 29: XML Signature

<SignatureMethod />

The SignatureMethod is the algorithm that is used to convert the canonicalized SignedInfo

into the SignatureValue.

Page 30: XML Signature

<SignatureMethod />

- http://www.w3.org/2000/09/xmldsig#dsa-sha1

- http://www.w3.org/2000/09/xmldsig#rsa-sha1

- http://www.w3.org/2000/09/xmldsig#hmac-sha1

Page 31: XML Signature

QUESTION 6

What are the differences between RSA and DSA ?

Page 32: XML Signature

QUESTION 7

Would HMAC-SHA1 provide both the integrity of a message and the non-repudiation ?

Page 33: XML Signature

XML-Signature (Example)

Signature

<apache:RootElement xmlns:apache="http://www.apache.org/ns/#app1" xmlns:foo="http://example.org/#foo">Some simple text <Signature xmlns="http://www.w3.org/2000/09/xmldsig#"> <SignedInfo> <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"></CanonicalizationMethod>

<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#dsa-sha1"></SignatureMethod><Reference URI="">

<Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"></Transform><Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"></Transform>

</Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></DigestMethod><DigestValue>f+pDsT3LzyKV9Sg6rdK5bBrQlbo=</DigestValue>

</Reference></SignedInfo><SignatureValue>QNoLqAc0KYDmomJA3LvXhCf6vpuN/wh9R4y42QylvJCko9gRDhpHAA==</SignatureValue><KeyInfo>...</KeyInfo>

</Signature></apache:RootElement>

Page 34: XML Signature

XML-Signature - <SignedInfo /><SignedInfo> <CanonicalizationMethod /> <SignatureMethod /> <Reference URI > <Transforms /> <DigestMethd /> <DigestValue /> </Reference></SignedInfo>

Page 35: XML Signature

<Reference/>

Points to the elements which are being signed. Any element inside the same XML document

starts from “#”.

Page 36: XML Signature

XML-Signature (Example-1)

Signature

<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"><ds:SignedInfo>

<ds:CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"></ds:CanonicalizationMethod><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#dsa-sha1"></ds:SignatureMethod><ds:Reference URI="#TheFirstObject">

<ds:Transforms><ds:Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"></ds:Transform>

</ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></ds:DigestMethod><ds:DigestValue>ipbs0UyafkdRIcfIo9zyZLce+CE=</ds:DigestValue>

</ds:Reference></ds:SignedInfo><ds:SignatureValue>BSChZzMdH1kHVbKL+EyNorZXcEZ9ekL+cf/VW8ejhItfZoXOZQVNnw==</ds:SignatureValue><ds:KeyInfo> ... </ds:KeyInfo><ds:Object Id="TheFirstObject">

<InsideObject>A text in a box</InsideObject></ds:Object>

</ds:Signature>

Page 37: XML Signature

XML-Signature (Example-2)

Signature

<apache:RootElement xmlns:apache="http://www.apache.org/ns/#app1" xmlns:foo="http://example.org/#foo">Some simple text <Signature xmlns="http://www.w3.org/2000/09/xmldsig#"> <SignedInfo> <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"></CanonicalizationMethod>

<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#dsa-sha1"></SignatureMethod><Reference URI="">

<Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"></Transform><Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"></Transform>

</Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></DigestMethod><DigestValue>f+pDsT3LzyKV9Sg6rdK5bBrQlbo=</DigestValue>

</Reference></SignedInfo><SignatureValue>QNoLqAc0KYDmomJA3LvXhCf6vpuN/wh9R4y42QylvJCko9gRDhpHAA==</SignatureValue><KeyInfo>...</KeyInfo>

</Signature></apache:RootElement>

Page 38: XML Signature

QUESTION 8

How do we reference an XML element in an external XML document ?

Page 39: XML Signature

XML-Signature - <Reference/><SignedInfo> <CanonicalizationMethod /> <SignatureMethod /> <Reference URI > <Transforms /> <DigestMethd /> <DigestValue /> </Reference></SignedInfo>

Page 40: XML Signature

<Transforms/>- <Transforms/> receive the results of

dereferencing the <Reference URI=“”> and alter the result in some way.

- A simple <Transform> can be an Xpath statement that causes the signature to apply only to a part of an XML document.

- Multiple transforms can appear under a <Reference> working in a pipe-line fashion.

- <Transform Algorithm=“” />

Page 41: XML Signature

QUESTION 9

What is the difference between CanonicalizationMethod and the Transforms ?

Page 42: XML Signature

XML Signature spec defines five Transforms

1. Canonicalization

2. Base-64

3. XPath Filtering

4. Enveloped Signature Transform

5. XSLT Transform

<Transforms/>

Page 43: XML Signature

- Normalize the XML, so that regardless of physical inconsistencies, two logically equivalent XML documents will become physically bit to bit to equivalent.

Canonicalization

<Order><Items>

<item number=100></item><item number=101></item>

</Items></Order>

<Order><Items>

<item number=100/><item number=101/>

</Items></Order>

<Transforms/>

Page 44: XML Signature

- Maps binary data into text- http://www.w3.org/2000/09/xmldsig#base64

Base-64

<Transforms/>

Page 45: XML Signature

- Commonly used when we want to sign just a fragment of an XML document.

- http://www.w3.org/TR/1999/REC-xpath-19991116

XPath Filtering

<Transforms/>

Page 46: XML Signature

- Commonly used in Enveloped Signatures where the parent element is to be signed.

- Need to remove the Signature element from the element being signed before validation.

http://www.w3.org/2000/09/xmldsig#enveloped-signature

Enveloped Signature Transform

<Transforms/>

Page 47: XML Signature

QUESTION 10

Provide an example for Enveloped Signature Transformation and explain why its needed?

Page 48: XML Signature

- A good practice is to sign what actually the signer sees.- Used to sign XML documents when an XSL is involved. - http://www.w3.org/TR/1999/REC-xslt-19991116

XSLT Transform

<Transforms/>

Page 49: XML Signature

XML-Signature - <Reference/><SignedInfo> <CanonicalizationMethod /> <SignatureMethod /> <Reference URI > <Transforms /> <DigestMethd /> <DigestValue /> </Reference></SignedInfo>

Page 50: XML Signature

<DigestMethod/>

- Algorithm to calculate the digest of the element/resource pointed by the <Reference URI=“”>

- <DigestMethod Algorithm=http://www.w3.org/2000/09/xmldsig#sha1 />

Page 51: XML Signature

QUESTION 11

Explain two digest methods with similarities and differences.

Page 52: XML Signature

<DigestValue/>

- Contains Base-64 encoded value of the digest

<DigestValue>f+pDsT3LzyKV9Sg6rdK5bBrQlbo=</DigestValue>

Page 53: XML Signature

QUESTION 12

Why do we have to base64 encode the digest value ?

Page 54: XML Signature

XML-Signature

<Signature xmlns=“…../2000/09/xmldsig#”>

<SignedInfo /> <SignatureValue /> <KeyInfo /> <Object /> </Signature>

Page 55: XML Signature

<SignatureValue/>

The Base-64 resulting value of encrypting the digest of the <SignedInfo/> element.

Page 56: XML Signature

QUESTION 13

Where do we specify the digest method to create the digest of the SignedInfo ?

Page 57: XML Signature

XML-Signature

<Signature xmlns=“…../2000/09/xmldsig#”>

<SignedInfo /> <SignatureValue /> <KeyInfo /> <Object /> </Signature>

Page 58: XML Signature

<KeyInfo>

This is an optional element in the XML Signature, if no KeyInfo – it is expected that we what the

validation key is.

Page 59: XML Signature

<KeyInfo>

<KeyInfo> <KeyName />

<KeyValue /> <RetrievalMethod /> <X509Data /> <PGPData /> <SPKIData />

</KeyInfo>

Page 60: XML Signature

<KeyName/>

A unique name to identify the associated key.

Page 61: XML Signature

<KeyInfo>

<KeyInfo> <KeyName />

<KeyValue /> <RetrievalMethod /> <X509Data /> <PGPData /> <SPKIData />

</KeyInfo>

Page 62: XML Signature

<KeyValue/>

Actual key it self embedded in XML.

Page 63: XML Signature

<KeyInfo>

<KeyInfo> <KeyName />

<KeyValue /> <RetrievalMethod /> <X509Data /> <PGPData /> <SPKIData />

</KeyInfo>

Page 64: XML Signature

<RetrievalMethod/>- Used to reference a key that is stored in a separate location.

- If multiple signatures use the same key, we can keep the KeyInfo structure in a standalone element with a unique ID and refer to using <RetrievalMethod/> of each <Signature>

- Either or both the ds:KeyName and RetrievalMethod could be used to identify the same key.

<KeyInfo>

<RetrievalMethod URI='#EK' "/>

<KeyName>Sally Doe</KeyName>

<KeyInfo>

Page 65: XML Signature

<KeyInfo>

<KeyInfo> <KeyName />

<KeyValue /> <RetrievalMethod /> <X509Data /> <PGPData /> <SPKIData />

</KeyInfo>

Page 66: XML Signature

<X509Data/>

- Provides either an identifier to look to look up an X509 certificate or the X509 certificate it self.

- A certificate chain can also be contained in X509Data

Page 67: XML Signature

<KeyInfo>

<KeyInfo> <KeyName />

<KeyValue /> <RetrievalMethod /> <X509Data /> <PGPData /> <SPKIData />

</KeyInfo>

Page 68: XML Signature

<PGPData/>

Can point to the PGP key or can contain the key it self.

Page 69: XML Signature

<KeyInfo>

<KeyInfo> <KeyName />

<KeyValue /> <RetrievalMethod /> <X509Data /> <PGPData /> <SPKIData />

</KeyInfo>

Page 70: XML Signature

<SPKIData/>

Similar to PGPData point to the key or contains key it self.

Page 71: XML Signature

XML-Signature

<Signature xmlns=“…../2000/09/xmldsig#”>

<SignedInfo /> <SignatureValue /> <KeyInfo /> <Object /> </Signature>

Page 72: XML Signature

<Object/>

- Can put anything you want.

- Typically includes one of the following three

1. XML fragment or a base-64 encoded binary object – Enveloping Signature

2. A <Manifest> element

3. A <SignatureProperties> element

Page 73: XML Signature

<Manifest/>

<Object>

<Manifest Id=“101”>

<Reference>…. </Reference>

<Reference> …. </Reference>

</Manifest>

</Object>

Page 74: XML Signature

<Manifest/>

- Contains a list of references

- <Reference> elements inside <SignedInfo> element must be validated in order to accept the signature a valid one.

- To validate or not to validate <Reference> elements inside <Manifest> element is up to the developer decide.

- Developers get more granular control over which <Reference> mater and which does not.

Page 75: XML Signature

<Manifest/>

<SignedInfo>

<Reference URI=“101”

Type=“"http://www.w3.org/2000/09/xmldsig#Manifest"”>

……

</Reference>

</SignedInfo>

Page 76: XML Signature

<SignatureProperties/>Provides a place to put name/value information about the signature it self.<Object>

<SignatureProperties>

<SignatureProperty Id=“101” Target=“#100”>

<timestamp xmlns=“”>

<date>….</date>

<time>….</time>

</timestamp>

</SignatureProperty>

</SignatureProperties>

</Object>

Page 77: XML Signature

<Signature Id=“100”>

<SignedInfo>

<Reference URI=“101”

Type=“" http://www.w3.org/2000/09/xmldsig#SignatureProperties "”>

……

</Reference>

</SignedInfo>

</Signature>

<SignatureProperties/>

Page 78: XML Signature

XML-Signature Building Process

- Reference Generation- Signature Generation

Page 79: XML Signature

XML-Signature Ref. Generation1. Obtain the resource specified by the <Reference

URI=“” >2. Apply Transforms3. Calculate the digest for the final output from the

Transform algorithm, using the <DigestMethod>4. Create the <Reference> element including all it’s sub

elements by populating the <DigestValue>5. Perform the above actions to all the <Reference>

elements found inside <SignedInfo>

Page 80: XML Signature

XML-Signature Sig. Generation1. Create the <SignedInfo> element 2. Canonicalize <SignedInfo> element using the

algorithm specified under <CanonicalizationMethod>3. Create a hash for the out put of the canonicalization

using the <SignatureMethod> specified.4. Create the <SignatureValue> with the

<SignatureMethod> specified, against the canonicalized, hashed <SignedInfo>

5. Build the complete <Signature> element

Page 81: XML Signature

XML-Signature Validation Process

- Reference Validation- Signature Validation

Page 82: XML Signature

XML-Signature Ref. Validation1. Canonicalize the <SignedInfo> element based

on the <CanonicalizationMethod> element.2. For each <Reference> element do the following3. Get the resource pointed out by the

<Reference>4. Apply Transforms5. Create a hash using the <DigestMethod>6. Find the DigestValue and compare it with the

DigestValue returned.

Page 83: XML Signature

XML-Signature Sig. Validation1. Obtain the key used to sign the message

2. Create a hash of the canonicalized <SignedInfo>3. Using the verification key decrypt the

<SignatureValue>4. Compare the value from 3 with value from 2.

Page 84: XML Signature

lean . enterprise . middleware