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

Function dispatchRequest

cmd/multirootca/api.go:78–194  ·  view source on GitHub ↗
(w http.ResponseWriter, req *http.Request)

Source from the content-addressed store, hash-verified

76}
77
78func dispatchRequest(w http.ResponseWriter, req *http.Request) {
79 if req.Method != "POST" {
80 fail(w, req, http.StatusMethodNotAllowed, 1, "only POST is permitted", "")
81 return
82 }
83
84 defer req.Body.Close()
85 body, err := io.ReadAll(req.Body)
86 if err != nil {
87 fail(w, req, http.StatusInternalServerError, 1, err.Error(), "while reading request body")
88 return
89 }
90
91 var authReq auth.AuthenticatedRequest
92 err = json.Unmarshal(body, &authReq)
93 if err != nil {
94 fail(w, req, http.StatusBadRequest, 1, err.Error(), "while unmarshaling request body")
95 return
96 }
97
98 var sigRequest signer.SignRequest
99 err = json.Unmarshal(authReq.Request, &sigRequest)
100 if err != nil {
101 fail(w, req, http.StatusBadRequest, 1, err.Error(), "while unmarshalling authenticated request")
102 return
103 }
104
105 if sigRequest.Label == "" {
106 sigRequest.Label = defaultLabel
107 }
108
109 acl := whitelists[sigRequest.Label]
110 if acl != nil {
111 ip, err := whitelist.HTTPRequestLookup(req)
112 if err != nil {
113 fail(w, req, http.StatusInternalServerError, 1, err.Error(), "while getting request IP")
114 return
115 }
116
117 if !acl.Permitted(ip) {
118 fail(w, req, http.StatusForbidden, 1, "not authorised", "because IP is not whitelisted")
119 return
120 }
121 }
122
123 s, ok := signers[sigRequest.Label]
124 if !ok {
125 fail(w, req, http.StatusBadRequest, 1, "bad request", "request is for non-existent label "+sigRequest.Label)
126 return
127 }
128 requests.WithLabelValues(signOperation, sigRequest.Label).Inc()
129 // Sanity checks to ensure that we have a valid policy. This
130 // should have been checked in NewAuthSignHandler.
131 policy := s.Policy()
132 if policy == nil {
133 fail(w, req, http.StatusInternalServerError, 1, "invalid policy", "signer was initialised without a signing policy")
134 return
135 }

Callers

nothing calls this directly

Calls 12

HTTPRequestLookupFunction · 0.92
ParseCertificatePEMFunction · 0.92
InfofFunction · 0.92
NewSuccessResponseFunction · 0.92
ErrorfFunction · 0.92
failFunction · 0.85
PermittedMethod · 0.65
PolicyMethod · 0.65
VerifyMethod · 0.65
SignMethod · 0.65
CloseMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…