Skip to content

Commit

Permalink
http/client: use dynamically sized buffers for PEM setters
Browse files Browse the repository at this point in the history
  • Loading branch information
maximilianfridrich committed May 13, 2024
1 parent 475573a commit b9f6f31
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/http/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
#define DEBUG_LEVEL 5
#include <re_dbg.h>

#define PEMBUF_SIZE 512

enum {
CONN_TIMEOUT = 30000,
RECV_TIMEOUT = 60000,
Expand Down Expand Up @@ -1108,8 +1106,9 @@ int http_client_set_cert(struct http_cli *cli, const char *path)

/**
* Set client certificate in PEM format
*
* @param cli HTTP Client
* @param pem Client certificate in PEM format
* @param pem Client certificate as 0-terminated string in PEM format
*
* @return 0 for success, error code otherwise.
*/
Expand All @@ -1120,11 +1119,19 @@ int http_client_set_certpem(struct http_cli *cli, const char *pem)
return EINVAL;

cli->cert = mem_deref(cli->cert);
cli->cert = mbuf_alloc(PEMBUF_SIZE);
cli->cert = mbuf_alloc(strlen(pem));
return mbuf_write_str(cli->cert, pem);
}


/**
* Set client key
*
* @param cli HTTP Client
* @param path File path to client key
*
* @return 0 for success, error code otherwise.
*/
int http_client_set_key(struct http_cli *cli, const char *path)
{
int err = 0;
Expand All @@ -1143,14 +1150,22 @@ int http_client_set_key(struct http_cli *cli, const char *path)
}


/**
* Set client key in PEM format
*
* @param cli HTTP Client
* @param pem Client key as 0-terminated string in PEM format
*
* @return 0 for success, error code otherwise.
*/
int http_client_set_keypem(struct http_cli *cli, const char *pem)
{
if (!cli || !str_isset(pem))
return EINVAL;

cli->key = mem_deref(cli->key);

cli->key = mbuf_alloc(PEMBUF_SIZE);
cli->key = mbuf_alloc(strlen(pem));
return mbuf_write_str(cli->key, pem);
}

Expand Down

0 comments on commit b9f6f31

Please sign in to comment.