Created
January 7, 2019 19:01
-
-
Save HanSooloo/1b34417b17d65400fc87ce5c9faef784 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from cryptography import x509 | |
from cryptography.hazmat.backends import default_backend | |
from cryptography.hazmat.primitives import hashes | |
from cryptography.hazmat.primitives.asymmetric import rsa | |
from cryptography.x509.oid import NameOID | |
import datetime | |
one_day = datetime.timedelta(1, 0, 0) | |
private_key = rsa.generate_private_key( | |
public_exponent=65537, | |
key_size=2048, | |
backend=default_backend() | |
) | |
public_key = private_key.public_key() | |
builder = x509.CertificateBuilder() | |
builder = builder.subject_name(x509.Name([ | |
x509.NameAttribute(NameOID.COMMON_NAME, u'istanbulnet.io'), | |
])) | |
builder = builder.issuer_name(x509.Name([ | |
x509.NameAttribute(NameOID.COMMON_NAME, u'istanbulnet.io'), | |
])) | |
builder = builder.not_valid_before(datetime.datetime.today() - one_day) | |
builder = builder.not_valid_after(datetime.datetime.today() + (one_day * 30)) | |
builder = builder.serial_number(x509.random_serial_number()) | |
builder = builder.public_key(public_key) | |
builder = builder.add_extension( | |
x509.SubjectAlternativeName( | |
[x509.DNSName(u'istanbulnet.io')] | |
), | |
critical=False | |
) | |
builder = builder.add_extension( | |
x509.BasicConstraints(ca=False, path_length=None), critical=True, | |
) | |
builder = builder.add_extension( | |
x509.AuthorityInformationAccess([ | |
x509.AccessDescription(x509.AuthorityInformationAccessOID.CA_ISSUERS, | |
x509.DirectoryName('ldap:///blah')) | |
]) | |
) | |
certificate = builder.sign( | |
private_key=private_key, algorithm=hashes.SHA256(), | |
backend=default_backend() | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment