2 * Copyright (C) 2000-2004 Andreas Steffen, Zuercher Hochschule Winterthur
3 * Copyright (C) 2006 Martin Will, Hochschule fuer Technik Rapperswil
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26 /* Defines some primitive ASN1 types */
31 ASN1_BIT_STRING
= 0x03,
32 ASN1_OCTET_STRING
= 0x04,
35 ASN1_ENUMERATED
= 0x0A,
36 ASN1_UTF8STRING
= 0x0C,
37 ASN1_NUMERICSTRING
= 0x12,
38 ASN1_PRINTABLESTRING
= 0x13,
39 ASN1_T61STRING
= 0x14,
40 ASN1_VIDEOTEXSTRING
= 0x15,
41 ASN1_IA5STRING
= 0x16,
43 ASN1_GENERALIZEDTIME
= 0x18,
44 ASN1_GRAPHICSTRING
= 0x19,
45 ASN1_VISIBLESTRING
= 0x1A,
46 ASN1_GENERALSTRING
= 0x1B,
47 ASN1_UNIVERSALSTRING
= 0x1C,
48 ASN1_BMPSTRING
= 0x1E,
50 ASN1_CONSTRUCTED
= 0x20,
56 ASN1_CONTEXT_S_0
= 0x80,
57 ASN1_CONTEXT_S_1
= 0x81,
58 ASN1_CONTEXT_S_2
= 0x82,
59 ASN1_CONTEXT_S_3
= 0x83,
60 ASN1_CONTEXT_S_4
= 0x84,
61 ASN1_CONTEXT_S_5
= 0x85,
62 ASN1_CONTEXT_S_6
= 0x86,
63 ASN1_CONTEXT_S_7
= 0x87,
64 ASN1_CONTEXT_S_8
= 0x88,
66 ASN1_CONTEXT_C_0
= 0xA0,
67 ASN1_CONTEXT_C_1
= 0xA1,
68 ASN1_CONTEXT_C_2
= 0xA2,
69 ASN1_CONTEXT_C_3
= 0xA3,
70 ASN1_CONTEXT_C_4
= 0xA4,
71 ASN1_CONTEXT_C_5
= 0xA5
74 /* Definition of ASN1 flags */
76 #define ASN1_NONE 0x00
79 #define ASN1_LOOP 0x04
82 #define ASN1_BODY 0x20
85 #define ASN1_INVALID_LENGTH 0xffffffff
87 /* definition of an ASN.1 object */
96 #define ASN1_MAX_LEVEL 10
101 u_int loopAddr
[ASN1_MAX_LEVEL
+1];
102 chunk_t blobs
[ASN1_MAX_LEVEL
+2];
105 /* some common prefabricated ASN.1 constants */
106 extern const chunk_t ASN1_INTEGER_0
;
107 extern const chunk_t ASN1_INTEGER_1
;
108 extern const chunk_t ASN1_INTEGER_2
;
110 /* some popular algorithmIdentifiers */
111 extern const chunk_t ASN1_md5_id
;
112 extern const chunk_t ASN1_sha1_id
;
113 extern const chunk_t ASN1_rsaEncryption_id
;
114 extern const chunk_t ASN1_md5WithRSA_id
;
115 extern const chunk_t ASN1_sha1WithRSA_id
;
117 #define TIMETOA_BUF 30
119 extern chunk_t
asn1_algorithmIdentifier(int oid
);
120 extern int known_oid(chunk_t object
);
121 extern u_int
asn1_length(chunk_t
*blob
);
122 extern bool is_printablestring(chunk_t str
);
123 extern time_t asn1totime(const chunk_t
*utctime
, asn1_t type
);
124 extern void asn1_init(asn1_ctx_t
*ctx
, chunk_t blob
, u_int level0
, bool implicit
);
125 extern bool extract_object(asn1Object_t
const *objects
, u_int
*objectID
, chunk_t
*object
, u_int
*level
, asn1_ctx_t
*ctx
);
126 extern bool parse_asn1_simple_object(chunk_t
*object
, asn1_t type
, u_int level
, const char* name
);
127 extern int parse_algorithmIdentifier(chunk_t blob
, int level0
, chunk_t
*parameters
);
128 extern bool is_asn1(chunk_t blob
);
130 extern void code_asn1_length(size_t length
, chunk_t
*code
);
131 extern u_char
* build_asn1_object(chunk_t
*object
, asn1_t type
, size_t datalen
);
132 extern chunk_t
asn1_integer_from_mpz(const mpz_t value
);
133 extern chunk_t
asn1_simple_object(asn1_t tag
, chunk_t content
);
134 extern chunk_t
asn1_wrap(asn1_t type
, const char *mode
, ...);
135 extern chunk_t
timetoasn1(const time_t *time
, asn1_t type
);