using Bit.Core.Auth.Models.Api.Request.Opaque; using Bit.Core.Auth.Models.Api.Response.Opaque; using Bit.Core.Entities; namespace Bit.Core.Auth.Services; /// /// Service that exposes methods enabling the use of the Opaque Key Exchange extension. /// public interface IOpaqueKeyExchangeService { /// /// Begin registering a user's Opaque Key Exchange Credential. We write to the distributed cache so since there is some back and forth between the client and server. /// /// unsure what this byte array is for. /// user being acted on /// configuration shared between the client and server to ensure the proper crypto-algorithms are being utilized. /// void public Task StartRegistration(byte[] request, User user, OpaqueKeyExchangeCipherConfiguration cipherConfiguration); /// /// This updates the cache with the server setup and cipher configuration so that WriteCacheCredentialToDatabase method can finish registration /// by writing the credential to the database. /// /// Cache Id /// Byte Array for Rust Magic /// User being acted on /// Key Pair that can be used for vault decryption /// void public Task FinishRegistration(Guid sessionId, byte[] registrationUpload, User user, RotateableOpaqueKeyset keyset); /// /// Returns server crypto material for the client to consume and reply with a login request to the identity/token endpoint. /// To protect against account enumeration we will always return a deterministic response based on the user's email. /// /// client crypto material /// user email trying to login /// tuple(login SessionId for cache lookup, Server crypto material) public Task<(Guid, byte[])> StartLogin(byte[] request, string email); /// /// Accepts the client's login request and validates it against the server's crypto material. If successful then the session is marked as authenticated. /// If using a fake account we will return a standard failed login. If the account does have a legitimate credential but is still invalid /// the session is not marked as authenticated. /// /// /// /// public Task FinishLogin(Guid sessionId, byte[] finishCredential); /// /// Returns the user for the authentication session, or null if the session is invalid or has not yet finished authentication. /// /// /// public Task GetUserForAuthenticatedSession(Guid sessionId); /// /// Clears the authentication session from the cache. /// /// session being acted on. /// void public Task ClearAuthenticationSession(Guid sessionId); /// /// This method writes the Credential to the database. If a credential already exists then it will be removed before the new one is added. /// A user can only have one credential. /// /// cache value /// user being acted on /// bool based on action result public Task WriteCacheCredentialToDatabase(Guid sessionId, User user); /// /// Removes the credential for the user. If the user does not exist then this does nothing. /// /// User being acted on. /// void public Task RemoveUserOpaqueKeyExchangeCredential(User user); }