public static void AesHandshake(string packet, AuthClient authClient) { try { var args = new List <object>(); var deserializedPacket = JObject.Parse(packet); args.AddRange(JArray.Parse(deserializedPacket["args"].ToString())); if (authClient != null) { var authKey = authClient.Client.GetHashCode().ToString(); var privateKey = authClient.PrivateKey; var encryptedKey = args[0].ToString(); var encryptedIv = args[1].ToString(); authClient.AesKey = Rsa.Decryption(privateKey, encryptedKey); authClient.AesIv = Rsa.Decryption(privateKey, encryptedIv); authClient.AesShook = true; ConnectionHandler.Clients[authKey] = authClient; var handshake = new { message = "Handshake Accepted", shook = true }; MessageHandler.SendMessage("aeshandshake", handshake, authClient); } } catch (Exception e) { if (authClient != null) { var handshake = new { message = "Handshake Failed", reason = e.Message, shook = false }; MessageHandler.SendMessage("aeshandshake", handshake, authClient); } } }
public void AesHandshake() { try { var connectionId = CookieManager.GetConnectionId(_client); AuthClient authClient; UlteriusApiServer.AllClients.TryGetValue(connectionId, out authClient); if (authClient != null) { var privateKey = authClient.PrivateKey; var encryptedKey = _packet.Args[0].ToString(); var encryptedIv = _packet.Args[1].ToString(); authClient.AesKey = Rsa.Decryption(privateKey, encryptedKey); authClient.AesIv = Rsa.Decryption(privateKey, encryptedIv); authClient.AesShook = true; //update the auth client UlteriusApiServer.AllClients[connectionId] = authClient; var endData = new { shook = true }; _builder.WriteMessage(endData); } else { throw new Exception("AuthWindows client is null"); } } catch (Exception e) { var endData = new { shook = false, message = e.Message }; _builder.WriteMessage(endData); } }
public void AesHandshake() { try { var authKey = _client.GetHashCode().ToString(); AuthClient authClient; TaskManagerServer.AllClients.TryGetValue(authKey, out authClient); if (authClient != null) { var privateKey = authClient.PrivateKey; var encryptedKey = _packet.Args[0].ToString(); var encryptedIv = _packet.Args[1].ToString(); authClient.AesKey = Rsa.Decryption(privateKey, encryptedKey); authClient.AesIv = Rsa.Decryption(privateKey, encryptedIv); authClient.AesShook = true; //update the auth client TaskManagerServer.AllClients[authKey] = authClient; var endData = new { shook = true }; _serializator.Serialize(_client, _packet.Endpoint, _packet.SyncKey, endData); } else { throw new Exception("Auth client is null"); } } catch (Exception e) { var endData = new { shook = false, message = e.Message }; _serializator.Serialize(_client, _packet.Endpoint, _packet.SyncKey, endData); } }
private IConnectionRequest Build(string typeName, JObject json, out Type type, UserConnection user = null) { switch (typeName) { case "CreateTerminalRequest": type = typeof(CreateTerminalRequest); return(new CreateTerminalRequest { TerminalType = json.Property("terminalType").Value.ToString(), CorrelationId = (int)json.Property("correlationId") }); case "AesHandShakeRequest": type = typeof(AesHandshakeRequest); if (user != null) { if (user.AesShook) { return(new AesHandshakeRequest { AesShook = user.AesShook }); } try { var encryptedKey = json.Property("encryptedKey").Value.ToString(); var encryptedIv = json.Property("encryptedIv").Value.ToString(); var privateKey = user.PrivateKey; user.AesKey = Rsa.Decryption(privateKey, encryptedKey); user.AesIv = Rsa.Decryption(privateKey, encryptedIv); user.AesShook = true; return(new AesHandshakeRequest { AesShook = user.AesShook }); } catch (Exception) { return(new AesHandshakeRequest { AesShook = false }); } } return(new AesHandshakeRequest { AesShook = false }); case "TerminalInputRequest": type = typeof(TerminalInputRequest); return(new TerminalInputRequest { TerminalId = Guid.Parse(json.Property("terminalId").Value.ToString()), Input = json.Property("input").Value.ToString(), CorrelationId = (int)json.Property("correlationId") }); case "CloseTerminalRequest": type = typeof(CloseTerminalRequest); return(new CloseTerminalRequest { TerminalId = Guid.Parse(json.Property("terminalId").Value.ToString()) }); } type = null; return(null); }