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

Method Handle

api/certadd/insert.go:82–212  ·  view source on GitHub ↗

Handle handles HTTP requests to add certificates

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

80
81// Handle handles HTTP requests to add certificates
82func (h *Handler) Handle(w http.ResponseWriter, r *http.Request) error {
83 body, err := io.ReadAll(r.Body)
84 if err != nil {
85 return err
86 }
87 r.Body.Close()
88
89 var req AddRequest
90
91 err = json.Unmarshal(body, &req)
92 if err != nil {
93 return errors.NewBadRequestString("Unable to parse certificate addition request")
94 }
95
96 if len(req.Serial) == 0 {
97 return errors.NewBadRequestString("Serial number is required but not provided")
98 }
99
100 if len(req.AKI) == 0 {
101 return errors.NewBadRequestString("Authority key identifier is required but not provided")
102 }
103
104 if _, present := ocsp.StatusCode[req.Status]; !present {
105 return errors.NewBadRequestString("Invalid certificate status")
106 }
107
108 if ocsp.StatusCode[req.Status] == stdocsp.Revoked {
109 if req.RevokedAt == (time.Time{}) {
110 return errors.NewBadRequestString("Revoked certificate should specify when it was revoked")
111 }
112
113 if _, present := validReasons[req.Reason]; !present {
114 return errors.NewBadRequestString("Invalid certificate status reason code")
115 }
116 }
117
118 if len(req.PEM) == 0 {
119 return errors.NewBadRequestString("The provided certificate is empty")
120 }
121
122 if req.Expiry.IsZero() {
123 return errors.NewBadRequestString("Expiry is required but not provided")
124 }
125
126 // Parse the certificate and validate that it matches
127 cert, err := helpers.ParseCertificatePEM([]byte(req.PEM))
128 if err != nil {
129 return errors.NewBadRequestString("Unable to parse PEM encoded certificates")
130 }
131
132 serialBigInt := new(big.Int)
133 if _, success := serialBigInt.SetString(req.Serial, 10); !success {
134 return errors.NewBadRequestString("Unable to parse serial key of request")
135 }
136
137 if serialBigInt.Cmp(cert.SerialNumber) != 0 {
138 return errors.NewBadRequestString("Serial key of request and certificate do not match")
139 }

Callers

nothing calls this directly

Calls 7

NewBadRequestStringFunction · 0.92
ParseCertificatePEMFunction · 0.92
SendResponseFunction · 0.92
InsertCertificateMethod · 0.65
SignMethod · 0.65
InsertOCSPMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected