25 lines
465 B
Go
25 lines
465 B
Go
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
|
|
}
|