paramiko/paramiko — pull request #351 by Kami (2014-07-02 18:41:06+00:00)
Title: [BUG FIX] Fix an issue with propagating invalid exception when using RSA key but authentication failure occurs

## Problem description

Currently if you use a valid RSA key, but authentication failure occurs, paramiko will propagate an invalid `not a valid DSA private key file` exception. The exception which should be propagated is `Authentication failed`.

The reason why this occurs is because paramiko tries to load / parse private key in the following order:

1. RSA
2. DSA

If parsing of the key as RSA succeeds, but authentication failure occurs, paramiko won't stop, but it will also try to parse the same key which is already to be determined to be an RSA key as DSA. Obviously, parsing RSA key as DSA won't work, so `not a valid DSA private key file` exception will be stored in `saved_exception` and propagated to the end user later in the code.

Note: I discovered this bug while debugging some Libcloud deployment issues. Sadly a work-around for us (and others) until this has been merged into master is to catch `Invalid DSS key exception` exception and treat it in the same way as authentication failure which is far from ideal.