acme.go 2.4 KB

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