Better error checking on private key and csr.  Also, pull in file names ...

...instead of pointers.
But you changed the behaviour by not using `key_pem` throughout the function.