Backported fix for #1273 (protocol downgrade attack)