Cache certificate chains, and support bitcoincore/gavinemail certs
Fix use-after-free bug, and better error handling