Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
DNS testing tools
Remoh
Commits
8cba1a31
Commit
8cba1a31
authored
Sep 07, 2020
by
Alexandre
Browse files
Split CustomException with better exception names
parent
8e3ad9a4
Changes
1
Hide whitespace changes
Inline
Side-by-side
homer.py
View file @
8cba1a31
...
...
@@ -261,9 +261,9 @@ def get_addrfamily(addr, forceIPv4=False, forceIPv6=False):
# thoses checks between the IP family and the command line option
# might need to land somewhere else
if
forceIPv4
and
family
==
6
:
raise
Custom
Exception
(
"You cannot force IPv4 with a litteral IPv6 address (%s)"
%
addr
)
raise
Family
Exception
(
"You cannot force IPv4 with a litteral IPv6 address (%s)"
%
addr
)
elif
forceIPv6
and
family
==
4
:
raise
Custom
Exception
(
"You cannot force IPv6 with a litteral IPv4 address (%s)"
%
addr
)
raise
Family
Exception
(
"You cannot force IPv6 with a litteral IPv4 address (%s)"
%
addr
)
if
forceIPv4
or
family
==
4
:
family
=
socket
.
AF_INET
...
...
@@ -289,7 +289,16 @@ def timeout_connection(signum, frame):
class
TimeoutConnectionError
(
Exception
):
pass
class
CustomException
(
Exception
):
class
ConnectionException
(
Exception
):
pass
class
ConnectionDOTException
(
ConnectionException
):
pass
class
ConnectionDOHException
(
ConnectionException
):
pass
class
FamilyException
(
ConnectionException
):
pass
class
Request
:
...
...
@@ -389,18 +398,19 @@ class RequestDOH(Request):
class
Connection
:
def
__init__
(
self
,
server
,
servername
=
None
,
connect_to
=
None
,
forceIPv4
=
False
,
forceIPv6
=
False
,
insecure
=
False
,
verbose
=
False
,
debug
=
False
,
dot
=
False
):
if
dot
and
not
is_valid_hostname
(
server
):
raise
C
ustom
Exception
(
"DoT requires a host name or IP address, not
\"
%s
\"
"
%
server
)
raise
C
onnectionDOT
Exception
(
"DoT requires a host name or IP address, not
\"
%s
\"
"
%
server
)
if
not
dot
and
not
is_valid_url
(
server
):
raise
C
ustom
Exception
(
"DoH requires a valid HTTPS URL, not
\"
%s
\"
"
%
server
)
raise
C
onnectionDOH
Exception
(
"DoH requires a valid HTTPS URL, not
\"
%s
\"
"
%
server
)
if
forceIPv4
and
forceIPv6
:
raise
C
ustom
Exception
(
"Force IPv4 *or* IPv6 but not both"
)
raise
C
onnection
Exception
(
"Force IPv4 *or* IPv6 but not both"
)
self
.
dot
=
dot
self
.
server
=
server
...
...
@@ -491,7 +501,7 @@ class ConnectionDOT(Connection):
error
=
"Could not connect to
\"
%s
\"
"
%
self
.
server
if
self
.
connect_to
is
not
None
:
error
+=
" on %s"
%
self
.
connect_to
raise
C
ustom
Exception
(
error
)
raise
C
onnectionDOT
Exception
(
error
)
def
establish_session
(
self
,
addr
,
sock_family
):
"""Return True if a TLS session is established."""
...
...
@@ -749,7 +759,7 @@ class ConnectionDOH(Connection):
request
=
create_request
(
'.'
,
qtype
=
'NS'
,
dot
=
False
)
try
:
self
.
do_test
(
request
,
synchronous
=
False
)
except
(
OpenSSL
.
SSL
.
Error
,
CustomException
)
as
e
:
except
OpenSSL
.
SSL
.
Error
as
e
:
ok
=
False
error
(
e
)
self
.
perform_multi
(
silent
=
True
,
display_results
=
False
,
show_time
=
False
)
...
...
@@ -971,12 +981,7 @@ def run_check_default(connection):
handle
=
connection
.
curl_handle
handle
.
prepare
(
handle
,
connection
,
request
)
bundle
=
handle
try
:
connection
.
send_and_receive
(
bundle
)
except
CustomException
as
e
:
ok
=
False
error
(
e
)
break
connection
.
send_and_receive
(
bundle
)
request
.
check_response
(
connection
.
debug
)
if
not
print_result
(
connection
,
request
,
prefix
=
test_name
,
display_err
=
False
):
if
level
>=
opts
.
mandatory_level
:
...
...
@@ -1005,11 +1010,7 @@ def run_check_mime(connection, accept="application/dns-message", content_type="a
handle
=
connection
.
curl_handle
handle
.
setopt
(
pycurl
.
HTTPHEADER
,
header
)
handle
.
prepare
(
handle
,
connection
,
request
)
try
:
connection
.
send_and_receive
(
handle
)
except
CustomException
as
e
:
ok
=
False
error
(
e
)
connection
.
send_and_receive
(
handle
)
request
.
check_response
(
connection
.
debug
)
if
not
print_result
(
connection
,
request
,
prefix
=
f
"Test Header
{
', '
.
join
(
header
)
}
"
):
ok
=
False
...
...
@@ -1042,9 +1043,6 @@ def run_check_trunc(connection):
try
:
# 8.8.8.8 replies FORMERR but most DoT servers violently shut down the connection (which is legal)
connection
.
send_and_receive
(
bundle
,
dump
=
connection
.
debug
)
except
CustomException
as
e
:
ok
=
False
error
(
e
)
except
OpenSSL
.
SSL
.
ZeroReturnError
:
# This is acceptable
return
ok
except
dns
.
exception
.
FormError
:
# This is also acceptable
...
...
@@ -1328,7 +1326,7 @@ def run_default(name, connection, opts):
if
not
opts
.
pipelining
:
try
:
connection
.
do_test
(
request
,
synchronous
=
not
opts
.
multistreams
)
except
(
OpenSSL
.
SSL
.
Error
,
CustomException
)
as
e
:
except
OpenSSL
.
SSL
.
Error
as
e
:
ok
=
False
error
(
e
)
break
...
...
@@ -1440,7 +1438,7 @@ for ip in ip_set:
error
(
"
\"
%s
\"
not a name or an IP address"
%
url
)
except
socket
.
gaierror
:
error
(
"Could not resolve
\"
%s
\"
"
%
url
)
except
C
ustom
Exception
as
e
:
except
C
onnection
Exception
as
e
:
error
(
e
)
if
conn
.
dot
and
not
conn
.
success
:
ok
=
False
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment