public async Task <ActionResult <MainResponse> > TestWord(UserSecretKeyRequest secretKeyRequest) { User user = HttpContext.GetUser(); if (user == null) { return(Unauthorized()); } KeySession keySession = await _context.KeySessions.FirstOrDefaultAsync(p => p.VerificationData == secretKeyRequest.IdentificationWord); if (keySession != null) { user.KeySession = keySession; user.UserState = Enums.UserStates.Online; _context.Update(user); await _context.SaveChangesAsync(); } UserSecretKeyResponse secretKeyResponse = new UserSecretKeyResponse() { UnknownKey = keySession == null }; if (keySession != null) { secretKeyResponse.PublicKey = keySession.RSAKeyPair.PublicKey; secretKeyResponse.EncryptedPrivateKey = keySession.RSAKeyPair.EncryptedPrivateKey; secretKeyResponse.KeyId = keySession.RSAKeyPair.Id; } return(MainResponse.GetSuccess(secretKeyResponse)); }
public async Task <ActionResult <MainResponse> > CreateTestWord(CreateNewSessionRequest request) { User user = HttpContext.GetUser(); if (user == null) { return(StatusCode(401)); } KeySession keySession = _context.KeySessions.FirstOrDefault(p => p.VerificationData == request.IdentificationWord); if (keySession == null) { RSAKeyPair keyPair = new RSAKeyPair() { EncryptedPrivateKey = request.EncryptedPrivateKey, LastKeyPair = null, LastPublicKeySign = null, PublicKey = request.PublicKey }; _context.RSAKeyPairs.Add(keyPair); keySession = new KeySession() { CreationDate = DateTime.Now, VerificationData = request.IdentificationWord, RSAKeyPair = keyPair }; user.KeySession = keySession; user.UserState = Enums.UserStates.Online; user.AvailableKeys--; _context.Users.Update(user); await _context.KeySessions.AddAsync(keySession); await _context.SaveChangesAsync(); } UserSecretKeyResponse secretKeyResponse = new UserSecretKeyResponse() { UnknownKey = false }; return(MainResponse.GetSuccess(secretKeyResponse)); }