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 Digest Auth #2785

Open
wants to merge 1 commit into
base: v4.3-stable
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
2 changes: 2 additions & 0 deletions include/libwebsockets/lws-client.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ struct lws_client_connect_info {
* context template to take a copy of for this wsi. Used to isolate
* wsi-specific logs into their own stream or file.
*/
const char *auth_username;
const char *auth_password;

/* Add new things just above here ---^
* This is part of the ABI, don't needlessly break compatibility
Expand Down
2 changes: 1 addition & 1 deletion include/libwebsockets/lws-misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ lws_json_simple_strcmp(const char *buf, size_t len, const char *name, const char
* string.
*/
LWS_VISIBLE LWS_EXTERN int
lws_hex_to_byte_array(const char *h, uint8_t *dest, int max);
lws_hex_to_byte_array(const char *h, int hlen_or_minus1, uint8_t *dest, int max);

/**
* lws_hex_from_byte_array(): render byte array as hex char string
Expand Down
2 changes: 2 additions & 0 deletions lib/core-net/client/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ lws_client_connect_via_info(const struct lws_client_connect_info *i)
cisin[CIS_METHOD] = i->method;
cisin[CIS_IFACE] = i->iface;
cisin[CIS_ALPN] = i->alpn;
cisin[CIS_USERNAME] = i->auth_username;
cisin[CIS_PASSWORD] = i->auth_password;

if (lws_client_stash_create(wsi, cisin))
goto bail;
Expand Down
6 changes: 6 additions & 0 deletions lib/core-net/client/connect2.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ lws_client_connect_2_dnsreq(struct lws *wsi)
goto solo;
}

if (wsi->keepalive_rejected) {
lwsl_notice("defeating pipelining due to no "
"keepalive on server\n");
goto solo;
}

/* only pipeline things we associate with being a stream */

if (meth && strcmp(meth, "RAW") && strcmp(meth, "GET") &&
Expand Down
2 changes: 2 additions & 0 deletions lib/core-net/private-lib-core-net.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ enum {
CIS_METHOD,
CIS_IFACE,
CIS_ALPN,
CIS_USERNAME,
CIS_PASSWORD,


CIS_COUNT
Expand Down
28 changes: 25 additions & 3 deletions lib/core/libwebsockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,14 @@ signed char char_to_hex(const char c)
}

int
lws_hex_to_byte_array(const char *h, uint8_t *dest, int max)
lws_hex_to_byte_array(const char *h, int hlen_or_minus1, uint8_t *dest, int max)
{
uint8_t *odest = dest;

while (max-- && *h) {
if (hlen_or_minus1 != -1 && (hlen_or_minus1 & 1))
return -1;

while ((hlen_or_minus1 == -1 || hlen_or_minus1 > 1) && max-- && *h) {
int t = char_to_hex(*h++), t1;

if (!*h || t < 0)
Expand All @@ -150,7 +153,7 @@ lws_hex_to_byte_array(const char *h, uint8_t *dest, int max)
if (max < 0)
return -1;

return lws_ptr_diff(dest, odest);
return (int)(dest - odest);
}

static char *hexch = "0123456789abcdef";
Expand All @@ -171,6 +174,25 @@ lws_hex_from_byte_array(const uint8_t *src, size_t slen, char *dest, size_t len)
*dest = '\0';
}

int
lws_byte_array_to_hex(const uint8_t *src, size_t len, char *dest, size_t dlen)
{
char *odest = dest;

if (dlen < (2 * len) + 1)
return -1;

while (len--) {
*dest++ = hexch[(*src) >> 4];
*dest++ = hexch[(*src) & 15];
src++;
}

*dest = '\0';

return (int)(dest - odest);
}

int
lws_hex_random(struct lws_context *context, char *dest, size_t len)
{
Expand Down
Loading