TLS/SSL setup code for #103

This probably needs more work to integrate well: it's a slightly cleaned-up version of a project-specific implementation. The entry point is `setup_tls`, which could be called from `bootstrap` if desired.