GNU libmicrohttpd 1.0.2
|
Implements HTTP digest authentication. More...
#include "digestauth.h"
#include "gen_auth.h"
#include "platform.h"
#include "mhd_limits.h"
#include "internal.h"
#include "response.h"
#include "mhd_locks.h"
#include "mhd_mono_clock.h"
#include "mhd_str.h"
#include "mhd_compat.h"
#include "mhd_bithelpers.h"
#include "mhd_assert.h"
Go to the source code of this file.
Macros | |
#define | REUSE_TIMEOUT 30 |
#define | DAUTH_JUMPBACK_MAX (0x7F) |
#define | TIMESTAMP_BIN_SIZE (48 / 8) |
#define | TRIM_TO_TIMESTAMP(value) |
#define | TIMESTAMP_CHARS_LEN (TIMESTAMP_BIN_SIZE * 2) |
#define | NONCE_STD_LEN(digest_size) |
#define | VLA_ARRAY_LEN_DIGEST(n) |
#define | VLA_CHECK_LEN_DIGEST(n) |
#define | MAX_USERNAME_LENGTH 128 |
#define | MAX_REALM_LENGTH 256 |
#define | MAX_AUTH_RESPONSE_LENGTH (MAX_DIGEST * 2) |
#define | MHD_DAUTH_EXT_PARAM_PREFIX "UTF-8'" |
#define | MHD_DAUTH_EXT_PARAM_MIN_LEN MHD_STATICSTR_LEN_ (MHD_DAUTH_EXT_PARAM_PREFIX "'") |
#define | digest_setup_zero(da) |
#define | digest_deinit(da) |
#define | digest_ext_error(da) |
#define | _MHD_STATIC_UNQ_BUFFER_SIZE 128 |
Enumerations | |
enum | MHD_CheckNonceNC_ { MHD_CHECK_NONCENC_OK = MHD_DAUTH_OK , MHD_CHECK_NONCENC_STALE = MHD_DAUTH_NONCE_STALE , MHD_CHECK_NONCENC_WRONG = MHD_DAUTH_NONCE_WRONG } |
enum | MHD_GetRqNCResult { MHD_GET_RQ_NC_NONE = -1 , MHD_GET_RQ_NC_VALID = 0 , MHD_GET_RQ_NC_TOO_LONG = 1 , MHD_GET_RQ_NC_TOO_LARGE = 2 , MHD_GET_RQ_NC_BROKEN = 3 } |
enum | _MHD_GetUnqResult { _MHD_UNQ_OK = 0 , _MHD_UNQ_TOO_LARGE = -7 , _MHD_UNQ_OUT_OF_MEM = 3 } |
Functions | |
_MHD_static_inline enum MHD_DigestBaseAlgo | get_base_digest_algo (enum MHD_DigestAuthAlgo3 algo3) |
_MHD_static_inline size_t | digest_get_hash_size (enum MHD_DigestAuthAlgo3 algo3) |
_MHD_EXTERN size_t | MHD_digest_get_hash_size (enum MHD_DigestAuthAlgo3 algo3) |
_MHD_static_inline unsigned int | digest_get_size (struct DigestAlgorithm *da) |
_MHD_static_inline bool | digest_init_one_time (struct DigestAlgorithm *da, enum MHD_DigestBaseAlgo algo) |
_MHD_static_inline void | digest_update (struct DigestAlgorithm *da, const void *data, size_t length) |
_MHD_static_inline void | digest_update_str (struct DigestAlgorithm *da, const char *str) |
_MHD_static_inline void | digest_update_with_colon (struct DigestAlgorithm *da) |
_MHD_static_inline void | digest_calc_hash (struct DigestAlgorithm *da, uint8_t *digest) |
_MHD_static_inline void | digest_reset (struct DigestAlgorithm *da) |
static bool | get_nonce_timestamp (const char *const nonce, size_t noncelen, uint64_t *const ptimestamp) |
static MHD_DATA_TRUNCATION_RUNTIME_CHECK_DISABLE_ uint32_t | fast_simple_hash (const uint8_t *data, size_t data_size) |
static MHD_DATA_TRUNCATION_RUNTIME_CHECK_RESTORE_ size_t | get_nonce_nc_idx (size_t arr_size, const char *nonce, size_t noncelen) |
static enum MHD_CheckNonceNC_ | check_nonce_nc (struct MHD_Connection *connection, const char *nonce, size_t noncelen, uint64_t nonce_time, uint64_t nc) |
_MHD_static_inline enum MHD_DigestAuthUsernameType | get_rq_uname_type (const struct MHD_RqDAuth *params) |
_MHD_static_inline size_t | get_rq_unames_size (const struct MHD_RqDAuth *params, enum MHD_DigestAuthUsernameType uname_type) |
static size_t | get_rq_param_unquoted_copy_z (const struct MHD_RqDAuthParam *param, char *buf) |
static ssize_t | get_rq_extended_uname_copy_z (const char *uname_ext, size_t uname_ext_len, char *buf, size_t buf_size) |
static size_t | get_rq_uname (const struct MHD_RqDAuth *params, enum MHD_DigestAuthUsernameType uname_type, struct MHD_DigestAuthUsernameInfo *uname_info, uint8_t *buf, size_t buf_size) |
static enum MHD_GetRqNCResult | get_rq_nc (const struct MHD_RqDAuth *params, uint32_t *nc) |
_MHD_EXTERN struct MHD_DigestAuthInfo * | MHD_digest_auth_get_request_info3 (struct MHD_Connection *connection) |
_MHD_EXTERN struct MHD_DigestAuthUsernameInfo * | MHD_digest_auth_get_username3 (struct MHD_Connection *connection) |
_MHD_EXTERN char * | MHD_digest_auth_get_username (struct MHD_Connection *connection) |
static void | calculate_nonce (uint64_t nonce_time, enum MHD_HTTP_Method mthd_e, const char *method, const char *rnd, size_t rnd_size, const struct sockaddr_storage *saddr, size_t saddr_size, const char *uri, size_t uri_len, const struct MHD_HTTP_Req_Header *first_header, const char *realm, size_t realm_len, unsigned int bind_options, struct DigestAlgorithm *da, char *nonce) |
static bool | is_slot_available (const struct MHD_NonceNc *const nn, const uint64_t now, const char *const new_nonce, size_t new_nonce_len) |
static bool | calculate_add_nonce (struct MHD_Connection *const connection, uint64_t timestamp, const char *realm, size_t realm_len, struct DigestAlgorithm *da, char *nonce) |
static MHD_DATA_TRUNCATION_RUNTIME_CHECK_DISABLE_ bool | calculate_add_nonce_with_retry (struct MHD_Connection *const connection, const char *realm, struct DigestAlgorithm *da, char *nonce) |
MHD_DATA_TRUNCATION_RUNTIME_CHECK_RESTORE_ _MHD_static_inline void | calc_userdigest (struct DigestAlgorithm *da, const char *username, const size_t username_len, const char *realm, const size_t realm_len, const char *password, uint8_t *ha1_bin) |
_MHD_EXTERN enum MHD_Result | MHD_digest_auth_calc_userdigest (enum MHD_DigestAuthAlgo3 algo3, const char *username, const char *realm, const char *password, void *userdigest_bin, size_t bin_buf_size) |
_MHD_static_inline void | calc_userhash (struct DigestAlgorithm *da, const char *username, const size_t username_len, const char *realm, const size_t realm_len, uint8_t *digest_bin) |
_MHD_EXTERN enum MHD_Result | MHD_digest_auth_calc_userhash (enum MHD_DigestAuthAlgo3 algo3, const char *username, const char *realm, void *userhash_bin, size_t bin_buf_size) |
_MHD_EXTERN enum MHD_Result | MHD_digest_auth_calc_userhash_hex (enum MHD_DigestAuthAlgo3 algo3, const char *username, const char *realm, char *userhash_hex, size_t hex_buf_size) |
static enum MHD_Result | test_header (void *cls, const char *key, size_t key_size, const char *value, size_t value_size, enum MHD_ValueKind kind) |
static bool | check_argument_match (struct MHD_Connection *connection, char *args) |
static bool | check_uri_match (struct MHD_Connection *connection, char *uri, size_t uri_len) |
static char * | get_buffer_for_size (char tmp1[_MHD_STATIC_UNQ_BUFFER_SIZE], char **ptmp2, size_t *ptmp2_size, size_t required_size) |
static enum _MHD_GetUnqResult | get_unquoted_param (const struct MHD_RqDAuthParam *param, char tmp1[_MHD_STATIC_UNQ_BUFFER_SIZE], char **ptmp2, size_t *ptmp2_size, struct _MHD_str_w_len *unquoted) |
static enum _MHD_GetUnqResult | get_unquoted_param_copy (const struct MHD_RqDAuthParam *param, char tmp1[_MHD_STATIC_UNQ_BUFFER_SIZE], char **ptmp2, size_t *ptmp2_size, struct _MHD_mstr_w_len *unquoted) |
_MHD_static_inline bool | is_param_equal (const struct MHD_RqDAuthParam *param, const char *const str, const size_t str_len) |
_MHD_static_inline bool | is_param_equal_caseless (const struct MHD_RqDAuthParam *param, const char *const str, const size_t str_len) |
static enum MHD_DigestAuthResult | digest_auth_check_all_inner (struct MHD_Connection *connection, const char *realm, const char *username, const char *password, const uint8_t *userdigest, unsigned int nonce_timeout, uint32_t max_nc, enum MHD_DigestAuthMultiQOP mqop, enum MHD_DigestAuthMultiAlgo3 malgo3, char **pbuf, struct DigestAlgorithm *da) |
static enum MHD_DigestAuthResult | digest_auth_check_all (struct MHD_Connection *connection, const char *realm, const char *username, const char *password, const uint8_t *userdigest, unsigned int nonce_timeout, uint32_t max_nc, enum MHD_DigestAuthMultiQOP mqop, enum MHD_DigestAuthMultiAlgo3 malgo3) |
_MHD_EXTERN int | MHD_digest_auth_check (struct MHD_Connection *connection, const char *realm, const char *username, const char *password, unsigned int nonce_timeout) |
_MHD_EXTERN enum MHD_DigestAuthResult | MHD_digest_auth_check3 (struct MHD_Connection *connection, const char *realm, const char *username, const char *password, unsigned int nonce_timeout, uint32_t max_nc, enum MHD_DigestAuthMultiQOP mqop, enum MHD_DigestAuthMultiAlgo3 malgo3) |
_MHD_EXTERN enum MHD_DigestAuthResult | MHD_digest_auth_check_digest3 (struct MHD_Connection *connection, const char *realm, const char *username, const void *userdigest, size_t userdigest_size, unsigned int nonce_timeout, uint32_t max_nc, enum MHD_DigestAuthMultiQOP mqop, enum MHD_DigestAuthMultiAlgo3 malgo3) |
_MHD_EXTERN int | MHD_digest_auth_check2 (struct MHD_Connection *connection, const char *realm, const char *username, const char *password, unsigned int nonce_timeout, enum MHD_DigestAuthAlgorithm algo) |
_MHD_EXTERN int | MHD_digest_auth_check_digest2 (struct MHD_Connection *connection, const char *realm, const char *username, const uint8_t *digest, size_t digest_size, unsigned int nonce_timeout, enum MHD_DigestAuthAlgorithm algo) |
_MHD_EXTERN int | MHD_digest_auth_check_digest (struct MHD_Connection *connection, const char *realm, const char *username, const uint8_t digest[MHD_MD5_DIGEST_SIZE], unsigned int nonce_timeout) |
static enum MHD_Result | queue_auth_required_response3_inner (struct MHD_Connection *connection, const char *realm, const char *opaque, const char *domain, struct MHD_Response *response, int signal_stale, enum MHD_DigestAuthMultiQOP mqop, enum MHD_DigestAuthMultiAlgo3 malgo3, int userhash_support, int prefer_utf8, char **buf_ptr, struct DigestAlgorithm *da) |
_MHD_EXTERN enum MHD_Result | MHD_queue_auth_required_response3 (struct MHD_Connection *connection, const char *realm, const char *opaque, const char *domain, struct MHD_Response *response, int signal_stale, enum MHD_DigestAuthMultiQOP mqop, enum MHD_DigestAuthMultiAlgo3 algo, int userhash_support, int prefer_utf8) |
_MHD_EXTERN enum MHD_Result | MHD_queue_auth_fail_response2 (struct MHD_Connection *connection, const char *realm, const char *opaque, struct MHD_Response *response, int signal_stale, enum MHD_DigestAuthAlgorithm algo) |
_MHD_EXTERN enum MHD_Result | MHD_queue_auth_fail_response (struct MHD_Connection *connection, const char *realm, const char *opaque, struct MHD_Response *response, int signal_stale) |
Implements HTTP digest authentication.
Definition in file digestauth.c.
#define _MHD_STATIC_UNQ_BUFFER_SIZE 128 |
The size of the unquoting buffer in stack
Definition at line 2311 of file digestauth.c.
Referenced by digest_auth_check_all_inner(), get_buffer_for_size(), get_unquoted_param(), and get_unquoted_param_copy().
#define DAUTH_JUMPBACK_MAX (0x7F) |
The maximum value of artificial timestamp difference to avoid clashes. The value must be suitable for bitwise AND operation.
Definition at line 65 of file digestauth.c.
Referenced by calculate_add_nonce_with_retry().
#define digest_deinit | ( | da | ) |
Definition at line 430 of file digestauth.c.
Referenced by digest_auth_check_all(), MHD_digest_auth_calc_userdigest(), MHD_digest_auth_calc_userhash(), and MHD_queue_auth_required_response3().
#define digest_ext_error | ( | da | ) |
Definition at line 728 of file digestauth.c.
Referenced by calculate_add_nonce(), calculate_add_nonce_with_retry(), digest_auth_check_all_inner(), MHD_digest_auth_calc_userdigest(), MHD_digest_auth_calc_userhash(), and queue_auth_required_response3_inner().
#define digest_setup_zero | ( | da | ) |
Definition at line 429 of file digestauth.c.
Referenced by digest_auth_check_all(), and MHD_queue_auth_required_response3().
#define MAX_AUTH_RESPONSE_LENGTH (MAX_DIGEST * 2) |
Maximum length of the response in digest authentication.
Definition at line 167 of file digestauth.c.
#define MAX_REALM_LENGTH 256 |
Maximum length of a realm for digest authentication.
Definition at line 162 of file digestauth.c.
#define MAX_USERNAME_LENGTH 128 |
Maximum length of a username for digest authentication.
Definition at line 157 of file digestauth.c.
#define MHD_DAUTH_EXT_PARAM_MIN_LEN MHD_STATICSTR_LEN_ (MHD_DAUTH_EXT_PARAM_PREFIX "'") |
The minimal size of the prefix for parameter with the extended notation
Definition at line 177 of file digestauth.c.
Referenced by digest_auth_check_all_inner(), get_rq_extended_uname_copy_z(), get_rq_uname_type(), and get_rq_unames_size().
#define MHD_DAUTH_EXT_PARAM_PREFIX "UTF-8'" |
The required prefix of parameter with the extended notation
Definition at line 172 of file digestauth.c.
Referenced by get_rq_extended_uname_copy_z().
#define NONCE_STD_LEN | ( | digest_size | ) |
Standard server nonce length, not including terminating null,
digest_size | digest size |
Definition at line 92 of file digestauth.c.
Referenced by calculate_add_nonce(), calculate_add_nonce_with_retry(), digest_auth_check_all_inner(), get_nonce_timestamp(), is_slot_available(), and queue_auth_required_response3_inner().
#define REUSE_TIMEOUT 30 |
Allow re-use of the nonce-nc map array slot after REUSE_TIMEOUT seconds, if this slot is needed for the new nonce, while the old nonce was not used even one time by the client. Typically clients immediately use generated nonce for new request.
Definition at line 59 of file digestauth.c.
Referenced by check_nonce_nc(), and is_slot_available().
#define TIMESTAMP_BIN_SIZE (48 / 8) |
#define TIMESTAMP_CHARS_LEN (TIMESTAMP_BIN_SIZE * 2) |
The printed timestamp size in chars
Definition at line 84 of file digestauth.c.
Referenced by get_nonce_timestamp().
#define TRIM_TO_TIMESTAMP | ( | value | ) |
Trim value to the TIMESTAMP_BIN_SIZE size
Definition at line 77 of file digestauth.c.
Referenced by check_nonce_nc(), digest_auth_check_all_inner(), and is_slot_available().
#define VLA_ARRAY_LEN_DIGEST | ( | n | ) |
Macro to avoid using VLAs if the compiler does not support them. Return #MAX_DIGEST.
n | length of the digest to be used for a VLA |
Definition at line 137 of file digestauth.c.
#define VLA_CHECK_LEN_DIGEST | ( | n | ) |
enum _MHD_GetUnqResult |
The result of parameter unquoting
Enumerator | |
---|---|
_MHD_UNQ_OK | Got unquoted string |
_MHD_UNQ_TOO_LARGE | The string is too large to unquote |
_MHD_UNQ_OUT_OF_MEM | Out of memory error |
Definition at line 2356 of file digestauth.c.
enum MHD_CheckNonceNC_ |
The result of nonce-nc map array check.
Definition at line 183 of file digestauth.c.
enum MHD_GetRqNCResult |
Result of request's Digest Authorization 'nc' value extraction
Definition at line 1187 of file digestauth.c.
MHD_DATA_TRUNCATION_RUNTIME_CHECK_RESTORE_ _MHD_static_inline void calc_userdigest | ( | struct DigestAlgorithm * | da, |
const char * | username, | ||
const size_t | username_len, | ||
const char * | realm, | ||
const size_t | realm_len, | ||
const char * | password, | ||
uint8_t * | ha1_bin ) |
Calculate userdigest, return it as binary data.
It is equal to H(A1) for non-session algorithms.
MHD internal version.
da | the digest algorithm | |
username | the username to use | |
username_len | the length of the username | |
realm | the realm to use | |
realm_len | the length of the realm | |
password | the password, must be zero-terminated | |
[out] | ha1_bin | the output buffer, must have at least #digest_get_size(da) bytes available |
Definition at line 1887 of file digestauth.c.
References digest_calc_hash(), digest_update(), digest_update_str(), digest_update_with_colon(), and mhd_assert.
Referenced by digest_auth_check_all_inner(), and MHD_digest_auth_calc_userdigest().
_MHD_static_inline void calc_userhash | ( | struct DigestAlgorithm * | da, |
const char * | username, | ||
const size_t | username_len, | ||
const char * | realm, | ||
const size_t | realm_len, | ||
uint8_t * | digest_bin ) |
Calculate userhash, return it as binary data.
MHD internal version.
da | the digest algorithm | |
username | the username to use | |
username_len | the length of the username | |
realm | the realm to use | |
realm_len | the length of the realm | |
[out] | digest_bin | the output buffer, must have at least #MHD_digest_get_hash_size(algo3) bytes available |
Definition at line 1987 of file digestauth.c.
References digest_calc_hash(), digest_update(), digest_update_with_colon(), mhd_assert, and NULL.
Referenced by digest_auth_check_all_inner(), and MHD_digest_auth_calc_userhash().
|
static |
Calculate the server nonce so that it mitigates replay attacks and add the new nonce to the nonce-nc map array.
connection | the MHD connection structure | |
timestamp | the current timestamp | |
realm | the string of characters that describes the realm of auth | |
realm_len | the length of the realm | |
da | the digest algorithm to use | |
[out] | nonce | the pointer to a character array for the nonce to put in, must provide NONCE_STD_LEN(digest_get_size(da)) bytes, result is NOT zero-terminated |
Definition at line 1697 of file digestauth.c.
References MHD_Connection::addr, MHD_Connection::addr_len, calculate_nonce(), MHD_Connection::daemon, digest_ext_error, digest_get_size(), get_nonce_nc_idx(), MHD_Request::headers_received, MHD_Request::http_mthd, is_slot_available(), MAX_DIGEST_NONCE_LENGTH, MHD_Request::method, mhd_assert, MHD_get_master(), MHD_mutex_lock_chk_, MHD_mutex_unlock_chk_, MHD_NonceNc::nc, MHD_NonceNc::nmask, MHD_NonceNc::nonce, NONCE_STD_LEN, MHD_Connection::rq, MHD_Request::url, and MHD_Request::url_len.
Referenced by calculate_add_nonce_with_retry().
|
static |
Calculate the server nonce so that it mitigates replay attacks and add the new nonce to the nonce-nc map array.
connection | the MHD connection structure | |
realm | A string of characters that describes the realm of auth. | |
da | digest algorithm to use | |
[out] | nonce | the pointer to a character array for the nonce to put in, must provide NONCE_STD_LEN(digest_get_size(da)) bytes, result is NOT zero-terminated |
Definition at line 1777 of file digestauth.c.
References _, _MHD_ROTL32(), _MHD_ROTR32(), calculate_add_nonce(), MHD_Connection::daemon, DAUTH_JUMPBACK_MAX, digest_ext_error, digest_get_size(), digest_reset(), mhd_assert, MHD_get_master(), MHD_monotonic_msec_counter(), MHD_NonceNc::nonce, and NONCE_STD_LEN.
Referenced by queue_auth_required_response3_inner().
|
static |
Calculate the server nonce so that it mitigates replay attacks The current format of the nonce is ... H(timestamp:random data:various parameters) + Hex(timestamp)
nonce_time | The amount of time in seconds for a nonce to be invalid | |
mthd_e | HTTP method as enum value | |
method | HTTP method as a string | |
rnd | the pointer to a character array for the random seed | |
rnd_size | The size of the random seed array rnd | |
saddr | the pointer to the socket address structure | |
saddr_size | the size of the socket address structure saddr | |
uri | the HTTP URI (in MHD, without the arguments ("?k=v") | |
uri_len | the length of the uri | |
first_header | the pointer to the first request's header | |
realm | A string of characters that describes the realm of auth. | |
realm_len | the length of the realm. | |
bind_options | the nonce bind options (MHD_DAuthBindNonce values). | |
da | digest algorithm to use | |
[out] | nonce | the pointer to a character array for the nonce to put in, must provide NONCE_STD_LEN(digest_get_size(da)) bytes, result is NOT zero-terminated |
Definition at line 1485 of file digestauth.c.
References digest_calc_hash(), digest_get_size(), digest_update(), digest_update_str(), digest_update_with_colon(), MHD_HTTP_Req_Header::header, MHD_HTTP_Req_Header::header_size, MHD_HTTP_Req_Header::kind, mhd_assert, MHD_bin_to_hex(), MHD_DAUTH_BIND_NONCE_CLIENT_IP, MHD_DAUTH_BIND_NONCE_NONE, MHD_DAUTH_BIND_NONCE_REALM, MHD_DAUTH_BIND_NONCE_URI, MHD_DAUTH_BIND_NONCE_URI_PARAMS, MHD_GET_ARGUMENT_KIND, MHD_HTTP_MTHD_GET, MHD_HTTP_MTHD_HEAD, MHD_HTTP_MTHD_OTHER, MHD_HTTP_Req_Header::next, NULL, TIMESTAMP_BIN_SIZE, MHD_HTTP_Req_Header::value, and MHD_HTTP_Req_Header::value_size.
Referenced by calculate_add_nonce(), and digest_auth_check_all_inner().
|
static |
Check that the arguments given by the client as part of the authentication header match the arguments we got as part of the HTTP request URI.
connection | connections with headers to compare against |
args | the copy of argument URI string (after "?" in URI), will be modified by this function |
Definition at line 2219 of file digestauth.c.
References MHD_Request::headers_received, MHD_HTTP_Req_Header::kind, MHD_GET_ARGUMENT_KIND, MHD_NO, MHD_parse_arguments_(), MHD_HTTP_Req_Header::next, NULL, MHD_Connection::rq, and test_header().
Referenced by check_uri_match().
|
static |
Check nonce-nc map array with the new nonce counter.
connection | The MHD connection structure |
nonce | the pointer that referenced hex nonce, does not need to be zero-terminated |
noncelen | the length of nonce, in characters |
nc | The nonce counter |
< The timestamp in the slot
Definition at line 832 of file digestauth.c.
References MHD_Connection::daemon, get_nonce_nc_idx(), get_nonce_timestamp(), MAX_DIGEST_NONCE_LENGTH, mhd_assert, MHD_CHECK_NONCENC_OK, MHD_CHECK_NONCENC_STALE, MHD_CHECK_NONCENC_WRONG, MHD_get_master(), MHD_mutex_lock_chk_, MHD_mutex_unlock_chk_, MHD_NonceNc::nc, MHD_NonceNc::nmask, MHD_NonceNc::nonce, REUSE_TIMEOUT, TRIM_TO_TIMESTAMP, UINT32_MAX, and UINT64_MAX.
Referenced by digest_auth_check_all_inner().
|
static |
Check that the URI provided by the client as part of the authentication header match the real HTTP request URI.
connection | connections with headers to compare against |
uri | the copy of URI in the authentication header, should point to modifiable buffer at least uri_len + 1 characters long, will be modified by this function, not valid upon return |
uri_len | the length of the uri string in characters |
Definition at line 2266 of file digestauth.c.
References _, check_argument_match(), MHD_Connection::daemon, NULL, MHD_Connection::rq, MHD_Daemon::unescape_callback, MHD_Daemon::unescape_callback_cls, MHD_Request::url, and MHD_Request::url_len.
Referenced by digest_auth_check_all_inner().
_MHD_static_inline void digest_calc_hash | ( | struct DigestAlgorithm * | da, |
uint8_t * | digest ) |
Finally calculate hash (the digest).
da | the digest calculation | |
[out] | digest | the pointer to the buffer to put calculated digest, must be at least digest_get_size(da) bytes large |
Definition at line 576 of file digestauth.c.
References mhd_assert, MHD_DIGEST_BASE_ALGO_MD5, MHD_DIGEST_BASE_ALGO_SHA256, MHD_DIGEST_BASE_ALGO_SHA512_256, MHD_MD5_finish(), MHD_MD5_finish_reset, MHD_SHA256_finish(), MHD_SHA256_finish_reset, and MHD_SHA512_256_finish().
Referenced by calc_userdigest(), calc_userhash(), calculate_nonce(), and digest_auth_check_all_inner().
_MHD_static_inline size_t digest_get_hash_size | ( | enum MHD_DigestAuthAlgo3 | algo3 | ) |
Get digest size for specified algorithm.
Internal inline version.
algo3 | the algorithm to check |
Definition at line 232 of file digestauth.c.
References MD5_DIGEST_SIZE, mhd_assert, MHD_DIGEST_BASE_ALGO_MD5, MHD_DIGEST_BASE_ALGO_SHA256, MHD_DIGEST_BASE_ALGO_SHA512_256, MHD_MD5_DIGEST_SIZE, MHD_SHA256_DIGEST_SIZE, MHD_SHA512_256_DIGEST_SIZE, SHA256_DIGEST_SIZE, and SHA512_256_DIGEST_SIZE.
Referenced by MHD_digest_auth_calc_userhash_hex(), MHD_digest_auth_check_digest3(), and MHD_digest_get_hash_size().
_MHD_static_inline unsigned int digest_get_size | ( | struct DigestAlgorithm * | da | ) |
Return the size of the digest.
da | the digest calculation structure to identify |
Definition at line 351 of file digestauth.c.
References MD5_DIGEST_SIZE, mhd_assert, MHD_DIGEST_BASE_ALGO_MD5, MHD_DIGEST_BASE_ALGO_SHA256, MHD_DIGEST_BASE_ALGO_SHA512_256, SHA256_DIGEST_SIZE, and SHA512_256_DIGEST_SIZE.
Referenced by calculate_add_nonce(), calculate_add_nonce_with_retry(), calculate_nonce(), digest_auth_check_all_inner(), MHD_digest_auth_calc_userdigest(), MHD_digest_auth_calc_userhash(), and queue_auth_required_response3_inner().
_MHD_static_inline bool digest_init_one_time | ( | struct DigestAlgorithm * | da, |
enum MHD_DigestBaseAlgo | algo ) |
Set-up the digest calculation structure and initialise with initial values.
If da was successfully initialised, digest_deinit() must be called after finishing using of the da.
This function must not be called more than once for any da.
da | the structure to set-up |
algo | the algorithm to use for digest calculation |
Definition at line 448 of file digestauth.c.
References MHD_DIGEST_BASE_ALGO_INVALID, MHD_DIGEST_BASE_ALGO_MD5, MHD_DIGEST_BASE_ALGO_SHA256, MHD_DIGEST_BASE_ALGO_SHA512_256, MHD_MD5_init_one_time, MHD_SHA256_init_one_time, and MHD_SHA512_256_init().
Referenced by digest_auth_check_all_inner(), MHD_digest_auth_calc_userdigest(), MHD_digest_auth_calc_userhash(), and queue_auth_required_response3_inner().
_MHD_static_inline void digest_reset | ( | struct DigestAlgorithm * | da | ) |
Reset the digest calculation structure.
da | the structure to reset |
Definition at line 638 of file digestauth.c.
References mhd_assert, MHD_DIGEST_BASE_ALGO_MD5, MHD_DIGEST_BASE_ALGO_SHA256, MHD_DIGEST_BASE_ALGO_SHA512_256, MHD_MD5_reset, MHD_SHA256_reset, and MHD_SHA512_256_init().
Referenced by calculate_add_nonce_with_retry(), and digest_auth_check_all_inner().
_MHD_static_inline void digest_update | ( | struct DigestAlgorithm * | da, |
const void * | data, | ||
size_t | length ) |
Feed digest calculation with more data.
da | the digest calculation |
data | the data to process |
length | the size of the data in bytes |
Definition at line 512 of file digestauth.c.
References data, mhd_assert, MHD_DIGEST_BASE_ALGO_MD5, MHD_DIGEST_BASE_ALGO_SHA256, MHD_DIGEST_BASE_ALGO_SHA512_256, MHD_MD5_update(), MHD_SHA256_update(), and MHD_SHA512_256_update().
Referenced by calc_userdigest(), calc_userhash(), calculate_nonce(), digest_auth_check_all_inner(), digest_update_str(), and digest_update_with_colon().
_MHD_static_inline void digest_update_str | ( | struct DigestAlgorithm * | da, |
const char * | str ) |
Feed digest calculation with more data from string.
da | the digest calculation |
str | the zero-terminated string to process |
Definition at line 548 of file digestauth.c.
References digest_update().
Referenced by calc_userdigest(), calculate_nonce(), and digest_auth_check_all_inner().
_MHD_static_inline void digest_update_with_colon | ( | struct DigestAlgorithm * | da | ) |
Feed digest calculation with single colon ':' character.
da | the digest calculation |
str | the zero-terminated string to process |
Definition at line 562 of file digestauth.c.
References digest_update().
Referenced by calc_userdigest(), calc_userhash(), calculate_nonce(), and digest_auth_check_all_inner().
|
static |
Super-fast xor-based "hash" function
data | the data to calculate hash for |
data_size | the size of the data in bytes |
Definition at line 777 of file digestauth.c.
References _MHD_ROTL32(), and data.
Referenced by get_nonce_nc_idx().
_MHD_static_inline enum MHD_DigestBaseAlgo get_base_digest_algo | ( | enum MHD_DigestAuthAlgo3 | algo3 | ) |
Get base hash calculation algorithm from MHD_DigestAuthAlgo3 value.
algo3 | the MHD_DigestAuthAlgo3 value |
Definition at line 210 of file digestauth.c.
References MHD_DIGEST_AUTH_ALGO3_NON_SESSION, and MHD_DIGEST_AUTH_ALGO3_SESSION.
Referenced by digest_auth_check_all_inner(), MHD_digest_auth_calc_userdigest(), MHD_digest_auth_calc_userhash(), and queue_auth_required_response3_inner().
|
static |
Get the pointer to buffer with required size
tmp1 | the first buffer with fixed size |
ptmp2 | the pointer to pointer to malloc'ed buffer |
ptmp2_size | the pointer to the size of the buffer pointed by ptmp2 |
required_size | the required size in buffer |
Definition at line 2324 of file digestauth.c.
References _MHD_AUTH_DIGEST_MAX_PARAM_SIZE, _MHD_STATIC_UNQ_BUFFER_SIZE, mhd_assert, and NULL.
Referenced by digest_auth_check_all_inner(), get_unquoted_param(), and get_unquoted_param_copy().
|
static |
Get index of the nonce in the nonce-nc map array.
arr_size | the size of nonce_nc array |
nonce | the pointer that referenced a zero-terminated array of nonce |
noncelen | the length of nonce, in characters |
Definition at line 807 of file digestauth.c.
References fast_simple_hash(), and mhd_assert.
Referenced by calculate_add_nonce(), and check_nonce_nc().
|
static |
Extract timestamp from the given nonce.
nonce | the nonce to check | |
noncelen | the length of the nonce, zero for autodetect | |
[out] | ptimestamp | the pointer to store extracted timestamp |
Definition at line 741 of file digestauth.c.
References MD5_DIGEST_SIZE, MHD_strx_to_uint64_n_(), NONCE_STD_LEN, and TIMESTAMP_CHARS_LEN.
Referenced by check_nonce_nc(), digest_auth_check_all_inner(), and is_slot_available().
|
static |
Get decoded version of username from extended notation. This function automatically zero-teminate the result.
uname_ext | the string of client's 'username*' parameter value | |
uname_ext_len | the length of uname_ext in chars | |
[out] | buf | the output buffer to put decoded username value |
buf_size | the size of buf |
Definition at line 1052 of file digestauth.c.
References mhd_assert, MHD_DAUTH_EXT_PARAM_MIN_LEN, MHD_DAUTH_EXT_PARAM_PREFIX, MHD_STATICSTR_LEN_, MHD_str_equal_caseless_bin_n_(), MHD_str_pct_decode_strict_n_(), and SSIZE_MAX.
Referenced by digest_auth_check_all_inner(), and get_rq_uname().
|
static |
Get 'nc' value from request's Authorization header
params | the request digest authentication | |
[out] | nc | the pointer to put nc value to |
Definition at line 1204 of file digestauth.c.
References MHD_GET_RQ_NC_BROKEN, MHD_GET_RQ_NC_NONE, MHD_GET_RQ_NC_TOO_LARGE, MHD_GET_RQ_NC_TOO_LONG, MHD_GET_RQ_NC_VALID, MHD_strx_to_uint64_n_(), NULL, and UINT32_MAX.
Referenced by MHD_digest_auth_get_request_info3().
|
static |
Get unquoted version of Digest Authorization parameter. This function automatically zero-teminate the result.
param | the parameter to extract | |
[out] | buf | the output buffer, must be enough size to hold the result, the recommended size is 'param->value.len + 1' |
Definition at line 1022 of file digestauth.c.
References mhd_assert, and NULL.
Referenced by get_rq_uname(), and MHD_digest_auth_get_request_info3().
|
static |
Get copy of username used by the client.
params | the Digest Authorization parameters | |
uname_type | the type of username | |
[out] | uname_info | the pointer to the structure to be filled |
buf | the buffer to be used for usernames | |
buf_size | the size of the buf |
Definition at line 1102 of file digestauth.c.
References get_rq_extended_uname_copy_z(), get_rq_param_unquoted_copy_z(), get_rq_uname_type(), mhd_assert, MHD_DIGEST_AUTH_UNAME_TYPE_EXTENDED, MHD_DIGEST_AUTH_UNAME_TYPE_INVALID, MHD_DIGEST_AUTH_UNAME_TYPE_MISSING, MHD_DIGEST_AUTH_UNAME_TYPE_STANDARD, MHD_DIGEST_AUTH_UNAME_TYPE_USERHASH, MHD_hex_to_bin(), NULL, MHD_DigestAuthUsernameInfo::uname_type, MHD_DigestAuthUsernameInfo::userhash_bin, MHD_DigestAuthUsernameInfo::userhash_hex, MHD_DigestAuthUsernameInfo::userhash_hex_len, MHD_DigestAuthUsernameInfo::username, and MHD_DigestAuthUsernameInfo::username_len.
Referenced by MHD_digest_auth_get_request_info3(), MHD_digest_auth_get_username(), and MHD_digest_auth_get_username3().
_MHD_static_inline enum MHD_DigestAuthUsernameType get_rq_uname_type | ( | const struct MHD_RqDAuth * | params | ) |
Get username type used by the client. This function does not check whether userhash can be decoded or extended notation (if used) is valid.
params | the Digest Authorization parameters |
Definition at line 960 of file digestauth.c.
References MHD_DAUTH_EXT_PARAM_MIN_LEN, MHD_DIGEST_AUTH_UNAME_TYPE_EXTENDED, MHD_DIGEST_AUTH_UNAME_TYPE_INVALID, MHD_DIGEST_AUTH_UNAME_TYPE_MISSING, MHD_DIGEST_AUTH_UNAME_TYPE_STANDARD, MHD_DIGEST_AUTH_UNAME_TYPE_USERHASH, and NULL.
Referenced by get_rq_uname(), get_rq_unames_size(), MHD_digest_auth_get_request_info3(), MHD_digest_auth_get_username(), and MHD_digest_auth_get_username3().
_MHD_static_inline size_t get_rq_unames_size | ( | const struct MHD_RqDAuth * | params, |
enum MHD_DigestAuthUsernameType | uname_type ) |
Get total size required for 'username' and 'userhash_bin'
params | the Digest Authorization parameters |
uname_type | the type of username |
Definition at line 992 of file digestauth.c.
References get_rq_uname_type(), mhd_assert, MHD_DAUTH_EXT_PARAM_MIN_LEN, MHD_DIGEST_AUTH_UNAME_TYPE_EXTENDED, MHD_DIGEST_AUTH_UNAME_TYPE_STANDARD, and MHD_DIGEST_AUTH_UNAME_TYPE_USERHASH.
Referenced by MHD_digest_auth_get_request_info3(), MHD_digest_auth_get_username(), and MHD_digest_auth_get_username3().
|
static |
Get Digest authorisation parameter as unquoted string.
param | the parameter to process | |
tmp1 | the small buffer in stack | |
ptmp2 | the pointer to pointer to malloc'ed buffer | |
ptmp2_size | the pointer to the size of the buffer pointed by ptmp2 | |
[out] | unquoted | the pointer to store the result, NOT zero terminated |
Definition at line 2373 of file digestauth.c.
References _MHD_AUTH_DIGEST_MAX_PARAM_SIZE, _MHD_STATIC_UNQ_BUFFER_SIZE, _MHD_UNQ_OK, _MHD_UNQ_OUT_OF_MEM, _MHD_UNQ_TOO_LARGE, get_buffer_for_size(), _MHD_str_w_len::len, mhd_assert, NULL, and _MHD_str_w_len::str.
Referenced by digest_auth_check_all_inner().
|
static |
Get copy of Digest authorisation parameter as unquoted string.
param | the parameter to process | |
tmp1 | the small buffer in stack | |
ptmp2 | the pointer to pointer to malloc'ed buffer | |
ptmp2_size | the pointer to the size of the buffer pointed by ptmp2 | |
[out] | unquoted | the pointer to store the result, NOT zero terminated, but with enough space to zero-terminate |
Definition at line 2416 of file digestauth.c.
References _MHD_AUTH_DIGEST_MAX_PARAM_SIZE, _MHD_STATIC_UNQ_BUFFER_SIZE, _MHD_UNQ_OK, _MHD_UNQ_OUT_OF_MEM, _MHD_UNQ_TOO_LARGE, get_buffer_for_size(), _MHD_mstr_w_len::len, mhd_assert, NULL, and _MHD_mstr_w_len::str.
Referenced by digest_auth_check_all_inner().
_MHD_static_inline bool is_param_equal | ( | const struct MHD_RqDAuthParam * | param, |
const char *const | str, | ||
const size_t | str_len ) |
Check whether Digest Auth request parameter is equal to given string
param | the parameter to check |
str | the string to compare with, does not need to be zero-terminated |
str_len | the length of the str |
Definition at line 2458 of file digestauth.c.
References mhd_assert, and NULL.
Referenced by digest_auth_check_all_inner().
_MHD_static_inline bool is_param_equal_caseless | ( | const struct MHD_RqDAuthParam * | param, |
const char *const | str, | ||
const size_t | str_len ) |
Check whether Digest Auth request parameter is caseless equal to given string
param | the parameter to check |
str | the string to compare with, does not need to be zero-terminated |
str_len | the length of the str |
Definition at line 2482 of file digestauth.c.
References mhd_assert, and NULL.
Referenced by digest_auth_check_all_inner().
|
static |
Check whether it is possible to use slot in nonce-nc map array.
Should be called with mutex held to avoid external modification of the slot data.
nn | the pointer to the nonce-nc slot |
now | the current time |
new_nonce | the new nonce supposed to be stored in this slot, zero-terminated |
new_nonce_len | the length of the new_nonce in chars, not including the terminating zero. |
Definition at line 1641 of file digestauth.c.
References get_nonce_timestamp(), MAX_DIGEST_NONCE_LENGTH, mhd_assert, MHD_NonceNc::nc, MHD_NonceNc::nonce, NONCE_STD_LEN, REUSE_TIMEOUT, and TRIM_TO_TIMESTAMP.
Referenced by calculate_add_nonce().
|
static |
Test if the given key-value pair is in the headers for the given connection.
cls | the test context |
key | the key |
key_size | number of bytes in key |
value | the value, can be NULL |
value_size | number of bytes in value |
kind | type of the header |
Definition at line 2158 of file digestauth.c.
References MHD_HTTP_Req_Header::header, MHD_HTTP_Req_Header::header_size, MHD_Request::headers_received, MHD_HTTP_Req_Header::kind, mhd_assert, MHD_NO, MHD_YES, MHD_HTTP_Req_Header::next, NULL, MHD_Connection::rq, MHD_HTTP_Req_Header::value, and MHD_HTTP_Req_Header::value_size.
Referenced by check_argument_match().