Sockets secure implementations

Rebased on `master`.
well this is a bit more concise than the java implementation... :+1: