Skip to content
This repository was archived by the owner on Jun 11, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
42566e6
Implement bank channel
Apr 4, 2018
df3b440
Update .gitignore
Apr 6, 2018
0428208
Add login with token on bank channel
Apr 25, 2018
ca8f334
Fix account channel join topic
Apr 25, 2018
51dcc2b
Implement bank public
Apr 25, 2018
c975278
Improve test helpers
Apr 25, 2018
db904f2
Add support for getting src and tgt bank information
Apr 25, 2018
29d03fb
Implement bank transfer
Apr 25, 2018
0516695
Implement BankAccount bootstrap
Apr 25, 2018
c9b4eed
Implement BankAccount password change
Apr 25, 2018
43069fa
Implement BankAccount close request
Apr 25, 2018
46fb8fa
Implement BankAccount password reveal
Apr 25, 2018
f31acdc
Implement bank logout request
Apr 25, 2018
22b18a4
Implement bank account create request
Apr 25, 2018
63ef969
Implement login with token
May 31, 2018
af7464b
Update bank internal
May 31, 2018
ab683b8
Improve testing tooling
May 31, 2018
ece497e
Improve Bank Public
May 31, 2018
cad510d
Improve bank internal testing
May 31, 2018
466445a
Improve bank events
May 31, 2018
ced9075
Improve bank action
May 31, 2018
1a43058
Improve bank bootstrap request
May 31, 2018
2a78472
Improve bank change password request
May 31, 2018
54f73c2
Improve bank create password request
May 31, 2018
cce6431
Improve logout request
May 31, 2018
d72dd05
Improved bank transfer process
May 31, 2018
30b3890
Improve bank transfer request
May 31, 2018
f0cf006
Move bank tests to proper directory
May 31, 2018
1a6bd56
Add information on whom_to_notify
May 31, 2018
b70c5a1
Add AccountCreate process
Jun 7, 2018
1a2e58e
Add AccountClose process
Jun 7, 2018
e6d301d
update BankAccount open and close tests
Jun 11, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ erl_crash.dump
xref_graph.dot
/graphs

# Visual Code
.elixir_ls/

# Elixir
.iex.exs

**GPATH
**GRTAGS
**GTAGS
22 changes: 21 additions & 1 deletion lib/account/websocket/channel/account.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ channel Helix.Account.Websocket.Channel.Account do
alias Helix.Network.Websocket.Requests.Bounce.Remove, as: BounceRemoveRequest
alias Helix.Software.Websocket.Requests.Virus.Collect, as: VirusCollectRequest
alias Helix.Story.Websocket.Requests.Email.Reply, as: EmailReplyRequest
alias Helix.Universe.Bank.Websocket.Requests.CreateAccount,
as: BankAccountCreateRequest

@doc """
Joins the Account channel.
Expand All @@ -27,7 +29,7 @@ channel Helix.Account.Websocket.Channel.Account do
authenticated on the socket.
+ base errors
"""
join _, AccountJoin
join "account:" <> _, AccountJoin

@doc """
Forces a bootstrap to happen. It is the exact same operation ran during join.
Expand Down Expand Up @@ -233,6 +235,24 @@ channel Helix.Account.Websocket.Channel.Account do
"""
topic "virus.collect", VirusCollectRequest

@doc """
Creates a BankAccount

Params:
*atm_id: ATM.id related to bank that player wants to create account in

Returns: :ok

Errors:

Henforcer:
- atm_not_a_bank: Given `atm_id` is not a bank

Input:
+ base errors
"""
topic "bank.createacc", BankAccountCreateRequest

@doc """
Intercepts and handles outgoing events.
"""
Expand Down
25 changes: 24 additions & 1 deletion lib/core/validator/validator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@ defmodule Helix.Core.Validator do
| :hostname
| :bounce_name
| :reply_id
| :token

