Beispiel #1
0
    def test_not_able_to_send_aarq(
            self, aarq: acse.ApplicationAssociationRequestApdu):
        c = DlmsConnection.with_pre_established_association(
            conformance=Conformance())

        with pytest.raises(LocalDlmsProtocolError):
            c.send(aarq)
Beispiel #2
0
def test_aarq_makes_dlms_waiting_for_aare():
    s = state.DlmsConnectionState()
    s.process_event(
        acse.ApplicationAssociationRequestApdu(
            user_information=UserInformation(
                InitiateRequestApdu(proposed_conformance=Conformance())
            )
        )
    )
    assert s.current_state == state.AWAITING_ASSOCIATION_RESPONSE
Beispiel #3
0
    def test_state_is_ready_in_init(self):
        c = DlmsConnection.with_pre_established_association(
            conformance=Conformance(
                priority_management_supported=True,
                attribute_0_supported_with_get=True,
                block_transfer_with_action=True,
                block_transfer_with_get_or_read=True,
                block_transfer_with_set_or_write=True,
                multiple_references=True,
                get=True,
                set=True,
                selective_access=True,
                event_notification=True,
                action=True,
            ))

        assert c.state.current_state == state.READY
Beispiel #4
0
    def test_encode_no_ciphering_high_security(self):
        data = b"`6\xa1\t\x06\x07`\x85t\x05\x08\x01\x01\x8a\x02\x07\x80\x8b\x07`\x85t\x05\x08\x02\x05\xac\n\x80\x08K56iVagY\xbe\x10\x04\x0e\x01\x00\x00\x00\x06_\x1f\x04\x00\x00~\x1f\x04\xb0"
        aarq = ApplicationAssociationRequest(
            system_title=None,
            public_cert=None,
            authentication=enumerations.AuthenticationMechanism.HLS_GMAC,
            ciphered=False,
            authentication_value=b"K56iVagY",
            user_information=UserInformation(
                content=InitiateRequest(
                    proposed_conformance=Conformance(
                        general_protection=False,
                        general_block_transfer=False,
                        delta_value_encoding=False,
                        attribute_0_supported_with_set=False,
                        priority_management_supported=True,
                        attribute_0_supported_with_get=True,
                        block_transfer_with_get_or_read=True,
                        block_transfer_with_set_or_write=True,
                        block_transfer_with_action=True,
                        multiple_references=True,
                        data_notification=False,
                        access=False,
                        get=True,
                        set=True,
                        selective_access=True,
                        event_notification=True,
                        action=True,
                    ),
                    proposed_quality_of_service=0,
                    client_max_receive_pdu_size=1200,
                    proposed_dlms_version_number=6,
                    response_allowed=True,
                    dedicated_key=None,
                )
            ),
            calling_ae_invocation_identifier=None,
            called_ap_title=None,
            called_ae_qualifier=None,
            called_ap_invocation_identifier=None,
            called_ae_invocation_identifier=None,
            calling_ap_invocation_identifier=None,
            implementation_information=None,
        )

        assert aarq.to_bytes() == data
Beispiel #5
0
    def test_no_ciher_hls_ok(self):
        data = bytes.fromhex(
            "6142A109060760857405080101A203020100A305A10302010E88020780890760857405080205AA0A8008503677524A323146BE10040E0800065F1F040000501F01F40007"
        )

        aare = acse.ApplicationAssociationResponse(
            result=enumerations.AssociationResult.ACCEPTED,
            result_source_diagnostics=enumerations.AcseServiceUserDiagnostics.AUTHENTICATION_REQUIRED,
            ciphered=False,
            authentication=enumerations.AuthenticationMechanism.HLS_GMAC,
            public_cert=None,
            system_title=None,
            authentication_value=b"P6wRJ21F",
            user_information=UserInformation(
                content=InitiateResponse(
                    negotiated_conformance=Conformance(
                        general_protection=False,
                        general_block_transfer=False,
                        delta_value_encoding=False,
                        attribute_0_supported_with_set=False,
                        priority_management_supported=True,
                        attribute_0_supported_with_get=False,
                        block_transfer_with_get_or_read=True,
                        block_transfer_with_set_or_write=False,
                        block_transfer_with_action=False,
                        multiple_references=False,
                        data_notification=False,
                        access=False,
                        get=True,
                        set=True,
                        selective_access=True,
                        event_notification=True,
                        action=True,
                    ),
                    server_max_receive_pdu_size=500,
                    negotiated_dlms_version_number=6,
                    negotiated_quality_of_service=0,
                )
            ),
            implementation_information=None,
            responding_ap_invocation_id=None,
            responding_ae_invocation_id=None,
        )

        assert aare.to_bytes() == data
Beispiel #6
0
    def test_no_ciphering_no_security_app_context_name_wrong(self):
        data = bytes.fromhex(
            "6129A109060760857405080101A203020101A305A103020102BE10040E0800065F1F040000501F01F40007"
        )
        aare = acse.ApplicationAssociationResponse(
            result=enumerations.AssociationResult.REJECTED_PERMANENT,
            result_source_diagnostics=enumerations.AcseServiceUserDiagnostics.APPLICATION_CONTEXT_NAME_NOT_SUPPORTED,
            ciphered=False,
            authentication=None,
            system_title=None,
            public_cert=None,
            authentication_value=None,
            user_information=acse.UserInformation(
                content=InitiateResponse(
                    negotiated_conformance=Conformance(
                        general_protection=False,
                        general_block_transfer=False,
                        delta_value_encoding=False,
                        attribute_0_supported_with_set=False,
                        priority_management_supported=True,
                        attribute_0_supported_with_get=False,
                        block_transfer_with_get_or_read=True,
                        block_transfer_with_set_or_write=False,
                        block_transfer_with_action=False,
                        multiple_references=False,
                        data_notification=False,
                        access=False,
                        get=True,
                        set=True,
                        selective_access=True,
                        event_notification=True,
                        action=True,
                    ),
                    server_max_receive_pdu_size=500,
                    negotiated_dlms_version_number=6,
                    negotiated_quality_of_service=0,
                )
            ),
            implementation_information=None,
            responding_ap_invocation_id=None,
            responding_ae_invocation_id=None,
        )

        assert aare.to_bytes() == data
