Perl encrypting STDIN passwords Perl encrypting STDIN passwords linux linux

Perl encrypting STDIN passwords


$ strace perl -E '<STDIN>'.... scroll, scroll, scroll ....read(0, ... type, type, type ...."secret\n", 4096)               = 7exit_group(0)                           = ?

I don't think that you can prevent someone with sufficient access rights from peeking inside your system calls or memory.


That's tough.

Run your encrypting code as a separate process, child of the main code, which process reads from STDIN and returns the encrypted password (and perhaps key). In that way, the code using your module will itself never hold the plaintext in memory.

Sure, tracing and memory inspection (and system memory inspection after process death) of the child helper will reveal the plaintext. The same techniques will reveal key and ciphertext read from a child helper, too. However, if the scenario against which you wish to defend is accidental retention of the plaintext in your process — in a complex object or a closure or I-didn't-know-a-temp-var-was-allocated-there — then do the work in a dedicated, short-lived process.


Sounds like you're implementing the Password Anti-pattern. That's a terrible idea - it teaches users to be phished. Please don't do that. You should look at using OAuth instead.