Skip to content

Commit d396ec6

Browse files
Merge pull request #39 from aykevl/fixes
Be more flexible in the accepted XML
2 parents 6f318b2 + 44c0b4b commit d396ec6

File tree

3 files changed

+13
-21
lines changed

3 files changed

+13
-21
lines changed

sign.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,11 @@ func (ctx *SigningContext) constructSignedInfo(el *etree.Element, enveloped bool
9292

9393
dataId := el.SelectAttrValue(ctx.IdAttribute, "")
9494
if dataId == "" {
95-
return nil, errors.New("Missing data ID")
95+
reference.CreateAttr(URIAttr, "")
96+
} else {
97+
reference.CreateAttr(URIAttr, "#"+dataId)
9698
}
9799

98-
reference.CreateAttr(URIAttr, "#"+dataId)
99100

100101
// /SignedInfo/Reference/Transforms
101102
transforms := ctx.createNamespacedElement(reference, TransformsTag)

sign_test.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,6 @@ func TestSignErrors(t *testing.T) {
9696

9797
_, err := ctx.SignEnveloped(authnRequest)
9898
require.Error(t, err)
99-
100-
randomKeyStore = RandomKeyStoreForTest()
101-
ctx = NewDefaultSigningContext(randomKeyStore)
102-
103-
authnRequest = &etree.Element{
104-
Space: "samlp",
105-
Tag: "AuthnRequest",
106-
}
107-
108-
_, err = ctx.SignEnveloped(authnRequest)
109-
require.Error(t, err)
11099
}
111100

112101
func TestSignNonDefaultID(t *testing.T) {

validate.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -234,16 +234,17 @@ func (ctx *ValidationContext) verifySignedInfo(sig *types.Signature, canonicaliz
234234
}
235235

236236
func (ctx *ValidationContext) validateSignature(el *etree.Element, sig *types.Signature, cert *x509.Certificate) (*etree.Element, error) {
237-
idAttr := el.SelectAttr(ctx.IdAttribute)
238-
if idAttr == nil || idAttr.Value == "" {
239-
return nil, errors.New("Missing ID attribute")
237+
idAttrEl := el.SelectAttr(ctx.IdAttribute)
238+
idAttr := ""
239+
if idAttrEl != nil {
240+
idAttr = idAttrEl.Value
240241
}
241242

242243
var ref *types.Reference
243244

244245
// Find the first reference which references the top-level element
245246
for _, _ref := range sig.SignedInfo.References {
246-
if _ref.URI == "" || _ref.URI[1:] == idAttr.Value {
247+
if _ref.URI == "" || _ref.URI[1:] == idAttr {
247248
ref = &_ref
248249
}
249250
}
@@ -318,9 +319,10 @@ func validateShape(signatureEl *etree.Element) error {
318319

319320
// findSignature searches for a Signature element referencing the passed root element.
320321
func (ctx *ValidationContext) findSignature(root *etree.Element) (*types.Signature, error) {
321-
idAttr := root.SelectAttr(ctx.IdAttribute)
322-
if idAttr == nil || idAttr.Value == "" {
323-
return nil, errors.New("Missing ID attribute")
322+
idAttrEl := root.SelectAttr(ctx.IdAttribute)
323+
idAttr := ""
324+
if idAttrEl != nil {
325+
idAttr = idAttrEl.Value
324326
}
325327

326328
var sig *types.Signature
@@ -403,7 +405,7 @@ func (ctx *ValidationContext) findSignature(root *etree.Element) (*types.Signatu
403405
// Traverse references in the signature to determine whether it has at least
404406
// one reference to the top level element. If so, conclude the search.
405407
for _, ref := range _sig.SignedInfo.References {
406-
if ref.URI == "" || ref.URI[1:] == idAttr.Value {
408+
if ref.URI == "" || ref.URI[1:] == idAttr {
407409
sig = _sig
408410
return etreeutils.ErrTraversalHalted
409411
}

0 commit comments

Comments
 (0)