pglombardo / PasswordPusher

🔐 Securely share sensitive information with automatic expiration & deletion after a set number of views or duration. Track who, what and when with full audit logs.
https://docs.pwpush.com
Apache License 2.0
1.82k stars 332 forks source link

Sending emails using ssl/tls conection fails #754

Open tesudacochino opened 1 year ago

tesudacochino commented 1 year ago

🐛 Bug Report

I try to send any notification by mail using an SSL/TLS connection and I get an error message on the server.

🔬 How To Reproduce

To reproduce it, all you have to do is register a new user These are the logs of my mail server

Jan 26 16:25:11 mail postfix/smtps/smtpd[130056]: connect from unknown[192.168.4.120]
Jan 26 16:25:11 mail postfix/smtps/smtpd[130056]: setting up TLS connection from unknown[192.168.4.120]
Jan 26 16:25:11 mail postfix/smtps/smtpd[130056]: unknown[192.168.4.120]: TLS cipher list "aNULL:-aNULL:HIGH:@STRENGTH:!aNULL:!MD5:!DES:!ADH:!RC4:!PSD:!SRP:!3DES:!eNULL"
Jan 26 16:25:21 mail postfix/smtps/smtpd[130056]: SSL_accept error from unknown[192.168.4.120]: lost connection
Jan 26 16:25:21 mail postfix/smtps/smtpd[130056]: lost connection after CONNECT from unknown[192.168.4.120]
Jan 26 16:25:21 mail postfix/smtps/smtpd[130056]: disconnect from unknown[192.168.4.120] ehlo=1 auth=0/1 commands=1/2

The error returned by passwordpusher with PWPMAILRAISE_DELIVERY_ERRORS: true imagen

version: '2.1'
services:

  passwordpusher:
    image: pglombardo/pwpush-ephemeral:latest
    container_name: passwordpusher
    hostname: passwordpusher.local
    restart: always
    environment:
      PWP__ENABLE_LOGINS: true
      PWP__ALLOW_ANONYMOUS: true
      PWP__MAIL__SMTP_STARTTLS: false
      PWP__MAIL__SMTP_ENABLE_STARTTLS_AUTO: true
      # PWP__MAIL__RAISE_DELIVERY_ERRORS: true
      PWP__HOST_PROTOCOL: http
      PWP__MAIL__SMTP_ADDRESS: 192.168.1.113
      PWP__MAIL__SMTP_PORT: 465
      PWP__MAIL__SMTP_USER_NAME: ${USER_MAIL}
      PWP__MAIL__SMTP_PASSWORD: ${USER_PASSWORD}
      PWP__MAIL__MAILER_SENDER: ${MAILER_SENDER}
      PWP__HOST_DOMAIN: ${HOST_DOMAIN}
    ports:
      - "5100:5100"

Environment

Where are you running/using Password Pusher?

I tried latest and stable docker versión.

Screenshots

📈 Expected behavior

Receive an email :-)

📎 Additional context

This is my configuration of my Thunderbird mail client. imagen

github-actions[bot] commented 1 year ago

Hello @tesudacochino, thanks for contributing to the Password Pusher community! We will respond as soon as possible.

pglombardo commented 1 year ago

HI @tesudacochino - apologies for the issue. I've oddly had a couple reports of this lately despite no changes in the mail delivery.

To better diagnose, could you open a console in the pwpush container and run the following:

docker exec -it <containerId> /bin/bash
./bin/rails console
Rails.application.config.action_mailer.smtp_settings

That last command will output the Mail settings. Could you post that here without any sensitive information?

Then run this code snippet to manually send an email. Replace those email addresses with something valid:

Mail.deliver do
  to 'your@email.com'
  from 'your@email.com'
  subject 'testing mail'
  body 'testing mail'
end

Could you let me know what the output is. And did you get the email?

pglombardo commented 1 year ago

Setting PWP__MAIL__SMTP_STARTTLS to true may be worth trying too.

tesudacochino commented 1 year ago

Hi @pglombardo

thanks for your quick reply. I have tried the configuration you asked for.

docker-compose.yml file

version: '2.1'
services:

  passwordpusher:
    image: pglombardo/pwpush-ephemeral:latest
    container_name: passwordpusher
    hostname: passwordpusher.local
    restart: always
    environment:
      PWP__ENABLE_LOGINS: true
      PWP__ALLOW_ANONYMOUS: true
      PWP__MAIL__SMTP_STARTTLS: true
      PWP__MAIL__SMTP_ENABLE_STARTTLS_AUTO: true
      PWP__MAIL__RAISE_DELIVERY_ERRORS: true
      PWP__HOST_PROTOCOL: http
      PWP__MAIL__SMTP_ADDRESS: 192.168.1.113
      PWP__MAIL__SMTP_PORT: 465
      PWP__MAIL__SMTP_USER_NAME: ${USER_MAIL}
      PWP__MAIL__SMTP_PASSWORD: ${USER_PASSWORD}
      PWP__MAIL__MAILER_SENDER: ${MAILER_SENDER}
      PWP__HOST_DOMAIN: ${HOST_DOMAIN}
    ports:
      - "5100:5100"

