forked from blue/squawk
feat(omemo): add signal protocol wrappers
This commit is contained in:
parent
12ffe8e8e6
commit
2654e38665
28 changed files with 874 additions and 27 deletions
14
qomemo/signal/stores/CMakeLists.txt
Normal file
14
qomemo/signal/stores/CMakeLists.txt
Normal file
|
@ -0,0 +1,14 @@
|
|||
target_sources(squawk PRIVATE
|
||||
identity_key_store.cpp
|
||||
identity_key_store.h
|
||||
pre_key_store.cpp
|
||||
pre_key_store.h
|
||||
sender_key_store.cpp
|
||||
sender_key_store.h
|
||||
session_store.cpp
|
||||
session_store.h
|
||||
signed_pre_key_store.cpp
|
||||
signed_pre_key_store.h
|
||||
store_context.cpp
|
||||
store_context.h
|
||||
)
|
47
qomemo/signal/stores/identity_key_store.cpp
Normal file
47
qomemo/signal/stores/identity_key_store.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Created by victoria on 2021-05-13.
|
||||
*/
|
||||
|
||||
#include "identity_key_store.h"
|
||||
|
||||
void Signal::Store::IdentityKeyStore::boundToContext(
|
||||
signal_protocol_store_context *ctx) {
|
||||
signal_protocol_identity_key_store store{};
|
||||
|
||||
store.user_data = nullptr;
|
||||
store.destroy_func = nullptr;
|
||||
|
||||
store.get_identity_key_pair = [](signal_buffer **public_data, signal_buffer **private_data, void *ptr) {
|
||||
return static_cast<IdentityKeyStore *>(ptr)->getIdentityKeyPair(public_data, private_data);
|
||||
};
|
||||
store.get_local_registration_id = [](void *ptr, uint32_t *registrationId) {
|
||||
return static_cast<IdentityKeyStore *>(ptr)->getLocalRegistrationId(registrationId);
|
||||
};
|
||||
store.is_trusted_identity = [](const signal_protocol_address *address, uint8_t *key_data, size_t key_len,
|
||||
void *ptr) {
|
||||
return static_cast<IdentityKeyStore *>(ptr)->isTrustedIdentity(address, key_data, key_len);
|
||||
};
|
||||
store.save_identity = [](const signal_protocol_address *address, uint8_t *key_data, size_t key_len, void *ptr) {
|
||||
return static_cast<IdentityKeyStore *>(ptr)->saveIdentity(address, key_data, key_len);
|
||||
};
|
||||
|
||||
signal_protocol_store_context_set_identity_key_store(ctx, &store);
|
||||
}
|
||||
|
||||
int Signal::Store::IdentityKeyStore::getIdentityKeyPair(signal_buffer **public_data, signal_buffer **private_data) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Signal::Store::IdentityKeyStore::getLocalRegistrationId(uint32_t *registration_id) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Signal::Store::IdentityKeyStore::saveIdentity(const signal_protocol_address *address, uint8_t *key_data,
|
||||
size_t key_len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Signal::Store::IdentityKeyStore::isTrustedIdentity(const signal_protocol_address *address, uint8_t *key_data,
|
||||
size_t key_len) {
|
||||
return 0;
|
||||
}
|
21
qomemo/signal/stores/identity_key_store.h
Normal file
21
qomemo/signal/stores/identity_key_store.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Created by victoria on 2021-05-13.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <signal/signal_protocol.h>
|
||||
|
||||
namespace Signal::Store {
|
||||
|
||||
class IdentityKeyStore {
|
||||
public:
|
||||
static void boundToContext(signal_protocol_store_context *ctx);
|
||||
|
||||
int getIdentityKeyPair(signal_buffer **public_data, signal_buffer **private_data);
|
||||
int getLocalRegistrationId(uint32_t *registration_id);
|
||||
int saveIdentity(const signal_protocol_address *address, uint8_t *key_data, size_t key_len);
|
||||
int isTrustedIdentity(const signal_protocol_address *address, uint8_t *key_data, size_t key_len);
|
||||
};
|
||||
|
||||
} // namespace Signal::Store
|
43
qomemo/signal/stores/pre_key_store.cpp
Normal file
43
qomemo/signal/stores/pre_key_store.cpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Created by victoria on 2021-05-13.
|
||||
*/
|
||||
|
||||
#include "pre_key_store.h"
|
||||
|
||||
void Signal::Store::PreKeyStore::boundToContext(
|
||||
signal_protocol_store_context *ctx) {
|
||||
signal_protocol_pre_key_store store{};
|
||||
|
||||
store.destroy_func = nullptr;
|
||||
store.user_data = nullptr;
|
||||
|
||||
store.contains_pre_key = [](uint32_t id, void *ptr) {
|
||||
return static_cast<PreKeyStore *>(ptr)->containsPreKey(id);
|
||||
};
|
||||
store.load_pre_key = [](signal_buffer **record, uint32_t id, void *ptr) {
|
||||
return static_cast<PreKeyStore *>(ptr)->loadPreKey(record, id);
|
||||
};
|
||||
store.remove_pre_key = [](uint32_t id, void *ptr) {
|
||||
return static_cast<PreKeyStore *>(ptr)->removePreKey(id);
|
||||
};
|
||||
store.store_pre_key = [](uint32_t id, uint8_t *record, size_t size,
|
||||
void *ptr) {
|
||||
return static_cast<PreKeyStore *>(ptr)->storePreKey(id, record, size);
|
||||
};
|
||||
|
||||
signal_protocol_store_context_set_pre_key_store(ctx, &store);
|
||||
}
|
||||
|
||||
int Signal::Store::PreKeyStore::containsPreKey(uint32_t pre_key_id) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Signal::Store::PreKeyStore::loadPreKey(signal_buffer **record, uint32_t pre_key_id) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Signal::Store::PreKeyStore::storePreKey(uint32_t pre_key_id, uint8_t *record, size_t record_len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Signal::Store::PreKeyStore::removePreKey(uint32_t pre_key_id) { return 0; }
|
21
qomemo/signal/stores/pre_key_store.h
Normal file
21
qomemo/signal/stores/pre_key_store.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Created by victoria on 2021-05-13.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <signal/signal_protocol.h>
|
||||
|
||||
namespace Signal::Store {
|
||||
|
||||
class PreKeyStore {
|
||||
public:
|
||||
static void boundToContext(signal_protocol_store_context *ctx);
|
||||
|
||||
int containsPreKey(uint32_t pre_key_id);
|
||||
int loadPreKey(signal_buffer **record, uint32_t pre_key_id);
|
||||
int storePreKey(uint32_t pre_key_id, uint8_t *record, size_t record_len);
|
||||
int removePreKey(uint32_t pre_key_id);
|
||||
};
|
||||
|
||||
} // namespace Signal::Store
|
36
qomemo/signal/stores/sender_key_store.cpp
Normal file
36
qomemo/signal/stores/sender_key_store.cpp
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Created by victoria on 2021-05-13.
|
||||
*/
|
||||
|
||||
#include "sender_key_store.h"
|
||||
|
||||
void Signal::Store::SenderKeyStore::boundToContext(
|
||||
signal_protocol_store_context *ctx) {
|
||||
signal_protocol_sender_key_store store{};
|
||||
|
||||
store.user_data = nullptr;
|
||||
store.destroy_func = nullptr;
|
||||
|
||||
store.load_sender_key = [](signal_buffer **record, signal_buffer **user_record,
|
||||
const signal_protocol_sender_key_name *sender_key_name, void *ptr) {
|
||||
return static_cast<SenderKeyStore *>(ptr)->loadSenderKey(record, user_record, sender_key_name);
|
||||
};
|
||||
store.store_sender_key = [](const signal_protocol_sender_key_name *sender_key_name, uint8_t *record,
|
||||
size_t record_len, uint8_t *user_record, size_t user_record_len, void *ptr) {
|
||||
return static_cast<SenderKeyStore *>(ptr)->storeSenderKey(sender_key_name, record, record_len, user_record,
|
||||
user_record_len);
|
||||
};
|
||||
|
||||
signal_protocol_store_context_set_sender_key_store(ctx, &store);
|
||||
}
|
||||
|
||||
int Signal::Store::SenderKeyStore::loadSenderKey(signal_buffer **record, signal_buffer **user_record,
|
||||
const signal_protocol_sender_key_name *sender_key_name) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Signal::Store::SenderKeyStore::storeSenderKey(const signal_protocol_sender_key_name *sender_key_name,
|
||||
uint8_t *record, size_t record_len, uint8_t *user_record,
|
||||
size_t user_record_len) {
|
||||
return 0;
|
||||
}
|
21
qomemo/signal/stores/sender_key_store.h
Normal file
21
qomemo/signal/stores/sender_key_store.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Created by victoria on 2021-05-13.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <signal/signal_protocol.h>
|
||||
|
||||
namespace Signal::Store {
|
||||
|
||||
class SenderKeyStore {
|
||||
public:
|
||||
static void boundToContext(signal_protocol_store_context *ctx);
|
||||
|
||||
int storeSenderKey(const signal_protocol_sender_key_name *sender_key_name, uint8_t *record, size_t record_len,
|
||||
uint8_t *user_record, size_t user_record_len);
|
||||
int loadSenderKey(signal_buffer **record, signal_buffer **user_record,
|
||||
const signal_protocol_sender_key_name *sender_key_name);
|
||||
};
|
||||
|
||||
} // namespace Signal::Store
|
63
qomemo/signal/stores/session_store.cpp
Normal file
63
qomemo/signal/stores/session_store.cpp
Normal file
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Created by victoria on 2021-05-13.
|
||||
*/
|
||||
|
||||
#include "session_store.h"
|
||||
|
||||
void Signal::Store::SessionStore::boundToContext(
|
||||
signal_protocol_store_context *ctx) {
|
||||
signal_protocol_session_store store{};
|
||||
|
||||
store.user_data = nullptr;
|
||||
store.destroy_func = nullptr;
|
||||
|
||||
store.load_session_func = [](signal_buffer **record, signal_buffer **user_record,
|
||||
const signal_protocol_address *address, void *ptr) {
|
||||
return static_cast<SessionStore *>(ptr)->loadSession(record, user_record, address);
|
||||
};
|
||||
store.get_sub_device_sessions_func = [](signal_int_list **sessions, const char *name, size_t name_len, void *ptr) {
|
||||
return static_cast<SessionStore *>(ptr)->getSubDeviceSessions(sessions, name, name_len);
|
||||
};
|
||||
store.store_session_func = [](const signal_protocol_address *address, uint8_t *record, size_t record_len,
|
||||
uint8_t *user_record, size_t user_record_len, void *ptr) {
|
||||
return static_cast<SessionStore *>(ptr)->storeSession(address, record, record_len, user_record,
|
||||
user_record_len);
|
||||
};
|
||||
store.contains_session_func = [](const signal_protocol_address *address, void *ptr) {
|
||||
return static_cast<SessionStore *>(ptr)->containsSession(address);
|
||||
};
|
||||
store.delete_session_func = [](const signal_protocol_address *address, void *ptr) {
|
||||
return static_cast<SessionStore *>(ptr)->deleteSession(address);
|
||||
};
|
||||
store.delete_all_sessions_func = [](const char *name, size_t name_len, void *ptr) {
|
||||
return static_cast<SessionStore *>(ptr)->deleteAllSessions(name, name_len);
|
||||
};
|
||||
|
||||
signal_protocol_store_context_set_session_store(ctx, &store);
|
||||
}
|
||||
|
||||
int Signal::Store::SessionStore::loadSession(signal_buffer **record, signal_buffer **user_record,
|
||||
const signal_protocol_address *address) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Signal::Store::SessionStore::getSubDeviceSessions(signal_int_list **sessions, const char *name, size_t name_len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Signal::Store::SessionStore::storeSession(const signal_protocol_address *address, uint8_t *record,
|
||||
size_t record_len, uint8_t *user_record, size_t user_record_len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Signal::Store::SessionStore::containsSession(const signal_protocol_address *address) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Signal::Store::SessionStore::deleteSession(const signal_protocol_address *address) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Signal::Store::SessionStore::deleteAllSessions(const char *name, size_t name_len) {
|
||||
return 0;
|
||||
}
|
24
qomemo/signal/stores/session_store.h
Normal file
24
qomemo/signal/stores/session_store.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Created by victoria on 2021-05-13.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <signal/signal_protocol.h>
|
||||
|
||||
namespace Signal::Store {
|
||||
|
||||
class SessionStore {
|
||||
public:
|
||||
static void boundToContext(signal_protocol_store_context *ctx);
|
||||
|
||||
int loadSession(signal_buffer **record, signal_buffer **user_record, const signal_protocol_address *address);
|
||||
int getSubDeviceSessions(signal_int_list **sessions, const char *name, size_t name_len);
|
||||
int storeSession(const signal_protocol_address *address, uint8_t *record, size_t record_len,
|
||||
uint8_t *user_record, size_t user_record_len);
|
||||
int containsSession(const signal_protocol_address *address);
|
||||
int deleteSession(const signal_protocol_address *address);
|
||||
int deleteAllSessions(const char *name, size_t name_len);
|
||||
};
|
||||
|
||||
} // namespace Signal::Store
|
48
qomemo/signal/stores/signed_pre_key_store.cpp
Normal file
48
qomemo/signal/stores/signed_pre_key_store.cpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Created by victoria on 2021-05-13.
|
||||
*/
|
||||
|
||||
#include "signed_pre_key_store.h"
|
||||
|
||||
void Signal::Store::SignedPreKeyStore::boundToContext(
|
||||
signal_protocol_store_context *ctx) {
|
||||
signal_protocol_signed_pre_key_store store{};
|
||||
|
||||
store.user_data = nullptr;
|
||||
store.destroy_func = nullptr;
|
||||
|
||||
store.load_signed_pre_key = [](signal_buffer **record, uint32_t signed_pre_key_id, void *ptr) {
|
||||
return static_cast<SignedPreKeyStore *>(ptr)->loadSignedPreKey(
|
||||
record, signed_pre_key_id);
|
||||
};
|
||||
store.store_signed_pre_key = [](uint32_t signed_pre_key_id, uint8_t *record, size_t record_len, void *ptr) {
|
||||
return static_cast<SignedPreKeyStore *>(ptr)->storeSignedPreKey(
|
||||
signed_pre_key_id, record, record_len);
|
||||
};
|
||||
store.contains_signed_pre_key = [](uint32_t signed_pre_key_id, void *ptr) {
|
||||
return static_cast<SignedPreKeyStore *>(ptr)->containsSignedPreKey(
|
||||
signed_pre_key_id);
|
||||
};
|
||||
store.remove_signed_pre_key = [](uint32_t signed_pre_key_id, void *ptr) {
|
||||
return static_cast<SignedPreKeyStore *>(ptr)->removeSignedPreKey(
|
||||
signed_pre_key_id);
|
||||
};
|
||||
|
||||
signal_protocol_store_context_set_signed_pre_key_store(ctx, &store);
|
||||
}
|
||||
|
||||
int Signal::Store::SignedPreKeyStore::loadSignedPreKey(signal_buffer **record, uint32_t signed_pre_key_id) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Signal::Store::SignedPreKeyStore::storeSignedPreKey(uint32_t signed_pre_key_id, uint8_t *record, size_t record_len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Signal::Store::SignedPreKeyStore::containsSignedPreKey(uint32_t signed_pre_key_id) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Signal::Store::SignedPreKeyStore::removeSignedPreKey(uint32_t signed_pre_key_id) {
|
||||
return 0;
|
||||
}
|
20
qomemo/signal/stores/signed_pre_key_store.h
Normal file
20
qomemo/signal/stores/signed_pre_key_store.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* Created by victoria on 2021-05-13.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <signal/signal_protocol.h>
|
||||
|
||||
namespace Signal::Store {
|
||||
|
||||
class SignedPreKeyStore {
|
||||
public:
|
||||
static void boundToContext(signal_protocol_store_context *ctx);
|
||||
int loadSignedPreKey(signal_buffer **record, uint32_t signed_pre_key_id);
|
||||
int storeSignedPreKey(uint32_t signed_pre_key_id, uint8_t *record, size_t record_len);
|
||||
int containsSignedPreKey(uint32_t signed_pre_key_id);
|
||||
int removeSignedPreKey(uint32_t signed_pre_key_id);
|
||||
};
|
||||
|
||||
} // namespace Signal::Store
|
13
qomemo/signal/stores/store_context.cpp
Normal file
13
qomemo/signal/stores/store_context.cpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
/*
|
||||
* Created by victoria on 2021-05-13.
|
||||
*/
|
||||
|
||||
#include "store_context.h"
|
||||
|
||||
Signal::Store::Context::Context(signal_context *global) {
|
||||
signal_protocol_store_context_create(&ctx, global);
|
||||
}
|
||||
|
||||
Signal::Store::Context::~Context() {
|
||||
signal_protocol_store_context_destroy(ctx);
|
||||
}
|
24
qomemo/signal/stores/store_context.h
Normal file
24
qomemo/signal/stores/store_context.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Created by victoria on 2021-05-13.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <signal/signal_protocol.h>
|
||||
|
||||
namespace Signal::Store {
|
||||
|
||||
class Context {
|
||||
public:
|
||||
explicit Context(signal_context *global);
|
||||
~Context();
|
||||
|
||||
Context(const Context &) = delete;
|
||||
Context(Context &&) = delete;
|
||||
Context &operator=(const Context &) = delete;
|
||||
|
||||
private:
|
||||
signal_protocol_store_context *ctx{nullptr};
|
||||
};
|
||||
|
||||
} // namespace Signal::Store
|
Loading…
Add table
Add a link
Reference in a new issue