When running with ruby 2.4 or 2.5, ruby will raise a certname mismatch error before we have a chance to handle it, and print a meaningful message.
This is a backport of the changes made in 6.4.x in PUP-8213
Merged #7490 into 5.5.x at dfcdfe6.
Merged #7491 into 6.0.x at f4d22a7.