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

Method attributeQueryAssertions

service_provider_attribute_query.go:419–466  ·  view source on GitHub ↗

attributeQueryAssertions returns the assertions of responseEl, decrypting the encrypted ones. Each must be valid for query; if signatureRequired, each must also be signed by the attribute authority. receivedEl is the Response as received (see receivedChildren), on whose plaintext assertions their si

(responseEl, receivedEl *etree.Element, query *AttributeQuery, now time.Time, signatureRequired bool)

Source from the content-addressed store, hash-verified

417// Response as received (see receivedChildren), on whose plaintext
418// assertions their signatures are checked.
419func (sp *ServiceProvider) attributeQueryAssertions(responseEl, receivedEl *etree.Element, query *AttributeQuery, now time.Time, signatureRequired bool) ([]Assertion, error) {
420 var assertionEls []*etree.Element
421
422 encryptedAssertionEls, err := findChildren(responseEl, "urn:oasis:names:tc:SAML:2.0:assertion", "EncryptedAssertion")
423 if err != nil {
424 return nil, err
425 }
426 plaintextAssertionEls, receivedAssertionEls, err := receivedChildren(responseEl, receivedEl, "urn:oasis:names:tc:SAML:2.0:assertion", "Assertion")
427 if err != nil {
428 return nil, err
429 }
430
431 // As for a login response: each assertion of an unsigned Response is
432 // decrypted and its signature checked, which costs more per assertion,
433 // so an unsigned Response may carry only one. Count before decrypting.
434 if signatureRequired {
435 if n := len(encryptedAssertionEls) + len(plaintextAssertionEls); n > 1 {
436 return nil, classify(fmt.Errorf("an unsigned Response must contain exactly one Assertion or EncryptedAssertion, not %d", n), ErrMalformedMessage)
437 }
438 }
439
440 for _, encryptedAssertionEl := range encryptedAssertionEls {
441 if err := sp.checkCBCIntegrity(encryptedAssertionEl, !signatureRequired); err != nil {
442 return nil, err
443 }
444 assertionEl, err := sp.decryptElement(encryptedAssertionEl)
445 if err != nil {
446 return nil, classify(fmt.Errorf("failed to decrypt EncryptedAssertion: %w", err), ErrDecryptionFailed)
447 }
448 if assertionEl.NamespaceURI() != "urn:oasis:names:tc:SAML:2.0:assertion" || assertionEl.Tag != "Assertion" {
449 return nil, classify(errors.New("the EncryptedAssertion does not hold an Assertion"), ErrMalformedMessage)
450 }
451 assertionEls = append(assertionEls, assertionEl)
452 }
453 // A decrypted assertion is its own received form.
454 receivedEls := append(append([]*etree.Element{}, assertionEls...), receivedAssertionEls...)
455 assertionEls = append(assertionEls, plaintextAssertionEls...)
456
457 assertions := make([]Assertion, 0, len(assertionEls))
458 for i, assertionEl := range assertionEls {
459 assertion, err := sp.attributeQueryAssertion(assertionEl, receivedEls[i], query, now, signatureRequired)
460 if err != nil {
461 return nil, err
462 }
463 assertions = append(assertions, *assertion)
464 }
465 return assertions, nil
466}
467
468// attributeQueryAssertion parses and validates assertionEl. receivedEl is
469// the assertion as received (see receivedChildren), on which its signature

Callers 1

Calls 7

checkCBCIntegrityMethod · 0.95
decryptElementMethod · 0.95
findChildrenFunction · 0.85
receivedChildrenFunction · 0.85
classifyFunction · 0.85
NewMethod · 0.65

Tested by

no test coverage detected