I'd like to ask for some advice on the app security when it comes to getting the password from the user and storing it.
I'm developing a tool using .NET Core (console project) and Selenium WebDriver to automate a process on a website, which requires authentication, and my concerns are following:
1. Getting the password from the user (using console) and securely handle it
2. Storing the password in a secure manner
Regarding the first point:
- I've found an answer on
SO pointing out that
using
SecureString
doesn't fully prevent sensitive data to be read as at some point it has to be converted to/from normal string. I have come across the solution for getting user input from console usingSecureString
s, but according to what's written hereSecureStringToBSTR
has to be used to handle the sensitive data in a secure way. However,SecureStringToBSTR
is not included in .NET Core, because it's available only for Windows thus I'm stuck.
As for the second point:
- I cannot hash the password as it has to be restored. At first I
wanted to use platform specific solutions and check the current
platform in the app, but after a research I found out that there's API only for DPAPI for Windows, there's no API for KeyChain in MacOS (there's some workaround) and Linux doesn't have a unified way of storing sensitive data at all. The only solution I can think of is to force the user to generate public/private keys (using for example RSA which is available on all platforms, encrypt the password using public key and require private key to retrieve the password. Then I would store the encrypted password either in
appsettings.json
or as an Environmental variable as desribed here. Unfortunately Azure Key Vault is not free
I am aware that there are many questions similar to this, but:
- I couldn't find any regarding storing passwords, most sources focus on hashing them, however, it doesn't apply to described use case
- Virtually all are focused on ASP.NET Core MVC
Thanks in advance for the hints.