This commit is contained in:
2026-04-23 20:36:37 +03:00
parent 4ecc8973bf
commit 840d7d8e3b
19 changed files with 758 additions and 0 deletions

24
internal/tlsutil/ca.go Normal file
View File

@@ -0,0 +1,24 @@
package tlsutil
import (
"crypto/tls"
"crypto/x509"
"fmt"
)
func LoadCACert(certPath, keyPath string) (*tls.Certificate, error) {
cert, err := tls.LoadX509KeyPair(certPath, keyPath)
if err != nil {
return nil, err
}
if len(cert.Certificate) == 0 {
return nil, fmt.Errorf("empty certificate chain in %s", certPath)
}
leaf, err := x509.ParseCertificate(cert.Certificate[0])
if err != nil {
return nil, err
}
cert.Leaf = leaf
return &cert, nil
}