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

Function decryptWithKey

service_provider.go:1933–1953  ·  view source on GitHub ↗

decryptWithKey decrypts encryptedDataEl, the EncryptedData child of encryptedEl, with decryptionKey. If encryptedKeyEl is not nil, it is an EncryptedKey, beside the EncryptedData or inside its KeyInfo, that holds the content key wrapped with decryptionKey.

(decryptionKey interface{}, encryptedEl, encryptedKeyEl, encryptedDataEl *etree.Element)

Source from the content-addressed store, hash-verified

1931// EncryptedKey, beside the EncryptedData or inside its KeyInfo, that holds
1932// the content key wrapped with decryptionKey.
1933func decryptWithKey(decryptionKey interface{}, encryptedEl, encryptedKeyEl, encryptedDataEl *etree.Element) ([]byte, error) {
1934 if encryptedKeyEl == nil {
1935 return xmlenc.Decrypt(decryptionKey, encryptedDataEl)
1936 }
1937 key, err := xmlenc.Decrypt(decryptionKey, encryptedKeyEl)
1938 if err != nil {
1939 if encryptedKeyEl.Parent() == encryptedEl {
1940 return nil, classify(fmt.Errorf("failed to decrypt key from response: %w", err), ErrDecryptionFailed)
1941 }
1942 return nil, err
1943 }
1944 // The block ciphers unwrap an EncryptedKey in KeyInfo themselves, so
1945 // hand them the EncryptedData without one, now that the key is known.
1946 if encryptedDataEl.FindElement("./KeyInfo/EncryptedKey") != nil {
1947 encryptedDataEl = encryptedDataEl.Copy()
1948 for _, el := range encryptedDataEl.FindElements("./KeyInfo/EncryptedKey") {
1949 el.Parent().RemoveChild(el)
1950 }
1951 }
1952 return xmlenc.Decrypt(key, encryptedDataEl)
1953}
1954
1955func (sp *ServiceProvider) parseAssertion(assertionEl *etree.Element, possibleRequestIDs []string, now time.Time, signatureRequirement signatureRequirement) (*Assertion, error) {
1956 return sp.parseReceivedAssertion(assertionEl, assertionEl, possibleRequestIDs, now, signatureRequirement)

Callers 1

decryptWithKeysFunction · 0.85

Calls 2

DecryptFunction · 0.92
classifyFunction · 0.85

Tested by

no test coverage detected