MCPcopy Create free account
hub / github.com/cloudflare/cfssl / worker

Function worker

cmd/mkbundle/mkbundle.go:25–72  ·  view source on GitHub ↗

worker does all the parsing and validation of the certificate(s) contained in a single file. It first reads all the data in the file, then begins parsing certificates in the file. Those certificates are then checked for revocation.

(paths chan string, bundler chan *x509.Certificate, pool *sync.WaitGroup)

Source from the content-addressed store, hash-verified

23// file, then begins parsing certificates in the file. Those
24// certificates are then checked for revocation.
25func worker(paths chan string, bundler chan *x509.Certificate, pool *sync.WaitGroup) {
26 defer (*pool).Done()
27 for {
28 path, ok := <-paths
29 if !ok {
30 return
31 }
32
33 log.Infof("Loading %s", path)
34
35 fileData, err := os.ReadFile(path)
36 if err != nil {
37 log.Warningf("%v", err)
38 continue
39 }
40
41 for {
42 var block *pem.Block
43 if len(fileData) == 0 {
44 break
45 }
46 block, fileData = pem.Decode(fileData)
47 if block == nil {
48 log.Warningf("%s: no PEM data found", path)
49 break
50 } else if block.Type != "CERTIFICATE" {
51 log.Info("Skipping non-certificate")
52 continue
53 }
54
55 cert, err := x509.ParseCertificate(block.Bytes)
56 if err != nil {
57 log.Warningf("Invalid certificate: %v", err)
58 continue
59 }
60
61 log.Infof("Validating %+v", cert.Subject)
62 revoked, ok := revoke.VerifyCertificate(cert)
63 if !ok {
64 log.Warning("Failed to verify certificate.")
65 } else if !revoked {
66 bundler <- cert
67 } else {
68 log.Info("Skipping revoked certificate")
69 }
70 }
71 }
72}
73
74// supervisor sets up the workers and signals the bundler that all
75// certificates have been processed.

Callers 1

supervisorFunction · 0.85

Calls 5

InfofFunction · 0.92
WarningfFunction · 0.92
InfoFunction · 0.92
VerifyCertificateFunction · 0.92
WarningFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…