From 2fbb4ed1de7a14c803f207f8394bbb726812d6c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=9F=D0=BE=D0=B7?= =?UTF-8?q?=D0=B4=D0=BD=D1=8F=D0=BA=D0=BE=D0=B2?= Date: Tue, 30 Aug 2022 16:54:54 +0300 Subject: [PATCH] Ready to migrate and encrypt --- apps/explorer/lib/encrypt.ex | 23 ++++++++++++- .../lib/explorer/account/custom_abi.ex | 14 ++++---- .../explorer/lib/explorer/account/identity.ex | 32 +++++++++---------- .../explorer/account/public_tags_request.ex | 7 ++++ .../lib/explorer/account/tag_address.ex | 12 +++---- .../lib/explorer/account/tag_transaction.ex | 14 ++++---- .../lib/explorer/account/watchlist_address.ex | 15 ++++----- .../account/watchlist_notification.ex | 32 +++++++++---------- .../third_party_integrations/airtable.ex | 4 ++- .../20220706114430_encrypt_account_data.exs | 6 ++++ ...220706153506_remove_unencrypted_fields.exs | 9 ++++++ 11 files changed, 106 insertions(+), 62 deletions(-) diff --git a/apps/explorer/lib/encrypt.ex b/apps/explorer/lib/encrypt.ex index 95f2f4ecf9..e105feb11d 100644 --- a/apps/explorer/lib/encrypt.ex +++ b/apps/explorer/lib/encrypt.ex @@ -3,7 +3,17 @@ defmodule Mix.Tasks.Encrypt do use Mix.Task alias Ecto.Changeset - alias Explorer.Account.{CustomABI, Identity, TagAddress, TagTransaction, WatchlistAddress, WatchlistNotification} + + alias Explorer.Account.{ + CustomABI, + Identity, + PublicTagsRequest, + TagAddress, + TagTransaction, + WatchlistAddress, + WatchlistNotification + } + alias Explorer.Repo.Account alias Mix.Task @@ -91,5 +101,16 @@ defmodule Mix.Tasks.Encrypt do }) |> Account.update!() end) + + PublicTagsRequest + |> Account.all() + |> Enum.each(fn element -> + element + |> Changeset.change(%{ + encrypted_full_name: element.full_name, + encrypted_email: element.email + }) + |> Account.update!() + end) end end diff --git a/apps/explorer/lib/explorer/account/custom_abi.ex b/apps/explorer/lib/explorer/account/custom_abi.ex index 6395f57b0e..37d898eeed 100644 --- a/apps/explorer/lib/explorer/account/custom_abi.ex +++ b/apps/explorer/lib/explorer/account/custom_abi.ex @@ -8,7 +8,7 @@ defmodule Explorer.Account.CustomABI do alias Ecto.Changeset alias Explorer.Account.Identity alias Explorer.{Chain, Repo} - # alias Explorer.Chain.Hash + alias Explorer.Chain.Hash import Explorer.Chain, only: [hash_to_lower_case_string: 1] import Ecto.Changeset @@ -20,16 +20,16 @@ defmodule Explorer.Account.CustomABI do field(:given_abi, :string, virtual: true) field(:abi_validating_error, :string, virtual: true) - # field(:name, :string) - # field(:address_hash, Hash.Address, null: false) + field(:name, :string) + field(:address_hash, Hash.Address, null: false) - # field(:encrypted_address_hash, Explorer.Encrypted.AddressHash, null: false) - # field(:encrypted_name, Explorer.Encrypted.Binary) + field(:encrypted_address_hash, Explorer.Encrypted.AddressHash, null: false) + field(:encrypted_name, Explorer.Encrypted.Binary) field(:address_hash_hash, Cloak.Ecto.SHA256) - field(:address_hash, Explorer.Encrypted.AddressHash, null: false) - field(:name, Explorer.Encrypted.Binary) + # field(:address_hash, Explorer.Encrypted.AddressHash, null: false) + # field(:name, Explorer.Encrypted.Binary) belongs_to(:identity, Identity) diff --git a/apps/explorer/lib/explorer/account/identity.ex b/apps/explorer/lib/explorer/account/identity.ex index 7923199f0c..5be36afc12 100644 --- a/apps/explorer/lib/explorer/account/identity.ex +++ b/apps/explorer/lib/explorer/account/identity.ex @@ -11,25 +11,25 @@ defmodule Explorer.Account.Identity do alias Explorer.Account.{TagAddress, Watchlist} schema "account_identities" do - # field(:uid, :string) - # field(:email, :string) - # field(:name, :string) - # field(:nickname, :string) - # field(:avatar, :string) - - # field(:encrypted_uid, Explorer.Encrypted.Binary) - # field(:encrypted_email, Explorer.Encrypted.Binary) - # field(:encrypted_name, Explorer.Encrypted.Binary) - # field(:encrypted_nickname, Explorer.Encrypted.Binary) - # field(:encrypted_avatar, Explorer.Encrypted.Binary) + field(:uid, :string) + field(:email, :string) + field(:name, :string) + field(:nickname, :string) + field(:avatar, :string) + + field(:encrypted_uid, Explorer.Encrypted.Binary) + field(:encrypted_email, Explorer.Encrypted.Binary) + field(:encrypted_name, Explorer.Encrypted.Binary) + field(:encrypted_nickname, Explorer.Encrypted.Binary) + field(:encrypted_avatar, Explorer.Encrypted.Binary) field(:uid_hash, Cloak.Ecto.SHA256) - field(:uid, Explorer.Encrypted.Binary) - field(:email, Explorer.Encrypted.Binary) - field(:name, Explorer.Encrypted.Binary) - field(:nickname, Explorer.Encrypted.Binary) - field(:avatar, Explorer.Encrypted.Binary) + # field(:uid, Explorer.Encrypted.Binary) + # field(:email, Explorer.Encrypted.Binary) + # field(:name, Explorer.Encrypted.Binary) + # field(:nickname, Explorer.Encrypted.Binary) + # field(:avatar, Explorer.Encrypted.Binary) has_many(:tag_addresses, TagAddress) has_many(:watchlists, Watchlist) diff --git a/apps/explorer/lib/explorer/account/public_tags_request.ex b/apps/explorer/lib/explorer/account/public_tags_request.ex index 273d7b5b18..2d47374bd4 100644 --- a/apps/explorer/lib/explorer/account/public_tags_request.ex +++ b/apps/explorer/lib/explorer/account/public_tags_request.ex @@ -22,6 +22,7 @@ defmodule Explorer.Account.PublicTagsRequest do schema("account_public_tags_requests") do field(:full_name, :string) field(:email, :string) + field(:company, :string) field(:website, :string) field(:tags, :string) @@ -33,6 +34,12 @@ defmodule Explorer.Account.PublicTagsRequest do field(:remove_reason, :string) field(:request_id, :string) + field(:encrypted_full_name, Explorer.Encrypted.Binary) + field(:encrypted_email, Explorer.Encrypted.Binary) + + # field(:full_name, Explorer.Encrypted.Binary) + # field(:email, Explorer.Encrypted.Binary) + belongs_to(:identity, Identity) timestamps() diff --git a/apps/explorer/lib/explorer/account/tag_address.ex b/apps/explorer/lib/explorer/account/tag_address.ex index d82dc81c7a..ba91331cb4 100644 --- a/apps/explorer/lib/explorer/account/tag_address.ex +++ b/apps/explorer/lib/explorer/account/tag_address.ex @@ -17,15 +17,15 @@ defmodule Explorer.Account.TagAddress do @max_tag_address_per_account 15 schema "account_tag_addresses" do - # field(:name, :string) - # field(:address_hash, Hash.Address, null: false) - # field(:encrypted_name, Explorer.Encrypted.Binary) - # field(:encrypted_address_hash, Explorer.Encrypted.AddressHash, null: false) + field(:name, :string) + field(:address_hash, Hash.Address, null: false) + field(:encrypted_name, Explorer.Encrypted.Binary) + field(:encrypted_address_hash, Explorer.Encrypted.AddressHash, null: false) field(:address_hash_hash, Cloak.Ecto.SHA256) - field(:name, Explorer.Encrypted.Binary) - field(:address_hash, Explorer.Encrypted.AddressHash, null: false) + # field(:name, Explorer.Encrypted.Binary) + # field(:address_hash, Explorer.Encrypted.AddressHash, null: false) belongs_to(:identity, Identity) diff --git a/apps/explorer/lib/explorer/account/tag_transaction.ex b/apps/explorer/lib/explorer/account/tag_transaction.ex index 26da9843ca..5649ea0be8 100644 --- a/apps/explorer/lib/explorer/account/tag_transaction.ex +++ b/apps/explorer/lib/explorer/account/tag_transaction.ex @@ -10,21 +10,21 @@ defmodule Explorer.Account.TagTransaction do alias Ecto.Changeset alias Explorer.Account.Identity alias Explorer.{Chain, Repo} - # alias Explorer.Chain.Hash + alias Explorer.Chain.Hash import Explorer.Chain, only: [hash_to_lower_case_string: 1] @max_tag_transaction_per_account 15 schema "account_tag_transactions" do - # field(:name, :string) - # field(:tx_hash, Hash.Full, null: false) + field(:name, :string) + field(:tx_hash, Hash.Full, null: false) - # field(:encrypted_name, Explorer.Encrypted.Binary) - # field(:encrypted_tx_hash, Explorer.Encrypted.TransactionHash, null: false) + field(:encrypted_name, Explorer.Encrypted.Binary) + field(:encrypted_tx_hash, Explorer.Encrypted.TransactionHash, null: false) field(:tx_hash_hash, Cloak.Ecto.SHA256) - field(:name, Explorer.Encrypted.Binary) - field(:tx_hash, Explorer.Encrypted.TransactionHash, null: false) + # field(:name, Explorer.Encrypted.Binary) + # field(:tx_hash, Explorer.Encrypted.TransactionHash, null: false) belongs_to(:identity, Identity) diff --git a/apps/explorer/lib/explorer/account/watchlist_address.ex b/apps/explorer/lib/explorer/account/watchlist_address.ex index e75dea41d6..728ca76313 100644 --- a/apps/explorer/lib/explorer/account/watchlist_address.ex +++ b/apps/explorer/lib/explorer/account/watchlist_address.ex @@ -11,23 +11,22 @@ defmodule Explorer.Account.WatchlistAddress do alias Explorer.Account.Notifier.ForbiddenAddress alias Explorer.Account.Watchlist alias Explorer.{Chain, Repo} - alias Explorer.Chain.{Address, Wei} - # , Hash + alias Explorer.Chain.{Address, Wei, Hash} import Explorer.Chain, only: [hash_to_lower_case_string: 1] @max_watchlist_addresses_per_account 10 schema "account_watchlist_addresses" do - # field(:name, :string) - # field(:address_hash, Hash.Address, null: false) - # field(:encrypted_name, Explorer.Encrypted.Binary) - # field(:encrypted_address_hash, Explorer.Encrypted.AddressHash, null: false) + field(:name, :string) + field(:address_hash, Hash.Address, null: false) + field(:encrypted_name, Explorer.Encrypted.Binary) + field(:encrypted_address_hash, Explorer.Encrypted.AddressHash, null: false) field(:address_hash_hash, Cloak.Ecto.SHA256) - field(:name, Explorer.Encrypted.Binary) - field(:address_hash, Explorer.Encrypted.AddressHash, null: false) + # field(:name, Explorer.Encrypted.Binary) + # field(:address_hash, Explorer.Encrypted.AddressHash, null: false) belongs_to(:watchlist, Watchlist) diff --git a/apps/explorer/lib/explorer/account/watchlist_notification.ex b/apps/explorer/lib/explorer/account/watchlist_notification.ex index f2e5a11cc9..7625026c78 100644 --- a/apps/explorer/lib/explorer/account/watchlist_notification.ex +++ b/apps/explorer/lib/explorer/account/watchlist_notification.ex @@ -10,7 +10,7 @@ defmodule Explorer.Account.WatchlistNotification do alias Explorer.Account.WatchlistAddress - # alias Explorer.Chain.Hash + alias Explorer.Chain.Hash schema "account_watchlist_notifications" do field(:amount, :decimal) @@ -21,30 +21,30 @@ defmodule Explorer.Account.WatchlistNotification do field(:type, :string) field(:viewed_at, :integer) - # field(:name, :string) - # field(:subject, :string) + field(:name, :string) + field(:subject, :string) - # field(:encrypted_name, Explorer.Encrypted.Binary) - # field(:encrypted_subject, Explorer.Encrypted.Binary) + field(:encrypted_name, Explorer.Encrypted.Binary) + field(:encrypted_subject, Explorer.Encrypted.Binary) - field(:name, Explorer.Encrypted.Binary) - field(:subject, Explorer.Encrypted.Binary) + # field(:name, Explorer.Encrypted.Binary) + # field(:subject, Explorer.Encrypted.Binary) field(:subject_hash, Cloak.Ecto.SHA256) belongs_to(:watchlist_address, WatchlistAddress) - # field(:encrypted_from_address_hash, Explorer.Encrypted.AddressHash) - # field(:encrypted_to_address_hash, Explorer.Encrypted.AddressHash) - # field(:encrypted_transaction_hash, Explorer.Encrypted.TransactionHash) + field(:encrypted_from_address_hash, Explorer.Encrypted.AddressHash) + field(:encrypted_to_address_hash, Explorer.Encrypted.AddressHash) + field(:encrypted_transaction_hash, Explorer.Encrypted.TransactionHash) - # field(:from_address_hash, Hash.Address) - # field(:to_address_hash, Hash.Address) - # field(:transaction_hash, Hash.Full) + field(:from_address_hash, Hash.Address) + field(:to_address_hash, Hash.Address) + field(:transaction_hash, Hash.Full) - field(:from_address_hash, Explorer.Encrypted.AddressHash) - field(:to_address_hash, Explorer.Encrypted.AddressHash) - field(:transaction_hash, Explorer.Encrypted.TransactionHash) + # field(:from_address_hash, Explorer.Encrypted.AddressHash) + # field(:to_address_hash, Explorer.Encrypted.AddressHash) + # field(:transaction_hash, Explorer.Encrypted.TransactionHash) field(:from_address_hash_hash, Cloak.Ecto.SHA256) field(:to_address_hash_hash, Cloak.Ecto.SHA256) diff --git a/apps/explorer/lib/explorer/third_party_integrations/airtable.ex b/apps/explorer/lib/explorer/third_party_integrations/airtable.ex index cd7e1e0f88..f45ea8499b 100644 --- a/apps/explorer/lib/explorer/third_party_integrations/airtable.ex +++ b/apps/explorer/lib/explorer/third_party_integrations/airtable.ex @@ -37,7 +37,9 @@ defmodule Explorer.ThirdPartyIntegrations.AirTable do input - _ -> + error -> + Logger.error(fn -> ["Error while submitting AirTable entry", inspect(error)] end) + {:error, %{ (%PublicTagsRequest{} diff --git a/apps/explorer/priv/account/migrations/20220706114430_encrypt_account_data.exs b/apps/explorer/priv/account/migrations/20220706114430_encrypt_account_data.exs index 4811b2db0f..0328025982 100644 --- a/apps/explorer/priv/account/migrations/20220706114430_encrypt_account_data.exs +++ b/apps/explorer/priv/account/migrations/20220706114430_encrypt_account_data.exs @@ -11,6 +11,7 @@ defmodule Explorer.Repo.Account.Migrations.EncryptAccountData do add(:encrypted_avatar, :binary, null: true) end + # unused because we dont have personal watchlists, only autogenerated `default` for each identity # alter table(:account_watchlists) do # add(:encrypted_name, :binary) # end @@ -50,5 +51,10 @@ defmodule Explorer.Repo.Account.Migrations.EncryptAccountData do add(:to_address_hash_hash, :binary, null: true) add(:transaction_hash_hash, :binary, null: true) end + + alter table(:account_public_tags_requests) do + add(:encrypted_email, :binary) + add(:encrypted_full_name, :binary) + end end end diff --git a/apps/explorer/priv/account/migrations/20220706153506_remove_unencrypted_fields.exs b/apps/explorer/priv/account/migrations/20220706153506_remove_unencrypted_fields.exs index 0660e09521..b887ac9f79 100644 --- a/apps/explorer/priv/account/migrations/20220706153506_remove_unencrypted_fields.exs +++ b/apps/explorer/priv/account/migrations/20220706153506_remove_unencrypted_fields.exs @@ -16,6 +16,7 @@ defmodule Explorer.Repo.Account.Migrations.RemoveUnencryptedFields do rename(table(:account_identities), :encrypted_nickname, to: :nickname) rename(table(:account_identities), :encrypted_avatar, to: :avatar) + # unused because we dont have personal watchlists, only autogenerated `default` for each identity # alter table(:account_watchlists) do # remove(:name) # end @@ -66,5 +67,13 @@ defmodule Explorer.Repo.Account.Migrations.RemoveUnencryptedFields do rename(table(:account_watchlist_notifications), :encrypted_from_address_hash, to: :from_address_hash) rename(table(:account_watchlist_notifications), :encrypted_to_address_hash, to: :to_address_hash) rename(table(:account_watchlist_notifications), :encrypted_transaction_hash, to: :transaction_hash) + + alter table(:account_public_tags_requests) do + remove(:full_name) + remove(:email) + end + + rename(table(:account_public_tags_requests), :encrypted_full_name, to: :full_name) + rename(table(:account_public_tags_requests), :encrypted_email, to: :email) end end