ssl: switch to using memory BIOs

This patch includes a backport of the upstream Memory BIO support.