1 / 28

An Introduction to Abstract Syntax Notation 1 (ASN.1)

An Introduction to Abstract Syntax Notation 1 (ASN.1). Steinar Andresen/Rolv Bræk/Finn Arve Aagesen Norwegian University of Science and Technology, Trondheim. The need of a “common language” In order to cooperate the following needs arise.

abdalla
Download Presentation

An Introduction to Abstract Syntax Notation 1 (ASN.1)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. An Introduction to Abstract Syntax Notation 1 (ASN.1) Steinar Andresen/Rolv Bræk/Finn Arve Aagesen Norwegian University of Science and Technology, Trondheim

  2. The need of a “common language”In order to cooperate the following needs arise A shared interpretation of what the data means and a common protocol for interchange • A shared view on data structure The ASN.1 Notation • Transfer coding rulesThe ASN.1 Encoding schemes: BER, PER, .. L A N - O r g A P U B L I C W A N L A N O r g C L A N O r g B

  3. The history of ASN.1 General purpose notation and encoding scheme: • Developed to be applied to the MHS protocols (X.400) (“born” in 1982) • Generalised as general tools ISO 8824 Notation and ISO 8825 Encoding rules in 1990, Revised in 1995 • General use in many application fields today

  4. The original “realm” of ASN • Applied first to the Presentation layer in the “Open Systems Interconnection”. • Soon used to define the protocols of the Applications layer:FTAM, ROSE, MHS, etc. • Also used for lower layers

  5. Why ASN.1 and BER? O S I P r o t o c o l S t a c k O S I P r o t o c o l S t a c k A p p l i c a t i o n A p p l i c a t i o n ASN.1 for the data syntax P r e s e n t a t i o n P r e s e n t a t i o n PDU PDU s S e s s i o n S e s s i o n n o T r a n s p o r t T r a n s p o r t BER for the (sequential) transfer syntax N e t w o r k N e t w o r k D a t a l i n k D a t a l i n k P h y s i c a l P h y s i c a l

  6. 0 1 | 0 | 1 | 0 | 0 | 1 | 1 ASN.1 Use A PDU can be a complex element (letter, document, …) and: • specified using datatypes of SDL, LOTOS, UML, ... • implemented using datatypes of CHILL, C++, Java, ... ASN.1 provides a language independent syntax and ASN.1 compilers take care of the mapping C++, Java, SDL... PDU PDU C++, Java, SDL... ASN.1 ASN.1 BER Decode Encode C++, Java,... C++, Java,...

  7. ASN.1 Module • A module is a set of ASN.1 definitions assembled for a specific purpose. • The structure of a module is:ModuleDefinition::= ModuleIdentifier DEFINITIONSDEFINITIONS::= BEGIN ModuleBody END

  8. ASN.1 Module Identifier • ModuleIdentifer is an element of type Object Identifiers • Object Identifiers are adminstrered by ISO, ITU-T, etc. A Module Identifier represents an official reference to the Module.

  9. Module Body ModuleBody::= Exports -- definitions that may be exported to other modules Imports -- definitions that are imported from other modules AssignmentList --this modules definitions | -- “|” means “or” empty

  10. W h e a t h e r R e p o r t : : = S EQUENCE{ . . . . . . } N a m e o f a t y p e r e f e r e n c e t o d e f i n e d t y p e Assignments Type assignment Value assignment s a m p l e W R e p o r t W h e a t h e r R e p o r t : : = { . . . . . . } N a m e o f a v a l u e T h e t y p e o f t h i s v a l u e A c t u a l v a l u e s p e c .

  11. Type assignment A type assignment has three syntactic elements: • the type reference (the name allocated to it), • the symbol “::=“ (means defined as) and • the appropriate type notation WheatherReport ::= SEQUENCE { stationNumber INTEGER {1..99999} timeOfReport UTCTime ......... }

  12. Value assignment A value assignment has four syntactic elements: • the value reference (the name allocated), • the type to which the value belongs • the symbol “::=“ (means defined as) and • the appropriate value notation Sample value assignment: sampleReport WheatherReport ::= { stationNumber 73290 timeOfReport “900102125703Z” ......... }

  13. Sequence Letter ::= SEQUENCE { opening OCTETSTRING, body OCTETSTRING, closing OCTETSTRING, address AddressType } AddressType ::= SEQUENCE { name OCTETSTRING, number INTEGER, street OCTETSTRING, postOffice OCTETSTRING, state OCTETSTRING, zipCode INTEGER }

  14. Optional AddressType ::= SEQUENCE { name OCTETSTRING, number INTEGER, street OCTETSTRING, apartNumber INTEGER OPTIONAL, postOffice OCTETSTRING, state OCTETSTRING, zipCode INTEGER }

  15. Tags Letter ::= SEQUENCE { opening OCTETSTRING, body OCTETSTRING, closing OCTETSTRING, receiverAddr AddressType OPTIONAL, senderAddr AddressType OPTIONAL } Letter ::= SEQUENCE { opening OCTETSTRING, body OCTETSTRING, closing OCTETSTRING, receiverAddr [0] AddressType OPTIONAL, senderAddr [1] AddressType OPTIONAL }

  16. Spelling Conventions • Reserved words: only CAPITAL letters (INTEGER, CHOICE,…) • Types: first letter Capital (TransactionID) • Value reference: first letter Lowercase (application(0)) • Identifier: first letter Lowercase (destination, responder) • Macro: only CAPITAL letters

  17. ASN.1 Tagged Types Four classes: 1. UNIVERSAL (ASN.1 In-build types) 2. Application specific types (non-ambiguous within module) 3. Context specific types (non-ambiguous within construct) 3. Private (non-ambiguous within some ”enterprise”) UNIVERSAL: • Simple types (BOOLEAN, INTEGER, ENUMERATED, …) • Constructor types (SEQUENCE, SEQUENCE OF, SET, SETOF) • Additional predefined (NumericString, Teletxstring, GeneralizedTime, …) • OBJECT IDENTIFIER • Tagging is needed to recognise the types in the transfer syntaxt (when decoding a received PDU)

  18. Universal Types Universal Tag ASN.1 Type • 1 BOOLEAN • 2 INTEGER • 3 BITSTRING • 4 OCTETSTRING • 5 NULL • 6 OBJECTIDENTIFIER • 7 ObjectDescriptor • 8 EXTERNAL • 9 REAL • 10 ENUMERATED • 11-15 reserved for addenda • 16 SEQUENCE, SEQUENCE OF • 17 SET, SET OF • … ...

  19. Example Example DEFINITIONS::= BEGIN TransactionID ::= INTEGER Component ::= INTEGER {application(0), networkManager(1),systemManager(2)} Request ::= PrintableString EntityIdentifier ::= [PRIVATE 1] IMPLICIT OCTETSTRING RequestPDU ::= SEQUENCE {responseRequired BOOLEAN, TransactionID, requestor EntityIdentifier,request CHOICE { command [0] IMPLICIT SET {destination Component, Request} shutdown [1] IMPLICIT NULL}} ResponsePDU ::= SEQUENCE {TransactionID, responder EntityIdentifier OPTIONAL, result INTEGER {success(0), failure(1)}} END

  20. A Value assignment example aRequestPDU RequestPDU ::= {ResponseRequired TRUE, 45, requestor “MySystem”,request { command {destination systemManager, ‘status’} }} aResponsePDU ResponsePDU::= {45, result INTEGER {success}}

  21. ASN.1 Transfer Syntax • Basic Encoding Rules BER • Packed Encoding Rules PER • Canonical Encoding Rules CER • Disting. Encoding Rules DER • Defines how to encode the values before sending over the line • Basically it is a Type, Length, Value encoding scheme with one or more octets for each of the fields. Type Length Value identified by tagging

  22. TLV encoding scheme ... Octet 1 Octet 2 Octet 3 Octet n bit8 bit 7 ...bit1 Type Length Type Length Value Type Length Value … Data Element Data Element Data Element

  23. Class: 00 UNIVERSAL 01 APPLICATION 10 Context specific 11 Private f: 0 primitive encoding 1 constructed encoding number: <31 directly >=31 as below: ASN.1 Transfer Syntax T A G F I E L D (=Type identifier field) class f n u m b e r | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | last ... class f 11111 1 … 1 … 0 …

  24. B O O L E A N 0 0 | 0 | 0 | 0 | 1 0 | 0 | c l a s s | f | n u m b e r | 0 0 | 0 | 0 | 1 | 0 0 | 0 I N T E G E R | c l a s s | f | n u m b e r | Examples • BOOLEAN: UNIVERSAL 1 = 00000001 hex • INTEGER: UNIVERSAL 2 = 00000002 hex • SEQUENCE: UNIVERSAL 16 constructed = 00110000 = 30 hex • [PRIVATE 35] IMPLICIT INTEGER = 11011111 00100011

  25. Length field Definite form • short: length < 128 • long: length > 128 Indefinite form: only for constructed types 0 <length> ... 1 <length of length field> <length field> <length field> ... 10000000 <value> <value> 00000000 00000000

  26. 0 0 | 0 | 0 | 1 | 0 0 | 0 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | c l a s s | f | n u m b e r | | l e n g t h | V A L U E F I E L D S B O O L E A N E x . F A L S E 0 0 | 0 | 0 | 0 | 1 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 0 | 0 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | c l a s s | f | n u m b e r | | l e n g t h | | c o n t e n t s | ( T R U E w i t h c o n t e n t v a l u e d i f f e r e n t f r o m 0 ) I N T E G E R E x . 1 0 0 ( d e c i m a l ) 0 | 1 | 1 | 0 | 0 | 1 | 0 | 0 | c o n t e n t s |

  27. How to encode RequestPDU ::= SEQUENCE {responseRequired BOOLEAN, TransactionID, requestor EntityIdentifier,request CHOICE { command [0] IMPLICIT SET {destination Component, Request} shutdown [1] IMPLICIT NULL}} where: ResponseRequired = FALSE, TransactionID = 10, requestor = “MySystem”,request = command { destination = networkManager, Request = ‘status’} ??

  28. Encoding summary • Universal Tag ASN.1 Type • 1 BOOLEAN • 2 INTEGER • 3 BITSTRING • 4 OCTETSTRING • 5 NULL • 6 OBJECTIDENTIIER • 7 ObjectDescriptor • 8 EXTERNAL • 9 REAL • 10 ENUMERATED • 11-15 reserved for addenda • 16 SEQUENCE, SEQUENCE OF • 17 SET, SET OF • … ... • Class: • 00 UNIVERSAL • 01 APPLICATION • 10 Context specific • 11 Private • f: • 0 primitive encoding • 1 constructed encoding class f n u m b e r | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | • number: • <31 directly • >=31 as below: ... class f 11111 1 … 1 … 0 …

More Related