mirror of
https://github.com/dani-garcia/vaultwarden.git
synced 2026-04-26 01:35:54 +03:00
[GH-ISSUE #356] SMTP AUTH PLAIN value is not sent correctly #204
Labels
No labels
SSO
Third party
better for forum
bug
bug
documentation
duplicate
enhancement
future Vault
future Vault
future Vault
good first issue
help wanted
low priority
notes
pull-request
question
troubleshooting
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vaultwarden#204
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @goooseman on GitHub (Jan 21, 2019).
Original GitHub issue: https://github.com/dani-garcia/vaultwarden/issues/356
I have a problem with emails not being sent using SMTP, because of AUTH PLAIN value is not sent correctly.
I am using mailgun SMTP server to send emails using SSL with latest docker image of Bitwarden_rs server.
My email env vars are the following: (of course username and password are not real)
The logs :
The problem is how Bitwarden server (or
letterlibrary) is generating theAUTH PLAINvalue.Let's say, we have those credentials:
Username: test@test.com
Password: 12345678
AUTH PLAIN is username + password in base64 format
So the result should be
dGVzdEB0ZXN0LmNvbTEyMzQ1Njc4Cg==(echo test@test.com12345678 | base64)But Bitwarden is sending
AHRlc3RAdGVzdC5jb20KADEyMzQ1Njc4Cg==. If we decode it, we get the following:So the difference is a line break. I have not found any AUTH PLAIN specification with a line break between username and password.
Does SMTP works for somebody?
And how this issue can be fixed?
I've looked at the
mail.rssource file and I see that we are usinglettrelibrary to send emails.But the library should work OK, I have found a working code with this library and Mailgun SMTP, but it uses
SmtpTransportBuilderinstead ofSmtpClient.Or maybe the problem can be how we parse the env vars?
I am completely new to Rust so I do not know how can I debug this problem more.
@goooseman commented on GitHub (Jan 21, 2019):
Strange, but it works with Gmail server ok. I mean the issue is still exists, just some SMTP servers works ok with username and password separated by a new line, and some not.
@dani-garcia commented on GitHub (Jan 21, 2019):
That's interesting.
The
SmtpTransportBuildervsSmtpClientissue was due to a refactor in lettre, so that shouldn't be the problem.Looking through lettre's credentials impl, they don't add a new line, but a null character first and between them it seems: https://github.com/lettre/lettre/blob/master/lettre/src/smtp/authentication.rs#L100
You can replace the block in https://github.com/dani-garcia/bitwarden_rs/blob/master/src/mail.rs#L27 with somethting like this:
And that should print something like
|test@test.com|12345678|if the newline is caused by the config or by lettre.I'll try to test this in a day or two if you can't get to it by then.
@goooseman commented on GitHub (Jan 22, 2019):
Thanks for the reply,
It took some time for me to set up a local rust environment on my machine.
But I succeded and here is the ouput:
|test@test.com|12345678|.So the problem is in lettre library. Does bitwarden_rs use the latest version?
If yes, should I open an issue there?
Strange thing, that lettre works ok with mailgun, but using
SmtpTransportBuilderclass.@dani-garcia commented on GitHub (Jan 22, 2019):
Can you try to run this one:
It's basically doing the exact same thing that the code that works for you, but using the newer version with the newer API. If that still doesn't work, then you can probably report this upstream, but the Lettre project doesn't seem to be actively maintained, so I'm not sure if you'll get a response.
Worst case, we could migrate to another email library like this one, which seems more actively maintained, but it's also quite less known: https://crates.io/crates/mail
@goooseman commented on GitHub (Jan 22, 2019):
Hi, thank you for an example.
I've tried the code and it works perfectly. Got an email to my mailbox.
@dani-garcia commented on GitHub (Jan 22, 2019):
That's interesting, can you try if it works without the line
.authentication_mechanism(Mechanism::Plain)?Right now we aren't specifying that, but as far as I know lettre uses Plain by default.
The only other difference is that we disable connection reuse, but that shouldn't affect this.
@goooseman commented on GitHub (Jan 22, 2019):
Yep, it works without
authentication_mechanism.I was trying to turn on debug for lettre to see what exactly does it send as
AUTH PLAIN, but did not figure out how to it.But anyway, it works.
@dani-garcia commented on GitHub (Jan 22, 2019):
The only other differences that I can see between that code and what we are doing are:
The connection reuse thing:
Add
.connection_reuse(ConnectionReuseParameters::NoReuse)in place of theauthentication_mechanismand adduse lettre::smtp::ConnectionReuseParameters;after the other uses.We are also using a different
from()when building the email:Change it to
.from((mailgun_username.as_str(), "Your Name"))You could test if changing those two things does anything, but I can't imagine how that could be related
@goooseman commented on GitHub (Jan 22, 2019):
.from()method take only 1 parameter, so I get an error, when using 2:But I've tried to make all other modifications, and I still get an email.
Just for the reference, my final code looks like this:
Can it be just the lettre version?
UPD: I see, that it is the same lettre version. Really weird.
How can I debug what is lettre sending now?
@dani-garcia commented on GitHub (Jan 22, 2019):
The from needs two parenthesis, it's not two parameters, but one tuple with two values:
from( (a, b) )The lettre version that I put in the example above is the same one that we are currently using, which is the latest commit in the lettre repo.
About edit: The logs already print everything that there is to show, you could use a debugger to follow the code step by step or you could clone lettre and add extra debug prints before the error occurs to try to locate the cause.
@goooseman commented on GitHub (Jan 22, 2019):
Ooook, found smth interesting...
I've tried to send a real email from bitwarden_rs locally.
Sorry, did not try before locally.
And it works!
So the issue is only reproducible in my K8S cluster using
mprasil/bitwarden:latestdocker image.I will do more tests tomorrow from the cluster. But this is really weird.
@goooseman commented on GitHub (Jan 22, 2019):
Ok, I confirm.
Bitwarden_rs running locally generates a correct
AUTH PLAINstring without line break, if decoded from base64.Bitwarden_rs running in K8S cluster generates not a correct
AUTH PLAINstring without line break, if decoded from base64.But with Gmail it works OK even in K8S cluster, but there is a line break in the
AUTH PLAINstring.@goooseman commented on GitHub (Jan 22, 2019):
Ok, now I see. It is how I encode to base64.
Do not use
echo smth | base64