Skip to content

Commit

Permalink
Fix rebase problems with credential sharing
Browse files Browse the repository at this point in the history
  • Loading branch information
lkleisa committed Jul 12, 2023
1 parent 355397e commit 4a89e14
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
11 changes: 7 additions & 4 deletions app/models/encryptable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,20 @@ class Encryptable < ApplicationRecord
def encrypt(team_password, encryption_algorithm = nil)
return if file? && cleartext_file.empty?

used_encrypted_attrs.each do |attribute|
encrypt_attr(attribute, team_password, encryption_algorithm)
end
attributes = transferred? ? available_attrs : used_encrypted_attrs
attributes.each { |attribute| encrypt_attr(attribute, team_password, encryption_algorithm) }
end

def decrypt(team_password)
used_encrypted_attrs.each do |attribute|
available_attrs.each do |attribute|
decrypt_attr(attribute, team_password)
end
end

def available_attrs
used_encrypted_attrs.select { |attribute| encrypted_data[attribute]&.dig(:data) }
end

def recrypt(team_password, new_team_password, new_encryption_class)
decrypt(team_password)

Expand Down
4 changes: 0 additions & 4 deletions app/models/encryptable/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ class Encryptable::File < Encryptable

validate :file_size, on: [:create, :update]

def decrypt_transferred(private_key)
decrypt(plaintext_transfer_password(private_key))
end

def team
folder&.team || encryptable_credential.folder.team
end
Expand Down
11 changes: 7 additions & 4 deletions app/utils/encryptable_transfer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

class EncryptableTransfer

# rubocop:disable Metrics/MethodLength
def transfer(encryptable, receiver, sender)
transfer_password = transfer_password(receiver)
encryption_algorithm = receiver_encryption_algorithm(receiver)

transfer_password = encryption_algorithm.random_key
encryptable.encrypt(transfer_password, encryption_algorithm)

encryptable.name = encryptable_destination_name(encryptable, receiver)
Expand All @@ -16,6 +19,7 @@ def transfer(encryptable, receiver, sender)
)
encryptable
end
# rubocop:enable Metrics/MethodLength

def receive(encryptable, private_key, personal_team_password)
encryptable.decrypt_transferred(private_key)
Expand Down Expand Up @@ -45,10 +49,9 @@ def encrypted_transfer_password(password, receiver)
)
end

def transfer_password(receiver)
def receiver_encryption_algorithm(receiver)
encryption_algorithm = receiver.personal_team.encryption_algorithm
encryption_algorithm = Crypto::Symmetric::ALGORITHMS[encryption_algorithm]
encryption_algorithm.random_key
Crypto::Symmetric::ALGORITHMS[encryption_algorithm]
end

def transfered_name(name, existing_names, is_file)
Expand Down

0 comments on commit 4a89e14

Please sign in to comment.