Although Hosseini never directly writes that Ali knows about Hassan's true parentage, he implies that Ali most likely would have known. When Rahim Khan tells Amir the truth about Baba and Sanuabar's affair, he also tells Amir that Ali had been married before Sanuabar but that his first wife had left him for another man. While Ali's first wife had no children with him, she went on to have children with the other man. Ali is not stupid and most likely would have known that he was sterile and that Hassan could not have been his.
While this example does not necessarily mean that Ali would have known Baba was Hassan's father, Hosseini does give an example earlier in the book which implies that Ali knows Baba's secret. After a young Amir frames Hassan by hiding his new watch and money in Hassan's hut, Ali decides that he will not allow Hassan to endure any more cruelty. He tells Baba that he and Hassan can no longer live there, and Baba is devastated. When Baba begs Ali to stay, Ali adamantly refuses, and it is clear from the scene that Baba doesn't dare push him any further--Ali looks at Baba as if to remind him that Baba had already hurt him and Hassan enough. The only thing that would have caused this look is Ali's knowledge of Baba's betrayal with Sanuabar.
Chapter 18 gives readers further insight into the issue. After Amir leaves Rahim Khan's apartment, he angrily processes the information he's just learned and reflects on his past life from a different perspective:
The questions kept coming at me: How had Baba brought himself to look Ali in the eye? How had Ali lived in that house, day in and day out, knowing he had been dishonored by his master in the single worst way an Afghan man can be dishonored?
Though Rahim Khan does not directly tell Amir that Ali knew Hassan wasn't his son, this passage shows that, in retrospect, Amir believes that Ali must have known. While Amir is completely shocked by the news that Hassan was his brother, he is able to see, in retrospect, that many signs pointed that way his entire childhood. (In Chapter 18, Amir recalls Baba's insistence that he'd never get new servants, his quest to have Hassan's harelip fixed, and the way in which Baba "had wept, wept, when Ali announced he and Hassan were leaving us.")