config.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package cli
  2. import (
  3. "flag"
  4. "time"
  5. "github.com/cloudflare/cfssl/config"
  6. "github.com/cloudflare/cfssl/helpers"
  7. "github.com/cloudflare/cfssl/log"
  8. "github.com/cloudflare/cfssl/signer/universal"
  9. )
  10. // Config is a type to hold flag values used by cfssl commands.
  11. type Config struct {
  12. Hostname string
  13. CertFile string
  14. CSRFile string
  15. CAFile string
  16. CAKeyFile string
  17. TLSCertFile string
  18. TLSKeyFile string
  19. MutualTLSCAFile string
  20. MutualTLSCNRegex string
  21. TLSRemoteCAs string
  22. MutualTLSCertFile string
  23. MutualTLSKeyFile string
  24. KeyFile string
  25. IntermediatesFile string
  26. CABundleFile string
  27. IntBundleFile string
  28. Address string
  29. Port int
  30. Password string
  31. ConfigFile string
  32. CFG *config.Config
  33. Profile string
  34. IsCA bool
  35. RenewCA bool
  36. IntDir string
  37. Flavor string
  38. Metadata string
  39. Domain string
  40. IP string
  41. Remote string
  42. Label string
  43. AuthKey string
  44. ResponderFile string
  45. ResponderKeyFile string
  46. Status string
  47. Reason string
  48. RevokedAt string
  49. Interval time.Duration
  50. List bool
  51. Family string
  52. Timeout time.Duration
  53. Scanner string
  54. CSVFile string
  55. NumWorkers int
  56. MaxHosts int
  57. Responses string
  58. Path string
  59. CRL string
  60. Usage string
  61. PGPPrivate string
  62. PGPName string
  63. Serial string
  64. CNOverride string
  65. AKI string
  66. DBConfigFile string
  67. CRLExpiration time.Duration
  68. }
  69. // registerFlags defines all cfssl command flags and associates their values with variables.
  70. func registerFlags(c *Config, f *flag.FlagSet) {
  71. f.StringVar(&c.Hostname, "hostname", "", "Hostname for the cert, could be a comma-separated hostname list")
  72. f.StringVar(&c.CertFile, "cert", "", "Client certificate that contains the public key")
  73. f.StringVar(&c.CSRFile, "csr", "", "Certificate signature request file for new public key")
  74. f.StringVar(&c.CAFile, "ca", "", "CA used to sign the new certificate -- accepts '[file:]fname' or 'env:varname'")
  75. f.StringVar(&c.CAKeyFile, "ca-key", "", "CA private key -- accepts '[file:]fname' or 'env:varname'")
  76. f.StringVar(&c.TLSCertFile, "tls-cert", "", "Other endpoint CA to set up TLS protocol")
  77. f.StringVar(&c.TLSKeyFile, "tls-key", "", "Other endpoint CA private key")
  78. f.StringVar(&c.MutualTLSCAFile, "mutual-tls-ca", "", "Mutual TLS - require clients be signed by this CA ")
  79. f.StringVar(&c.MutualTLSCNRegex, "mutual-tls-cn", "", "Mutual TLS - regex for whitelist of allowed client CNs")
  80. f.StringVar(&c.TLSRemoteCAs, "tls-remote-ca", "", "CAs to trust for remote TLS requests")
  81. f.StringVar(&c.MutualTLSCertFile, "mutual-tls-client-cert", "", "Mutual TLS - client certificate to call remote instance requiring client certs")
  82. f.StringVar(&c.MutualTLSKeyFile, "mutual-tls-client-key", "", "Mutual TLS - client key to call remote instance requiring client certs")
  83. f.StringVar(&c.KeyFile, "key", "", "private key for the certificate")
  84. f.StringVar(&c.IntermediatesFile, "intermediates", "", "intermediate certs")
  85. f.StringVar(&c.CABundleFile, "ca-bundle", "", "path to root certificate store")
  86. f.StringVar(&c.IntBundleFile, "int-bundle", "", "path to intermediate certificate store")
  87. f.StringVar(&c.Address, "address", "127.0.0.1", "Address to bind")
  88. f.IntVar(&c.Port, "port", 8888, "Port to bind")
  89. f.StringVar(&c.ConfigFile, "config", "", "path to configuration file")
  90. f.StringVar(&c.Profile, "profile", "", "signing profile to use")
  91. f.BoolVar(&c.IsCA, "initca", false, "initialise new CA")
  92. f.BoolVar(&c.RenewCA, "renewca", false, "re-generate a CA certificate from existing CA certificate/key")
  93. f.StringVar(&c.IntDir, "int-dir", "", "specify intermediates directory")
  94. f.StringVar(&c.Flavor, "flavor", "ubiquitous", "Bundle Flavor: ubiquitous, optimal and force.")
  95. f.StringVar(&c.Metadata, "metadata", "", "Metadata file for root certificate presence. The content of the file is a json dictionary (k,v): each key k is SHA-1 digest of a root certificate while value v is a list of key store filenames.")
  96. f.StringVar(&c.Domain, "domain", "", "remote server domain name")
  97. f.StringVar(&c.IP, "ip", "", "remote server ip")
  98. f.StringVar(&c.Remote, "remote", "", "remote CFSSL server")
  99. f.StringVar(&c.Label, "label", "", "key label to use in remote CFSSL server")
  100. f.StringVar(&c.AuthKey, "authkey", "", "key to authenticate requests to remote CFSSL server")
  101. f.StringVar(&c.ResponderFile, "responder", "", "Certificate for OCSP responder")
  102. f.StringVar(&c.ResponderKeyFile, "responder-key", "", "private key for OCSP responder certificate")
  103. f.StringVar(&c.Status, "status", "good", "Status of the certificate: good, revoked, unknown")
  104. f.StringVar(&c.Reason, "reason", "0", "Reason code for revocation")
  105. f.StringVar(&c.RevokedAt, "revoked-at", "now", "Date of revocation (YYYY-MM-DD)")
  106. f.DurationVar(&c.Interval, "interval", 4*helpers.OneDay, "Interval between OCSP updates (default: 96h)")
  107. f.BoolVar(&c.List, "list", false, "list possible scanners")
  108. f.StringVar(&c.Family, "family", "", "scanner family regular expression")
  109. f.StringVar(&c.Scanner, "scanner", "", "scanner regular expression")
  110. f.DurationVar(&c.Timeout, "timeout", 5*time.Minute, "duration (ns, us, ms, s, m, h) to scan each host before timing out")
  111. f.StringVar(&c.CSVFile, "csv", "", "file containing CSV of hosts")
  112. f.IntVar(&c.NumWorkers, "num-workers", 10, "number of workers to use for scan")
  113. f.IntVar(&c.MaxHosts, "max-hosts", 100, "maximum number of hosts to scan")
  114. f.StringVar(&c.Responses, "responses", "", "file to load OCSP responses from")
  115. f.StringVar(&c.Path, "path", "/", "Path on which the server will listen")
  116. f.StringVar(&c.CRL, "crl", "", "CRL URL Override")
  117. f.StringVar(&c.Password, "password", "0", "Password for accessing PKCS #12 data passed to bundler")
  118. f.StringVar(&c.Usage, "usage", "", "usage of private key")
  119. f.StringVar(&c.PGPPrivate, "pgp-private", "", "file to load a PGP Private key decryption")
  120. f.StringVar(&c.PGPName, "pgp-name", "", "PGP public key name, can be a comma-sepearted key name list")
  121. f.StringVar(&c.Serial, "serial", "", "certificate serial number")
  122. f.StringVar(&c.CNOverride, "cn", "", "certificate common name (CN)")
  123. f.StringVar(&c.AKI, "aki", "", "certificate issuer (authority) key identifier")
  124. f.StringVar(&c.DBConfigFile, "db-config", "", "certificate db configuration file")
  125. f.DurationVar(&c.CRLExpiration, "expiry", 7*helpers.OneDay, "time from now after which the CRL will expire (default: one week)")
  126. f.IntVar(&log.Level, "loglevel", log.LevelInfo, "Log level (0 = DEBUG, 5 = FATAL)")
  127. }
  128. // RootFromConfig returns a universal signer Root structure that can
  129. // be used to produce a signer.
  130. func RootFromConfig(c *Config) universal.Root {
  131. return universal.Root{
  132. Config: map[string]string{
  133. "cert-file": c.CAFile,
  134. "key-file": c.CAKeyFile,
  135. },
  136. ForceRemote: c.Remote != "",
  137. }
  138. }