Let's examine the possible cases. If you are both truthful, the correct answer to “are you both liars?” It's no.
A would say no. B says “He said no,” which is true.
This case fits. If A is truthful and B is a liar, A would say no.
So B, by saying “He said no,” would be telling the truth, which cannot happen if he is a liar. If A is a liar and B is truthful, the correct answer is still no, so A, by lying, would have to say yes.
But then B could not truthfully say “He said no.” If you are both liars, the correct answer to “are you both liars?” it would be yes. A, by lying, would say no.
But then B, by saying “He said no,” would be telling the truth. There is only one possibility: A and B are truthful.