Skip to content
Snippets Groups Projects
Commit 88efd329 authored by Vlad-Andrei BĂDOIU (78692)'s avatar Vlad-Andrei BĂDOIU (78692)
Browse files

lab11: fix TODO ordering

parent 51c84018
No related branches found
No related tags found
No related merge requests found
...@@ -51,7 +51,7 @@ void handle_encrypted_message(int source, char *data, size_t size) ...@@ -51,7 +51,7 @@ void handle_encrypted_message(int source, char *data, size_t size)
switch (source) { switch (source) {
case SRC_ALICE: case SRC_ALICE:
if (!key_retrieved) { if (!key_retrieved) {
// TODO 6. Steal the key from Alice in the first step // TODO 2. Steal the key from Alice in the first step
key_retrieved = 1; key_retrieved = 1;
return; return;
} }
...@@ -64,7 +64,7 @@ void handle_encrypted_message(int source, char *data, size_t size) ...@@ -64,7 +64,7 @@ void handle_encrypted_message(int source, char *data, size_t size)
printf("Unknown source: %d\n", source); printf("Unknown source: %d\n", source);
} }
fflush(stdout); fflush(stdout);
// TODO 6. Use the stolen key to decrypt the intercepted message // TODO 2. Use the stolen key to decrypt the intercepted message
} }
void handle_dh_message(int source, char *data, size_t size) void handle_dh_message(int source, char *data, size_t size)
...@@ -80,14 +80,14 @@ void handle_dh_message(int source, char *data, size_t size) ...@@ -80,14 +80,14 @@ void handle_dh_message(int source, char *data, size_t size)
switch (source) { switch (source) {
case SRC_ALICE: case SRC_ALICE:
if (!exchange_done) { if (!exchange_done) {
// TODO 8.1 Intercept Alice's first message. // TODO 4.1 Intercept Alice's first message.
// Create your own secret, calculate the shared value // Create your own secret, calculate the shared value
// and send it to Bob (by overwriting "data") // and send it to Bob (by overwriting "data")
// Calculate the secret key shared with Alice. // Calculate the secret key shared with Alice.
return; return;
} else { } else {
// TODO 8.3 Use the key for Alice to decrypt the // TODO 4.3 Use the key for Alice to decrypt the
// message and print it // message and print it
// Then use the key for Bob to encrypt it back and // Then use the key for Bob to encrypt it back and
// send it to Bob (overwrite "data") // send it to Bob (overwrite "data")
...@@ -96,13 +96,13 @@ void handle_dh_message(int source, char *data, size_t size) ...@@ -96,13 +96,13 @@ void handle_dh_message(int source, char *data, size_t size)
break; break;
case SRC_BOB: case SRC_BOB:
if (!exchange_done) { if (!exchange_done) {
// TODO 8.2 Intercept Bob's message. // TODO 4.2 Intercept Bob's message.
// send your shared value to Alice (by overwriting "data") // send your shared value to Alice (by overwriting "data")
// Calculate the secret key shared with Bob. // Calculate the secret key shared with Bob.
exchange_done = 1; exchange_done = 1;
return; return;
} else { } else {
// TODO 8.3 Use the key for Bob to decrypt the // TODO 4.3 Use the key for Bob to decrypt the
// message and print it // message and print it
// Then use the key for Alice to encrypt it back and // Then use the key for Alice to encrypt it back and
// send it to Bob (overwrite "data") // send it to Bob (overwrite "data")
...@@ -169,6 +169,7 @@ int main(int argc, char *argv[]) ...@@ -169,6 +169,7 @@ int main(int argc, char *argv[])
DIE(res < 0, "inet_pton"); DIE(res < 0, "inet_pton");
/* The code below handles the forwarding between Bob and Alice. */
while (1) { while (1) {
struct packet pkt; struct packet pkt;
......
...@@ -50,13 +50,13 @@ void run_client(int sockfd) { ...@@ -50,13 +50,13 @@ void run_client(int sockfd) {
uint32_t *obtain_key_plain(int sockfd) uint32_t *obtain_key_plain(int sockfd)
{ {
// TODO 5. Generate the key and send it to Bob. Use create_key from tea.h // TODO 1. Generate the key and send it to Bob. Use create_key from tea.h
return NULL; return NULL;
} }
uint32_t *obtain_key_dh(int sockfd) uint32_t *obtain_key_dh(int sockfd)
{ {
// TODO 7. Perform DH using the primitives in "include/dh.h". Use derive_key with the // TODO 3. Perform DH using the primitives in "include/dh.h". Use derive_key with the
// secret as argument. We do this because the key and the secret don't necessarly have // secret as argument. We do this because the key and the secret don't necessarly have
// the same size or structure. // the same size or structure.
return NULL; return NULL;
...@@ -66,11 +66,11 @@ void run_encryption_client(int sockfd) { ...@@ -66,11 +66,11 @@ void run_encryption_client(int sockfd) {
int res; int res;
struct message msg; struct message msg;
// TODO 7. Comment this and uncomment the next line // TODO 3. Comment this and uncomment the next line
/*uint32_t *key = obtain_key_plain(sockfd);*/ /*uint32_t *key = obtain_key_plain(sockfd);*/
uint32_t *key = obtain_key_dh(sockfd); uint32_t *key = obtain_key_dh(sockfd);
while (1) { while (1) {
// TODO 5. just like run_client, read a string, send it to the // TODO 1. just like run_client, read a string, send it to the
// sever, then receive a reply and print it // sever, then receive a reply and print it
// but the request will need to be encrypted and the reply // but the request will need to be encrypted and the reply
// decrypted // decrypted
...@@ -111,7 +111,7 @@ int main(int argc, char *argv[]) ...@@ -111,7 +111,7 @@ int main(int argc, char *argv[])
DIE(rc < 0, "connect"); DIE(rc < 0, "connect");
run_client(sockfd); run_client(sockfd);
// TODO 5: We will now use the run_ecryption_client // TODO 1: We will now use the run_ecryption_client
//run_encryption_client(sockfd); //run_encryption_client(sockfd);
// Inchidem conexiunea si socketul creat // Inchidem conexiunea si socketul creat
......
...@@ -51,13 +51,13 @@ void run_server(int sockfd) { ...@@ -51,13 +51,13 @@ void run_server(int sockfd) {
uint32_t *obtain_key_plain(int sockfd) uint32_t *obtain_key_plain(int sockfd)
{ {
// TODO 5. Get the key from Alice. // TODO 1. Get the key from Alice.
return NULL; return NULL;
} }
uint32_t *obtain_key_dh(int sockfd) uint32_t *obtain_key_dh(int sockfd)
{ {
// TODO 7. Perform DH using the primitives in "include/dh.h". Use derive_key with the // TODO 3. Perform DH using the primitives in "include/dh.h". Use derive_key with the
// secret as argument. We do this because the key and the secret don't necessarly have // secret as argument. We do this because the key and the secret don't necessarly have
// the same size or structure. // the same size or structure.
return NULL; return NULL;
...@@ -68,12 +68,12 @@ void run_secure_server(int sockfd) ...@@ -68,12 +68,12 @@ void run_secure_server(int sockfd)
int res; int res;
struct message msg; struct message msg;
// TODO 7. Comment this and uncomment the next line // TODO 3. Comment this and uncomment the next line
uint32_t *key = obtain_key_plain(sockfd); uint32_t *key = obtain_key_plain(sockfd);
/*uint32_t *key = obtain_key_dh(sockfd);*/ /*uint32_t *key = obtain_key_dh(sockfd);*/
while (1) { while (1) {
// TODO 5. just like run_server, receive a message, process it, // TODO 1. just like run_server, receive a message, process it,
// then send a reply; // then send a reply;
// but the incoming message will be encrypted so we need to // but the incoming message will be encrypted so we need to
// decrypt and the outgoing reply needs to be encrypted as well. // decrypt and the outgoing reply needs to be encrypted as well.
...@@ -125,7 +125,7 @@ int main(int argc, char *argv[]) { ...@@ -125,7 +125,7 @@ int main(int argc, char *argv[]) {
int clientfd = accept(listenfd, NULL, NULL); int clientfd = accept(listenfd, NULL, NULL);
DIE(clientfd == -1, "accept"); DIE(clientfd == -1, "accept");
// TODO 5. Comment this and uncomment the next line // TODO 1. Comment this and uncomment the next line
run_server(clientfd); run_server(clientfd);
/*run_secure_server(clientfd);*/ /*run_secure_server(clientfd);*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment