[backport] fixed encrypted socket communication, fixes #1897