options.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package apiv1
  2. import (
  3. "crypto"
  4. "crypto/x509"
  5. "github.com/pkg/errors"
  6. "github.com/smallstep/certificates/kms"
  7. )
  8. // Options represents the configuration options used to select and configure the
  9. // CertificateAuthorityService (CAS) to use.
  10. type Options struct {
  11. // The type of the CAS to use.
  12. Type string `json:"type"`
  13. // CertificateAuthority reference:
  14. // In StepCAS the value is the CA url, e.g. "https://ca.smallstep.com:9000".
  15. // In CloudCAS the format is "projects/*/locations/*/certificateAuthorities/*".
  16. CertificateAuthority string `json:"certificateAuthority,omitempty"`
  17. // CertificateAuthorityFingerprint is the root fingerprint used to
  18. // authenticate the connection to the CA when using StepCAS.
  19. CertificateAuthorityFingerprint string `json:"certificateAuthorityFingerprint,omitempty"`
  20. // CertificateIssuer contains the configuration used in StepCAS.
  21. CertificateIssuer *CertificateIssuer `json:"certificateIssuer,omitempty"`
  22. // Path to the credentials file used in CloudCAS. If not defined the default
  23. // authentication mechanism provided by Google SDK will be used. See
  24. // https://cloud.google.com/docs/authentication.
  25. CredentialsFile string `json:"credentialsFile,omitempty"`
  26. // Certificate and signer are the issuer certificate, along with any other
  27. // bundled certificates to be returned in the chain for consumers, and
  28. // signer used in SoftCAS. They are configured in ca.json crt and key
  29. // properties.
  30. CertificateChain []*x509.Certificate `json:"-"`
  31. Signer crypto.Signer `json:"-"`
  32. // IsCreator is set to true when we're creating a certificate authority. Is
  33. // used to skip some validations when initializing a CertificateAuthority.
  34. IsCreator bool `json:"-"`
  35. // KeyManager is the KMS used to generate keys in SoftCAS.
  36. KeyManager kms.KeyManager `json:"-"`
  37. // Project, Location, CaPool and GCSBucket are parameters used in CloudCAS
  38. // to create a new certificate authority. If a CaPool does not exist it will
  39. // be created. GCSBucket is optional, if not provided GCloud will create a
  40. // managed bucket.
  41. Project string `json:"-"`
  42. Location string `json:"-"`
  43. CaPool string `json:"-"`
  44. CaPoolTier string `json:"-"`
  45. GCSBucket string `json:"-"`
  46. }
  47. // CertificateIssuer contains the properties used to use the StepCAS certificate
  48. // authority service.
  49. type CertificateIssuer struct {
  50. Type string `json:"type"`
  51. Provisioner string `json:"provisioner,omitempty"`
  52. Certificate string `json:"crt,omitempty"`
  53. Key string `json:"key,omitempty"`
  54. Password string `json:"password,omitempty"`
  55. }
  56. // Validate checks the fields in Options.
  57. func (o *Options) Validate() error {
  58. var typ Type
  59. if o == nil {
  60. typ = Type(SoftCAS)
  61. } else {
  62. typ = Type(o.Type)
  63. }
  64. // Check that the type can be loaded.
  65. if _, ok := LoadCertificateAuthorityServiceNewFunc(typ); !ok {
  66. return errors.Errorf("unsupported cas type %s", typ)
  67. }
  68. return nil
  69. }
  70. // Is returns if the options have the given type.
  71. func (o *Options) Is(t Type) bool {
  72. if o == nil {
  73. return t.String() == SoftCAS
  74. }
  75. return Type(o.Type).String() == t.String()
  76. }