Ring Daemon 16.0.0
Loading...
Searching...
No Matches
jami::AccountManager Class Referenceabstract

#include <account_manager.h>

Inheritance diagram for jami::AccountManager:
Inheritance graph
Collaboration diagram for jami::AccountManager:
Collaboration graph

Classes

struct  AccountCredentials
 

Public Types

enum class  AddDeviceError { INVALID_URI = -1 , ALREADY_LINKING = -2 , GENERIC = -3 }
 
enum class  AuthError { UNKNOWN , INVALID_ARGUMENTS , SERVER_ERROR , NETWORK }
 
using AuthFailureCallback = std::function< void(AuthError error, const std::string &message)>
 
using AuthSuccessCallback = std::function< void(const AccountInfo &info, const std::map< std::string, std::string > &config, std::string &&receipt, std::vector< uint8_t > &&receipt_signature)>
 
using CertRequest = std::future< std::unique_ptr< dht::crypto::CertificateRequest > >
 
using clock = std::chrono::system_clock
 
using DeviceSyncCallback = std::function< void(DeviceSync &&syncData)>
 
using LookupCallback = NameDirectory::LookupCallback
 
using OnChangeCallback = ContactList::OnChangeCallback
 
using OnDeviceAnnouncedCb = std::function< void()>
 
using OnNewDeviceCb = std::function< void(const std::shared_ptr< dht::crypto::Certificate > &)>
 
using PeerCertificateCb = std::function< void(const std::shared_ptr< dht::crypto::Certificate > &crt, const dht::InfoHash &peer_account)>
 
using PrivateKey = std::shared_future< std::shared_ptr< dht::crypto::PrivateKey > >
 
using RegistrationCallback = NameDirectory::RegistrationCallback
 
using RevokeDeviceCallback = std::function< void(RevokeDeviceResult)>
 
enum class  RevokeDeviceResult { SUCCESS = 0 , ERROR_CREDENTIALS , ERROR_NETWORK }
 
using SearchCallback = NameDirectory::SearchCallback
 
using SearchResponse = NameDirectory::Response
 
using SearchResult = NameDirectory::SearchResult
 
using time_point = clock::time_point
 

Public Member Functions

bool acceptTrustRequest (const std::string &from, bool includeConversation=true)
 
 AccountManager (const std::string &accountId, const std::filesystem::path &path, const std::string &nameServer)
 
bool addContact (const dht::InfoHash &uri, bool confirmed=false, const std::string &conversationId="")
 Add contact to the account contact list.
 
virtual int32_t addDevice (const std::string &, std::string_view, AuthChannelHandler *)
 Initiates the process of adding a new device to the account.
 
CertRequest buildRequest (PrivateKey fDeviceKey)
 
virtual bool cancelAddDevice (uint32_t)
 
dhtnet::tls::CertificateStore & certStore () const
 
virtual bool changePassword (const std::string &password_old, const std::string &password_new)=0
 
virtual bool confirmAddDevice (uint32_t)
 
bool discardTrustRequest (const std::string &from)
 
virtual bool findCertificate (const dht::InfoHash &h, std::function< void(const std::shared_ptr< dht::crypto::Certificate > &)> &&cb={})
 
virtual bool findCertificate (const dht::PkId &h, std::function< void(const std::shared_ptr< dht::crypto::Certificate > &)> &&cb={})
 
void forEachDevice (const dht::InfoHash &to, std::function< void(const std::shared_ptr< dht::crypto::PublicKey > &)> &&op, std::function< void(bool)> &&end={})
 
bool foundAccountDevice (const std::shared_ptr< dht::crypto::Certificate > &crt, const std::string &name={}, const time_point &last_sync=time_point::min())
 
std::string getAccountDeviceName () const
 
std::vector< std::string > getCertificatesByStatus (dhtnet::tls::TrustStore::PermissionStatus status)
 
dhtnet::tls::TrustStore::PermissionStatus getCertificateStatus (const std::string &cert_id) const
 
std::map< std::string, std::string > getContactDetails (const std::string &uri) const
 Obtain details about one account contact in serializable form.
 
