Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pcom-laboratoare-public
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tudor-Andrei CORNESCU
pcom-laboratoare-public
Commits
88efd329
Commit
88efd329
authored
1 year ago
by
Vlad-Andrei BĂDOIU (78692)
Browse files
Options
Downloads
Patches
Plain Diff
lab11: fix TODO ordering
parent
51c84018
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lab11/attacker.c
+7
-6
7 additions, 6 deletions
lab11/attacker.c
lab11/client.c
+5
-5
5 additions, 5 deletions
lab11/client.c
lab11/server.c
+5
-5
5 additions, 5 deletions
lab11/server.c
with
17 additions
and
16 deletions
lab11/attacker.c
+
7
−
6
View file @
88efd329
...
@@ -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
;
...
...
This diff is collapsed.
Click to expand it.
lab11/client.c
+
5
−
5
View file @
88efd329
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
lab11/server.c
+
5
−
5
View file @
88efd329
...
@@ -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);*/
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment