Skip to content

Commit

Permalink
extract ca test function
Browse files Browse the repository at this point in the history
  • Loading branch information
SciLor committed Oct 2, 2024
1 parent c4fce1f commit 9d770e1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
1 change: 1 addition & 0 deletions include/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -648,5 +648,6 @@ bool settings_set_by_string_id(const char *item, const char *value, uint8_t sett
void settings_load_all_certs();
error_t settings_try_load_certs_id(uint8_t settingsId);
error_t settings_load_certs_id(uint8_t settingsId);
bool test_boxine_ca(uint8_t settingsId);

#endif
48 changes: 28 additions & 20 deletions src/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -1597,33 +1597,14 @@ error_t settings_try_load_certs_id(uint8_t settingsId)
load_cert("internal.client.crt", "core.client_cert.file.crt", "core.client_cert.data.crt", settingsId);
load_cert("internal.client.key", "core.client_cert.file.key", "core.client_cert.data.key", settingsId);

const char *client_ca_crt = settings_get_string("internal.client.ca");

size_t boxine_ca_length = 2008;
size_t ca_length = osStrlen(client_ca_crt);
if (ca_length > 0)
{
if (ca_length != boxine_ca_length)
{
TRACE_WARNING("Client CA length mismatch %" PRIuSIZE " expected %" PRIuSIZE "\r\n", ca_length, boxine_ca_length);
}
else
{
if (osStrstr(client_ca_crt, "MC0JveGluZSBHbW") == NULL // Boxine GmbH
|| osStrstr(client_ca_crt, "DAlCb3hpbmUgQ") == NULL) // Boxine
{
TRACE_WARNING("Client CA does not match Boxine\r\n");
}
}
}
test_boxine_ca(settingsId);

const char *server_crt = settings_get_string("internal.server.crt");
const char *server_ca_crt = settings_get_string("internal.server.ca");

char *chain = custom_asprintf("%s%s", server_crt, server_ca_crt);
settings_set_string_id("internal.server.cert_chain", chain, settingsId);
osFreeMem(chain);

return NO_ERROR;
}

Expand All @@ -1648,3 +1629,30 @@ error_t settings_load_certs_id(uint8_t settingsId)

return NO_ERROR;
}

bool test_boxine_ca(uint8_t settingsId)
{
const char *client_ca_crt = settings_get_string_id("internal.client.ca", settingsId);

size_t boxine_ca_length = 2008;
size_t ca_length = osStrlen(client_ca_crt);
if (ca_length > 0)
{
if (ca_length != boxine_ca_length)
{
TRACE_WARNING("Client CA length mismatch %" PRIuSIZE " expected %" PRIuSIZE "\r\n", ca_length, boxine_ca_length);
return false;
}
else
{
if (osStrstr(client_ca_crt, "MC0JveGluZSBHbW") == NULL // Boxine GmbH
|| osStrstr(client_ca_crt, "DAlCb3hpbmUgQ") == NULL) // Boxine
{
TRACE_WARNING("Client CA does not match Boxine\r\n");
return false;
}
}
return true;
}
return false;
}

0 comments on commit 9d770e1

Please sign in to comment.