12345678910111213141516171819202122232425262728293031323334 |
- package acme
- import (
- "crypto/x509"
- "encoding/pem"
- "fmt"
- "io/ioutil"
- )
- // Get the issuer name from pem file
- func ExtractIssuerNameFromPEM(pemFilePath string) (string, error) {
- // Read the PEM file
- pemData, err := ioutil.ReadFile(pemFilePath)
- if err != nil {
- return "", err
- }
- // Parse the PEM block
- block, _ := pem.Decode(pemData)
- if block == nil || block.Type != "CERTIFICATE" {
- return "", fmt.Errorf("failed to decode PEM block containing certificate")
- }
- // Parse the certificate
- cert, err := x509.ParseCertificate(block.Bytes)
- if err != nil {
- return "", fmt.Errorf("failed to parse certificate: %v", err)
- }
- // Extract the issuer name
- issuer := cert.Issuer.Organization[0]
- return issuer, nil
- }
|