revoke.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Package revoke implements the revoke command.
  2. package revoke
  3. import (
  4. "errors"
  5. "github.com/cloudflare/cfssl/certdb/dbconf"
  6. "github.com/cloudflare/cfssl/certdb/sql"
  7. "github.com/cloudflare/cfssl/cli"
  8. "github.com/cloudflare/cfssl/log"
  9. "github.com/cloudflare/cfssl/ocsp"
  10. )
  11. var revokeUsageTxt = `cfssl revoke -- revoke a certificate in the certificate store
  12. Usage:
  13. Revoke a certificate:
  14. cfssl revoke -db-config config_file -serial serial -aki authority_key_id [-reason reason]
  15. Reason can be an integer code or a string in ReasonFlags in RFC 5280
  16. Flags:
  17. `
  18. var revokeFlags = []string{"serial", "reason"}
  19. func revokeMain(args []string, c cli.Config) error {
  20. if len(args) > 0 {
  21. return errors.New("argument is provided but not defined; please refer to the usage by flag -h")
  22. }
  23. if len(c.Serial) == 0 {
  24. return errors.New("serial number is required but not provided")
  25. }
  26. if len(c.AKI) == 0 {
  27. return errors.New("authority key id is required but not provided")
  28. }
  29. if c.DBConfigFile == "" {
  30. return errors.New("need DB config file (provide with -db-config)")
  31. }
  32. db, err := dbconf.DBFromConfig(c.DBConfigFile)
  33. if err != nil {
  34. return err
  35. }
  36. dbAccessor := sql.NewAccessor(db)
  37. reasonCode, err := ocsp.ReasonStringToCode(c.Reason)
  38. if err != nil {
  39. log.Error("Invalid reason code: ", err)
  40. return err
  41. }
  42. return dbAccessor.RevokeCertificate(c.Serial, c.AKI, reasonCode)
  43. }
  44. // Command assembles the definition of Command 'revoke'
  45. var Command = &cli.Command{
  46. UsageText: revokeUsageTxt,
  47. Flags: revokeFlags,
  48. Main: revokeMain,
  49. }