abstract syntax notation one asn.1

39
Abstract Syntax Notation One ASN.1 by Behzad Akbari Fall 2011 In the Name of the Most High These slides are based in parts upon slides of Prof. Dssouli (Concordia university)

Upload: gavivi

Post on 24-Feb-2016

83 views

Category:

Documents


5 download

DESCRIPTION

In the Name of the Most High . Abstract Syntax Notation One ASN.1. by Behzad Akbari Fall 2011. These slides are based in parts upon slides of Prof. Dssouli (Concordia university ). Abstract Syntax Notation One. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Abstract Syntax Notation One ASN.1

Abstract Syntax Notation One

ASN.1

byBehzad Akbari

Fall 2011

In the Name of the Most High

These slides are based in parts upon slides of Prof. Dssouli (Concordia university)

Page 2: Abstract Syntax Notation One ASN.1

Abstract Syntax Notation One

Both the information and communications models need to be specified syntactically and semantically.

This requires a language that specifies the management protocol in the application layer.

This is where Abstract Syntax Notation One (ASN.1) plays a role. ASN.1 is actually more than a syntax; it’s a language that addresses both syntax

and semantics Two type of syntax

Abstract syntax: set of rules that specify data type and structure for information storage Transfer syntax: set of rules for communicating information between systems

Can generate machine-readable code: Basic Encoding Rules (BER) ASN.1 is based on the Backus system and uses the formal syntax and grammar

of the Backus-Nauer Form (BNF)

Page 3: Abstract Syntax Notation One ASN.1

Backus-Nauer Form (BNF)

Definition: <name> ::= <definition> where <name> denotes “entity” and the symbol “::=“ represents “defined as” primitive definitions:

<digit> ::= 0|1|2|3|4|5|6|7|8|9 <op> ::= +|-|x|/

similarly, an entity number can be constructed from primitives: <number> ::= <number> | <digit> <number> Example:

9 is primitive 9 19 is construct of 1 and 9 619 is construct of 6 and 19

Page 4: Abstract Syntax Notation One ASN.1

ASN.1 Assignments

Assignments <BooleanType> ::= BOOLEAN data type assignment (or

name of the entity) <BooleanValue> ::= TRUE | FALSE value assignment

(assigned value to the data type)

Group of assignments: Modules Start with capital letters Usually modules are built from primitive (atomic) data types (e.g.,

INTEGER, REAL, etc..) May use ASN.1 constructs (e.g., SET, SEQUENCE, etc.) Constructors are used to build structured data types Backward and forward references, and inline definition

Page 5: Abstract Syntax Notation One ASN.1

A module PersonnelRecord(a set of data types)

ASN.1 Modules

Three construction mechanisms (develop structured data types):Alternatives: CHOICEList: SET and SEQUENCERepetition: SET OF and SEQUENCE OF

PersonnelRecord ::= SET { Name, title GraphicString, division CHOICE { marketing [0] SEQUENCE {Sector, Country}, research [1] CHOICE {product-based [0] NULL, basic [1] NULL}, production [2] SEQUENCE {Product-line, Country } }}

Primitives data types

Constructs: “list makers”

Construct: alternatives

Page 6: Abstract Syntax Notation One ASN.1

PersonnelRecord is a set of different data types, each uniquely associated with a name and can be encoded and transmitted in any order.

ASN.1 Modules

Example:“Smith”, “Manager”, {“North”, “Chile”}“Manager”, “Smith”, {“North”, “Chile”}{“North”, “Chile”}, “Smith”, “Manager”

PersonnelRecord ::= SET { Name, title GraphicString, division CHOICE { marketing [0] SEQUENCE {Sector, Country}, research [1] CHOICE {product-based [0] NULL, basic [1] NULL}, production [2] SEQUENCE {Product-line, Country } }}

Lists built with “SEQUENCE” maintains the correct order

Page 7: Abstract Syntax Notation One ASN.1

ASN.1 Symbols

Symbol Meaning::= Defined as| or, alternative, options of a list- Signed number-- Following the symbol are

