acme.go 2.3 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. 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. profileDefaultDuration(p.claimer.DefaultTLSCertDuration()),
  60. newProvisionerExtensionOption(TypeACME, p.Name, ""),
  61. newValidityValidator(p.claimer.MinTLSCertDuration(), p.claimer.MaxTLSCertDuration()),
  62. defaultPublicKeyValidator{},
  63. }, nil
  64. }
  65. // AuthorizeRenewal is not implemented for the ACME provisioner.
  66. func (p *ACME) AuthorizeRenewal(cert *x509.Certificate) error {
  67. if p.claimer.IsDisableRenewal() {
  68. return errors.Errorf("renew is disabled for provisioner %s", p.GetID())
  69. }
  70. return nil
  71. }