fs-crypt-common.c revision 86ad48a2e740bd63a9b7299d7f3e229831d9b303
/* Copyright (c) 2015-2017 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "randgen.h"
#include "istream.h"
#include "ostream.h"
#include "istream-decrypt.h"
#include "ostream-encrypt.h"
#include "iostream-temp.h"
#include "mailbox-list.h"
#include "mail-namespace.h"
#include "mail-crypt-common.h"
#include "mail-crypt-key.h"
#include "dcrypt-iostream.h"
#include "fs-api-private.h"
struct crypt_fs {
struct mail_crypt_global_keys keys;
bool keys_loaded;
char *enc_algo;
char *set_prefix;
char *public_key_path;
char *private_key_path;
char *password;
};
struct crypt_fs_file {
struct fs_file *super_read;
enum fs_open_mode open_mode;
struct ostream *super_output;
struct ostream *temp_output;
};
/* defined outside this file */
extern const struct fs FS_CLASS_CRYPT;
static
static struct fs *fs_crypt_alloc(void)
{
}
static int
struct fs_settings *set)
{
const char *enc_algo, *set_prefix;
/* [algo=<s>:][set_prefix=<n>:][public_key_path=<s>:]
[private_key_path=<s>:[password=<s>:]]<parent fs> */
set_prefix = "mail_crypt_global";
enc_algo = "aes-256-gcm-sha256";
for (;;) {
if (p == NULL) {
return -1;
}
break;
args = p+1;
set_prefix = value;
else {
return -1;
}
}
if (parent_args == NULL) {
parent_name = args;
parent_args = "";
} else {
parent_args++;
}
return -1;
}
return 0;
}
{
}
static struct fs_file *fs_crypt_file_alloc(void)
{
}
static void
{
/* avoid unnecessarily creating two seekable streams */
if (mode == FS_OPEN_MODE_READONLY &&
(flags & FS_OPEN_FLAG_ASYNC) == 0) {
/* use async stream for super, so fs_read_stream() won't create
another seekable stream needlessly */
} else {
}
}
{
}
{
}
char **key_data_r, const char **error_r)
{
int ret;
while (i_stream_read(input) > 0) ;
if (input->stream_errno != 0) {
ret = -1;
} else {
ret = 0;
}
return ret;
}
static int
{
char *key_data;
if (fs_crypt_read_file("crypt:public_key_path",
return -1;
if (mail_crypt_load_global_public_key("crypt:public_key_path",
error_r) < 0) {
return -1;
}
}
if (fs_crypt_read_file("crypt:private_key_path",
return -1;
if (mail_crypt_load_global_private_key("crypt:private_key_path",
key_data, "crypt:password",
error_r) < 0) {
return -1;
}
}
return 0;
}
static int
fs_crypt_istream_get_key(const char *pubkey_digest,
struct dcrypt_private_key **priv_key_r,
{
return -1;
}
static struct istream *
{
}
}
{
const char *error;
"Couldn't read settings: %s", error);
return;
}
i_debug("No public key provided, "
"NOT encrypting stream %s",
return;
}
enum io_stream_encrypt_flags flags;
} else {
}
file->temp_output =
flags);
}
{
int ret;
else
}
if (!success) {
/* no encryption */
"write(%s) failed: %s",
} else {
}
return -1;
}
/* no encrypt */
}
/* finishing up */
}
/* finish writing the temporary file */
return ret;
}