ASN.1
Abstract Syntax Notation One is a standard interface description language for defining data structures that can be serialized and deserialized in a cross-platform way. It is broadly used in telecommunications and computer networking, and especially in cryptography.
Protocol developers define data structures in ASN.1 modules, which are generally a section of a broader standards document written in the ASN.1 language. The advantage is that the ASN.1 description of the data encoding is independent of a particular computer or programming language. Because ASN.1 is both human-readable and machine-readable, an ASN.1 compiler can compile modules into libraries of code, codecs, that decode or encode the data structures. Some ASN.1 compilers can produce code to encode or decode several encodings, e.g. packed, BER or XML.
ASN.1 is a joint standard of the International Telecommunication Union Telecommunication Standardization Sector in ITU-T Study Group 17 and International Organization for Standardization/International Electrotechnical Commission, originally defined in 1984 as part of CCITT X.409:1984. In 1988, ASN.1 moved to its own standard, X.208, due to wide applicability. The substantially revised 1995 version is covered by the X.680-X.683 series. The latest revision of the X.680 series of recommendations is the 6.0 Edition, published in 2021.
Structure
- X.680 defines the basic lexical items of the ASN.1 language. It defines the syntax of a "module definition", the definition of a module within a protocol. A module definition can contain data types, predefined information objects written in those data types, constraint elements, among other things.
- X.681 defines the syntax of an information object, which allows for objects in custom datatypes to be represented in the language. It also defines a way to reference a specific value from an object using a dot notation as if it is a table.
- X.682 defines constraint elements, which can be used to apply more advanced constraints in a module.
- X.683, Parameterization of ASN.1 specifications, allows assignments and definitions to vary according to parameters.
Language support
Applications
ASN.1 is used to define a large number of protocols. Its most extensive uses continue to be telecommunications, cryptography, and biometrics.| Protocol | Specification | Specified or customary encoding rules | Uses |
| Interledger Protocol | Octet Encoding Rules | ||
| NTCIP 1103 - Transport Management Protocols | Octet Encoding Rules | Traffic, Transportation, and Infrastructure Management | |
| X.500 Directory Services | The ITU X.500 Recommendation Series | Basic Encoding Rules, Distinguished Encoding Rules | LDAP, TLS Certificates, Authentication |
| Lightweight Directory Access Protocol | Basic Encoding Rules | ||
| PKCS Cryptography Standards | PKCS Cryptography Standards | Basic Encoding Rules and Distinguished Encoding Rules | Asymmetric Keys, certificate bundles |
| X.400 Message Handling | The ITU X.400 Recommendation Series | An early competitor to email | |
| EMV | EMVCo Publications | Payment cards | |
| T.120 Multimedia conferencing | The ITU T.120 Recommendation Series | Basic Encoding Rules, Packed Encoding Rules | Microsoft's Remote Desktop Protocol |
| Simple Network Management Protocol | Basic Encoding Rules | Managing and monitoring networks and computers, particularly characteristics pertaining to performance and reliability | |
| Common Management Information Protocol | ITU Recommendation | A competitor to SNMP but more capable and not nearly as popular | |
| Signalling System No. 7 | The ITU Q.700 Recommendation Series | Managing telephone connections over the Public Switched Telephone Network | |
| ITU H-Series Multimedia Protocols | The ITU H.200, H.300, and H.400 Recommendation Series | Voice Over Internet Protocol | |
| BioAPI Interworking Protocol | |||
| Common Biometric Exchange Formats Framework | Basic Encoding Rules | ||
| Authentication Contexts for Biometrics | |||
| Computer-supported telecommunications applications | Basic Encoding Rules | ||
| Dedicated short-range communications | Packed Encoding Rules | Vehicle communication | |
| IEEE 802.11p | Vehicle communication | ||
| Intelligent Transport Systems | Unaligned Packed Encoding Rules | Vehicle communication | |
| Global System for Mobile Communications | 2G Mobile Phone Communications | ||
| General Packet Radio Service / Enhanced Data rates for GSM Evolution | 2.5G Mobile Phone Communications | ||
| Universal Mobile Telecommunications System | 3G Mobile Phone Communications | ||
| Long-Term Evolution | 4G Mobile Phone Communications | ||
| 5G | 5G Mobile Phone Communications | ||
| Common Alerting Protocol | XML Encoding Rules | Exchanging Alert Information, such as Amber Alerts | |
| Controller–pilot data link communications | Aeronautics communications | ||
| Space Link Extension Services | Space systems communications | ||
| Manufacturing Message Specification | Manufacturing | ||
| File Transfer, Access and Management | An early and more capable competitor to File Transfer Protocol, but its rarely used anymore. | ||
| Remote Operations Service Element protocol | ITU Recommendations X.880, X.881, and X.882 | An early form of Remote procedure call | |
| Association Control Service Element | ITU Recommendation | ||
| Building Automation and Control Networks Protocol | BACnet Encoding Rules | Building automation and control, such as with fire alarms, elevators, HVAC systems, etc. | |
| Kerberos | Basic Encoding Rules | Secure authentication | |
| WiMAX 2 | Wide Area Networks | ||
| Intelligent Network | The ITU Q.1200 Recommendation Series | Telecommunications and computer networking | |
| X2AP | Basic Aligned Packed Encoding Rules | ||
| Lawful Interception Handover Interface | Lawful Interception |
Encodings
ASN.1 is closely associated with a set of encoding rules that specify how to represent a data structure as a series of bytes. The standard ASN.1 encoding rules include:Encoding Control Notation
ASN.1 recommendations provide a number of predefined encoding rules. If none of the existing encoding rules are suitable, the Encoding Control Notation provides a way for a user to define his or her own customized encoding rules.Relation to Privacy-Enhanced Mail (PEM) Encoding
encoding is entirely unrelated to ASN.1 and its codecs, but encoded ASN.1 data, which is often binary, is often PEM-encoded so that it can be transmitted as textual data, e.g. over SMTP relays, or through copy/paste buffers.As computer files
ASN.1 language and encoding specifications do not specify details such as what filename extension to use when a chunk of data is stored as a file on a computer. Nevertheless, some conventions have arisen:- ASN.1-language text: extensions of
.asn1and.allhave been used for general files..asnhas been used for files only containing module definitions and.prtfor files only containing value definitions. - BER-encoded data:
.berhas been used. There is also a proposed MIME typeapplication/ber-streamwhich includes aprotocolparameter specifying an associated OID. - * DER-encoded data:
.der. For DER-encoded X.509 certificates,.cerand.crtin addition to.der. The MIME typeapplication/x-x509-ca-certis specifically for DER-encoded certificates, not general DER data. - Other encoded data:
asn1csample files use.xerfor XER,.perfor PER, and.coerfor COER.Example
Module and constraint
This is an example ASN.1 module defining the messages of a fictitious Foo Protocol:FooProtocol DEFINITIONS ::= BEGIN
FooQuestion ::= SEQUENCE
FooAnswer ::= SEQUENCE
END
This could be a specification published by creators of Foo Protocol. Conversation flows, transaction interchanges, and states are not defined in ASN.1, but are left to other notations and textual description of the protocol.
ASN.1 supports constraints on values and sizes, and extensibility. The above specification can be changed to:
FooProtocol DEFINITIONS ::= BEGIN
FooQuestion ::= SEQUENCE
FooAnswer ::= SEQUENCE
FooHistory ::= SEQUENCE
END
This change constrains trackingNumbers to have a value between 0 and 199 inclusive, and questionNumbers to have a value between 10 and 20 inclusive. The size of the questions array can be between 0 and 10 elements, with the answers array between 1 and 10 elements. The anArray field is a fixed length 100 element array of integers that must be in the range 0 to 1000. The '...' extensibility marker means that the FooHistory message specification may have additional fields in future versions of the specification; systems compliant with one version should be able to receive and transmit transactions from a later version, though able to process only the fields specified in the earlier version. Good ASN.1 compilers will generate source code that will automatically check that transactions fall within these constraints. Transactions that violate the constraints should not be accepted from, or presented to, the application. Constraint management in this layer significantly simplifies protocol specification because the applications will be protected from constraint violations, reducing risk and cost.
The above examples only make use of syntax from X.680. More advanced constraints from X.682 are not used.