package acme import ( "crypto/x509" "encoding/pem" "fmt" "io/ioutil" "time" ) // 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 } // Check if a cert is expired by public key func CertIsExpired(certBtyes []byte) bool { block, _ := pem.Decode(certBtyes) if block != nil { cert, err := x509.ParseCertificate(block.Bytes) if err == nil { elapsed := time.Since(cert.NotAfter) if elapsed > 0 { // if it is expired then add it in // make sure it's uniqueless return true } } } return false }