Fix CN name error and add certificate caching