It's already been done: https://git.daplie.com/Daplie/localhost.daplie.me-certificat...
Which I find to be a very practical solution for connecting to localhost over https, it frees you from having to install a self-signed certificates/CAs on your machine.