Skip to content

Commit

Permalink
fix(s2nd): parse psk given to s2nd non-destructively (aws#4006)
Browse files Browse the repository at this point in the history
* fix: use stuffer for psk params

* specify precision when printing the psk identity

* fix formatting

* cast token pointer

* Copy the string instead of using stuffer

* Remove empty line

* remove empty line

* fix comment format
  • Loading branch information
WesleyRosenblum committed May 15, 2023
1 parent 73f1639 commit 8584b89
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion bin/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,13 @@ static int s2n_setup_external_psk(struct s2n_psk **psk, char *params)
GUARD_EXIT_NULL(psk);
GUARD_EXIT_NULL(params);

/* duplicate params as strtok will modify the input string */
char *params_dup = malloc(strlen(params) + 1);
GUARD_EXIT_NULL(params_dup);
strcpy(params_dup, params);

size_t token_idx = 0;
for (char *token = strtok(params, ","); token != NULL; token = strtok(NULL, ","), token_idx++) {
for (char *token = strtok(params_dup, ","); token != NULL; token = strtok(NULL, ","), token_idx++) {
switch (token_idx) {
case 0:
GUARD_EXIT(s2n_psk_set_identity(*psk, (const uint8_t *) token, strlen(token)),
Expand All @@ -288,6 +293,7 @@ static int s2n_setup_external_psk(struct s2n_psk **psk, char *params)
}
}

free(params_dup);
return S2N_SUCCESS;
}

Expand Down
2 changes: 1 addition & 1 deletion bin/echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ int print_connection_info(struct s2n_connection *conn)
uint8_t *identity = (uint8_t *) malloc(identity_length);
GUARD_EXIT_NULL(identity);
GUARD_EXIT(s2n_connection_get_negotiated_psk_identity(conn, identity, identity_length), "Error getting negotiated psk identity from the connection\n");
printf("Negotiated PSK identity: %s\n", identity);
printf("Negotiated PSK identity: %.*s\n", identity_length, identity);
free(identity);
}

Expand Down

0 comments on commit 8584b89

Please sign in to comment.