From: Stephan Bosch Date: Sat, 4 Mar 2023 16:21:37 +0000 (+0100) Subject: auth: mech-digest-md5 - Move types to source file X-Git-Tag: 2.4.2~330 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e3e8eccf8796a1100032389eeee3cd30eb60b3ba;p=thirdparty%2Fdovecot%2Fcore.git auth: mech-digest-md5 - Move types to source file These were exposed for testing, but exposing the whole struct is excessive. Putting the struct in the source file is consistent with the other mechanisms and this test is going to be restructured so that this internal access is no longer needed. --- diff --git a/src/auth/mech-digest-md5-private.h b/src/auth/mech-digest-md5-private.h index fb9ff803a7..00f69f14c5 100644 --- a/src/auth/mech-digest-md5-private.h +++ b/src/auth/mech-digest-md5-private.h @@ -3,36 +3,7 @@ #include "auth-request.h" -enum qop_option { - QOP_AUTH = 0x01, /* authenticate */ - QOP_AUTH_INT = 0x02, /* + integrity protection, not supported yet */ - QOP_AUTH_CONF = 0x04, /* + encryption, not supported yet */ - - QOP_COUNT = 3 -}; - -struct digest_auth_request { - struct auth_request auth_request; - - pool_t pool; - - /* requested: */ - char *nonce; - enum qop_option qop; - - /* received: */ - char *username; - char *cnonce; - char *nonce_count; - char *qop_value; - char *digest_uri; /* may be NULL */ - char *authzid; /* may be NULL, authorization ID */ - unsigned char response[32]; - unsigned long maxbuf; - bool nonce_found:1; - - /* final reply: */ - char *rspauth; -}; +void mech_digest_test_set_nonce(struct auth_request *auth_request, + const char *nonce); #endif diff --git a/src/auth/mech-digest-md5.c b/src/auth/mech-digest-md5.c index bdd1cff492..6f5fe5b118 100644 --- a/src/auth/mech-digest-md5.c +++ b/src/auth/mech-digest-md5.c @@ -18,6 +18,38 @@ /* Linear whitespace */ #define IS_LWS(c) ((c) == ' ' || (c) == '\t') +enum qop_option { + QOP_AUTH = 0x01, /* authenticate */ + QOP_AUTH_INT = 0x02, /* + integrity protection, not supported yet */ + QOP_AUTH_CONF = 0x04, /* + encryption, not supported yet */ + + QOP_COUNT = 3 +}; + +struct digest_auth_request { + struct auth_request auth_request; + + pool_t pool; + + /* requested: */ + char *nonce; + enum qop_option qop; + + /* received: */ + char *username; + char *cnonce; + char *nonce_count; + char *qop_value; + char *digest_uri; /* may be NULL */ + char *authzid; /* may be NULL, authorization ID */ + unsigned char response[32]; + unsigned long maxbuf; + bool nonce_found:1; + + /* final reply: */ + char *rspauth; +}; + static const char *qop_names[] = { "auth", "auth-int", "auth-conf" }; static_assert_array_size(qop_names, QOP_COUNT); @@ -598,3 +630,14 @@ const struct mech_module mech_digest_md5 = { mech_digest_md5_auth_continue, mech_generic_auth_free }; + +void mech_digest_test_set_nonce(struct auth_request *auth_request, + const char *nonce) +{ + struct digest_auth_request *request = + container_of(auth_request, struct digest_auth_request, + auth_request); + + i_assert(auth_request->mech == &mech_digest_md5); + request->nonce = p_strdup(request->pool, nonce); +} diff --git a/src/auth/test-mech.c b/src/auth/test-mech.c index 6df98234d4..4ada604119 100644 --- a/src/auth/test-mech.c +++ b/src/auth/test-mech.c @@ -143,9 +143,7 @@ test_mech_handle_challenge(struct auth_request *request, str_truncate(out, 0); str_append(out, "testuser b913a602c7eda7a495b4e6e7334d3890"); } else if (request->mech == &mech_digest_md5) { - struct digest_auth_request *digest_request = - (struct digest_auth_request *) request; - digest_request->nonce = "OA6MG9tEQGm2hh"; + mech_digest_test_set_nonce(request, "OA6MG9tEQGm2hh"); } auth_request_continue(request, out->data, out->used); }