diff --git a/pkg/server/sig.go b/pkg/server/sig.go index 322dd8ae9..feb88b2f9 100644 --- a/pkg/server/sig.go +++ b/pkg/server/sig.go @@ -132,6 +132,19 @@ func (h *JSONSignHandler) uploadPublicKey(sto blobserver.Storage, key string) er return err } +func (h *JSONSignHandler) discoveryMap(base string) map[string]interface{} { + m := map[string]interface{}{ + "publicKeyId": h.entity.PrimaryKey.KeyIdString(), + "signHandler": base + "camli/sig/sign", + "verifyHandler": base + "camli/sig/verify", + } + if h.pubKeyBlobRef != nil { + m["publicKeyBlobRef"] = h.pubKeyBlobRef.String() + m["publicKey"] = base + h.pubKeyBlobRefServeSuffix + } + return m +} + func (h *JSONSignHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) { base := req.Header.Get("X-PrefixHandler-PathBase") subPath := req.Header.Get("X-PrefixHandler-PathSuffix") @@ -150,16 +163,7 @@ func (h *JSONSignHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) { http.Error(rw, "POST required", 400) return case "camli/sig/discovery": - m := map[string]interface{}{ - "publicKeyId": h.entity.PrimaryKey.KeyIdString(), - "signHandler": base + "camli/sig/sign", - "verifyHandler": base + "camli/sig/verify", - } - if h.pubKeyBlobRef != nil { - m["publicKeyBlobRef"] = h.pubKeyBlobRef.String() - m["publicKey"] = base + h.pubKeyBlobRefServeSuffix - } - httputil.ReturnJSON(rw, m) + httputil.ReturnJSON(rw, h.discoveryMap(base)) return } case "POST": diff --git a/pkg/server/ui.go b/pkg/server/ui.go index 23b8f4590..2d135daf1 100644 --- a/pkg/server/ui.go +++ b/pkg/server/ui.go @@ -77,6 +77,7 @@ type UIHandler struct { prefix string // of the UI handler itself root *RootHandler + sigh *JSONSignHandler // or nil Cache blobserver.Storage // or nil sc ScaledImage // cache for scaled images, optional @@ -101,6 +102,13 @@ func newUIFromConfig(ld blobserver.Loader, conf jsonconfig.Obj) (h http.Handler, return } + if ui.JSONSignRoot != "" { + h, _ := ld.GetHandler(ui.JSONSignRoot) + if sigh, ok := h.(*JSONSignHandler); ok { + ui.sigh = sigh + } + } + ui.PublishRoots = make(map[string]*PublishHandler) for _, pubRoot := range pubRoots { h, err := ld.GetHandler(pubRoot) @@ -295,6 +303,9 @@ func (ui *UIHandler) populateDiscoveryMap(m map[string]interface{}) { "directoryHelper": path.Join(ui.prefix, "tree") + "/", "publishRoots": pubRoots, } + if ui.sigh != nil { + uiDisco["signing"] = ui.sigh.discoveryMap(ui.JSONSignRoot) + } for k, v := range uiDisco { if _, ok := m[k]; ok { log.Fatalf("Duplicate discovery key %q", k)