mirror of
https://github.com/mailcow/mailcow-dockerized.git
synced 2026-11-05 16:29:32 +00:00
[Dovecot][Web] imapsync: verify certificates against the source host, make the check optional per source
This commit is contained in:
13 files changed
+126
-18
No files matched your search
@@ -36,7 +36,7 @@ token_sync_interval = 60
|
||||
next_sql = """SELECT i.id, i.user1, i.user2, i.password1, i.exclude, i.delete2duplicates, i.maxage,
|
||||
i.subfolder2, i.delete1, i.delete2, i.automap, i.skipcrossduplicates, i.maxbytespersecond, i.custom_params,
|
||||
i.subscribeall, i.timeout1, i.timeout2, i.dry, i.source_id,
|
||||
s.host1, s.port1, s.enc1, s.auth_type, s.oauth_flow
|
||||
s.host1, s.port1, s.enc1, s.verify_cert, s.auth_type, s.oauth_flow
|
||||
FROM imapsync i JOIN imapsync_source s ON i.source_id = s.id
|
||||
WHERE i.active = 1
|
||||
AND s.active = 1
|
||||
@@ -131,6 +131,14 @@ def internal_host(host):
|
||||
return True
|
||||
return False
|
||||
|
||||
# SNI takes host names only
|
||||
def ip_literal(host):
|
||||
try:
|
||||
ipaddress.ip_address(host)
|
||||
return True
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
def oauth_token(j):
|
||||
if j['oauth_flow'] == 'authorization_code':
|
||||
return query(user_token_sql, (j['source_id'], j['user2'], j['user1'])).fetchone() or {}
|
||||
@@ -239,8 +247,13 @@ def prepare_job(j, global_bw, files):
|
||||
cmd.append(opt)
|
||||
enc1 = {'TLS': '--tls1', 'SSL': '--ssl1'}.get(j['enc1'])
|
||||
if enc1:
|
||||
# Check the certificate of the source (imapsync does not by default), custom sslargs1 can turn it off
|
||||
cmd += [enc1, '--sslargs1', 'SSL_verify_mode=1']
|
||||
# Mail::IMAPClient starts TLS without a host name: check the certificate against host1, not its address
|
||||
cmd += [enc1, '--sslargs1', 'SSL_verifycn_scheme=imap', '--sslargs1', 'SSL_verifycn_name=' + j['host1']]
|
||||
if not ip_literal(j['host1']):
|
||||
cmd += ['--sslargs1', 'SSL_hostname=' + j['host1']]
|
||||
# imapsync does not check certificates by default; custom sslargs1 of password jobs can still change it
|
||||
if j['verify_cert'] == 1:
|
||||
cmd += ['--sslargs1', 'SSL_verify_mode=1']
|
||||
cmd += ['--host1', j['host1'], '--user1', j['user1']] + auth_args + ['--port1', str(j['port1'])]
|
||||
cmd += ['--host2', 'localhost', '--user2', j['user2'] + '*' + master_user, '--passfile2', tmpfile(master_pass + '\n')]
|
||||
if j['dry'] == 1:
|
||||
|
||||
Reference in new issue
Block a user