cyassl re-port with cellular comms, PSK test
Dependencies: VodafoneUSBModem_bleedingedge2 mbed-rtos mbed-src
cyassllib/cyassl/ctaocrypt/asn.h@1:b211d97b0068, 2013-04-26 (annotated)
- Committer:
- ashleymills
- Date:
- Fri Apr 26 16:59:36 2013 +0000
- Revision:
- 1:b211d97b0068
- Parent:
- 0:e979170e02e7
nothing
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ashleymills | 0:e979170e02e7 | 1 | /* asn.h |
ashleymills | 0:e979170e02e7 | 2 | * |
ashleymills | 0:e979170e02e7 | 3 | * Copyright (C) 2006-2012 Sawtooth Consulting Ltd. |
ashleymills | 0:e979170e02e7 | 4 | * |
ashleymills | 0:e979170e02e7 | 5 | * This file is part of CyaSSL. |
ashleymills | 0:e979170e02e7 | 6 | * |
ashleymills | 0:e979170e02e7 | 7 | * CyaSSL is free software; you can redistribute it and/or modify |
ashleymills | 0:e979170e02e7 | 8 | * it under the terms of the GNU General Public License as published by |
ashleymills | 0:e979170e02e7 | 9 | * the Free Software Foundation; either version 2 of the License, or |
ashleymills | 0:e979170e02e7 | 10 | * (at your option) any later version. |
ashleymills | 0:e979170e02e7 | 11 | * |
ashleymills | 0:e979170e02e7 | 12 | * CyaSSL is distributed in the hope that it will be useful, |
ashleymills | 0:e979170e02e7 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
ashleymills | 0:e979170e02e7 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ashleymills | 0:e979170e02e7 | 15 | * GNU General Public License for more details. |
ashleymills | 0:e979170e02e7 | 16 | * |
ashleymills | 0:e979170e02e7 | 17 | * You should have received a copy of the GNU General Public License |
ashleymills | 0:e979170e02e7 | 18 | * along with this program; if not, write to the Free Software |
ashleymills | 0:e979170e02e7 | 19 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
ashleymills | 0:e979170e02e7 | 20 | */ |
ashleymills | 0:e979170e02e7 | 21 | |
ashleymills | 0:e979170e02e7 | 22 | #ifndef NO_ASN |
ashleymills | 0:e979170e02e7 | 23 | |
ashleymills | 0:e979170e02e7 | 24 | #ifndef CTAO_CRYPT_ASN_H |
ashleymills | 0:e979170e02e7 | 25 | #define CTAO_CRYPT_ASN_H |
ashleymills | 0:e979170e02e7 | 26 | |
ashleymills | 0:e979170e02e7 | 27 | #include <cyassl/ctaocrypt/types.h> |
ashleymills | 0:e979170e02e7 | 28 | #include <cyassl/ctaocrypt/rsa.h> |
ashleymills | 0:e979170e02e7 | 29 | #include <cyassl/ctaocrypt/dh.h> |
ashleymills | 0:e979170e02e7 | 30 | #include <cyassl/ctaocrypt/dsa.h> |
ashleymills | 0:e979170e02e7 | 31 | #include <cyassl/ctaocrypt/sha.h> |
ashleymills | 0:e979170e02e7 | 32 | #include <cyassl/ctaocrypt/md5.h> |
ashleymills | 0:e979170e02e7 | 33 | #include <cyassl/ctaocrypt/asn_public.h> /* public interface */ |
ashleymills | 0:e979170e02e7 | 34 | #ifdef HAVE_ECC |
ashleymills | 0:e979170e02e7 | 35 | #include <cyassl/ctaocrypt/ecc.h> |
ashleymills | 0:e979170e02e7 | 36 | #endif |
ashleymills | 0:e979170e02e7 | 37 | |
ashleymills | 0:e979170e02e7 | 38 | #ifdef __cplusplus |
ashleymills | 0:e979170e02e7 | 39 | extern "C" { |
ashleymills | 0:e979170e02e7 | 40 | #endif |
ashleymills | 0:e979170e02e7 | 41 | |
ashleymills | 0:e979170e02e7 | 42 | |
ashleymills | 0:e979170e02e7 | 43 | enum { |
ashleymills | 0:e979170e02e7 | 44 | ISSUER = 0, |
ashleymills | 0:e979170e02e7 | 45 | SUBJECT = 1, |
ashleymills | 0:e979170e02e7 | 46 | |
ashleymills | 0:e979170e02e7 | 47 | EXTERNAL_SERIAL_SIZE = 32, |
ashleymills | 0:e979170e02e7 | 48 | |
ashleymills | 0:e979170e02e7 | 49 | BEFORE = 0, |
ashleymills | 0:e979170e02e7 | 50 | AFTER = 1 |
ashleymills | 0:e979170e02e7 | 51 | }; |
ashleymills | 0:e979170e02e7 | 52 | |
ashleymills | 0:e979170e02e7 | 53 | /* ASN Tags */ |
ashleymills | 0:e979170e02e7 | 54 | enum ASN_Tags { |
ashleymills | 0:e979170e02e7 | 55 | ASN_BOOLEAN = 0x01, |
ashleymills | 0:e979170e02e7 | 56 | ASN_INTEGER = 0x02, |
ashleymills | 0:e979170e02e7 | 57 | ASN_BIT_STRING = 0x03, |
ashleymills | 0:e979170e02e7 | 58 | ASN_OCTET_STRING = 0x04, |
ashleymills | 0:e979170e02e7 | 59 | ASN_TAG_NULL = 0x05, |
ashleymills | 0:e979170e02e7 | 60 | ASN_OBJECT_ID = 0x06, |
ashleymills | 0:e979170e02e7 | 61 | ASN_ENUMERATED = 0x0a, |
ashleymills | 0:e979170e02e7 | 62 | ASN_SEQUENCE = 0x10, |
ashleymills | 0:e979170e02e7 | 63 | ASN_SET = 0x11, |
ashleymills | 0:e979170e02e7 | 64 | ASN_UTC_TIME = 0x17, |
ashleymills | 0:e979170e02e7 | 65 | ASN_DNS_TYPE = 0x02, |
ashleymills | 0:e979170e02e7 | 66 | ASN_GENERALIZED_TIME = 0x18, |
ashleymills | 0:e979170e02e7 | 67 | CRL_EXTENSIONS = 0xa0, |
ashleymills | 0:e979170e02e7 | 68 | ASN_EXTENSIONS = 0xa3, |
ashleymills | 0:e979170e02e7 | 69 | ASN_LONG_LENGTH = 0x80 |
ashleymills | 0:e979170e02e7 | 70 | }; |
ashleymills | 0:e979170e02e7 | 71 | |
ashleymills | 0:e979170e02e7 | 72 | enum ASN_Flags{ |
ashleymills | 0:e979170e02e7 | 73 | ASN_CONSTRUCTED = 0x20, |
ashleymills | 0:e979170e02e7 | 74 | ASN_CONTEXT_SPECIFIC = 0x80 |
ashleymills | 0:e979170e02e7 | 75 | }; |
ashleymills | 0:e979170e02e7 | 76 | |
ashleymills | 0:e979170e02e7 | 77 | enum DN_Tags { |
ashleymills | 0:e979170e02e7 | 78 | ASN_COMMON_NAME = 0x03, /* CN */ |
ashleymills | 0:e979170e02e7 | 79 | ASN_SUR_NAME = 0x04, /* SN */ |
ashleymills | 0:e979170e02e7 | 80 | ASN_COUNTRY_NAME = 0x06, /* C */ |
ashleymills | 0:e979170e02e7 | 81 | ASN_LOCALITY_NAME = 0x07, /* L */ |
ashleymills | 0:e979170e02e7 | 82 | ASN_STATE_NAME = 0x08, /* ST */ |
ashleymills | 0:e979170e02e7 | 83 | ASN_ORG_NAME = 0x0a, /* O */ |
ashleymills | 0:e979170e02e7 | 84 | ASN_ORGUNIT_NAME = 0x0b /* OU */ |
ashleymills | 0:e979170e02e7 | 85 | }; |
ashleymills | 0:e979170e02e7 | 86 | |
ashleymills | 0:e979170e02e7 | 87 | enum PBES { |
ashleymills | 0:e979170e02e7 | 88 | PBE_MD5_DES = 0, |
ashleymills | 0:e979170e02e7 | 89 | PBE_SHA1_DES = 1, |
ashleymills | 0:e979170e02e7 | 90 | PBE_SHA1_DES3 = 2, |
ashleymills | 0:e979170e02e7 | 91 | PBE_SHA1_RC4_128 = 3, |
ashleymills | 0:e979170e02e7 | 92 | PBES2 = 13 /* algo ID */ |
ashleymills | 0:e979170e02e7 | 93 | }; |
ashleymills | 0:e979170e02e7 | 94 | |
ashleymills | 0:e979170e02e7 | 95 | enum ENCRYPTION_TYPES { |
ashleymills | 0:e979170e02e7 | 96 | DES_TYPE = 0, |
ashleymills | 0:e979170e02e7 | 97 | DES3_TYPE = 1, |
ashleymills | 0:e979170e02e7 | 98 | RC4_TYPE = 2 |
ashleymills | 0:e979170e02e7 | 99 | }; |
ashleymills | 0:e979170e02e7 | 100 | |
ashleymills | 0:e979170e02e7 | 101 | enum ECC_TYPES { |
ashleymills | 0:e979170e02e7 | 102 | ECC_PREFIX_0 = 160, |
ashleymills | 0:e979170e02e7 | 103 | ECC_PREFIX_1 = 161 |
ashleymills | 0:e979170e02e7 | 104 | }; |
ashleymills | 0:e979170e02e7 | 105 | |
ashleymills | 0:e979170e02e7 | 106 | enum Misc_ASN { |
ashleymills | 0:e979170e02e7 | 107 | ASN_NAME_MAX = 256, |
ashleymills | 0:e979170e02e7 | 108 | MAX_SALT_SIZE = 64, /* MAX PKCS Salt length */ |
ashleymills | 0:e979170e02e7 | 109 | MAX_IV_SIZE = 64, /* MAX PKCS Iv length */ |
ashleymills | 0:e979170e02e7 | 110 | MAX_KEY_SIZE = 64, /* MAX PKCS Key length */ |
ashleymills | 0:e979170e02e7 | 111 | PKCS5 = 5, /* PKCS oid tag */ |
ashleymills | 0:e979170e02e7 | 112 | PKCS5v2 = 6, /* PKCS #5 v2.0 */ |
ashleymills | 0:e979170e02e7 | 113 | PKCS12 = 12, /* PKCS #12 */ |
ashleymills | 0:e979170e02e7 | 114 | MAX_UNICODE_SZ = 256, |
ashleymills | 0:e979170e02e7 | 115 | ASN_BOOL_SIZE = 2, /* including type */ |
ashleymills | 0:e979170e02e7 | 116 | SHA_SIZE = 20, |
ashleymills | 0:e979170e02e7 | 117 | RSA_INTS = 8, /* RSA ints in private key */ |
ashleymills | 0:e979170e02e7 | 118 | MIN_DATE_SIZE = 13, |
ashleymills | 0:e979170e02e7 | 119 | MAX_DATE_SIZE = 32, |
ashleymills | 0:e979170e02e7 | 120 | ASN_GEN_TIME_SZ = 15, /* 7 numbers * 2 + Zulu tag */ |
ashleymills | 0:e979170e02e7 | 121 | MAX_ENCODED_SIG_SZ = 512, |
ashleymills | 0:e979170e02e7 | 122 | MAX_SIG_SZ = 256, |
ashleymills | 0:e979170e02e7 | 123 | MAX_ALGO_SZ = 20, |
ashleymills | 0:e979170e02e7 | 124 | MAX_SEQ_SZ = 5, /* enum(seq | con) + length(4) */ |
ashleymills | 0:e979170e02e7 | 125 | MAX_SET_SZ = 5, /* enum(set | con) + length(4) */ |
ashleymills | 0:e979170e02e7 | 126 | MAX_VERSION_SZ = 5, /* enum + id + version(byte) + (header(2))*/ |
ashleymills | 0:e979170e02e7 | 127 | MAX_ENCODED_DIG_SZ = 73, /* sha512 + enum(bit or octet) + legnth(4) */ |
ashleymills | 0:e979170e02e7 | 128 | MAX_RSA_INT_SZ = 517, /* RSA raw sz 4096 for bits + tag + len(4) */ |
ashleymills | 0:e979170e02e7 | 129 | MAX_NTRU_KEY_SZ = 610, /* NTRU 112 bit public key */ |
ashleymills | 0:e979170e02e7 | 130 | MAX_NTRU_ENC_SZ = 628, /* NTRU 112 bit DER public encoding */ |
ashleymills | 0:e979170e02e7 | 131 | MAX_LENGTH_SZ = 4, /* Max length size for DER encoding */ |
ashleymills | 0:e979170e02e7 | 132 | MAX_RSA_E_SZ = 16, /* Max RSA public e size */ |
ashleymills | 0:e979170e02e7 | 133 | MAX_CA_SZ = 32, /* Max encoded CA basic constraint length */ |
ashleymills | 0:e979170e02e7 | 134 | MAX_SN_SZ = 35, /* Max encoded serial number (INT) length */ |
ashleymills | 0:e979170e02e7 | 135 | #ifdef CYASSL_CERT_GEN |
ashleymills | 0:e979170e02e7 | 136 | #ifdef CYASSL_ALT_NAMES |
ashleymills | 0:e979170e02e7 | 137 | MAX_EXTENSIONS_SZ = 1 + MAX_LENGTH_SZ + CTC_MAX_ALT_SIZE, |
ashleymills | 0:e979170e02e7 | 138 | #else |
ashleymills | 0:e979170e02e7 | 139 | MAX_EXTENSIONS_SZ = 1 + MAX_LENGTH_SZ + MAX_CA_SZ, |
ashleymills | 0:e979170e02e7 | 140 | #endif |
ashleymills | 0:e979170e02e7 | 141 | /* Max total extensions, id + len + others */ |
ashleymills | 0:e979170e02e7 | 142 | #endif |
ashleymills | 0:e979170e02e7 | 143 | MAX_OCSP_EXT_SZ = 58, /* Max OCSP Extension length */ |
ashleymills | 0:e979170e02e7 | 144 | MAX_OCSP_NONCE_SZ = 18, /* OCSP Nonce size */ |
ashleymills | 0:e979170e02e7 | 145 | EIGHTK_BUF = 8192, /* Tmp buffer size */ |
ashleymills | 0:e979170e02e7 | 146 | MAX_PUBLIC_KEY_SZ = MAX_NTRU_ENC_SZ + MAX_ALGO_SZ + MAX_SEQ_SZ * 2 |
ashleymills | 0:e979170e02e7 | 147 | /* use bigger NTRU size */ |
ashleymills | 0:e979170e02e7 | 148 | }; |
ashleymills | 0:e979170e02e7 | 149 | |
ashleymills | 0:e979170e02e7 | 150 | |
ashleymills | 0:e979170e02e7 | 151 | enum Oid_Types { |
ashleymills | 0:e979170e02e7 | 152 | hashType = 0, |
ashleymills | 0:e979170e02e7 | 153 | sigType = 1, |
ashleymills | 0:e979170e02e7 | 154 | keyType = 2 |
ashleymills | 0:e979170e02e7 | 155 | }; |
ashleymills | 0:e979170e02e7 | 156 | |
ashleymills | 0:e979170e02e7 | 157 | |
ashleymills | 0:e979170e02e7 | 158 | enum Hash_Sum { |
ashleymills | 0:e979170e02e7 | 159 | MD2h = 646, |
ashleymills | 0:e979170e02e7 | 160 | MD5h = 649, |
ashleymills | 0:e979170e02e7 | 161 | SHAh = 88, |
ashleymills | 0:e979170e02e7 | 162 | SHA256h = 414, |
ashleymills | 0:e979170e02e7 | 163 | SHA384h = 415, |
ashleymills | 0:e979170e02e7 | 164 | SHA512h = 416 |
ashleymills | 0:e979170e02e7 | 165 | }; |
ashleymills | 0:e979170e02e7 | 166 | |
ashleymills | 0:e979170e02e7 | 167 | |
ashleymills | 0:e979170e02e7 | 168 | enum Key_Sum { |
ashleymills | 0:e979170e02e7 | 169 | DSAk = 515, |
ashleymills | 0:e979170e02e7 | 170 | RSAk = 645, |
ashleymills | 0:e979170e02e7 | 171 | NTRUk = 364, |
ashleymills | 0:e979170e02e7 | 172 | ECDSAk = 518 |
ashleymills | 0:e979170e02e7 | 173 | }; |
ashleymills | 0:e979170e02e7 | 174 | |
ashleymills | 0:e979170e02e7 | 175 | |
ashleymills | 0:e979170e02e7 | 176 | enum Ecc_Sum { |
ashleymills | 0:e979170e02e7 | 177 | ECC_256R1 = 526, |
ashleymills | 0:e979170e02e7 | 178 | ECC_384R1 = 210, |
ashleymills | 0:e979170e02e7 | 179 | ECC_521R1 = 211, |
ashleymills | 0:e979170e02e7 | 180 | ECC_160R1 = 184, |
ashleymills | 0:e979170e02e7 | 181 | ECC_192R1 = 520, |
ashleymills | 0:e979170e02e7 | 182 | ECC_224R1 = 209 |
ashleymills | 0:e979170e02e7 | 183 | }; |
ashleymills | 0:e979170e02e7 | 184 | |
ashleymills | 0:e979170e02e7 | 185 | |
ashleymills | 0:e979170e02e7 | 186 | enum KDF_Sum { |
ashleymills | 0:e979170e02e7 | 187 | PBKDF2_OID = 660 |
ashleymills | 0:e979170e02e7 | 188 | }; |
ashleymills | 0:e979170e02e7 | 189 | |
ashleymills | 0:e979170e02e7 | 190 | |
ashleymills | 0:e979170e02e7 | 191 | enum Extensions_Sum { |
ashleymills | 0:e979170e02e7 | 192 | BASIC_CA_OID = 133, |
ashleymills | 0:e979170e02e7 | 193 | ALT_NAMES_OID = 131, |
ashleymills | 0:e979170e02e7 | 194 | CRL_DIST_OID = 145, |
ashleymills | 0:e979170e02e7 | 195 | AUTH_INFO_OID = 69, |
ashleymills | 0:e979170e02e7 | 196 | CA_ISSUER_OID = 117 |
ashleymills | 0:e979170e02e7 | 197 | }; |
ashleymills | 0:e979170e02e7 | 198 | |
ashleymills | 0:e979170e02e7 | 199 | |
ashleymills | 0:e979170e02e7 | 200 | enum VerifyType { |
ashleymills | 0:e979170e02e7 | 201 | NO_VERIFY = 0, |
ashleymills | 0:e979170e02e7 | 202 | VERIFY = 1 |
ashleymills | 0:e979170e02e7 | 203 | }; |
ashleymills | 0:e979170e02e7 | 204 | |
ashleymills | 0:e979170e02e7 | 205 | |
ashleymills | 0:e979170e02e7 | 206 | typedef struct DNS_entry DNS_entry; |
ashleymills | 0:e979170e02e7 | 207 | |
ashleymills | 0:e979170e02e7 | 208 | struct DNS_entry { |
ashleymills | 0:e979170e02e7 | 209 | DNS_entry* next; /* next on DNS list */ |
ashleymills | 0:e979170e02e7 | 210 | char* name; /* actual DNS name */ |
ashleymills | 0:e979170e02e7 | 211 | }; |
ashleymills | 0:e979170e02e7 | 212 | |
ashleymills | 0:e979170e02e7 | 213 | typedef struct DecodedCert DecodedCert; |
ashleymills | 0:e979170e02e7 | 214 | typedef struct Signer Signer; |
ashleymills | 0:e979170e02e7 | 215 | |
ashleymills | 0:e979170e02e7 | 216 | |
ashleymills | 0:e979170e02e7 | 217 | struct DecodedCert { |
ashleymills | 0:e979170e02e7 | 218 | byte* publicKey; |
ashleymills | 0:e979170e02e7 | 219 | word32 pubKeySize; |
ashleymills | 0:e979170e02e7 | 220 | int pubKeyStored; |
ashleymills | 0:e979170e02e7 | 221 | word32 certBegin; /* offset to start of cert */ |
ashleymills | 0:e979170e02e7 | 222 | word32 sigIndex; /* offset to start of signature */ |
ashleymills | 0:e979170e02e7 | 223 | word32 sigLength; /* length of signature */ |
ashleymills | 0:e979170e02e7 | 224 | word32 signatureOID; /* sum of algorithm object id */ |
ashleymills | 0:e979170e02e7 | 225 | word32 keyOID; /* sum of key algo object id */ |
ashleymills | 0:e979170e02e7 | 226 | DNS_entry* altNames; /* alt names list of dns entries */ |
ashleymills | 0:e979170e02e7 | 227 | byte subjectHash[SHA_SIZE]; /* hash of all Names */ |
ashleymills | 0:e979170e02e7 | 228 | byte issuerHash[SHA_SIZE]; /* hash of all Names */ |
ashleymills | 0:e979170e02e7 | 229 | #ifdef HAVE_OCSP |
ashleymills | 0:e979170e02e7 | 230 | byte issuerKeyHash[SHA_SIZE]; /* hash of the public Key */ |
ashleymills | 0:e979170e02e7 | 231 | #endif /* HAVE_OCSP */ |
ashleymills | 0:e979170e02e7 | 232 | byte* signature; /* not owned, points into raw cert */ |
ashleymills | 0:e979170e02e7 | 233 | char* subjectCN; /* CommonName */ |
ashleymills | 0:e979170e02e7 | 234 | int subjectCNLen; |
ashleymills | 0:e979170e02e7 | 235 | int subjectCNStored; /* have we saved a copy we own */ |
ashleymills | 0:e979170e02e7 | 236 | char issuer[ASN_NAME_MAX]; /* full name including common name */ |
ashleymills | 0:e979170e02e7 | 237 | char subject[ASN_NAME_MAX]; /* full name including common name */ |
ashleymills | 0:e979170e02e7 | 238 | int verify; /* Default to yes, but could be off */ |
ashleymills | 0:e979170e02e7 | 239 | byte* source; /* byte buffer holder cert, NOT owner */ |
ashleymills | 0:e979170e02e7 | 240 | word32 srcIdx; /* current offset into buffer */ |
ashleymills | 0:e979170e02e7 | 241 | word32 maxIdx; /* max offset based on init size */ |
ashleymills | 0:e979170e02e7 | 242 | void* heap; /* for user memory overrides */ |
ashleymills | 0:e979170e02e7 | 243 | byte serial[EXTERNAL_SERIAL_SIZE]; /* raw serial number */ |
ashleymills | 0:e979170e02e7 | 244 | int serialSz; /* raw serial bytes stored */ |
ashleymills | 0:e979170e02e7 | 245 | byte* extensions; /* not owned, points into raw cert */ |
ashleymills | 0:e979170e02e7 | 246 | int extensionsSz; /* length of cert extensions */ |
ashleymills | 0:e979170e02e7 | 247 | word32 extensionsIdx; /* if want to go back and parse later */ |
ashleymills | 0:e979170e02e7 | 248 | byte* extAuthInfo; /* Authority Information Access URI */ |
ashleymills | 0:e979170e02e7 | 249 | int extAuthInfoSz; /* length of the URI */ |
ashleymills | 0:e979170e02e7 | 250 | byte* extCrlInfo; /* CRL Distribution Points */ |
ashleymills | 0:e979170e02e7 | 251 | int extCrlInfoSz; /* length of the URI */ |
ashleymills | 0:e979170e02e7 | 252 | byte isCA; /* CA basic constraint true */ |
ashleymills | 0:e979170e02e7 | 253 | #ifdef CYASSL_CERT_GEN |
ashleymills | 0:e979170e02e7 | 254 | /* easy access to subject info for other sign */ |
ashleymills | 0:e979170e02e7 | 255 | char* subjectSN; |
ashleymills | 0:e979170e02e7 | 256 | int subjectSNLen; |
ashleymills | 0:e979170e02e7 | 257 | char* subjectC; |
ashleymills | 0:e979170e02e7 | 258 | int subjectCLen; |
ashleymills | 0:e979170e02e7 | 259 | char* subjectL; |
ashleymills | 0:e979170e02e7 | 260 | int subjectLLen; |
ashleymills | 0:e979170e02e7 | 261 | char* subjectST; |
ashleymills | 0:e979170e02e7 | 262 | int subjectSTLen; |
ashleymills | 0:e979170e02e7 | 263 | char* subjectO; |
ashleymills | 0:e979170e02e7 | 264 | int subjectOLen; |
ashleymills | 0:e979170e02e7 | 265 | char* subjectOU; |
ashleymills | 0:e979170e02e7 | 266 | int subjectOULen; |
ashleymills | 0:e979170e02e7 | 267 | char* subjectEmail; |
ashleymills | 0:e979170e02e7 | 268 | int subjectEmailLen; |
ashleymills | 0:e979170e02e7 | 269 | byte* beforeDate; |
ashleymills | 0:e979170e02e7 | 270 | int beforeDateLen; |
ashleymills | 0:e979170e02e7 | 271 | byte* afterDate; |
ashleymills | 0:e979170e02e7 | 272 | int afterDateLen; |
ashleymills | 0:e979170e02e7 | 273 | #endif /* CYASSL_CERT_GEN */ |
ashleymills | 0:e979170e02e7 | 274 | }; |
ashleymills | 0:e979170e02e7 | 275 | |
ashleymills | 0:e979170e02e7 | 276 | |
ashleymills | 0:e979170e02e7 | 277 | /* CA Signers */ |
ashleymills | 0:e979170e02e7 | 278 | struct Signer { |
ashleymills | 0:e979170e02e7 | 279 | byte* publicKey; |
ashleymills | 0:e979170e02e7 | 280 | word32 pubKeySize; |
ashleymills | 0:e979170e02e7 | 281 | word32 keyOID; /* key type */ |
ashleymills | 0:e979170e02e7 | 282 | char* name; /* common name */ |
ashleymills | 0:e979170e02e7 | 283 | byte hash[SHA_DIGEST_SIZE]; /* sha hash of names in certificate */ |
ashleymills | 0:e979170e02e7 | 284 | Signer* next; |
ashleymills | 0:e979170e02e7 | 285 | }; |
ashleymills | 0:e979170e02e7 | 286 | |
ashleymills | 0:e979170e02e7 | 287 | |
ashleymills | 0:e979170e02e7 | 288 | /* not for public consumption but may use for testing sometimes */ |
ashleymills | 0:e979170e02e7 | 289 | #ifdef CYASSL_TEST_CERT |
ashleymills | 0:e979170e02e7 | 290 | #define CYASSL_TEST_API CYASSL_API |
ashleymills | 0:e979170e02e7 | 291 | #else |
ashleymills | 0:e979170e02e7 | 292 | #define CYASSL_TEST_API CYASSL_LOCAL |
ashleymills | 0:e979170e02e7 | 293 | #endif |
ashleymills | 0:e979170e02e7 | 294 | |
ashleymills | 0:e979170e02e7 | 295 | CYASSL_TEST_API void FreeAltNames(DNS_entry*, void*); |
ashleymills | 0:e979170e02e7 | 296 | CYASSL_TEST_API void InitDecodedCert(DecodedCert*, byte*, word32, void*); |
ashleymills | 0:e979170e02e7 | 297 | CYASSL_TEST_API void FreeDecodedCert(DecodedCert*); |
ashleymills | 0:e979170e02e7 | 298 | CYASSL_TEST_API int ParseCert(DecodedCert*, int type, int verify, void* cm); |
ashleymills | 0:e979170e02e7 | 299 | |
ashleymills | 0:e979170e02e7 | 300 | CYASSL_LOCAL int ParseCertRelative(DecodedCert*, int type, int verify,void* cm); |
ashleymills | 0:e979170e02e7 | 301 | CYASSL_LOCAL int DecodeToKey(DecodedCert*, int verify); |
ashleymills | 0:e979170e02e7 | 302 | |
ashleymills | 0:e979170e02e7 | 303 | CYASSL_LOCAL word32 EncodeSignature(byte* out, const byte* digest, word32 digSz, |
ashleymills | 0:e979170e02e7 | 304 | int hashOID); |
ashleymills | 0:e979170e02e7 | 305 | |
ashleymills | 0:e979170e02e7 | 306 | CYASSL_LOCAL Signer* MakeSigner(void*); |
ashleymills | 0:e979170e02e7 | 307 | CYASSL_LOCAL void FreeSigners(Signer*, void*); |
ashleymills | 0:e979170e02e7 | 308 | |
ashleymills | 0:e979170e02e7 | 309 | |
ashleymills | 0:e979170e02e7 | 310 | CYASSL_LOCAL int ToTraditional(byte* buffer, word32 length); |
ashleymills | 0:e979170e02e7 | 311 | CYASSL_LOCAL int ToTraditionalEnc(byte* buffer, word32 length,const char*, int); |
ashleymills | 0:e979170e02e7 | 312 | |
ashleymills | 0:e979170e02e7 | 313 | CYASSL_LOCAL int ValidateDate(const byte* date, byte format, int dateType); |
ashleymills | 0:e979170e02e7 | 314 | |
ashleymills | 0:e979170e02e7 | 315 | #ifdef HAVE_ECC |
ashleymills | 0:e979170e02e7 | 316 | /* ASN sig helpers */ |
ashleymills | 0:e979170e02e7 | 317 | CYASSL_LOCAL int StoreECC_DSA_Sig(byte* out, word32* outLen, mp_int* r, |
ashleymills | 0:e979170e02e7 | 318 | mp_int* s); |
ashleymills | 0:e979170e02e7 | 319 | CYASSL_LOCAL int DecodeECC_DSA_Sig(const byte* sig, word32 sigLen, |
ashleymills | 0:e979170e02e7 | 320 | mp_int* r, mp_int* s); |
ashleymills | 0:e979170e02e7 | 321 | /* private key helpers */ |
ashleymills | 0:e979170e02e7 | 322 | CYASSL_LOCAL int EccPrivateKeyDecode(const byte* input,word32* inOutIdx, |
ashleymills | 0:e979170e02e7 | 323 | ecc_key*,word32); |
ashleymills | 0:e979170e02e7 | 324 | #endif |
ashleymills | 0:e979170e02e7 | 325 | |
ashleymills | 0:e979170e02e7 | 326 | #ifdef CYASSL_CERT_GEN |
ashleymills | 0:e979170e02e7 | 327 | |
ashleymills | 0:e979170e02e7 | 328 | enum cert_enums { |
ashleymills | 0:e979170e02e7 | 329 | NAME_ENTRIES = 8, |
ashleymills | 0:e979170e02e7 | 330 | JOINT_LEN = 2, |
ashleymills | 0:e979170e02e7 | 331 | EMAIL_JOINT_LEN = 9, |
ashleymills | 0:e979170e02e7 | 332 | RSA_KEY = 10, |
ashleymills | 0:e979170e02e7 | 333 | NTRU_KEY = 11 |
ashleymills | 0:e979170e02e7 | 334 | }; |
ashleymills | 0:e979170e02e7 | 335 | |
ashleymills | 0:e979170e02e7 | 336 | |
ashleymills | 0:e979170e02e7 | 337 | #endif /* CYASSL_CERT_GEN */ |
ashleymills | 0:e979170e02e7 | 338 | |
ashleymills | 0:e979170e02e7 | 339 | |
ashleymills | 0:e979170e02e7 | 340 | |
ashleymills | 0:e979170e02e7 | 341 | /* for pointer use */ |
ashleymills | 0:e979170e02e7 | 342 | typedef struct CertStatus CertStatus; |
ashleymills | 0:e979170e02e7 | 343 | |
ashleymills | 0:e979170e02e7 | 344 | #ifdef HAVE_OCSP |
ashleymills | 0:e979170e02e7 | 345 | |
ashleymills | 0:e979170e02e7 | 346 | enum Ocsp_Response_Status { |
ashleymills | 0:e979170e02e7 | 347 | OCSP_SUCCESSFUL = 0, /* Response has valid confirmations */ |
ashleymills | 0:e979170e02e7 | 348 | OCSP_MALFORMED_REQUEST = 1, /* Illegal confirmation request */ |
ashleymills | 0:e979170e02e7 | 349 | OCSP_INTERNAL_ERROR = 2, /* Internal error in issuer */ |
ashleymills | 0:e979170e02e7 | 350 | OCSP_TRY_LATER = 3, /* Try again later */ |
ashleymills | 0:e979170e02e7 | 351 | OCSP_SIG_REQUIRED = 5, /* Must sign the request (4 is skipped) */ |
ashleymills | 0:e979170e02e7 | 352 | OCSP_UNAUTHROIZED = 6 /* Request unauthorized */ |
ashleymills | 0:e979170e02e7 | 353 | }; |
ashleymills | 0:e979170e02e7 | 354 | |
ashleymills | 0:e979170e02e7 | 355 | |
ashleymills | 0:e979170e02e7 | 356 | enum Ocsp_Cert_Status { |
ashleymills | 0:e979170e02e7 | 357 | CERT_GOOD = 0, |
ashleymills | 0:e979170e02e7 | 358 | CERT_REVOKED = 1, |
ashleymills | 0:e979170e02e7 | 359 | CERT_UNKNOWN = 2 |
ashleymills | 0:e979170e02e7 | 360 | }; |
ashleymills | 0:e979170e02e7 | 361 | |
ashleymills | 0:e979170e02e7 | 362 | |
ashleymills | 0:e979170e02e7 | 363 | enum Ocsp_Sums { |
ashleymills | 0:e979170e02e7 | 364 | OCSP_BASIC_OID = 117, |
ashleymills | 0:e979170e02e7 | 365 | OCSP_NONCE_OID = 118 |
ashleymills | 0:e979170e02e7 | 366 | }; |
ashleymills | 0:e979170e02e7 | 367 | |
ashleymills | 0:e979170e02e7 | 368 | |
ashleymills | 0:e979170e02e7 | 369 | typedef struct OcspRequest OcspRequest; |
ashleymills | 0:e979170e02e7 | 370 | typedef struct OcspResponse OcspResponse; |
ashleymills | 0:e979170e02e7 | 371 | |
ashleymills | 0:e979170e02e7 | 372 | |
ashleymills | 0:e979170e02e7 | 373 | struct CertStatus { |
ashleymills | 0:e979170e02e7 | 374 | CertStatus* next; |
ashleymills | 0:e979170e02e7 | 375 | |
ashleymills | 0:e979170e02e7 | 376 | byte serial[EXTERNAL_SERIAL_SIZE]; |
ashleymills | 0:e979170e02e7 | 377 | int serialSz; |
ashleymills | 0:e979170e02e7 | 378 | |
ashleymills | 0:e979170e02e7 | 379 | int status; |
ashleymills | 0:e979170e02e7 | 380 | |
ashleymills | 0:e979170e02e7 | 381 | byte thisDate[MAX_DATE_SIZE]; |
ashleymills | 0:e979170e02e7 | 382 | byte nextDate[MAX_DATE_SIZE]; |
ashleymills | 0:e979170e02e7 | 383 | byte thisDateFormat; |
ashleymills | 0:e979170e02e7 | 384 | byte nextDateFormat; |
ashleymills | 0:e979170e02e7 | 385 | }; |
ashleymills | 0:e979170e02e7 | 386 | |
ashleymills | 0:e979170e02e7 | 387 | |
ashleymills | 0:e979170e02e7 | 388 | struct OcspResponse { |
ashleymills | 0:e979170e02e7 | 389 | int responseStatus; /* return code from Responder */ |
ashleymills | 0:e979170e02e7 | 390 | |
ashleymills | 0:e979170e02e7 | 391 | byte* response; /* Pointer to beginning of OCSP Response */ |
ashleymills | 0:e979170e02e7 | 392 | word32 responseSz; /* length of the OCSP Response */ |
ashleymills | 0:e979170e02e7 | 393 | |
ashleymills | 0:e979170e02e7 | 394 | byte producedDate[MAX_DATE_SIZE]; |
ashleymills | 0:e979170e02e7 | 395 | /* Date at which this response was signed */ |
ashleymills | 0:e979170e02e7 | 396 | byte producedDateFormat; /* format of the producedDate */ |
ashleymills | 0:e979170e02e7 | 397 | byte* issuerHash; |
ashleymills | 0:e979170e02e7 | 398 | byte* issuerKeyHash; |
ashleymills | 0:e979170e02e7 | 399 | |
ashleymills | 0:e979170e02e7 | 400 | byte* cert; |
ashleymills | 0:e979170e02e7 | 401 | word32 certSz; |
ashleymills | 0:e979170e02e7 | 402 | |
ashleymills | 0:e979170e02e7 | 403 | byte* sig; /* Pointer to sig in source */ |
ashleymills | 0:e979170e02e7 | 404 | word32 sigSz; /* Length in octets for the sig */ |
ashleymills | 0:e979170e02e7 | 405 | word32 sigOID; /* OID for hash used for sig */ |
ashleymills | 0:e979170e02e7 | 406 | |
ashleymills | 0:e979170e02e7 | 407 | CertStatus* status; /* certificate status to fill out */ |
ashleymills | 0:e979170e02e7 | 408 | |
ashleymills | 0:e979170e02e7 | 409 | byte* nonce; /* pointer to nonce inside ASN.1 response */ |
ashleymills | 0:e979170e02e7 | 410 | int nonceSz; /* length of the nonce string */ |
ashleymills | 0:e979170e02e7 | 411 | |
ashleymills | 0:e979170e02e7 | 412 | byte* source; /* pointer to source buffer, not owned */ |
ashleymills | 0:e979170e02e7 | 413 | word32 maxIdx; /* max offset based on init size */ |
ashleymills | 0:e979170e02e7 | 414 | }; |
ashleymills | 0:e979170e02e7 | 415 | |
ashleymills | 0:e979170e02e7 | 416 | |
ashleymills | 0:e979170e02e7 | 417 | struct OcspRequest { |
ashleymills | 0:e979170e02e7 | 418 | DecodedCert* cert; |
ashleymills | 0:e979170e02e7 | 419 | |
ashleymills | 0:e979170e02e7 | 420 | byte useNonce; |
ashleymills | 0:e979170e02e7 | 421 | byte nonce[MAX_OCSP_NONCE_SZ]; |
ashleymills | 0:e979170e02e7 | 422 | int nonceSz; |
ashleymills | 0:e979170e02e7 | 423 | |
ashleymills | 0:e979170e02e7 | 424 | byte* issuerHash; /* pointer to issuerHash in source cert */ |
ashleymills | 0:e979170e02e7 | 425 | byte* issuerKeyHash; /* pointer to issuerKeyHash in source cert */ |
ashleymills | 0:e979170e02e7 | 426 | byte* serial; /* pointer to serial number in source cert */ |
ashleymills | 0:e979170e02e7 | 427 | int serialSz; /* length of the serial number */ |
ashleymills | 0:e979170e02e7 | 428 | |
ashleymills | 0:e979170e02e7 | 429 | byte* dest; /* pointer to the destination ASN.1 buffer */ |
ashleymills | 0:e979170e02e7 | 430 | word32 destSz; /* length of the destination buffer */ |
ashleymills | 0:e979170e02e7 | 431 | }; |
ashleymills | 0:e979170e02e7 | 432 | |
ashleymills | 0:e979170e02e7 | 433 | |
ashleymills | 0:e979170e02e7 | 434 | CYASSL_LOCAL void InitOcspResponse(OcspResponse*, CertStatus*, byte*, word32); |
ashleymills | 0:e979170e02e7 | 435 | CYASSL_LOCAL int OcspResponseDecode(OcspResponse*); |
ashleymills | 0:e979170e02e7 | 436 | |
ashleymills | 0:e979170e02e7 | 437 | CYASSL_LOCAL void InitOcspRequest(OcspRequest*, DecodedCert*, |
ashleymills | 0:e979170e02e7 | 438 | byte, byte*, word32); |
ashleymills | 0:e979170e02e7 | 439 | CYASSL_LOCAL int EncodeOcspRequest(OcspRequest*); |
ashleymills | 0:e979170e02e7 | 440 | |
ashleymills | 0:e979170e02e7 | 441 | CYASSL_LOCAL int CompareOcspReqResp(OcspRequest*, OcspResponse*); |
ashleymills | 0:e979170e02e7 | 442 | |
ashleymills | 0:e979170e02e7 | 443 | |
ashleymills | 0:e979170e02e7 | 444 | #endif /* HAVE_OCSP */ |
ashleymills | 0:e979170e02e7 | 445 | |
ashleymills | 0:e979170e02e7 | 446 | |
ashleymills | 0:e979170e02e7 | 447 | /* for pointer use */ |
ashleymills | 0:e979170e02e7 | 448 | typedef struct RevokedCert RevokedCert; |
ashleymills | 0:e979170e02e7 | 449 | |
ashleymills | 0:e979170e02e7 | 450 | #ifdef HAVE_CRL |
ashleymills | 0:e979170e02e7 | 451 | |
ashleymills | 0:e979170e02e7 | 452 | struct RevokedCert { |
ashleymills | 0:e979170e02e7 | 453 | byte serialNumber[EXTERNAL_SERIAL_SIZE]; |
ashleymills | 0:e979170e02e7 | 454 | int serialSz; |
ashleymills | 0:e979170e02e7 | 455 | RevokedCert* next; |
ashleymills | 0:e979170e02e7 | 456 | }; |
ashleymills | 0:e979170e02e7 | 457 | |
ashleymills | 0:e979170e02e7 | 458 | typedef struct DecodedCRL DecodedCRL; |
ashleymills | 0:e979170e02e7 | 459 | |
ashleymills | 0:e979170e02e7 | 460 | struct DecodedCRL { |
ashleymills | 0:e979170e02e7 | 461 | word32 certBegin; /* offset to start of cert */ |
ashleymills | 0:e979170e02e7 | 462 | word32 sigIndex; /* offset to start of signature */ |
ashleymills | 0:e979170e02e7 | 463 | word32 sigLength; /* length of signature */ |
ashleymills | 0:e979170e02e7 | 464 | word32 signatureOID; /* sum of algorithm object id */ |
ashleymills | 0:e979170e02e7 | 465 | byte* signature; /* pointer into raw source, not owned */ |
ashleymills | 0:e979170e02e7 | 466 | byte issuerHash[SHA_DIGEST_SIZE]; /* issuer hash */ |
ashleymills | 0:e979170e02e7 | 467 | byte crlHash[SHA_DIGEST_SIZE]; /* raw crl data hash */ |
ashleymills | 0:e979170e02e7 | 468 | byte lastDate[MAX_DATE_SIZE]; /* last date updated */ |
ashleymills | 0:e979170e02e7 | 469 | byte nextDate[MAX_DATE_SIZE]; /* next update date */ |
ashleymills | 0:e979170e02e7 | 470 | byte lastDateFormat; /* format of last date */ |
ashleymills | 0:e979170e02e7 | 471 | byte nextDateFormat; /* format of next date */ |
ashleymills | 0:e979170e02e7 | 472 | RevokedCert* certs; /* revoked cert list */ |
ashleymills | 0:e979170e02e7 | 473 | int totalCerts; /* number on list */ |
ashleymills | 0:e979170e02e7 | 474 | }; |
ashleymills | 0:e979170e02e7 | 475 | |
ashleymills | 0:e979170e02e7 | 476 | CYASSL_LOCAL void InitDecodedCRL(DecodedCRL*); |
ashleymills | 0:e979170e02e7 | 477 | CYASSL_LOCAL int ParseCRL(DecodedCRL*, const byte* buff, word32 sz, void* cm); |
ashleymills | 0:e979170e02e7 | 478 | CYASSL_LOCAL void FreeDecodedCRL(DecodedCRL*); |
ashleymills | 0:e979170e02e7 | 479 | |
ashleymills | 0:e979170e02e7 | 480 | |
ashleymills | 0:e979170e02e7 | 481 | #endif /* HAVE_CRL */ |
ashleymills | 0:e979170e02e7 | 482 | |
ashleymills | 0:e979170e02e7 | 483 | |
ashleymills | 0:e979170e02e7 | 484 | #ifdef __cplusplus |
ashleymills | 0:e979170e02e7 | 485 | } /* extern "C" */ |
ashleymills | 0:e979170e02e7 | 486 | #endif |
ashleymills | 0:e979170e02e7 | 487 | |
ashleymills | 0:e979170e02e7 | 488 | #endif /* CTAO_CRYPT_ASN_H */ |
ashleymills | 0:e979170e02e7 | 489 | |
ashleymills | 0:e979170e02e7 | 490 | #endif /* !NO_ASN */ |