comments{} Start and end of a list[] Start and end of a tag() Start and end of subtype.. Range

Page 8: Abstract Syntax Notation One ASN.1

Data Types

Data Types

Convention

Example

Object name Initial lowercase letter sysDescr, etherStatsPkts

Application data type Initial uppercase letter Counter, IpAddress

Module Initial uppercase letter PersonnelRecord

Macro, MIB module All uppercase letters RMON-MIB

Keywords All uppercase letters INTEGER, BEGIN

Data types are generally defined based on a structure and a tag: Structure: simple (or atomic), structured, etc.. Tag: class and a tag

Page 9: Abstract Syntax Notation One ASN.1

Data Type

OtherTaggedStructuredSimple

Number

Tag

Structure

Class

Universal Application Context-specific Private

Figure 3.15 ASN.1 Data Type Structure and Tag

Data Type: Structure & Tag• Structure defines how data type is built

• Tag uniquely identifies the data type

Page 10: Abstract Syntax Notation One ASN.1

ASN.1 simple types

Basic Typeso BOOLEANo INTEGERo ENUMERATEDo REALo BIT STRINGo OCTET STRING

Character String Types (various subsets of ISO 10646-1)o NumericString (0-9,<space>)o PrintableString (0-9,A-Z,a z,<space>,<special>)o VisibleStringo GraphicStringo TeletexStringo UTF8Stringo IA5String

Page 11: Abstract Syntax Notation One ASN.1

ASN.1 simple types

Syntax : <type name> ::= type Example: counter ::= INTEGER IpAddress ::= OCTET STRING PageNumber ::= INTEGER ChapterNumber::= INTEGER

