MCPcopy
hub / github.com/caddyserver/caddy / convertPEMFilesToDER

Function convertPEMFilesToDER

modules/caddytls/connpolicy.go:755–776  ·  view source on GitHub ↗
(filename string)

Source from the content-addressed store, hash-verified

753}
754
755func convertPEMFilesToDER(filename string) ([]string, error) {
756 certDataPEM, err := os.ReadFile(filename)
757 if err != nil {
758 return nil, err
759 }
760 var ders []string
761 // while block is not nil, we have more certificates in the file
762 for block, rest := pem.Decode(certDataPEM); block != nil; block, rest = pem.Decode(rest) {
763 if block.Type != "CERTIFICATE" {
764 return nil, fmt.Errorf("no CERTIFICATE pem block found in %s", filename)
765 }
766 ders = append(
767 ders,
768 base64.StdEncoding.EncodeToString(block.Bytes),
769 )
770 }
771 // if we decoded nothing, return an error
772 if len(ders) == 0 {
773 return nil, fmt.Errorf("no CERTIFICATE pem block found in %s", filename)
774 }
775 return ders, nil
776}
777
778func (clientauth *ClientAuthentication) provision(ctx caddy.Context) error {
779 if len(clientauth.CARaw) > 0 && (len(clientauth.TrustedCACerts) > 0 || len(clientauth.TrustedCACertPEMFiles) > 0) {

Callers 2

UnmarshalCaddyfileMethod · 0.85
provisionMethod · 0.85

Calls 1

ReadFileMethod · 0.80

Tested by

no test coverage detected