56 lines
1.1 KiB
Go
56 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"acme-mana/src"
|
|
"crypto/x509"
|
|
"encoding/json"
|
|
"encoding/pem"
|
|
"github.com/go-acme/lego/v4/certificate"
|
|
"log"
|
|
"os"
|
|
"path"
|
|
"path/filepath"
|
|
)
|
|
|
|
func main() {
|
|
//src.Start()
|
|
testParseCert()
|
|
}
|
|
|
|
func testParseCert() {
|
|
// 读取
|
|
dir := src.GetAppConfig().CertDir
|
|
dir = filepath.Join(dir, "acme.zzzykj.cn")
|
|
certFile := path.Join(dir, "cert.crt")
|
|
certBytes, err := os.ReadFile(certFile)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
block, _ := pem.Decode(certBytes)
|
|
if block == nil {
|
|
log.Fatalf("Failed to decode PEM block")
|
|
return
|
|
}
|
|
|
|
certParse, err := x509.ParseCertificate(block.Bytes)
|
|
if err != nil {
|
|
log.Fatalf("Failed to parse certificate: %v", err)
|
|
}
|
|
//info, err := json.Marshal(certParse)
|
|
//if err != nil {
|
|
// log.Fatalf("Failed to marshal certificate: %v", err)
|
|
//}
|
|
certInfo := src.CertInfo{
|
|
Cert: certificate.Resource{},
|
|
Info: *certParse,
|
|
}
|
|
info, err := json.Marshal(certInfo)
|
|
if err != nil {
|
|
log.Fatalf("Failed to marshal certificate: %v", err)
|
|
}
|
|
log.Println(string(info))
|
|
|
|
//log.Println(string(info))
|
|
//log.Println(certParse)
|
|
}
|