I cry a little when someone says something is wrong, without explaining how to do it right. What's insecure with this, and how should it be done instead?
touch /tmp/pubkey.pem
chmod a+w /tmp/pubkey.pem
before the victim runs the code.No sticky bit, no restrictive umask, also no protected_hardlinks/protected_symlinks is going to save you.
While we're on the subject of the openssl tool and file permissions, I've been disappointed... On my system, this command creates key.pem word-readable: "openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -nodes" I've been meaning to set my umask to fix issues like this, as I have rare need to let another user account access my files. On the other hand, there aren't supposed to be any other users on my systems, and it's more likely my browser will get pwned and have access to my self-readable private keys anyway.
[0] https://github.com/hannob/tlshelpers/blob/46c50b27adf79476ae...