Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Few bug fixes in the sample code. #5

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions example/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ void parseHostPathAndPort(char* url, char** out_hostname, char** out_path,
port = strtol(p, &endptr, 10);
if (endptr == p) {
printf("Invalid port number\n");
free(hostname);
usage();
}
p = endptr;
Expand All @@ -152,6 +153,7 @@ void parseHostPathAndPort(char* url, char** out_hostname, char** out_path,
} else {
if (*p != '/') {
printf("Expecting / in url\n");
free(hostname);
usage();
}
path = copystring(p);
Expand Down Expand Up @@ -532,6 +534,7 @@ void closeConnection(Connection* connection) {
printf("closing connection\n");
SSL_shutdown(connection->ssl);
SSL_free(connection->ssl);
SSL_CTX_free(connection->ctx);
close(connection->server_fd);
free(connection);
}
Expand Down Expand Up @@ -726,27 +729,28 @@ int main(int argc, char** argv) {
if (type == HTTP_UNKNOWN) {
usage();
}
char* hostname;
char* path;
int port;
char* hostname, *path, *tbheader, *cookies, *response, *etld_plus1;
int ret = 1, port;
CookieJar *cookie_jar;
Oracle *oracle;

parseHostPathAndPort(argv[2], &hostname, &path, &port);
Connection* connection = openConnection(hostname, port);
if (connection == NULL) {
printf("Could not connect to %s:%u\n", hostname, port);
return 1;
goto err;
}
if (connection->key_type == TB_INVALID_KEY_TYPE) {
printf("The server did not negotiate token binding\n");
return 1;
goto err;
}
char* etld_plus1 = getETLDPlus1(hostname);
etld_plus1 = getETLDPlus1(hostname);
printf("eTLD+1=%s\n", etld_plus1);
Oracle* oracle = readOracleKeys();
CookieJar* cookie_jar = readCookieJar();
char* tbheader =
oracle = readOracleKeys();
cookie_jar = readCookieJar();
tbheader =
generateTokenBindingHeader(connection, oracle, etld_plus1, NULL);
char* cookies = findCookies(cookie_jar, hostname);
char* response;
cookies = findCookies(cookie_jar, hostname);
if (type == HTTP_GET) {
response =
sendGetRequest(connection, hostname, port, path, tbheader, cookies);
Expand All @@ -762,6 +766,15 @@ int main(int argc, char** argv) {
processSetCookies(cookie_jar, response, hostname);
saveCookieJar(cookie_jar);
saveOracleKeys(oracle);
ret = 0;

err:
if (hostname != NULL) {
free(hostname);
}
if (path != NULL) {
free(path);
}
closeConnection(connection);
return 0;
return ret;
}
4 changes: 2 additions & 2 deletions example/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ void closeConnection(Connection* connection) {
char* readRequest(Connection* connection) {
char buffer[kBufferSize];
int num_bytes = SSL_read(connection->ssl, buffer, kBufferSize);
buffer[num_bytes] = '\0';
if (num_bytes <= 0) {
printf("Could not read with return val %u\n", num_bytes);
return NULL;
}
buffer[num_bytes] = '\0';
printf("Here is the message:\n%s\n", buffer);
return copystring(buffer);
}
Expand Down Expand Up @@ -379,7 +379,7 @@ bool getRequestTokenBindingID(char* request, Connection* connection,
char* tbheader = findRequestHeader(request, "sec-token-binding");
if (tbheader == NULL) {
printf("No token binding header in request\n");
return NULL;
return false;
}
printf("Found token binding header: %s\n", tbheader);
uint8_t* referred_tokbind_id;
Expand Down
2 changes: 1 addition & 1 deletion token_bind_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ static void cacheAdd(tbCache* cache, const uint8_t* message,
}
if (cache->num_message_hashes == 0) {
cache->message_hashes = calloc(2, sizeof(uint64_t));
if (cache == NULL) {
if (cache->message_hashes == NULL) {
cache->status = TB_CACHE_MEMORY_ERROR;
return;
}
Expand Down