diff --git a/clients/go/camput/camput.go b/clients/go/camput/camput.go index 6beeaf27a..157ddd4d0 100644 --- a/clients/go/camput/camput.go +++ b/clients/go/camput/camput.go @@ -9,7 +9,7 @@ import ( "camli/blobref" "camli/client" "camli/schema" -// "camli/jsonsign" + "camli/jsonsign" "crypto/sha1" "flag" "fmt" @@ -145,9 +145,34 @@ func (up *Uploader) UploadMap(m map[string]interface{}) (*client.PutResult, os.E return up.Upload(h) } +func (up *Uploader) SignMap(m map[string]interface{}) (string, os.Error) { + camliSigBlobref := up.Client.SignerPublicKeyBlobref() + if camliSigBlobref == nil { + // TODO: more helpful error message + return "", os.NewError("No public key configured.") + } + + m["camliSigner"] = camliSigBlobref.String() + unsigned, err := schema.MapToCamliJson(m) + if err != nil { + return "", err + } + sr := &jsonsign.SignRequest{ + UnsignedJson: unsigned, + Fetcher: up.Client.GetBlobFetcher(), + } + return sr.Sign() +} + func (up *Uploader) UploadNewPermanode() (*client.PutResult, os.Error) { unsigned := schema.NewUnsignedPermanode() - log.Printf("Got schema: %q", unsigned) + + signed, err := up.SignMap(unsigned) + if err != nil { + return nil, err + } + + log.Printf("Got signed permanode: %q", signed) return nil, nil } diff --git a/lib/go/jsonsign/sign.go b/lib/go/jsonsign/sign.go index 7de15d3b3..4b1d35644 100644 --- a/lib/go/jsonsign/sign.go +++ b/lib/go/jsonsign/sign.go @@ -62,7 +62,7 @@ func (sr *SignRequest) Sign() (signedJson string, err os.Error) { pk, err := openArmoredPublicKeyFile(pubkeyReader) if err != nil { - return execfail(fmt.Sprintf("failed to parse public key from blobref %s", signerBlob.String())) + return execfail(fmt.Sprintf("failed to parse public key from blobref %s: %v", signerBlob.String(), err)) } // This check should be redundant if the above JSON parse succeeded, but diff --git a/lib/go/schema/schema.go b/lib/go/schema/schema.go index a04ba6d8f..970108b09 100644 --- a/lib/go/schema/schema.go +++ b/lib/go/schema/schema.go @@ -8,7 +8,6 @@ import ( "fmt" "io" "json" - "log" "os" "rand" "strconv" @@ -65,7 +64,7 @@ func newCamliMap(version int, ctype string) map[string]interface{} { return m } -func NewUnsignedPermanode() string { +func NewUnsignedPermanode() map[string]interface{} { m := newCamliMap(1, "permanode") chars := make([]byte, 20) // Don't need cryptographically secure random here, as this @@ -75,11 +74,7 @@ func NewUnsignedPermanode() string { chars[idx] = byte(32 + rnd.Intn(126 - 32)) } m["random"] = string(chars) - unsigned, err := MapToCamliJson(m) - if err != nil { - log.Panicf("Unexpected error: %v", err) - } - return unsigned + return m } // Map returns a Camli map of camliType "static-set"