Skip to content

Commit

Permalink
httpauth: remove SHA1 support
Browse files Browse the repository at this point in the history
  • Loading branch information
cHuberCoffee committed Sep 14, 2023
1 parent b809a94 commit 5b79d61
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 93 deletions.
20 changes: 5 additions & 15 deletions src/httpauth/digest.c
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ int httpauth_digest_response_print(struct re_printf *pf,
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 nonce_counter)
uint32_t cnonce, uint32_t nonce_counter)
{
int err = 0, n = 0;

Expand Down Expand Up @@ -972,25 +972,15 @@ int httpauth_digest_response_full(struct httpauth_digest_enc_resp **presp,
goto out;
}

if (pl_strstr(&chall->algorithm, "SHA256-sess")) {
if (pl_strstr(&chall->algorithm, "SHA-256-sess")) {
resp->hashh = &sha256;
resp->hash_length = SHA256_DIGEST_LENGTH;
err = str_dup(&resp->algorithm, "SHA256-sess");
err = str_dup(&resp->algorithm, "SHA-256-sess");
}
else if (pl_strstr(&chall->algorithm, "SHA256")) {
else if (pl_strstr(&chall->algorithm, "SHA-256")) {
resp->hashh = &sha256;
resp->hash_length = SHA256_DIGEST_LENGTH;
err = str_dup(&resp->algorithm, "SHA256");
}
else if (pl_strstr(&chall->algorithm, "SHA1-sess")) {
resp->hashh = &sha1;
resp->hash_length = SHA_DIGEST_LENGTH;
err = str_dup(&resp->algorithm, "SHA1-sess");
}
else if (pl_strstr(&chall->algorithm, "SHA1")) {
resp->hashh = &sha1;
resp->hash_length = SHA_DIGEST_LENGTH;
err = str_dup(&resp->algorithm, "SHA1");
err = str_dup(&resp->algorithm, "SHA-256");
}
else if (pl_strstr(&chall->algorithm, "MD5-sess")) {
resp->hashh = &md5;
Expand Down
89 changes: 11 additions & 78 deletions test/httpauth.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,38 +374,23 @@ int test_httpauth_digest_request(void)
},
{
"Digest realm=\"/my/home\", qop=\"auth\","
" nonce=\"%s\", algorithm=SHA256",
" nonce=\"%s\", algorithm=SHA-256",
"/my/home", NULL, "localhost:5060", NULL, false,
"SHA256", "auth", NULL, false, 0
"SHA-256", "auth", NULL, false, 0
},
{
"Digest realm=\"/my/home\", qop=\"auth\","
" nonce=\"%s\", algorithm=SHA256-sess, stale=true",
" nonce=\"%s\", algorithm=SHA-256-sess, stale=true",
"/my/home", NULL, "localhost:5060", NULL, true,
"SHA256-sess", "auth", NULL, false, 0
"SHA-256-sess", "auth", NULL, false, 0
},
{
"Digest realm=\"/my/home\", qop=\"auth\","
" nonce=\"%s\", algorithm=SHA1,"
" stale=true, userhash=true",
"/my/home", NULL, "localhost:5060", NULL, true,
"SHA1", "auth", NULL, true, 0
},
{
"Digest realm=\"/my/home\", qop=\"auth\","
" nonce=\"%s\", algorithm=SHA1-sess,"
" domain=\"example.com\", stale=true,"
" charset=\"UTF-8\", userhash=true",
"/my/home", "example.com", "localhost:5060", NULL,
true, "SHA1-sess", "auth", "UTF-8", true, 0
},
{
"Digest realm=\"/my/home\", qop=\"auth\","
" nonce=\"%s\", algorithm=SHA256,"
" nonce=\"%s\", algorithm=SHA-256,"
" domain=\"example.com\", stale=true,"
" charset=\"UTF-8\", userhash=true",
"/my/home", "example.com", "localhost:5060", NULL,
true, "SHA256", "auth", "UTF-8", true, 0
true, "SHA-256", "auth", "UTF-8", true, 0
},
{
"Digest realm=\"/my/home\", qop=\"auth-int\","
Expand All @@ -415,14 +400,6 @@ int test_httpauth_digest_request(void)
"/my/home", "example.com", "localhost:5060", NULL,
true, "MD5-sess", "auth-int", "UTF-8", true, 0
},
{
"Digest realm=\"/my/home\", qop=\"auth-int\","
" nonce=\"%s\", algorithm=SHA1-sess,"
" domain=\"example.com\", stale=true,"
" charset=\"UTF-8\", userhash=true",
"/my/home", "example.com", "213579023", NULL,
true, "SHA1-sess", "auth-int", "UTF-8", true, 0
},
{
"Digest realm=\"/my/home\", qop=\"auth-int\","
" nonce=\"%s\", algorithm=MD5,"
Expand Down Expand Up @@ -550,29 +527,7 @@ int test_httpauth_digest_response(void)
PL("b5c64f319d37323ac652b77012817ccaa"
"6e9a7e4e7563155f1f9556414dd4615"),
PL("324DF3428BCF42D29A"), PL_INIT,
PL("SHA1"), PL("auth"), PL_INIT, PL_INIT,
PL_INIT
},
"retest", "sec_pwd_retest", "auth", PL("GET"),
"example.com/my/home/something", NULL,
"417bd44d62c73baa0f0291fb36d4777878369544",

"Digest realm=\"/my/home\","
" nonce=\"b5c64f319d37323ac652b77012817ccaa6e9a"
"7e4e7563155f1f9556414dd4615\","" username=\"retest\","
" uri=\"example.com/my/home/something\","
" response=\"417bd44d62c73baa0f0291fb36d4777878"
"369544\", opaque=\"324DF3428BCF42D29A\","
" algorithm=SHA1, qop=auth, cnonce=\"deadbeef\","
" nc=\"00000001\"",
},
{
{
PL("/my/home"),
PL("b5c64f319d37323ac652b77012817ccaa"
"6e9a7e4e7563155f1f9556414dd4615"),
PL("324DF3428BCF42D29A"), PL_INIT,
PL("SHA256"), PL("auth"), PL_INIT, PL_INIT,
PL("SHA-256"), PL("auth"), PL_INIT, PL_INIT,
PL_INIT
},
"retest", "sec_pwd_retest", "auth", PL("GET"),
Expand All @@ -586,7 +541,7 @@ int test_httpauth_digest_response(void)
" uri=\"example.com/my/home/something\","
" response=\"c22b56ce81bbb59570f0fbbc0ba27210dbbfcb2b2"
"3fea371d214722f319dc41c\","
" opaque=\"324DF3428BCF42D29A\", algorithm=SHA256,"
" opaque=\"324DF3428BCF42D29A\", algorithm=SHA-256,"
" qop=auth, cnonce=\"deadbeef\", nc=\"00000001\"",
},
{
Expand Down Expand Up @@ -616,30 +571,8 @@ int test_httpauth_digest_response(void)
PL("b5c64f319d37323ac652b77012817ccaa"
"6e9a7e4e7563155f1f9556414dd4615"),
PL("324DF3428BCF42D29A"), PL_INIT,
PL("SHA1"), PL("auth-int"), PL_INIT, PL_INIT,
PL_INIT
},
"retest", "sec_pwd_retest", "auth-int", PL("GET"),
"example.com/my/home/something", "a text body",
"1565b20cc176a3eed8cd0318600cf3caf96fd23c",

"Digest realm=\"/my/home\","
" nonce=\"b5c64f319d37323ac652b77012817ccaa6e9a7e4e756"
"3155f1f9556414dd4615\", username=\"retest\","
" uri=\"example.com/my/home/something\","
" response=\"1565b20cc176a3eed8cd0318600cf3caf96f"
"d23c\", opaque=\"324DF3428BCF42D29A\","
" algorithm=SHA1, qop=auth-int, cnonce=\"deadbeef\","
" nc=\"00000001\"",
},
{
{
PL("/my/home"),
PL("b5c64f319d37323ac652b77012817ccaa"
"6e9a7e4e7563155f1f9556414dd4615"),
PL("324DF3428BCF42D29A"), PL_INIT,
PL("SHA256"), PL("auth-int"), PL_INIT, PL_INIT,
PL_INIT
PL("SHA-256"), PL("auth-int"), PL_INIT,
PL_INIT, PL_INIT
},
"retest", "sec_pwd_retest", "auth-int", PL("GET"),
"example.com/my/home/something", "",
Expand All @@ -652,7 +585,7 @@ int test_httpauth_digest_response(void)
" uri=\"example.com/my/home/something\","
" response=\"2c0746b7174441314164d8d9a980d8920732de32e"
"16303f0e6a82970230e79e4\","
" opaque=\"324DF3428BCF42D29A\", algorithm=SHA256,"
" opaque=\"324DF3428BCF42D29A\", algorithm=SHA-256,"
" qop=auth-int, cnonce=\"deadbeef\", nc=\"00000001\"",
},
};
Expand Down

0 comments on commit 5b79d61

Please sign in to comment.