dataset/seed/postfix-relay/funcs/opendkim.py

32 lines
1 KiB
Python
Raw Normal View History

2022-03-08 19:42:28 +01:00
import dkim.dknewkey as _dknewkey
2022-10-17 18:28:22 +02:00
from os.path import join as _join, isfile as _isfile, isdir as _isdir
from os import makedirs as _makedirs, environ as _environ
2022-03-08 19:42:28 +01:00
from shutil import rmtree as _rmtree
import __main__
def _eprint(*args, **kwargs):
pass
_dknewkey.eprint = _eprint
2022-10-17 18:28:22 +02:00
_HERE = _environ['PWD']
2022-03-15 12:12:56 +01:00
_DKIM_DIR = _join(_HERE, 'pki/dkim')
2022-03-08 19:42:28 +01:00
def get_dkim_key(domain_name_eth0, domain):
2022-03-15 12:12:56 +01:00
dkim_dir = _join(_DKIM_DIR, domain_name_eth0, domain)
2022-03-15 22:25:05 +01:00
# dkim_file_src = _join(dkim_dir, f'{domain}')
2022-03-08 19:42:28 +01:00
dkim_file_key = _join(dkim_dir, f'{domain}.key')
dkim_file = _join(dkim_dir, f'{domain}.dns')
if not _isfile(dkim_file):
if _isdir(dkim_dir):
_rmtree(dkim_dir)
_makedirs(dkim_dir)
2022-03-15 22:25:05 +01:00
priv_key = _dknewkey.GenRSAKeys(dkim_file_key)
_dknewkey.ExtractRSADnsPublicKey(dkim_file_key, dkim_file)
# priv_key = _dknewkey.GenEd25519Keys(dkim_file_key)
# _dknewkey.ExtractEd25519PublicKey(dkim_file_src, priv_key)
2022-03-08 19:42:28 +01:00
with open(dkim_file_key, 'r') as fh:
return fh.read().strip()