Package pysmime :: Module file
[hide private]
[frames] | no frames]

Module file

source code

Functions to verify, sign, encrypt and decrypt SMIME files, build on top of pysmime/core.

Functions [hide private]
M2Crypto.SMIME.PKCS7
file_encrypt(input_file_path, recipient_cert, output_file_path=None, keyring_source='file', cypher='des_ede3_cbc')
Encrypts the input file data with public key of input certificate.
source code
str
file_decrypt(input_file_path, recipient_private_key, recipient_cert, output_file_path=None, keyring_source='file', type='DER')
Decrypts the input file data with input private key and input certificate.
source code
M2Crypto.SMIME.PKCS7
file_sign(input_file_path, sender_private_key, sender_cert, output_file_path=None, keyring_source='file', type='DER')
Signs the input file data with input private key and input certificate.
source code
list
file_verify(input_file_path, certstore_path, AUTO_SIGNED_CERT=False, type='DER')
Verifies the input file data against the certificates stored in file at certstore path.
source code
Function Details [hide private]

file_encrypt(input_file_path, recipient_cert, output_file_path=None, keyring_source='file', cypher='des_ede3_cbc')

source code 

Encrypts the input file data with public key of input certificate. If an output file path is present, the encrypted data is also written to that file.

Parameters:
  • input_file_path (filepath) - the filepath from where retrieve the data to encrypt
  • recipient_cert (filepath or M2Crypto.BIO or M2Crypto.X509.X509) - the recipient certificate reference from filepath, could be from file, from memory or from pkcs11 smartcard, based on keyring_source input parameter.
  • output_file_path (filepath) - if present, the filepath where to write the encrypted data.
  • keyring_source (str) - the type of the source for input certificate, used to recall the appropriate method for encrypter settings. Ammitted values are: file, memory, pkcs11.
  • cypher (str) - the cypher to use for encryption of the data, run "openssl enc -help" for supported cyphers, you have to choose a public key cypher from availables.
Returns: M2Crypto.SMIME.PKCS7
the PKCS#7 encrypted data in DER format.

file_decrypt(input_file_path, recipient_private_key, recipient_cert, output_file_path=None, keyring_source='file', type='DER')

source code 

Decrypts the input file data with input private key and input certificate. If an output file path is present, the decrypted data is also written to that file.

Parameters:
  • input_file_path (filepath) - the filepath from where retrieve the data to decrypt
  • recipient_private_key (filepath or M2Crypto.BIO or M2Crypto.EVP.PKey) - recipient private key reference, could be from file, from memory or from pkcs11 smartcard, based on keyring_source input parameter.
  • recipient_cert (filepath or M2Crypto.BIO or M2Crypto.X509.X509) - recipient certificate, could be from filepath, from memory or from pkcs11 smartcard, based on keyring_source input parameter.
  • output_file_path (filepath) - if present, the filepath where to write the decrypted data.
  • keyring_source (str) - the type of the source for input certificate, used to recall the appropriate method for decrypter settings. Ammitted values are: file, memory, pkcs11.
  • type (str) - specifies the type of input PKCS#7 data: PEM or DER
Returns: str
the decrypted data in plain form.

file_sign(input_file_path, sender_private_key, sender_cert, output_file_path=None, keyring_source='file', type='DER')

source code 

Signs the input file data with input private key and input certificate. If an output file path is present, the signed data is also written to that file.

Parameters:
  • input_file_path (filepath) - the filepath from where retrieve the data to sign.
  • sender_private_key (filepath or M2Crypto.BIO or M2Crypto.EVP.PKey) - recipient private key reference, could be from file, from memory or from pkcs11 smartcard, based on keyring_source input parameter.
  • sender_cert (filepath or M2Crypto.BIO or M2Crypto.X509.X509) - recipient certificate, could be from filepath, from memory or from pkcs11 smartcard, based on keyring_source input parameter.
  • output_file_path (filepath) - if present, the filepath where to write the signed data.
  • keyring_source (str) - the type of the source for input certificate, used to recall the appropriate method for decrypter settings. Ammitted values are: file, memory, pkcs11.
  • type (str) - specifies the type of output PKCS#7 data: PEM or DER
Returns: M2Crypto.SMIME.PKCS7
the PKCS#7 signed data in DER format.

file_verify(input_file_path, certstore_path, AUTO_SIGNED_CERT=False, type='DER')

source code 

Verifies the input file data against the certificates stored in file at certstore path.

Parameters:
  • input_file_path (filepath) - the filepath from where retrieve the data to verify.
  • certstore_path (filepath) - path to the file of the trusted certificates, for example /etc/ssl/certs/ca-certificats.crt.
  • AUTO_SIGNED_CERT (boolean) - to accept or not auto signed certificates as valid for verification.
  • type (str) - specifies the type of input PKCS#7 data: PEM or DER
Returns: list
list of the certificate of the signer verified.