Git Product home page Git Product logo

asn1bean's People

Contributors

bibmaster avatar hdreihah avatar koh-osug avatar onderson avatar sfeuerhahn avatar stefanfeuerhahn avatar ukarim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

asn1bean's Issues

ASN1 structure delcaration order

compared to other libraries, you need to compile java class after reading all asn1 structures like asn1tools for python

Hello := Sequence(
var1 STR_FIRST,
var2 STR_SECOND)

STR_FIRST := INT
STR_SECOND := INT

use 1.13.0 to convert asn file to java code failed

  1. asn file content below

`VehStatus DEFINITIONS AUTOMATIC TAGS ::= BEGIN

-- imports and exports

EXPORTS TransmissionState, VehicleEventFlags, ExteriorLights;
IMPORTS ;

TransmissionState ::= ENUMERATED {
	neutral (0), -- Neutral
	park (1), -- Park
	forwardGears (2), -- Forward gears
	reverseGears (3), -- Reverse gears
	reserved1 (4),
	reserved2 (5),
	reserved3 (6),
	unavailable (7)-- not-equipped or unavailable value,
	-- Any related speed is relative to the vehicle reference frame used
}

VehicleEventFlags ::= BIT STRING {
	eventHazardLights (0),
	eventStopLineViolation (1), -- Intersection Violation
	eventABSactivated (2),
	eventTractionControlLoss (3),
	eventStabilityControlactivated (4),
	eventHazardousMaterials (5),
	eventReserved1 (6),
	eventHardBraking (7),
	eventLightsChanged (8),
	eventWipersChanged (9),
	eventFlatTire (10),
	eventDisabledVehicle (11), -- The DisabledVehicle DF may also be sent
	eventAirBagDeployment (12)
	} (SIZE (13, ...))	

ExteriorLights ::= BIT STRING { 
	-- All lights off is indicated by no bits set
	lowBeamHeadlightsOn (0),
	highBeamHeadlightsOn (1),
	leftTurnSignalOn (2),
	rightTurnSignalOn (3),
	hazardSignalOn (4),
	automaticLightControlOn (5),
	daytimeRunningLightsOn (6),
	fogLightOn (7),
	parkingLightsOn (8)
	} (SIZE (9, ...))

END`

  1. run command
    ./bin/asn1bean-compiler -f VehStatus.asn

  2. error info
    line 38:28: expecting R_PAREN, found ','
    line 38:34: expecting "END", found ')'
    line 40:24: unexpected token: ::=
    line 53:1: expecting "DEFINITIONS", found 'null'
    Generating classes for module "VehStatus"
    Generating classes for module "ExteriorLights"
    done

IA5String type not supported

Hi, I'm using jasn.1 compiler and while trying to decompile one of the asn files I got error saying:
Exception in thread "main" java.lang.IllegalStateException: Type definition "IA5STRING" was not found in module
Could you please tell me when this type will be supported?

Use Interface on generated classes that includes encode/decode withTag variant

Hi @sfeuerhahn

I recently updated to the latest version of the JASN.1 library 1.10.0 and I see that a new BerType interface has been added so first of all I would like to thank you for considering it and adding it.

I see the BerType has been added to all types in the type hierarchy and includes the encode/decode methods.

To expand a little on my use case, in order to integrate with a legacy asn.1 message using my RPC framework, I need to be able to use the encode(Inputstream, boolean) variant in order to encode without prepending the tag.

I currently work around this by weaving in my own interface called BerSerializable, into the classes generated by the JASN.1 compiler. I use aspectj to do this at the moment but I would really like to remove it.

Would it be possible to add another interface like BerSerializable that extends BerType but which is only applied to the generated classes produced by the JASN.1 compiler.

Thanks.

Can't disable constraint evaluation

Hello,

I have a use case where I need that the class's of asn1 generated by the tool don't look to the asn1 constraints when decoding, but in actual version that is not possible.

Resuming, I can't disable the constraints evaluation on the classes generated.

I think this would be a very important and useful feature, since the asn1 protocol its a very old protocol and have some constraints that in the nowadays don't make much sense.

Can someone know any workaround, for my use case.

Thank you very much

Empty Octet String issue

I'm using the jAsn1 library to convert ASN1 definition into java classes and then ASN1 values files (representation of the ASN1 definition with real values written in ASN1) to instantiate dynamically the java objects.
During the parsing of the ASN1 values files with jAsn1, I found, if I'm not wrong, that the empty octet string (ie in ASN1: varName ''H ) was not correctly parsed in the ASNLexer class.

Example of definition:

MyElement ::= CHOICE {
	element ElementType
}

ElementType ::= SEQUENCE {
	eltOctetString OCTET STRING,
	eltOctetStringEmpty OCTET STRING
}

With corresponding Value used:

test MyElement ::= element : {
	eltOctetString 'ABBA'H,
	eltOctetStringEmpty ''H
}

Error reported by jAsn1:

line 1:20: unexpected token: element
line 2:24: unexpected token: 'ABBA'H
line 2:31: expecting ASSIGN_OP, found ','
line 3:29: unexpected token: '
line 4:1: expecting ASSIGN_OP, found '}'

To correct this, I modified the nextToken() method by adding in the default case of the switch a new else if :

else if ((LA(1) == '\'') && (LA(2) == '\'') && (LA(3) == 'H')) {
    mH_STRING(true);
    theRetToken = _returnToken;
}

and I modified the mH_STRING method by modifying the if (_cnt73 >= 1) into if (_cnt73 >= 0).

Would it be possible that you confirm me that these changes make sens for you ?

BER string types use all UTF-8 encoding but X.690 says otherwise

lets cite ITU-T X.690-2021 aka ISO/IEC 8825-1:2021 (E):

8.23.5 For restricted character strings apart from UniversalString, UTF8String and BMPString, the octet string shall
contain the octets specified in ISO/IEC 2022 for encodings in an 8-bit environment, using the escape sequence and character
codings registered in accordance with ISO/IEC 2375.

