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

Method Handle

api/bundle/bundle.go:35–91  ·  view source on GitHub ↗

Handle implements an http.Handler interface for the bundle handler.

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

Source from the content-addressed store, hash-verified

33
34// Handle implements an http.Handler interface for the bundle handler.
35func (h *Handler) Handle(w http.ResponseWriter, r *http.Request) error {
36 blob, matched, err := api.ProcessRequestFirstMatchOf(r,
37 [][]string{
38 {"certificate"},
39 {"domain"},
40 })
41 if err != nil {
42 log.Warningf("invalid request: %v", err)
43 return err
44 }
45
46 flavor := blob["flavor"]
47 bf := bundler.Ubiquitous
48 if flavor != "" {
49 bf = bundler.BundleFlavor(flavor)
50 }
51 log.Infof("request for flavor %v", bf)
52
53 var result *bundler.Bundle
54 switch matched[0] {
55 case "domain":
56 bundle, err := h.bundler.BundleFromRemote(blob["domain"], blob["ip"], bf)
57 if err != nil {
58 log.Warningf("couldn't bundle from remote: %v", err)
59 return err
60 }
61 result = bundle
62 case "certificate":
63 bundle, err := h.bundler.BundleFromPEMorDER([]byte(blob["certificate"]), []byte(blob["private_key"]), bf, "")
64 if err != nil {
65 log.Warning("bad PEM certificate or private key")
66 return err
67 }
68
69 serverName := blob["domain"]
70 ip := blob["ip"]
71
72 if serverName != "" {
73 err := bundle.Cert.VerifyHostname(serverName)
74 if err != nil {
75 return errors.Wrap(errors.CertificateError, errors.VerifyFailed, err)
76 }
77
78 }
79
80 if ip != "" {
81 err := bundle.Cert.VerifyHostname(ip)
82 if err != nil {
83 return errors.Wrap(errors.CertificateError, errors.VerifyFailed, err)
84 }
85 }
86
87 result = bundle
88 }
89 log.Info("wrote response")
90 return api.SendResponse(w, result)
91}

Callers

nothing calls this directly

Calls 11

WarningfFunction · 0.92
BundleFlavorTypeAlias · 0.92
InfofFunction · 0.92
WarningFunction · 0.92
WrapFunction · 0.92
InfoFunction · 0.92
SendResponseFunction · 0.92
BundleFromRemoteMethod · 0.80
BundleFromPEMorDERMethod · 0.80
VerifyHostnameMethod · 0.80

Tested by

no test coverage detected