/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "str.h"
#include "base64.h"
#include "array.h"
#include "http-parser.h"
#include "http-auth.h"
/* RFC 7235, Section 2.1:
challenge = auth-scheme [ 1*SP ( token68 / #auth-param ) ]
credentials = auth-scheme [ 1*SP ( token68 / #auth-param ) ]
auth-scheme = token
auth-param = token BWS "=" BWS ( token / quoted-string )
token68 = 1*( ALPHA / DIGIT /
"-" / "." / "_" / "~" / "+" / "/" ) *"="
OWS = *( SP / HTAB )
; optional whitespace
BWS = OWS
; "bad" whitespace
*/
/*
* Parsing
*/
static int
{
const unsigned char *first;
/* token68 = 1*( ALPHA / DIGIT /
"-" / "." / "_" / "~" / "+" / "/" ) *"="
*/
/* 1*( ALPHA / DIGIT / "-" / "." / "_" / "~" / "+" / "/" ) */
return 0;
/* *"=" */
return 1;
}
static int
{
int ret;
/* auth-param = token BWS "=" BWS ( token / quoted-string ) */
/* token */
return ret;
}
/* BWS "=" BWS */
return 0;
}
/* ( token / quoted-string ) */
return ret;
}
return 1;
}
static int
{
unsigned int count = 0;
int ret;
while ((ret=http_parse_auth_param
if (!array_is_created(params))
count++;
/* OWS "," OWS
--> also allow empty elements
*/
for (;;) {
break;
}
}
if (ret < 0)
return -1;
return (count > 0 ? 1 : 0);
}
{
int ret;
/* WWW-Authenticate = 1#challenge
Proxy-Authenticate = 1#challenge
challenge = auth-scheme [ 1*SP ( token68 / #auth-param ) ]
auth-scheme = token
*/
/* 1#element => *( "," OWS ) ... ; RFC 7230, Section 7 */
for (;;) {
break;
}
for (;;) {
/* auth-scheme */
if (ret < 0)
return -1;
break;
}
/* [ 1*SP ... ] */
return 1;
/* ( token68 / #auth-param ) */
if (ret < 0)
return -1;
return -1;
}
if (!array_is_created(chlngs))
/* OWS "," OWS
--> also allow empty elements
*/
for (;;) {
break;
}
}
return -1;
return 1;
}
struct http_auth_credentials *crdts)
{
int ret;
/* Authorization = credentials
Proxy-Authorization = credentials
credentials = auth-scheme [ 1*SP ( token68 / #auth-param ) ]
auth-scheme = token
*/
/* auth-scheme */
return -1;
/* [ 1*SP ... ] */
return 1;
/* ( token68 / #auth-param ) */
if (ret < 0)
return -1;
return -1;
}
return -1;
return 1;
}
/*
* Construction
*/
static void
{
const char *p, *first;
/* auth-param = token BWS "=" BWS ( token / quoted-string ) */
if ( *p != '\0' ) {
while (*p != '\0') {
if (*p == '\\' || *p == '"') {
first = p;
}
p++;
}
} else {
}
}
static void
{
unsigned int count, i;
if (!array_is_created(params))
return;
for (i = 0; i < count; i++) {
if (i > 0)
}
}
{
const char *p = data;
/* Make sure we're not working with nonsense. */
i_assert(http_char_is_token68(*p));
for (p++; *p != '\0' && *p != '='; p++)
i_assert(http_char_is_token68(*p));
for (; *p != '\0'; p++)
i_assert(*p == '=');
}
const struct http_auth_challenge *chlng)
{
/* challenge = auth-scheme [ 1*SP ( token68 / #auth-param ) ]
auth-scheme = token
*/
/* auth-scheme */
/* SP token68 */
} else {
/* SP #auth-param */
}
}
{
unsigned int count, i;
/* WWW-Authenticate = 1#challenge
Proxy-Authenticate = 1#challenge
*/
for (i = 0; i < count; i++) {
if (i > 0)
}
}
const struct http_auth_credentials *crdts)
{
/* Authorization = credentials
Proxy-Authorization = credentials
credentials = auth-scheme [ 1*SP ( token68 / #auth-param ) ]
auth-scheme = token
*/
/* auth-scheme */
/* SP token68 */
} else {
/* SP #auth-param */
}
}
/*
* Manipulation
*/
static void
{
if (!array_is_created(src))
return;
}
}
struct http_auth_challenge *dst,
const struct http_auth_challenge *src)
{
else
}
struct http_auth_challenge *
const struct http_auth_challenge *src)
{
return new;
}
struct http_auth_credentials *dst,
const struct http_auth_credentials *src)
{
else
}
struct http_auth_credentials *
const struct http_auth_credentials *src)
{
return new;
}
/*
* Simple schemes
*/
const char *realm)
{
}
}
{
const char *auth;
}