ASN.1 lecture v.0.2 Abstract Syntax Notation One Máté J. Csorba csorba@item.ntnu.no 1
Contents Past, present and future of ASN.1 Why ASN.1? Tools and integration Training material Basic conventions, built-in types Tagging, extensions Subtyping, constraints, etc... Introduction to BER (PER skipped) Short examples 2
Credits Some of the material includes intellectual property from: Dr. Andreas Steffen, Zürcher Hochschule Winterthur Prof. John Larmouth, Salford University, UK Dr. György Réthy, János Zoltán Szabó, Test Competence Center, Ericsson Hungary 3
The stone-age Diagrams of bits and bytes - e.g. IPv4 (The earliest approach, simple and clear, but focusing totally on the bits-on-the-line.) Tool support not possible Extensibility support crude - based on reserved fields. 4
The stone-age Simple command lines in ASCII, e.g. Telnet Simple character mnemonics and error codes (e.g. 200 OK ) Simple comma-separated parameters Good for simple dialogues Extensibility by adding commands in V2, with unknown commands ignored by V1 systems 5
The bronze-age TLV and Tabular Notation Each PDU and each parameter has an ID (or Tag), a Length, and a Value Nested TLVs in TLVs? Tables list each parameter: Tabular Notation 6
And finally: ASN.1 ASN.1 was borne around 1982 First ASN.1 Standard (CCITT X.409) in 1984 International Standard : ITU-T X.680 to X.683 ISO/IEC 8824-1 to 4 There was a need for A means of syntax (data structure) specification Procedure (sequence) specification Test suite specification Validation And tools to support rapid implementation! 7
ASN.1: What is it? Describes the data exchanged between two communicating applications Supported by efficient encodings of the data Supports a diversity of operating systems and programming languages 8
ASN.1: What is it? Formal notation, supported by tools, means: no ambiguity validation is easier, at lower cost reduced time-to-market Translates easily, with tool support, into any programming language (C, C++, Java, Cobol, Pascal, and many others) Integration also with SDL 9
Abstract vs. Transfer Syntax *Taken from: Dr. Andreas Steffen, Zürcher Hochschule Winterthur 10
So. ASN.1 offers today. Wide use in a large range of industries: Keeping the lights burning Portable phones we need them Birthday presents on time Traffic lights Aircraft fly safely Multimedia standards Many other industrial sectors 11
So thanks to ASN.1 Without ASN.1: The lights go out! Portable phones don t work! Parcels get lost! X Traffic lights fail! X Aircraft fall from the sky! Your impending marriage suffers as Net Meeting fails! X X X X 12
The near future Recognition of: Separation of "abstract syntax" (content) from encoding Encoding rules Work continues on the full integration of ASN.1 with XML Use of ASN.1 in web services 13
Tool Vendors Adrenta Technologies ATOS Origin France Telecom R&D Nikolaus Computertechnik Objective Systems OSS Nokalva Talura Aps unigone * (according to ASN.1 consortium, ITU-T) 14
Ericsson s TITAN TTCN-3 test executor => Data definition language for protocol testing - Conformance - Interoperability - Load/stress - Regression In my time 15
And now for something completely different Next => Training material, prepare some coffee in the break! Recommended bookmark: http://www.asn1.org/books/a4card.pdf 16
Abstract Syntax introduction *Taken from: Dr. György Réthy, TCC Ericsson 17
Structure of ASN.1 18
Recommended reading John Larmouth, ASN.1 Complete, Elsevier-Morgan Kaufmann, 1999 Downloadable PDF version: http://www.oss.com/asn1/larmouth.html Olivier Dubuisson, ASN.1 - Communication between heterogeneous systems, Elsevier-Morgan Kaufmann, 2000 Downloadable PDF version: http://www.oss.com/asn1/dubuisson.html 19
Contents 1. Basic conventions 2. Built-in ASN.1 types (basics of tagging and extensibility) NULL, BOOLEAN, INTEGER, BIT STRING, OCTET STRING, ENUMERATED, SEQUENCE (OF), SET (OF), CHOICE, Character string types, time types, REAL, ANY & other hole types: EMBEDDED PDV, EXTERNAL, Unrestricted character string 3. Tagging - additions Types of tags, IMPLICIT, EXPLICIT, AUTOMATIC tagging, tagging rules 4. Subtyping & constraints Single value, value range, size constraint, type constraint, permitted alphabet, contained subtype, inner subtyping 5. Extensibility - further rules ASN.1 model of extensions, extension marker, exception identifier, extensibility rules, version brackets 20
Naming conventions -1 21
Naming conventions -2 22
Module definition 23
Contents 1. Basic conventions 2. Built-in ASN.1 types (basics of tagging and extensibility) NULL, BOOLEAN, INTEGER, BIT STRING, OCTET STRING, ENUMERATED, SEQUENCE (OF), SET (OF), CHOICE, Character string types, time types, REAL, ANY & other hole types: EMBEDDED PDV, EXTERNAL, Unrestricted character string 3. Tagging - additions Types of tags, IMPLICIT, EXPLICIT, AUTOMATIC tagging, tagging rules 4. Subtyping & constraints Single value, value range, size constraint, type constraint, permitted alphabet, contained subtype, inner subtyping 5. Extensibility - further rules ASN.1 model of extensions, extension marker, exception identifier, extensibility rules, version brackets 24
NULL, BOOLEAN 25
Integer 26
Bitstring 27
Octetstring 28
Enumerated 29
Enumerated, extension 30
Rules to extension 31
Sequence 32
Tagging example -1 33
When tags shall be distinct 34
Sequence additions 35
Extension of a Sequence 36
Rules for extension 37
Rules for extension 38
Rules for extension 39
Set 40
Set 41
Choice 42
Tagging example 2 43
When tags shall be distinct 44
Choice 45
Version brackets 46
Selection type 47
Sequence of and Set of 48
Object identifiers 49
Real 50
Restricted charstring types 51
Time types 52
Embedded PDV 53
External 54
Contents 1. Basic conventions 2. Built-in ASN.1 types (basics of tagging and extensibility) NULL, BOOLEAN, INTEGER, BIT STRING, OCTET STRING, ENUMERATED, SEQUENCE (OF), SET (OF), CHOICE, Character string types, time types, REAL, ANY & other hole types: EMBEDDED PDV, EXTERNAL, Unrestricted character string 3. Tagging - additions Types of tags, IMPLICIT, EXPLICIT, AUTOMATIC tagging, tagging rules 4. Subtyping & constraints Single value, value range, size constraint, type constraint, permitted alphabet, contained subtype, inner subtyping 5. Extensibility - further rules ASN.1 model of extensions, extension marker, exception identifier, extensibility rules, version brackets 55
Tagging example 3 56
Tagging 57
Tagging 58
Universal class tags 59
Module definition again 60
Contents 1. Basic conventions 2. Built-in ASN.1 types (basics of tagging and extensibility) NULL, BOOLEAN, INTEGER, BIT STRING, OCTET STRING, ENUMERATED, SEQUENCE (OF), SET (OF), CHOICE, Character string types, time types, REAL, ANY & other hole types: EMBEDDED PDV, EXTERNAL, Unrestricted character string 3. Tagging - additions Types of tags, IMPLICIT, EXPLICIT, AUTOMATIC tagging, tagging rules 4. Subtyping & constraints Single value, value range, size constraint, type constraint, permitted alphabet, contained subtype, inner subtyping 5. Extensibility - further rules ASN.1 model of extensions, extension marker, exception identifier, extensibility rules, version brackets 61
Subtyping 62
Subtyping 63
Subtyping 64
Subtyping 65
Subtyping 66
Subtyping 67
Contents 1. Basic conventions 2. Built-in ASN.1 types (basics of tagging and extensibility) NULL, BOOLEAN, INTEGER, BIT STRING, OCTET STRING, ENUMERATED, SEQUENCE (OF), SET (OF), CHOICE, Character string types, time types, REAL, ANY & other hole types: EMBEDDED PDV, EXTERNAL, Unrestricted character string 3. Tagging - additions Types of tags, IMPLICIT, EXPLICIT, AUTOMATIC tagging, tagging rules 4. Subtyping & constraints Single value, value range, size constraint, type constraint, permitted alphabet, contained subtype, inner subtyping 5. Extensibility - further rules ASN.1 model of extensions, extension marker, exception identifier, extensibility rules, version brackets 68
Exeption handling 69
Extension examples 70
Parameterization 71
Parameterization 72
Parameterization 73
Jump to the topic of coding BER Tagging Tag of ASN.1 types Encoding of different types 74
Basics of coding 75
Coding of tag values higher then 30 76
Coding of the length field 77
Coding of the length field 78
When the length is null 79
Encoding of tags 80
Null, Boolean and Enumerated 81
Integer 82
Choice 83
Octetstring 84
Bitstring 85
Sequence (of), Set (of) 86
Obj. ID. 87
Real, base 10 88
Real, base 2 89
Ellipsis 90
Time for some practice 91
Example 1 Given the definition Company ::= SET { name [0] IA5String, zipcode [1] IA5String, CitationType INTEGER, other ANY DEFINED BY CitationType } where the INTEGER value of CitationType can be 0 = INTEGER, 1 = REAL, or 2 BOOLEAN, which of the following values are valid? Assume tagging has been done accurately. 1. CyberReal, 20742-1911, 1, TRUE 2. 60603, Villaland, 0, 500000.00 3. 0, 450, HomeNet 4. SitCom, 1, 70000.00 92
Example 2 A base-ball card value in XML syntax: <BBCard> <name>jorge Posada</name> <team>new York Yankees</team> <age>29</age> <position>c</position> <handedness>right-handed</handedness> <batting-average>0.277</batting-average> </BBCard> Definition in ASN.1 (type and value)? 93
Solution 2 ASN.1 notation: BBCard ::= SEQUENCE { name IA5String, team IA5String, age INTEGER, position IA5String, handedness ENUMERATED { left-handed, right-handed, ambidextrous }, batting-average REAL } 94
ASN.1 value: Solution 2 cont d player1 BBCard ::= { name Jorge Posada, team New York Yankees, age 29, position C, handedness right-handed, batting-average 0.277 } 95
Example 3 The C data-structure for the base-ball card: typedef struct BBCard { char name [61] ; char team [61] ; short age ; char position [61] ; enum { left_handed = 0, right_handed = 1, ambidextrous = 2, } handedness ; float batting_average ; } BBCard ; Define in ASN.1 using subtyping/constraints! 96
Solution 3 BBCard ::= SEQUENCE { name IA5String (SIZE (1..60)), team IA5String (SIZE (1..60)), age INTEGER (1..100), position IA5String (SIZE (1..60)), handedness ENUMERATED { left-handed, right-handed, ambidextrous }, batting-average REAL } 97
Example 4 FooProtocol defined using ASN.1: FooProtocol DEFINITIONS ::= BEGIN FooQuestion ::= SEQUENCE { trackingnumber INTEGER, question VisibleString } FooAnswer ::= SEQUENCE { questionnumber INTEGER, answer BOOLEAN } END Example message (PDU): myquestion FooQuestion ::= { trackingnumber 5, question "Anybody there?" } Cookbook: Tags of a SEQUENCE : 30 an INTEGER: 02 a VisibleString: 1a "Anybody there?" in ASCII: 41 6e 79 62 6f 64 79 20 74 68 65 72 65 3f Encode using simple TLV triplets and XER! 98
Solution 4 TLV, 21 octets: 30 13 02 01 05 1a 0e 41 6e 79 62 6f 64 79 20 74 68 65 72 65 3f XER, 108 octets but more readable: <FooQuestion> <trackingnumber>5</trackingnumber> <question>anybody there?</question> </FooQuestion> 99