cfssl.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package roots
  2. import (
  3. "crypto/x509"
  4. "encoding/json"
  5. "errors"
  6. "github.com/cloudflare/cfssl/api/client"
  7. "github.com/cloudflare/cfssl/helpers"
  8. "github.com/cloudflare/cfssl/info"
  9. )
  10. // This package contains CFSSL integration.
  11. // NewCFSSL produces a new CFSSL root.
  12. func NewCFSSL(metadata map[string]string) ([]*x509.Certificate, error) {
  13. host, ok := metadata["host"]
  14. if !ok {
  15. return nil, errors.New("transport: CFSSL root provider requires a host")
  16. }
  17. label := metadata["label"]
  18. profile := metadata["profile"]
  19. cert, err := helpers.LoadClientCertificate(metadata["mutual-tls-cert"], metadata["mutual-tls-key"])
  20. if err != nil {
  21. return nil, err
  22. }
  23. remoteCAs, err := helpers.LoadPEMCertPool(metadata["tls-remote-ca"])
  24. if err != nil {
  25. return nil, err
  26. }
  27. srv := client.NewServerTLS(host, helpers.CreateTLSConfig(remoteCAs, cert))
  28. data, err := json.Marshal(info.Req{Label: label, Profile: profile})
  29. if err != nil {
  30. return nil, err
  31. }
  32. resp, err := srv.Info(data)
  33. if err != nil {
  34. return nil, err
  35. }
  36. return helpers.ParseCertificatesPEM([]byte(resp.Certificate))
  37. }