22#include <dhtnet/multiplexed_socket.h>
44 const std::filesystem::path& path,
47 std::string archivePath,
48 const std::string& nameServer)
52 , archivePath_(
std::
move(archivePath))
63 std::string deviceName,
64 std::unique_ptr<AccountCredentials> credentials,
74 virtual std::vector<uint8_t>
getPasswordKey(
const std::string& )
override;
79 std::string_view auth_scheme,
85 std::string_view scheme,
86 const std::string& password,
89 std::string_view scheme,
90 const std::string& password);
94 const std::string& scheme);
98 std::string_view scheme,
99 const std::string& password,
107 const std::string& password,
108 dht::crypto::Identity& device,
109 const dht::InfoHash&
id,
113 void onAuthReady(
const std::string& deviceId, std::shared_ptr<dhtnet::ChannelSocket> channel);
121 std::string accountId;
125 std::string deviceName;
126 std::unique_ptr<ArchiveAccountCredentials> credentials;
127 std::shared_ptr<LinkDeviceContext> linkDevCtx;
128 std::unique_ptr<AddDeviceContext> addDeviceCtx;
131 std::unique_ptr<asio::steady_timer> timeout;
132 bool canceled {
false};
134 struct DecodingContext;
136 struct DeviceAuthInfo;
137 std::shared_ptr<AuthContext> authCtx_;
139 void createAccount(AuthContext& ctx);
140 void migrateAccount(AuthContext& ctx);
142 std::pair<std::string, std::shared_ptr<dht::Value>> makeReceipt(
143 const dht::crypto::Identity&
id,
144 const dht::crypto::Certificate& device,
145 const std::string& ethAccount);
146 void updateArchive(AccountArchive&
content )
const;
147 void saveArchive(AccountArchive&
content, std::string_view scheme,
const std::string&
pwd);
148 AccountArchive readArchive(std::string_view scheme,
const std::string& password)
const;
149 static std::pair<std::vector<uint8_t>, dht::InfoHash> computeKeys(
const std::string& password,
150 const std::string&
pin,
152 bool updateCertificates(AccountArchive&
archive, dht::crypto::Identity& device);
153 static bool needsMigration(
const std::string& accountId,
const dht::crypto::Identity&
id);
155 void loadFromFile(AuthContext& ctx);
158 void startLoadArchiveFromDevice(
const std::shared_ptr<AuthContext>& ctx);
160 bool doAddDevice(std::string_view scheme,
161 const std::shared_ptr<AuthContext>& ctx,
162 const std::shared_ptr<dhtnet::ChannelSocket>& channel);
166 inline std::weak_ptr<ArchiveAccountManager> weak()
173 std::string archivePath_;
NameDirectory::RegistrationCallback RegistrationCallback
std::function< void(const std::shared_ptr< dht::crypto::Certificate > &)> OnNewDeviceCb
virtual void registerName(const std::string &name, std::string_view scheme, const std::string &password, RegistrationCallback cb)=0
std::function< void()> OnDeviceAnnouncedCb
virtual void onSyncData(DeviceSync &&device, bool checkDevice=true)
std::shared_future< std::shared_ptr< dht::crypto::PrivateKey > > PrivateKey
std::function< void(RevokeDeviceResult)> RevokeDeviceCallback
std::function< void(AuthError error, const std::string &message)> AuthFailureCallback
std::future< std::unique_ptr< dht::crypto::CertificateRequest > > CertRequest
std::function< void(const AccountInfo &info, const std::map< std::string, std::string > &config, std::string &&receipt, std::vector< uint8_t > &&receipt_signature)> AuthSuccessCallback
virtual std::vector< uint8_t > getPasswordKey(const std::string &) override
bool exportArchive(const std::string &destinationPath, std::string_view scheme, const std::string &password)
bool cancelAddDevice(uint32_t token) override
bool provideAccountAuthentication(const std::string &credentialsFromUser, const std::string &scheme)
int32_t addDevice(const std::string &uri, std::string_view auth_scheme, AuthChannelHandler *) override
Initiates the process of adding a new device to the account.
std::function< std::map< std::string, std::string >()> OnExportConfig
void initAuthentication(PrivateKey request, std::string deviceName, std::unique_ptr< AccountCredentials > credentials, AuthSuccessCallback onSuccess, AuthFailureCallback onFailure, const OnChangeCallback &onChange) override
bool revokeDevice(const std::string &device, std::string_view scheme, const std::string &password, RevokeDeviceCallback) override
void syncDevices() override
bool confirmAddDevice(uint32_t token) override
bool setValidity(std::string_view scheme, const std::string &password, dht::crypto::Identity &device, const dht::InfoHash &id, int64_t validity)
Change the validity of a certificate.
std::function< void(DeviceSync &&)> OnSyncData
ArchiveAccountManager(const std::string &accountId, const std::filesystem::path &path, OnExportConfig &&onExportConfig, OnSyncData &&onSyncData, std::string archivePath, const std::string &nameServer)
void startSync(const OnNewDeviceCb &, const OnDeviceAnnouncedCb &dcb={}, bool publishPresence=true) override
bool isPasswordValid(const std::string &password) override
void onAuthReady(const std::string &deviceId, std::shared_ptr< dhtnet::ChannelSocket > channel)
bool changePassword(const std::string &password_old, const std::string &password_new) override
Manages channels for syncing informations.
void emitSignal(Args... args)
dht::crypto::Identity updateIdentity
std::vector< std::string > dhtBootstrap