import certtool
cert = certtool.generate_private_key(bits=1024, type=certtool.RSA_KEY)
out = cert.export(format=certtool.FMT_PEM)
print out
open("privatekey.pem", "wb").write(out)
import certtool
t = certtool.Template()
t.organization = "teste2"
t.common_name = "teste"
t.expiration_days = 900
t.country = "br"
t.email = "template@teste.teste"
t.locality = "locality"
t.state = "state or province"
t.unit = "unit"