The only way to determine whether the issue is with the camera or the lens is to use another EOS lens, preferably another EF 40mm f/2.8 STM or more generally any STM lens, with your camera and/or use your lens with another Canon EOS camera.
My guess, however, is that this is most likely a problem with the lens. Dry it out for several days and see if the issue continues.
Also check to be sure the lens is properly mounted and turned all the way until the lens release 'clicks'. You should not be able to rotate the lens more than a millimeter or two in either direction without pressing the lens release button. If you can rotate the lens more than that when the lens release mechanism is "locked", you need to have that repaired. It is highly unlikely this is causing the odd behavior you describe unless one of the camera's or lens' contacts has become misaligned or there is something physically shorting them out, because the way the lens/camera connection is designed the power contacts are the first to lose connection and none of the lens' other contacts pass over the power leads on the camera as the lens is rotated off the camera.
Just to be on the safe side: When half-pressing the shutter (thus starting autofocus), your camera/lens does not focus, but the aperture closes? Did I get that right? – flolilolilo
Yup, the aperture closes. – gloriousCatnip
One thing you might want to try is to reassign the 'Depth of Field Preview' button to another function and see if the lens still occasionally physically stops down the aperture on a shutter half-press. It might be that the 'DoF Preview' button is malfunctioning and causing the aperture iris to stop down on a half press. If that is the case, then the issue is definitely with the camera. Or it may be that you are accidentally pressing the 'DoF Preview' button by the way you are holding the camera.
Going forward
The next time you are shooting in wet conditions, unless you are using weather resistant pro-grade bodies and lenses, use a rain cover on your camera and lens.
If your camera does get wet again and starts to act 'crazy', turn it off and remove the battery immediately. Most damage to microelectronics is done by the power shorting across gaps using the impurities in the water. Wait until the camera is completely dry inside and out to place the battery back in the camera.