ca.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package acme
  2. /*
  3. CA.go
  4. This script load CA definition from embedded ca.json
  5. */
  6. import (
  7. _ "embed"
  8. "encoding/json"
  9. "errors"
  10. "log"
  11. "strings"
  12. )
  13. // CA definition, load from embeded json when startup
  14. type CaDef struct {
  15. Production map[string]string
  16. Test map[string]string
  17. }
  18. //go:embed ca.json
  19. var caJson []byte
  20. var caDef CaDef = CaDef{}
  21. func init() {
  22. runtimeCaDef := CaDef{}
  23. err := json.Unmarshal(caJson, &runtimeCaDef)
  24. if err != nil {
  25. log.Println("[ERR] Unable to unmarshal CA def from embedded file. You sure your ca.json is valid?")
  26. return
  27. }
  28. caDef = runtimeCaDef
  29. }
  30. // Get the CA ACME server endpoint and error if not found
  31. func loadCAApiServerFromName(caName string) (string, error) {
  32. // handle BuyPass cert org section (Buypass AS-983163327)
  33. if strings.HasPrefix(caName, "Buypass AS") {
  34. caName = "Buypass"
  35. }
  36. val, ok := caDef.Production[caName]
  37. if !ok {
  38. return "", errors.New("This CA is not supported")
  39. }
  40. return val, nil
  41. }
  42. func IsSupportedCA(caName string) bool {
  43. _, err := loadCAApiServerFromName(caName)
  44. return err == nil
  45. }