Fixed thread safety in certificate check (fixed #670)