common.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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, *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. accountTable = []byte("acme-accounts")
  22. accountByKeyIDTable = []byte("acme-keyID-accountID-index")
  23. authzTable = []byte("acme-authzs")
  24. challengeTable = []byte("acme-challenges")
  25. nonceTable = []byte("nonce-table")
  26. orderTable = []byte("acme-orders")
  27. ordersByAccountIDTable = []byte("acme-account-orders-index")
  28. certTable = []byte("acme-certs")
  29. )
  30. var (
  31. // StatusValid -- valid
  32. StatusValid = "valid"
  33. // StatusInvalid -- invalid
  34. StatusInvalid = "invalid"
  35. // StatusPending -- pending; e.g. an Order that is not ready to be finalized.
  36. StatusPending = "pending"
  37. // StatusDeactivated -- deactivated; e.g. for an Account that is not longer valid.
  38. StatusDeactivated = "deactivated"
  39. // StatusReady -- ready; e.g. for an Order that is ready to be finalized.
  40. StatusReady = "ready"
  41. //statusExpired = "expired"
  42. //statusActive = "active"
  43. //statusProcessing = "processing"
  44. )
  45. var idLen = 32
  46. func randID() (val string, err error) {
  47. val, err = randutil.Alphanumeric(idLen)
  48. if err != nil {
  49. return "", ServerInternalErr(errors.Wrap(err, "error generating random alphanumeric ID"))
  50. }
  51. return val, nil
  52. }
  53. // Clock that returns time in UTC rounded to seconds.
  54. type Clock int
  55. // Now returns the UTC time rounded to seconds.
  56. func (c *Clock) Now() time.Time {
  57. return time.Now().UTC().Round(time.Second)
  58. }
  59. var clock = new(Clock)
  60. // URLSafeProvisionerName returns a path escaped version of the ACME provisioner
  61. // ID that is safe to use in URL paths.
  62. func URLSafeProvisionerName(p provisioner.Interface) string {
  63. return url.PathEscape(p.GetName())
  64. }