It can be done.
Many moons ago, I went through Infantry Officer Phase 3 Training with a 40+ year old fellow candidate. The rest of us were 21-25 ish. Although the 40+ year old got hurt in the final days, he managed to get through training and was the top candidate on the course. He went on to complete Phase 4 no problem.
Going further back in time, to a previous life when I was an NCM /instructor, I remember a 40-ish recruit who successfully completed training and he was one of the better ones. On the other hand, I also recall an unusual situation where two recruits were a mom and son. She must have been around 40. They were placed in the same platoon. It did not end well. After a few weeks of Basic Military Training, they both quit.
Post BMT, you are going into the intelligence trade so your related training/work is going to have a significant emphasis on performing staff work: analyses, reports, preparing/delivering briefings, etc. The physical toll on your 40yr old body should not be onerous.
My personal observation is that intelligence operators often tend to be “older”. I think the reason for this is that many of them start their careers in other trades and later ”re-muster/ reclassify” to Intelligence. You may find yourself on course with a few “older” people like this, which may help you feel more comfortable with age gap issues.
As always, common experiences as you progress through training (and beyond) will help you to build a peer group with the younger set.
Note that the CAF has adjusted its Compulsory Retirement Age over the years. It went from 55 to 60, roughly ten years ago, and some are now speculating that it may go to 65 in the future. You could have 20-25 years ahead of you, provided that you remain fit.
Good Luck meeting your career goals in the CAF.