test-mail-key.c revision efe78d3ba24fc866af1c79b9223dc0809ba26cad
/* Copyright (c) 2015-2016 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "test-common.h"
#include "ioloop.h"
#include "lib-signals.h"
#include "master-service.h"
#include "mail-storage.h"
#include "mail-storage-service.h"
#include "mailbox-list.h"
#include "settings-parser.h"
#include "mail-user.h"
#include "safe-mkstemp.h"
#include "safe-mkdir.h"
#include "str.h"
#include "unlink-directory.h"
#include "randgen.h"
#include "dcrypt.h"
#include "hex-binary.h"
#include "mail-crypt-common.h"
#include "mail-crypt-key.h"
#include "mail-crypt-plugin.h"
static const char *mcp_old_user_key = "1\t716\t0\t048FD04FD3612B22D32790C592CF21CEF417EFD2EA34AE5F688FA5B51BED29E05A308B68DA78E16E90B47A11E133BD9A208A2894FD01B0BEE865CE339EA3FB17AC\td0cfaca5d335f9edc41c84bb47465184cb0e2ec3931bebfcea4dd433615e77a0";
static const char *mcp_old_user_key_id = "d0cfaca5d335f9edc41c84bb47465184cb0e2ec3931bebfcea4dd433615e77a0";
static const char *mcp_old_box_key = "1\t716\t1\t0567e6bf9579813ae967314423b0fceb14bda24749303923de9a9bb9370e0026f995901a57e63113eeb2baf0c940e978d00686cbb52bd5014bc318563375876255\t0300E46DA2125427BE968EB3B649910CDC4C405E5FFDE18D433A97CABFEE28CEEFAE9EE356C792004FFB80981D67E741B8CC036A34235A8D2E1F98D1658CFC963D07EB\td0cfaca5d335f9edc41c84bb47465184cb0e2ec3931bebfcea4dd433615e77a0\t7c9a1039ea2e4fed73e81dd3ffc3fa22ea4a28352939adde7bf8ea858b00fa4f";
static const char *mcp_old_box_key_id = "7c9a1039ea2e4fed73e81dd3ffc3fa22ea4a28352939adde7bf8ea858b00fa4f";
static const char *mail_home;
static const char *test_user_key_id;
static const char *test_box_key_id;
static struct mail_crypt_user mail_crypt_user;
{
return &mail_crypt_user;
}
static
{
const char *attr_name;
enum mail_attribute_type attr_type;
} else {
shared ? PUBKEYS_PREFIX :
pubid);
}
struct mail_attribute_value value;
int ret;
if (ret < 0) {
}
} else {
}
return ret;
}
static int
{
const char *attr_name;
enum mail_attribute_type attr_type;
} else {
shared ? PUBKEYS_PREFIX :
pubid);
}
struct mail_attribute_value attr_value;
int ret;
i_zero(&attr_value);
attr_name, &attr_value)) <= 0) {
if (ret < 0) {
}
}
return ret;
}
static
int init_test_mail_user(void)
{
struct setting_parser_context *set_parser;
const char *error;
char path_buf[4096];
i_fatal("getcwd() failed: %m");
struct mail_storage_service_input input = {
.userdb_fields = (const char*const[]){
t_strdup_printf("mail=maildir:~/"),
t_strdup_printf("mail_crypt_curve=prime256v1"),
},
.username = "mcp_test",
.no_userdb_lookup = TRUE,
};
&test_service_user, &error) < 0)
{
return -1;
}
t_strdup_printf("mail_attribute_dict=file:%s/dovecot-attributes",
mail_home)) < 0) {
i_error("Cannot set mail_attribute_dict: %s",
return -1;
}
&test_mail_user, &error) < 0)
{
return -1;
}
return 0;
}
static
void deinit_test_mail_user()
{
const char *error;
&error) < 0)
}
static void test_generate_user_key(void)
{
struct dcrypt_keypair pair;
const char *pubid;
test_begin("generate user key");
/* try to generate a keypair for user */
test_exit(1);
}
/* keys ought to be in cache or somewhere...*/
{
}
test_end();
}
static void test_generate_inbox_key(void)
{
struct dcrypt_public_key *user_key;
struct dcrypt_keypair pair;
test_begin("generate inbox key");
&error) <= 0) {
}
struct mail_namespace *ns =
if (mailbox_open(box) < 0)
i_fatal("mailbox_open(INBOX) failed: %s",
&error) < 0) {
test_exit(1);
}
mailbox_free(&box);
test_end();
}
static void test_cache_reset(void)
{
struct dcrypt_keypair pair;
test_begin("cache reset");
test_end();
}
static void test_verify_keys(void)
{
const char *enc_id;
test_begin("verify keys");
struct mail_namespace *ns =
if (mailbox_open(box) < 0)
i_fatal("mailbox_open(INBOX) failed: %s",
/* verify links */
/* user's public key */
&error) > 0);
/* load key */
/* see if it matches */
&error) > 0);
/* user's private key */
&error) > 0);
/* load key */
/* see if it matches */
&error) > 0);
/* inbox's public key */
&error) > 0);
/* load key */
/* see if it matches */
&error) > 0);
/* user's private key */
&error) > 0);
/* load key */
/* see if it matches */
&error) > 0);
mailbox_free(&box);
test_end();
}
static void test_old_key(void)
{
test_begin("old keys");
struct mail_namespace *ns =
if (mailbox_open(box) < 0)
i_fatal("mailbox_open(INBOX) failed: %s",
mcp_old_box_key, &error);
(void)mailbox_transaction_commit(&t);
/* try to load old key */
i_error("mail_crypt_get_private_key(%s) failed: %s",
error);
}
mailbox_free(&box);
test_end();
}
static void test_setup(void)
{
struct dcrypt_settings set = {
};
i_info("No functional dcrypt backend found - skipping tests");
test_exit(0);
}
/* allocate a user */
if (init_test_mail_user() < 0) {
test_exit(1);
}
}
static void test_teardown(void)
{
}
{
void (*tests[])(void) = {
};
random_init();
return ret;
}