diff --git a/pkg/importer/importer.go b/pkg/importer/importer.go index b99739a08..a5cba9639 100644 --- a/pkg/importer/importer.go +++ b/pkg/importer/importer.go @@ -29,6 +29,8 @@ import ( "camlistore.org/pkg/blob" "camlistore.org/pkg/blobserver" "camlistore.org/pkg/jsonconfig" + "camlistore.org/pkg/jsonsign/signhandler" + "camlistore.org/pkg/schema" "camlistore.org/pkg/search" "camlistore.org/pkg/server" ) @@ -39,6 +41,7 @@ type Host struct { target blobserver.StatReceiver search *search.Handler + signer *schema.Signer // client optionally specifies how to fetch external network // resources. If nil, http.DefaultClient is used. @@ -290,8 +293,17 @@ func (h *Host) InitHandler(hl blobserver.FindHandlerByTyper) error { } h.target = rh.Storage + _, handler, _ = hl.FindHandlerByType("jsonsign") + if sigh, ok := handler.(*signhandler.Handler); ok { + h.signer = sigh.Signer() + } + if h.signer == nil { + return errors.New("importer requires a 'jsonsign' handler") + } + ro, err := h.RootObject() log.Printf("Got a %#v, %v", ro, err) + log.Printf("Signer = %s", h.signer) return nil } diff --git a/pkg/jsonsign/signhandler/sig.go b/pkg/jsonsign/signhandler/sig.go index 2dd1bf0ec..1f9ac66d3 100644 --- a/pkg/jsonsign/signhandler/sig.go +++ b/pkg/jsonsign/signhandler/sig.go @@ -55,8 +55,11 @@ type Handler struct { pubKeyWritten bool entity *openpgp.Entity + signer *schema.Signer } +func (h *Handler) Signer() *schema.Signer { return h.signer } + func (h *Handler) secretRingPath() string { if h.secretRing != "" { return h.secretRing @@ -114,6 +117,11 @@ func newJSONSignFromConfig(ld blobserver.Loader, conf jsonconfig.Obj) (http.Hand Fetcher: ms, } + h.signer, err = schema.NewSigner(h.pubKeyBlobRef, strings.NewReader(armoredPublicKey), h.entity) + if err != nil { + return nil, err + } + return h, nil } diff --git a/pkg/schema/sign.go b/pkg/schema/sign.go index b4d6d7f22..793daf791 100644 --- a/pkg/schema/sign.go +++ b/pkg/schema/sign.go @@ -42,6 +42,10 @@ type Signer struct { baseSigReq jsonsign.SignRequest } +func (s *Signer) String() string { + return fmt.Sprintf("[*schema.Signer for key=%s pubkey=%s]", s.keyId, s.pubref) +} + // NewSigner returns an Signer given an armored public key's blobref, // its armored content, and its associated private key entity. // The privateKeySource must be either an *openpgp.Entity or a string filename to a secret key. diff --git a/pkg/serverconfig/serverconfig.go b/pkg/serverconfig/serverconfig.go index 15939e380..fb283d02c 100644 --- a/pkg/serverconfig/serverconfig.go +++ b/pkg/serverconfig/serverconfig.go @@ -168,12 +168,23 @@ func makeCamliHandler(prefix, baseURL string, storage blobserver.Storage, hf blo } func (hl *handlerLoader) FindHandlerByType(htype string) (prefix string, handler interface{}, err error) { - for prefix, config := range hl.config { + nFound := 0 + for pfx, config := range hl.config { if config.htype == htype { - return prefix, hl.handler[prefix], nil + nFound++ + prefix, handler = pfx, hl.handler[pfx] } } - return "", nil, blobserver.ErrHandlerTypeNotFound + if nFound == 0 { + return "", nil, blobserver.ErrHandlerTypeNotFound + } + if htype == "jsonsign" && nFound > 1 { + // TODO: do this for all handler types later? audit + // callers of FindHandlerByType and see if that's + // feasible. For now I'm only paranoid about jsonsign. + return "", nil, fmt.Errorf("%d handlers found of type %q; ambiguous", nFound, htype) + } + return } func (hl *handlerLoader) setupAll() {