Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detailed logging for decryption/validation #10

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
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
27 changes: 21 additions & 6 deletions lib/decrypt_mails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ module InstanceMethods

def receive_with_encryption(email, options={})

# Extract useful metadata for logging
sender_email = email.from.to_a.first.to_s.strip
# We need to store this before decryption, because after decryption
# email.encrypted? == false
encrypted = email.encrypted?
# Sometimes this isn't available after decryption. This seems like a bug,
# so extract it here so we're guaranteed to have it
message_id = email.message_id

# encrypt and check validity of signature
if email.encrypted?
email = email.decrypt(
Expand All @@ -32,7 +41,6 @@ def receive_with_encryption(email, options={})
# compare identity of signature with sender
if valid
valid = false
sender_email = email.from.to_a.first.to_s.strip
user = User.find_by_mail sender_email if sender_email.present?
key = Pgpkey.find_by user_id: user.id
signatures.each do |s|
Expand All @@ -41,10 +49,17 @@ def receive_with_encryption(email, options={})
end

# error on invalid signature
if Setting.plugin_openpgp['signature_needed'] and not valid
if logger
logger.info "MailHandler: ignoring emails with invalid signature"
end
ignored = !!(Setting.plugin_openpgp['signature_needed'] and not valid)

if logger
logger.info "MailHandler: received email from #{sender_email} " +
"with Message-ID #{message_id}: " +
"encrypted=#{encrypted}, " +
"valid=#{valid}, "+
"ignored=#{ignored}"
end

if ignored
return false
end

Expand All @@ -53,4 +68,4 @@ def receive_with_encryption(email, options={})
end

end
end
end