@regex_hostname ~r/^[a-zA-Z0-9-_.@#]{1,20}$/

@uuid ~r/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/

@spec validate_input(input :: String.t, input_type, opts :: term) ::
{:ok, validated_input :: String.t}
| :error
@doc """
This is a generic function meant to validate external input that does not
conform to a specific shape or format (like internal IDs or IP addresses).

The `element` argument identifies what the input is supposed to represent, and
The `type` argument identifies what the input is supposed to represent, and
we leverage this information to customize the validation for different kinds
of input.
"""
Expand All @@ -24,6 +27,9 @@ defmodule Helix.Core.Validator do
def validate_input(input, :password, _),
do: validate_password(input)

def validate_input(input, :money, _),
do: validate_money(input)

def validate_input(input, :hostname, _),
do: validate_hostname(input)

Expand All @@ -33,6 +39,9 @@ defmodule Helix.Core.Validator do
def validate_input(input, :reply_id, _),
do: validate_reply_id(input)

def validate_input(input, :token, _),
do: validate_token(input)

defp validate_hostname(v) when not is_binary(v),
do: :error
defp validate_hostname(v) do
Expand All @@ -43,6 +52,16 @@ defmodule Helix.Core.Validator do
end
end

defp validate_token(v) when not is_binary(v),
do: :error
defp validate_token(v) do
if Regex.match?(@uuid, v) do
{:ok, v}
else
:error
end
end

defp validate_password(input),
do: validate_hostname(input) # TODO

Expand All @@ -51,4 +70,8 @@ defmodule Helix.Core.Validator do

defp validate_reply_id(v),
do: validate_hostname(v) # TODO

defp validate_money(v),
do: validate_hostname(v)

end
23 changes: 23 additions & 0 deletions lib/event/dispatcher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -272,23 +272,29 @@ defmodule Helix.Event.Dispatcher do
# All
event BankEvent.Bank.Account.Login
event BankEvent.Bank.Account.Updated
event BankEvent.Bank.Account.Removed
event BankEvent.Bank.Account.Password.Revealed
event BankEvent.Bank.Account.Password.Changed
event BankEvent.Bank.Account.Token.Acquired
event BankEvent.Bank.Transfer.Processed
event BankEvent.Bank.Transfer.Aborted
event BankEvent.AccountCreate.Processed
event BankEvent.RevealPassword.Processed
event BankEvent.ChangePassword.Processed

# Custom handlers
event BankEvent.Bank.Transfer.Processed,
BankHandler.Bank.Transfer,
:transfer_processed

event BankEvent.Bank.Transfer.Processed,
NetworkHandler.Connection,
:bank_transfer_processed

event BankEvent.Bank.Transfer.Aborted,
BankHandler.Bank.Transfer,
:transfer_aborted

event BankEvent.Bank.Transfer.Aborted,
SoftwareHandler.Cracker,
:bank_transfer_aborted
Expand All @@ -301,11 +307,28 @@ defmodule Helix.Event.Dispatcher do
BankHandler.Bank.Account,
:password_reveal_processed

event BankEvent.ChangePassword.Processed,
BankHandler.Bank.Account,
:password_change_processed

event BankEvent.AccountCreate.Processed,
BankHandler.Bank.Account,
:account_create_processed

event BankEvent.AccountClose.Processed,
BankHandler.Bank.Account,
:account_close_processed

event BankEvent.Bank.Account.Password.Revealed,
EntityHandler.Database,
:bank_password_revealed

event BankEvent.Bank.Account.Password.Changed,
BankHandler.Bank.Account,
:password_changed

event BankEvent.Bank.Account.Login,
EntityHandler.Database,
:bank_account_login

end
7 changes: 5 additions & 2 deletions lib/event/notificable/notificable.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ defprotocol Helix.Event.Notificable do
action, also receive special treatment. Hence:

- third AT attack_target - Third party on victim's server
- third AT attack_source - Third party on attacker's server.
- third AT attack_source - Third party on attacker's server.
- third AT random_server - Third party on unrelated (random) server.

Last but not least, in some cases we do not have an attacker/victim
Expand Down Expand Up @@ -98,11 +98,14 @@ defprotocol Helix.Event.Notificable do

alias Helix.Account.Model.Account
alias Helix.Server.Model.Server
alias Helix.Universe.Bank.Model.ATM
alias Helix.Universe.Bank.Model.BankAccount

@type whom_to_notify ::
%{
optional(:server) => [Server.id],
optional(:account) => [Account.id]
optional(:account) => [Account.id],
optional(:bank_acc) => [term]
}

@spec generate_payload(event :: struct, Socket.t) ::
Expand Down
22 changes: 22 additions & 0 deletions lib/event/notification_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ defmodule Helix.Event.NotificationHandler do
alias Helix.Entity.Model.Entity
alias Helix.Server.Model.Server
alias Helix.Server.State.Websocket.Channel, as: ServerWebsocketChannelState
alias Helix.Universe.Bank.Model.ATM
alias Helix.Universe.Bank.Model.BankAccount

@type channel_account_id :: Account.id | Entity.id
@type channel_bank_id :: {ATM.id, BankAccount.account}

@doc """
Handler responsible for guiding the event through the Notificable flow. It
Expand All @@ -34,6 +37,18 @@ defmodule Helix.Event.NotificationHandler do
@spec channel_mapper(Notificable.whom_to_notify) ::
channels :: [String.t]
defp channel_mapper(whom_to_notify, acc \\ [])
defp channel_mapper(notify = %{bank_acc: bank_accs}, acc) do
acc =
bank_accs
|> Utils.ensure_list()
|> Enum.uniq()
|> get_bank_channels()
|> List.flatten()
|> Kernel.++(acc)

channel_mapper(Map.delete(notify, :bank_acc), acc)
end

defp channel_mapper(notify = %{server: servers}, acc) do
acc =
servers
Expand Down Expand Up @@ -94,6 +109,13 @@ defmodule Helix.Event.NotificationHandler do
defp get_account_channels(account_id),
do: ["account:" <> to_string(account_id)]

@spec get_bank_channels([channel_bank_id] | channel_bank_id) ::
channels :: [String.t]
defp get_bank_channels(bank_accs) when is_list(bank_accs),
do: Enum.map(bank_accs, &get_bank_channels/1)
defp get_bank_channels({atm_id, account_number}),
do: ["bank:" <> to_string(account_number) <> "@" <> to_string(atm_id)]

defp concat(a, b),
do: a <> to_string(b)
end
17 changes: 12 additions & 5 deletions lib/process/executable.ex
Original file line number Diff line number Diff line change
Expand Up @@ -318,18 +318,25 @@ defmodule Helix.Process.Executable do
src_acc_number: BankAccount.account | nil
}
@doc false
defp get_source_bank_account(_, _, _, _),
do: %{src_atm_id: nil, src_acc_number: nil}
defp get_source_bank_account(_, _, _, meta) do
%{
src_atm_id: Map.get(meta, :src_atm_id, nil),
src_acc_number: Map.get(meta, :src_acc_number, nil)
}
end

@spec get_target_bank_account(Server.t, Server.t, params, meta) ::
%{
tgt_atm_id: Server.t | nil,
tgt_acc_number: BankAccount.account | nil
}
@doc false
defp get_target_bank_account(_, _, _, _),
do: %{tgt_atm_id: nil, tgt_acc_number: nil}

defp get_target_bank_account(_, _, _, meta) do
%{
tgt_atm_id: Map.get(meta, :tgt_atm_id, nil),
tgt_acc_number: Map.get(meta, :tgt_acc_number, nil)
}
end
@spec get_target_process(Server.t, Server.t, params, meta) ::
%{tgt_process_id: Process.t | nil}
@doc false
Expand Down
3 changes: 3 additions & 0 deletions lib/process/model/process.ex
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ defmodule Helix.Process.Model.Process do
| :cracker_bruteforce
| :cracker_overflow
| :install_virus
| :bank_change_password
| :bank_reveal_password
| :bank_account_create

@typedoc """
List of signals a process may receive during its lifetime.
Expand Down
2 changes: 1 addition & 1 deletion lib/server/websocket/channel/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ channel Helix.Server.Websocket.Channel.Server do
Disables the PublicFTP server of the player.

Params: none

Returns: %{}

Errors:
Expand Down
4 changes: 2 additions & 2 deletions lib/software/model/file.ex
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ defmodule Helix.Software.Model.File do
path_size = (byte_size(path) - 1) * 8

case path do
<<path::bits-size(path_size)>> <> "/" ->
<<path::bits-size(path_size)>>
<<path::binary-size(path_size)>> <> "/" ->
<<path::binary-size(path_size)>>
path ->
path
end
Expand Down
Loading