provisioners.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package authority
  2. import (
  3. "crypto/x509"
  4. "github.com/smallstep/certificates/authority/provisioner"
  5. "github.com/smallstep/certificates/errs"
  6. )
  7. // GetEncryptedKey returns the JWE key corresponding to the given kid argument.
  8. func (a *Authority) GetEncryptedKey(kid string) (string, error) {
  9. key, ok := a.provisioners.LoadEncryptedKey(kid)
  10. if !ok {
  11. return "", errs.NotFound("encrypted key with kid %s was not found", kid)
  12. }
  13. return key, nil
  14. }
  15. // GetProvisioners returns a map listing each provisioner and the JWK Key Set
  16. // with their public keys.
  17. func (a *Authority) GetProvisioners(cursor string, limit int) (provisioner.List, string, error) {
  18. provisioners, nextCursor := a.provisioners.Find(cursor, limit)
  19. return provisioners, nextCursor, nil
  20. }
  21. // LoadProvisionerByCertificate returns an interface to the provisioner that
  22. // provisioned the certificate.
  23. func (a *Authority) LoadProvisionerByCertificate(crt *x509.Certificate) (provisioner.Interface, error) {
  24. p, ok := a.provisioners.LoadByCertificate(crt)
  25. if !ok {
  26. return nil, errs.NotFound("provisioner not found")
  27. }
  28. return p, nil
  29. }
  30. // LoadProvisionerByID returns an interface to the provisioner with the given ID.
  31. func (a *Authority) LoadProvisionerByID(id string) (provisioner.Interface, error) {
  32. p, ok := a.provisioners.Load(id)
  33. if !ok {
  34. return nil, errs.NotFound("provisioner not found")
  35. }
  36. return p, nil
  37. }