decryptIdentifier decrypts encryptedID, a saml:EncryptedID element, with decrypt, which returns the root element of the plaintext. It returns the saml:NameID it holds or, if allowBaseID is true, the saml:BaseID it holds. Anything else is rejected.
(encryptedID *etree.Element, decrypt func(*etree.Element) (*etree.Element, error), allowBaseID bool)
| 30 | // saml:NameID it holds or, if allowBaseID is true, the saml:BaseID it holds. |
| 31 | // Anything else is rejected. |
| 32 | func decryptIdentifier(encryptedID *etree.Element, decrypt func(*etree.Element) (*etree.Element, error), allowBaseID bool) (*NameID, *etree.Element, error) { |
| 33 | plaintext, err := decrypt(encryptedID) |
| 34 | if err != nil { |
| 35 | return nil, nil, classify(fmt.Errorf("cannot decrypt EncryptedID: %w", err), ErrDecryptionFailed) |
| 36 | } |
| 37 | if plaintext.NamespaceURI() == samlAssertionNamespace { |
| 38 | switch { |
| 39 | case plaintext.Tag == "NameID": |
| 40 | var nameID NameID |
| 41 | if err := unmarshalElement(plaintext, &nameID); err != nil { |
| 42 | return nil, nil, err |
| 43 | } |
| 44 | return &nameID, nil, nil |
| 45 | case plaintext.Tag == "BaseID" && allowBaseID: |
| 46 | return nil, plaintext, nil |
| 47 | } |
| 48 | } |
| 49 | supported := "saml:NameID" |
| 50 | if allowBaseID { |
| 51 | supported = "saml:NameID and saml:BaseID are" |
| 52 | } else { |
| 53 | supported += " is" |
| 54 | } |
| 55 | return nil, nil, classify(fmt.Errorf("EncryptedID holds a %s element, only %s supported", plaintext.FullTag(), supported), ErrUnsupported) |
| 56 | } |
| 57 | |
| 58 | // resolveLogoutRequestNameID makes sure req identifies the principal with |
| 59 | // exactly one of BaseID, NameID and EncryptedID, as saml-core-2.0-os §3.7.1 |
no test coverage detected