mirror of
https://github.com/ipxe/ipxe
synced 2026-07-04 20:01:38 +03:00
[http] Remove knowledge of MD5 digest context internal structure
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -46,6 +46,14 @@ FILE_SECBOOT ( PERMITTED );
|
||||
__einfo_uniqify ( EINFO_EACCES, 0x01, \
|
||||
"No username available for Digest authentication" )
|
||||
|
||||
/** An HTTP Digest algorithm context */
|
||||
struct http_digest_context {
|
||||
/** MD5 context */
|
||||
uint8_t md5[MD5_CTX_SIZE];
|
||||
/** Length of colon field separator before next field */
|
||||
size_t colon_len;
|
||||
};
|
||||
|
||||
/** An HTTP Digest "WWW-Authenticate" response field */
|
||||
struct http_digest_field {
|
||||
/** Name */
|
||||
@@ -125,10 +133,13 @@ static int http_parse_digest_auth ( struct http_transaction *http,
|
||||
* @v ctx Digest context
|
||||
* @v string Initial string
|
||||
*/
|
||||
static void http_digest_init ( struct md5_context *ctx ) {
|
||||
static void http_digest_init ( struct http_digest_context *ctx ) {
|
||||
|
||||
/* Initialise MD5 digest */
|
||||
digest_init ( &md5_algorithm, ctx );
|
||||
digest_init ( &md5_algorithm, ctx->md5 );
|
||||
|
||||
/* Omit colon before first field */
|
||||
ctx->colon_len = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,13 +148,16 @@ static void http_digest_init ( struct md5_context *ctx ) {
|
||||
* @v ctx Digest context
|
||||
* @v string String to append
|
||||
*/
|
||||
static void http_digest_update ( struct md5_context *ctx, const char *string ) {
|
||||
static void http_digest_update ( struct http_digest_context *ctx,
|
||||
const char *string ) {
|
||||
static const char colon = ':';
|
||||
|
||||
/* Add (possibly colon-separated) field to MD5 digest */
|
||||
if ( ctx->len )
|
||||
digest_update ( &md5_algorithm, ctx, &colon, sizeof ( colon ) );
|
||||
digest_update ( &md5_algorithm, ctx, string, strlen ( string ) );
|
||||
digest_update ( &md5_algorithm, ctx->md5, &colon, ctx->colon_len );
|
||||
digest_update ( &md5_algorithm, ctx->md5, string, strlen ( string ) );
|
||||
|
||||
/* Include colon before any subsequent fields */
|
||||
ctx->colon_len = sizeof ( colon );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,12 +167,12 @@ static void http_digest_update ( struct md5_context *ctx, const char *string ) {
|
||||
* @v out Buffer for digest output
|
||||
* @v len Buffer length
|
||||
*/
|
||||
static void http_digest_final ( struct md5_context *ctx, char *out,
|
||||
static void http_digest_final ( struct http_digest_context *ctx, char *out,
|
||||
size_t len ) {
|
||||
uint8_t digest[MD5_DIGEST_SIZE];
|
||||
|
||||
/* Finalise and base16-encode MD5 digest */
|
||||
digest_final ( &md5_algorithm, ctx, digest );
|
||||
digest_final ( &md5_algorithm, ctx->md5, digest );
|
||||
base16_encode ( digest, sizeof ( digest ), out, len );
|
||||
}
|
||||
|
||||
@@ -175,7 +189,7 @@ static int http_digest_authenticate ( struct http_transaction *http ) {
|
||||
char ha2[ base16_encoded_len ( MD5_DIGEST_SIZE ) + 1 /* NUL */ ];
|
||||
static const char md5sess[] = "MD5-sess";
|
||||
static const char md5[] = "MD5";
|
||||
struct md5_context ctx;
|
||||
struct http_digest_context ctx;
|
||||
const char *password;
|
||||
|
||||
/* Check for required response parameters */
|
||||
|
||||
Reference in New Issue
Block a user