mail-crypt-key.h revision 4c78d9e646c4a1158d7167806937c02d86cdfc25
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi#ifndef MAIL_CRYPT_KEY
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi#define MAIL_CRYPT_KEY
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi#include "mail-crypt-common.h"
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi#include "mail-crypt-global-key.h"
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi#include "mail-storage.h"
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi/*
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi For mailboxes:
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi shared/<mailbox GUID>/.../crypt/active = digest for the active public key
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi that is used for encrypting new emails
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi shared/<mailbox GUID>/.../crypt/pubkeys/<digest> = <key>
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi private/<mailbox GUID>/.../crypt/privkeys/<digest> = <key>
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi Similarly for users:
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi shared/<INBOX GUID>/.../crypt/active = digest for the active public key that
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi is used for encrypting new folder keys
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi shared/<INBOX GUID>/.../crypt/pubkeys/<digest> = <key>
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi private/<INBOX GUID>/.../crypt/privkeys/<digest> = <key>
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi*/
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomistruct mail_crypt_key_cache_entry;
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi/**
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi * key cache management functions
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi */
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomivoid mail_crypt_key_cache_destroy(struct mail_crypt_key_cache_entry **cache);
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomivoid mail_crypt_key_register_mailbox_internal_attributes(void);
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi/* returns -1 on error, 0 not found, 1 = found */
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomiint mail_crypt_get_private_key(struct mailbox *box, const char *pubid,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi bool user_key, bool shared,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi struct dcrypt_private_key **key_r,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi const char **error_r);
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomiint mail_crypt_user_get_private_key(struct mail_user *user, const char *pubid,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi struct dcrypt_private_key **key_r,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi const char **error_r);
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomiint mail_crypt_box_get_private_key(struct mailbox *box,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi struct dcrypt_private_key **key_r,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi const char **error_r);
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomiint mail_crypt_box_get_private_keys(struct mailbox *box,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi ARRAY_TYPE(dcrypt_private_key) *keys_r,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi const char **error_r);
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomiint mail_crypt_user_get_public_key(struct mail_user *user,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi struct dcrypt_public_key **key_r,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi const char **error_r);
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomiint mail_crypt_box_get_public_key(struct mailbox *box,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi struct dcrypt_public_key **key_r,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi const char **error_r);
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomiint mail_crypt_box_get_shared_key(struct mailbox *box,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi const char *pubid,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi struct dcrypt_private_key **key_r,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi const char **error_r);
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi/* returns -1 on error, 0 no match , 1 = match */
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomiint mail_crypt_private_key_id_match(struct dcrypt_private_key *key,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi const char *pubid, const char **error_r);
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomiint mail_crypt_public_key_id_match(struct dcrypt_public_key *key,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi const char *pubid, const char **error_r);
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi/* returns -1 on error, 0 = ok */
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomiint mail_crypt_user_set_private_key(struct mail_user *user, const char *pubid,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi struct dcrypt_private_key *key,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi const char **error_r);
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomiint mail_crypt_box_set_private_key(struct mailbox *box, const char *pubid,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi struct dcrypt_private_key *key,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi struct dcrypt_public_key *user_key,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi const char **error_r);
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomiint mail_crypt_user_set_public_key(struct mail_user *user, const char *pubid,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi struct dcrypt_public_key *key,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi const char **error_r);
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomiint mail_crypt_box_set_public_key(struct mailbox *box, const char *pubid,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi struct dcrypt_public_key *key,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi const char **error_r);
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomiint mail_crypt_user_generate_keypair(struct mail_user *user,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi struct dcrypt_keypair *pair,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi const char **pubid_r,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi const char **error_r);
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomiint mail_crypt_box_generate_keypair(struct mailbox *box,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi struct dcrypt_keypair *pair,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi struct dcrypt_public_key *user_key,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi const char **pubid_r,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi const char **error_r);
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi/* returns -1 on error, 0 = ok */
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomiint mail_crypt_box_set_shared_key(struct mailbox_transaction_context *t,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi const char *pubid,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi struct dcrypt_private_key *privkey,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi const char *target_uid,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi struct dcrypt_public_key *user_key,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi const char **error_r);
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomiint mail_crypt_box_unset_shared_key(struct mailbox_transaction_context *t,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi const char *pubid,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi const char *target_uid,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi const char **error_r);
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomiint mail_crypt_box_share_private_keys(struct mailbox_transaction_context *t,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi struct dcrypt_public_key *dest_pub_key,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi const char *dest_user,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi const ARRAY_TYPE(dcrypt_private_key) *priv_keys,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi const char **error_r);
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi/* returns -1 on error, 0 = ok
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi these will also attempt to generate a keypair
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi*/
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomiint mail_crypt_user_get_or_gen_public_key(struct mail_user *user,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi struct dcrypt_public_key **pub_key_r,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi const char **error_r);
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomiint mail_crypt_box_get_or_gen_public_key(struct mailbox *box,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi struct dcrypt_public_key **pub_key_r,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi const char **error_r);
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi/* Lookup all private keys' digests. Returns 0 if ok, -1 on error. */
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomiint mail_crypt_box_get_pvt_digests(struct mailbox *box, pool_t pool,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi enum mail_attribute_type type,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi ARRAY_TYPE(const_string) *digests,
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi const char **error_r);
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi/* is secure sharing enabled */
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomibool mail_crypt_acl_secure_sharing_enabled(struct mail_user *user);
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi
4c78d9e646c4a1158d7167806937c02d86cdfc25Aki Tuomi#endif