sign.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Package sign implements the HTTP handler for the certificate signing command.
  2. package sign
  3. import (
  4. "net/http"
  5. "github.com/cloudflare/cfssl/api/signhandler"
  6. "github.com/cloudflare/cfssl/config"
  7. "github.com/cloudflare/cfssl/log"
  8. "github.com/cloudflare/cfssl/signer/universal"
  9. )
  10. // NewHandler generates a new Handler using the certificate
  11. // authority private key and certficate to sign certificates. If remote
  12. // is not an empty string, the handler will send signature requests to
  13. // the CFSSL instance contained in remote by default.
  14. func NewHandler(caFile, caKeyFile string, policy *config.Signing) (http.Handler, error) {
  15. root := universal.Root{
  16. Config: map[string]string{
  17. "cert-file": caFile,
  18. "key-file": caKeyFile,
  19. },
  20. }
  21. s, err := universal.NewSigner(root, policy)
  22. if err != nil {
  23. log.Errorf("setting up signer failed: %v", err)
  24. return nil, err
  25. }
  26. return signhandler.NewHandlerFromSigner(s)
  27. }
  28. // NewAuthHandler generates a new AuthHandler using the certificate
  29. // authority private key and certficate to sign certificates. If remote
  30. // is not an empty string, the handler will send signature requests to
  31. // the CFSSL instance contained in remote by default.
  32. func NewAuthHandler(caFile, caKeyFile string, policy *config.Signing) (http.Handler, error) {
  33. root := universal.Root{
  34. Config: map[string]string{
  35. "cert-file": caFile,
  36. "key-file": caKeyFile,
  37. },
  38. }
  39. s, err := universal.NewSigner(root, policy)
  40. if err != nil {
  41. log.Errorf("setting up signer failed: %v", err)
  42. return nil, err
  43. }
  44. return signhandler.NewAuthHandlerFromSigner(s)
  45. }