LCOV - code coverage report
Current view: top level - src/jamidht - archive_account_manager.h (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 4 4 100.0 %
Date: 2024-04-24 08:04:06 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :  *  Copyright (C) 2004-2024 Savoir-faire Linux Inc.
       3             :  *  Author : Adrien BĂ©raud <adrien.beraud@savoirfairelinux.com>
       4             :  *
       5             :  *  This program is free software; you can redistribute it and/or modify
       6             :  *  it under the terms of the GNU General Public License as published by
       7             :  *  the Free Software Foundation; either version 3 of the License, or
       8             :  *  (at your option) any later version.
       9             :  *
      10             :  *  This program is distributed in the hope that it will be useful,
      11             :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      12             :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13             :  *  GNU General Public License for more details.
      14             :  *
      15             :  *  You should have received a copy of the GNU General Public License
      16             :  *  along with this program. If not, see <https://www.gnu.org/licenses/>.
      17             :  */
      18             : #pragma once
      19             : 
      20             : #include "account_manager.h"
      21             : 
      22             : namespace jami {
      23             : 
      24             : class ArchiveAccountManager : public AccountManager
      25             : {
      26             : public:
      27             :     using OnExportConfig = std::function<std::map<std::string, std::string>()>;
      28             : 
      29         790 :     ArchiveAccountManager(const std::filesystem::path& path,
      30             :                           OnExportConfig&& onExportConfig,
      31             :                           std::string archivePath,
      32             :                           const std::string& nameServer)
      33         790 :         : AccountManager(path, nameServer)
      34         790 :         , onExportConfig_(std::move(onExportConfig))
      35        1580 :         , archivePath_(std::move(archivePath)) {}
      36             : 
      37             :     struct ArchiveAccountCredentials : AccountCredentials
      38             :     {
      39             :         in_port_t dhtPort;
      40             :         std::vector<std::string> dhtBootstrap;
      41             :         dht::crypto::Identity updateIdentity;
      42             :     };
      43             : 
      44             :     void initAuthentication(const std::string& accountId,
      45             :                             PrivateKey request,
      46             :                             std::string deviceName,
      47             :                             std::unique_ptr<AccountCredentials> credentials,
      48             :                             AuthSuccessCallback onSuccess,
      49             :                             AuthFailureCallback onFailure,
      50             :                             const OnChangeCallback& onChange) override;
      51             : 
      52             :     void startSync(const OnNewDeviceCb&, const OnDeviceAnnouncedCb& dcb = {}, bool publishPresence = true) override;
      53             : 
      54             :     bool changePassword(const std::string& password_old, const std::string& password_new) override;
      55             :     virtual std::vector<uint8_t> getPasswordKey(const std::string& /*password*/) override;
      56             : 
      57             :     void syncDevices() override;
      58             : 
      59             :     void addDevice(const std::string& password, AddDeviceCallback) override;
      60             :     bool revokeDevice(const std::string& device,
      61             :                       std::string_view scheme, const std::string& password,
      62             :                       RevokeDeviceCallback) override;
      63             :     bool exportArchive(const std::string& destinationPath, std::string_view scheme, const std::string& password);
      64             :     bool isPasswordValid(const std::string& password) override;
      65             : 
      66             : #if HAVE_RINGNS
      67             :     /*void lookupName(const std::string& name, LookupCallback cb) override;
      68             :     void lookupAddress(const std::string& address, LookupCallback cb) override;*/
      69             :     void registerName(const std::string& name,
      70             :                       std::string_view scheme, const std::string& password,
      71             :                       RegistrationCallback cb) override;
      72             : #endif
      73             : 
      74             :     /**
      75             :      * Change the validity of a certificate. If hash is empty, update all certificates
      76             :      */
      77             :     bool setValidity(std::string_view scheme, const std::string& password,
      78             :                      dht::crypto::Identity& device,
      79             :                      const dht::InfoHash& id,
      80             :                      int64_t validity);
      81             : 
      82             : private:
      83             :     struct DhtLoadContext;
      84             :     struct AuthContext
      85             :     {
      86             :         std::string accountId;
      87             :         PrivateKey key;
      88             :         CertRequest request;
      89             :         std::string deviceName;
      90             :         std::unique_ptr<ArchiveAccountCredentials> credentials;
      91             :         std::unique_ptr<DhtLoadContext> dhtContext;
      92             :         AuthSuccessCallback onSuccess;
      93             :         AuthFailureCallback onFailure;
      94             :     };
      95             : 
      96             :     void createAccount(AuthContext& ctx);
      97             :     void migrateAccount(AuthContext& ctx);
      98             : 
      99             :     std::pair<std::string, std::shared_ptr<dht::Value>> makeReceipt(
     100             :         const dht::crypto::Identity& id,
     101             :         const dht::crypto::Certificate& device,
     102             :         const std::string& ethAccount);
     103             :     void updateArchive(AccountArchive& content /*, const ContactList& syncData*/) const;
     104             :     void saveArchive(AccountArchive& content, std::string_view scheme, const std::string& pwd);
     105             :     AccountArchive readArchive(std::string_view scheme, const std::string& password) const;
     106             :     static std::pair<std::vector<uint8_t>, dht::InfoHash> computeKeys(const std::string& password,
     107             :                                                                       const std::string& pin,
     108             :                                                                       bool previous = false);
     109             :     bool updateCertificates(AccountArchive& archive, dht::crypto::Identity& device);
     110             :     static bool needsMigration(const dht::crypto::Identity& id);
     111             : 
     112             :     void loadFromFile(AuthContext& ctx);
     113             :     void loadFromDHT(const std::shared_ptr<AuthContext>& ctx);
     114             :     void onArchiveLoaded(AuthContext& ctx,
     115             :                          AccountArchive&& a);
     116             : 
     117             :     OnExportConfig onExportConfig_;
     118             :     std::string archivePath_;
     119             : };
     120             : 
     121             : } // namespace jami

Generated by: LCOV version 1.14