envelope 2.2.1__tar.gz → 2.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {envelope-2.2.1 → envelope-2.3.0}/PKG-INFO +1 -1
- {envelope-2.2.1 → envelope-2.3.0}/envelope/envelope.py +28 -15
- {envelope-2.2.1 → envelope-2.3.0}/envelope/smtp_handler.py +5 -3
- {envelope-2.2.1 → envelope-2.3.0}/pyproject.toml +1 -1
- {envelope-2.2.1 → envelope-2.3.0}/LICENSE +0 -0
- {envelope-2.2.1 → envelope-2.3.0}/README.md +0 -0
- {envelope-2.2.1 → envelope-2.3.0}/envelope/__init__.py +0 -0
- {envelope-2.2.1 → envelope-2.3.0}/envelope/__main__.py +0 -0
- {envelope-2.2.1 → envelope-2.3.0}/envelope/_auth.py +0 -0
- {envelope-2.2.1 → envelope-2.3.0}/envelope/address.py +0 -0
- {envelope-2.2.1 → envelope-2.3.0}/envelope/attachment.py +0 -0
- {envelope-2.2.1 → envelope-2.3.0}/envelope/constants.py +0 -0
- {envelope-2.2.1 → envelope-2.3.0}/envelope/message.py +0 -0
- {envelope-2.2.1 → envelope-2.3.0}/envelope/parser.py +0 -0
- {envelope-2.2.1 → envelope-2.3.0}/envelope/utils.py +0 -0
|
@@ -1275,29 +1275,32 @@ class Envelope:
|
|
|
1275
1275
|
def _import_cryptoraphy_modules(self):
|
|
1276
1276
|
try:
|
|
1277
1277
|
from cryptography.hazmat.primitives.serialization import load_pem_private_key, pkcs7
|
|
1278
|
-
from cryptography.x509 import load_pem_x509_certificate
|
|
1278
|
+
from cryptography.x509 import load_pem_x509_certificates, load_pem_x509_certificate
|
|
1279
1279
|
from cryptography.hazmat.primitives import hashes, serialization
|
|
1280
|
-
return load_pem_private_key, pkcs7, load_pem_x509_certificate, hashes, serialization
|
|
1280
|
+
return load_pem_private_key, pkcs7, load_pem_x509_certificates, load_pem_x509_certificate, hashes, serialization
|
|
1281
1281
|
except ImportError:
|
|
1282
1282
|
raise ImportError(smime_import_error)
|
|
1283
1283
|
|
|
1284
1284
|
def smime_sign_only(self, email, sign):
|
|
1285
|
-
load_pem_private_key, pkcs7,
|
|
1285
|
+
load_pem_private_key, pkcs7, load_pem_x509_certificates, _, hashes, serialization = self._import_cryptoraphy_modules()
|
|
1286
1286
|
# get sender's cert
|
|
1287
1287
|
# cert and private key can be one file
|
|
1288
1288
|
|
|
1289
1289
|
# if certfile is not provided, sign has to have both private key and certificate
|
|
1290
1290
|
# cert is not in sign (--sign_path file), it is cert.pem
|
|
1291
1291
|
if self._cert:
|
|
1292
|
-
|
|
1292
|
+
certs = self._cert
|
|
1293
1293
|
else:
|
|
1294
1294
|
# certificate is in sign (--sign_path file), it is key-cert-together.pem
|
|
1295
|
-
|
|
1295
|
+
certs = sign
|
|
1296
1296
|
|
|
1297
1297
|
try:
|
|
1298
|
-
|
|
1298
|
+
certs = load_pem_x509_certificates(certs)
|
|
1299
1299
|
except ValueError as e:
|
|
1300
1300
|
raise ValueError(f"Certificate not found: {e}")
|
|
1301
|
+
# no certificate found
|
|
1302
|
+
if len(certs) == 0:
|
|
1303
|
+
raise ValueError("Certificate not found")
|
|
1301
1304
|
|
|
1302
1305
|
# get senders private key for signing
|
|
1303
1306
|
try:
|
|
@@ -1312,29 +1315,36 @@ class Envelope:
|
|
|
1312
1315
|
|
|
1313
1316
|
options = [pkcs7.PKCS7Options.DetachedSignature]
|
|
1314
1317
|
|
|
1315
|
-
|
|
1318
|
+
signature_builder = pkcs7.PKCS7SignatureBuilder().set_data(
|
|
1316
1319
|
email
|
|
1317
1320
|
).add_signer(
|
|
1318
|
-
|
|
1319
|
-
)
|
|
1321
|
+
certs[0], key, hashes.SHA256()
|
|
1322
|
+
)
|
|
1323
|
+
# add the whole certificate chain
|
|
1324
|
+
for cert in certs[1:]:
|
|
1325
|
+
signature_builder = signature_builder.add_certificate(cert)
|
|
1326
|
+
|
|
1327
|
+
signed_email = signature_builder.sign(
|
|
1320
1328
|
serialization.Encoding.SMIME, options
|
|
1321
1329
|
)
|
|
1322
1330
|
|
|
1323
1331
|
return signed_email
|
|
1324
1332
|
|
|
1325
1333
|
def smime_sign_encrypt(self, email, sign, encrypt):
|
|
1326
|
-
load_pem_private_key, pkcs7, load_pem_x509_certificate, hashes, serialization = self._import_cryptoraphy_modules()
|
|
1334
|
+
load_pem_private_key, pkcs7, load_pem_x509_certificates, load_pem_x509_certificate, hashes, serialization = self._import_cryptoraphy_modules()
|
|
1327
1335
|
|
|
1328
1336
|
if self._cert:
|
|
1329
|
-
|
|
1337
|
+
sender_certs = self._cert
|
|
1330
1338
|
else:
|
|
1331
1339
|
# certificate is in sign (--sign_path file), it is key-cert-together.pem
|
|
1332
|
-
|
|
1340
|
+
sender_certs = sign
|
|
1333
1341
|
|
|
1334
1342
|
try:
|
|
1335
|
-
|
|
1343
|
+
sender_certs = load_pem_x509_certificates(sender_certs)
|
|
1336
1344
|
except ValueError as e:
|
|
1337
1345
|
logger.warning(f"Certificate not found: {e}")
|
|
1346
|
+
if len(sender_certs) == 0:
|
|
1347
|
+
raise ValueError("Certificate not found")
|
|
1338
1348
|
|
|
1339
1349
|
# get senders private key for signing
|
|
1340
1350
|
try:
|
|
@@ -1348,7 +1358,10 @@ class Envelope:
|
|
|
1348
1358
|
|
|
1349
1359
|
# sign the message first
|
|
1350
1360
|
signature_builder = pkcs7.PKCS7SignatureBuilder().set_data(email)
|
|
1351
|
-
signature_builder = signature_builder.add_signer(
|
|
1361
|
+
signature_builder = signature_builder.add_signer(sender_certs[0], sender_key, hash_algorithm=hashes.SHA256())
|
|
1362
|
+
# add the whole certificate chain
|
|
1363
|
+
for cert in sender_certs[1:]:
|
|
1364
|
+
signature_builder = signature_builder.add_certificate(cert)
|
|
1352
1365
|
signed_email = signature_builder.sign(serialization.Encoding.SMIME, [pkcs7.PKCS7Options.DetachedSignature])
|
|
1353
1366
|
|
|
1354
1367
|
# get recipent's certificate for encryption
|
|
@@ -1385,7 +1398,7 @@ class Envelope:
|
|
|
1385
1398
|
|
|
1386
1399
|
def smime_encrypt_only(self, email, encrypt):
|
|
1387
1400
|
|
|
1388
|
-
_, pkcs7, load_pem_x509_certificate, _, serialization = self._import_cryptoraphy_modules()
|
|
1401
|
+
_, pkcs7, _, load_pem_x509_certificate, _, serialization = self._import_cryptoraphy_modules()
|
|
1389
1402
|
|
|
1390
1403
|
if self._cert:
|
|
1391
1404
|
certificates = [self._cert]
|
|
@@ -33,6 +33,8 @@ class SMTPHandler:
|
|
|
33
33
|
d = locals()
|
|
34
34
|
del d["self"]
|
|
35
35
|
self.key = repr(d)
|
|
36
|
+
d["password"] = "********"
|
|
37
|
+
self.obfuscated_key = repr(d)
|
|
36
38
|
|
|
37
39
|
def connect(self):
|
|
38
40
|
if self.instance: # we received this instance as is so we suppose it is already connected
|
|
@@ -55,13 +57,13 @@ class SMTPHandler:
|
|
|
55
57
|
smtp.login(self.user, self.password)
|
|
56
58
|
except SMTPAuthenticationError as e:
|
|
57
59
|
logger.error(
|
|
58
|
-
f"SMTP authentication failed: {self.
|
|
60
|
+
f"SMTP authentication failed: {self.obfuscated_key}.\n{e}")
|
|
59
61
|
return False
|
|
60
62
|
except SMTPException as e:
|
|
61
|
-
logger.error(f"SMTP connection failed: {self.
|
|
63
|
+
logger.error(f"SMTP connection failed: {self.obfuscated_key}.\n{e}")
|
|
62
64
|
return False
|
|
63
65
|
except (gaierror, ConnectionError):
|
|
64
|
-
logger.error(f"SMTP connection refused: {self.
|
|
66
|
+
logger.error(f"SMTP connection refused: {self.obfuscated_key}.")
|
|
65
67
|
return False
|
|
66
68
|
return smtp
|
|
67
69
|
|
|
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
|
|
|
4
4
|
|
|
5
5
|
[tool.poetry]
|
|
6
6
|
name = "envelope"
|
|
7
|
-
version = "2.
|
|
7
|
+
version = "2.3.0"
|
|
8
8
|
description = "Insert a message and attachments and send e-mail / sign / encrypt contents by a single line."
|
|
9
9
|
authors = ["Edvard Rejthar <edvard.rejthar@nic.cz>"]
|
|
10
10
|
license = "LGPL-3.0-or-later"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|