Skip to content

Commit

Permalink
Log access CRAM-MD5 authentication failures (#2304)
Browse files Browse the repository at this point in the history
  • Loading branch information
wadabum authored Mar 13, 2023
1 parent acc1fe7 commit 9b1ed1e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/postal/smtp_server/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,10 @@ def auth_cram_md5(data)
username, password = Base64.decode64(data).split(' ', 2).map{ |a| a.chomp }
org_permlink, server_permalink = username.split(/[\/\_]/, 2)
server = ::Server.includes(:organization).where(:organizations => {:permalink => org_permlink}, :permalink => server_permalink).first
next '535 Denied' if server.nil?
if server.nil?
log "\e[33m WARN: AUTH failure for #{@ip_address}\e[0m"
next '535 Denied'
end
grant = nil
server.credentials.where(:type => 'SMTP').each do |credential|
correct_response = OpenSSL::HMAC.hexdigest(CRAM_MD5_DIGEST, credential.key, challenge)
Expand All @@ -239,7 +242,11 @@ def auth_cram_md5(data)
break
end
end
grant || '535 Denied'
if grant.nil?
log "\e[33m WARN: AUTH failure for #{@ip_address}\e[0m"
next "535 Denied"
end
grant
end

@proc = handler
Expand Down

0 comments on commit 9b1ed1e

Please sign in to comment.