provisioners.go 1.5 KB

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