mirror of https://github.com/MISP/mail_to_misp
new: Add support for starttls
parent
48f3f9eea0
commit
942bffd93a
22
fake_smtp.py
22
fake_smtp.py
|
@ -1,9 +1,21 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
import ssl
|
||||
from pathlib import Path
|
||||
import importlib
|
||||
from subprocess import run, PIPE
|
||||
import aiosmtpd.controller
|
||||
from aiosmtpd.controller import Controller
|
||||
from aiosmtpd.smtp import SMTP
|
||||
import subprocess
|
||||
|
||||
key_path = Path('certs', 'key.pem')
|
||||
cert_path = Path('certs', 'cert.pem')
|
||||
|
||||
|
||||
# Pass SSL context to aiosmtpd
|
||||
class ControllerStarttls(Controller):
|
||||
def factory(self):
|
||||
return SMTP(self.handler, require_starttls=False, tls_context=context)
|
||||
|
||||
|
||||
class CustomSMTPHandler:
|
||||
|
@ -29,10 +41,16 @@ if __name__ == '__main__':
|
|||
smtp_port = config.smtp_port
|
||||
binpath = config.binpath
|
||||
|
||||
if not cert_path.exists() and not key_path.exists():
|
||||
subprocess.call(f'openssl req -x509 -newkey rsa:4096 -keyout {key_path.as_posix()} -out {cert_path.as_posix()} -days 365 -nodes -subj "/CN=localhost"', shell=True)
|
||||
|
||||
context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
|
||||
context.load_cert_chain(cert_path.as_posix(), key_path.as_posix())
|
||||
|
||||
print("Starting Fake-SMTP-to-MISP server")
|
||||
|
||||
handler = CustomSMTPHandler()
|
||||
server = aiosmtpd.controller.Controller(handler, hostname=smtp_addr, port=smtp_port)
|
||||
server = ControllerStarttls(handler, hostname=smtp_addr, port=smtp_port)
|
||||
server.start()
|
||||
input("Server started. Press Return to quit.")
|
||||
server.stop()
|
||||
|
|
Loading…
Reference in New Issue