def _get_certificate(cert_url):
global _cache<EOL>if cert_url in _cache:<EOL><INDENT>cert = _cache[cert_url]<EOL>if cert.has_expired():<EOL><INDENT>_cache = {}<EOL><DEDENT>else:<EOL><INDENT>return cert<EOL><DEDENT><DEDENT>url = urlparse(cert_url)<EOL>host = url.netloc.lower()<EOL>path = posixpath.normpath(url.path)<EOL>if url.scheme != '<STR_LIT>' orhost not in ['<STR_LIT>', '<STR_LIT>'] ornot path.startswith('<STR_LIT>'):<EOL><INDENT>log.error('<STR_LIT>', cert_url)<EOL>return<EOL><DEDENT>resp = urlopen(cert_url)<EOL>if resp.getcode() != <NUM_LIT:200>:<EOL><INDENT>log.error('<STR_LIT>')<EOL>return<EOL><DEDENT>cert = crypto.load_certificate(crypto.FILETYPE_PEM, resp.read())<EOL>if cert.has_expired() or cert.get_subject().CN != '<STR_LIT>':<EOL><INDENT>log.error('<STR_LIT>')<EOL>return<EOL><DEDENT>_cache[cert_url] = cert<EOL>return cert<EOL>
Download and validate a specified Amazon PEM file.