forked from hpyhacking/peatio
-
Notifications
You must be signed in to change notification settings - Fork 623
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
116 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 49 additions & 8 deletions
57
db/migrate/20190807092706_add_encrypted_secret_to_payment_address.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,67 @@ | ||
class AddEncryptedSecretToPaymentAddress < ActiveRecord::Migration[5.2] | ||
def up | ||
secrets = PaymentAddress.pluck(:id, :secret) | ||
# details = PaymentAddress.pluck(:id, :details) | ||
# settings = Wallet.pluck(:id, :settings) | ||
details = PaymentAddress.pluck(:id, :details) | ||
settings = Wallet.pluck(:id, :settings) | ||
|
||
remove_column :payment_addresses, :secret | ||
add_column :payment_addresses, :secret_encrypted , :string, after: :address | ||
|
||
remove_column :payment_addresses, :details | ||
add_column :payment_addresses, :details_encrypted , :string, after: :secret_encrypted | ||
add_column :payment_addresses, :details_encrypted , :string, limit: 1024, after: :secret_encrypted | ||
|
||
remove_column :wallets, :settings | ||
add_column :wallets, :settings_encrypted , :string, after: :status | ||
add_column :wallets, :settings_encrypted , :string, limit: 1024, after: :gateway | ||
|
||
secrets.each do |s| | ||
atr = PaymentAddress.__vault_attributes[:secret] | ||
enc = Vault::Rails.encrypt(atr[:path], atr[:key], s[1]) | ||
# PaymentAddress.find(s[0]).update!(secret: s[1]) | ||
execute "UPDATE payment_addresses SET secret_encrypted = #{enc} WHERE id = #{s[0]}" | ||
execute "UPDATE payment_addresses SET #{atr[:encrypted_column]} = '#{enc}' WHERE id = #{s[0]}" | ||
end | ||
|
||
details.each do |d| | ||
atr = PaymentAddress.__vault_attributes[:details] | ||
enc = Vault::Rails.encrypt(atr[:path], atr[:key], d[1]) | ||
execute "UPDATE payment_addresses SET #{atr[:encrypted_column]} = '#{enc}' WHERE id = #{d[0]}" | ||
end | ||
|
||
settings.each do |s| | ||
atr = Wallet.__vault_attributes[:settings] | ||
enc = Vault::Rails.encrypt(atr[:path], atr[:key], s[1]) | ||
execute "UPDATE wallets SET #{atr[:encrypted_column]} = '#{enc}' WHERE id = #{s[0]}" | ||
end | ||
# details.each { |s| PaymentAddress.find(s[0]).update(details_encrypted: s[1]) } | ||
# settings.each { |s| Wallet.find(s[0]).update(settings_encrypted: s[1]) } | ||
end | ||
|
||
def down | ||
secrets = PaymentAddress.pluck(:id, :secret_encrypted) | ||
details = PaymentAddress.pluck(:id, :details_encrypted) | ||
settings = Wallet.pluck(:id, :settings_encrypted) | ||
|
||
add_column :payment_addresses, :secret, :string, limit: 128, after: :address | ||
remove_column :payment_addresses, :secret_encrypted , :string, after: :address | ||
|
||
add_column :payment_addresses, :details, :string, limit: 1.kilobyte, null: false, default: '{}', after: :secret | ||
remove_column :payment_addresses, :details_encrypted , :string, limit: 1024, after: :secret_encrypted | ||
|
||
add_column :wallets, :settings, :string, limit: 1000, default: '{}', null: false, after: :gateway | ||
remove_column :wallets, :settings_encrypted , :string, limit: 1024, after: :gateway | ||
|
||
secrets.each do |s| | ||
atr = PaymentAddress.__vault_attributes[:secret] | ||
dec = Vault::Rails.decrypt(atr[:path], atr[:key], s[1]) | ||
execute "UPDATE payment_addresses SET secret = '#{dec}' WHERE id = #{s[0]}" | ||
end | ||
|
||
details.each do |d| | ||
atr = PaymentAddress.__vault_attributes[:details] | ||
dec = Vault::Rails.decrypt(atr[:path], atr[:key], d[1]) | ||
execute "UPDATE payment_addresses SET details = '#{dec}' WHERE id = #{d[0]}" | ||
end | ||
|
||
settings.each do |s| | ||
atr = Wallet.__vault_attributes[:settings] | ||
dec = Vault::Rails.decrypt(atr[:path], atr[:key], s[1]) | ||
execute "UPDATE wallets SET settings = '#{dec}' WHERE id = #{s[0]}" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters