Merge pull request #359 from ThomasWaldmann/tsigkeyring-exceptions

catch exceptions of dns.tsigkeyring.from_text(), fixes #338, fixes #319
This commit is contained in:
TW 2018-09-30 22:05:20 +02:00 committed by GitHub
commit 64780a0368
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View File

@ -16,6 +16,7 @@ UPDATE_TIMEOUT = float(os.environ.get('DNS_UPDATE_TIMEOUT', '20.0'))
UNAVAILABLE_RETRY = 120.0
import binascii
import time
from datetime import timedelta
from collections import namedtuple
@ -334,9 +335,13 @@ def update_ns(fqdn, rdtype='A', ipaddr=None, action='upd', ttl=60):
assert isinstance(fqdn, FQDN)
assert action in ['add', 'del', 'upd', ]
nameserver, nameserver2, origin, domain, name, keyname, key, algo = get_ns_info(fqdn)
upd = dns.update.Update(origin,
keyring=dns.tsigkeyring.from_text({keyname: key}),
keyalgorithm=algo)
try:
keyring = dns.tsigkeyring.from_text({keyname: key})
except (UnicodeError, binascii.Error) as e:
msg = "Exception when building keyring for %s: [%s]" % (keyname, str(e))
logger.error(msg)
raise DnsUpdateError(msg)
upd = dns.update.Update(origin, keyring=keyring, keyalgorithm=algo)
if action == 'add':
assert ipaddr is not None
upd.add(name, ttl, rdtype, ipaddr)

View File

@ -63,6 +63,14 @@ class CreateDomainForm(forms.ModelForm):
class EditDomainForm(forms.ModelForm):
def clean_nameserver_update_secret(self):
secret = self.cleaned_data['nameserver_update_secret']
try:
binascii.a2b_base64(secret.encode(encoding="ascii", errors="strict"))
except (binascii.Error, UnicodeEncodeError):
raise forms.ValidationError(_("Enter a valid secret in base64 format."), code='invalid')
return secret
def clean(self):
cleaned_data = super(EditDomainForm, self).clean()