An officer may ask you at any time if they can search you or any of your other property including vehicles but they key is that you have the right to say no. Even if you do grant an officer permission to search you have the right to the officer where he or she may search and you can revoke that consent at any time during the search.
According to the infamous case of Arizona v. Gant, an officer is permitted to ONLY search what is in the “immediate grabbable area” when you are stopped for an infraction. Thusly, they are permitted to search what is underneath your seat, in your purse, glove compartment, and back seat, but that is it. They cannot search your trunk without a warrant, or an applicable exception. This is now a federal law, and is interconnected to the Fourth Amendement’s ” Search and Seizure” requirments.
One of those most common exceptions is when the driver of the vehicle gives the officer consent.
If an officer wants to search your vehicle, generally he or she will make various statements to you to try to get your consent. Commonly he or she may try to make it a general request by something like “I have a certain amount of vehicle I have to search every month and I don’t think you are a criminal or anything, would you mind if I have a quick look?” Another common question would be something along the lines of “You don’t have any dead bodies, machine guns, bombs, or anything like that in your car do you?” Most people of course do not, so the tactic is that listing items such as these the driver will believe that is what the officer is searching for and will give consent.
No matter what an officer tries to tell you to get consent to search always say no. If an officer has probable cause to search the officer will not ask you for permission but rather will tell you that he has probable cause to search or has a warrant and will do so. Of course in this case you must let the officer search. If the officer is asking your permission to search then you have every right to say no.