std::optional< ContactgetContactInfo (const std::string &uri) const
 
std::vector< std::map< std::string, std::string > > getContacts (bool includeRemoved=false) const
 
const AccountInfogetInfo () const
 
const std::map< dht::PkId, KnownDevice > & getKnownDevices () const
 
virtual std::vector< uint8_tgetPasswordKey (const std::string &)
 
std::vector< std::map< std::string, std::string > > getTrustRequests () const
 
virtual void initAuthentication (PrivateKey request, std::string deviceName, std::unique_ptr< AccountCredentials > credentials, AuthSuccessCallback onSuccess, AuthFailureCallback onFailure, const OnChangeCallback &onChange)=0
 
bool isAllowed (const crypto::Certificate &crt, bool allowPublic=false)
 
virtual bool isPasswordValid (const std::string &)
 
dht::crypto::Identity loadIdentity (const std::string &crt_path, const std::string &key_path, const std::string &key_pwd) const
 
virtual void lookupAddress (const std::string &address, LookupCallback cb)
 
virtual void lookupUri (const std::string &name, const std::string &defaultServer, LookupCallback cb)
 
bool onPeerCertificate (const std::shared_ptr< dht::crypto::Certificate > &crt, bool allowPublic, dht::InfoHash &account_id)
 
void onPeerMessage (const dht::crypto::PublicKey &peer_device, bool allowPublic, PeerCertificateCb &&cb)
 
virtual void onSyncData (DeviceSync &&device, bool checkDevice=true)
 
virtual void registerName (const std::string &name, std::string_view scheme, const std::string &password, RegistrationCallback cb)=0
 
void reloadContacts ()
 
void removeContact (const std::string &uri, bool banned=true)
 
void removeContactConversation (const std::string &uri)
 
virtual bool revokeDevice (const std::string &, std::string_view, const std::string &, RevokeDeviceCallback)
 
virtual bool searchUser (const std::string &, SearchCallback)
 
void sendTrustRequest (const std::string &to, const std::string &convId, const std::vector< uint8_t > &payload)
 
void sendTrustRequestConfirm (const dht::InfoHash &to, const std::string &conversationId)
 
void setAccountDeviceName (const std::string &name)
 
bool setCertificateStatus (const std::shared_ptr< crypto::Certificate > &cert, dhtnet::tls::TrustStore::PermissionStatus status, bool local=true)
 
bool setCertificateStatus (const std::string &cert_id, dhtnet::tls::TrustStore::PermissionStatus status)
 
void setDht (const std::shared_ptr< dht::DhtRunner > &dht)
 
virtual void startSync (const OnNewDeviceCb &cb, const OnDeviceAnnouncedCb &dcb, bool publishPresence=true)
 
virtual void syncDevices ()=0
 
void updateContactConversation (const std::string &uri, const std::string &convId)
 
const AccountInfouseIdentity (const dht::crypto::Identity &id, const std::string &receipt, const std::vector< uint8_t > &receiptSignature, const std::string &username, const OnChangeCallback &onChange)
 
virtual ~AccountManager ()
 

Static Public Member Functions

static bool foundPeerDevice (const std::string &accoundId, const std::shared_ptr< dht::crypto::Certificate > &crt, dht::InfoHash &account_id)
 Inform that a potential peer device have been found.
 
static std::shared_ptr< dht::Value > parseAnnounce (const std::string &announceBase64, const std::string &accountId, const std::string &deviceSha1, const std::string &deviceSha256)
 

Static Public Attributes

static constexpr const char *const DHT_TYPE_NS = "cx.ring"
 

Protected Attributes

const std::string accountId_
 
std::shared_ptr< dht::DhtRunner > dht_
 
std::unique_ptr< AccountInfoinfo_
 
std::reference_wrapper< NameDirectorynameDir_
 
OnChangeCallback onChange_
 
const std::filesystem::path path_
 

Detailed Description

Definition at line 73 of file account_manager.h.

Member Typedef Documentation

◆ AuthFailureCallback

using jami::AccountManager::AuthFailureCallback = std::function<void(AuthError error, const std::string& message)>

