Yes it is possible and legal. Usually, if the house is listed with an agency, this stipulation is disclosed in the listing ( IE: buyer to obtain CCO/ fire certification and make repairs necessary to obtain necessary certificates) . Even if it is not listed with an agency, the seller can require you to do the fixes and obtain the CCO.
Many towns give temporary CO's as well. This is common pratice in many cases, especially in New Brunswick, and a short sale transaction.
If the house is listed, and/or you are using an agent, check with them to verify the municipalities procedure and if they issue a temporary CO. If you are purchasing this on your own, then do your due diligence and contact the township directly to see if they issue a temporary CCO (since you may not want to do the fixes until you actually close on and own the property) and speak to an attorney in both scenarios.