[http] Handle parsing of WWW-Authenticate header within authentication scheme

Allow individual authentication schemes to parse WWW-Authenticate
headers that do not comply with RFC2617.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2017-11-11 22:05:53 +00:00
parent c49acbb4d2
commit 96bd872c03
4 changed files with 157 additions and 75 deletions

View File

@@ -42,6 +42,25 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
__einfo_uniqify ( EINFO_EACCES, 0x01, \
"No username available for Basic authentication" )
/**
* Parse HTTP "WWW-Authenticate" header for Basic authentication
*
* @v http HTTP transaction
* @v line Remaining header line
* @ret rc Return status code
*/
static int http_parse_basic_auth ( struct http_transaction *http,
char *line __unused ) {
/* Allow HTTP request to be retried if the request had not
* already tried authentication.
*/
if ( ! http->request.auth.auth )
http->response.flags |= HTTP_RESPONSE_RETRY;
return 0;
}
/**
* Perform HTTP Basic authentication
*
@@ -49,7 +68,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
* @ret rc Return status code
*/
static int http_basic_authenticate ( struct http_transaction *http ) {
struct http_request_auth *req = &http->request.auth;
struct http_request_auth_basic *req = &http->request.auth.basic;
/* Record username and password */
if ( ! http->uri->user ) {
@@ -73,7 +92,7 @@ static int http_basic_authenticate ( struct http_transaction *http ) {
*/
static int http_format_basic_auth ( struct http_transaction *http,
char *buf, size_t len ) {
struct http_request_auth *req = &http->request.auth;
struct http_request_auth_basic *req = &http->request.auth.basic;
size_t user_pw_len = ( strlen ( req->username ) + 1 /* ":" */ +
strlen ( req->password ) );
char user_pw[ user_pw_len + 1 /* NUL */ ];
@@ -93,6 +112,7 @@ static int http_format_basic_auth ( struct http_transaction *http,
/** HTTP Basic authentication scheme */
struct http_authentication http_basic_auth __http_authentication = {
.name = "Basic",
.parse = http_parse_basic_auth,
.authenticate = http_basic_authenticate,
.format = http_format_basic_auth,
};