Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My applications need to send emails, where and how should I store the SMTP password?

It seems like every application I create needs to be able to send the occasional email. E.g. status emails. For this question, assume my application is a backup tool, locally installed on many windows clients, and each installation needs to send daily status mails. It could be installed on an organization's server or on a private computer.

I am asking the user to provide the credentials to an email account he owns (STMP host, port, username, password, from-address). I copied this approach from applications like Atlassian Jira/Confluence or JFrog Artifactory. Where and how are they storing the SMTP passwords anyway?

My current understanding is: Salting/Hashing approaches do not apply here as I need to be able to retrieve the plaintext password to actually send the emails. I don't want to store the passwords in plaintext, so it's got to be some kind of encryption/decryption approach (right?).

I can tell the user not to use his main email account, but to use some secondary account or, even better, setup a special email account just to be used by my application. If the user is an admin of an organization, he might be able to setup an email account on his exchange server or configure SMTP relaying. But, I know me, and I know my private users, some of them will just use their main email account anyway, so I want to do everything I can to keep their credentials as safe as possible (by that I mean "follow best practices").

Preferrably I would like to store the encrypted password in the application's database.

I've spent hours and hours reading through questions on stackoverflow, but I cannot see a consensus (like there is for user account login credentials). I find this surprising, as I expect basically every developer to be confronted with this problem sooner or later.

There must be some best practices to follow, some established way to go about this, but I haven't found it yet.

Please point me to resources on SO/the web that explain how to tackle this problem. If at all possible written by some specialist in the field.

Some SO questions I have looked at:

  • Protecting user passwords in desktop applications (Rev 2)
  • Windows equivalent of OS X Keychain?
like image 345
Reto Höhener Avatar asked Jul 10 '13 08:07

Reto Höhener


People also ask

Do you need a password for SMTP?

Why you shouldn't use SMTP servers without authentication. Let's say your company supplies an email address for your employees. However, there is no need for authentication to connect to the email server. So, they don't have to enter a username and password to send an email.


1 Answers

It would be good if you would have provided more details on the operating system and the programming language...

However here are some general advices:

The most important thing you have to know is: If your application is able to decrypt it without user interaction (e.g. a password by the user or a hardware token) any attacker will be able to do it. All measures you implement will just increase the complexity of gaining this password.

Of course you should raise the bar as high as possible. For Windows, the DPAPI will be your friend. You can find some Information on how to use it for example here: http://www.c-sharpcorner.com/UploadFile/mosessaur/dpapiprotecteddataclass01052006142332PM/dpapiprotecteddataclass.aspx with C# (I don't know which environment you use).

You can also implement your own configuration and encrypt it using a RSA with a key stored in the local key container - see http://msdn.microsoft.com/en-us/library/system.security.cryptography.rsacryptoserviceprovider%28v=vs.100%29.aspx.

Maybe some other people can help you with other operating systems, but the concept there will be the same.

What also may be possible is to use some kind of SSO authentication like Kerberos or NTLM or ..., but this means modifications on the mail server.

like image 113
Chris Avatar answered Oct 03 '22 04:10

Chris