Implémentation #2

Open
opened 2024-06-18 15:22:00 +02:00 by faraphel · 1 comment
Contributor

L'implémentation pourrait se faire dans le language Python à l'aide du module cryptography, offrant accès à tous un ensemble de modules et de fonctions concernant la cryptographie, en particulier le module X.509 (https://cryptography.io/en/latest/x509/) permettant de créer un système de certificat sans passer par bash.

L'implémentation pourrait se faire dans le language Python à l'aide du module `cryptography`, offrant accès à tous un ensemble de modules et de fonctions concernant la cryptographie, en particulier le module `X.509` (https://cryptography.io/en/latest/x509/) permettant de créer un système de certificat sans passer par bash.
faraphel added this to the PCA-Project project 2024-06-18 15:22:00 +02:00
Author
Contributor

Voici un simple snippet permettant de générer des certificats en python à l'aide de cette librairie :

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

Des extensions additionnels peuvent être ajoutées dans le certificat pour stocker des informations supplémentaires.

Voici un simple snippet permettant de générer des certificats en python à l'aide de cette librairie : ```py 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()) ``` Des extensions additionnels peuvent être ajoutées dans le certificat pour stocker des informations supplémentaires.
faraphel added a new dependency 2024-06-26 21:21:46 +02:00
faraphel added a new dependency 2024-06-26 21:21:51 +02:00
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Depends on
#3 Implémentation Carte
study-faraphel/M1-PCA-Project
#4 Implémentation Machine
study-faraphel/M1-PCA-Project
Reference: study-faraphel/M1-PCA-Project#2
No description provided.