MCPcopy Create free account
hub / github.com/crewjam/saml / checkSignatureReference

Function checkSignatureReference

signature_reference.go:23–60  ·  view source on GitHub ↗

checkSignatureReference checks that the enveloped ds:Signature of el (its direct child) follows the reference profile of saml-core-2.0-os §5.4.2 and saml-metadata-2.0-os §3.1: "Signatures MUST contain a single containing a same-document reference to the ID attribute value of the root

(el *etree.Element)

Source from the content-addressed store, hash-verified

21// ErrInvalidSignature, and a signed element without an ID also matches
22// ErrMissingElement.
23func checkSignatureReference(el *etree.Element) error {
24 sigEl, err := findChild(el, dsig.Namespace, "Signature")
25 if err != nil {
26 return err
27 }
28 if sigEl == nil {
29 return errSignatureElementNotPresent
30 }
31 var refs []*etree.Element
32 if signedInfo, err := findChild(sigEl, dsig.Namespace, "SignedInfo"); err != nil {
33 return err
34 } else if signedInfo != nil {
35 if refs, err = findChildren(signedInfo, dsig.Namespace, "Reference"); err != nil {
36 return err
37 }
38 }
39 if len(refs) != 1 {
40 return classify(fmt.Errorf("signature must contain exactly one Reference, not %d", len(refs)), ErrInvalidSignature)
41 }
42 id := el.SelectAttrValue("ID", "")
43 if id == "" {
44 return classify(fmt.Errorf("signed %s has no ID for its signature to reference", el.Tag), ErrInvalidSignature, ErrMissingElement)
45 }
46 // Look at every attribute named URI, whatever its prefix, so that a
47 // prefixed one cannot stand in for (or next to) the real one.
48 var uris []string
49 unprefixed := true
50 for _, attr := range refs[0].Attr {
51 if attr.Key == "URI" {
52 uris = append(uris, attr.Value)
53 unprefixed = unprefixed && attr.Space == ""
54 }
55 }
56 if len(uris) != 1 || !unprefixed || uris[0] != "#"+id {
57 return classify(fmt.Errorf("signature Reference URI must be %q, not %q", "#"+id, uris), ErrInvalidSignature)
58 }
59 return nil
60}

Callers 2

verifiedEnvelopedElementFunction · 0.85
verifySignedElementMethod · 0.85

Calls 3

findChildFunction · 0.85
findChildrenFunction · 0.85
classifyFunction · 0.85

Tested by

no test coverage detected