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

Function encryptionKey

encrypted_id.go:161–185  ·  view source on GitHub ↗

encryptionKey returns the certificate to encrypt to from the KeyDescriptors of an entity's metadata, and the EncryptionMethods listed with it: the first certificate whose KeyDescriptor has use="encryption", or else the first one whose KeyDescriptor has no use. It returns os.ErrNotExist if there is n

(keyDescriptors []KeyDescriptor)

Source from the content-addressed store, hash-verified

159// or else the first one whose KeyDescriptor has no use. It returns
160// os.ErrNotExist if there is none.
161func encryptionKey(keyDescriptors []KeyDescriptor) (*x509.Certificate, []EncryptionMethod, error) {
162 for _, use := range []string{"encryption", ""} {
163 for _, keyDescriptor := range keyDescriptors {
164 if keyDescriptor.Use != use {
165 continue
166 }
167 for _, certificate := range keyDescriptor.KeyInfo.X509Data.X509Certificates {
168 certStr := whitespaceRegexp.ReplaceAllString(certificate.Data, "")
169 if certStr == "" {
170 continue
171 }
172 certBytes, err := base64.StdEncoding.DecodeString(certStr)
173 if err != nil {
174 return nil, nil, classify(fmt.Errorf("cannot decode certificate base64: %w", err), ErrInvalidCertificate)
175 }
176 cert, err := x509.ParseCertificate(certBytes)
177 if err != nil {
178 return nil, nil, classify(fmt.Errorf("cannot parse certificate: %w", err), ErrInvalidCertificate)
179 }
180 return cert, keyDescriptor.EncryptionMethods, nil
181 }
182 }
183 }
184 return nil, nil, os.ErrNotExist
185}
186
187var whitespaceRegexp = regexp.MustCompile(`\s+`)
188

Callers 5

encryptLogoutNameIDMethod · 0.85
MakeAssertionElMethod · 0.85
getSPEncryptionCertMethod · 0.85
spEncryptionMethodsFunction · 0.85
getIDPEncryptionCertMethod · 0.85

Calls 1

classifyFunction · 0.85

Tested by 1

spEncryptionMethodsFunction · 0.68