Skip to content
This repository has been archived by the owner on Jun 17, 2023. It is now read-only.

fixes #66 #65 #64 #67

Merged
merged 4 commits into from Feb 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 10 additions & 7 deletions csirtg_indicator/utils/__init__.py
Expand Up @@ -15,8 +15,11 @@

# http://stackoverflow.com/a/17871737
RE_IPV6 = re.compile('(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))')

# http://goo.gl/Cztyn2 -- probably needs more work
RE_FQDN = re.compile('^((xn--)?(--)?[a-zA-Z0-9-_@]+(-[a-zA-Z0-9]+)*\.)+[a-zA-Z]{2,}(--p1ai)?$')
# http://stackoverflow.com/a/26987741/7205341
# ^((xn--)?(--)?[a-zA-Z0-9-_@]+(-[a-zA-Z0-9]+)*\.)+[a-zA-Z]{2,}(--p1ai)?$
RE_FQDN = re.compile('^((?!-))(xn--)?[a-z0-9][a-z0-9-_\.]{0,61}[a-z0-9]{0,1}\.(xn--)?([a-z0-9\-]{1,61}|[a-z0-9-]{1,30}\.[a-z]{2,})$')
RE_URI_SCHEMES = re.compile('^(https?|ftp)$')
RE_EMAIL = re.compile('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$')

Expand Down Expand Up @@ -134,18 +137,18 @@ def _email(s):
elif _hash(indicator):
return _hash(indicator)

elif _email(indicator):
return 'email'

elif _fqdn(indicator):
return 'fqdn'

elif _ipv4(indicator) or _ipv4_cidr(indicator):
return 'ipv4'

elif _ipv6(indicator):
return 'ipv6'

elif _email(indicator):
return 'email'

elif _fqdn(indicator):
return 'fqdn'

try:
error = 'unknown itype for "{}"'.format(indicator)
except UnicodeEncodeError:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Expand Up @@ -2,4 +2,4 @@ arrow>=0.7.0
pytricia>=0.9.0
ipaddress>=1.0.16
pendulum>=0.5.2
prettytable>=0.7.2
prettytable>=0.7.2
11 changes: 9 additions & 2 deletions test/test_fqdn.py
@@ -1,6 +1,14 @@
from csirtg_indicator import Indicator
from csirtg_indicator.utils import is_subdomain

GOOD = [
'hdxturkceizle.xn--6frz82g',
'xn--1--blcfn0a0ai7a1a7e.xn--p1acf',
'example.org',
'1.2.3.4.com',
'xn----jtbbmekqknepg3a.xn--p1ai'
]


def _not(data):
for d in data:
Expand All @@ -24,9 +32,8 @@ def test_fqdn_urls():


def test_fqdn_ok():
data = ['example.org', '1.2.3.4.com', 'xn----jtbbmekqknepg3a.xn--p1ai']

for d in data:
for d in GOOD:
d = Indicator(d)
assert d.itype is 'fqdn'

Expand Down