4 # Copyright (c) 2020 Project CHIP Authors
5 # Copyright (c) 2019 Google LLC.
6 # Copyright (c) 2013-2017 Nest Labs, Inc.
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
24 # This file implements a Python script to generate a C/C++ header
25 # for individual ASN1 Object IDs (OIDs) that are used in CHIP
26 # TLV encodings (notably the CHIP Certificate object).
29 from __future__ import absolute_import
30 from __future__ import print_function
41 characteristicTwo = identity
45 digest_algorithm = identity
49 organization = identity
53 joint_iso_ccitt = identity
56 member_body = identity
71 ( "PubKeyAlgo", 0x0100 ),
72 ( "SigAlgo", 0x0200 ),
73 ( "AttributeType", 0x0300 ),
74 ( "EllipticCurve", 0x0400 ),
75 ( "Extension", 0x0500 ),
76 ( "KeyPurpose", 0x0600 )
79 # Table of well-known ASN.1 object IDs
85 # The enumerated values associated with individual object IDs are used in CHIP TLV encodings (notably the CHIP Certificate object).
86 # Because of this, the Enum Values assigned to object IDs in this table MUST NOT BE CHANGED once in use.
90 # Category Name Value Object ID
91 # ----------------- -------------------------- -------- ------------------------------------------------------------------------------------------------
93 # Public Key Algorithms
94 ( "PubKeyAlgo", "ECPublicKey", 1, [ iso(1), member_body(2), us(840), ansi_X9_62(10045), keyType(2), 1 ] ),
96 # Signature Algorithms
98 ( "SigAlgo", "ECDSAWithSHA256", 1, [ iso(1), member_body(2), us(840), ansi_X9_62(10045), signatures(4), 3, 2 ] ),
100 # X.509 Distinguished Name Attribute Types
101 # WARNING -- Assign no values higher than 127.
102 ( "AttributeType", "CommonName", 1, [ joint_iso_ccitt(2), ds(5), 4, 3 ] ),
103 ( "AttributeType", "Surname", 2, [ joint_iso_ccitt(2), ds(5), 4, 4 ] ),
104 ( "AttributeType", "SerialNumber", 3, [ joint_iso_ccitt(2), ds(5), 4, 5 ] ),
105 ( "AttributeType", "CountryName", 4, [ joint_iso_ccitt(2), ds(5), 4, 6 ] ),
106 ( "AttributeType", "LocalityName", 5, [ joint_iso_ccitt(2), ds(5), 4, 7 ] ),
107 ( "AttributeType", "StateOrProvinceName", 6, [ joint_iso_ccitt(2), ds(5), 4, 8 ] ),
108 ( "AttributeType", "OrganizationName", 7, [ joint_iso_ccitt(2), ds(5), 4, 10 ] ),
109 ( "AttributeType", "OrganizationalUnitName", 8, [ joint_iso_ccitt(2), ds(5), 4, 11 ] ),
110 ( "AttributeType", "Title", 9, [ joint_iso_ccitt(2), ds(5), 4, 12 ] ),
111 ( "AttributeType", "Name", 10, [ joint_iso_ccitt(2), ds(5), 4, 41 ] ),
112 ( "AttributeType", "GivenName", 11, [ joint_iso_ccitt(2), ds(5), 4, 42 ] ),
113 ( "AttributeType", "Initials", 12, [ joint_iso_ccitt(2), ds(5), 4, 43 ] ),
114 ( "AttributeType", "GenerationQualifier", 13, [ joint_iso_ccitt(2), ds(5), 4, 44 ] ),
115 ( "AttributeType", "DNQualifier", 14, [ joint_iso_ccitt(2), ds(5), 4, 46 ] ),
116 ( "AttributeType", "Pseudonym", 15, [ joint_iso_ccitt(2), ds(5), 4, 65 ] ),
117 ( "AttributeType", "DomainComponent", 16, [ itu_t(0), 9, 2342, 19200300, 100, 1, 25 ] ),
118 ( "AttributeType", "ChipNodeId", 17, [ iso(1), organization(3), dod(6), internet(1), private(4), enterprise(1), zigbee(37244), chip(1), 1 ] ),
119 ( "AttributeType", "ChipCAId", 18, [ iso(1), organization(3), dod(6), internet(1), private(4), enterprise(1), zigbee(37244), chip(1), 2 ] ),
120 ( "AttributeType", "ChipSoftwarePublisherId", 19, [ iso(1), organization(3), dod(6), internet(1), private(4), enterprise(1), zigbee(37244), chip(1), 3 ] ),
121 ( "AttributeType", "ChipFabricId", 20, [ iso(1), organization(3), dod(6), internet(1), private(4), enterprise(1), zigbee(37244), chip(1), 4 ] ),
124 ( "EllipticCurve", "prime256v1", 1, [ iso(1), member_body(2), us(840), ansi_X9_62(10045), curves(3), prime(1), 7 ] ),
126 # Certificate Extensions
127 ( "Extension", "AuthorityKeyIdentifier", 1, [ joint_iso_ccitt(2), ds(5), 29, 35 ] ),
128 ( "Extension", "SubjectKeyIdentifier", 2, [ joint_iso_ccitt(2), ds(5), 29, 14 ] ),
129 ( "Extension", "KeyUsage", 3, [ joint_iso_ccitt(2), ds(5), 29, 15 ] ),
130 ( "Extension", "BasicConstraints", 4, [ joint_iso_ccitt(2), ds(5), 29, 19 ] ),
131 ( "Extension", "ExtendedKeyUsage", 5, [ joint_iso_ccitt(2), ds(5), 29, 37 ] ),
134 ( "KeyPurpose", "ServerAuth", 1, [ iso(1), organization(3), dod(6), internet(1), security(5), mechanisms(5), pkix(7), 3, 1 ] ),
135 ( "KeyPurpose", "ClientAuth", 2, [ iso(1), organization(3), dod(6), internet(1), security(5), mechanisms(5), pkix(7), 3, 2 ] ),
136 ( "KeyPurpose", "CodeSigning", 3, [ iso(1), organization(3), dod(6), internet(1), security(5), mechanisms(5), pkix(7), 3, 3 ] ),
137 ( "KeyPurpose", "EmailProtection", 4, [ iso(1), organization(3), dod(6), internet(1), security(5), mechanisms(5), pkix(7), 3, 4 ] ),
138 ( "KeyPurpose", "TimeStamping", 5, [ iso(1), organization(3), dod(6), internet(1), security(5), mechanisms(5), pkix(7), 3, 8 ] ),
139 ( "KeyPurpose", "OCSPSigning", 6, [ iso(1), organization(3), dod(6), internet(1), security(5), mechanisms(5), pkix(7), 3, 9 ] ),
147 oid = [ (oid[0]*40 + oid[1]) ] + oid[2:]
151 val, byte = divmod(val, 128)
154 val, byte = divmod(val, 128)
155 seg.insert(0, byte + 0x80)
163 * Copyright (c) 2020 Project CHIP Authors
164 * Copyright (c) 2019 Google LLC.
165 * Copyright (c) 2013-2017 Nest Labs, Inc.
166 * All rights reserved.
168 * Licensed under the Apache License, Version 2.0 (the \"License\");
169 * you may not use this file except in compliance with the License.
170 * You may obtain a copy of the License at
172 * http://www.apache.org/licenses/LICENSE-2.0
174 * Unless required by applicable law or agreed to in writing, software
175 * distributed under the License is distributed on an \"AS IS\" BASIS,
176 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
177 * See the License for the specific language governing permissions and
178 * limitations under the License.
184 * ASN.1 Object ID Definitions
186 * !!! WARNING !!! WARNING !!! WARNING !!!
188 * DO NOT EDIT THIS FILE! This file is generated by the
189 * gen-oid-table.py script.
191 * To make changes, edit the script and re-run it to generate
199 %(oid_category_enums)s
201 typedef uint16_t OID;
209 const uint8_t *EncodedOID;
210 uint16_t EncodedOIDLen;
213 struct OIDNameTableEntry
219 extern const OIDTableEntry sOIDTable[];
220 extern const OIDNameTableEntry sOIDNameTable[];
221 extern const size_t sOIDTableSize;
223 #ifdef ASN1_DEFINE_OID_TABLE
226 const OIDTableEntry sOIDTable[] =
229 const size_t sOIDTableSize = sizeof(sOIDTable) / sizeof(OIDTableEntry);
231 #endif // ASN1_DEFINE_OID_TABLE
233 #ifdef ASN1_DEFINE_OID_NAME_TABLE
235 const OIDNameTableEntry sOIDNameTable[] =
238 #endif // ASN1_DEFINE_OID_NAME_TABLE
241 oid_category_enums ="{\n"
242 for (catName, catEnum) in oidCategories:
243 oid_category_enums +=" kOIDCategory_%s = 0x%04X,\n" % (catName, catEnum)
244 oid_category_enums +='''
245 kOIDCategory_NotSpecified = 0,
246 kOIDCategory_Unknown = 0x0F00,
247 kOIDCategory_Mask = 0x0F00
251 for (catName, catEnum) in oidCategories:
252 for (oidCatName, oidName, oidEnum, oid) in oids:
253 if (oidCatName == catName):
254 oid_enums +=" kOID_%s_%s = 0x%04X,\n" % (catName, oidName, catEnum + oidEnum)
256 oid_enums +=''' kOID_NotSpecified = 0,
257 kOID_Unknown = 0xFFFF,
258 kOID_EnumMask = 0x00FF
261 oid_utf8_strings ="\n"
262 for (catName, oidName, oidEnum, oid) in oids:
263 oid_utf8_strings +="static const uint8_t sOID_%s_%s[] = { %s };\n" % (catName, oidName, ", ".join([ "0x%02X" % (x) for x in encodeOID(oid) ]))
266 for (catName, oidName, oidEnum, oid) in oids:
267 oid_table +=" { kOID_%s_%s, sOID_%s_%s, sizeof(sOID_%s_%s) },\n" % (catName, oidName, catName, oidName, catName, oidName)
268 oid_table +=" { kOID_NotSpecified, NULL, 0 }\n};"
270 oid_name_table ="{\n"
271 for (catName, oidName, oidEnum, oid) in oids:
272 oid_name_table +=" { kOID_%s_%s, \"%s\" },\n" % (catName, oidName, oidName)
273 oid_name_table +=" { kOID_NotSpecified, NULL }\n};"
277 parser = optparse.OptionParser()
279 parser.add_option('--output_file')
281 options, _ = parser.parse_args(argv)
284 'oid_category_enums': oid_category_enums,
285 'oid_enums': oid_enums,
286 'oid_utf8_strings': oid_utf8_strings,
287 'oid_table': oid_table,
288 'oid_name_table': oid_name_table,
291 with open(options.output_file, 'w') as asn1oid_file:
292 asn1oid_file.write(TEMPLATE % template_args)
296 if __name__ == '__main__':
297 sys.exit(main(sys.argv[1:]))