Example #1
0
    def test_decode_with_dedicated_key(self):
        data = bytes.fromhex(
            "01011000112233445566778899AABBCCDDEEFF0000065F1F0400007E1F04B0")

        apdu = xdlms.InitiateRequest(
            proposed_conformance=xdlms.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=b'\x00\x11"3DUfw\x88\x99\xaa\xbb\xcc\xdd\xee\xff',
        )

        assert xdlms.InitiateRequest.from_bytes(data) == apdu
Example #2
0
    def test_parse_simple(self):
        data = bytes.fromhex("01000000065F1F0400007E1F04B0")

        ir = xdlms.InitiateRequest(
            proposed_conformance=xdlms.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,
        )

        assert xdlms.InitiateRequest.from_bytes(data) == ir
Example #3
0
 def test_encode_simple(self):
     data = bytes.fromhex("0800065F1F040000501F01F40007")
     ir = xdlms.InitiateResponse(
         negotiated_conformance=xdlms.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,
     )
     assert data == ir.to_bytes()
Example #4
0
def aarq():

    return acse.ApplicationAssociationRequest(
        ciphered=False,
        system_title=None,
        public_cert=None,
        authentication=None,
        authentication_value=None,
        user_information=acse.UserInformation(content=xdlms.InitiateRequest(
            proposed_conformance=xdlms.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,
        )),
    )
Example #5
0
    def test_encrypt(self):
        apdu = xdlms.InitiateRequest(
            proposed_conformance=xdlms.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=b'\x00\x11"3DUfw\x88\x99\xaa\xbb\xcc\xdd\xee\xff',
        )

        encryption_key = bytes.fromhex("000102030405060708090A0B0C0D0E0F")
        authentication_key = bytes.fromhex("D0D1D2D3D4D5D6D7D8D9DADBDCDDDEDF")
        system_title = bytes.fromhex("4D4D4D0000BC614E")
        security_control = security.SecurityControlField(
            security_suite=0,
            authenticated=True,
            encrypted=True,
            broadcast_key=False,
            compressed=False,
        )
        invocation_counter = 19088743

        ciphered_apdu = xdlms.GlobalCipherInitiateRequest(
            security_control=security.SecurityControlField(
                security_suite=0,
                authenticated=True,
                encrypted=True,
                broadcast_key=False,
                compressed=False,
            ),
            invocation_counter=19088743,
            ciphered_text=
            b'\x80\x13\x02\xff\x8axt\x13=AL\xed%\xb4%4\xd2\x8d\xb0\x04w `k\x17[\xd5"\x11\xbehA\xdb M9\xeeo\xdb\x8e5hU',
        )

        cipher_text = security.encrypt(
            security_control=security_control,
            system_title=system_title,
            key=encryption_key,
            auth_key=authentication_key,
            invocation_counter=invocation_counter,
            plain_text=apdu.to_bytes(),
        )

        assert cipher_text == ciphered_apdu.ciphered_text