Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mereacre committed Feb 27, 2024
1 parent 070b76c commit 0bfb175
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
31 changes: 15 additions & 16 deletions src/brski/brski.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include <cstdlib>
#include <mutex>
#include <string>
#include <vector>
#include <unistd.h>
#include <vector>

#include "masa/masa_server.hpp"
#include "pledge/pledge_request.hpp"
Expand All @@ -19,7 +19,7 @@ extern "C" {
#include "config.h"
#include "pledge/pledge_utils.h"

#define MAX_STDIN_SIZE 4096
#define MAX_STDIN_SIZE 4096

// declare here, since we pass a pointer to this to C code
void log_lock_fun(bool lock);
Expand Down Expand Up @@ -54,7 +54,8 @@ const std::array<struct command_config, 7> command_list = {{
{"preq", CommandId::COMMAND_PLEDGE_REQUEST,
"\tpreq\t\tSend a pledge-voucher request to the registrar and\n"
"\t\t\t return the pinned-domain-cert."},
{"vmasa", CommandId::COMMAND_VERIFY_MASA, "\tvmasa\t\tVerify masa pledge reply\n"},
{"vmasa", CommandId::COMMAND_VERIFY_MASA,
"\tvmasa\t\tVerify masa pledge reply\n"},
{"sign", CommandId::COMMAND_SIGN_CERT, "\tsign\t\tSign a certificate\n"},
{"serial", CommandId::COMMAND_GET_SERIAL,
"\tserial\t\tReturns the serial number of a certificate\n"},
Expand Down Expand Up @@ -224,10 +225,9 @@ void print_key(const char *key, int prefix) {
std::fprintf(stdout, "-----END PRIVATE KEY-----\n");
}

int read_stdin(uint8_t buf[])
{
int read_stdin(uint8_t buf[]) {
int cnt = 0;
while(read(STDIN_FILENO, &buf[cnt], 1) > 0) {
while (read(STDIN_FILENO, &buf[cnt], 1) > 0) {
cnt++;
if (cnt > MAX_STDIN_SIZE)
return -1;
Expand All @@ -237,8 +237,7 @@ int read_stdin(uint8_t buf[])
}

int output_domain_cert(struct BinaryArray *pinned_domain_cert,
std::string &out_filename)
{
std::string &out_filename) {
char outf[255];

if (out_filename.empty()) {
Expand All @@ -262,7 +261,6 @@ int output_domain_cert(struct BinaryArray *pinned_domain_cert,
return 0;
}


int main(int argc, char *argv[]) {
int verbose = 0;
unsigned int port = 0;
Expand Down Expand Up @@ -319,7 +317,7 @@ int main(int argc, char *argv[]) {
log_error("file_to_x509buf fail");
return EXIT_FAILURE;
}

if (out_filename.empty()) {
char *base64 =
voucher_pledge_request_to_base64(&config.pconf, tls_cert);
Expand Down Expand Up @@ -416,7 +414,7 @@ int main(int argc, char *argv[]) {
}

log_info("Verifying MASA response with registrar tsl cert at %s",
in_filename.c_str());
in_filename.c_str());

int sz = read_stdin(inbuf);
if (sz < 0) {
Expand All @@ -430,21 +428,22 @@ int main(int argc, char *argv[]) {
struct BinaryArray masa_pledge_voucher_cms = {};

if ((masa_pledge_voucher_cms.length =
serialize_base64str2array((const uint8_t *)inbuf, sz,
&masa_pledge_voucher_cms.array)) < 0) {
serialize_base64str2array((const uint8_t *)inbuf, sz,
&masa_pledge_voucher_cms.array)) < 0) {
log_errno("serialize_base64str2array fail");
return EXIT_FAILURE;
}

struct BinaryArray *registrar_tls_cert = file_to_x509buf(in_filename.c_str());
struct BinaryArray *registrar_tls_cert =
file_to_x509buf(in_filename.c_str());
if (registrar_tls_cert == NULL) {
log_error("file_to_keybuf fail");
return EXIT_FAILURE;
}

if (verify_masa_pledge_request(&config.pconf, &masa_pledge_voucher_cms,
registrar_tls_cert, &pinned_domain_cert) < 0)
{
registrar_tls_cert,
&pinned_domain_cert) < 0) {
log_error("verify_masa_pledge_request fail");
return EXIT_FAILURE;
}
Expand Down
9 changes: 3 additions & 6 deletions src/brski/pledge/pledge_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ extern "C" {
int verify_masa_pledge_request(struct pledge_config *pconf,
struct BinaryArray *masa_pledge_voucher_cms,
struct BinaryArray *registrar_tls_cert,
struct BinaryArray *pinned_domain_cert)
{
struct BinaryArray *pinned_domain_cert) {
struct BinaryArray *nonce = NULL;
struct BinaryArrayList *masa_verify_certs = NULL;
struct BinaryArrayList *masa_store_certs = NULL;
Expand Down Expand Up @@ -178,7 +177,6 @@ int post_voucher_pledge_request(struct pledge_config *pconf,
const char *masa_pledge_voucher_str = http_res.response.c_str();
struct BinaryArray masa_pledge_voucher_cms = {};


if ((masa_pledge_voucher_cms.length =
serialize_base64str2array((const uint8_t *)masa_pledge_voucher_str,
strlen(masa_pledge_voucher_str),
Expand All @@ -187,9 +185,8 @@ int post_voucher_pledge_request(struct pledge_config *pconf,
goto post_voucher_pledge_request_fail;
}

if (verify_masa_pledge_request(pconf,
&masa_pledge_voucher_cms, registrar_tls_cert, pinned_domain_cert) < 0)
{
if (verify_masa_pledge_request(pconf, &masa_pledge_voucher_cms,
registrar_tls_cert, pinned_domain_cert) < 0) {
log_errno("verify_masa_pledge_request fail");
goto post_voucher_pledge_request_fail;
}
Expand Down
3 changes: 2 additions & 1 deletion src/brski/pledge/pledge_request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ int post_sign_cert(struct pledge_config *pconf, struct registrar_config *rconf,
* registrar
*
* @param[in] pconf The pledge configuration structure
* @param[in] masa_pledge_voucher_cms The masa pledge request reply in CMS format
* @param[in] masa_pledge_voucher_cms The masa pledge request reply in CMS
* format
* @param[in] registrar_tls_cert The registrar certificate in DER format
* @param[out] pinned_domain_cert The pinned domain certificate in DER format
* @return int 0 on success, -1 on failure
Expand Down

0 comments on commit 0bfb175

Please sign in to comment.