def build_certificate(<EOL>common_names,<EOL>include_extension=True,<EOL>bad_extension=False<EOL>):
names = []<EOL>for common_name in common_names:<EOL><INDENT>names.append(<EOL>x509.NameAttribute(x509.oid.NameOID.COMMON_NAME, common_name)<EOL>)<EOL><DEDENT>name = x509.Name(names)<EOL>t = datetime.datetime.now()<EOL>delta = datetime.timedelta(days=<NUM_LIT:30>)<EOL>not_valid_before = t - delta<EOL>not_valid_after = t + delta<EOL>private_key = rsa.generate_private_key(<EOL>public_exponent=<NUM_LIT>,<EOL>key_size=<NUM_LIT>,<EOL>backend=default_backend()<EOL>)<EOL>builder = x509.CertificateBuilder().serial_number(<EOL><NUM_LIT:1><EOL>).issuer_name(<EOL>name<EOL>).subject_name(<EOL>name<EOL>).not_valid_before(<EOL>not_valid_before<EOL>).not_valid_after(<EOL>not_valid_after<EOL>).public_key(<EOL>private_key.public_key()<EOL>)extended_key_usage_values = []<EOL>if bad_extension:<EOL><INDENT>extended_key_usage_values.append(<EOL>x509.oid.ExtendedKeyUsageOID.SERVER_AUTH<EOL>)<EOL><DEDENT>else:<EOL><INDENT>extended_key_usage_values.append(<EOL>x509.oid.ExtendedKeyUsageOID.CLIENT_AUTH<EOL>)<EOL><DEDENT>if include_extension:<EOL><INDENT>builder = builder.add_extension(<EOL>x509.ExtendedKeyUsage(extended_key_usage_values),<EOL>True<EOL>)<EOL><DEDENT>return builder.sign(private_key, hashes.SHA256(), default_backend())<EOL>
Programmatically generate a self-signed certificate for testing purposes.

Args:
    common_names (list): A list of strings for the common names of the
        cert.
    include_extension (boolean): A flag enabling/disabling the inclusion
        of certificate extensions.
    bad_extension (boolean): A flag enabling/disabling the setting of
        invalid certificate extension values.

Returns:
    x509.Certificate: The newly generated certificate object.