acme.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. Type string `json:"type"`
  11. Name string `json:"name"`
  12. Claims *Claims `json:"claims,omitempty"`
  13. claimer *Claimer
  14. }
  15. // GetID returns the provisioner unique identifier.
  16. func (p ACME) GetID() string {
  17. return "acme/" + p.Name
  18. }
  19. // GetTokenID returns the identifier of the token.
  20. func (p *ACME) GetTokenID(ott string) (string, error) {
  21. return "", errors.New("acme provisioner does not implement GetTokenID")
  22. }
  23. // GetName returns the name of the provisioner.
  24. func (p *ACME) GetName() string {
  25. return p.Name
  26. }
  27. // GetType returns the type of provisioner.
  28. func (p *ACME) GetType() Type {
  29. return TypeACME
  30. }
  31. // GetEncryptedKey returns the base provisioner encrypted key if it's defined.
  32. func (p *ACME) GetEncryptedKey() (string, string, bool) {
  33. return "", "", false
  34. }
  35. // Init initializes and validates the fields of a JWK type.
  36. func (p *ACME) Init(config Config) (err error) {
  37. switch {
  38. case p.Type == "":
  39. return errors.New("provisioner type cannot be empty")
  40. case p.Name == "":
  41. return errors.New("provisioner name cannot be empty")
  42. }
  43. // Update claims with global ones
  44. if p.claimer, err = NewClaimer(p.Claims, config.Claims); err != nil {
  45. return err
  46. }
  47. return err
  48. }
  49. // AuthorizeRevoke is not implemented yet for the ACME provisioner.
  50. func (p *ACME) AuthorizeRevoke(token string) error {
  51. return nil
  52. }
  53. // AuthorizeSign validates the given token.
  54. func (p *ACME) AuthorizeSign(ctx context.Context, _ string) ([]SignOption, error) {
  55. if m := MethodFromContext(ctx); m != SignMethod {
  56. return nil, errors.Errorf("unexpected method type %d in context", m)
  57. }
  58. return []SignOption{
  59. // modifiers / withOptions
  60. newProvisionerExtensionOption(TypeACME, p.Name, ""),
  61. profileDefaultDuration(p.claimer.DefaultTLSCertDuration()),
  62. // validators
  63. defaultPublicKeyValidator{},
  64. newValidityValidator(p.claimer.MinTLSCertDuration(), p.claimer.MaxTLSCertDuration()),
  65. }, nil
  66. }
  67. // AuthorizeRenewal is not implemented for the ACME provisioner.
  68. func (p *ACME) AuthorizeRenewal(cert *x509.Certificate) error {
  69. if p.claimer.IsDisableRenewal() {
  70. return errors.Errorf("renew is disabled for provisioner %s", p.GetID())
  71. }
  72. return nil
  73. }