2019-06-17 04:47:56 -04:00
|
|
|
/*
|
|
|
|
* omemo.h
|
2019-11-13 06:11:05 -05:00
|
|
|
* vim: expandtab:ts=4:sts=4:sw=4
|
2019-06-17 04:47:56 -04:00
|
|
|
*
|
|
|
|
* Copyright (C) 2019 Paul Fariello <paul@fariello.eu>
|
|
|
|
*
|
|
|
|
* This file is part of Profanity.
|
|
|
|
*
|
|
|
|
* Profanity is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Profanity is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Profanity. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* In addition, as a special exception, the copyright holders give permission to
|
|
|
|
* link the code of portions of this program with the OpenSSL library under
|
|
|
|
* certain conditions as described in each individual source file, and
|
|
|
|
* distribute linked combinations including the two.
|
|
|
|
*
|
|
|
|
* You must obey the GNU General Public License in all respects for all of the
|
|
|
|
* code used other than OpenSSL. If you modify file(s) with this exception, you
|
|
|
|
* may extend this exception to your version of the file(s), but you are not
|
|
|
|
* obligated to do so. If you do not wish to do so, delete this exception
|
|
|
|
* statement from your version. If you delete this exception statement from all
|
|
|
|
* source files in the program, then also delete it here.
|
|
|
|
*
|
|
|
|
*/
|
2019-02-22 13:17:26 -05:00
|
|
|
#include <glib.h>
|
|
|
|
|
2020-07-07 03:43:28 -04:00
|
|
|
#include "ui/ui.h"
|
2020-07-07 07:53:30 -04:00
|
|
|
#include "config/account.h"
|
2019-02-19 12:38:15 -05:00
|
|
|
|
2019-02-26 13:53:06 -05:00
|
|
|
#define OMEMO_ERR_UNSUPPORTED_CRYPTO -10000
|
2020-07-07 08:18:57 -04:00
|
|
|
#define OMEMO_ERR_GCRYPT -20000
|
2019-02-26 13:53:06 -05:00
|
|
|
|
2020-07-20 16:49:50 -04:00
|
|
|
#define OMEMO_AESGCM_NONCE_LENGTH 12
|
|
|
|
#define OMEMO_AESGCM_KEY_LENGTH 32
|
|
|
|
#define OMEMO_AESGCM_URL_SCHEME "aesgcm"
|
2020-06-28 09:16:03 -04:00
|
|
|
|
2019-04-15 16:09:47 -04:00
|
|
|
typedef enum {
|
|
|
|
PROF_OMEMOPOLICY_MANUAL,
|
|
|
|
PROF_OMEMOPOLICY_AUTOMATIC,
|
|
|
|
PROF_OMEMOPOLICY_ALWAYS
|
|
|
|
} prof_omemopolicy_t;
|
|
|
|
|
2019-02-19 12:58:40 -05:00
|
|
|
typedef struct omemo_context_t omemo_context;
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
typedef struct omemo_key
|
|
|
|
{
|
|
|
|
unsigned char* data;
|
2019-02-26 13:53:06 -05:00
|
|
|
size_t length;
|
|
|
|
gboolean prekey;
|
|
|
|
uint32_t device_id;
|
2019-03-06 11:10:28 -05:00
|
|
|
uint32_t id;
|
2019-02-26 13:53:06 -05:00
|
|
|
} omemo_key_t;
|
|
|
|
|
2019-02-19 13:23:50 -05:00
|
|
|
void omemo_init(void);
|
2019-07-04 04:30:56 -04:00
|
|
|
void omemo_close(void);
|
2020-07-07 08:18:57 -04:00
|
|
|
void omemo_on_connect(ProfAccount* account);
|
2019-03-21 19:03:16 -04:00
|
|
|
void omemo_on_disconnect(void);
|
2020-07-07 08:18:57 -04:00
|
|
|
void omemo_generate_crypto_materials(ProfAccount* account);
|
|
|
|
void omemo_key_free(omemo_key_t* key);
|
2019-04-08 13:09:25 -04:00
|
|
|
void omemo_publish_crypto_materials(void);
|
2019-02-21 13:04:01 -05:00
|
|
|
|
|
|
|
uint32_t omemo_device_id(void);
|
2020-07-07 08:18:57 -04:00
|
|
|
void omemo_identity_key(unsigned char** output, size_t* length);
|
|
|
|
void omemo_signed_prekey(unsigned char** output, size_t* length);
|
|
|
|
void omemo_signed_prekey_signature(unsigned char** output, size_t* length);
|
|
|
|
void omemo_prekeys(GList** prekeys, GList** ids, GList** lengths);
|
|
|
|
void omemo_set_device_list(const char* const jid, GList* device_list);
|
|
|
|
GKeyFile* omemo_identity_keyfile(void);
|
2019-03-07 12:58:15 -05:00
|
|
|
void omemo_identity_keyfile_save(void);
|
2020-07-07 08:18:57 -04:00
|
|
|
GKeyFile* omemo_trust_keyfile(void);
|
2019-04-08 21:01:02 -04:00
|
|
|
void omemo_trust_keyfile_save(void);
|
2020-07-07 08:18:57 -04:00
|
|
|
GKeyFile* omemo_sessions_keyfile(void);
|
2019-03-07 01:20:29 -05:00
|
|
|
void omemo_sessions_keyfile_save(void);
|
2020-07-07 08:18:57 -04:00
|
|
|
char* omemo_format_fingerprint(const char* const fingerprint);
|
|
|
|
char* omemo_own_fingerprint(gboolean formatted);
|
|
|
|
void omemo_trust(const char* const jid, const char* const fingerprint);
|
|
|
|
void omemo_untrust(const char* const jid, const char* const fingerprint);
|
|
|
|
GList* omemo_known_device_identities(const char* const jid);
|
|
|
|
gboolean omemo_is_trusted_identity(const char* const jid, const char* const fingerprint);
|
|
|
|
char* omemo_fingerprint_autocomplete(const char* const search_str, gboolean previous, void* context);
|
2019-03-25 13:27:36 -04:00
|
|
|
void omemo_fingerprint_autocomplete_reset(void);
|
2020-07-07 08:18:57 -04:00
|
|
|
gboolean omemo_automatic_start(const char* const recipient);
|
2019-02-21 13:04:01 -05:00
|
|
|
|
2019-04-10 11:11:15 -04:00
|
|
|
void omemo_start_sessions(void);
|
2020-07-07 08:18:57 -04:00
|
|
|
void omemo_start_session(const char* const barejid);
|
|
|
|
void omemo_start_muc_sessions(const char* const roomjid);
|
|
|
|
void omemo_start_device_session(const char* const jid, uint32_t device_id, GList* prekeys, uint32_t signed_prekey_id, const unsigned char* const signed_prekey, size_t signed_prekey_len, const unsigned char* const signature, size_t signature_len, const unsigned char* const identity_key, size_t identity_key_len);
|
2019-02-25 11:27:11 -05:00
|
|
|
|
2019-02-21 13:04:01 -05:00
|
|
|
gboolean omemo_loaded(void);
|
2020-07-20 07:01:05 -04:00
|
|
|
char* omemo_on_message_send(ProfWin* win, const char* const message, gboolean request_receipt, gboolean muc, const char* const replace_id);
|
|
|
|
char* omemo_on_message_recv(const char* const from, uint32_t sid, const unsigned char* const iv, size_t iv_len, GList* keys, const unsigned char* const payload, size_t payload_len, gboolean muc, gboolean* trusted);
|
2020-06-28 09:16:03 -04:00
|
|
|
|
2020-07-20 07:01:05 -04:00
|
|
|
char* omemo_encrypt_file(FILE* in, FILE* out, off_t file_size, int* gcry_res);
|
2020-07-20 16:49:50 -04:00
|
|
|
int omemo_decrypt_file(FILE* in, FILE* out, off_t file_size, const char* fragment);
|
2020-07-20 07:01:05 -04:00
|
|
|
void omemo_free(void* a);
|
2020-07-20 16:49:50 -04:00
|
|
|
int omemo_parse_aesgcm_url(const char* aesgcm_url, char** https_url, char** fragment);
|