ASN.1 - TU Ilmenau
Transcrição
ASN.1 - TU Ilmenau
Abstrakte Syntaxnotation 1 Beispiel Basic Encoding Rules Literatur Spezifikation von Kommunikationssystemen 4. Abstrakte Syntaxnotation 1 (ASN.1) Prof. Jochen Seitz Fachgebiet „Kommunikationsnetze“ 5. Mai 2015 1 / 19 Abstrakte Syntaxnotation 1 Beispiel Basic Encoding Rules Literatur Übersicht 1 Abstrakte Syntaxnotation 1 2 Beispiel 3 Basic Encoding Rules 2 / 19 Abstrakte Syntaxnotation 1 Beispiel Basic Encoding Rules Literatur Abstrakte Syntaxnotation 1 Beschreibungssprache zur Definition von Datenstrukturen, ohne auf die rechnerinterne Darstellung einzugehen. Festlegungen zur Umsetzung von Datenstrukturen und Elementen in ein netzeinheitliches Format. gemeinsamer Standard der ITU-T (International Telecommunication Union – Telecommunication Standardization Sector) und der ISO (Internationale Organisation für Normung). verbreitete Möglichkeit, die Nachrichtenelemente von Kommunikationsprotokollen eindeutig zu beschreiben. 3 / 19 Abstrakte Syntaxnotation 1 Beispiel Basic Encoding Rules Literatur Problem: Heterogenität Beispiel (nach Dubuisson (2000)): typedef struct Record { char name[31]; int age; enum { unknown = 0; male = 1; female = 2 } gender; } Record; type record = { name : string; age : num; gender : t_gender } and t_gender = Unknown | Male | Female (a) C-Code (b) Objective Caml Code Unterschiede: Ein String endet mit einem einem NULL byte in C, aber nicht in Objective Caml. Die Länge des Namens ist nicht begrenzt in Objective Caml. Über die interne Repräsentation des Eintrags „age“ ist nichts ausgesagt. Objective Caml kennt keine Vorgabewerte für Aufzähltypen. 4 / 19 Abstrakte Syntaxnotation 1 Beispiel Basic Encoding Rules Literatur Konvertierung Symmetrisch Sender makes right Receiver makes right Asymmetrisch Konvertierung in Zwischenformat ASN.1 5 / 19 Abstrakte Syntaxnotation 1 Beispiel Basic Encoding Rules Literatur Anwendung auf das Beispiel Abstrakte Syntax in ASN.1 Record ::= SEQUENCE { name PrintableString (SIZE (1..30)), age INTEGER, gender ENUMERATED { unknown (0), male (1), female (2) } } Maschine A Konkrete Syntax in C Maschine B Konkrete Syntax in Objective Caml typedef struct Record { char name[31]; int age; enum { unknown = 0; male = 1; female = 2 } gender; } Record; type record = { name : string; age : num; gender : t_gender } and t_gender = Unknown | Male | Female Transfersyntax (Bytes oder Bits) 6 / 19 Abstrakte Syntaxnotation 1 Beispiel Basic Encoding Rules Literatur Das Typ-Konzept in ASN.1 Ein ASN.1-Typ ist eine nicht-leere Menge von Werten, die kodiert werden können, um übertragen zu werden. Dieses Typ-Konzept ist daher vergleichbar mit dem in bekannten Programmiersprachen, um dort komplexe Datenstrukturen zu vereinbaren. ASN.1-Typen sind aber speziell auf den Datentransport hin zu vereinbaren. Entsprechende Funktionen sind vorzusehen (z. B. „OPTIONAL“). 7 / 19 Abstrakte Syntaxnotation 1 Beispiel Basic Encoding Rules Literatur Elementare Datentypen in ASN.1 BOOLEAN (true oder false) NULL (mit nur einem Wert, nämlich NULL) INTEGER (positive und negative Ganzzahlen) REAL (Gleitkommazahlen) ENUMERATED (Aufzählungstyp) BIT STRING (binäre Zeichenfolge) OCTET STRING (Folge von Bytes) IA5STRING (nach IA5-Tabelle kodierte Zeichenfolge, siehe ISO 646) CHARACTER STRING UTCTime, GeneralizedTime (Zeit- und Datumsangaben) 8 / 19 Abstrakte Syntaxnotation 1 Beispiel Basic Encoding Rules Literatur Zusammengesetzte Datentypen in ASN.1 SEQUENCE (geordnete Abfolge verschiedener Typen) SEQUENCE OF <Typ> (geordnete Abfolge gleichen Typs) SET (ungeordnete Abfolge verschiedener Typen) SET OF <Typ> (ungeordnete Abfolge gleichen Typs) CHOICE (Summentyp) Beispiele: Coordinates ::= SET { x [1] INTEGER, y [2] INTEGER, z [3] INTEGER OPTIONAL } Lottery-number ::= INTEGER (1..49) Lottery-draw ::= SEQUENCE SIZE (6) OF Lottery-number 9 / 19 Abstrakte Syntaxnotation 1 Beispiel Basic Encoding Rules Literatur Spezielle Datentypen in ASN.1 Spezielle Datentypen in ASN.1: OBJECT IDENTIFIER (weltweit eindeutige Kennung) RELATIVE-OID (relative Objektkennung) Anwendungsfeld Netzmanagement: Management Information Base iso (1) ... dod (6) ... ... internet (1) directory (1) mgmt (2) experimental (3) ... mib-2 (1) OBJECT IDENTIFIER 1.3.6.1.2.1.1.1.0 eindeutige Adressierung des Objekts sysDescr org (3) sysDescr (1) system (1) ... ... ... ... ... private (4) ... enterprises (1) ... ... 10 / 19 Abstrakte Syntaxnotation 1 Beispiel Basic Encoding Rules Literatur Wertezuweisungen in ASN.1 ASN.1 erlaubt die explizite Zuweisung von Werten zu Typen. Beispiele: counter Lottery-number ::= 45 sixtuple Lottery-draw ::= {7, 12, 23, 31, 33, 41} pair Coordinates ::= {x 5, y -3} Es wird keine Aussage darüber gemacht, wie diese Werte zu kodieren sind. 11 / 19 Abstrakte Syntaxnotation 1 Beispiel Basic Encoding Rules Literatur Spezifikation mittels ASN.1 Sammlung von ASN.1-Datentypen. Zusammenfassung zu Modulen, die eine eindeutige Kennung bekommen. Schnittstelle des Moduls wird mit IMPORT und EXPORT angegeben. Beispielhafte Anwendung von ASN.1: Netzmanagement (z. B. in Case u. a. (1993)) Verzeichnisdienste (z. B. in Legg (2004)) 12 / 19 Abstrakte Syntaxnotation 1 Beispiel Basic Encoding Rules Literatur Beispiel: SNMPv2-PDU nach Case u. a. (1993) PDUs ::= CHOICE { get-request get-next-request get-bulk-request response set-request inform-request snmpV2-trap } GetRequest-PDU, GetNextRequest-PDU, GetBulkRequest-PDU, Response-PDU, SetRequest-PDU, InformRequest-PDU, SNMPv2-Trap-PDU 13 / 19 Abstrakte Syntaxnotation 1 Beispiel Basic Encoding Rules Literatur Beispiel: SNMPv2-PDU nach Case u. a. (1993) PDU ::= SEQUENCE { request-id Integer32, error-status INTEGER -- sometimes ignored { noError(0), tooBig(1), noSuchName(2), -- for proxy compatibility badValue(3), -- for proxy compatibility readOnly(4), -- for proxy compatibility genErr(5), noAccess(6), wrongType(7), wrongLength(8), wrongEncoding(9), wrongValue(10), noCreation(11), inconsistentValue(12), resourceUnavailable(13), commitFailed(14), undoFailed(15), authorizationError(16), notWritable(17), inconsistentName(18) }, error-index INTEGER (0..max-bindings), -- sometimes ignored variable-bindings VarBindList -- values are sometimes ignored } 14 / 19 Abstrakte Syntaxnotation 1 Beispiel Basic Encoding Rules Literatur ASN.1: Codierung und Decodierung I Idee für die eindeutige Codierung der ASN.1-Werte: TLV-Ansatz (siehe http://telecom.htwm.de/asn1/index.htm) T – Type: Typangabe L – Length: Längenangabe V – Value: Wertangabe Typ Länge Wert Typ Län -ge Typ Län -ge Typ Wert Wert Län -ge Wert 15 / 19 Abstrakte Syntaxnotation 1 Beispiel Basic Encoding Rules Literatur ASN.1: Codierung und Decodierung II Basiscodierungsregeln — Basic Encoding Rules (BER) (siehe ITU (2008)) Bezeichner Bit 7 6 Typklasse 00: 01: 02: 03: Universal Application Context Specific Private Länge 5 4 3 Inhalt 2 1 0 Datentyp Tag-Nummer 0: einfach 1: strukturiert 0..30: wie angegeben 31: nächstes Byte gibt Tag an 16 / 19 Abstrakte Syntaxnotation 1 Beispiel Basic Encoding Rules Literatur BER – Einfaches Beispiel Codierung des Integer-Werts 5: 0 0 0 0 0 0 1 0 0 0 0 0 0 Länge 0 0 1 0 0 0 0 0 1 0 1 Wert Tag-Nummer = 2 Datentyp INTEGER Einfacher Datentyp UniversalKlasse 17 / 19 Abstrakte Syntaxnotation 1 Beispiel Basic Encoding Rules Literatur BER – Kompliziertes Beispiel ASN.1-Typ: SEQUENCE {name IA5STRING, ok BOOLEAN} ASN.1-Wert: name Smith, ok TRUE Codierung: SEQUENCE 3016 Länge 0A16 Inhalt IA5STRING 1616 BOOLEAN 0116 Länge 0516 Länge 0116 Inhalt Smith Inhalt FF16 (TRUE wird als Byte codiert, das mindestens eine 1 enthält. . . ) 18 / 19 Abstrakte Syntaxnotation 1 Beispiel Basic Encoding Rules Literatur Literatur [Case u. a. 1993] C ASE, Jeffrey D. ; M C C LOGHRIE, Keith ; R OSE, Marshall T. ; WALDBUSSER, Steven: Protocol Operations for Version 2 of the Simple Network Management Protocol (SNMPv2) / Internet Engineering Task Force. URL http://www.rfc-editor.org/rfc/rfc1448.txt, April 1993 (RFC 1448). – Request for Comments [Dubuisson 2000] D UBUISSON, Olivier: ASN.1 – Communication Between Heterogeneous Systems. San Diego : Morgan Kaufmann, 2000. – ISBN 978-01263-3361-9 [ITU 2008] ITU-T S TUDY G ROUP 17: OSI Networking and System Aspects – Abstract Syntax Notation One (ASN.1) — Information Technology – ASN.1 Encoding Rules: Specification of Basic Encoding Rules (BER), Canonical Encoding Rules (CER) and Distinguished Encoding Rules (DER) / International Telecommunication Union – Telecommunication Standardization Sector. URL http://www.itu.int/rec/dologin_pub.asp?lang=e&id=T-REC-X. 690-200811-I!!PDF-E&type=items, November 2008 (ITU-T X.690). – ITU-T X-Series Recommendations – Data Networks, Open System Communications and Security [Legg 2004] L EGG, Steven: ASN.1 Module Definition for the LDAP and X.500 Component Matching Rules / Internet Engineering Task Force. URL http://www.rfc-editor.org/rfc/rfc3727.txt, Februar 2004 (RFC 3727). – Request for Comments 19 / 19