func (id *IndexDeps) uploadAndSign(m *schema.Builder) blob.Ref { m.SetSigner(id.SignerBlobRef) unsigned, err := m.JSON() if err != nil { id.Fatalf("uploadAndSignMap: " + err.Error()) } sr := &jsonsign.SignRequest{ UnsignedJSON: unsigned, Fetcher: id.PublicKeyFetcher, EntityFetcher: id.EntityFetcher, SignatureTime: id.now, } signed, err := sr.Sign() if err != nil { id.Fatalf("problem signing: " + err.Error()) } tb := &test.Blob{Contents: signed} _, err = id.BlobSource.ReceiveBlob(tb.BlobRef(), tb.Reader()) if err != nil { id.Fatalf("public uploading signed blob to blob source, pre-indexing: %v, %v", tb.BlobRef(), err) } _, err = id.Index.ReceiveBlob(tb.BlobRef(), tb.Reader()) if err != nil { id.Fatalf("problem indexing blob: %v\nblob was:\n%s", err, signed) } return tb.BlobRef() }
func (h *Handler) Sign(bb *schema.Builder) (string, error) { bb.SetSigner(h.pubKeyBlobRef) unsigned, err := bb.JSON() if err != nil { return "", err } sreq := &jsonsign.SignRequest{ UnsignedJSON: unsigned, Fetcher: h.pubKeyFetcher, ServerMode: true, SecretKeyringPath: h.secretRing, } claimTime, err := bb.Blob().ClaimDate() if err != nil { if !schema.IsMissingField(err) { return "", err } } else { sreq.SignatureTime = claimTime } if err := h.uploadPublicKey(); err != nil { log.Printf("signing handler failed to upload public key: %v", err) } return sreq.Sign() }