Authentication and integrity I was trying to solve this problem:

Sometimes Alice needs to send a file to Bob, guaranteeing her identity and the file integrity (no confidentiality
required); the two parties are sharing a secret w and make use of a hash function $H$ that outputs 40-bit numbers and a symmetric encryption $E$.
Each time they use the following (pre-agreed) protocol.

A → B: $E_w(nA)$, where $nA$ is a nonce (Alice sends a challenge).

B → A: $E_w(nA+1)$ (Bob proves he knows the secret, providing response to challenge).

A → B: $(F, H(F),E_w(H(F)))$ (Bob, given $F$, computes $H(F)$ and $E_w(H(F))$, and then compare his results to data
actually received)

**1.Show how an attacker can act in place of Alice and send a file to Bob tricking him into
believing that the file is coming from Alice.

2.Fix the protocol without significantly perturbing it too.**

*My answer to 1:
The attacker can do Man in the middle attack.
Suppose Trudy impersonates Bob's network address.
1.Alice sends w{nA} to Trudy.
2.Trudy sends w{nA} to Bob.
3.Now Bob will send w{nA+1} to Trudy, which she will use it to send it to Alice.
4.After Trudy sends w{nA+1},
Alice will send (F, H(F),w{H(F)}) to Trudy, thinking she is Bob because she proved her that she is Bob.

Scheme:


A → T: $E_w(nA)$
T → B: $E_w(nA)$
B → T: $E_w(nA+1)$
T → A: $E_w(nA+1)$
A → T: $(F, H(F),E_w(H(F)))$


Is my answer to question 1 correct?
How do I solve the 2nd question?

Best Regards.
Q1 asks “Show how an attacker can act in place of Alice and send a file to Bob tricking him into believing that the file is coming from Alice.”

In your answer, Trudy simply relays the traffic to the two parties without doing anything else, thus this is not really an attack that achieves what is asked. Note that whatever Bob receives is truly coming from Alice in this session.

Hint for Q2: the problem in the protocol is that Bob cannot verify that the last message is fresh, and it can come from a previous session intercepted by Trudy (replay attack).