Improve the ssl handling: storage and check based on certificate chain