HTTPS support

Maybe this requires a more thorough review as it's security-related code? Perhaps one of @renelvon @charapod @lolosk @sophron would like to take a look when time permits.