certificates/authority/provisioners.go

48 lines
1.5 KiB
Go
Raw Permalink Normal View History

2018-10-05 21:48:36 +00:00
package authority
import (
"crypto/x509"
2018-10-05 21:48:36 +00:00
"net/http"
"github.com/pkg/errors"
"github.com/smallstep/certificates/authority/provisioner"
2018-10-05 21:48:36 +00:00
)
// GetEncryptedKey returns the JWE key corresponding to the given kid argument.
func (a *Authority) GetEncryptedKey(kid string) (string, error) {
key, ok := a.provisioners.LoadEncryptedKey(kid)
2018-10-05 21:48:36 +00:00
if !ok {
return "", &apiError{errors.Errorf("encrypted key with kid %s was not found", kid),
http.StatusNotFound, apiCtx{}}
2018-10-05 21:48:36 +00:00
}
return key, nil
}
// GetProvisioners returns a map listing each provisioner and the JWK Key Set
// with their public keys.
2019-03-07 21:07:39 +00:00
func (a *Authority) GetProvisioners(cursor string, limit int) (provisioner.List, string, error) {
provisioners, nextCursor := a.provisioners.Find(cursor, limit)
2018-10-26 01:53:13 +00:00
return provisioners, nextCursor, nil
2018-10-05 21:48:36 +00:00
}
// LoadProvisionerByCertificate returns an interface to the provisioner that
// provisioned the certificate.
func (a *Authority) LoadProvisionerByCertificate(crt *x509.Certificate) (provisioner.Interface, error) {
p, ok := a.provisioners.LoadByCertificate(crt)
if !ok {
return nil, &apiError{errors.Errorf("provisioner not found"),
http.StatusNotFound, apiCtx{}}
}
return p, nil
}
2019-05-27 00:41:10 +00:00
// LoadProvisionerByID returns an interface to the provisioner with the given ID.
func (a *Authority) LoadProvisionerByID(id string) (provisioner.Interface, error) {
p, ok := a.provisioners.Load(id)
if !ok {
return nil, &apiError{errors.Errorf("provisioner not found"),
http.StatusNotFound, apiCtx{}}
}
return p, nil
}