Gradle Task to Check Cert Validity

Hello all looked around but have not really seen anyone else doing this.

Background: We have now been bit a couple times by expiring certs for things like Apple Notification Service certs in our builds. (Yeah I know it should be easy but it keeps happening).

I was hoping to make a gradle task that could check the validity of the date in the cert bundle (p12) we have and fail the build or deploy task we have if the cert is going to expire say in 30 days and log it so it makes sure and gets people’s attention.

Has anyone done this or have an idea how to do it? thanks in advance