예제 #1
0
func (k *KexCommon) poll(ctx *Context, m *kex.Meta, secret *kex.Secret) {
	token, csrf := k.sessionArgs(ctx)
	k.recMu.Lock()
	k.rec = kex.NewReceiver(m.Direction, secret, token, csrf, k.G())
	k.recMu.Unlock()
	k.wg.Add(1)
	go func() {
		k.rec.Poll(m)
		k.wg.Done()
	}()
}
예제 #2
0
// TestBasicMessage verifies that a message can be sent and
// received.
func TestBasicMessage(t *testing.T) {
	tc := SetupEngineTest(t, "kex")
	defer tc.Cleanup()

	fu := CreateAndSignupFakeUser(tc, "login")

	sec, err := kex.NewSecret(fu.Username)
	if err != nil {
		t.Fatal(err)
	}

	var tok, csrf string
	err = tc.G.LoginState().LocalSession(func(s *libkb.Session) {
		tok, csrf = s.APIArgs()
	}, "TestBasicMessage")
	if err != nil {
		t.Fatal(err)
	}

	s := kex.NewSender(kex.DirectionYtoX, sec.Secret(), tok, csrf, tc.G)
	r := kex.NewReceiver(kex.DirectionYtoX, sec, tok, csrf, tc.G)

	ctx := testKexMeta(t, fu.Username, sec)
	if err := s.StartKexSession(ctx, ctx.StrongID); err != nil {
		t.Fatal(err)
	}
	rctx := testKexMeta(t, fu.Username, sec)
	rctx.Swap()
	n, err := r.Receive(rctx)
	if err != nil {
		t.Fatal(err)
	}
	if n != 1 {
		t.Errorf("receive count: %d, expected 1", n)
	}
	select {
	case msg := <-r.Msgs:
		if msg.Name() != kex.StartKexMsg {
			t.Errorf("msg: %s, expected %s", msg.Name(), kex.StartKexMsg)
		}
	default:
		t.Fatal("no msg in r.Msgs")
	}
}
예제 #3
0
func TestBadMACMessage(t *testing.T) {
	tc := SetupEngineTest(t, "kex")
	defer tc.Cleanup()

	fu := CreateAndSignupFakeUser(tc, "login")

	sec, err := kex.NewSecret(fu.Username)
	if err != nil {
		t.Fatal(err)
	}

	var tok, csrf string
	err = tc.G.LoginState().LocalSession(func(s *libkb.Session) {
		tok, csrf = s.APIArgs()
	}, "TestBadMACMessage")
	if err != nil {
		t.Fatal(err)
	}

	s := kex.NewSender(kex.DirectionYtoX, sec.Secret(), tok, csrf, tc.G)
	r := kex.NewReceiver(kex.DirectionYtoX, sec, tok, csrf, tc.G)

	ctx := testKexMeta(t, fu.Username, sec)
	if err := s.CorruptStartKexSession(ctx, ctx.StrongID); err != nil {
		t.Fatal(err)
	}
	rctx := testKexMeta(t, fu.Username, sec)
	rctx.Swap()
	n, err := r.Receive(rctx)
	if err != nil {
		t.Fatal(err)
	}
	if n != 0 {
		t.Errorf("receive count: %d, expected 0", n)
	}
}