mirror of https://github.com/perkeep/perkeep.git
Create & sign permanodes.
This commit is contained in:
parent
21d33c9b6a
commit
c761e1afc8
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue