2018-10-05 21:48:36 +00:00
|
|
|
package authority
|
|
|
|
|
|
|
|
import (
|
2019-03-05 08:07:13 +00:00
|
|
|
"crypto/x509"
|
2018-10-05 21:48:36 +00:00
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2019-03-06 23:00:23 +00:00
|
|
|
"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) {
|
2019-03-06 23:00:23 +00:00
|
|
|
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),
|
2019-07-29 18:56:14 +00:00
|
|
|
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) {
|
2019-03-06 23:00:23 +00:00
|
|
|
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
|
|
|
}
|
2019-03-05 08:07:13 +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"),
|
2019-07-29 18:56:14 +00:00
|
|
|
http.StatusNotFound, apiCtx{}}
|
2019-03-05 08:07:13 +00:00
|
|
|
}
|
|
|
|
return p, nil
|
|
|
|
}
|