Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
DNS testing tools
Remoh
Commits
3e48b3c6
Commit
3e48b3c6
authored
Mar 06, 2020
by
Alexandre
Browse files
[DoH] Divide request in different steps
parent
4500e063
Changes
1
Hide whitespace changes
Inline
Side-by-side
homer.py
View file @
3e48b3c6
...
@@ -184,9 +184,52 @@ class RequestDoH:
...
@@ -184,9 +184,52 @@ class RequestDoH:
def
close_handle
(
self
):
def
close_handle
(
self
):
self
.
handle
.
close
()
self
.
handle
.
close
()
def
perform
(
self
):
def
prepare_query
(
self
,
curl_opt
):
self
.
buffer
=
io
.
BytesIO
()
curl_opt
[
pycurl
.
WRITEDATA
]
=
self
.
buffer
self
.
create_handle
(
curl_opt
)
def
perform_query
(
self
):
self
.
handle
.
perform
()
self
.
handle
.
perform
()
def
receive_query
(
self
):
self
.
body
=
self
.
buffer
.
getvalue
()
self
.
body_size
=
len
(
self
.
body
)
self
.
buffer
.
close
()
def
check_response
(
self
):
ok
=
True
self
.
rcode
=
self
.
handle
.
getinfo
(
pycurl
.
RESPONSE_CODE
)
if
self
.
rcode
==
200
:
ctype
=
self
.
handle
.
getinfo
(
pycurl
.
CONTENT_TYPE
)
if
ctype
!=
"application/dns-message"
:
self
.
response
=
"Content type of the response (
\"
%s
\"
) invalid"
%
ctype
ok
=
False
else
:
if
not
head
:
try
:
self
.
response
=
dns
.
message
.
from_wire
(
self
.
body
)
except
dns
.
message
.
TrailingJunk
:
# Not DNS. Should
# not happen for a content type
# application/dns-message but who knows?
self
.
response
=
"ERROR Not proper DNS data, trailing junk
\"
%s
\"
"
%
self
.
body
ok
=
False
except
dns
.
name
.
BadLabelType
:
# Not DNS.
self
.
response
=
"ERROR Not proper DNS data (wrong path in the URL?)
\"
%s
\"
"
%
self
.
body
[:
100
]
ok
=
False
else
:
if
self
.
body_size
==
0
:
self
.
response
=
"HEAD successful"
else
:
self
.
response
=
"ERROR Body length is not null
\"
%s
\"
"
%
self
.
body
[:
100
]
ok
=
False
else
:
ok
=
False
if
self
.
body_size
==
0
:
self
.
response
=
"[No details]"
else
:
self
.
response
=
self
.
body
class
Connection
:
class
Connection
:
def
__init__
(
self
,
server
,
servername
=
None
,
connect
=
None
,
forceIPv4
=
False
,
forceIPv6
=
False
,
def
__init__
(
self
,
server
,
servername
=
None
,
connect
=
None
,
forceIPv4
=
False
,
forceIPv6
=
False
,
...
@@ -388,47 +431,11 @@ class ConnectionDoH(Connection):
...
@@ -388,47 +431,11 @@ class ConnectionDoH(Connection):
self
.
prepare_test_head
(
qname
,
qtype
)
self
.
prepare_test_head
(
qname
,
qtype
)
else
:
else
:
self
.
prepare_test_get
(
qname
,
qtype
)
self
.
prepare_test_get
(
qname
,
qtype
)
buffer
=
io
.
BytesIO
()
self
.
request
.
prepare_query
(
self
.
curl_opt
)
self
.
curl_opt
[
pycurl
.
WRITEDATA
]
=
buffer
self
.
request
.
perform_query
()
self
.
request
.
create_handle
(
self
.
curl_opt
)
self
.
request
.
receive_query
()
self
.
request
.
perform
()
self
.
request
.
check_response
()
size
=
None
return
(
self
.
request
.
rcode
,
self
.
request
.
response
,
self
.
request
.
body_size
)
rcode
=
self
.
request
.
handle
.
getinfo
(
pycurl
.
RESPONSE_CODE
)
ok
=
True
if
rcode
==
200
:
ctype
=
self
.
request
.
handle
.
getinfo
(
pycurl
.
CONTENT_TYPE
)
if
ctype
!=
"application/dns-message"
:
response
=
"Content type of the response (
\"
%s
\"
) invalid"
%
ctype
ok
=
False
else
:
body
=
buffer
.
getvalue
()
if
not
head
:
try
:
size
=
len
(
body
)
response
=
dns
.
message
.
from_wire
(
body
)
except
dns
.
message
.
TrailingJunk
:
# Not DNS. Should
# not happen for a content type
# application/dns-message but who knows?
response
=
"ERROR Not proper DNS data, trailing junk
\"
%s
\"
"
%
body
ok
=
False
except
dns
.
name
.
BadLabelType
:
# Not DNS.
response
=
"ERROR Not proper DNS data (wrong path in the URL?)
\"
%s
\"
"
%
body
[:
100
]
ok
=
False
else
:
if
len
(
body
)
==
0
:
response
=
"HEAD successful"
else
:
response
=
"ERROR Body length is not null
\"
%s
\"
"
%
body
[:
100
]
ok
=
False
else
:
ok
=
False
body
=
buffer
.
getvalue
()
if
len
(
body
)
==
0
:
response
=
"[No details]"
else
:
response
=
body
buffer
.
close
()
return
(
rcode
,
response
,
size
)
# Main program
# Main program
me
=
os
.
path
.
basename
(
sys
.
argv
[
0
])
me
=
os
.
path
.
basename
(
sys
.
argv
[
0
])
...
...
Write
Preview
Supports
Markdown
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