Defining and Preventing Man-in-the-Middle Attacks