From 962d65877d16d21da352e8850c4f179f55b015dc Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 5 May 2011 16:41:00 -0700 Subject: [PATCH] some sig discovery work --- lib/go/camli/blobref/fetcher.go | 6 +++--- server/go/camlistored/sig.go | 13 ++++++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/go/camli/blobref/fetcher.go b/lib/go/camli/blobref/fetcher.go index 1ea3fbd3b..fb1597864 100644 --- a/lib/go/camli/blobref/fetcher.go +++ b/lib/go/camli/blobref/fetcher.go @@ -120,9 +120,9 @@ type MemoryStore struct { m map[string]string } -func (s *MemoryStore) AddBlob(hashtype crypto.Hash, data string) os.Error { +func (s *MemoryStore) AddBlob(hashtype crypto.Hash, data string) (*BlobRef, os.Error) { if hashtype != crypto.SHA1 { - return os.NewError("blobref: unsupported hash type") + return nil, os.NewError("blobref: unsupported hash type") } hash := hashtype.New() hash.Write([]byte(data)) @@ -134,7 +134,7 @@ func (s *MemoryStore) AddBlob(hashtype crypto.Hash, data string) os.Error { } s.m[bstr] = data log.Printf("added %s", bstr) - return nil + return Parse(bstr), nil } func (s *MemoryStore) FetchStreaming(b *BlobRef) (file io.ReadCloser, size int64, err os.Error) { diff --git a/server/go/camlistored/sig.go b/server/go/camlistored/sig.go index e35e3e7f9..05aa5841d 100644 --- a/server/go/camlistored/sig.go +++ b/server/go/camlistored/sig.go @@ -29,6 +29,7 @@ import ( "strings" "camli/blobref" + "camli/httputil" "camli/jsonconfig" "camli/jsonsign" ) @@ -45,6 +46,7 @@ type JSONSignHandler struct { // of the longer forms. keyId string + pubKeyBlobRef *blobref.BlobRef pubKeyFetcher blobref.StreamingFetcher entity *openpgp.Entity @@ -100,7 +102,7 @@ func createJSONSignHandler(conf jsonconfig.Obj) (http.Handler, os.Error) { log.Printf("got key: %s", buf.String()) ms := new(blobref.MemoryStore) - err = ms.AddBlob(crypto.SHA1, buf.String()) + h.pubKeyBlobRef, err = ms.AddBlob(crypto.SHA1, buf.String()) if err != nil { return nil, err } @@ -111,6 +113,15 @@ func createJSONSignHandler(conf jsonconfig.Obj) (http.Handler, os.Error) { func (h *JSONSignHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) { switch req.Method { + case "GET": + if strings.HasSuffix(req.URL.Path, "/camli/sig/discovery") { + m := map[string]interface{}{} + if h.pubKeyBlobRef != nil { + m["publicKeyBlobRef"] = h.pubKeyBlobRef.String() + } + httputil.ReturnJson(rw, m) + return + } case "POST": switch { case strings.HasSuffix(req.URL.Path, "/camli/sig/sign"):