backport from https://github.com/phus/backport_ssl