SharkSSL™ Embedded SSL/TLS Stack
SharkSslASN1.h
Go to the documentation of this file.
1/*
2 * ____ _________ __ _
3 * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4 * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5 * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6 * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7 * /____/
8 *
9 * SharkSSL Embedded SSL/TLS Stack
10 ****************************************************************************
11 * PROGRAM MODULE
12 *
13 * $Id: SharkSslASN1.h 3670 2015-03-28 21:25:15Z gianluca $
14 *
15 * COPYRIGHT: Real Time Logic LLC, 2018 - 2026
16 *
17 * This software is copyrighted by and is the sole property of Real
18 * Time Logic LLC. All rights, title, ownership, or other interests in
19 * the software remain the property of Real Time Logic LLC. This
20 * software may only be used in accordance with the terms and
21 * conditions stipulated in the corresponding license agreement under
22 * which the software has been supplied. Any unauthorized use,
23 * duplication, transmission, distribution, or disclosure of this
24 * software is expressly forbidden.
25 *
26 * This Copyright notice may not be removed or modified without prior
27 * written consent of Real Time Logic LLC.
28 *
29 * Real Time Logic LLC. reserves the right to modify this software
30 * without notice.
31 *
32 * http://www.realtimelogic.com
33 * http://www.sharkssl.com
34 ****************************************************************************
35 *
36 */
37#ifndef _SharkSslASN1_h
38#define _SharkSslASN1_h
39
45#include "SharkSslEx.h"
46
53#define SHARKSSL_ASN1_BOOLEAN 0x01
54#define SHARKSSL_ASN1_INTEGER 0x02
55#define SHARKSSL_ASN1_BIT_STRING 0x03
56#define SHARKSSL_ASN1_OCTET_STRING 0x04
57#define SHARKSSL_ASN1_NULL 0x05
58#define SHARKSSL_ASN1_OID 0x06
59#define SHARKSSL_ASN1_UTF8_STRING 0x0C
60#define SHARKSSL_ASN1_SEQUENCE 0x10
61#define SHARKSSL_ASN1_SET 0x11
62#define SHARKSSL_ASN1_PRINTABLE_STRING 0x13
63#define SHARKSSL_ASN1_T61_STRING 0x14
64#define SHARKSSL_ASN1_IA5_STRING 0x16
65#define SHARKSSL_ASN1_UTC_TIME 0x17
66#define SHARKSSL_ASN1_GENERALIZED_TIME 0x18
67#define SHARKSSL_ASN1_BMP_STRING 0x1E
68#define SHARKSSL_ASN1_CONSTRUCTED 0x20
69#define SHARKSSL_ASN1_CONTEXT_SPECIFIC 0x80
70
74#define SHARKSSL_OID_JIIT_DS 0x55
75#define SHARKSSL_OID_JIIT_DS_ATTRTYPE 0x04
76#define SHARKSSL_OID_JIIT_DS_ATTRTYPE_CN 0x03
77#define SHARKSSL_OID_JIIT_DS_ATTRTYPE_SERIAL 0x05
78#define SHARKSSL_OID_JIIT_DS_ATTRTYPE_COUNTRY 0x06
79#define SHARKSSL_OID_JIIT_DS_ATTRTYPE_LOCALITY 0x07
80#define SHARKSSL_OID_JIIT_DS_ATTRTYPE_PROVINCE 0x08
81#define SHARKSSL_OID_JIIT_DS_ATTRTYPE_ORGANIZATION 0x0A
82#define SHARKSSL_OID_JIIT_DS_ATTRTYPE_UNIT 0x0B
86#define SHARKSSL_OID_JIIT_DS_CERTEXT 0x1D
87#define SHARKSSL_OID_JIIT_DS_CERTEXT_KEYUSAGE 0x0F
88#define SHARKSSL_OID_JIIT_DS_CERTEXT_SUBJALTNAMES 0x11
89#define SHARKSSL_OID_JIIT_DS_CERTEXT_BASICCONSTRAINTS 0x13
90
96#define SHARKSSL_CSR_TAG_ATTRIBUTES 0x00
97
103#define SHARKSSL_X509_TAG_VERSION 0x00
104#define SHARKSSL_X509_TAG_ISSUERUNIQUEID 0x01
105#define SHARKSSL_X509_TAG_SUBJECTUNIQUEID 0x02
106#define SHARKSSL_X509_TAG_EXTENSIONS 0x03
107
112#define SHARKSSL_ECC_PRIVKEY_TAG_PARAMETERS 0x00
113#define SHARKSSL_ECC_PRIVKEY_TAG_PUBLIC_KEY 0x01
114
118#define SHARKSSL_X509_KU_DIGITAL_SIGNATURE 0x80
119#define SHARKSSL_X509_KU_NON_REPUDIATION 0x40
120#define SHARKSSL_X509_KU_KEY_ENCIPHERMENT 0x20
121#define SHARKSSL_X509_KU_DATA_ENCIPHERMENT 0x10
122#define SHARKSSL_X509_KU_KEY_AGREEMENT 0x08
123#define SHARKSSL_X509_KU_KEY_CERT_SIGN 0x04
124#define SHARKSSL_X509_KU_CRL_SIGN 0x02
125
130#define SHARKSSL_X509_NS_CERT_TYPE_SSL_CLIENT 0x80
131#define SHARKSSL_X509_NS_CERT_TYPE_SSL_SERVER 0x40
132#define SHARKSSL_X509_NS_CERT_TYPE_OBJECT_SIGNING 0x10
133#define SHARKSSL_X509_NS_CERT_TYPE_SSL_CA 0x04
134#define SHARKSSL_X509_NS_CERT_TYPE_OBJECT_SIGNING_CA 0x01
135
136
139
140
141/* OID's - length has to match the content in SharkSslASN1.c */
142extern const U8 sharkssl_oid_CN[3];
143extern const U8 sharkssl_oid_serial[3];
144extern const U8 sharkssl_oid_country[3];
145extern const U8 sharkssl_oid_locality[3];
146extern const U8 sharkssl_oid_province[3];
147extern const U8 sharkssl_oid_organization[3];
148extern const U8 sharkssl_oid_unit[3];
149extern const U8 sharkssl_oid_emailAddress[9];
150extern const U8 sharkssl_oid_csr_ext_req[9];
151extern const U8 sharkssl_oid_signedData[9];
152extern const U8 sharkssl_oid_ns_cert_type[9];
153extern const U8 sharkssl_oid_key_usage[3];
154extern const U8 sharkssl_oid_san[3];
155extern const U8 sharkssl_oid_basic_constraints[3];
156extern const U8 sharkssl_oid_ecPublicKey[7];
157extern const U8 sharkssl_oid_prime192v1[8];
158extern const U8 sharkssl_oid_prime256v1[8];
159extern const U8 sharkssl_oid_ecdsaWithSHA1[7];
160extern const U8 sharkssl_oid_ecdsaWithSHA256[8];
161extern const U8 sharkssl_oid_ecdsaWithSHA384[8];
162extern const U8 sharkssl_oid_ecdsaWithSHA512[8];
163extern const U8 sharkssl_oid_secp224r1[5];
164extern const U8 sharkssl_oid_secp384r1[5];
165extern const U8 sharkssl_oid_secp521r1[5];
166extern const U8 sharkssl_oid_brainpoolP256r1[9];
167extern const U8 sharkssl_oid_brainpoolP384r1[9];
168extern const U8 sharkssl_oid_brainpoolP512r1[9];
169extern const U8 sharkssl_oid_curve25519[9];
170extern const U8 sharkssl_oid_rsaEncryption[9];
171extern const U8 sharkssl_oid_md2withRSAEncryption[9];
172extern const U8 sharkssl_oid_md5withRSAEncryption[9];
173extern const U8 sharkssl_oid_sha1withRSAEncryption[9];
174extern const U8 sharkssl_oid_sha256withRSAEncryption[9];
175extern const U8 sharkssl_oid_sha384withRSAEncryption[9];
176extern const U8 sharkssl_oid_sha512withRSAEncryption[9];
177extern const U8 sharkssl_oid_md5[8];
178extern const U8 sharkssl_oid_sha1[5];
179extern const U8 sharkssl_oid_sha256[9];
180extern const U8 sharkssl_oid_sha384[9];
181extern const U8 sharkssl_oid_sha512[9];
182extern const U8 sharkssl_oid_pkcs5PBES2[9];
183extern const U8 sharkssl_oid_pkcs5PBKDF2[9];
184extern const U8 sharkssl_oid_HMACWithSHA256[8];
185#if SHARKSSL_ENABLE_AES_CBC
186extern const U8 sharkssl_oid_aes128cbc[9];
187extern const U8 sharkssl_oid_aes256cbc[9];
188#endif
189#if (SHARKSSL_ENABLE_RSA && SHARKSSL_ENABLE_RSASSA_PSS)
190extern const U8 sharkssl_oid_rsassaPss[9];
191extern const U8 sharkssl_oid_mgf1[9];
192#endif
193
194
195#define sharkssl_oid_ex(type) (const U8*)sharkssl_oid_ ## type, (sizeof(sharkssl_oid_ ## type)/sizeof(sharkssl_oid_ ## type[0]))
196
197
198
199/* never call these functions directly but only through the macros below */
200int SharkSslParseASN1_getLength(SharkSslParseASN1 *o);
201SHARKSSL_API int SharkSslParseASN1_getType(SharkSslParseASN1 *o, U8 ASN1type); /* dataptr, datalen are valid */
202SHARKSSL_API int SharkSslParseASN1_getSetSeq(SharkSslParseASN1 *o, U8 ASN1id);
203
204#define SharkSslParseASN1_getBool(o) SharkSslParseASN1_getType(o, SHARKSSL_ASN1_BOOLEAN)
205#define SharkSslParseASN1_getInt(o) SharkSslParseASN1_getType(o, SHARKSSL_ASN1_INTEGER)
206#define SharkSslParseASN1_getBitString(o) SharkSslParseASN1_getType(o, SHARKSSL_ASN1_BIT_STRING)
207#define SharkSslParseASN1_getOctetString(o) SharkSslParseASN1_getType(o, SHARKSSL_ASN1_OCTET_STRING)
208#define SharkSslParseASN1_getNULL(o) SharkSslParseASN1_getType(o, SHARKSSL_ASN1_NULL)
209#define SharkSslParseASN1_getOID(o) SharkSslParseASN1_getType(o, SHARKSSL_ASN1_OID)
210#define SharkSslParseASN1_getUTCTime(o) SharkSslParseASN1_getType(o, SHARKSSL_ASN1_UTC_TIME)
211#define SharkSslParseASN1_getGenTime(o) SharkSslParseASN1_getType(o, SHARKSSL_ASN1_GENERALIZED_TIME)
212#define SharkSslParseASN1_getIssuerUniqueID(o) SharkSslParseASN1_getType(o, SHARKSSL_ASN1_CONTEXT_SPECIFIC | SHARKSSL_ASN1_CONSTRUCTED | SHARKSSL_X509_TAG_ISSUERUNIQUEID)
213#define SharkSslParseASN1_getSubjectUniqueID(o) SharkSslParseASN1_getType(o, SHARKSSL_ASN1_CONTEXT_SPECIFIC | SHARKSSL_ASN1_CONSTRUCTED | SHARKSSL_X509_TAG_SUBJECTUNIQUEID)
214#define SharkSslParseASN1_getExtensions(o) SharkSslParseASN1_getType(o, SHARKSSL_ASN1_CONTEXT_SPECIFIC | SHARKSSL_ASN1_CONSTRUCTED | SHARKSSL_X509_TAG_EXTENSIONS)
215#define SharkSslParseASN1_getCSRAttributes(o) SharkSslParseASN1_getType(o, SHARKSSL_ASN1_CONTEXT_SPECIFIC | SHARKSSL_ASN1_CONSTRUCTED | SHARKSSL_CSR_TAG_ATTRIBUTES)
216
217#define SharkSslParseASN1_getECParameters(o) SharkSslParseASN1_getSetSeq(o, SHARKSSL_ASN1_CONTEXT_SPECIFIC | SHARKSSL_ASN1_CONSTRUCTED | SHARKSSL_ECC_PRIVKEY_TAG_PARAMETERS)
218#define SharkSslParseASN1_getECPublicKey(o) SharkSslParseASN1_getSetSeq(o, SHARKSSL_ASN1_CONTEXT_SPECIFIC | SHARKSSL_ASN1_CONSTRUCTED | SHARKSSL_ECC_PRIVKEY_TAG_PUBLIC_KEY)
219#define SharkSslParseASN1_getVersion(o) SharkSslParseASN1_getSetSeq(o, SHARKSSL_ASN1_CONTEXT_SPECIFIC | SHARKSSL_ASN1_CONSTRUCTED | SHARKSSL_X509_TAG_VERSION)
220#define SharkSslParseASN1_getSet(o) SharkSslParseASN1_getSetSeq(o, SHARKSSL_ASN1_CONSTRUCTED | SHARKSSL_ASN1_SET)
221#define SharkSslParseASN1_getSequence(o) SharkSslParseASN1_getSetSeq(o, SHARKSSL_ASN1_CONSTRUCTED | SHARKSSL_ASN1_SEQUENCE)
222
223int SharkSslParseASN1_getContextSpecific(SharkSslParseASN1 *o, U8 *tag);
224int SharkSslParseASN1_parseCertSignatureAlgorithm(SharkSslParseASN1 *o);
225
226
232typedef struct SharkSslASN1Create
233{
234 U8 *start;
235 U8 *end;
236 U8 *ptr;
238
243typedef struct SharkSslBitExtReq
244{
245 U8 bits;
247
248
249#define SharkSslASN1Create_getLen(o) ((int)((o)->end - (o)->ptr))
250#define SharkSslASN1Create_getData(o) ((o)->ptr)
251
257#define SharkSslASN1Create_getDataLen(o, startOfDataPtr) (*(startOfDataPtr) = (o)->ptr, (int)((o)->end - (o)->ptr))
258
259SHARKSSL_API void SharkSslASN1Create_constructor(SharkSslASN1Create *o, U8 *buf, int bufSize);
260SHARKSSL_API int SharkSslASN1Create_int(SharkSslASN1Create *o, const U8 *intptr, int len);
261
262SHARKSSL_API int SharkSslASN1Create_length(SharkSslASN1Create *o, int len);
263SHARKSSL_API int SharkSslASN1Create_tag(SharkSslASN1Create *o, U8 ASN1type);
264
265#define SharkSslASN1Create_bitString(o) SharkSslASN1Create_tag(o, SHARKSSL_ASN1_BIT_STRING)
266#define SharkSslASN1Create_octetString(o) SharkSslASN1Create_tag(o, SHARKSSL_ASN1_OCTET_STRING)
267#define SharkSslASN1Create_printableString(o) SharkSslASN1Create_tag(o, SHARKSSL_ASN1_PRINTABLE_STRING)
268#define SharkSslASN1Create_IA5String(o) SharkSslASN1Create_tag(o, SHARKSSL_ASN1_IA5_STRING)
269#define SharkSslASN1Create_extensions(o) SharkSslASN1Create_tag(o, SHARKSSL_ASN1_CONTEXT_SPECIFIC | SHARKSSL_ASN1_CONSTRUCTED | SHARKSSL_X509_TAG_EXTENSIONS)
270#define SharkSslASN1Create_version(o) SharkSslASN1Create_tag(o, SHARKSSL_ASN1_CONTEXT_SPECIFIC | SHARKSSL_ASN1_CONSTRUCTED | SHARKSSL_X509_TAG_VERSION)
271#define SharkSslASN1Create_CSRAttributes(o) SharkSslASN1Create_tag(o, SHARKSSL_ASN1_CONTEXT_SPECIFIC | SHARKSSL_ASN1_CONSTRUCTED | SHARKSSL_CSR_TAG_ATTRIBUTES)
272#define SharkSslASN1Create_ECParameters(o) SharkSslASN1Create_tag(o, SHARKSSL_ASN1_CONTEXT_SPECIFIC | SHARKSSL_ASN1_CONSTRUCTED | SHARKSSL_ECC_PRIVKEY_TAG_PARAMETERS)
273#define SharkSslASN1Create_ECPublicKey(o) SharkSslASN1Create_tag(o, SHARKSSL_ASN1_CONTEXT_SPECIFIC | SHARKSSL_ASN1_CONSTRUCTED | SHARKSSL_ECC_PRIVKEY_TAG_PUBLIC_KEY)
274
275#define SharkSslASN1Create_set(o) SharkSslASN1Create_tag(o, SHARKSSL_ASN1_CONSTRUCTED | SHARKSSL_ASN1_SET)
276#define SharkSslASN1Create_sequence(o) SharkSslASN1Create_tag(o, SHARKSSL_ASN1_CONSTRUCTED | SHARKSSL_ASN1_SEQUENCE)
277
278#if (SHARKSSL_ENABLE_CSR_CREATION || SHARKSSL_ENABLE_CSR_SIGNING || SHARKSSL_ENABLE_ASN1_KEY_CREATION)
279SHARKSSL_API int SharkSslASN1Create_oid(SharkSslASN1Create *o, const U8 *oid, int oidLen);
280SHARKSSL_API int SharkSslASN1Create_raw(SharkSslASN1Create *o, const void *data, int size);
281#endif
282#if (SHARKSSL_ENABLE_CSR_CREATION || SHARKSSL_ENABLE_CSR_SIGNING)
283SHARKSSL_API int SharkSslASN1Create_email(SharkSslASN1Create *o, const U8 *oid, int oidLen, const U8 *email, int emailLen);
284SHARKSSL_API int SharkSslASN1Create_name(SharkSslASN1Create *o, const U8 *oid, int oidLen, const U8 *name, int nameLen);
285#endif
286#if (SHARKSSL_ENABLE_CSR_SIGNING)
287SHARKSSL_API int SharkSslASN1Create_boolean(SharkSslASN1Create *o, U8 boolean);
288#endif
289
290
291/* Semi public (non documented) types and functions */
292SHARKSSL_API int sharkssl_PEM_getSeqVersion(SharkSslParseASN1 *parseKey, U32 len);
293SHARKSSL_API U8 SharkSslParseASN1_getAlgoID(const SharkSslParseASN1 *o);
294SHARKSSL_API U8 SharkSslParseASN1_getCurveID(const SharkSslParseASN1 *o);
295
296/* heterogeneous usage of _getAlgoID to detect ecPublicKey OID in EC
297 * public certs
298*/
299#define ALGO_OID_EC_PUBLIC_KEY SHARKSSL_OID_EC_PUBLIC_KEY
300
301#define SHARKSSL_EC_CURVE_ID_UNKNOWN 0
302#define SHARKSSL_EC_POINT_UNCOMPRESSED 0x04
303
304
305#endif
struct SharkSslBitExtReq SharkSslBitExtReq
https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/nss_tech_notes/nss_tech_note3 http://to...
struct SharkSslASN1Create SharkSslASN1Create
Opaque object used when creating ASN.1 encoded data.
Opaque object used when creating ASN.1 encoded data.
Definition: SharkSslASN1.h:233
https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/nss_tech_notes/nss_tech_note3 http://to...
Definition: SharkSslASN1.h:244
SubjectAltName Iterator.
Definition: SharkSslEx.h:52