Ring Daemon 16.0.0
Loading...
Searching...
No Matches
accountarchive.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2025 Savoir-faire Linux Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17#pragma once
18
19#include "jami_contact.h"
20#include "jamidht/jamiaccount.h"
21#include "fileutils.h"
22
23#include <opendht/crypto.h>
24#include <memory>
25#include <vector>
26#include <map>
27#include <string>
28
29namespace jami {
30
36{
38 dht::crypto::Identity id;
39
41 std::shared_ptr<dht::crypto::PrivateKey> ca_key;
42
44 std::shared_ptr<dht::crypto::RevocationList> revoked;
45
47 std::vector<uint8_t> eth_key;
48
50 std::map<dht::InfoHash, Contact> contacts;
51
52 // Conversations
53 std::map<std::string, ConvInfo> conversations;
54 std::map<std::string, ConversationRequest> conversationsRequests;
55
57 std::map<std::string, std::string> config;
58
60 std::vector<uint8_t> password_salt;
61
62 AccountArchive() = default;
63 AccountArchive(const std::vector<uint8_t>& data, const std::vector<uint8_t>& password_salt = {})
64 {
65 deserialize(std::string_view((const char*) data.data(), data.size()), password_salt);
66 }
67 AccountArchive(std::string_view data, const std::vector<uint8_t>& password_salt = {})
68 {
70 }
71 AccountArchive(const std::filesystem::path& path,
72 std::string_view scheme = {},
73 const std::string& pwd = {})
74 {
75 load(path, scheme, pwd);
76 }
77
79 std::string serialize() const;
80
82 void deserialize(std::string_view data, const std::vector<uint8_t>& salt);
83
85 void load(const std::filesystem::path& path, std::string_view scheme, const std::string& pwd)
86 {
87 auto data = fileutils::readArchive(path, scheme, pwd);
88 deserialize(data.data, data.salt);
89 }
90
92 bool save(const std::filesystem::path& path,
93 std::string_view scheme,
94 const std::string& password) const
95 {
96 return fileutils::writeArchive(serialize(), path, scheme, password, password_salt);
97 }
98};
99
100} // namespace jami
ArchiveStorageData readArchive(const std::filesystem::path &path, std::string_view scheme, const std::string &pwd)
bool writeArchive(const std::string &archive_str, const std::filesystem::path &path, std::string_view scheme, const std::string &password, const std::vector< uint8_t > &password_salt)
void emitSignal(Args... args)
Definition ring_signal.h:64
Crypto material contained in the archive, not persisted in the account configuration.
AccountArchive(const std::filesystem::path &path, std::string_view scheme={}, const std::string &pwd={})
void load(const std::filesystem::path &path, std::string_view scheme, const std::string &pwd)
Load archive from file, optionally encrypted with provided password.
bool save(const std::filesystem::path &path, std::string_view scheme, const std::string &password) const
Save archive to file, optionally encrypted with provided password.
std::map< dht::InfoHash, Contact > contacts
Contacts.
void deserialize(std::string_view data, const std::vector< uint8_t > &salt)
Deserialize archive from memory.
AccountArchive(const std::vector< uint8_t > &data, const std::vector< uint8_t > &password_salt={})
std::map< std::string, ConversationRequest > conversationsRequests
std::shared_ptr< dht::crypto::RevocationList > revoked
Revoked devices.
std::string serialize() const
Serialize structured archive data to memory.
std::shared_ptr< dht::crypto::PrivateKey > ca_key
Generated CA key (for self-signed certificates)
AccountArchive(std::string_view data, const std::vector< uint8_t > &password_salt={})
std::vector< uint8_t > password_salt
Salt for the archive encryption password.
AccountArchive()=default
dht::crypto::Identity id
Account main private key and certificate chain.
std::map< std::string, ConvInfo > conversations
std::vector< uint8_t > eth_key
Ethereum private key.
std::map< std::string, std::string > config
Account configuration.