Skip to content

Commit a21f337

Browse files
committed
Make message signature verifications optional in VTN
This makes the verification of TLS signatures optional in the VTN, which is useful if the VEN is using client-side TLS but no message signatures.
1 parent 57339f3 commit a21f337

File tree

5 files changed

+37
-21
lines changed

5 files changed

+37
-21
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.5.30
1+
0.5.32

openleadr/messaging.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ def validate_xml_signature_none(xml_tree):
117117
assert xml_tree.find('.//{http://www.w3.org/2000/09/xmldsig#}X509Certificate') is None
118118

119119

120-
async def authenticate_message(request, message_tree, message_payload, fingerprint_lookup=None, ven_lookup=None):
120+
async def authenticate_message(request, message_tree, message_payload,
121+
fingerprint_lookup=None, ven_lookup=None,
122+
verify_message_signature=True):
121123
if request.secure and 'ven_id' in message_payload:
122124
connection_fingerprint = utils.get_cert_fingerprint_from_request(request)
123125
if connection_fingerprint is None:
@@ -152,21 +154,22 @@ async def authenticate_message(request, message_tree, message_payload, fingerpri
152154
f"does not match the expected fingerprint '{expected_fingerprint}'")
153155
raise errors.NotRegisteredOrAuthorizedError(msg)
154156

155-
message_cert = utils.extract_pem_cert(message_tree)
156-
message_fingerprint = utils.certificate_fingerprint(message_cert)
157-
if message_fingerprint != expected_fingerprint:
158-
msg = (f"The fingerprint of the certificate used to sign the message "
159-
f"{message_fingerprint} did not match the fingerprint that this "
160-
f"VTN has for you {expected_fingerprint}. Make sure you use the correct "
161-
"certificate to sign your messages.")
162-
raise errors.NotRegisteredOrAuthorizedError(msg)
163-
164-
try:
165-
validate_xml_signature(message_tree)
166-
except ValueError:
167-
msg = ("The message signature did not match the message contents. Please make sure "
168-
"you are using the correct XMLDSig algorithm and C14n canonicalization.")
169-
raise errors.NotRegisteredOrAuthorizedError(msg)
157+
if verify_message_signature:
158+
message_cert = utils.extract_pem_cert(message_tree)
159+
message_fingerprint = utils.certificate_fingerprint(message_cert)
160+
if message_fingerprint != expected_fingerprint:
161+
msg = (f"The fingerprint of the certificate used to sign the message "
162+
f"{message_fingerprint} did not match the fingerprint that this "
163+
f"VTN has for you {expected_fingerprint}. Make sure you use the correct "
164+
"certificate to sign your messages.")
165+
raise errors.NotRegisteredOrAuthorizedError(msg)
166+
167+
try:
168+
validate_xml_signature(message_tree)
169+
except ValueError:
170+
msg = ("The message signature did not match the message contents. Please make sure "
171+
"you are using the correct XMLDSig algorithm and C14n canonicalization.")
172+
raise errors.NotRegisteredOrAuthorizedError(msg)
170173

171174

172175
def _create_replay_protect():

openleadr/server.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ class OpenADRServer:
4848
def __init__(self, vtn_id, cert=None, key=None, passphrase=None, fingerprint_lookup=None,
4949
show_fingerprint=True, http_port=8080, http_host='127.0.0.1', http_cert=None,
5050
http_key=None, http_key_passphrase=None, http_path_prefix='/OpenADR2/Simple/2.0b',
51-
requested_poll_freq=timedelta(seconds=10), http_ca_file=None, ven_lookup=None):
51+
requested_poll_freq=timedelta(seconds=10), http_ca_file=None, ven_lookup=None,
52+
verify_message_signatures=True):
5253
"""
5354
Create a new OpenADR VTN (Server).
5455
@@ -73,11 +74,18 @@ def __init__(self, vtn_id, cert=None, key=None, passphrase=None, fingerprint_loo
7374
:param str http_key_passphrase: The passphrase for the HTTP private key.
7475
:param ven_lookup: A callback that takes a ven_id and returns a dict containing the
7576
ven_id, ven_name, fingerprint and registration_id.
77+
:param verify_message_signatures: Whether to verify message signatures.
7678
"""
7779
# Set up the message queues
7880

7981
self.app = web.Application()
8082
self.services = {}
83+
84+
# Globally enable or disable the verification of message
85+
# signatures. Only used in combination with TLS.
86+
VTNService.verify_message_signatures = verify_message_signatures
87+
88+
# Create the separate OpenADR services
8189
self.services['event_service'] = EventService(vtn_id)
8290
self.services['report_service'] = ReportService(vtn_id)
8391
self.services['poll_service'] = PollService(vtn_id)

openleadr/service/vtn_service.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232

3333

3434
class VTNService:
35+
36+
verify_message_signatures = True
37+
3538
def __init__(self, vtn_id):
3639
self.vtn_id = vtn_id
3740
self.handlers = {}
@@ -79,10 +82,12 @@ async def handler(self, request):
7982
if request.secure and 'ven_id' in message_payload:
8083
if hasattr(self, 'fingerprint_lookup'):
8184
await authenticate_message(request, message_tree, message_payload,
82-
fingerprint_lookup=self.fingerprint_lookup)
85+
fingerprint_lookup=self.fingerprint_lookup,
86+
verify_message_signature=self.verify_message_signatures)
8387
elif hasattr(self, 'ven_lookup'):
8488
await authenticate_message(request, message_tree, message_payload,
85-
ven_lookup=self.ven_lookup)
89+
ven_lookup=self.ven_lookup,
90+
verify_message_signature=self.verify_message_signatures)
8691
else:
8792
logger.error("Could not authenticate this VEN because "
8893
"you did not provide a 'ven_lookup' function. Please see "

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
long_description = file.read()
2121

2222
setup(name='openleadr',
23-
version='0.5.31',
23+
version='0.5.32',
2424
description='Python3 library for building OpenADR Clients (VENs) and Servers (VTNs)',
2525
long_description=long_description,
2626
long_description_content_type='text/markdown',

0 commit comments

Comments
 (0)