Months ::= ENUMERATED {january (1), february (2),

march (3), april (4), may (5), june (6), july (7 august (8), september (9), october (10), november (11), december (12)}

Page 12: Abstract Syntax Notation One ASN.1

ASN.1 simple types

A subtype is derived from a parent type

Syntax: <subtype name> ::= <type> ( <constraint> )Examples:

Counter ::= INTEGER ( 0..4294967295 )IpAddress ::= OCTET STRING ( SIZE(4) )Spring ::= Months ( march | april | may )Summer ::= Months ( june | july | august )SmallPrime ::= INTEGER ( 2 | 3 | 5 | 7 | 11 )

Page 13: Abstract Syntax Notation One ASN.1

Structure• Simple

PageNumber ::= INTEGERChapterNumber ::= INTEGER

• Structured / Construct BookPageNumber ::= SEQUENCE

{ChapterNumber, Separator, PageNumber}• Tagged

• Derived from another type; given a new ID• In Fig. 3-14, INTEGER is either universal or

application specific

• Other• CHOICE, ANY

Page 14: Abstract Syntax Notation One ASN.1

Structured Type

SEQUENCE Ordered list maker

SEQUENCE OF Ordered array of repetitive data

SET Unordered list maker

SET OF Unordered list of repetitive data

Page 15: Abstract Syntax Notation One ASN.1

ASN.1 structured types

A data type is structured type when it contains other types (i.e., have components)

BookPageNumber ::= SEQUENCE {ChapterNumber, Separator, PageNumber}

separator is a VisibleString data type with value “-” Example: {1-1, 2-3, 3-39} BookPages ::= SEQUENCE OF { BookPageNumber }

BookPages ::= SEQUENCE OF { SEQUENCE

{ChapterNumber, Separator, PageNumber}} Example: {1-1, 1-2,..,2-1, 2-2,…..}

Page 16: Abstract Syntax Notation One ASN.1

ASN.1 structured types

The pages of a book could also be specified as a collection of individual pages in random order

BookPages ::= SET OF{ SEQUENCE {ChapterNumber, Separator, PageNumber}}

Page 17: Abstract Syntax Notation One ASN.1

ASN.1 Tagged Types

Tag uniquely identifies a data type and is required for encoding the data types for communication

Comprises class and tag number Class:

o Universal - similar to global variableso Application - only in the application usedo Context-specific - specific context in applicationo Private - used extensively by commercial vendors

Example: BOOLEAN Universal 1 INTEGER Universal 2 research Application [1]

product-based Context-specific under research [0]

Page 18: Abstract Syntax Notation One ASN.1

ASN.1 Tagged Types

- basic types

- object types

- character string types

- miscellaneous types

- structured types

UNIVERSAL 1

UNIVERSAL 3

UNIVERSAL 9 UNIVERSAL 10

BOOLEAN

BIT STRING

REAL ENUMERATED

UNIVERSAL 2 INTEGER

UNIVERSAL 4 OCTET STRING

UNIVERSAL 6

UNIVERSAL 7 ObjectDescriptor

OBJECT IDENTIFIER

UNIVERSAL 5 NULL

UNIVERSAL 23 UTCTime

UNIVERSAL 24 GeneralizedTime

UNIVERSAL 16 SEQUENCE [OF] UNIVERSAL 17 SET [OF]

UNIVERSAL 26 VisibleString . . .

Page 19: Abstract Syntax Notation One ASN.1

ASN.1 Tagged Types

Context specific (subset of an application, and limited to the application)

Tag nb is 1 (overrides that of BOOLEAN)

Application specific

PersonnelRecord ::= SET { Name, title GraphicString, division CHOICE { marketing [0] SEQUENCE {Sector, Country}, research [1] CHOICE {product-based [0] NULL, basic [1] NULL}, production [2] SEQUENCE {Product-line, Country } }}

Page 20: Abstract Syntax Notation One ASN.1

ASN.1 Object Types

Used to name and describe information objects Such as standard documents, data structures, managed objects

In general, an information object is a class of information, e.g., file format, rather than an instance of such a class (i.e., individual file)

Object identifier is a unique identifier for a particular object and its value consist of a set of integers

Object descriptor is a human readable description of an information object

Page 21: Abstract Syntax Notation One ASN.1

ASN.1 Object Types

internet OBJECT IDENTIFIER ::= {iso(1) org(3) dod(6) 1 }

root

ccitt(0) iso(1) joint-iso-ccitt(2)

org(3)

dod(6)internet(1)

private(4)mgmt(2)experimental(3)

enterprise(1)mib-2(1)

private OBJECT IDENTIFIER ::= {internet 4 }

Page 22: Abstract Syntax Notation One ASN.1

ASN.1 Object Types

Private type is used extensively by vendors of network products

A vendor is assigned a node on the MIT, all branches and leaves under that node will be assigned private data types by the vendor

iso-itu2

iso1

itu0

org3

dod6

internet1

private4

enterprise1

IBM2

ibm OBJECT IDENTIFIER ::= {iso(1) org(3) dod(6) internet(1) private(4) enterprize(1) 2}

Page 23: Abstract Syntax Notation One ASN.1

Encoding Structure

ASN.1 syntax containing management information is encoded using the Basic Encoding Rules (BER) that is defined for the transfer syntax

BER is a specification developed and standardized by CCITT and OSI

ASCII data is converted to bit-oriented data

TLV, Type-Length-Value: is a specific encoding structure Type: indicates the ASN.1 type, class of the type Length: length of the actual value representation Value: the value of the ASN.1 type as a string of octets

Page 24: Abstract Syntax Notation One ASN.1

Encoding Structure

P/C (1-bit) specifies whether the structure is simple or a construct 0 for simple 1 for construct

Type Length Value

Class(7-8th bits)

P/C(6th bit)

Tag Number(1-5th bits)

1 byte

Page 25: Abstract Syntax Notation One ASN.1

Encoding Structure

Class (2 bits): specifies the class being used

Type Length Value

Class(7-8th bits)

P/C(6th bit)

Tag Number(1-5th bits)

1 byte

Class 8th bit 7th bit Universal 0 0 Application 0 1 Context-specific 1 0 Private 1 1

Page 26: Abstract Syntax Notation One ASN.1

Universal class Primitive Tag value = 2

Encoding Structure

Tag Number: designates the tag value in binary

Example: 00 0 00010 for encoding INTEGER

Type Length Value

Class(7-8th bits)

P/C(6th bit)

Tag Number(1-5th bits)

1 byte

Page 27: Abstract Syntax Notation One ASN.1

Tag number < 31

Class P/C Tag number

0 = Primitive

1 = Constructed

0 0 = Universal

0 1 = Application

1 0 = Context-specific

1 1 = Private

8 7 6 5 4 3 2 1Bits

Identifier Octet

Page 28: Abstract Syntax Notation One ASN.1

Tag number >= 31

Class P/C 1 1 1 1 1

Leading octet

1

2nd octet

1 0

Last octet

. . .

+ +. . . +

= Tag number

Page 29: Abstract Syntax Notation One ASN.1

Encoding of Length Field

Binary equivalent of 128

Short form ( L < 128 octets)

0 Length L

one octet

Contents (or Value) field

L octets

Long form ( 128 L < 21008 octets)

1 K

first octet

Length L

K octets

Contents field

L octets

Example, L = 128: 10000001 10000000

Page 30: Abstract Syntax Notation One ASN.1

BER, Examples

distance INTEGER ::= 27

00 0 00010

UNIVERSAL P 2

today INTEGER ::= 129 02 02 00 81Length is 2 to indicate 2 octets for Value

DayOfYear ::= [APPLICATION 17] IMPLICIT INTEGER

01 0 10001

APPLICATION P 17

51 02 00 81today DayOfYear ::= 129

02 01 1B

Type Length Value

Page 31: Abstract Syntax Notation One ASN.1

BER, Examples

BER EncodingBirthday Length Contents30 ?? VisibleString Length Contents 1A 04 "Jane" DayOfYear Length Contents 51 02 00 81

Birthday ::= SEQUENCE {name VisibleString,day DayOfYear

}

Type Definition

myBirthday Birthday ::= {name "Jane",day 129

}

Value Assignment

0A

UNIVERSAL 1600 1 10000

Page 32: Abstract Syntax Notation One ASN.1

Example: SNMP Message

Message ::= SEQUENCE { version INTEGER {

version-1(0) },

community OCTET STRING,data ANY

}

3002

04

Tag

Page 33: Abstract Syntax Notation One ASN.1

Example: SNMP Message

Type 30: SEQUENCELength 82 01 c0: 448 octets

82: 10000010

Page 34: Abstract Syntax Notation One ASN.1

Type 30: SEQUENCELength 32: 50 octets

Page 35: Abstract Syntax Notation One ASN.1

Macros

<macroname> MACRO ::=BEGIN

TYPE NOTATION ::= <syntaxOfNewType>VALUE NOTATION ::= <syntaxOfNewValue><auxiliaryAssignments>

END

Page 36: Abstract Syntax Notation One ASN.1

Macro Example

OBJECT-TYPE MACRO ::= BEGIN TYPE NOTATION ::= "SYNTAX" type (TYPE ObjectSyntax) “ACCESS" Access "STATUS" Status VALUE NOTATION ::= value (VALUE ObjectName) Access ::= "read-only" | "read-write“ | "write-only

| "not-accessible" Status ::= "mandatory” | "optional“ | "obsolete"END

Page 37: Abstract Syntax Notation One ASN.1

Object-Type Example

sysName OBJECT-TYPE SYNTAX DisplayString (SIZE (0..255)) ACCESS read-write STATUS mandatory::= { system 5 }

Page 38: Abstract Syntax Notation One ASN.1

Marco Example 2

CAR MACRO::= BEGIN TYPE NOTATION ::= Brand Engine CarType Year VALUE NOTATION ::= value (VALUE OBJECT IDENTIFIER) Brand ::= “BRAND” value (PrintableString) Engine ::= “CC” Ccs Ccs ::= Cc | Ccs”,” Cc Cc ::= value (INTEGER (600..5000)) CarType ::= “STYLE” CType CType ::= “Sedan” | “Liftback” | “SUV” | “Other” Year ::= “YEAR” value (INTEGER)END

Page 39: Abstract Syntax Notation One ASN.1

Camry CARBRAND ToyotaCC 2000, 2400, 3000STYLE SedanYEAR 2006

::= {toyota 3}