Download Latest Version 0.1.0.zip (7.2 kB)
Email in envelope

Get an email when there's a new version of server-client-chat

Home
Name Modified Size InfoDownloads / Week
README.md 2021-04-26 6.9 kB
0.1.0.zip 2021-04-26 7.2 kB
Totals: 2 Items   14.0 kB 0

TCP Server-Client Chat

Author: Atharv Sonwane

This projects is a rudimentary version of a chat application which uses a server to relay encrypted messages between two clients. Note that the project is very bare bones and developed more to learn about networking than for actual use.

Instructions

  1. Run the make command in the terminal while inside the project directory.
  2. This should generate the server and client executables in the same directory.
  3. Run the server executable with ./server <port>.
  4. Run the client executable with ./client <server ip> <server port> <your private key> <their public key>.
  5. Run the client executable in another terminal with the same format
  6. Typing in the terminal in either client will send the message to the other client.

Example

  • Terminal 0: ./server 2000
  • Terminal 1: ./client 0.0.0.0 2000 client1/private_key.pem client2/public_key.pem
  • Terminal 2: ./client 0.0.0.0 4000 client2/private_key.pem client1/public_key.pem

Outputs

Terminal 0:

$ ./server 2000

server running at 0.0.0.0:2000

serving client 0 at 127.0.0.1

serving client 1 at 127.0.0.1

sent 128 / 128 bytes from 127.0.0.1 to 127.0.0.1

sent 128 / 128 bytes from 127.0.0.1 to 127.0.0.1

sent 128 / 128 bytes from 127.0.0.1 to 127.0.0.1

sent 128 / 128 bytes from 127.0.0.1 to 127.0.0.1

sent 128 / 128 bytes from 127.0.0.1 to 127.0.0.1

closing connection with 127.0.0.1
closing connection with 127.0.0.1

Terminal 1:

$ ./client 0.0.0.0 2000 client1/private_key.pem client2/public_key.pem 

connected to server at 0.0.0.0
server ready

hello there
sent 128 / 128 bytes

received 128 bytes
ciphertext:
----------------
2b01411ffffffc5ffffff93ffffffe0ffffffb51a7225ffffffe4ffffff86ffffff9546ffffffdaffffffddffffff8ce394bffffffc7324affffffdeffffffdcffffffbf5affffffd0ffffff8045ffffff808ffffff8fffffffd66affffff835a6b3cffffff90ffffffb2ffffff8ae21ffffffe0ffffffd4ffffffe5ffffffef324372fffffff5ffffffe4effffffd2ffffffd66287b4763ffffffc6ffffffc9ffffff9d24ffffff8d68ffffff8dffffffb3ffffffa05bffffff975824ffffffadffffffdeffffffb83ffffffaeffffffbcffffffd5ffffffb16effffffb1ffffffd35fffffff90ffffffb9ffffffb036ffffffdb6c626f9674a4bffffff967ffffffff2ffffffd04576ffffffb9ffffff88ffffffe0ffffffb9ffffffff1fffffffa1ffffff9cffffffcaffffffc3ffffffd66dffffffb2ffffffd5571842ffffffd8ffffff9932ffffff9517
----------------

plaintext:
----------------
hey, nice to see you
----------------

looks like these messages are secret!
sent 128 / 128 bytes

received 128 bytes
ciphertext:
----------------
5dffffffa42cfffffff96f3e2cffffffd2245235ffffff904963ffffff892affffff8c7259ffffffb018ffffff88ffffffbbfffffff47352685941ffffffa7ffffff9fffffffd37c5affffff96ffffffa23effffff8cffffffb0cffffffbd4effffff86ffffffabffffff842fffffffb74a65623034ffffff8d21ffffff90724f69ffffff9e2a1f3affffff9d41ffffff85ffffffd0ffffffbfffffffdd32ffffffea2bffffff9bffffffe0ffffffb56bffffffc8ffffffb1ffffff8971ffffffbe7dffffffd375ffffffb9ffffffa57e3effffffbf1f3952ffffffca19ffffffa64efffffff23fffffff82fffffff85b59ffffff9affffffc8ffffff99ffffff977c4affffffc22f2fffffffb819ffffffa6ffffff937722ffffffb4fffffffeffffffe9ffffff9887ffffffff6c7c442bffffffc3
----------------

