I'm writing a PowerShell script that, every few months, a third-party app will automatically call to do the following among other things:
- Use
[System.Web.Security.Membership]::GeneratePassword()
to randomly-generate a password then use that password withExport-PfxCertificate
and OpenSSL'spassin
. - Use a static password to authenticate via COM API to a third-party system that doesn't support API keys or anything.
What's the best way to do this securely?
As far as I'm aware, there's nothing wrong with #1 but everything I've read online regarding #2 advises:
- Requiring that the user supply the credentials when the script is executed but that defeats the point of automating the process.
- Using PSCredential but that's not possible here.
- Using an encrypted key / password file but, as far as I'm aware, there isn't really any point in that as you're effectively still storing the password alongside the script file - if the server gets compromised then they could either read the password from the script or decrypt the password in the keyfile. Unless you use a custom encryption key which isn't stored on the server but, again, that defeats the automation.