initial commit

This commit is contained in:
Faraphel 2024-06-26 20:39:09 +02:00
commit 7679a6c842
4 changed files with 30 additions and 0 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
# IDE
.idea/
!.idea/runConfigurations/

1
requirements.txt Normal file
View file

@ -0,0 +1 @@
cryptography

0
source/__init__.py Normal file
View file

26
source/__main__.py Normal file
View file

@ -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)