Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Python Linux
- # Chemin d'accès au fichier de certificat PFX et au mot de passe
- pfx_file_path = 'certificat.pfx' #certificat
- pfx_password = 'ma_cle' # key
- from cryptography.hazmat.primitives import serialization
- from requests import Session
- import cryptography.hazmat.primitives.serialization.pkcs12
- import tempfile #Generate temporary files and directories
- with open(pfx_file_path, "rb") as f:
- (
- private_key,
- certificate,
- additional_certificates,
- ) = serialization.pkcs12.load_key_and_certificates(
- f.read(), pfx_password.encode()
- )
- """
- La clé sera disponible dans un fichier temporaire lisible par l'utilisateur pendant
- l' exécution du programme (jusqu'à ce que la clé et le certificat soient gc'ed)
- """
- key = tempfile.NamedTemporaryFile()
- cert = tempfile.NamedTemporaryFile()
- key.write(
- private_key.private_bytes(
- encoding=serialization.Encoding.PEM,
- format=serialization.PrivateFormat.PKCS8,
- encryption_algorithm=serialization.NoEncryption(),
- )
- )
- key.flush()
- """ Ecrire certificat PEM Generate temporary files and directories """
- cert.write(
- certificate.public_bytes(serialization.Encoding.PEM),
- )
- cert.flush()
- session = Session() # ... requests.session()
- session.cert = (cert.name, key.name)
- print ("DEBUG session.cert ",session.cert, cert.name,key.name)
- input("Presiona Enter para continuar...")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement