コード例 #1
0
ファイル: revoke.go プロジェクト: wbl/ringauth
func main() {
	var err error
	var group = new(bbssig.Group)
	var sk = new(bbssig.PrivateKey)
	var part = new(bbssig.MemberKey)
	var rev *bbssig.Revocation
	var revbyte []byte
	var partfile *os.File
	partfile, err = os.Open(os.Args[1])
	if err != nil {
		log.Fatal(err)
	}
	var privfile *os.File
	privfile, err = os.Open(os.Args[2])
	if err != nil {
		log.Fatal(err)
	}
	var partreader = bufio.NewReader(partfile)
	var privreader = bufio.NewReader(privfile)
	/* Now we have a detail, namely need to skip some stuff from
	the part file before we can use it. But first load the
	private key*/
	{
		var gb = basepack.Unpack(privreader)
		var success bool
		_, success = group.Unmarshal(gb)
		if !success {
			log.Fatal("Could not load key")
		}
		var sb = basepack.Unpack(privreader)
		_, success = sk.Unmarshal(group, sb)
		if !success {
			log.Fatal("Could not load private key")
		}
	}
	{
		var success bool
		basepack.Unpack(partreader) /*Skip first entry*/
		var memb = basepack.Unpack(partreader)
		_, success = part.Unmarshal(group, memb)
		if !success {
			log.Fatal("Part could not be upacked")
		}
	}
	rev = sk.GenerateRevocation(part)
	revbyte = rev.Marshal()
	fmt.Printf("The revokation string is %s\n",
		base64.StdEncoding.EncodeToString(revbyte))
}
コード例 #2
0
ファイル: server_test.go プロジェクト: houndbee/pond
func TestRevocation(t *testing.T) {
	t.Parallel()

	message := []byte{1, 2, 3}
	var revocation *bbssig.Revocation

	runScript(t, script{
		numPlayers:             2,
		numPlayersWithAccounts: 1,
		actions: []action{
			{
				player: 0,
				buildRequest: func(s *scriptState) *pond.Request {
					memberKey, err := s.groupPrivateKeys[0].NewMember(rand.Reader)
					if err != nil {
						t.Errorf("Failed to create group member key: %s", err)
					}
					revocation = s.groupPrivateKeys[0].GenerateRevocation(memberKey)
					return &pond.Request{
						Revocation: &pond.SignedRevocation{
							Revocation: &pond.SignedRevocation_Revocation{
								Generation: proto.Uint32(0x1234),
								Revocation: revocation.Marshal(),
							},
							Signature: []byte{7, 8, 9},
						},
					}
				},
				validate: func(t *testing.T, reply *pond.Reply) {
					if reply.Status != nil {
						t.Errorf("Bad reply to revocation: %s", reply)
					}
				},
			},
			{
				player: 1,
				buildRequest: func(s *scriptState) *pond.Request {
					return s.buildDelivery(0, message, 0x1234)
				},
				validate: func(t *testing.T, reply *pond.Reply) {
					if reply.Status == nil || *reply.Status != pond.Reply_GENERATION_REVOKED {
						t.Errorf("Bad status to delivery request: %#v", reply)
					}
					if reply.Revocation == nil {
						t.Errorf("Missing revocation information: %#v", reply)
					}
				},
			},
			{
				player: 1,
				buildRequest: func(s *scriptState) *pond.Request {
					s.groupPrivateKeys[0].Update(revocation)
					return s.buildDelivery(0, message, 0x1235)
				},
				validate: func(t *testing.T, reply *pond.Reply) {
					if reply.Status != nil {
						t.Errorf("Bad reply to revocation: %s", reply)
					}
				},
			},
		},
	})
}