plaintext:
----------------
thats what they want you to think ...
----------------

received 128 bytes
closing connection due to exit instruction

Terminal 2:

$ ./client 0.0.0.0 4000 client2/private_key.pem client1/public_key.pem 

connected to server at 0.0.0.0
server ready

received 128 bytes
ciphertext:
----------------
223c67ffffffe4ffffffdd50ffffffb9ffffffb13a246affffffaeffffffa6ffffffbd7a17ffffff8effffffa8ffffffd0ffffffcbffffffa2ffffffb3573efffffff4fffffff963afffffff33f1cffffffa9ffffffad5260ffffffbcffffffc7ffffffbd7effffffa7ffffffafffffffddffffffa85411fffffffb2effffffd04f243bffffffab70ffffff9bffffff81164dffffffe6ffffffc0ffffffbaffffffa947fffffff6fffffff8228ffffffed4ffffffbcffffff855affffffeffffffffd7affffffa4ffffffc629135fffffffa5ffffffe3ffffffc7771ffffff96ffffff9dffffffa32511ffffffb7ffffff9048ffffff8effffff8022ffffffb85bffffff9c731fffffffd33effffffa3ffffffa4ffffff8673ffffffc8286945563d5c385f20133ffffffb470ffffffa2ffffffaffffffffe1111ffffff9bffffffaf73
----------------

plaintext:
----------------
hello there
----------------

hey, nice to see you
sent 128 / 128 bytes

received 128 bytes
ciphertext:
----------------
31ffffffe7ffffffa9ffffffb217fffffff974ffffffcaffffffe8fffffffd7c1affffffedffffff952632ffffffe66510ffffffe3ffffff8cffffffcebfffffffd7bffffffc4263513726fffffffcffffffabffffffa1ffffffc9ffffff87ffffffe7ffffff92ffffffb1ffffff826e5624ffffffc7ffffffac2640ffffffdc1d45175a20ffffffbfffffffaeffffff9010ffffff8affffffcfffffff89ffffff925f306d44ffffff9240fffffff572c60ffffff93391a5dffffff9efffffff2ffffffadffffffa520ffffffea46effffffe7514bffffffedffffffe1ffffffdcffffffd157ffffff88ffffffc053ffffff9bffffffafffffffc35b32d784c6714ffffffc665ffffffba39ffffffbe2dffffff96ffffffbad291e34ffffffdfffffffcf3f58ffffff85ffffffd356ffffffd055fffffff2ffffffa835
----------------

plaintext:
----------------
looks like these messages are secret!
----------------

thats what they want you to think ...
sent 128 / 128 bytes

exit
sent 128 / 128 bytes

closing connection due to exit instruction

Explanation

We start the server in Terminal 0 (T0), client 0 (c0) in Terminal 1 (T1) and client 1 (c1) in Terminal 2 (T2). We pass each client their private key and the public key of the other client as well as the server address and port.

Once both clients are started, we see the message server ready appeach on both T1 and T2 while ther server (at T0) displays that it has successfully connected to both clients.

Once everything is ready, we typed the message hello there into client 0's prompt (at T1). This is received by ther server and sent to the client and becomes visible at client 1's prompt along with the cipher text in hexadecimal (at T2). The server logs to T0 the number of bytes it transfered between the clients.

This procedure is repeated for the messages in the following order:

C1 -> C0: hey, nice to see you C0 -> C1: looks like these messages are secret! C1 -> C0: thats what they want us to think...

At this point the message exit is entered into C0's prompt (T1). This is sent to C1 but not displayed. After this both clients close their connection. The server also logs to T0 that it has closed its connections with both clients.

With this the conversation is complete and the server is ready to accept further clients.

NOTE:

  • Two pairs of private and public keys have been provided in client1/ and client2/ for testing purposes.

  • If another client tries to connect to the server while two clients are already connected, it is turned away gracefully.

  • If the server is closed (with a Cntrl+C) while two clients are connected, both clients also exit gracefully.

  • The ciphertext is displayed in hexadecimal format

Source: README.md, updated 2021-04-26