Definition at line 102 of file account_manager.h.

◆ AuthSuccessCallback

using jami::AccountManager::AuthSuccessCallback = std::function<void(const AccountInfo& info, const std::map<std::string, std::string>& config, std::string&& receipt, std::vector<uint8_t>&& receipt_signature)>

Definition at line 97 of file account_manager.h.

◆ CertRequest

using jami::AccountManager::CertRequest = std::future<std::unique_ptr<dht::crypto::CertificateRequest> >

Definition at line 104 of file account_manager.h.

◆ clock

using jami::AccountManager::clock = std::chrono::system_clock

Definition at line 77 of file account_manager.h.

◆ DeviceSyncCallback

◆ LookupCallback

◆ OnChangeCallback

◆ OnDeviceAnnouncedCb

Definition at line 80 of file account_manager.h.

◆ OnNewDeviceCb

using jami::AccountManager::OnNewDeviceCb = std::function<void(const std::shared_ptr<dht::crypto::Certificate>&)>

Definition at line 79 of file account_manager.h.

◆ PeerCertificateCb

using jami::AccountManager::PeerCertificateCb = std::function<void(const std::shared_ptr<dht::crypto::Certificate>& crt, const dht::InfoHash& peer_account)>

Definition at line 204 of file account_manager.h.

◆ PrivateKey

using jami::AccountManager::PrivateKey = std::shared_future<std::shared_ptr<dht::crypto::PrivateKey> >

Definition at line 105 of file account_manager.h.

◆ RegistrationCallback

◆ RevokeDeviceCallback

◆ SearchCallback

◆ SearchResponse

◆ SearchResult

◆ time_point

Definition at line 78 of file account_manager.h.

Member Enumeration Documentation

◆ AddDeviceError

Enumerator
INVALID_URI 
ALREADY_LINKING 
GENERIC 

Definition at line 156 of file account_manager.h.

◆ AuthError

Enumerator
UNKNOWN 
INVALID_ARGUMENTS 
SERVER_ERROR 
NETWORK 

Definition at line 95 of file account_manager.h.

◆ RevokeDeviceResult

Enumerator
SUCCESS 
ERROR_CREDENTIALS 
ERROR_NETWORK 

Definition at line 158 of file account_manager.h.

Constructor & Destructor Documentation

◆ AccountManager()

jami::AccountManager::AccountManager ( const std::string &  accountId,
const std::filesystem::path &  path,
const std::string &  nameServer 
)
inline

Definition at line 82 of file account_manager.h.

◆ ~AccountManager()

jami::AccountManager::~AccountManager ( )
virtual

Definition at line 53 of file account_manager.cpp.

References dht_.

Member Function Documentation

◆ acceptTrustRequest()

bool jami::AccountManager::acceptTrustRequest ( const std::string &  from,
bool  includeConversation = true 
)

◆ addContact()

bool jami::AccountManager::addContact ( const dht::InfoHash &  uri,
bool  confirmed = false,
const std::string &  conversationId = "" 
)

Add contact to the account contact list.

Set confirmed if we know the contact also added us.

Definition at line 487 of file account_manager.cpp.

References JAMI_ERROR, and JAMI_WARNING.

◆ addDevice()

virtual int32_t jami::AccountManager::addDevice ( const std::string &  ,
std::string_view  ,
AuthChannelHandler  
)
inlinevirtual

Initiates the process of adding a new device to the account.

Parameters
uriThe URI provided by the new device to be added
auth_schemeThe auth scheme (currently only "password" is expected)
chanel
Returns
A positive operation ID if successful, or a negative value indicating an AddDeviceError:
  • INVALID_URI (-1): The provided URI is invalid
  • ALREADY_LINKING (-2): A device linking operation is already in progress
  • GENERIC (-3): A generic error occurred during the process

Reimplemented in jami::ArchiveAccountManager.

Definition at line 176 of file account_manager.h.

◆ buildRequest()

AccountManager::CertRequest jami::AccountManager::buildRequest ( PrivateKey  fDeviceKey)

Definition at line 40 of file account_manager.cpp.

References jami::emitSignal().

