The process involves two interested parties A (client) and B (server) and the attacker M. M is capable of intercepting all the communication between A and B (Man in the Middle) and even modify it. However A's private key has not been compromised.
Success of authentication process depends on A's capacity to sign an arbitrary packet sent by B with it's private key.
The authentication process proceeds as following:
A establishes TCP connection with B.
B calculates a nonce and associates it with the incoming connection from A.
B already has A's public key.
M connects with A.
B calculates a nonce and associates it with the incoming connection from M.
M initiates authentication process, B generates a new nonce based on the nonce generated in step 5 and some internal state and sends it to M.
M sits idle and waits for A to initiate the authentication process.
A initiates the authentication process, B generates a new nonce based on the nonce generated in step 2 and some internal state and sends it to A.
M intercepts the communication B -> A in step 8 and replaces the nonce with the one it received in step 6.
A signs the the packet and sends back to B.
M intercepts the packet A -> B of step 10, blocks it from going through and replays it as it's own.
B verifies the nonce and the signature and identifies M as A.
M masquerades as A.
What can be done to prevent M from becoming A in eyes of B?