Skip to content

Commit

Permalink
allow a custom dkim selector
Browse files Browse the repository at this point in the history
  • Loading branch information
bilogic committed Jan 5, 2024
1 parent 3b259ee commit b51550d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions management/dns_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def has_rec(qname, rtype, prefix=None):

# Append the DKIM TXT record to the zone as generated by OpenDKIM.
# Skip if the user has set a DKIM record already.
opendkim_record_file = os.path.join(env['STORAGE_ROOT'], 'mail/dkim/mail.txt')
opendkim_record_file = os.path.join(env['STORAGE_ROOT'], 'mail/dkim/' + env['DKIM_SELECTOR'] + '.txt')
with open(opendkim_record_file) as orf:
m = re.match(r'(\S+)\s+IN\s+TXT\s+\( ((?:"[^"]+"\s+)+)\)', orf.read(), re.S)
val = "".join(re.findall(r'"([^"]+)"', m.group(2)))
Expand Down Expand Up @@ -764,7 +764,7 @@ def write_opendkim_tables(domains, env):
# Append a record to OpenDKIM's KeyTable and SigningTable for each domain
# that we send mail from (zones and all subdomains).

opendkim_key_file = os.path.join(env['STORAGE_ROOT'], 'mail/dkim/mail.private')
opendkim_key_file = os.path.join(env['STORAGE_ROOT'], 'mail/dkim/' + env['DKIM_SELECTOR'] + '.private')

if not os.path.exists(opendkim_key_file):
# Looks like OpenDKIM is not installed.
Expand All @@ -789,7 +789,7 @@ def write_opendkim_tables(domains, env):
# signing domain must match the sender's From: domain.
"KeyTable":
"".join(
"{domain} {domain}:mail:{key_file}\n".format(domain=domain, key_file=opendkim_key_file)
"{domain} {domain}:{selector}:{key_file}\n".format(domain=domain, selector=env['DKIM_SELECTOR'], key_file=opendkim_key_file)
for domain in domains
),
}
Expand Down
4 changes: 2 additions & 2 deletions setup/dkim.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ fi
# A 1024-bit key is seen as a minimum standard by several providers
# such as Google. But they and others use a 2048 bit key, so we'll
# do the same. Keys beyond 2048 bits may exceed DNS record limits.
if [ ! -f "$STORAGE_ROOT/mail/dkim/mail.private" ]; then
opendkim-genkey -b 2048 -r -s mail -D $STORAGE_ROOT/mail/dkim
if [ ! -f "$STORAGE_ROOT/mail/dkim/$DKIM_SELECTOR.private" ]; then
opendkim-genkey -b 2048 -r -s $DKIM_SELECTOR -D $STORAGE_ROOT/mail/dkim
fi

# Ensure files are owned by the opendkim user and are private otherwise.
Expand Down
2 changes: 1 addition & 1 deletion setup/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def migration_8(env):
# Delete DKIM keys. We had generated 1024-bit DKIM keys.
# By deleting the key file we'll automatically generate
# a new key, which will be 2048 bits.
os.unlink(os.path.join(env['STORAGE_ROOT'], 'mail/dkim/mail.private'))
os.unlink(os.path.join(env['STORAGE_ROOT'], 'mail/dkim/' + env['DKIM_SELECTOR'] + '.private'))

def migration_9(env):
# Add a column to the aliases table to store permitted_senders,
Expand Down
1 change: 1 addition & 0 deletions setup/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ PUBLIC_IPV6=$PUBLIC_IPV6
PRIVATE_IP=$PRIVATE_IP
PRIVATE_IPV6=$PRIVATE_IPV6
MTA_STS_MODE=${DEFAULT_MTA_STS_MODE:-enforce}
DKIM_SELECTOR=${DEFAULT_DKIM_SELECTOR:-mail}
EOF

# Start service configuration.
Expand Down

0 comments on commit b51550d

Please sign in to comment.