manage-accounts.md (5340B)
1 # Managing Accounts 2 In this part, we will learn how to manage a Ring account. This means, how to create a Ring account, modify the basic settings and delete the account. This part will *NOT* explain what all the settings mean or how we can use the account to do any action like adding a contact. 3 4 ## Create a new account 5 6 ### Client side 7 8 #### Gnome 9 10 The code related to this feature is located in `src/accountcreationwizard.*` 11 12 #### LRC 13 14 The account creation is mainly managed by the *NewAccountModel* in `src/api/newaccountmodel.h` and `src/newaccountmodel.cpp` 15 16 ### Daemon side 17 18 #### API 19 20 In cx.ring.Ring.ConfigurationManager: 21 22 ```xml 23 <method name="addAccount" tp:name-for-bindings="addAccount"> 24 <tp:docstring> 25 Add a new account. When created, the signal <tp:member-ref>accountsChanged</tp:member-ref> is emitted. The clients must then call <tp:member-ref>getAccountList</tp:member-ref> to update their internal data structure. 26 <tp:rationale>If no details are specified, the default parameters are used.</tp:rationale> 27 <tp:rationale>The core tries to register the account as soon it is created.</tp:rationale> 28 </tp:docstring> 29 <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="MapStringString"/> 30 <arg type="a{ss}" name="details" direction="in" tp:type="String_String_Map"> 31 <tp:docstring> 32 The new account settings 33 </tp:docstring> 34 </arg> 35 <arg type="s" name="createdAccountId" direction="out"> 36 <tp:docstring> 37 A new account ID 38 </tp:docstring> 39 </arg> 40 </method> 41 ``` 42 43 The details can be retrieven from the method `getAccountTemplate(type)` with `type=RING` or `type=SIP`. For example, this is the following code used in LRC. 44 45 ```cpp 46 std::string 47 NewAccountModel::createNewAccount(profile::Type type, 48 const std::string& displayName, 49 const std::string& archivePath, 50 const std::string& password, 51 const std::string& pin) 52 { 53 54 MapStringString details = type == profile::Type::SIP? 55 ConfigurationManager::instance().getAccountTemplate("SIP") : 56 ConfigurationManager::instance().getAccountTemplate("RING"); 57 using namespace DRing::Account; 58 details[ConfProperties::TYPE] = type == profile::Type::SIP? "SIP" : "RING"; 59 details[ConfProperties::DISPLAYNAME] = displayName.c_str(); 60 details[ConfProperties::ALIAS] = displayName.c_str(); 61 details[ConfProperties::UPNP_ENABLED] = "true"; 62 details[ConfProperties::ARCHIVE_PASSWORD] = password.c_str(); 63 details[ConfProperties::ARCHIVE_PIN] = pin.c_str(); 64 details[ConfProperties::ARCHIVE_PATH] = archivePath.c_str(); 65 QString accountId = ConfigurationManager::instance().addAccount(details); 66 return accountId.toStdString(); 67 } 68 ``` 69 70 When a new account is added, the signal `accountsChanged` will be emitted. The client should update its internal structure after this signal with other methods in ConfigurationManager. 71 72 #### Core 73 74 The main logic to create a new account is located in `src/ringdht/ringaccount.cpp`, in `RingAccount::createAccount` 75 76 ### How it works, from scratch 77 78 A Ring account is in fact represented by some files stored in a gzip archive. If a password is provided during the account creation, the archive will be encrypted as following: `dht::crypto::aesEncrypt(archive, password)` (`dht::crypto::aesEncrypt` is defined in OpenDHT and use `nettle/{aes,gcm}`). This is what the archive will contain a big JSON file with: 79 80 1. The private key `ringAccountKey` and certificate chain `ringAccountCert` (base64 encoded) 81 2. Generated CA key (for self-signed certificates) `ringCAKey` 82 3. Revocated devices `ringAccountCRL` 83 4. The ethereum private key `ethKey` for the device. It's only used when you register your name on `ns.ring.cx`. Not mandatory. 84 5. The contacts 85 6. The account settings 86 87 So let's generate it! 88 89 **TODO** 90 91 92 93 ## Delete the account 94 95 Deleting a Ring account is pretty simple. Because the keys are only on the device, if the keys are deleted... the account is deleted! The only thing outside the device is the username, on the nameserver. To remove this info, it depends how the nameserver work. For example, it's not possible with https://ns.ring.cx 96 97 ### Client side 98 99 #### Gnome 100 101 The code related to this feature is located in `newaccountsettingsview.cpp` 102 103 #### LRC 104 105 The account deletion is in the *NewAccountModel* in `src/api/newaccountmodel.h` and `src/newaccountmodel.cpp` (`removeAccount`) 106 107 ### Daemon side 108 109 #### API 110 111 In cx.ring.Ring.ConfigurationManager: 112 113 ```xml 114 <method name="removeAccount" tp:name-for-bindings="removeAccount"> 115 <tp:docstring> 116 Remove an existing account. When removed, the signal <tp:member-ref>accountsChanged</tp:member-ref> is emitted. The clients must then call <tp:member-ref>getAccountList</tp:member-ref> to update their internal data structure. 117 </tp:docstring> 118 <arg type="s" name="accoundID" direction="in"> 119 <tp:docstring> 120 The account to remove, identified by its ID 121 </tp:docstring> 122 </arg> 123 </method> 124 ``` 125 126 When the account is deleted, the signal `accountsChanged` will be emitted. The client should update its internal structure after this signal with other methods in ConfigurationManager. 127 128 #### Core 129 130 The main logic to create a new account is located in `src/manager.cpp`, in `Manager::removeAccount`. It removes the accounts files and update the config (`dring.yml`). 131 132 ## Update the settings 133 134 **TODO** 135 136 ## Add and revoke devices 137 138 **TODO**