P1sec / pycrate

A Python library to ease the development of encoders and decoders for various protocols and file formats; contains ASN.1 and CSN.1 compilers.
GNU Lesser General Public License v2.1
380 stars 130 forks source link

aChBillingCharacteristics - timeDurationCharging not parsed in IDP reply #233

Closed vazir closed 1 year ago

vazir commented 1 year ago

Hello

Trying to parse CAP reply to the IDP , and stuck the part of reply was not completely parsed

while in the wireshark i can see all the parsed part, the pycrate leaves the parameter encoded

    basicROS : invoke : {
      invokeId present : 2,
      opcode local : 35,
      argument ApplyChargingArg: {
        aChBillingChargingCharacteristics 'A00480020258'H
      }
    },

and in the wireshark it is image

searching in the pycrate code I did not find a timeDurationCharging parse code, but it is exists in the CAP-datatypes.asn Is there a way to include it so the message is parsed completely?

vazir commented 1 year ago

Dear @p1-bmu Benoit Michau,

Tryed to manually recompile the TCAP_CAP with

./pycrate_asn1compile.py -s TCAP_CAP

and noticed the

INF: CAP-datatypes.AChBillingChargingCharacteristics, unprocessed CONSTRAINED BY constraint

May it be the reason? And... is there a way to fix?

p1-bmu commented 1 year ago

You're correct.

The definition for AChBillingChargingCharacteristics is here: https://github.com/P1sec/pycrate/blob/da145b1c39ad4edd4a90216ba6c56119eb877825/pycrate_asn1dir/Pycrate_TCAP_CAP/CAP-datatypes.asn#L74 It's an OCTET STRING, with a CONSTRAINED BY constraint, which is not supported by Pycrate, as it is used in very different ways depending of the protocols, and is not very well defined by the ASN.1 specification itself. So, the object is just handled as an OCTET STRING in Pycrate.

If you want the full decoding of its content, you can try the CONTAINING constraint, which is supported by Pycrate. You will need to change the ASN.1 definition to something like this:

AChBillingChargingCharacteristics {PARAMETERS-BOUND : bound} ::= OCTET STRING (SIZE
    (bound.&minAChBillingChargingLength .. bound.&maxAChBillingChargingLength))
    (CONTAINING CAMEL-AChBillingChargingCharacteristics {bound})

And recompile the TCAP-CAP specification.

vazir commented 1 year ago

@p1-bmu It did worked like a charm... You are real magician!

    basicROS : invoke : {
      invokeId present : 2,
      opcode local : 35,
      argument ApplyChargingArg: {
        aChBillingChargingCharacteristics CAMEL-AChBillingChargingCharacteristics: timeDurationCharging : {
          maxCallPeriodDuration 600
        }
      }
    },

vazir commented 1 year ago

@p1-bmu I was dancing arround it for a whole day, got the .asn from wireshark (which have it remade plainly - no classes), compiling it with asn1tools (which did partially worked, giving very weird results) . And you just resolved it with a snap of fingers :) Thank you so much :)

p1-bmu commented 1 year ago

Thank you for your kind feedback @vazir