2019-05-27 00:41:10 +00:00
|
|
|
package provisioner
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"crypto/x509"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2019-12-20 21:30:05 +00:00
|
|
|
"github.com/smallstep/certificates/errs"
|
2019-05-27 00:41:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ACME is the acme provisioner type, an entity that can authorize the ACME
|
|
|
|
// provisioning flow.
|
|
|
|
type ACME struct {
|
2019-10-28 18:50:43 +00:00
|
|
|
*base
|
2019-05-27 00:41:10 +00:00
|
|
|
Type string `json:"type"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Claims *Claims `json:"claims,omitempty"`
|
|
|
|
claimer *Claimer
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetID returns the provisioner unique identifier.
|
|
|
|
func (p ACME) GetID() string {
|
|
|
|
return "acme/" + p.Name
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetTokenID returns the identifier of the token.
|
|
|
|
func (p *ACME) GetTokenID(ott string) (string, error) {
|
|
|
|
return "", errors.New("acme provisioner does not implement GetTokenID")
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetName returns the name of the provisioner.
|
|
|
|
func (p *ACME) GetName() string {
|
|
|
|
return p.Name
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetType returns the type of provisioner.
|
|
|
|
func (p *ACME) GetType() Type {
|
|
|
|
return TypeACME
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetEncryptedKey returns the base provisioner encrypted key if it's defined.
|
|
|
|
func (p *ACME) GetEncryptedKey() (string, string, bool) {
|
|
|
|
return "", "", false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init initializes and validates the fields of a JWK type.
|
|
|
|
func (p *ACME) Init(config Config) (err error) {
|
|
|
|
switch {
|
|
|
|
case p.Type == "":
|
|
|
|
return errors.New("provisioner type cannot be empty")
|
|
|
|
case p.Name == "":
|
|
|
|
return errors.New("provisioner name cannot be empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update claims with global ones
|
|
|
|
if p.claimer, err = NewClaimer(p.Claims, config.Claims); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-05-12 01:46:15 +00:00
|
|
|
// TODO: https://github.com/smallstep/certificates/issues/250
|
|
|
|
|
2019-05-27 00:41:10 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-10-28 18:50:43 +00:00
|
|
|
// AuthorizeSign does not do any validation, because all validation is handled
|
|
|
|
// in the ACME protocol. This method returns a list of modifiers / constraints
|
|
|
|
// on the resulting certificate.
|
|
|
|
func (p *ACME) AuthorizeSign(ctx context.Context, token string) ([]SignOption, error) {
|
2019-05-27 00:41:10 +00:00
|
|
|
return []SignOption{
|
2019-09-05 01:31:09 +00:00
|
|
|
// modifiers / withOptions
|
2019-05-27 00:41:10 +00:00
|
|
|
newProvisionerExtensionOption(TypeACME, p.Name, ""),
|
2019-09-05 01:31:09 +00:00
|
|
|
profileDefaultDuration(p.claimer.DefaultTLSCertDuration()),
|
|
|
|
// validators
|
2019-05-27 00:41:10 +00:00
|
|
|
defaultPublicKeyValidator{},
|
2019-09-05 01:31:09 +00:00
|
|
|
newValidityValidator(p.claimer.MinTLSCertDuration(), p.claimer.MaxTLSCertDuration()),
|
2019-05-27 00:41:10 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2019-10-28 18:50:43 +00:00
|
|
|
// AuthorizeRenew returns an error if the renewal is disabled.
|
|
|
|
// NOTE: This method does not actually validate the certificate or check it's
|
|
|
|
// revocation status. Just confirms that the provisioner that created the
|
|
|
|
// certificate was configured to allow renewals.
|
|
|
|
func (p *ACME) AuthorizeRenew(ctx context.Context, cert *x509.Certificate) error {
|
2019-05-27 00:41:10 +00:00
|
|
|
if p.claimer.IsDisableRenewal() {
|
2020-01-24 06:04:34 +00:00
|
|
|
return errs.Unauthorized("acme.AuthorizeRenew; renew is disabled for acme provisioner %s", p.GetID())
|
2019-05-27 00:41:10 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|