config.go 7.2 KB

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