CP-24800: Make TLS cert generation atomic
CP-24800: Make TLS cert generation atomic

Instead of concatenating text into the file in its final location and
then setting its permissions, prepare the file (content and
permissions) in a staging area and then use an atomic move operation
to make it appear in its final location.

Also some other improvements to reliability and safety.

Signed-off-by: Thomas Sanders <c547603d2dd860735c4f0c043b1348f5c48c02f8@citrix.com>

srowe/xen-api,srowe/xen-api,srowe/xen-api,srowe/xen-api,srowe/xen-api