Problem: issue #1273, protocol downgrade attack

Solution: backport fix from libzmq master. Also backported test
cases.