utils.go 760 B

12345678910111213141516171819202122232425262728293031323334
  1. package acme
  2. import (
  3. "crypto/x509"
  4. "encoding/pem"
  5. "fmt"
  6. "io/ioutil"
  7. )
  8. // Get the issuer name from pem file
  9. func ExtractIssuerNameFromPEM(pemFilePath string) (string, error) {
  10. // Read the PEM file
  11. pemData, err := ioutil.ReadFile(pemFilePath)
  12. if err != nil {
  13. return "", err
  14. }
  15. // Parse the PEM block
  16. block, _ := pem.Decode(pemData)
  17. if block == nil || block.Type != "CERTIFICATE" {
  18. return "", fmt.Errorf("failed to decode PEM block containing certificate")
  19. }
  20. // Parse the certificate
  21. cert, err := x509.ParseCertificate(block.Bytes)
  22. if err != nil {
  23. return "", fmt.Errorf("failed to parse certificate: %v", err)
  24. }
  25. // Extract the issuer name
  26. issuer := cert.Issuer.Organization[0]
  27. return issuer, nil
  28. }