which in java translates to US-ASCII or for more tolerance the ISO-8859-1 charset

8.23.7 For the UniversalString type, the octet string shall contain the octets specified in ISO/IEC 10646, using the 4-
octet canonical form (see 13.2 of ISO/IEC 10646). Signatures shall not be used. Control functions may be used provided they
satisfy the restrictions imposed by 8.23.9.

which in java translates to UTF-32 or rather transformed from UCS-4

8.23.8 For the BMPString type, the octet string shall contain the octets specified in ISO/IEC 10646, using the 2-octet BMP
form (see 13.1 of ISO/IEC 10646). Signatures shall not be used. Control functions may be used provided they satisfy the
restrictions imposed by 8.23.9.

which in java translates to UTF-16 or rather transformed from UCS-2

PER Support

Hello,

Are there any plans for supporting PER encoding/decoding ?

Kind regards,
Amine

Error when decode data for extension marker (...)

I have an asn.1 with extension marker (...)

Info ::= SEQUENCE {
   version Version,
   ...
}
Version ::= INTEGER

I got an error 'Unexpected end of sequence' when decoding data with some field/value after version.

Handling of EXPLICIT ANY DEFINED BY ...

When trying to parse cryptographic message syntax (https://tools.ietf.org/html/rfc3852) I'm unable to parse the actual content at places where the ANY type is used. Instead I only get the raw bytes.

A simplified example looks like this:

CMS DEFINITIONS IMPLICIT TAGS ::=
BEGIN
  ContentInfo ::= SEQUENCE {
        contentType ContentType,
        content [0] EXPLICIT ANY DEFINED BY contentType }
		
  ContentType ::= OBJECT IDENTIFIER
  
  id-signedData OBJECT IDENTIFIER ::= { iso(1) member-body(2)
         us(840) rsadsi(113549) pkcs(1) pkcs7(7) 2 }
  
  SignedData ::= SEQUENCE {
        version CMSVersion,
        ... }
		
  CMSVersion ::= INTEGER
        { v0(0), v1(1), v2(2), v3(3), v4(4), v5(5) }
END

When trying to replace ANY with the actual expected type such as in

CMS DEFINITIONS IMPLICIT TAGS ::=
BEGIN
  ContentInfo ::= SEQUENCE {
        contentType ContentType,
        content [0] EXPLICIT SignedData }
		
  ContentType ::= OBJECT IDENTIFIER
  
  id-signedData OBJECT IDENTIFIER ::= { iso(1) member-body(2)
         us(840) rsadsi(113549) pkcs(1) pkcs7(7) 2 }
  
  SignedData ::= SEQUENCE {
        version CMSVersion,
        ... }
		
  CMSVersion ::= INTEGER
        { v0(0), v1(1), v2(2), v3(3), v4(4), v5(5) }	
END

I receive an exception during decoding: java.io.IOException: Unexpected end of sequence, length tag: 20949315, actual sequence length: 3

Error in enum filtering

the code:

Distance::= SEQUENCE {
	value	INTEGER(1..16384),
	unit	RSCUnit (2..4|6..8)
}

does not work. does not supported the |

with RSCUnit:

RSCUnit::= INTEGER {
	kmperh				(0),
	milesperh			(1),
	kilometer			(2),
	meter				(3),
	decimeter			(4),
	centimeter			(5),
	mile				(6),
	yard				(7),
	foot				(8),
	minutesOfTime		(9),
	tonnes				(10),
	hundredkg			(11),
	pound				(12), 
	rateOfIncline		(13)
	-- other value reserved for future use
	} (0..15)

expecting '*', found '<EOF>'

Exception in thread "main" line 76:1: expecting '*', found ''
at org.openmuc.jasn1.compiler.parser.ASNLexer.nextToken(ASNLexer.java:350)
at antlr.TokenBuffer.fill(TokenBuffer.java:69)
at antlr.TokenBuffer.LA(TokenBuffer.java:80)
at antlr.LLkParser.LA(LLkParser.java:52)
at org.openmuc.jasn1.compiler.parser.ASNParser.module_definitions(ASNParser.java:62)
at org.openmuc.jasn1.compiler.Compiler.getJavaModelFromAsn1File(Compiler.java:102)
at org.openmuc.jasn1.compiler.Compiler.main(Compiler.java:84)

file to compile is
Security_Management_messages_NoPrivacy.asn.zip

TAP 3.12 Decoder

Hi,
would you mind please let me know that I can use jasn1 for decoding TAP file 3.12?
Does TAP specification exist in JASN.1?

Ucompilable code generated

The following asn.1 sequence taken from CCSDS SLE FSP spec (https://public.ccsds.org/Pubs/912x3b3.pdf) will produce a class ApidList that has embedded statically another class called also ApidList. The result will not compile.

ApidList ::= CHOICE
{ any [0] NULL
, apidList [1] SEQUENCE SIZE (1 .. 2048) OF Apid
}

How to iterate through all the records of a large CDR file

I have generated the Java classes using the ASN schema file, and using the top level class I can successfully decode the file, however it only decode one record, and the data file is around 10-20MB in size so I'm sure it has more than one record, so my question is how do I loop through all the records in the data file using the top level java object.

ex:
my code is similar to this

File inputFile = new File("c:\\path\\to\\CDR-file");
FileInputStream is = new FileInputStream(inputFile);

CallDataRecord cdr = new CallDataRecord();
cdr.decode(is);

Above code gives me the very first record CallDataRecord but how do I traverse the rest of the CallDataRecord colleciton.

Thank you

Add constraint checking for `SIZE` and `INTEGER(l..h)`

Hello.

For example:

IA5String SIZE(0..10) would check if the length of string is between 0 and 10.
IA5String SIZE(10) would check if the length of string is exactly 10.
INTEGER(0..10) would check if the value is between 0 and 10.
INTEGER(10) would check if the value is exactly 10.

Now, my issue is what would happen if it fails? We will most likely know it as runtime, right? Would it be possible to catch this constraint error as an user of the library? If not, then I really have no idea how one would handle the bounds check errors besides just simply crashing. In any case, it should definitely should be possible to do this, just throw an error in the generated Java code in the decode method, so when the user of the library attempts to decode data that fits the specification but say, a value is higher than N, then it should throw a range error or something.

Easy-to-digest information about it here: https://stackoverflow.com/a/24238356/15088101


While we are at it, type checking would be pretty cool, too. :)

MAP-ExtensionDataTypes cannot be parsed

I am trying to compile MAP-ExtensionDataTypes defined in:
https://portal.3gpp.org/desktopmodules/Specifications/SpecificationDetails.aspx?specificationId=1585

But I receive following errors:

Parsing ".\MAP-ExtensionDataTypes.asn1"
line 24:49: expecting R_BRACE, found 'OPTIONAL'
line 25:43: expecting ASSIGN_OP, found '}'
line 62:12: expecting R_BRACE, found ','
Exception in thread "main" java.lang.NullPointerException
at org.openmuc.jasn1.compiler.parser.ASNParser.assignment(ASNParser.java:845)
at org.openmuc.jasn1.compiler.parser.ASNParser.module_body(ASNParser.java:307)
at org.openmuc.jasn1.compiler.parser.ASNParser.module_definition(ASNParser.java:187)
at org.openmuc.jasn1.compiler.parser.ASNParser.module_definitions(ASNParser.java:63)
at org.openmuc.jasn1.compiler.Compiler.getJavaModelFromAsn1File(Compiler.java:99)
at org.openmuc.jasn1.compiler.Compiler.main(Compiler.java:82)

Do you know what causes this?

Extendlable bit-string

the code:

LaneAttributes-Vehicle ::= BIT STRING {
  isVehicleRevocableLane          (0),
  isVehicleFlyOverLane            (1),
  hovLaneUseOnly                  (2),
  restrictedToBusUse              (3),
  restrictedToTaxiUse             (4),
  restrictedFromPublicUse         (5),
  hasIRbeaconCoverage             (6),
  permissionOnRequest             (7),
  autonomousDrivingProhibitedLane (8)
} (SIZE (8,...))

in SIZE, the , is not supported.

NegativeArraySizeException and IndexOutOfBoundsException in certificate decoding

Hi,
While running fuzz testing (with afl and Kelinci) on the jasn1 generated java classes for PKIX1Explicit88.asn (ftp://ftp3.itu.int/t/fl/ietf/rfc/rfc3280/PKIX1Explicit88.html), crashes were discovered in five different locations during certificate decoding.

This was the Driver class used for the fuzzing:

import pkix1explicit88.Certificate;
import java.io.*;

public class Driver {
public static void main (String[] args) {
if (args.length != 1) {
System.err.println("driver: usage: driver file");
System.exit(1);
}
FileInputStream fis = null;
try {
fis = new FileInputStream(args[0]);
} catch (FileNotFoundException e) {
System.err.println("FileNotFound: " + args[0]);
System.exit(1);
}
try {
Certificate c = new Certificate();
c.decode(fis);
} catch (IOException e) {
System.err.println(e);
}
try {
fis.close();
} catch (IOException e) {
}
}
}

Crashes (inputs, i.e the der encoded certificates, to be decoded are in hex format):

  1. Input:
    3082034130820229a0030201020213066c9fcf99bf8c0a39e2f0788a43e6
    96365bca300d06092a864886f70d01010b05803039310b30090603550406
    13025553310f300d060355040a1306416d617a6f6e311930170603550403
    1310416d617a6f6e20526f6f742043412031301e170d3135303532363030
    303030305a170d3338303131373030303030305a3039310b300906035504
    0613025553310f300d060355040a1306416d617a6f6e3119301706035504
    031310416d617a6f6e20526f6f74204341203130820122300d06092a8648
    86f70d01010105000382010f003082010a0282010100b2788071ca78d5e3
    71af478050747d6ed8d78876f49968f7582160f97484012fac022d86d3a0
    437a4eb2a4d036ba01be8ddb48c80717364cf4ee8823c73eeb37f5b519f8
    4968b0ded7b976381d619ea4fe8236a5e54a56e445e1f9fdb416fa74da9c
    9b35392ffab02050066c7ad080b2a6f9afec47198f503807dca2873958f8
    bad5a9f948673096ee94785e6f89a351c0308666a14566ba54eba3c391f9
    48dcffd1e8302d7d2d747035d78824f79ec4596ebb738717f2324628b843
    fab71daacab4f29f240e2d4bf7715c5e69ffea9502cb388aae50386fdbfb
    2d621bc5c71e54e177e067c80f9c8723d63f40207f2080c4804c3e3b2426
    8e04ae6c9ac8aa0d0203010001a3423040300f0603551d130101ff040530
    030101ff300e0603551d0f0101ff040403020186301d0603551d0e041604
    148418cc8534ecbc0c94942e08599cc7b2104e0a08300d06092a864886f7
    0d01010b0500038201010098f2375a4190a11ac57651282036230eaee628
    bbaaf894ae48a4307f1bfc248d4bb4c8a197f6b6f17a70c85393cc0828e3
    9825cf23a4f9de21d37c8509ad4e9a753ac20b6a897876444718656c8d41
    8e3b7f9acbf4b5a750d7052c37e8034bade961a0026ef5f2f0c5b2ed5bb7
    dcfa945c779e13a57f52ad95f2f8933bde8b5c5bca5a525b60af14f74bef
    a3fb9f40956d3154fc42d3c7461f23add90f48709ad9757871d172433475
    6e5759c2025c266029cf2319168e8843a5d4e4cb08fb231143e843297262
    a1a95d5e08d490aeb8d8ce14c2d055f286f6c49343776661c0b9e841d797
    7860036e4a72aea5d17dba109e866c1b8ab95933f8ebc490bef1b9

Crash location:
Exception occurred: java.lang.IndexOutOfBoundsException (uncaught)"thread=main", java.io.FileInputStream.readBytes(), line=-1 bci=-1

main[1] where
[1] java.io.FileInputStream.readBytes (native method)
[2] java.io.FileInputStream.read (FileInputStream.java:255)
[3] org.openmuc.jasn1.ber.internal.Util.readFully (Util.java:18)
[4] org.openmuc.jasn1.ber.types.BerAny.decode (BerAny.java:61)
[5] pkix1explicit88.AlgorithmIdentifier.decode (AlgorithmIdentifier.java:121)
[6] pkix1explicit88.TBSCertificate.decode (TBSCertificate.java:238)
[7] pkix1explicit88.Certificate.decode (Certificate.java:119)
[8] pkix1explicit88.Certificate.decode (Certificate.java:98)
[9] Driver.main (Driver.java:19)

  1. Input:
    3082034130820229a0030201020213066c9fcf99bf8c0a39e2f0788a43e6
    96365bca300d06092a864886f70d01010b05003039310b30090603550406
    13025553310f300d060355040a1306416d617a6f6e311930170603550403
    1310416d617a6f6e20526f6f742043412031301e170d3135303532363030
    303030305a170d3338303131373030303030305a3039310b300906035504
    0613025553310f300d060355040a1306416d617a6f6e3119301706035504
    031310416d617a6f6e20526f6f74204341203130820122300d06092a8648
    86f70d01010105000380010f003082010a0282010100b2788071ca78d5e3
    71af478050747d6ed8d78876f49968f7582160f97484012fac022d86d3a0
    437a4eb2a4d036ba01be8ddb48c80717364cf4ee8823c73eeb37f5b519f8
    4968b0ded7b976381d619ea4fe8236a5e54a56e445e1f9fdb416fa74da9c
    9b35392ffab02050066c7ad080b2a6f9afec47198f503807dca2873958f8
    bad5a9f948673096ee94785e6f89a351c0308666a14566ba54eba3c391f9
    48dcffd1e8302d7d2d747035d78824f79ec4596ebb738717f2324628b843
    fab71daacab4f29f240e2d4bf7715c5e69ffea9502cb388aae50386fdbfb
    2d621bc5c71e54e177e067c80f9c8723d63f40207f2080c4804c3e3b2426
    8e04ae6c9ac8aa0d0203010001a3423040300f0603551d130101ff040530
    030101ff300e0603551d0f0101ff040403020186301d0603551d0e041604
    148418cc8534ecbc0c94942e08599cc7b2104e0a08300d06092a864886f7
    0d01010b0500038201010098f2375a4190a11ac57651282036230eaee628
    bbaaf894ae48a4307f1bfc248d4bb4c8a197f6b6f17a70c85393cc0828e3
    9825cf23a4f9de21d37c8509ad4e9a753ac20b6a897876444718656c8d41
    8e3b7f9acbf4b5a750d7052c37e8034bade961a0026ef5f2f0c5b2ed5bb7
    dcfa945c779e13a57f52ad95f2f8933bde8b5c5bca5a525b60af14f74bef
    a3fb9f40956d3154fc42d3c7461f23add90f48709ad9757871d172433475
    6e5759c2025c266029cf2319168e8843a5d4e4cb08fb231143e843297262
    a1a95d5e08d490aeb8d8ce14c2d055f286f6c49343776661c0b9e841d797
    7860036e4a72aea5d17dba109e866c1b8ab95933f8ebc490bef1b9

Crash location:
Exception occurred: java.lang.NegativeArraySizeException (uncaught)"thread=main", org.openmuc.jasn1.ber.types.BerBitString.decode(), line=126 bci=42

main[1] where
[1] org.openmuc.jasn1.ber.types.BerBitString.decode (BerBitString.java:126)
[2] pkix1explicit88.SubjectPublicKeyInfo.decode (SubjectPublicKeyInfo.java:117)
[3] pkix1explicit88.TBSCertificate.decode (TBSCertificate.java:264)
[4] pkix1explicit88.Certificate.decode (Certificate.java:119)
[5] pkix1explicit88.Certificate.decode (Certificate.java:98)
[6] Driver.main (Driver.java:19)

  1. Input:
    3082034130820229a0030201020213066c9fcf99bf8c0a39e2f0788a43e6
    96365bca300d06802a864886f70d01010b05003039310b30090603550406
    13025553310f300d060355040a1306416d617a6f6e311930170603550403
    1310416d617a6f6e20526f6f742043412031301e170d3135303532363030
    303030305a170d3338303131373030303030305a3039310b300906035504
    0613025553310f300d060355040a1306416d617a6f6e3119301706035504
    031310416d617a6f6e20526f6f74204341203130820122300d06092a8648
    86f70d01010105000382010f003082010a0282010100b2788071ca78d5e3
    71af478050747d6ed8d78876f49968f7582160f97484012fac022d86d3a0
    437a4eb2a4d036ba01be8ddb48c80717364cf4ee8823c73eeb37f5b519f8
    4968b0ded7b976381d619ea4fe8236a5e54a56e445e1f9fdb416fa74da9c
    9b35392ffab02050066c7ad080b2a6f9afec47198f503807dca2873958f8
    bad5a9f948673096ee94785e6f89a351c0308666a14566ba54eba3c391f9
    48dcffd1e8302d7d2d747035d78824f79ec4596ebb738717f2324628b843
    fab71daacab4f29f240e2d4bf7715c5e69ffea9502cb388aae50386fdbfb
    2d621bc5c71e54e177e067c80f9c8723d63f40207f2080c4804c3e3b2426
    8e04ae6c9ac8aa0d0203010001a3423040300f0603551d130101ff040530
    030101ff300e0603551d0f0101ff040403020186301d0603551d0e041604
    148418cc8534ecbc0c94942e08599cc7b2104e0a08300d06092a864886f7
    0d01010b0500038201010098f2375a4190a11ac57651282036230eaee628
    bbaaf894ae48a4307f1bfc248d4bb4c8a197f6b6f17a70c85393cc0828e3
    9825cf23a4f9de21d37c8509ad4e9a753ac20b6a897876444718656c8d41
    8e3b7f9acbf4b5a750d7052c37e8034bade961a0026ef5f2f0c5b2ed5bb7
    dcfa945c779e13a57f52ad95f2f8933bde8b5c5bca5a525b60af14f74bef
    a3fb9f40956d3154fc42d3c7461f23add90f48709ad9757871d172433475
    6e5759c2025c266029cf2319168e8843a5d4e4cb08fb231143e843297262
    a1a95d5e08d490aeb8d8ce14c2d055f286f6c49343776661c0b9e841d797
    7860036e4a72aea5d17dba109e866c1b8ab95933f8ebc490bef1b9

Crash location:
Exception occurred: java.lang.NegativeArraySizeException (uncaught)"thread=main", org.openmuc.jasn1.ber.types.BerObjectIdentifier.decode(), line=123 bci=56

main[1] where
[1] org.openmuc.jasn1.ber.types.BerObjectIdentifier.decode (BerObjectIdentifier.java:123)
[2] pkix1explicit88.AlgorithmIdentifier.decode (AlgorithmIdentifier.java:110)
[3] pkix1explicit88.TBSCertificate.decode (TBSCertificate.java:238)
[4] pkix1explicit88.Certificate.decode (Certificate.java:119)
[5] pkix1explicit88.Certificate.decode (Certificate.java:98)
[6] Driver.main (Driver.java:19)

  1. Input:
    3082034130820229a0030201020213066c9fcf99bf8c0a39e2f0788a43e6
    96365bca300d06092a864886f70d01010b05003039310b30090603550406
    13025553310f300d060355040a1306416d617a6f6e311930170603550403
    1310416d617a6f6e20526f6f742043412031301e17803135303532363030
    303030305a170d3338303131373030303030305a3039310b300906035504
    0613025553310f300d060355040a1306416d617a6f6e3119301706035504
    031310416d617a6f6e20526f6f74204341203130820122300d06092a8648
    86f70d01010105000382010f003082010a0282010100b2788071ca78d5e3
    71af478050747d6ed8d78876f49968f7582160f97484012fac022d86d3a0
    437a4eb2a4d036ba01be8ddb48c80717364cf4ee8823c73eeb37f5b519f8
    4968b0ded7b976381d619ea4fe8236a5e54a56e445e1f9fdb416fa74da9c
    9b35392ffab02050066c7ad080b2a6f9afec47198f503807dca2873958f8
    bad5a9f948673096ee94785e6f89a351c0308666a14566ba54eba3c391f9
    48dcffd1e8302d7d2d747035d78824f79ec4596ebb738717f2324628b843
    fab71daacab4f29f240e2d4bf7715c5e69ffea9502cb388aae50386fdbfb
    2d621bc5c71e54e177e067c80f9c8723d63f40207f2080c4804c3e3b2426
    8e04ae6c9ac8aa0d0203010001a3423040300f0603551d130101ff040530
    030101ff300e0603551d0f0101ff040403020186301d0603551d0e041604
    148418cc8534ecbc0c94942e08599cc7b2104e0a08300d06092a864886f7
    0d01010b0500038201010098f2375a4190a11ac57651282036230eaee628
    bbaaf894ae48a4307f1bfc248d4bb4c8a197f6b6f17a70c85393cc0828e3
    9825cf23a4f9de21d37c8509ad4e9a753ac20b6a897876444718656c8d41
    8e3b7f9acbf4b5a750d7052c37e8034bade961a0026ef5f2f0c5b2ed5bb7
    dcfa945c779e13a57f52ad95f2f8933bde8b5c5bca5a525b60af14f74bef
    a3fb9f40956d3154fc42d3c7461f23add90f48709ad9757871d172433475
    6e5759c2025c266029cf2319168e8843a5d4e4cb08fb231143e843297262
    a1a95d5e08d490aeb8d8ce14c2d055f286f6c49343776661c0b9e841d797
    7860036e4a72aea5d17dba109e866c1b8ab95933f8ebc490bef1b9

Crash location:
Exception occurred: java.lang.NegativeArraySizeException (uncaught)"thread=main", org.openmuc.jasn1.ber.types.string.BerVisibleString.decode(), line=67 bci=40

main[1] where
[1] org.openmuc.jasn1.ber.types.string.BerVisibleString.decode (BerVisibleString.java:67)
[2] org.openmuc.jasn1.ber.types.BerUtcTime.decode (BerUtcTime.java:57)
[3] pkix1explicit88.Time.decode (Time.java:92)
[4] pkix1explicit88.Validity.decode (Validity.java:107)
[5] pkix1explicit88.TBSCertificate.decode (TBSCertificate.java:251)
[6] pkix1explicit88.Certificate.decode (Certificate.java:119)
[7] pkix1explicit88.Certificate.decode (Certificate.java:98)
[8] Driver.main (Driver.java:19)

  1. Input:
    3082034130820229a0030201020213066c9fcf99bf8c0a39e2f0788a43e6
    96365bca300d06092a864886f70d01010b05003039310b30090603550406
    13025553310f300d060355040a1306416d617a6f6e311930170603550403
    1310416d617a6f6e20526f6f742043412031301e170d3135303532363030
    303030305a170d3338303131373030303030305a3039310b300906035504
    0613025553310f300d060355040a1306416d617a6f6e3119301706035504
    031310416d617a6f6e20526f6f74204341203130820122300d06092a8648
    86f70d01010105000382010f003082010a0282010100b2788071ca78d5e3
    71af478050747d6ed8d78876f49968f7582160f97484012fac022d86d3a0
    437a4eb2a4d036ba01be8ddb48c80717364cf4ee8823c73eeb37f5b519f8
    4968b0ded7b976381d619ea4fe8236a5e54a56e445e1f9fdb416fa74da9c
    9b35392ffab02050066c7ad080b2a6f9afec47198f503807dca2873958f8
    bad5a9f948673096ee94785e6f89a351c0308666a14566ba54eba3c391f9
    48dcffd1e8302d7d2d747035d78824f79ec4596ebb738717f2324628b843
    fab71daacab4f29f240e2d4bf7715c5e69ffea9502cb388aae50386fdbfb
    2d621bc5c71e54e177e067c80f9c8723d63f40207f2080c4804c3e3b2426
    8e04ae6c9ac8aa0d0203010001a3423040300f0603551d130101ff048030
    030101ff300e0603551d0f0101ff040403020186301d0603551d0e041604
    148418cc8534ecbc0c94942e08599cc7b2104e0a08300d06092a864886f7
    0d01010b0500038201010098f2375a4190a11ac57651282036230eaee628
    bbaaf894ae48a4307f1bfc248d4bb4c8a197f6b6f17a70c85393cc0828e3
    9825cf23a4f9de21d37c8509ad4e9a753ac20b6a897876444718656c8d41
    8e3b7f9acbf4b5a750d7052c37e8034bade961a0026ef5f2f0c5b2ed5bb7
    dcfa945c779e13a57f52ad95f2f8933bde8b5c5bca5a525b60af14f74bef
    a3fb9f40956d3154fc42d3c7461f23add90f48709ad9757871d172433475
    6e5759c2025c266029cf2319168e8843a5d4e4cb08fb231143e843297262
    a1a95d5e08d490aeb8d8ce14c2d055f286f6c49343776661c0b9e841d797
    7860036e4a72aea5d17dba109e866c1b8ab95933f8ebc490bef1b9

Crash location:
Exception occurred: java.lang.NegativeArraySizeException (uncaught)"thread=main", org.openmuc.jasn1.ber.types.BerOctetString.decode(), line=64 bci=40

main[1] where
[1] org.openmuc.jasn1.ber.types.BerOctetString.decode (BerOctetString.java:64)
[2] pkix1explicit88.Extension.decode (Extension.java:136)
[3] pkix1explicit88.Extensions.decode (Extensions.java:92)
[4] pkix1explicit88.TBSCertificate.decode (TBSCertificate.java:295)
[5] pkix1explicit88.Certificate.decode (Certificate.java:119)
[6] pkix1explicit88.Certificate.decode (Certificate.java:98)
[7] Driver.main (Driver.java:19)

Enum

Hello, I'm using jasn1 to generate a java model from an ASN.1 defintion.
Would it be possible to generate a Java Enum in cases like that?

StationType ::= INTEGER {unknown(0), pedestrian(1), cyclist(2),
moped(3), motorcycle(4), passengerCar(5), bus(6), lightTruck(7),
heavyTruck(8), trailer(9), specialVehicles(10), tram(11),
roadSideUnit(15)} (0..255)

Thanks!

User-defined constraints are not supported

Compilation of h235.asn leads to errors while handling user-defined constraints used in SIGNED, ENCRYPTED and HASHED definitions.

User-defined constraints are explained in X.682 (look at chapter 9)

Example of user-defined constraint:

HASHED{ToBeHashed} ::= SEQUENCE {
  algorithmOID  OBJECT IDENTIFIER,
  paramS        Params, -- any "runtime" parameters
  hash          BIT STRING
}(CONSTRAINED BY { -- Hash --ToBeHashed})

asn1bean-compiler generates code that doesn't compile when a field is called 'length'

Using the asn1bean-compiler on this asn file generates a .java file that does not compile:

TEST
DEFINITIONS IMPLICIT TAGS       ::=

BEGIN

ContentInfo  ::= SEQUENCE
{
     extensionType		[0]	INTEGER,
     length			[1]	INTEGER
}

END

It generates this (lines 118-128):

		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) {
			length = new BerInteger();
			vByteCount += length.decode(is, false);
			if (lengthVal >= 0 && vByteCount == lengthVal) {
				return tlByteCount + vByteCount;
			}
			vByteCount += berTag.decode(is);
		}
		else {
			throw new IOException("Tag does not match mandatory sequence component.");
		}

And the problem is obviously that a BerInteger is assigned to the local length variable of type BerLength. A trivial fix could be adding this.-prefix to class variable assignments.

Empty octet String

I encode the data ( esim profile )"
{ createFCP : { fileDescriptor '4121'H, fileID '6fc4'H, lcsi '05'H, securityAttributesReferenced '03'H, efFileSize '64'H, shortEFID ''H }
" but shortEFID ''H I don't know how to do using jasn1 because shortEFID ''H has length zero without value.

License clarification

The current LICENSE.txt contains the "templated" Apache 2.0 text, still with unreplaced "[yyyy] [name of copyright owner]" and the "APPENDIX: How to apply the Apache License to your work". Can you fix that ?

Furthermore, the User Guide at https://www.beanit.com/asn1/user-guide/ states "The generated Java classes may be put under a license of your choice". This exception relating to the Derivative Work should also be stated in the LICENSE.txt for clarity and comprehensiveness.

Sanity check on buffer allocation based for definite length sequences

I am trying out jASN1 to convert non-streaming DER-encoded data to Java classes generated using an ASN.1-schema.

The current API has no features to sanity check the buffer allocation which can lead to memory exhaustion due to eagerly overallocating byte buffers.

Are you interested in modifying the API to specifify an upper limit to sanity check these kinds of length?

Example:

import com.beanit.jasn1.ber.types.BerOctetString;
import org.junit.Assert;
import org.junit.Test;

import java.io.ByteArrayInputStream;
import java.io.EOFException;
import java.io.IOException;

public class BerOctetStringTest {

    @Test
    public void test() throws IOException {
        BerOctetString reverseMalformed = new BerOctetString();
        try {
            byte[] malformed = {4, -124, 8, 0, 0, 0};
            reverseMalformed.decode(new ByteArrayInputStream(malformed));
            Assert.fail();
        } catch (EOFException cause) {
            // expected
        } finally {
            // buffer was already allocated
            Assert.assertEquals(134217728, reverseMalformed.value.length);
        }
    }
}`

Comment line error

Comment lines currently break the parser. This snippet for example

-----------------------------------------------------------------
-- Detail Output Record
-----------------------------------------------------------------

will give an error like this:

Exception in thread "main" line 8:65: unexpected char: '-'
	at com.beanit.jasn1.compiler.parser.ASNLexer.nextToken(ASNLexer.java:342)
	at antlr.TokenBuffer.fill(TokenBuffer.java:69)
	at antlr.TokenBuffer.LA(TokenBuffer.java:80)
	at antlr.LLkParser.LA(LLkParser.java:52)
	at com.beanit.jasn1.compiler.parser.ASNParser.module_body(ASNParser.java:279)
	at com.beanit.jasn1.compiler.parser.ASNParser.module_definition(ASNParser.java:187)
	at com.beanit.jasn1.compiler.parser.ASNParser.module_definitions(ASNParser.java:63)
	at com.beanit.jasn1.compiler.Compiler.getJavaModelFromAsn1File(Compiler.java:182)
	at com.beanit.jasn1.compiler.Compiler.main(Compiler.java:122)

at line 1 and 3.

Add a choiceId for CHOICE

When i compile an asn.1 like this:
PDU ::= CHOICE { a A, b B }

i want a choiceId in the generated class, so that i can process it with switch/case. And constants CHOICE_ID_A, CHOICE_ID_B like this:

public class PDU implements Serializable
{
    public static final int CHOICE_ID_A = 0;

    public static final int CHOICE_ID_B = 1;

    private int choiceId;

    private A a = null;

    private B b = null;
}

INTEGER (value OR range) breaks

This snippet gives an error:

DayOfMonth ::= INTEGER (-1|1..31)

This is the error:

line 910:27: expecting R_PAREN, found '|'
line 910:28: expecting "END", found '1'
line 912:11: unexpected token: ::=

(-1|1) for example does work, while (1..31|-1) still gives an error.

IllegalStateException while compiling EXTERNAL type definition

I have following type definition:

XYZ02AccessControl ::= --xyzcc isPdu:"TRUE" -- EXTERNAL

which is causing this error:

Generating classes for module "XYZ02-ASN1"
Exception in thread "main" java.lang.IllegalStateException
	at org.openmuc.jasn1.compiler.BerClassWriter.followAndGetNextTaggedOrUniversalType(BerClassWriter.java:2491)
	at org.openmuc.jasn1.compiler.BerClassWriter.followAndGetNextTaggedOrUniversalType(BerClassWriter.java:2444)
	at org.openmuc.jasn1.compiler.BerClassWriter.getUniversalType(BerClassWriter.java:2536)
	at org.openmuc.jasn1.compiler.BerClassWriter.getUniversalType(BerClassWriter.java:2532)
	at org.openmuc.jasn1.compiler.BerClassWriter.writeRetaggingTypeClass(BerClassWriter.java:873)
	at org.openmuc.jasn1.compiler.BerClassWriter.translateModule(BerClassWriter.java:197)
	at org.openmuc.jasn1.compiler.BerClassWriter.translate(BerClassWriter.java:133)
	at org.openmuc.jasn1.compiler.Compiler.main(Compiler.java:89)

AFAIK this ASN1 file used to be compiled with binary notes compiler without any problems.
How can I make it work with JASN1?

JASN1 compiler version : 1.8.1

change encode method's arguement to OutputStream

Instead of having method signature as below;
public int encode(BerByteArrayOutputStream os) throws IOException
I would suggest having the signature like
public int encode(OutputStream os) throws IOException
This style would be more abstract and for example i would not need such import dependency in my camel-asn1 compiler where this would enable for third party developer's like me to have more loosly-coupled dependency in component library because i would not have such import

See;
https://github.com/onders86/camel/blob/CAMEL-ASN1/components/camel-asn1/src/main/java/org/apache/camel/dataformat/asn1/ASN1DataFormat.java#L35

Thanks

Missing CHOICE or SEQUENCE after decoding

When I decode my data I get all key and values correct but without CHOICE and SEQUENCE.

On versions 1.7.0 I get following decoded String

{
"asn": "CHOICE{ggsnPDPRecord: SEQUENCE{recordType: 0, servedIMSI: 22084139082042F1, ggsnAddress: CHOICE{iPBinaryAddress: CHOICE{iPBinV4Address: C0A8AC7D}}, chargingID: 1931767518, sgsnAddress: SEQUENCE OF{CHOICE{iPBinaryAddress: CHOICE{iPBinV4Address: D94F8201}}}, accessPointNameNI: gprs.swisscom.ch, pdpType: 0120, listOfTrafficVolumes: .................

Now on versions 1.9.0 I get following decoded String;

{
"asn": "ggsnPDPRecord: {\n\t\trecordType: 0,\n\t\tservedImsi: 22084139082042F1,\n\t\tggsnAddress: iPBinaryAddress: iPBinV4Address: C0A8AC7D,\n\t\tchargingId: 1931767518,\n\t\tsgsnAddress: {\n\t\t\tiPBinaryAddress: iPBinV4Address: D94F8201\n\t\t},\n\t\taccessPointNameNi: gprs.swisscom.ch,\n\t\tpdpType: 0120,\n\t\tlistOfTrafficVolumes: {\n\t\t\t{\n\t\t\t\tqosRequested: gsmQosInformation:..............

CHOICE and SEQUENCE are missing. Is there an additional step to have the proper decode?

THX for help

Use `enum` for `ENUMERATED`

Hello.

I expected

foobar [3] IMPLICIT ENUMERATED { six(0), eight(1), ten(2) }

to generate something like:

public static enum Foobar {
  SIX,
  EIGHT,
  TEN
}

Some even go as far as (not very :P):

if (instance.getFoobar() != null) {
  writer.writeComponent("foobar");
  switch (instance.getFoobar()) {
    case SIX:
      writer.writeIdentifier("six");
      break;
    case EIGHT:
      writer.writeIdentifier("eight");
      break;
    case TEN:
      writer.writeIdentifier("ten");
      break;
  }
}

OBJECT IDENTIFIER (a | b ) error

The following snippet is adapted from PKIX1Implicit88:

PKIX1Implicit88 {iso(1) identified-organization(3) dod(6) internet(1) security(5) mechanisms(5) pkix(7) id-mod(0) id-pkix1-implicit(19)}
--
-- Copyright (C) The Internet Society (2002). This version of
-- this ASN.1 module is part of RFC 3280;
-- see the RFC itself for full legal notices.
--
DEFINITIONS IMPLICIT TAGS ::=

BEGIN
id-pkix  OBJECT IDENTIFIER  ::=
         { iso(1) identified-organization(3) dod(6) internet(1)
                    security(5) mechanisms(5) pkix(7) }
id-qt          OBJECT IDENTIFIER ::=  { id-pkix 2 }
id-qt-cps      OBJECT IDENTIFIER ::=  { id-qt 1 }
id-qt-unotice  OBJECT IDENTIFIER ::=  { id-qt 2 }
PolicyQualifierId ::= OBJECT IDENTIFIER (id-qt-cps | id-qt-unotice)

Dummy ::= SEQUENCE {
  oid PolicyQualifierId
}
END

The following error occurs when trying to compile it:

$ ./run-scripts/jasn1-compiler -f sample.asn1 
Generated code will be saved in ./
Parsing "sample.asn1"
line 16:41: expecting "END", found '('
line 18:7: unexpected token: ::=
line 22:1: expecting "DEFINITIONS", found 'null'
Generating classes for module "PKIX1Implicit88"
Generating classes for module "Dummy"
done

This is a part of a much bigger definition. These errors break further parsing.

java.lang.NullPointerException in BerClassWriter

When I try to compile ROSE ASN.1 files [which can you find in: https://github.com/wireshark/wireshark/tree/master/epan/dissectors/asn1/ros]

I got below exception:

Generating classes for module "Remote-Operations-Useful-Definitions"
Exception in thread "main" java.lang.NullPointerException
at java.lang.String.compareTo(String.java:1155)
at java.lang.String.compareTo(String.java:111)
at java.util.ComparableTimSort.countRunAndMakeAscending(ComparableTimSort.java:320)
at java.util.ComparableTimSort.sort(ComparableTimSort.java:188)
at java.util.Arrays.sort(Arrays.java:1312)
at java.util.Arrays.sort(Arrays.java:1506)
at java.util.ArrayList.sort(ArrayList.java:1464)
at java.util.Collections.sort(Collections.java:143)
at com.beanit.asn1bean.compiler.BerClassWriter.writeOidValues(BerClassWriter.java:247)
at com.beanit.asn1bean.compiler.BerClassWriter.translateModule(BerClassWriter.java:241)
at com.beanit.asn1bean.compiler.BerClassWriter.translate(BerClassWriter.java:173)
at com.beanit.asn1bean.compiler.Compiler.main(Compiler.java:111)

Full output:

Parsing "Remote-Operations-Generic-ROS-PDUs.asn"
line 20:1: expecting "END", found '('
line 21:15: unexpected token: :
line 164:1: expecting "DEFINITIONS", found 'null'
Parsing "Remote-Operations-Information-Objects.asn"
line 21:26: unexpected token: ERROR
line 22:26: unexpected token: OPERATION
line 25:26: unexpected token: Priority
line 26:26: unexpected token: Priority
line 47:27: unexpected token: Priority
line 58:14: unexpected token: OPERATION
line 59:14: unexpected token: OPERATION
line 60:14: unexpected token: OPERATION
line 88:25: unexpected token: OPERATION-PACKAGE
line 89:25: unexpected token: OPERATION-PACKAGE
line 90:25: unexpected token: OPERATION-PACKAGE
line 102:26: unexpected token: ROS-OBJECT-CLASS
line 103:26: unexpected token: CONTRACT
line 104:26: unexpected token: CONTRACT
line 105:26: unexpected token: CONTRACT
Parsing "Remote-Operations-Useful-Definitions.asn"
line 16:39: expecting R_BRACE, found '{'
line 16:46: unexpected token: }
line 17:26: expecting ASSIGN_OP, found 'SYNCHRONOUS'
line 20:41: expecting R_BRACE, found 'TRUE'
line 23:30: expecting R_BRACE, found ':'
line 23:31: expecting "END", found '-1'
line 26:17: unexpected token: ::=
line 96:1: expecting "DEFINITIONS", found 'null'
Generating classes for module "Remote-Operations-Useful-Definitions"
Exception in thread "main" java.lang.NullPointerException
at java.lang.String.compareTo(String.java:1155)
at java.lang.String.compareTo(String.java:111)
at java.util.ComparableTimSort.countRunAndMakeAscending(ComparableTimSort.java:320)
at java.util.ComparableTimSort.sort(ComparableTimSort.java:188)
at java.util.Arrays.sort(Arrays.java:1312)
at java.util.Arrays.sort(Arrays.java:1506)
at java.util.ArrayList.sort(ArrayList.java:1464)
at java.util.Collections.sort(Collections.java:143)
at com.beanit.asn1bean.compiler.BerClassWriter.writeOidValues(BerClassWriter.java:247)
at com.beanit.asn1bean.compiler.BerClassWriter.translateModule(BerClassWriter.java:241)
at com.beanit.asn1bean.compiler.BerClassWriter.translate(BerClassWriter.java:173)
at com.beanit.asn1bean.compiler.Compiler.main(Compiler.java:111)

Support of TT-BER

I was wondering whether Jasn.1 has support for TT-BER asn data structures. Difference between TT-BER and BER is that in TT-BER blocks might have indefinite length. Jasn.1 compiler does have -il argument which should take care of this kind of data structures (even though it says that this feature is not fully developed yet), but it doesn't. please confirm whether or not this -il argument is for TT-BER. And when it will have full support for TT-BER.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.