var-expand-crypt-plugin.c revision 9e38412ec12ae8dc4f67ade5b18c8b976de59bcb
/* Copyright (c) 2003-2016 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "array.h"
#include "hex-binary.h"
#include "base64.h"
#include "str.h"
#include "strescape.h"
#include "var-expand.h"
#include "var-expand-private.h"
#include "dcrypt.h"
#define VAR_EXPAND_CRYPT_DEFAULT_ALGO "AES-256-CBC"
struct module;
enum crypt_field_format {
};
struct var_expand_crypt_context {
struct var_expand_context *ctx;
const char *algo;
enum crypt_field_format format;
bool enc_result_only:1;
};
static void var_expand_crypt_initialize(void);
void var_expand_crypt_deinit(void);
void auth_var_expand_crypt_deinit(void);
static bool has_been_init;
static int
{
args++;
continue;
} else {
value++;
}
if (strcmp(k, "iv") == 0) {
return -1;
}
/* try to decode IV */
} if (strcmp(k, "noiv") == 0) {
} if (strcmp(k, "algo") == 0) {
} else if (strcmp(k, "key") == 0) {
error_r) < 0) {
return -1;
}
} else if (strcmp(k, "format") == 0) {
} else {
"Cannot parse hash arguments:"
"'%s' is not supported format",
value);
return -1;
}
}
args++;
}
}
return 0;
}
static int
{
/* make sure IV is correct */
/* acquire IV */
return -1;
} else {
}
return -1;
} else {
}
return -1;
return 0;
}
static int
{
if (!has_been_init)
const char *value;
struct var_expand_crypt_context ctx;
int ret = 0;
if (p != NULL) {
}
return ret;
}
if (*value == '\0') {
return ret;
}
return -1;
ret = 0;
struct dcrypt_context_symmetric *dctx;
return -1;
if (ret == 0) {
/* makes compiler happy */
const char *enciv = "";
const char *res = "";
case FORMAT_HEX:
break;
case FORMAT_BASE64:
break;
default:
i_unreached();
}
if (ctx.enc_result_only)
else
ret = 1;
}
return ret;
}
static int
{
if (!has_been_init)
const char *value;
struct var_expand_crypt_context ctx;
int ret = 0;
if (p != NULL) {
}
return ret;
}
if (*value == '\0') {
return ret;
}
return -1;
/* make sure IV is correct */
/* see if IV can be taken from data */
} else {
}
str_truncate(field_value, 0);
/* try to decode iv and encdata */
case FORMAT_HEX:
break;
case FORMAT_BASE64:
break;
}
return -1;
}
struct dcrypt_context_symmetric *dctx;
return -1;
if (ret == 0)
return ret;
}
static const struct var_expand_extension_func_table funcs[] = {
{ "encrypt", var_expand_encrypt },
{ "decrypt", var_expand_decrypt },
};
static void var_expand_crypt_initialize(void)
{
}
{
/* do not initialize dcrypt here - saves alot of memory
to not load openssl every time. Only load it if
needed */
}
void var_expand_crypt_deinit(void)
{
if (has_been_init)
}
{
}
void auth_var_expand_crypt_deinit(void)
{
}