Codebase list golang-github-russellhaering-goxmldsig / 5ddbb622-f2ef-41b9-b314-5e0ed3b9dccd/main
New upstream snapshot. Debian Janitor 2 years ago
6 changed file(s) with 50 addition(s) and 36 deletion(s). Raw diff Collapse all Expand all
0 arch:
1 - amd64
2 - ppc64le
3
04 language: go
15
26 go:
1010 type Canonicalizer interface {
1111 Canonicalize(el *etree.Element) ([]byte, error)
1212 Algorithm() AlgorithmID
13 }
14
15 type NullCanonicalizer struct {
16 }
17
18 func MakeNullCanonicalizer() Canonicalizer {
19 return &NullCanonicalizer{}
20 }
21
22 func (c *NullCanonicalizer) Algorithm() AlgorithmID {
23 return AlgorithmID("NULL")
24 }
25
26 func (c *NullCanonicalizer) Canonicalize(el *etree.Element) ([]byte, error) {
27 scope := make(map[string]struct{})
28 return canonicalSerialize(canonicalPrep(el, scope, false))
1329 }
1430
1531 type c14N10ExclusiveCanonicalizer struct {
4864 // Canonicalize transforms the input Element into a serialized XML document in canonical form.
4965 func (c *c14N11Canonicalizer) Canonicalize(el *etree.Element) ([]byte, error) {
5066 scope := make(map[string]struct{})
51 return canonicalSerialize(canonicalPrep(el, scope))
67 return canonicalSerialize(canonicalPrep(el, scope, true))
5268 }
5369
5470 func (c *c14N11Canonicalizer) Algorithm() AlgorithmID {
6581 // Canonicalize transforms the input Element into a serialized XML document in canonical form.
6682 func (c *c14N10RecCanonicalizer) Canonicalize(el *etree.Element) ([]byte, error) {
6783 scope := make(map[string]struct{})
68 return canonicalSerialize(canonicalPrep(el, scope))
84 return canonicalSerialize(canonicalPrep(el, scope, true))
6985 }
7086
7187 func (c *c14N10RecCanonicalizer) Algorithm() AlgorithmID {
8298 // Canonicalize transforms the input Element into a serialized XML document in canonical form.
8399 func (c *c14N10CommentCanonicalizer) Canonicalize(el *etree.Element) ([]byte, error) {
84100 scope := make(map[string]struct{})
85 return canonicalSerialize(canonicalPrep(el, scope))
101 return canonicalSerialize(canonicalPrep(el, scope, true))
86102 }
87103
88104 func (c *c14N10CommentCanonicalizer) Algorithm() AlgorithmID {
115131 //
116132 // TODO(russell_h): This is very similar to excCanonicalPrep - perhaps they should
117133 // be unified into one parameterized function?
118 func canonicalPrep(el *etree.Element, seenSoFar map[string]struct{}) *etree.Element {
134 func canonicalPrep(el *etree.Element, seenSoFar map[string]struct{}, strip bool) *etree.Element {
119135 _seenSoFar := make(map[string]struct{})
120136 for k, v := range seenSoFar {
121137 _seenSoFar[k] = v
140156 for i, token := range ne.Child {
141157 childElement, ok := token.(*etree.Element)
142158 if ok {
143 ne.Child[i] = canonicalPrep(childElement, _seenSoFar)
159 ne.Child[i] = canonicalPrep(childElement, _seenSoFar, strip)
144160 }
145161 }
146162
0 golang-github-russellhaering-goxmldsig (1.1.0+git20201210.1.3541f5e-1) UNRELEASED; urgency=low
1
2 * New upstream snapshot.
3
4 -- Debian Janitor <janitor@jelmer.uk> Thu, 10 Jun 2021 23:09:05 -0000
5
06 golang-github-russellhaering-goxmldsig (1.1.0-1) unstable; urgency=medium
17
28 * New upstream release (Closes: #971615)
9191
9292 dataId := el.SelectAttrValue(ctx.IdAttribute, "")
9393 if dataId == "" {
94 return nil, errors.New("Missing data ID")
95 }
96
97 reference.CreateAttr(URIAttr, "#"+dataId)
94 reference.CreateAttr(URIAttr, "")
95 } else {
96 reference.CreateAttr(URIAttr, "#"+dataId)
97 }
98
9899
99100 // /SignedInfo/Reference/Transforms
100101 transforms := ctx.createNamespacedElement(reference, TransformsTag)
9595
9696 _, err := ctx.SignEnveloped(authnRequest)
9797 require.Error(t, err)
98
99 randomKeyStore = RandomKeyStoreForTest()
100 ctx = NewDefaultSigningContext(randomKeyStore)
101
102 authnRequest = &etree.Element{
103 Space: "samlp",
104 Tag: "AuthnRequest",
105 }
106
107 _, err = ctx.SignEnveloped(authnRequest)
108 require.Error(t, err)
10998 }
11099
111100 func TestSignNonDefaultID(t *testing.T) {
110110 ref *types.Reference) (*etree.Element, Canonicalizer, error) {
111111 transforms := ref.Transforms.Transforms
112112
113 if len(transforms) != 2 {
114 return nil, nil, errors.New("Expected Enveloped and C14N transforms")
115 }
116
117113 // map the path to the passed signature relative to the passed root, in
118114 // order to enable removal of the signature by an enveloped signature
119115 // transform
156152 }
157153
158154 if canonicalizer == nil {
159 return nil, nil, errors.New("Expected canonicalization transform")
155 canonicalizer = MakeNullCanonicalizer()
160156 }
161157
162158 return el, canonicalizer, nil
233229 }
234230
235231 func (ctx *ValidationContext) validateSignature(el *etree.Element, sig *types.Signature, cert *x509.Certificate) (*etree.Element, error) {
236 idAttr := el.SelectAttr(ctx.IdAttribute)
237 if idAttr == nil || idAttr.Value == "" {
238 return nil, errors.New("Missing ID attribute")
232 idAttrEl := el.SelectAttr(ctx.IdAttribute)
233 idAttr := ""
234 if idAttrEl != nil {
235 idAttr = idAttrEl.Value
239236 }
240237
241238 var ref *types.Reference
242239
243240 // Find the first reference which references the top-level element
244241 for _, _ref := range sig.SignedInfo.References {
245 if _ref.URI == "" || _ref.URI[1:] == idAttr.Value {
242 if _ref.URI == "" || _ref.URI[1:] == idAttr {
246243 ref = &_ref
247244 }
248245 }
317314
318315 // findSignature searches for a Signature element referencing the passed root element.
319316 func (ctx *ValidationContext) findSignature(root *etree.Element) (*types.Signature, error) {
320 idAttr := root.SelectAttr(ctx.IdAttribute)
321 if idAttr == nil || idAttr.Value == "" {
322 return nil, errors.New("Missing ID attribute")
317 idAttrEl := root.SelectAttr(ctx.IdAttribute)
318 idAttr := ""
319 if idAttrEl != nil {
320 idAttr = idAttrEl.Value
323321 }
324322
325323 var sig *types.Signature
365363 canonicalSignedInfo = detachedSignedInfo
366364
367365 case CanonicalXML11AlgorithmId:
368 canonicalSignedInfo = canonicalPrep(detachedSignedInfo, map[string]struct{}{})
366 canonicalSignedInfo = canonicalPrep(detachedSignedInfo, map[string]struct{}{}, true)
369367
370368 case CanonicalXML10RecAlgorithmId:
371 canonicalSignedInfo = canonicalPrep(detachedSignedInfo, map[string]struct{}{})
369 canonicalSignedInfo = canonicalPrep(detachedSignedInfo, map[string]struct{}{}, true)
372370
373371 case CanonicalXML10CommentAlgorithmId:
374 canonicalSignedInfo = canonicalPrep(detachedSignedInfo, map[string]struct{}{})
372 canonicalSignedInfo = canonicalPrep(detachedSignedInfo, map[string]struct{}{}, true)
375373
376374 default:
377375 return fmt.Errorf("invalid CanonicalizationMethod on Signature: %s", c14NAlgorithm)
402400 // Traverse references in the signature to determine whether it has at least
403401 // one reference to the top level element. If so, conclude the search.
404402 for _, ref := range _sig.SignedInfo.References {
405 if ref.URI == "" || ref.URI[1:] == idAttr.Value {
403 if ref.URI == "" || ref.URI[1:] == idAttr {
406404 sig = _sig
407405 return etreeutils.ErrTraversalHalted
408406 }