Skip to content

Commit 0da3d67

Browse files
authored
Merge pull request #14 from YassinLokhat/8-adding-readme
8 adding readme
2 parents e29a128 + 03a3f90 commit 0da3d67

5 files changed

Lines changed: 165 additions & 45 deletions

File tree

Core/Internal/Models/Account.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ internal sealed class Account : IAccount
99
{
1010
#region IAccount interface explicit Internal
1111

12-
string IItem.ItemId => ItemId;
13-
IService IAccount.Service => Service;
12+
string IItem.ItemId => Database.Get(ItemId);
13+
IService IAccount.Service => Database.Get(Service);
1414

1515
string IAccount.Label
1616
{
17-
get => Label;
17+
get => Database.Get(Label);
1818
set => Label = Database.AutoSave.UpdateValue(ItemId,
1919
itemName: ToString(),
2020
fieldName: nameof(Label),
@@ -25,7 +25,7 @@ string IAccount.Label
2525

2626
string[] IAccount.Identifiants
2727
{
28-
get => Identifiants;
28+
get => Database.Get(Identifiants);
2929
set => Identifiants = Database.AutoSave.UpdateValue(ItemId,
3030
itemName: ToString(),
3131
fieldName: nameof(Identifiants),
@@ -36,7 +36,7 @@ string[] IAccount.Identifiants
3636

3737
string IAccount.Password
3838
{
39-
get => Password;
39+
get => Database.Get(Password);
4040
set
4141
{
4242
if (!string.IsNullOrEmpty(value))
@@ -60,7 +60,7 @@ string IAccount.Password
6060

6161
string IAccount.Notes
6262
{
63-
get => Notes;
63+
get => Database.Get(Notes);
6464
set => Notes = Database.AutoSave.UpdateValue(ItemId,
6565
itemName: ToString(),
6666
fieldName: nameof(Notes),
@@ -71,7 +71,7 @@ string IAccount.Notes
7171

7272
int IAccount.PasswordUpdateReminderDelay
7373
{
74-
get => PasswordUpdateReminderDelay;
74+
get => Database.Get(PasswordUpdateReminderDelay);
7575
set => PasswordUpdateReminderDelay = Database.AutoSave.UpdateValue(ItemId,
7676
itemName: ToString(),
7777
fieldName: nameof(PasswordUpdateReminderDelay),
@@ -82,7 +82,7 @@ int IAccount.PasswordUpdateReminderDelay
8282

8383
AccountOption IAccount.Options
8484
{
85-
get => Options;
85+
get => Database.Get(Options);
8686
set => Options = Database.AutoSave.UpdateValue(ItemId,
8787
itemName: ToString(),
8888
fieldName: nameof(Options),

Core/Internal/Models/Database.cs

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,11 @@ internal sealed class Database : IDatabase
1414
public string AutoSaveFile { get; set; }
1515
public string LogFile { get; set; }
1616

17-
IUser? IDatabase.User
18-
{
19-
get
20-
{
21-
_lastActionTime = DateTime.Now;
22-
return User;
23-
}
24-
}
17+
IUser? IDatabase.User => Get(User);
2518

26-
ILog[]? IDatabase.Logs
27-
{
28-
get
29-
{
30-
_lastActionTime = DateTime.Now;
31-
return Logs.Logs;
32-
}
33-
}
19+
ILog[]? IDatabase.Logs => Get(Logs.Logs);
3420

35-
IWarning[]? IDatabase.Warnings
36-
{
37-
get
38-
{
39-
_lastActionTime = DateTime.Now;
40-
return User != null ? Warnings : null;
41-
}
42-
}
21+
IWarning[]? IDatabase.Warnings => Get(User != null ? Warnings : null);
4322

4423
public ICryptographyCenter CryptographyCenter { get; private set; }
4524
public ISerializationCenter SerializationCenter { get; private set; }
@@ -276,6 +255,13 @@ internal static IDatabase Open(ICryptographyCenter cryptographicCenter,
276255
return database;
277256
}
278257

258+
internal T Get<T>(T value)
259+
{
260+
_lastActionTime = DateTime.Now;
261+
262+
return value;
263+
}
264+
279265
private void _timer_Elapsed(object? sender, System.Timers.ElapsedEventArgs e)
280266
{
281267
if (User == null) throw new NullReferenceException(nameof(User));

Core/Internal/Models/Service.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ internal sealed class Service : IService
77
{
88
#region IService interface explicit Internal
99

10-
string IItem.ItemId => ItemId;
11-
IUser IService.User => User;
12-
IAccount[] IService.Accounts => [.. Accounts];
10+
string IItem.ItemId => Database.Get(ItemId);
11+
IUser IService.User => Database.Get(User);
12+
IAccount[] IService.Accounts => [.. Database.Get(Accounts)];
1313

1414
string IService.ServiceName
1515
{
16-
get => ServiceName;
16+
get => Database.Get(ServiceName);
1717
set => ServiceName = Database.AutoSave.UpdateValue(ItemId,
1818
itemName: ToString(),
1919
fieldName: nameof(ServiceName),
@@ -24,7 +24,7 @@ string IService.ServiceName
2424

2525
string IService.Url
2626
{
27-
get => Url;
27+
get => Database.Get(Url);
2828
set => Url = Database.AutoSave.UpdateValue(ItemId,
2929
itemName: ToString(),
3030
fieldName: nameof(Url),
@@ -35,7 +35,7 @@ string IService.Url
3535

3636
string IService.Notes
3737
{
38-
get => Notes;
38+
get => Database.Get(Notes);
3939
set => Notes = Database.AutoSave.UpdateValue(ItemId,
4040
itemName: ToString(),
4141
fieldName: nameof(Notes),

Core/Internal/Models/User.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ internal sealed class User : IUser
88
{
99
#region IUser interface explicit Internal
1010

11-
string IItem.ItemId => ItemId;
12-
IService[] IUser.Services => [.. Services];
11+
string IItem.ItemId => Database.Get(ItemId);
12+
IService[] IUser.Services => [.. Database.Get(Services)];
1313

1414
string IUser.Username
1515
{
16-
get => Username;
16+
get => Database.Get(Username);
1717
set => Username = Database.AutoSave.UpdateValue(ItemId,
1818
itemName: ToString(),
1919
fieldName: nameof(Username),
@@ -24,7 +24,7 @@ string IUser.Username
2424

2525
string[] IUser.Passkeys
2626
{
27-
get => Passkeys;
27+
get => Database.Get(Passkeys);
2828
set => Passkeys = Database.AutoSave.UpdateValue(ItemId,
2929
itemName: ToString(),
3030
fieldName: nameof(Passkeys),
@@ -35,7 +35,7 @@ string[] IUser.Passkeys
3535

3636
int IUser.LogoutTimeout
3737
{
38-
get => LogoutTimeout;
38+
get => Database.Get(LogoutTimeout);
3939
set => LogoutTimeout = Database.AutoSave.UpdateValue(ItemId,
4040
itemName: ToString(),
4141
fieldName: nameof(LogoutTimeout),
@@ -46,7 +46,7 @@ int IUser.LogoutTimeout
4646

4747
int IUser.CleaningClipboardTimeout
4848
{
49-
get => CleaningClipboardTimeout;
49+
get => Database.Get(CleaningClipboardTimeout);
5050
set => CleaningClipboardTimeout = Database.AutoSave.UpdateValue(ItemId,
5151
itemName: ToString(),
5252
fieldName: nameof(CleaningClipboardTimeout),
@@ -57,7 +57,7 @@ int IUser.CleaningClipboardTimeout
5757

5858
WarningType IUser.WarningsToNotify
5959
{
60-
get => WarningsToNotify;
60+
get => Database.Get(WarningsToNotify);
6161
set => WarningsToNotify = Database.AutoSave.UpdateValue(ItemId,
6262
itemName: ToString(),
6363
fieldName: nameof(WarningsToNotify),

README.md

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
2+
3+
**Upsilon.Apps.Passkey.Core**
4+
=============================================
5+
6+
**Overview**
7+
------------
8+
9+
This is a C# implementation of a local stored password manager core API. The API provides a secure way to store and manage passwords locally on a user's device.
10+
11+
**Features**
12+
------------
13+
14+
* **Password Storage**: Store accounts and services passwords securely
15+
* **History log**: Log every events
16+
* **Trigger warnings**: Trigger warnings when detected
17+
* **Autosave**: Autosave updates
18+
* **Password Generation**: Generate strong, unique passwords
19+
20+
**Security**
21+
------------
22+
23+
* **Encryption**: All passwords are encrypted using AES with a set of keys and RSA with a 1024-bit key
24+
* **Access Control**: Access to the password store is restricted to authorized users only
25+
26+
**Models**
27+
28+
----------
29+
30+
### Class diagram
31+
![Interfaces](https://github.com/user-attachments/assets/a4ad591c-1334-426f-86de-b7d264ea904b)
32+
33+
**Example Use Cases**
34+
35+
--------------------
36+
37+
### Create a new database
38+
39+
To create a new database, use the `IDatabase.Create` static method.
40+
41+
This method needs an `ICryptographyCenter` implementation, an `ISerializationCenter` implementation and an `IPasswordFactory` implementation.
42+
The namespace `Upsilon.Apps.PassKey.Core.Public.Utils` already contains implementations for all of these intefaces.
43+
44+
The next parameters are a set of files : the database file itself, the autosave file and the log file.
45+
These files will be created during the process.
46+
47+
Finally, the method take the username and the passkeys.
48+
Note that the passkeys are used as master passwords to encrypt the database (and the other files).
49+
50+
```csharp
51+
IDatabase database = IDatabase.Create(new Upsilon.Apps.PassKey.Core.Public.Utils.CryptographyCenter(),
52+
new Upsilon.Apps.PassKey.Core.Public.Utils.JsonSerializationCenter(),
53+
new Upsilon.Apps.PassKey.Core.Public.Utils.PasswordFactory(),
54+
"./database.pku",
55+
"./autosave.pks",
56+
"./log.pkl",
57+
"username",
58+
new string[] { "master_password_1", "master_password_2", "master_password_3" });
59+
```
60+
61+
After creation, the method will directly open the database but it will not login directly to the current user.
62+
So to login, check the **Login to an user** use case.
63+
64+
### Open an existing database
65+
66+
To open an existing database, use the `IDatabase.Open` static method.
67+
68+
This method needs the same `ICryptographyCenter` implementation, `ISerializationCenter` implementation and `IPasswordFactory` implementation as in the creation step.
69+
70+
The next parameters are a set of files : the database file itself, the autosave file and the log file.
71+
The database file must, obviously, exist, the autosave file and log files are optional but must be the same as provided during the creating process.
72+
73+
Finally, the method take the username.
74+
75+
```csharp
76+
IDatabase database = IDatabase.Open(new Upsilon.Apps.PassKey.Core.Public.Utils.CryptographyCenter(),
77+
new Upsilon.Apps.PassKey.Core.Public.Utils.JsonSerializationCenter(),
78+
new Upsilon.Apps.PassKey.Core.Public.Utils.PasswordFactory(),
79+
"./database.pku",
80+
"./autosave.pks",
81+
"./log.pkl",
82+
"username");
83+
```
84+
85+
### Login to an user
86+
87+
After opening (or creating) a database, use the `IDatabase.Login` method to login the user.
88+
To do that, call the login method with every passkeys used during the database creation process.
89+
Only the last call of that method, with every correct and ordered passkeys, will return the `IUser` representing the current user successfuly loged in.
90+
Else that method will return `null`.
91+
92+
```csharp
93+
IUser? user = database.Login("master_password_1"); // Will return null
94+
user = database.Login("master_password_2"); // Will also return null
95+
user = database.Login("master_password_3"); // Will return a IUser this time
96+
```
97+
98+
Once the IUser retrieved, it allow a full access to all services and accounts, all log history and all user parameters.
99+
100+
### Saving the changes
101+
102+
Use the `IDatabase.Save` method to save the user's updates.
103+
Note that any update on the user, its services and/or accounts which is not saved will be keeped in the autosave file.
104+
105+
```csharp
106+
user.LogoutTimeout = 5; // Setting the logout timeout to 5 min will create an autosave file
107+
database.Save(); // Will save the new logout timeout in the database file and removed the autosave file
108+
```
109+
110+
### Logout/Close a database
111+
112+
To logout and close the database, use the `IDatabase.Close` method.
113+
All unsaved updates are stored inside the autosave file.
114+
115+
```csharp
116+
database.Close();
117+
```
118+
119+
**Getting Started**
120+
-------------------
121+
122+
1. Clone the repository: `git clone https://github.com/YassinLokhat/Upsilon.Apps.Passkey.Core.git`
123+
2. Build the solution: `dotnet build`
124+
3. Run the API: `dotnet run`
125+
126+
**Contributing**
127+
------------
128+
129+
Contributions are welcome! Please submit a pull request with your changes.
130+
131+
**License**
132+
-------
133+
134+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

0 commit comments

Comments
 (0)