Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed user_information in Release Request #81

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions dlms_cosem/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ class DlmsConnection:
factory=DlmsConnectionSettings
))

# The user_information field that was carried in AARQ
# For internal use only. If you want to change the proposed parameters,
# see conformance and max_pdu_size arguments
initiate_request: Optional[xdlms.InitiateRequest] = attr.ib(default=None)

@classmethod
def with_pre_established_association(
cls,
Expand Down Expand Up @@ -525,6 +530,15 @@ def unprotect(self, event):
if isinstance(
event, (acse.ApplicationAssociationResponse, acse.ReleaseResponse)
):
"""
TODO: When RLRE check that it contains the same protected InitiateResponse that in AARE.
From "DLMS UA 1000-2 Ed. 10 - 9.3.3 The COSEM-RELEASE service":
If the xDLMS InitiateRequest APDU can be successfully deciphered, then the .response primitive shall
carry the same Negotiated_xDLMS_Context parameter as in the COSEM -OPEN.response primitive. It
is carried by the xDLMS InitiateResponse APDU, protected the same way as in the AARE and placed
in the user-information field of the RLRE APDU.
"""

if event.user_information:
if isinstance(
event.user_information.content,
Expand Down Expand Up @@ -576,6 +590,9 @@ def get_aarq(self) -> acse.ApplicationAssociationRequest:
client_max_receive_pdu_size=self.max_pdu_size,
)

# later used for release request
self.initiate_request = initiate_request

return acse.ApplicationAssociationRequest(
ciphered=ciphered_apdus,
system_title=self.client_system_title,
Expand All @@ -589,14 +606,25 @@ def get_rlrq(self) -> acse.ReleaseRequest:
Returns a ReleaseRequestApdu to release the current association if one should be used.
"""

initiate_request = xdlms.InitiateRequest(
proposed_conformance=self.conformance,
client_max_receive_pdu_size=self.max_pdu_size,
)
user_information=None
if self.use_protection:
"""
From DLMS UA 1000-2 Ed. 10 - 9.3.3 The COSEM-RELEASE service:
The Proposed_xDLMS_Context parameter is conditional. It is present only if the value of the
Use_RLRQ_RLRE is TRUE and the AA to be released has been established with an application context
using ciphering. This option allows securing the COSEM-RELEASE service, and avoiding thereby a
denial-of-service attack that may be carried out by unauthorized releasing of the AA.

In the .request primitive, the Proposed_xDLMS_Context parameter shall be the same as in the
COSEM-OPEN.request service primitive, having established the AA to be released. It is carried by the
xDLMS InitiateRequest APDU, protected the same way as in the AARQ and placed in the user-
information field of the RLRQ APDU.
"""
user_information=acse.UserInformation(content=self.initiate_request)

return acse.ReleaseRequest(
reason=enums.ReleaseRequestReason.NORMAL,
user_information=acse.UserInformation(content=initiate_request),
user_information=user_information
)

def update_negotiated_parameters(
Expand Down