Referenced by jami::ArchiveAccountManager::initAuthentication(), and jami::ServerAccountManager::initAuthentication().

Here is the call graph for this function:

◆ cancelAddDevice()

virtual bool jami::AccountManager::cancelAddDevice ( uint32_t  )
inlinevirtual

Reimplemented in jami::ArchiveAccountManager.

Definition at line 182 of file account_manager.h.

◆ certStore()

dhtnet::tls::CertificateStore & jami::AccountManager::certStore ( ) const

Definition at line 856 of file account_manager.cpp.

◆ changePassword()

virtual bool jami::AccountManager::changePassword ( const std::string &  password_old,
const std::string &  password_new 
)
pure virtual

◆ confirmAddDevice()

virtual bool jami::AccountManager::confirmAddDevice ( uint32_t  )
inlinevirtual

Reimplemented in jami::ArchiveAccountManager.

Definition at line 183 of file account_manager.h.

◆ discardTrustRequest()

bool jami::AccountManager::discardTrustRequest ( const std::string &  from)

Definition at line 711 of file account_manager.cpp.

◆ findCertificate() [1/2]

bool jami::AccountManager::findCertificate ( const dht::InfoHash &  h,
std::function< void(const std::shared_ptr< dht::crypto::Certificate > &)> &&  cb = {} 
)
virtual

Definition at line 610 of file account_manager.cpp.

Referenced by onSyncData().

◆ findCertificate() [2/2]

bool jami::AccountManager::findCertificate ( const dht::PkId &  h,
std::function< void(const std::shared_ptr< dht::crypto::Certificate > &)> &&  cb = {} 
)
virtual

Definition at line 632 of file account_manager.cpp.

◆ forEachDevice()

void jami::AccountManager::forEachDevice ( const dht::InfoHash &  to,
std::function< void(const std::shared_ptr< dht::crypto::PublicKey > &)> &&  op,
std::function< void(bool)> &&  end = {} 
)

Definition at line 771 of file account_manager.cpp.

References JAMI_ERROR, and JAMI_LOG.

◆ foundAccountDevice()

bool jami::AccountManager::foundAccountDevice ( const std::shared_ptr< dht::crypto::Certificate > &  crt,
const std::string &  name = {},
const time_point last_sync = time_point::min() 
)

Definition at line 379 of file account_manager.cpp.

◆ foundPeerDevice()

bool jami::AccountManager::foundPeerDevice ( const std::string &  accoundId,
const std::shared_ptr< dht::crypto::Certificate > &  crt,
dht::InfoHash &  account_id 
)
static

Inform that a potential peer device have been found.

Returns true only if the device certificate is a valid device certificate. In that case (true is returned) the account_id parameter is set to the peer account ID.

Definition at line 402 of file account_manager.cpp.

References JAMI_LOG, and JAMI_WARNING.

◆ getAccountDeviceName()

std::string jami::AccountManager::getAccountDeviceName ( ) const

Definition at line 394 of file account_manager.cpp.

◆ getCertificatesByStatus()

std::vector< std::string > jami::AccountManager::getCertificatesByStatus ( dhtnet::tls::TrustStore::PermissionStatus  status)

Definition at line 663 of file account_manager.cpp.

◆ getCertificateStatus()

dhtnet::tls::TrustStore::PermissionStatus jami::AccountManager::getCertificateStatus ( const std::string &  cert_id) const

Definition at line 669 of file account_manager.cpp.

◆ getContactDetails()

std::map< std::string, std::string > jami::AccountManager::getContactDetails ( const std::string &  uri) const

Obtain details about one account contact in serializable form.

Definition at line 580 of file account_manager.cpp.

References JAMI_ERROR.

◆ getContactInfo()

std::optional< Contact > jami::AccountManager::getContactInfo ( const std::string &  uri) const

Definition at line 595 of file account_manager.cpp.

References JAMI_ERROR.

◆ getContacts()

std::vector< std::map< std::string, std::string > > jami::AccountManager::getContacts ( bool  includeRemoved = false) const

Definition at line 556 of file account_manager.cpp.

References JAMI_ERROR.

◆ getInfo()

