Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http/client: use dynamically sized buffers for PEM setters #1117

Merged
merged 1 commit into from
May 15, 2024
Merged
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
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
Loading