imap-urlauth.c revision 5a580c3a38ced62d4bcc95b8ac7c4f2935b5d294
/* Copyright (c) 2013 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "hostpid.h"
#include "var-expand.h"
#include "hmac.h"
#include "sha1.h"
#include "randgen.h"
#include "safe-memset.h"
#include "mail-storage.h"
#include "mail-storage-service.h"
#include "mail-namespace.h"
#include "mail-user.h"
#include "imap-url.h"
#include "imap-msgpart-url.h"
#include "imap-urlauth-backend.h"
#include "imap-urlauth-fetch.h"
#include "imap-urlauth-connection.h"
#include "imap-urlauth-private.h"
#include <time.h>
#define IMAP_URLAUTH_MECH_INTERNAL_VERSION 0x01
#define URL_HOST_ALLOW_ANY "*"
struct imap_urlauth_context *
const struct imap_urlauth_config *config)
{
struct imap_urlauth_context *uctx;
unsigned int timeout;
if (config->access_anonymous)
else
} else {
}
}
return uctx;
}
{
}
static const unsigned char *
imap_urlauth_internal_generate(const char *rumpurl,
const unsigned char mailbox_key[IMAP_URLAUTH_KEY_LEN],
{
struct hmac_context hmac;
unsigned char *token;
return token;
}
static bool
imap_urlauth_internal_verify(const char *rumpurl,
const unsigned char mailbox_key[IMAP_URLAUTH_KEY_LEN],
{
const unsigned char *valtoken;
return FALSE;
&valtoken_len);
if (token_len != valtoken_len)
return FALSE;
}
static bool
const char *const *access_applications)
{
const char *const *application;
if (access_applications == NULL)
return FALSE;
const char *app = *application;
bool have_userid = FALSE;
have_userid = TRUE;
}
if (have_userid)
else
}
}
return FALSE;
}
static bool
const char **error_r)
{
*error_r = "URL is missing URLAUTH";
return FALSE;
}
/* user+<access_user> */
if (uctx->access_anonymous ||
if (uctx->access_anonymous) {
"No 'user+%s' access allowed for anonymous user",
} else {
}
return FALSE;
}
/* authuser */
if (uctx->access_anonymous) {
*error_r = "No 'authuser' access allowed for anonymous user";
return FALSE;
}
/* anonymous */
} else if (!ignore_unknown &&
if (uctx->access_anonymous) {
"No '%s%s' access allowed for anonymous user",
} else {
"No '%s%s' access allowed for user %s",
}
return FALSE;
}
return TRUE;
}
static bool
{
/* validate host */
*error_r = "Invalid URL: Inappropriate host name";
return FALSE;
}
/* validate port */
*error_r = "Invalid URL: Inappropriate server port";
return FALSE;
}
return TRUE;
}
{
enum imap_url_parse_flags url_flags =
struct imap_msgpart_url *mpurl;
const char *error;
enum mail_error error_code;
unsigned char mailbox_key[IMAP_URLAUTH_KEY_LEN];
const unsigned char *token;
int ret;
/* validate mechanism */
return 0;
}
/* validate URL */
return 0;
}
*error_r = "Invalid URL: Must be an URLAUTH rump URL";
return 0;
}
/* validate expiry time */
return 0;
}
}
/* validate user */
*error_r = "Invalid URL: Missing user name";
return 0;
}
"Not permitted to generate URLAUTH for user %s",
return 0;
}
/* validate host:port */
return 0;
/* validate mailbox */
return ret;
}
/* obtain mailbox key */
error_r, &error_code);
if (ret < 0) {
return ret;
}
return 1;
}
const char **error_r)
{
/* validate URL fields */
*error_r = "Invalid URL: Must be a full URLAUTH URL";
return FALSE;
}
/* check presence of userid */
*error_r = "Invalid URLAUTH: Missing user name";
return FALSE;
}
/* validate mechanism */
return FALSE;
}
/* validate expiry time */
return FALSE;
}
}
/* validate access */
error_r))
return FALSE;
/* validate host:port */
return FALSE;
return TRUE;
}
struct imap_msgpart_url **mpurl_r,
enum mail_error *error_code_r,
const char **error_r)
{
struct imap_msgpart_url *mpurl;
const char *error;
unsigned char mailbox_key[IMAP_URLAUTH_KEY_LEN];
int ret;
/* check urlauth mechanism, access, userid and authority */
return 0;
}
/* validate target user */
return 0;
}
/* validate mailbox */
return ret;
}
&error)) < 0) {
*error_r = "Internal server error";
return -1;
}
if (ret == 0) {
/* RFC says: `If the mailbox cannot be identified, an
authorization token is calculated on the rump URL, using
random "plausible" keys (selected by the server) as needed,
before returning a validation failure. This prevents timing
attacks aimed at identifying mailbox names.' */
return 0;
}
/* obtain mailbox key */
if (ret < 0) {
return -1;
}
if (ret == 0 ||
url->uauth_token_size)) {
*error_r = "URLAUTH verification failed";
ret = 0;
} else {
ret = 1;
}
return ret;
}
{
const char *error;
/* validate URL */
return 0;
}
}
{
}
{
}