Ruby console:

$ /opt/PasswordPusher/bin/rails console 
Loading private environment (Rails 7.0.4.1)
irb(main):001:0> Rails.application.config.action_mailer.smtp_settings
=> 
{:address=>"192.168.1.113",
 :port=>465,
 :user_name=>"xxxx@xxxxx.com",
 :password=>"xxxxx",
 :authentication=>"plain",
 :enable_starttls_auto=>true,
 :open_timeout=>10,
 :read_timeout=>10}
irb(main):002:1* Mail.deliver do
irb(main):003:1*   to 'sxxxx@xxxx.com'
irb(main):004:1*   from 'sxxxx@xxxxx.com'
irb(main):005:1*   subject 'testing mail'
irb(main):006:1*   body 'testing mail'
irb(main):007:0> end
/usr/local/lib/ruby/3.2.0/socket.rb:1217:in `__connect_nonblock': Cannot assign requested address - connect(2) for [::1]:25 (Errno::EADDRNOTAVAIL)
irb(main):008:0>
pglombardo commented 1 year ago

I don't understand really. The smtp_settings have "192.168.1.113" on port 465 but the error message refers to [::1]:25 which is the IPv6 localhost port 25.

Are you running in any special environment, container setup or equivalent?

pglombardo commented 1 year ago

Another test that should tell us something. Could you shell into the docker container again and run:

docker exec -it <containerId> /bin/bash
ruby -e 'require "socket"' -e "TCPSocket.open('192.168.1.113', 465)"
tesudacochino commented 1 year ago

I try different environment Docker in windows and Ubuntu 20.04.5 LTS and the same rsult.

pwpusher@passwordpusher:/opt/PasswordPusher/bin$ ruby -e 'require "socket"' -e "TCPSocket.open('192.168.1.113', 465)"
pwpusher@passwordpusher:/opt/PasswordPusher/bin$ rails console
Loading private environment (Rails 7.0.4.1)
irb(main):001:0> Rails.application.config.action_mailer.smtp_settings
irb(main):002:0* 
=> 
{:address=>"192.168.1.113",     
 :port=>465,                    
 :user_name=>"zurmo@brainstorm3d.com",
 :password=>"zurmo109238",      
 :authentication=>"plain",      
 :enable_starttls_auto=>true,   
 :open_timeout=>10,             
 :read_timeout=>10}
irb(main):003:1* Mail.deliver do
irb(main):004:1*   to 'your@email.com'
irb(main):005:1*   from 'your@email.com'
irb(main):006:1*   subject 'testing mail'
irb(main):007:1*   body 'testing mail'
irb(main):008:0> end
irb(main):009:0* 
/usr/local/lib/ruby/3.2.0/socket.rb:1217:in `__connect_nonblock': Cannot assign requested address - connect(2) for [::1]:25 (Errno::EADDRNOTAVAIL)
pglombardo commented 1 year ago

Hi @tesudacochino - I just released 1.25.6 that includes a mail system update that claims:

Bug Fixes: Regression: sendmail accepts string :arguments (@​sebbASF) Regression: accept enable_starttls_auto: false @​ahorek

A regression in that library would explain this change of behavior despite no changes in Password Pusher. Let's see if this has any affect for you. 1.25.6 is building now.

pglombardo commented 1 year ago

Hi @tesudacochino - Other users have reported a work around in https://github.com/pglombardo/PasswordPusher/issues/755#issuecomment-1429803307

It seems to be a bug in a dependent library that Password Pusher uses.

i have play with PWPMAILSMTP_ENABLE_STARTTLS_AUTO option. If i set this to false, the error is gone and the mail is send, with true the error is persistent.

cc: @kuehnel-net thanks for digging on this!

pglombardo commented 1 year ago

Hi @tesudacochino - it's been a while on this issue - has anything changed on your side? Have you tried setting PWP__MAIL__SMTP_ENABLE_STARTTLS_AUTO=false as mentioned in the comment above?

lauraled commented 1 year ago

Hello, not the OP, but setting PWP__MAIL__SMTP_ENABLE_STARTTLS_AUTO to false fixed the error for me. I checked the Ruby logs and the error message was the same. After setting the env variable I can now send mails.

pglombardo commented 3 months ago

Hi all - as an update on the email story: in v1.39.8, I added a tool to test email configurations. Could you update to that version and try this out?

It should reveal where the issue is...