예제 #1
0
// Runs two conodes and tests if the value returned is OK
func TestStamp(t *testing.T) {
	dbg.TestOutput(testing.Verbose(), 4)
	peer1, peer2 := createPeers()
	go peer1.LoopRounds(conode.RoundStamperListenerType, 4)
	go peer2.LoopRounds(conode.RoundStamperListenerType, 4)
	time.Sleep(2 * time.Second)

	s, err := conode.NewStamp("testdata/config.toml")
	if err != nil {
		t.Fatal("Couldn't open config-file:", err)
	}

	for _, port := range []int{7000, 7010} {
		stamper := "localhost:" + strconv.Itoa(port)
		dbg.Lvl2("Contacting stamper", stamper)
		tsm, err := s.GetStamp([]byte("test"), stamper)
		dbg.Lvl3("Evaluating results of", stamper)
		if err != nil {
			t.Fatal("Couldn't get stamp from server:", err)
		}

		if !tsm.Srep.AggPublic.Equal(s.X0) {
			t.Fatal("Not correct aggregate public key")
		}
	}

	dbg.Lvl2("Closing peer1")
	peer1.Close()
	dbg.Lvl2("Closing peer2")
	peer2.Close()
	dbg.Lvl3("Done with test")
}
예제 #2
0
파일: stamp.go 프로젝트: mlncn/cothority
// Takes a 'file' to hash and being stamped at the 'server'. The output of the
// signing will be written to 'file'.sig
func StampFile(file, server string) {
	// Create the hash of the file and send it over the net
	myHash := hashFile(file)

	stamper, err := conode.NewStamp("config.toml")
	if err != nil {
		dbg.Fatal("Couldn't setup stamper:", err)
	}
	tsm, err := stamper.GetStamp(myHash, server)
	if err != nil {
		dbg.Fatal("Stamper didn't succeed:", err)
	}

	if err := tsm.Srep.Save(file + sigExtension); err != nil {
		dbg.Fatal("Could not write signature file:", err)
	}
	dbg.Lvl1("Signature file", file+".sig", "written.")

	dbg.Lvl1("Stamp OK - signature file", file+".sig", "written.")
}