4
0

common.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package acme
  2. import (
  3. "crypto/x509"
  4. "net/url"
  5. "time"
  6. "github.com/pkg/errors"
  7. "github.com/smallstep/certificates/authority/provisioner"
  8. "github.com/smallstep/cli/crypto/randutil"
  9. )
  10. // SignAuthority is the interface implemented by a CA authority.
  11. type SignAuthority interface {
  12. Sign(cr *x509.CertificateRequest, opts provisioner.Options, signOpts ...provisioner.SignOption) ([]*x509.Certificate, error)
  13. LoadProvisionerByID(string) (provisioner.Interface, error)
  14. }
  15. // Identifier encodes the type that an order pertains to.
  16. type Identifier struct {
  17. Type string `json:"type"`
  18. Value string `json:"value"`
  19. }
  20. var (
  21. // StatusValid -- valid
  22. StatusValid = "valid"
  23. // StatusInvalid -- invalid
  24. StatusInvalid = "invalid"
  25. // StatusPending -- pending; e.g. an Order that is not ready to be finalized.
  26. StatusPending = "pending"
  27. // StatusDeactivated -- deactivated; e.g. for an Account that is not longer valid.
  28. StatusDeactivated = "deactivated"
  29. // StatusReady -- ready; e.g. for an Order that is ready to be finalized.
  30. StatusReady = "ready"
  31. //statusExpired = "expired"
  32. //statusActive = "active"
  33. //statusProcessing = "processing"
  34. )
  35. var idLen = 32
  36. func randID() (val string, err error) {
  37. val, err = randutil.Alphanumeric(idLen)
  38. if err != nil {
  39. return "", ServerInternalErr(errors.Wrap(err, "error generating random alphanumeric ID"))
  40. }
  41. return val, nil
  42. }
  43. // Clock that returns time in UTC rounded to seconds.
  44. type Clock int
  45. // Now returns the UTC time rounded to seconds.
  46. func (c *Clock) Now() time.Time {
  47. return time.Now().UTC().Round(time.Second)
  48. }
  49. var clock = new(Clock)
  50. // URLSafeProvisionerName returns a path escaped version of the ACME provisioner
  51. // ID that is safe to use in URL paths.
  52. func URLSafeProvisionerName(p provisioner.Interface) string {
  53. return url.PathEscape(p.GetName())
  54. }