Indeed, someone does need to brush up on criminal law, and that person is you. I'd start with section 25.1 of the Criminal Code, which allows police to do things that would otherwise be considered an offence. It is not a blanket authorization to break the law, and is subject to oversight, but it does exist.Somebody needs to brush-up on criminal laws. Nobody can legally do any criminal acts. A cop can not commit a crime, even if he is undercover. This is a way gangs use to bust cop infiltration, they ask the suspected cop to commit a crime. At times the cop's organization will arrange a fake crime to coverup or the cop will have to retreat. If the cop have to do something illegal because he is in immediate danger, the case will be closely analyzed after and it is likely he will be removed from the case or it could jeopardize the entire operation in front of the judge if he is left there.
I know a few female officers who used to do infiltration to bust stripclub and MP prostitution and they were not even allowed to take their cloths off because it was considered immoral, even less allowed to fuck a customer in the back room because that was illegal.
What LE often do is to use informants. Morality is no longer an issue with an informant. The cop can not tell the informant to commit a crime but can not control what the informant do. If the informant commit a crime, depending how serious the crime is the cop will arrange to get him immunity in exchange of collaboration. If the defendant can prove the crime was requested by the cop the informant's testimonial will get dropped.