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

Function signMetadata

metadata.go:293–320  ·  view source on GitHub ↗

signMetadata returns ed as an XML element carrying an enveloped signature made with signingContext (saml-metadata-2.0-os §3). The signature references the EntityDescriptor by its ID attribute; one is generated if ed does not have one. ed itself is not modified. The returned element must be serializ

(ed *EntityDescriptor, signingContext *dsig.SigningContext)

Source from the content-addressed store, hash-verified

291// element must be serialized as-is: re-indenting it changes the signed
292// content.
293func signMetadata(ed *EntityDescriptor, signingContext *dsig.SigningContext) (*etree.Element, error) {
294 unsigned := *ed
295 unsigned.Signature = nil
296 if unsigned.ID == "" {
297 unsigned.ID = fmt.Sprintf("id-%x", randomBytes(20))
298 }
299
300 buf, err := xml.Marshal(unsigned)
301 if err != nil {
302 return nil, err
303 }
304 doc := etree.NewDocument()
305 if err := doc.ReadFromBytes(buf); err != nil {
306 return nil, err
307 }
308
309 el := doc.Root()
310 sigEl, err := signingContext.ConstructSignature(el, true)
311 if err != nil {
312 return nil, err
313 }
314
315 // The metadata schema requires ds:Signature to be the first child of
316 // EntityDescriptor. The enveloped-signature transform removes it before
317 // the digest is computed, so its position does not affect validity.
318 el.InsertChildAt(0, sigEl)
319 return el, nil
320}
321
322// defaultSignatureMethod returns the signature method used when none is
323// configured: SHA-256 with ECDSA for an ECDSA key, and with RSA otherwise.

Calls 1

randomBytesFunction · 0.70