mirror of
https://github.com/certbot/certbot.git
synced 2026-08-01 02:44:21 +02:00
check recipient string before hashcash to produce more useful error message
This is more work for the server but if we don't do it in this order we always get a hashcash error instead of a recipient error if the client is confused about what server it meant to query. Giving the wrong error in this sense is OK from a protocol point of view but quite frustrating for a human being on the client end trying to figure out why the server is rejecting its apparently perfectly valid hashcash...
This commit is contained in:
+11
-7
@@ -212,6 +212,17 @@ class session(object):
|
|||||||
# It is mandatory to make a signing request at the outset of a session.
|
# It is mandatory to make a signing request at the outset of a session.
|
||||||
self.die(r, r.BadRequest, uri="https://ca.example.com/failures/missingrequest")
|
self.die(r, r.BadRequest, uri="https://ca.example.com/failures/missingrequest")
|
||||||
return
|
return
|
||||||
|
timestamp = m.request.timestamp
|
||||||
|
recipient = m.request.recipient
|
||||||
|
csr = m.request.csr
|
||||||
|
sig = m.request.sig
|
||||||
|
# Check whether we are the intended recipient of the request. Doing this
|
||||||
|
# before the hashcash check is more work for the server but gives a more
|
||||||
|
# helpful error message (because the hashcash will be wrong automatically
|
||||||
|
# if it's addressed to a different server!).
|
||||||
|
if recipient != chocolate_server_name:
|
||||||
|
self.die(r, r.BadRequest, uri="https://ca.example.com/failures/recipient")
|
||||||
|
return
|
||||||
# Check hashcash before doing any crypto or database access.
|
# Check hashcash before doing any crypto or database access.
|
||||||
if not m.request.clientpuzzle or not self.check_hashcash(m.request.clientpuzzle):
|
if not m.request.clientpuzzle or not self.check_hashcash(m.request.clientpuzzle):
|
||||||
self.die(r, r.NeedClientPuzzle, uri="https://ca.example.com/failures/hashcash")
|
self.die(r, r.NeedClientPuzzle, uri="https://ca.example.com/failures/hashcash")
|
||||||
@@ -223,10 +234,6 @@ class session(object):
|
|||||||
self.die(r, r.BadRequest, uri="https://ca.example.com/failures/priorrequest")
|
self.die(r, r.BadRequest, uri="https://ca.example.com/failures/priorrequest")
|
||||||
return
|
return
|
||||||
# Process the request.
|
# Process the request.
|
||||||
timestamp = m.request.timestamp
|
|
||||||
recipient = m.request.recipient
|
|
||||||
csr = m.request.csr
|
|
||||||
sig = m.request.sig
|
|
||||||
if not all([safe("recipient", recipient), safe("csr", csr)]):
|
if not all([safe("recipient", recipient), safe("csr", csr)]):
|
||||||
self.die(r, r.BadRequest, uri="https://ca.example.com/failures/illegalcharacter")
|
self.die(r, r.BadRequest, uri="https://ca.example.com/failures/illegalcharacter")
|
||||||
return
|
return
|
||||||
@@ -236,9 +243,6 @@ class session(object):
|
|||||||
if time.time() - timestamp > 100:
|
if time.time() - timestamp > 100:
|
||||||
self.die(r, r.BadRequest, uri="https://ca.example.com/failures/past")
|
self.die(r, r.BadRequest, uri="https://ca.example.com/failures/past")
|
||||||
return
|
return
|
||||||
if recipient != chocolate_server_name:
|
|
||||||
self.die(r, r.BadRequest, uri="https://ca.example.com/failures/recipient")
|
|
||||||
return
|
|
||||||
if not CSR.parse(csr):
|
if not CSR.parse(csr):
|
||||||
self.die(r, r.BadCSR)
|
self.die(r, r.BadCSR)
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user