gencrl.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //Package gencrl implements the gencrl command
  2. package gencrl
  3. import (
  4. "github.com/cloudflare/cfssl/cli"
  5. "github.com/cloudflare/cfssl/crl"
  6. "strings"
  7. )
  8. var gencrlUsageText = `cfssl gencrl -- generate a new Certificate Revocation List
  9. Usage of gencrl:
  10. cfssl gencrl INPUTFILE CERT KEY TIME
  11. Arguments:
  12. INPUTFILE: Text file with one serial number per line, use '-' for reading text from stdin
  13. CERT: The certificate that is signing this CRL, use '-' for reading text from stdin
  14. KEY: The private key of the certificate that is signing the CRL, use '-' for reading text from stdin
  15. TIME (OPTIONAL): The desired expiration from now, in seconds
  16. Flags:
  17. `
  18. var gencrlFlags = []string{}
  19. func gencrlMain(args []string, c cli.Config) (err error) {
  20. serialList, args, err := cli.PopFirstArgument(args)
  21. if err != nil {
  22. return
  23. }
  24. serialListBytes, err := cli.ReadStdin(serialList)
  25. if err != nil {
  26. return
  27. }
  28. certFile, args, err := cli.PopFirstArgument(args)
  29. if err != nil {
  30. return
  31. }
  32. certFileBytes, err := cli.ReadStdin(certFile)
  33. if err != nil {
  34. return
  35. }
  36. keyFile, args, err := cli.PopFirstArgument(args)
  37. if err != nil {
  38. return
  39. }
  40. keyBytes, err := cli.ReadStdin(keyFile)
  41. if err != nil {
  42. return
  43. }
  44. // Default value if no expiry time is given
  45. timeString := string("0")
  46. if len(args) > 0 {
  47. timeArg, _, err := cli.PopFirstArgument(args)
  48. if err != nil {
  49. return err
  50. }
  51. timeString = string(timeArg)
  52. // This is used to get rid of newlines
  53. timeString = strings.TrimSpace(timeString)
  54. }
  55. req, err := crl.NewCRLFromFile(serialListBytes, certFileBytes, keyBytes, timeString)
  56. if err != nil {
  57. return
  58. }
  59. cli.PrintCRL(req)
  60. return nil
  61. }
  62. // Command assembles the definition of Command 'gencrl'
  63. var Command = &cli.Command{UsageText: gencrlUsageText, Flags: gencrlFlags, Main: gencrlMain}