コード例 #1
0
func ClientSender(client *Client) {
	for {
		input := <-client.Outgoing
		if input[0] == 0x00 {
			break
		} //TODO add cleanup quit bool
		for _, clientz := range RoomList[client.Room].Clients {
			//TODO rename to client connections = ClientList
			temp := append([]byte(nil), input...)
			dbgMsg.Printf("NAME	: %s", input[10:30])
			dbgMsg.Printf("ROOMNAME	: %s", input[30:50])
			dbgMsg.Printf("PRECRYPT	: %s", input[50:])

			e := []byte(nil)
			if input[1] == 0xAE {
				e, _ = barrenoid.Encrypt(clientz.AES_Key, input[50:])
			} else {
				e = input[50:]
			}

			x := append(input[:50], e...)
			dbgMsg.Printf("SENDING: % X", x)
			_, err := clientz.Conn.Write(x)
			chkError(err)
			input = temp
		}
	}
	dbgMsg.Println("Client sender done.")
}
コード例 #2
0
func Test_BarrenoidAes(t *testing.T) {
	testString := []byte("Test Encrypted Message 123")
	encryptedTestString, _ := barrenoid.Encrypt(AES_KEY, testString)
	//fmt.Printf("E: %X\n", encryptedTestString)
	decryptedPayload, _ := barrenoid.Decrypt(AES_KEY, encryptedTestString)
	//fmt.Printf("D: %X - %s\n", decryptedPayload, decryptedPayload)
	if string(testString) != string(decryptedPayload) {
		t.Fatalf("Incorrect payload: % s != % s", testString, decryptedPayload)
	}
}
コード例 #3
0
func Test_ChangeNameEncrypted(t *testing.T) {
	testString := []byte("NewName123Encrypted")
	encryptedTestString, _ := barrenoid.Encrypt(AES_KEY, testString)
	CONN.Write(build(CHANGE_NAME, AES_ENCRYPTION, encryptedTestString))
	reply := readServer()
	cmdBitResp, encBitResp, tsResp, nameStringResp, roomStringResp, payloadResp := parseServerProtocol(reply)
	decryptedPayload, _ := barrenoid.Decrypt(AES_KEY, payloadResp)
	valid, msg := validateHeader(DATA, cmdBitResp, AES_ENCRYPTION, encBitResp, tsResp, string(testString), nameStringResp, "GeneralChat", roomStringResp)

	if valid != true {
		t.Fatalf(msg)
	}
	if string(decryptedPayload) != "Changed Name" {
		t.Fatalf("Incorrect payload: % X != % X", payloadResp, testString)
	}
}
コード例 #4
0
func Test_EncryptedMessage(t *testing.T) {
	testString := []byte("Test Encrypted Message 123")
	encryptedTestString, _ := barrenoid.Encrypt(AES_KEY, testString)
	CONN.Write(build(DATA, AES_ENCRYPTION, encryptedTestString))
	reply := readServer()
	cmdBitResp, encBitResp, tsResp, nameStringResp, roomStringResp, payloadResp := parseServerProtocol(reply)
	decryptedPayload, _ := barrenoid.Decrypt(AES_KEY, payloadResp)
	valid, msg := validateHeader(DATA, cmdBitResp, AES_ENCRYPTION, encBitResp, tsResp, "Anonymous", nameStringResp, "GeneralChat", roomStringResp)

	if valid != true {
		t.Fatalf(msg)
	}
	if string(decryptedPayload) != string(testString) {
		t.Fatalf("Incorrect payload: % X != % X", decryptedPayload, testString)
	}
}