def _pyopenssl_cert_or_req_san(cert_or_req):
 part_separator = ':'
 parts_separator = ', '
 prefix = ('DNS' + part_separator)
 if isinstance(cert_or_req, OpenSSL.crypto.X509):
  func = OpenSSL.crypto.dump_certificate
 else:
  func = OpenSSL.crypto.dump_certificate_request
 text = func(OpenSSL.crypto.FILETYPE_TEXT, cert_or_req).decode('utf-8')
 match = re.search('X509v3 Subject Alternative Name:\\s*(.*)', text)
 sans_parts = ([] if (match is None) else match.group(1).split(parts_separator))
 return [part.split(part_separator)[1] for part in sans_parts if part.startswith(prefix)]

def _pyopenssl_cert_or_req_san ( cert_or_req ) : part_separator = ':' parts_separator = ', ' prefix = ( 'DNS' + part_separator ) if isinstance ( cert_or_req , OpenSSL . crypto . X509 ) : func = OpenSSL . crypto . dump_certificate else : func = OpenSSL . crypto . dump_certificate_request text = func ( OpenSSL . crypto . FILETYPE_TEXT , cert_or_req ) . decode ( 'utf-8' ) match = re . search ( 'X509v3 Subject Alternative Name:\\s*(.*)' , text ) sans_parts = ( [ ] if ( match is None ) else match . group ( 1 ) . split ( parts_separator ) ) return [ part . split ( part_separator ) [ 1 ] for part in sans_parts if part . startswith ( prefix ) ]
get subject alternative names from certificate or csr using pyopenssl .