The Iranian leadership was struggling with a major legitimacy crisis when Trump came to its rescue.