Ejemplo n.º 1
0
func WriteProtobuf(conn *transport.Conn, message *proto.ClientToServer) error {
	unpadMsg, err := protobuf.Marshal(message)
	if err != nil {
		return err
	}
	_, err = conn.WriteFrame(proto.Pad(unpadMsg, proto.SERVER_MESSAGE_SIZE))
	return err
}
Ejemplo n.º 2
0
func (server *Server) writeProtobuf(conn *transport.Conn, outBuf []byte, message *proto.ServerToClient) error {
	unpadMsg, err := protobuf.Marshal(message)
	if err != nil {
		return err
	}
	padMsg := proto.Pad(unpadMsg, proto.SERVER_MESSAGE_SIZE)
	copy(outBuf, padMsg)
	conn.WriteFrame(outBuf[:proto.SERVER_MESSAGE_SIZE])
	return nil
}
Ejemplo n.º 3
0
func PrepareTestAccountDaemon(name string, rootDir string, denameConfig *denameClient.Config, serverAddr string, serverPk *[32]byte, t testing.TB) *Daemon {
	dnmClient, err := denameClient.NewClient(denameConfig, nil, nil)

	//get port from serverAddr
	addr, portStr, err := net.SplitHostPort(serverAddr)
	if err != nil {
		t.Fatal(err)
	}
	var port int
	if _, err := fmt.Sscanf(portStr, "%d", &port); err != nil {
		t.Fatal(err)
	}

	//create the accounts with Init
	torAddr := "DANGEROUS_NO_TOR"
	err = Init(rootDir, name, addr, port, serverPk, torAddr)
	if err != nil {
		t.Fatal(err)
	}

	//initialize daemon with Load
	theDaemon, err := Load(rootDir, denameConfig)
	if err != nil {
		t.Fatal(err)
	}

	cbProfile := new(proto.Profile)
	if err := persistence.UnmarshalFromFile(theDaemon.OurChatterboxProfilePath(), cbProfile); err != nil {
		t.Fatal(err)
	}

	chatProfileBytes, err := protobuf.Marshal(cbProfile)
	if err != nil {
		t.Fatal(err)
	}

	denameProfile, sk, err := denameClient.NewProfile(nil, nil)
	if err != nil {
		t.Fatal(err)
	}

	if err := denameClient.SetProfileField(denameProfile, cbClient.PROFILE_FIELD_ID, chatProfileBytes); err != nil {
		t.Fatal(err)
	}

	err = dnmClient.Register(sk, name, denameProfile, testutil2.MakeToken())
	if err != nil {
		t.Fatal(err)
	}

	return theDaemon
}
Ejemplo n.º 4
0
func TestMessageEncryptionAuthentication(t *testing.T) {
	t.Skip("apparently the tests can only run a single binary involving a dename server. this may have something to do with TCP TIME_WAIT. I (andres) am disabling this test to make the other one pass.")
	config, f := testutil.SingleServer(t)
	defer f()
	time.Sleep(100)

	ska, dnmca := createNewUser("Alice", t, config)
	skb, dnmcb := createNewUser("Bob", t, config)

	ratchA := &ratchet.Ratchet{
		FillAuth:  FillAuthWith(ska),
		CheckAuth: CheckAuthWith(noProfileRatchet(dnmca)),
		Rand:      nil,
		Now:       nil,
	}
	ratchB := &ratchet.Ratchet{
		FillAuth:  FillAuthWith(skb),
		CheckAuth: CheckAuthWith(noProfileRatchet(dnmcb)),
		Rand:      nil,
		Now:       nil,
	}

	//pka0, ska0, err := box.GenerateKey(rand.Reader)
	//handleError(err, t)
	pkb0, skb0, err := box.GenerateKey(rand.Reader)
	if err != nil {
		t.Fatal(err)
	}

	msg, err := protobuf.Marshal(&proto.Message{
		Subject:  "",
		Contents: []byte("Message"),
		Dename:   "Alice",
	})
	if err != nil {
		t.Fatal(err)
	}
	out := append([]byte{}, (*pkb0)[:]...)

	out = ratchA.EncryptFirst(out, msg, pkb0)
	msg2, err := ratchB.DecryptFirst(out[32:], skb0)
	if err != nil {
		t.Fatal(err)
	}

	if !bytes.Equal(msg, msg2) {
		t.Error("Original and decrypted message not the same.")
	}
}
Ejemplo n.º 5
0
func createNewUser(name string, t *testing.T, config *client.Config) (*[32]byte, *client.Client) {
	newClient, err := client.NewClient(config, nil, nil)
	if err != nil {
		t.Fatal(err)
	}

	//TODO: All these names are horrible, please change them
	pkAuth, skAuth, err := box.GenerateKey(rand.Reader)

	chatProfile := &proto.Profile{
		ServerAddressTCP:  "",
		ServerPortTCP:     -1,
		ServerTransportPK: (proto.Byte32)([32]byte{}),
		UserIDAtServer:    (proto.Byte32)([32]byte{}),
		KeySigningKey:     (proto.Byte32)([32]byte{}),
		MessageAuthKey:    (proto.Byte32)(*pkAuth),
	}

	chatProfileBytes, err := protobuf.Marshal(chatProfile)
	if err != nil {
		t.Fatal(err)
	}

	profile, sk, err := client.NewProfile(nil, nil)
	if err != nil {
		t.Fatal(err)
	}

	client.SetProfileField(profile, PROFILE_FIELD_ID, chatProfileBytes)

	err = newClient.Register(sk, name, profile, testutil2.MakeToken())
	if err != nil {
		t.Fatal(err)
	}

	//Remove this outside of the test
	profile2, err := newClient.Lookup(name)
	if !profile.Equal(profile2) {
		t.Error("Correct profile not added to server.")
		fmt.Printf("profile: %v\n", profile)
		fmt.Printf("profile2: %v\n", profile2)
	}

	return skAuth, newClient
}
Ejemplo n.º 6
0
func CreateTestDenameAccount(name string, denameClient *client.Client, secretConfig *proto.LocalAccountConfig, serverAddr string, serverPk *[32]byte, t testing.TB) {
	//TODO: move this to test?
	//TODO: All these names are horrible, please change them
	addr, portStr, err := net.SplitHostPort(serverAddr)
	if err != nil {
		t.Fatal(err)
	}
	var port int32
	if _, err := fmt.Sscanf(portStr, "%d", &port); err != nil {
		t.Fatal(err)
	}

	chatProfile := &proto.Profile{
		ServerAddressTCP:  addr,
		ServerPortTCP:     port,
		ServerTransportPK: (proto.Byte32)(*serverPk),
	}

	if err := GenerateLongTermKeys(secretConfig, chatProfile, rand.Reader); err != nil {
		t.Fatal(err)
	}

	chatProfileBytes, err := protobuf.Marshal(chatProfile)
	if err != nil {
		t.Fatal(err)
	}

	profile, sk, err := client.NewProfile(nil, nil)
	if err != nil {
		t.Fatal(err)
	}

	client.SetProfileField(profile, PROFILE_FIELD_ID, chatProfileBytes)

	err = denameClient.Register(sk, name, profile, testutil2.MakeToken())
	if err != nil {
		t.Fatal(err)
	}
}