acme.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package provisioner
  2. import (
  3. "context"
  4. "crypto/x509"
  5. "github.com/pkg/errors"
  6. "github.com/smallstep/certificates/errs"
  7. )
  8. // ACME is the acme provisioner type, an entity that can authorize the ACME
  9. // provisioning flow.
  10. type ACME struct {
  11. *base
  12. Type string `json:"type"`
  13. Name string `json:"name"`
  14. Claims *Claims `json:"claims,omitempty"`
  15. claimer *Claimer
  16. }
  17. // GetID returns the provisioner unique identifier.
  18. func (p ACME) GetID() string {
  19. return "acme/" + p.Name
  20. }
  21. // GetTokenID returns the identifier of the token.
  22. func (p *ACME) GetTokenID(ott string) (string, error) {
  23. return "", errors.New("acme provisioner does not implement GetTokenID")
  24. }
  25. // GetName returns the name of the provisioner.
  26. func (p *ACME) GetName() string {
  27. return p.Name
  28. }
  29. // GetType returns the type of provisioner.
  30. func (p *ACME) GetType() Type {
  31. return TypeACME
  32. }
  33. // GetEncryptedKey returns the base provisioner encrypted key if it's defined.
  34. func (p *ACME) GetEncryptedKey() (string, string, bool) {
  35. return "", "", false
  36. }
  37. // Init initializes and validates the fields of a JWK type.
  38. func (p *ACME) Init(config Config) (err error) {
  39. switch {
  40. case p.Type == "":
  41. return errors.New("provisioner type cannot be empty")
  42. case p.Name == "":
  43. return errors.New("provisioner name cannot be empty")
  44. }
  45. // Update claims with global ones
  46. if p.claimer, err = NewClaimer(p.Claims, config.Claims); err != nil {
  47. return err
  48. }
  49. return err
  50. }
  51. // AuthorizeSign does not do any validation, because all validation is handled
  52. // in the ACME protocol. This method returns a list of modifiers / constraints
  53. // on the resulting certificate.
  54. func (p *ACME) AuthorizeSign(ctx context.Context, token string) ([]SignOption, error) {
  55. return []SignOption{
  56. // modifiers / withOptions
  57. newProvisionerExtensionOption(TypeACME, p.Name, ""),
  58. profileDefaultDuration(p.claimer.DefaultTLSCertDuration()),
  59. // validators
  60. defaultPublicKeyValidator{},
  61. newValidityValidator(p.claimer.MinTLSCertDuration(), p.claimer.MaxTLSCertDuration()),
  62. }, nil
  63. }
  64. // AuthorizeRenew returns an error if the renewal is disabled.
  65. // NOTE: This method does not actually validate the certificate or check it's
  66. // revocation status. Just confirms that the provisioner that created the
  67. // certificate was configured to allow renewals.
  68. func (p *ACME) AuthorizeRenew(ctx context.Context, cert *x509.Certificate) error {
  69. if p.claimer.IsDisableRenewal() {
  70. return errs.Unauthorized("acme.AuthorizeRenew; renew is disabled for acme provisioner %s", p.GetID())
  71. }
  72. return nil
  73. }