commit 7679a6c84270a0b4c47de051a182e1894237df73 Author: Faraphel Date: Wed Jun 26 20:39:09 2024 +0200 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9672ada --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +# IDE +.idea/ +!.idea/runConfigurations/ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..0d38bc5 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +cryptography diff --git a/source/__init__.py b/source/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/source/__main__.py b/source/__main__.py new file mode 100644 index 0000000..7fa7189 --- /dev/null +++ b/source/__main__.py @@ -0,0 +1,26 @@ +from datetime import datetime, timedelta + +from cryptography import x509 +from cryptography.hazmat.primitives import hashes +from cryptography.hazmat.primitives.asymmetric import rsa + +# generate a private key for the certificate +private_key = rsa.generate_private_key(public_exponent=65537, key_size=2048) +# get the public key from it +public_key = private_key.public_key() + +# create a builder for the certificate +builder = x509.CertificateBuilder( + issuer_name=x509.Name([x509.NameAttribute(x509.oid.NameOID.COMMON_NAME, "vote.gouv.fr")]), + subject_name=x509.Name([x509.NameAttribute(x509.oid.NameOID.COMMON_NAME, "vote.gouv.fr")]), + serial_number=x509.random_serial_number(), + public_key=public_key, + not_valid_before=datetime.now(), + not_valid_after=datetime.now() + timedelta(weeks=1), +) + +# create the certificate by signing it +certificate = builder.sign(private_key, algorithm=hashes.SHA256()) + + +print(certificate)