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

Function ocsprefreshMain

cli/ocsprefresh/ocsprefresh.go:31–98  ·  view source on GitHub ↗

ocsprefreshMain is the main CLI of OCSP refresh functionality.

(args []string, c cli.Config)

Source from the content-addressed store, hash-verified

29
30// ocsprefreshMain is the main CLI of OCSP refresh functionality.
31func ocsprefreshMain(args []string, c cli.Config) error {
32 if c.DBConfigFile == "" {
33 return errors.New("need DB config file (provide with -db-config)")
34 }
35
36 if c.ResponderFile == "" {
37 return errors.New("need responder certificate (provide with -responder)")
38 }
39
40 if c.ResponderKeyFile == "" {
41 return errors.New("need responder key (provide with -responder-key)")
42 }
43
44 if c.CAFile == "" {
45 return errors.New("need CA certificate (provide with -ca)")
46 }
47
48 s, err := SignerFromConfig(c)
49 if err != nil {
50 log.Critical("Unable to create OCSP signer: ", err)
51 return err
52 }
53
54 db, err := dbconf.DBFromConfig(c.DBConfigFile)
55 if err != nil {
56 return err
57 }
58
59 dbAccessor := sql.NewAccessor(db)
60 certs, err := dbAccessor.GetUnexpiredCertificates()
61 if err != nil {
62 return err
63 }
64
65 // Set an expiry timestamp for all certificates refreshed in this batch
66 ocspExpiry := time.Now().Add(c.Interval)
67 for _, certRecord := range certs {
68 cert, err := helpers.ParseCertificatePEM([]byte(certRecord.PEM))
69 if err != nil {
70 log.Critical("Unable to parse certificate: ", err)
71 return err
72 }
73
74 req := ocsp.SignRequest{
75 Certificate: cert,
76 Status: certRecord.Status,
77 }
78
79 if certRecord.Status == "revoked" {
80 req.Reason = int(certRecord.Reason)
81 req.RevokedAt = certRecord.RevokedAt
82 }
83
84 resp, err := s.Sign(req)
85 if err != nil {
86 log.Critical("Unable to sign OCSP response: ", err)
87 return err
88 }

Callers 1

TestOCSPRefreshMainFunction · 0.85

Calls 11

UpsertOCSPMethod · 0.95
CriticalFunction · 0.92
DBFromConfigFunction · 0.92
NewAccessorFunction · 0.92
ParseCertificatePEMFunction · 0.92
NewMethod · 0.80
SignerFromConfigFunction · 0.70
AddMethod · 0.65
SignMethod · 0.65
StringMethod · 0.45

Tested by 1

TestOCSPRefreshMainFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…