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

Httpauth digest response #944

Merged
merged 8 commits into from
Oct 20, 2023
Merged

Conversation

cHuberCoffee
Copy link
Contributor

No description provided.

@sreimers sreimers added this to the v3.6.0 milestone Sep 6, 2023
@@ -16,21 +16,37 @@
#include <re_httpauth.h>


enum {
CNONCE_NC_LENGTH = 9, /* 8 characters + '\0' */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps SIZE is better ?

if you know the length, why do you need a trailing null terminator ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renaming to CNONCE_NC_SIZE is a good idea.
The enum is meant for the string size when the uint32_t is hex encoded. I added the NULL terminator, so i don't need to add 1 whenever i handle the array/string.

/* HASH A2 */
if (str_isset(resp->qop) && str_str(resp->qop, "auth-int")) {
if (!entitybody || str_casecmp(entitybody, "") == 0) {
resp->hash_function((uint8_t *)"", str_len(""), hash1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps check if hash_function is set, otherwise it might crash.

perhaps also use the "handler" paradigm with a trailing h.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will change to the "handler" paradigm.
The check does not hurt so i will add it. Since digest_response is an static function, it gets called only after an successful set of the hash_function. That is the reason i didn't include the check.


/* HASH A2 */
if (str_isset(resp->qop) && str_str(resp->qop, "auth-int")) {
if (!entitybody || str_casecmp(entitybody, "") == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

str_len("") is always 0.

int httpauth_digest_response_set_cnonce(struct httpauth_digest_enc_resp *resp,
const struct httpauth_digest_chall *chall, const struct pl *method,
const char *user, const char *passwd, const char *entitybody,
const uint32_t cnonce, const uint32_t nc_)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove trailing underscore from "nc_"

const is not needed for params passed by value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to write out the nonce_count and nc is already an static internal variable. Therefore the underscore.
I will write it out and remove the const.

pl_strstr(&chall->algorithm, "MD5")) {
resp->hash_function = &md5;
resp->hash_length = MD5_SIZE;
err = str_dup(&resp->algorithm, "MD5");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should consider how to deal with weak crypto such as MD5 or SHA1.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SHA1 is not in the specification anyway, i can remove it as supported algorithm. MD5 on the other hand is the default fallback if no algorithm is specified. Also the MD5 is needed for backwards compatibility.

In the RFC there are 3 algorithms, MD5, SHA256 and SHA512-256. The SHA512-256 is a special case of SHA512 which is not implemented in re for now. I checked the microsoft and apple documentation and non of these two have an interface for SHA512-256. OpenSSL has the capability to implement it, but it is not a single function call like the others for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for now it should be enough with MD5 and SHA256.

I am wondering if we should add a global macro ENABLE_WEAK_CIPHERS that we can put around
the MD5 and SHA1 code... ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disabling the MD5 via an macro is quite risky. It might break a lot of digest authentication implementations.
For SHA1 on the other hand it would be a good idea since the SHA2 family should be used instead.

I will remove the SHA1 algorithm for now.

goto out;
}

n = re_snprintf(resp->nc, CNONCE_NC_SIZE, "%08x", nonce_counter);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can cnonce and nonce_counter be stored as is on the struct ?

And the printing to hex can be done when needed ?


n = re_snprintf(resp->nc, CNONCE_NC_SIZE, "%08x", nonce_counter);
if (n == -1 || n != CNONCE_NC_SIZE -1) {
err = ERANGE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this error code can be returned directly

char *username_star;
char *uri;
char *cnonce;
char *nc;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated, this can also be fixed size: char nc[8+1]

test/httpauth.c Outdated

int err;

for (unsigned int i = 0; i < RE_ARRAY_SIZE(testv); i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to use size_t for i here ...

@alfredh
Copy link
Contributor

alfredh commented Sep 17, 2023

Could you also please add a link to the relevant RFC ?

@cHuberCoffee
Copy link
Contributor Author

These are the two RFCs, the last, this, and the upcoming PRs are based on.
HTTP Digest Access Authentication: https://www.rfc-editor.org/rfc/rfc7616
The Session Initiation Protocol (SIP) Digest Access Authentication Scheme: https://www.rfc-editor.org/rfc/rfc8760

@@ -16,21 +16,37 @@
#include <re_httpauth.h>


enum {
CNONCE_NC_SIZE = 9, /* 8 characters + '\0' */
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this used ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right, its not used anymore. it was to store the cnonce and nc as strings
it is removed now

@alfredh
Copy link
Contributor

alfredh commented Sep 29, 2023

These are the two RFCs, the last, this, and the upcoming PRs are based on. HTTP Digest Access Authentication: https://www.rfc-editor.org/rfc/rfc7616 The Session Initiation Protocol (SIP) Digest Access Authentication Scheme: https://www.rfc-editor.org/rfc/rfc8760

could you also add RFC7617 to the README ?

I had one more comment, apart from that it looks ready to merge.

@alfredh alfredh removed this from the v3.6.0 milestone Sep 29, 2023
@alfredh
Copy link
Contributor

alfredh commented Oct 11, 2023

The next release (3.6.0) is scheduled for Wed 18. October.
Should we merge this before or after the release ?

@alfredh alfredh added this to the v3.7.0 milestone Oct 11, 2023
@cHuberCoffee
Copy link
Contributor Author

Sry for the late response. I can make the changes only after the 18th. So i would suggest to wait for the release and my last fixes. Then its ready to go for 3.7

@alfredh
Copy link
Contributor

alfredh commented Oct 14, 2023

Okay, it is scheduled for after 3.6.0 release

If you dont have time to work on fixing review comments, please consider to close the PR
and reopen it when you have time...

@cHuberCoffee cHuberCoffee force-pushed the httpauth_digest_response branch from e6a2361 to c0bcd40 Compare October 19, 2023 07:44
@cHuberCoffee
Copy link
Contributor Author

I'm not sure what happens in the FreeBSD test. But i looks like the test is hanging in an bootloop. I checked it and it gets the same output over and over again. Its running for over 3h right now. There is no other output than the repeating boot messages.

@sreimers
Copy link
Member

I've just disabled the FreeBSD workflow for now (until its more stable):

vmactions/freebsd-vm#74

@alfredh alfredh merged commit e922af5 into baresip:main Oct 20, 2023
34 of 35 checks passed
@cHuberCoffee cHuberCoffee deleted the httpauth_digest_response branch December 11, 2023 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants