Can I ask an undercover cop if he is a cop?

Yes.

 

You can ask, but he doesn’t have to tell you the truth.