const AccountInfo * jami::AccountManager::getInfo ( ) const
inline

Definition at line 150 of file account_manager.h.

References info_.

◆ getKnownDevices()

const std::map< dht::PkId, KnownDevice > & jami::AccountManager::getKnownDevices ( ) const

Definition at line 373 of file account_manager.cpp.

◆ getPasswordKey()

virtual std::vector< uint8_t > jami::AccountManager::getPasswordKey ( const std::string &  )
inlinevirtual

Reimplemented in jami::ArchiveAccountManager.

Definition at line 132 of file account_manager.h.

◆ getTrustRequests()

std::vector< std::map< std::string, std::string > > jami::AccountManager::getTrustRequests ( ) const

Definition at line 682 of file account_manager.cpp.

References JAMI_ERROR.

◆ initAuthentication()

virtual void jami::AccountManager::initAuthentication ( PrivateKey  request,
std::string  deviceName,
std::unique_ptr< AccountCredentials credentials,
AuthSuccessCallback  onSuccess,
AuthFailureCallback  onFailure,
const OnChangeCallback onChange 
)
pure virtual

◆ isAllowed()

bool jami::AccountManager::isAllowed ( const crypto::Certificate &  crt,
bool  allowPublic = false 
)

Definition at line 676 of file account_manager.cpp.

◆ isPasswordValid()

virtual bool jami::AccountManager::isPasswordValid ( const std::string &  )
inlinevirtual

Reimplemented in jami::ArchiveAccountManager.

Definition at line 131 of file account_manager.h.

◆ loadIdentity()

dht::crypto::Identity jami::AccountManager::loadIdentity ( const std::string &  crt_path,
const std::string &  key_path,
const std::string &  key_pwd 
) const

Definition at line 113 of file account_manager.cpp.

References JAMI_DEBUG, and JAMI_ERROR.

◆ lookupAddress()

void jami::AccountManager::lookupAddress ( const std::string &  address,
LookupCallback  cb 
)
virtual

Definition at line 850 of file account_manager.cpp.

◆ lookupUri()

void jami::AccountManager::lookupUri ( const std::string &  name,
const std::string &  defaultServer,
LookupCallback  cb 
)
virtual

Definition at line 842 of file account_manager.cpp.

◆ onPeerCertificate()

bool jami::AccountManager::onPeerCertificate ( const std::shared_ptr< dht::crypto::Certificate > &  crt,
bool  allowPublic,
dht::InfoHash &  account_id 
)

Definition at line 466 of file account_manager.cpp.

References JAMI_WARNING.

◆ onPeerMessage()

void jami::AccountManager::onPeerMessage ( const dht::crypto::PublicKey &  peer_device,
bool  allowPublic,
PeerCertificateCb &&  cb 
)

Definition at line 443 of file account_manager.cpp.

References JAMI_WARNING.

◆ onSyncData()

void jami::AccountManager::onSyncData ( DeviceSync &&  device,
bool  checkDevice = true 
)
virtual

Definition at line 59 of file account_manager.cpp.

References accountId_, jami::emitSignal(), findCertificate(), info_, and JAMI_DEBUG.

Here is the call graph for this function:

◆ parseAnnounce()

std::shared_ptr< dht::Value > jami::AccountManager::parseAnnounce ( const std::string &  announceBase64,
const std::string &  accountId,
const std::string &  deviceSha1,
const std::string &  deviceSha256 
)
static

◆ registerName()

virtual void jami::AccountManager::registerName ( const std::string &  name,
std::string_view  scheme,
const std::string &  password,
RegistrationCallback  cb 
)
pure virtual

Implemented in jami::ServerAccountManager.

◆ reloadContacts()

void jami::AccountManager::reloadContacts ( )

Definition at line 269 of file account_manager.cpp.

◆ removeContact()

void jami::AccountManager::removeContact ( const std::string &  uri,
bool  banned = true 
)

Definition at line 502 of file account_manager.cpp.

References JAMI_ERROR.

◆ removeContactConversation()

void jami::AccountManager::removeContactConversation ( const std::string &  uri)

