Sockets secure implementations

Rebased on `master`.
Indenting is weird here. Should only ever need to out-dent by 2 spaces.