Beispiel #7
0
def aare():
    from dlms_cosem import enumerations
    from dlms_cosem.protocol import acse
    from dlms_cosem.protocol.xdlms import Conformance, InitiateResponse

    return acse.ApplicationAssociationResponse(
        result=enumerations.AssociationResult.ACCEPTED,
        result_source_diagnostics=enumerations.AcseServiceUserDiagnostics.NULL,
        ciphered=False,
        authentication=None,
        system_title=None,
        public_cert=None,
        authentication_value=None,
        user_information=acse.UserInformation(
            content=InitiateResponse(
                negotiated_conformance=Conformance(
                    general_protection=False,
                    general_block_transfer=False,
                    delta_value_encoding=False,
                    attribute_0_supported_with_set=False,
                    priority_management_supported=True,
                    attribute_0_supported_with_get=False,
                    block_transfer_with_get_or_read=True,
                    block_transfer_with_set_or_write=False,
                    block_transfer_with_action=False,
                    multiple_references=False,
                    data_notification=False,
                    access=False,
                    get=True,
                    set=True,
                    selective_access=True,
                    event_notification=True,
                    action=True,
                ),
                server_max_receive_pdu_size=500,
                negotiated_dlms_version_number=6,
                negotiated_quality_of_service=0,
            )
        ),
        implementation_information=None,
        responding_ap_invocation_id=None,
        responding_ae_invocation_id=None,
    )
Beispiel #8
0
def test_negotiated_conformance_is_updated():
    c = DlmsConnection(client_system_title=b"12345678")
    c.send(c.get_aarq())
    c.receive_data(
        acse.ApplicationAssociationResponseApdu(
            result=enumerations.AssociationResult.ACCEPTED,
            result_source_diagnostics=enumerations.AcseServiceUserDiagnostics.
            NULL,
            user_information=acse.UserInformation(
                content=xdlms.InitiateResponseApdu(
                    negotiated_conformance=Conformance(
                        general_protection=True, general_block_transfer=True),
                    server_max_receive_pdu_size=500,
                )),
        ).to_bytes())
    c.next_event()
    assert c.conformance.general_protection
    assert c.conformance.general_block_transfer
    assert c.max_pdu_size == 500
    assert c.state.current_state == state.READY
Beispiel #9
0
    def test_decode(self):
        resulting_bytes = bytes.fromhex(
            "601DA109060760857405080101BE10040E01000000065F1F0400001E1DFFFF"
        )
        aarq = ApplicationAssociationRequest(
            ciphered=False,
            system_title=None,
            public_cert=None,
            authentication=None,
            authentication_value=None,
            user_information=UserInformation(
                content=InitiateRequest(
                    proposed_conformance=Conformance(
                        general_protection=False,
                        general_block_transfer=False,
                        delta_value_encoding=False,
                        attribute_0_supported_with_set=False,
                        priority_management_supported=False,
                        attribute_0_supported_with_get=False,
                        block_transfer_with_get_or_read=True,
                        block_transfer_with_set_or_write=True,
                        block_transfer_with_action=True,
                        multiple_references=True,
                        data_notification=False,
                        access=False,
                        get=True,
                        set=True,
                        selective_access=True,
                        event_notification=False,
                        action=True,
                    ),
                    proposed_quality_of_service=0,
                    client_max_receive_pdu_size=65535,
                    proposed_dlms_version_number=6,
                    response_allowed=True,
                    dedicated_key=None,
                )
            ),
        )

        assert aarq.to_bytes() == resulting_bytes
Beispiel #10
0
    def test_no_cipher_no_auth_conformance(self):
        data = bytes.fromhex(
            "6129a109060760857405080101a203020100a305a103020100be10040e0800065f1f0400001e1d04c80007"
        )

        aare = acse.ApplicationAssociationResponse.from_bytes(data)

        assert aare.result == enumerations.AssociationResult.ACCEPTED
        assert (
            aare.result_source_diagnostics
            == enumerations.AcseServiceUserDiagnostics.NULL
        )
        assert not aare.ciphered
        assert not aare.authentication
        assert aare.system_title is None
        assert aare.authentication_value is None
        assert aare.public_cert is None
        assert isinstance(aare.user_information.content, InitiateResponse)
        assert aare.user_information.content.negotiated_conformance == Conformance(
            general_protection=False,
            general_block_transfer=False,
            delta_value_encoding=False,
            attribute_0_supported_with_set=False,
            priority_management_supported=False,
            attribute_0_supported_with_get=False,
            block_transfer_with_get_or_read=True,
            block_transfer_with_set_or_write=True,
            block_transfer_with_action=True,
            multiple_references=True,
            data_notification=False,
            access=False,
            get=True,
            set=True,
            selective_access=True,
            event_notification=False,
            action=True,
        )
    def test_not_able_to_send_rlrq(self, rlrq: acse.ReleaseRequest):
        c = DlmsConnection.with_pre_established_association(conformance=Conformance())

        with pytest.raises(exceptions.PreEstablishedAssociationError):
            c.send(rlrq)