aboutsummaryrefslogtreecommitdiff
path: root/cmd/batch/files.go
blob: cc4cad5caf4512f2902ff10717c1506c72f5c64c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package main

import (
	"crypto/tls"
	"crypto/x509"
	"path"
	"path/filepath"
)

func scanFiles(dir string) ([]tls.Certificate, error) {
	var certs []tls.Certificate
	keys, err := filepath.Glob(path.Join(dir, "private", "*.key"))
	if err != nil {
		return nil, err
	}
	for _, k := range keys {
		c := filepath.Join(dir, "certs", filepath.Base(k[:len(k)-4])+".pem")
		crt, err := tls.LoadX509KeyPair(c, k)
		if err != nil {
			continue
		}
		crt.Leaf, err = x509.ParseCertificate(crt.Certificate[0])
		if err != nil {
			return nil, err
		}
		certs = append(certs, crt)
	}
	return certs, nil
}