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

ASN.1 is a data type declaration notation. It does not define how to manipulate a variable of such a type. Manipulation of variables is defined in other languages such as SDL for executable modeling or TTCN-3 for conformance testing. Both these languages natively support ASN.1 declarations. It is possible to import an ASN.1 module and declare a variable of any of the ASN.1 types declared in the module.

Applications

ASN.1 is used to define a large number of protocols. Its most extensive uses continue to be telecommunications, cryptography, and biometrics.
ProtocolSpecificationSpecified or customary encoding rulesUses
Interledger ProtocolOctet Encoding Rules
NTCIP 1103 - Transport Management ProtocolsOctet Encoding RulesTraffic, Transportation, and Infrastructure Management
X.500 Directory ServicesThe ITU X.500 Recommendation SeriesBasic Encoding Rules, Distinguished Encoding RulesLDAP, TLS Certificates, Authentication
Lightweight Directory Access Protocol Basic Encoding Rules
PKCS Cryptography StandardsPKCS Cryptography StandardsBasic Encoding Rules and Distinguished Encoding RulesAsymmetric Keys, certificate bundles
X.400 Message HandlingThe ITU X.400 Recommendation SeriesAn early competitor to email
EMVEMVCo PublicationsPayment cards
T.120 Multimedia conferencingThe ITU T.120 Recommendation SeriesBasic Encoding Rules, Packed Encoding RulesMicrosoft's Remote Desktop Protocol
Simple Network Management Protocol Basic Encoding RulesManaging 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 SeriesManaging telephone connections over the Public Switched Telephone Network
ITU H-Series Multimedia ProtocolsThe ITU H.200, H.300, and H.400 Recommendation SeriesVoice 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 RulesVehicle communication
IEEE 802.11p Vehicle communication
Intelligent Transport Systems
Unaligned Packed Encoding RulesVehicle 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
5G5G Mobile Phone Communications
Common Alerting Protocol XML Encoding RulesExchanging 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.882An early form of Remote procedure call
Association Control Service Element ITU Recommendation
Building Automation and Control Networks Protocol BACnet Encoding RulesBuilding automation and control, such as with fire alarms, elevators, HVAC systems, etc.
KerberosBasic Encoding RulesSecure authentication
WiMAX 2Wide Area Networks
Intelligent NetworkThe ITU Q.1200 Recommendation SeriesTelecommunications and computer networking
X2APBasic Aligned Packed Encoding Rules
Lawful Interception Handover InterfaceLawful 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 .asn1 and .all have been used for general files. .asn has been used for files only containing module definitions and .prt for files only containing value definitions.
  • BER-encoded data: .ber has been used. There is also a proposed MIME type application/ber-stream which includes a protocol parameter specifying an associated OID.
  • * DER-encoded data: .der. For DER-encoded X.509 certificates, .cer and .crt in addition to .der. The MIME type application/x-x509-ca-cert is specifically for DER-encoded certificates, not general DER data.
  • Other encoded data: asn1c sample files use .xer for XER, .per for PER, and .coer for 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.