-
Notifications
You must be signed in to change notification settings - Fork 0
Core API
This section will cover all the API in detail.
This namespace groups the essentials of the API. It contains some utilities interfaces (such as the serialization center or the cryptography center) and all the models used to represent the user's data.
public interface ISerializationCenter;This interface only specifies how objects are serialized and deserialized, mainly for a storage purpose.
string Serialize<T>(T toSerialize) where T : notnull;This method serializes the given object to a string.
-
Tcan be any not null type. -
toSerializeis the object to serialize. - The method returns a string which is a serialized version of the given object.
T Deserialize<T>(string toDeserialize) where T : notnull;This method deserializes the given string to the given type object.
-
Tcan be any not null type. -
toDeserializeis the serialized version to deserialize. - The method returns the deserialized object.
Although the user can implement this interface according to his needs and preferences, this repository already has an implementation under the type Upsilon.Apps.PassKey.Core.Utils.JsonSerializationCenter According to its name, this implementation uses json serialization.
public interface ICryptographyCenter;This interface specifies all cryptographic methods such as the hashing algotithm, a symmetric encryption algotithm and an asymmetric encryption algotithm.
int HashLength { get; }This property indicate the constant length of the hashes provided by GetHash and GetSlowHash methods.
string GetHash(string source);This method returns a fast and length constant string hash of the given string.
-
sourceis the string to hash. - The method returns a string which is hash of the
sourceparameter.
string GetSlowHash(string source);This method returns a slow and length constant string hash of the given string.
-
sourceis the string to hash. - The method returns a string which is hash of the
sourceparameter.
void Sign(ref string source);This method signs a string.
-
sourceis the string to sign. The method will modify the string to add the signature.
bool CheckSign(ref string source);This method checks the signature of a given string.
-
sourceis the string to check. The method will modify the string to remove the signature. - The method returns
trueif the string is correctly signed,falseotherwise.
string EncryptSymmetrically(string source, string[] passwords);This method encrypts symmetrically a string with a set of passekeys in an onion structure.
-
sourceis the string to encrypt. -
passwordsis the set of passkeys used to encrypt the source. - The method returns the encrypted string.
string DecryptSymmetrically(string source, string[] passwords);This method decrypts symmetrically a string with a set of passekeys in an onion structure.
-
sourceis the string to decrypt. -
passwordsis the set of passkeys used to decrypt the source. - The method returns the decrypted string.
Note that the implementation of this method should be able to detect :
- A source corruption by throwing a
Upsilon.Apps.PassKey.Core.Utils.CorruptedSourceException - A wrong password at any level of the onion structure encryption by throwing a
Upsilon.Apps.PassKey.Core.Utils.WrongPasswordException
void GenerateRandomKeys(out string publicKey, out string privateKey);This method generates a random public key and private key pair for the asymmetric encryption algorithm.
-
publicKeyis the public key generated. -
privateKeyis the private key generated.
string EncryptAsymmetrically(string source, string key);This method encrypts asymmetrically a string with a public key.
-
sourceis the string to encrypt. -
keyis the public key used to encrypt the source. - The method returns the encrypted string.
string DecryptAsymmetrically(string source, string key);This method decrypts asymmetrically a string with a private key.
-
sourceis the string to decrypt. -
keyis the private key used to decrypt the source. - The method returns the decrypted string.
Note that the implementation of this method should be able to detect :
- A source corruption by throwing a
Upsilon.Apps.PassKey.Core.Utils.CorruptedSourceException - A wrong password by throwing a
Upsilon.Apps.PassKey.Core.Utils.WrongPasswordException
Although the user can implement this interface according to his needs and preferences, this repository already has an implementation under the type Upsilon.Apps.PassKey.Core.Utils.CryptographyCenter. This implementation uses a mix of MD5 and SHA1 for the hash, AES for the symmetric encryption and RSA for the asymmetric encryption.
public interface IPasswordFactory;This interface specifies how random passwords are generated and how to check if a password has been leaked.
string Alphabetic { get; }This property indicate the alphabetic characters used to generate a password.
string Numeric { get; }This property indicate the digit characters used to generate a password.
string SpecialChars { get; }This property indicate the special characters used to generate a password.
string GeneratePassword(int length,
bool includeUpperCaseAlphabeticChars = true,
bool includeLowerCaseAlphabeticChars = true,
bool includeNumericChars = true,
bool includeSpecialChars = true,
string excludedChars = "",
bool onlySafePasswords = true);This method generates a random password.
-
lengthis the length of the password to generate. -
includeUpperCaseAlphabeticCharstells if the upper alphabetic characters will used to build the password. -
includeLowerCaseAlphabeticCharstells if the lower alphabetic characters will used to build the password. -
includeNumericCharstells if the digit characters will used to build the password. -
includeSpecialCharstells if the special characters will used to build the password. -
excludedCharsis the set of characters to exclude when building the password. -
onlySafePasswordsensures that the generated password has not been already leaked. - The method returns a random password.
string GeneratePassword(int length,
string alphabet,
bool onlySafePasswords = true);This method generates a random password using the given alphabet.
-
lengthis the length of the password to generate. -
alphabetis the set of characters to exclude when building the password. -
onlySafePasswordsensures that the generated password has not been already leaked. - The method returns a random password.
bool PasswordLeaked(string password);This method checks if the password has been leaked.
-
passwordis the password to check. - The method returns
trueif the password has been leaked,falseotherwise.
Although the user can implement this interface according to his needs and preferences, this repository already has an implementation under the type Upsilon.Apps.PassKey.Core.Utils.PasswordFactory. This implementation uses ABCDEFGHIJKLMNOPQRSTUVWXYZ as alphabetic characters, 0123456789 as digit characters and ~!@#$%^&*()_-+={[}]\|'";:,<.>/? as special characters. It also uses the ';--have i been pwned? API to checks if a password leaked or not.
public interface IDatabase : IDisposable;This interface defines a database as the start point for all actions. It inherits from IDisposable.
string DatabaseFile { get; }This property indicate the path to the database file.
string AutoSaveFile { get; }This property indicate the path to the autosave file.
string LogFile { get; }This property indicate the path to the log file.
IUser? User { get; }This property refers the IUser representing the logged user. While no user is logged in, this will be null. Use the Login method to login.
ILog[]? Logs { get; }This property gives the list of logs for the logged user as a list of ILog. Like for the User property, while no user is logged in, this will be null.
IWarning[]? Warnings { get; }This property gives the list of all warnings detected for the logged user. Like for the User property, while no user is logged in, this will be null.
ISerializationCenter SerializationCenter { get; }This property refer to the ISerializationCenter used to serialize and deserialize data.
ICryptographyCenter CryptographyCenter { get; }This property refer to the ICryptographyCenter used to encrypt and decrypt data.
Upsilon.Apps.PassKey.Core.Interfaces.IPasswordFactory PasswordFactory { get; }This property refer to the IPasswordFactory implementation.
event EventHandler<WarningDetectedEventArgs>? WarningDetected;This event is raised when warnings are detected on successful login. The types of warnings detected here can be configured by the IUser.WarningsToNotify flag property. Note that if that user property is set to 0 (no warnings), this event will not be triggered even if warnings are effectively found. Though, the Warnings always gives all detected warnings and ignore the IUser.WarningsToNotify flag property.
-
Upsilon.Apps.PassKey.Core.Events.WarningDetectedEventArgsevent arg contains the detected warnings.
event EventHandler<AutoSaveDetectedEventArgs>? AutoSaveDetected;This event is raised when an autosave file is detected.
- The
Upsilon.Apps.PassKey.Core.Events.AutoSaveDetectedEventArgsevent arg contains aMergeBehaviorproperty of typeUpsilon.Apps.PassKey.Core.Enums.AutoSaveMergeBehaviorwhich allow the user to set how the autosave file will be handled. By default it isUpsilon.Apps.PassKey.Core.Enums.AutoSaveMergeBehavior.MergeThenRemoveAutoSaveFile.
event EventHandler? DatabaseSaved;This event is raised when the database is saved. This happen on a Save call, a Create call or a AutoSaveDetected event rize with a Upsilon.Apps.PassKey.Core.Events.AutoSaveDetectedEventArgs.MergeBehavior set to Upsilon.Apps.PassKey.Core.Enums.AutoSaveMergeBehavior.MergeThenRemoveAutoSaveFile.
event EventHandler<LogoutEventArgs>? DatabaseClosed;This event is raised when the database is closed. This happen on a IDatabase.Close call or when the IUser.LogoutTimeout is reached.
- The
Upsilon.Apps.PassKey.Core.Events.LogoutEventArgsevent arg contains a boolean property calledLoginTimeoutReachedto tell if the login timeout was reached or not.
IUser? Login(string passkey);This method tries to log into a database using the given passkey. In practice, the user calls several times this method by giving it every password of its set of master password. On the last call, this method updates the User property by loading the decripted content.
-
passkeyis the n-th passkey of the set of master password. - The method returns
nullif the set of previously given passwords don't match to the real master password set.
void Save();This method saves the current user to database file and triger the DatabaseSaved event.
The User must be loaded, else it will throw a NullReferenceException.
void Delete();This method deletes the current user with all its files.
The User must be loaded, else it will throw a NullReferenceException.
static IDatabase Create(ICryptographyCenter cryptographicCenter,
ISerializationCenter serializationCenter,
IPasswordFactory passwordFactory,
string databaseFile,
string autoSaveFile,
string logFile,
string username,
string[] passkeys);This static method creates a new user database and returns it.
After creating, the User should be loaded with the Login method.
-
cryptographicCenteris an implementation ofICryptographyCenter. -
serializationCenteris an implementation ofISerializationCenter. -
passwordFactoryis an implementation ofIPasswordFactory. -
databaseFileis the path to the database file. -
autoSaveFileis the path to the autosave file. -
logFileis the path to the log file. -
usernameis the username. -
passkeysis the set of master password of the user. - The method returns the
IDatabasecorresponding to the user database created.
static IDatabase Open(ICryptographyCenter cryptographicCenter,
ISerializationCenter serializationCenter,
IPasswordFactory passwordFactory,
string databaseFile,
string autoSaveFile,
string logFile,
string username);This static method opens an user database and returns it.
After opening, the User should be loaded with the Login method.
-
cryptographicCenteris an implementation ofICryptographyCenter. -
serializationCenteris an implementation ofISerializationCenter. -
passwordFactoryis an implementation ofIPasswordFactory. -
databaseFileis the path to the database file. -
autoSaveFileis the path to the autosave file. -
logFileis the path to the log file. -
usernameis the username. - The method returns the
IDatabasecorresponding to the user database opened.
There is no public implementation for this interface since the intern logic and behavious should be closed to the API user. To effectively get an implemented instance, use IDatabase.Create and IDatabase.Open static methods.