Sockets secure implementations

Rebased on `master`.