Definition at line 518 of file account_manager.cpp.

References JAMI_ERROR.

◆ revokeDevice()

virtual bool jami::AccountManager::revokeDevice ( const std::string &  ,
std::string_view  ,
const std::string &  ,
RevokeDeviceCallback   
)
inlinevirtual

Reimplemented in jami::ServerAccountManager, and jami::ArchiveAccountManager.

Definition at line 184 of file account_manager.h.

◆ searchUser()

virtual bool jami::AccountManager::searchUser ( const std::string &  ,
SearchCallback   
)
inlinevirtual

Reimplemented in jami::ServerAccountManager.

Definition at line 287 of file account_manager.h.

◆ sendTrustRequest()

void jami::AccountManager::sendTrustRequest ( const std::string &  to,
const std::string &  convId,
const std::vector< uint8_t > &  payload 
)

Definition at line 718 of file account_manager.cpp.

References JAMI_ERROR, and JAMI_WARNING.

◆ sendTrustRequestConfirm()

void jami::AccountManager::sendTrustRequestConfirm ( const dht::InfoHash &  to,
const std::string &  conversationId 
)

Definition at line 754 of file account_manager.cpp.

References JAMI_WARNING.

◆ setAccountDeviceName()

void jami::AccountManager::setAccountDeviceName ( const std::string &  name)

Definition at line 387 of file account_manager.cpp.

◆ setCertificateStatus() [1/2]

bool jami::AccountManager::setCertificateStatus ( const std::shared_ptr< crypto::Certificate > &  cert,
dhtnet::tls::TrustStore::PermissionStatus  status,
bool  local = true 
)

Definition at line 655 of file account_manager.cpp.

◆ setCertificateStatus() [2/2]

bool jami::AccountManager::setCertificateStatus ( const std::string &  cert_id,
dhtnet::tls::TrustStore::PermissionStatus  status 
)

Definition at line 648 of file account_manager.cpp.

◆ setDht()

void jami::AccountManager::setDht ( const std::shared_ptr< dht::DhtRunner > &  dht)
inline

Definition at line 144 of file account_manager.h.

References dht_.

◆ startSync()

void jami::AccountManager::startSync ( const OnNewDeviceCb cb,
const OnDeviceAnnouncedCb dcb,
bool  publishPresence = true 
)
virtual

Reimplemented in jami::ArchiveAccountManager.

Definition at line 277 of file account_manager.cpp.

References JAMI_DEBUG.

◆ syncDevices()

virtual void jami::AccountManager::syncDevices ( )
pure virtual

◆ updateContactConversation()

void jami::AccountManager::updateContactConversation ( const std::string &  uri,
const std::string &  convId 
)

◆ useIdentity()

const AccountInfo * jami::AccountManager::useIdentity ( const dht::crypto::Identity &  id,
const std::string &  receipt,
const std::vector< uint8_t > &  receiptSignature,
const std::string &  username,
const OnChangeCallback onChange 
)

Definition at line 185 of file account_manager.cpp.

References JAMI_ERROR, and JAMI_LOG.

Member Data Documentation

◆ accountId_

const std::string jami::AccountManager::accountId_
protected

◆ dht_

std::shared_ptr<dht::DhtRunner> jami::AccountManager::dht_
protected

Definition at line 301 of file account_manager.h.

Referenced by setDht(), and ~AccountManager().

◆ DHT_TYPE_NS

constexpr const char* const jami::AccountManager::DHT_TYPE_NS = "cx.ring"
staticconstexpr

Definition at line 91 of file account_manager.h.

◆ info_

std::unique_ptr<AccountInfo> jami::AccountManager::info_
protected

Definition at line 300 of file account_manager.h.

Referenced by getInfo(), and onSyncData().

◆ nameDir_

std::reference_wrapper<NameDirectory> jami::AccountManager::nameDir_
protected

Definition at line 302 of file account_manager.h.

◆ onChange_

OnChangeCallback jami::AccountManager::onChange_
protected

◆ path_

const std::filesystem::path jami::AccountManager::path_
protected

Definition at line 298 of file account_manager.h.


The documentation for this class was generated from the following files: