fork of cyassl-lib
Dependents: TLS_cyassl TLS_cyassl
cyassl/ctaocrypt/asn_public.h@0:714293de3836, 2013-09-05 (annotated)
- Committer:
- ashleymills
- Date:
- Thu Sep 05 10:33:04 2013 +0000
- Revision:
- 0:714293de3836
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ashleymills | 0:714293de3836 | 1 | /* asn_public.h |
ashleymills | 0:714293de3836 | 2 | * |
ashleymills | 0:714293de3836 | 3 | * Copyright (C) 2006-2013 wolfSSL Inc. |
ashleymills | 0:714293de3836 | 4 | * |
ashleymills | 0:714293de3836 | 5 | * This file is part of CyaSSL. |
ashleymills | 0:714293de3836 | 6 | * |
ashleymills | 0:714293de3836 | 7 | * CyaSSL is free software; you can redistribute it and/or modify |
ashleymills | 0:714293de3836 | 8 | * it under the terms of the GNU General Public License as published by |
ashleymills | 0:714293de3836 | 9 | * the Free Software Foundation; either version 2 of the License, or |
ashleymills | 0:714293de3836 | 10 | * (at your option) any later version. |
ashleymills | 0:714293de3836 | 11 | * |
ashleymills | 0:714293de3836 | 12 | * CyaSSL is distributed in the hope that it will be useful, |
ashleymills | 0:714293de3836 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
ashleymills | 0:714293de3836 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ashleymills | 0:714293de3836 | 15 | * GNU General Public License for more details. |
ashleymills | 0:714293de3836 | 16 | * |
ashleymills | 0:714293de3836 | 17 | * You should have received a copy of the GNU General Public License |
ashleymills | 0:714293de3836 | 18 | * along with this program; if not, write to the Free Software |
ashleymills | 0:714293de3836 | 19 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
ashleymills | 0:714293de3836 | 20 | */ |
ashleymills | 0:714293de3836 | 21 | |
ashleymills | 0:714293de3836 | 22 | |
ashleymills | 0:714293de3836 | 23 | #ifndef CTAO_CRYPT_ASN_PUBLIC_H |
ashleymills | 0:714293de3836 | 24 | #define CTAO_CRYPT_ASN_PUBLIC_H |
ashleymills | 0:714293de3836 | 25 | |
ashleymills | 0:714293de3836 | 26 | #include <cyassl/ctaocrypt/types.h> |
ashleymills | 0:714293de3836 | 27 | #ifdef CYASSL_CERT_GEN |
ashleymills | 0:714293de3836 | 28 | #include <cyassl/ctaocrypt/rsa.h> |
ashleymills | 0:714293de3836 | 29 | #endif |
ashleymills | 0:714293de3836 | 30 | |
ashleymills | 0:714293de3836 | 31 | |
ashleymills | 0:714293de3836 | 32 | #ifdef __cplusplus |
ashleymills | 0:714293de3836 | 33 | extern "C" { |
ashleymills | 0:714293de3836 | 34 | #endif |
ashleymills | 0:714293de3836 | 35 | |
ashleymills | 0:714293de3836 | 36 | |
ashleymills | 0:714293de3836 | 37 | /* Certificate file Type */ |
ashleymills | 0:714293de3836 | 38 | enum CertType { |
ashleymills | 0:714293de3836 | 39 | CERT_TYPE = 0, |
ashleymills | 0:714293de3836 | 40 | PRIVATEKEY_TYPE, |
ashleymills | 0:714293de3836 | 41 | DH_PARAM_TYPE, |
ashleymills | 0:714293de3836 | 42 | CRL_TYPE, |
ashleymills | 0:714293de3836 | 43 | CA_TYPE, |
ashleymills | 0:714293de3836 | 44 | ECC_PRIVATEKEY_TYPE |
ashleymills | 0:714293de3836 | 45 | }; |
ashleymills | 0:714293de3836 | 46 | |
ashleymills | 0:714293de3836 | 47 | |
ashleymills | 0:714293de3836 | 48 | /* Signature type, by OID sum */ |
ashleymills | 0:714293de3836 | 49 | enum Ctc_SigType { |
ashleymills | 0:714293de3836 | 50 | CTC_SHAwDSA = 517, |
ashleymills | 0:714293de3836 | 51 | CTC_MD2wRSA = 646, |
ashleymills | 0:714293de3836 | 52 | CTC_MD5wRSA = 648, |
ashleymills | 0:714293de3836 | 53 | CTC_SHAwRSA = 649, |
ashleymills | 0:714293de3836 | 54 | CTC_SHAwECDSA = 520, |
ashleymills | 0:714293de3836 | 55 | CTC_SHA256wRSA = 655, |
ashleymills | 0:714293de3836 | 56 | CTC_SHA256wECDSA = 524, |
ashleymills | 0:714293de3836 | 57 | CTC_SHA384wRSA = 656, |
ashleymills | 0:714293de3836 | 58 | CTC_SHA384wECDSA = 525, |
ashleymills | 0:714293de3836 | 59 | CTC_SHA512wRSA = 657, |
ashleymills | 0:714293de3836 | 60 | CTC_SHA512wECDSA = 526 |
ashleymills | 0:714293de3836 | 61 | }; |
ashleymills | 0:714293de3836 | 62 | |
ashleymills | 0:714293de3836 | 63 | |
ashleymills | 0:714293de3836 | 64 | #ifdef CYASSL_CERT_GEN |
ashleymills | 0:714293de3836 | 65 | |
ashleymills | 0:714293de3836 | 66 | enum Ctc_Misc { |
ashleymills | 0:714293de3836 | 67 | CTC_NAME_SIZE = 64, |
ashleymills | 0:714293de3836 | 68 | CTC_DATE_SIZE = 32, |
ashleymills | 0:714293de3836 | 69 | CTC_MAX_ALT_SIZE = 8192, /* may be huge */ |
ashleymills | 0:714293de3836 | 70 | CTC_SERIAL_SIZE = 8 |
ashleymills | 0:714293de3836 | 71 | }; |
ashleymills | 0:714293de3836 | 72 | |
ashleymills | 0:714293de3836 | 73 | typedef struct CertName { |
ashleymills | 0:714293de3836 | 74 | char country[CTC_NAME_SIZE]; |
ashleymills | 0:714293de3836 | 75 | char state[CTC_NAME_SIZE]; |
ashleymills | 0:714293de3836 | 76 | char locality[CTC_NAME_SIZE]; |
ashleymills | 0:714293de3836 | 77 | char sur[CTC_NAME_SIZE]; |
ashleymills | 0:714293de3836 | 78 | char org[CTC_NAME_SIZE]; |
ashleymills | 0:714293de3836 | 79 | char unit[CTC_NAME_SIZE]; |
ashleymills | 0:714293de3836 | 80 | char commonName[CTC_NAME_SIZE]; |
ashleymills | 0:714293de3836 | 81 | char email[CTC_NAME_SIZE]; /* !!!! email has to be last !!!! */ |
ashleymills | 0:714293de3836 | 82 | } CertName; |
ashleymills | 0:714293de3836 | 83 | |
ashleymills | 0:714293de3836 | 84 | |
ashleymills | 0:714293de3836 | 85 | /* for user to fill for certificate generation */ |
ashleymills | 0:714293de3836 | 86 | typedef struct Cert { |
ashleymills | 0:714293de3836 | 87 | int version; /* x509 version */ |
ashleymills | 0:714293de3836 | 88 | byte serial[CTC_SERIAL_SIZE]; /* serial number */ |
ashleymills | 0:714293de3836 | 89 | int sigType; /* signature algo type */ |
ashleymills | 0:714293de3836 | 90 | CertName issuer; /* issuer info */ |
ashleymills | 0:714293de3836 | 91 | int daysValid; /* validity days */ |
ashleymills | 0:714293de3836 | 92 | int selfSigned; /* self signed flag */ |
ashleymills | 0:714293de3836 | 93 | CertName subject; /* subject info */ |
ashleymills | 0:714293de3836 | 94 | int isCA; /* is this going to be a CA */ |
ashleymills | 0:714293de3836 | 95 | /* internal use only */ |
ashleymills | 0:714293de3836 | 96 | int bodySz; /* pre sign total size */ |
ashleymills | 0:714293de3836 | 97 | int keyType; /* public key type of subject */ |
ashleymills | 0:714293de3836 | 98 | #ifdef CYASSL_ALT_NAMES |
ashleymills | 0:714293de3836 | 99 | byte altNames[CTC_MAX_ALT_SIZE]; /* altNames copy */ |
ashleymills | 0:714293de3836 | 100 | int altNamesSz; /* altNames size in bytes */ |
ashleymills | 0:714293de3836 | 101 | byte beforeDate[CTC_DATE_SIZE]; /* before date copy */ |
ashleymills | 0:714293de3836 | 102 | int beforeDateSz; /* size of copy */ |
ashleymills | 0:714293de3836 | 103 | byte afterDate[CTC_DATE_SIZE]; /* after date copy */ |
ashleymills | 0:714293de3836 | 104 | int afterDateSz; /* size of copy */ |
ashleymills | 0:714293de3836 | 105 | #endif |
ashleymills | 0:714293de3836 | 106 | } Cert; |
ashleymills | 0:714293de3836 | 107 | |
ashleymills | 0:714293de3836 | 108 | |
ashleymills | 0:714293de3836 | 109 | |
ashleymills | 0:714293de3836 | 110 | |
ashleymills | 0:714293de3836 | 111 | /* Initialize and Set Certficate defaults: |
ashleymills | 0:714293de3836 | 112 | version = 3 (0x2) |
ashleymills | 0:714293de3836 | 113 | serial = 0 (Will be randomly generated) |
ashleymills | 0:714293de3836 | 114 | sigType = SHA_WITH_RSA |
ashleymills | 0:714293de3836 | 115 | issuer = blank |
ashleymills | 0:714293de3836 | 116 | daysValid = 500 |
ashleymills | 0:714293de3836 | 117 | selfSigned = 1 (true) use subject as issuer |
ashleymills | 0:714293de3836 | 118 | subject = blank |
ashleymills | 0:714293de3836 | 119 | isCA = 0 (false) |
ashleymills | 0:714293de3836 | 120 | keyType = RSA_KEY (default) |
ashleymills | 0:714293de3836 | 121 | */ |
ashleymills | 0:714293de3836 | 122 | CYASSL_API void InitCert(Cert*); |
ashleymills | 0:714293de3836 | 123 | CYASSL_API int MakeCert(Cert*, byte* derBuffer, word32 derSz, RsaKey*, RNG*); |
ashleymills | 0:714293de3836 | 124 | CYASSL_API int SignCert(Cert*, byte* derBuffer, word32 derSz, RsaKey*, RNG*); |
ashleymills | 0:714293de3836 | 125 | CYASSL_API int MakeSelfCert(Cert*, byte* derBuffer, word32 derSz, RsaKey*, |
ashleymills | 0:714293de3836 | 126 | RNG*); |
ashleymills | 0:714293de3836 | 127 | CYASSL_API int SetIssuer(Cert*, const char*); |
ashleymills | 0:714293de3836 | 128 | CYASSL_API int SetSubject(Cert*, const char*); |
ashleymills | 0:714293de3836 | 129 | #ifdef CYASSL_ALT_NAMES |
ashleymills | 0:714293de3836 | 130 | CYASSL_API int SetAltNames(Cert*, const char*); |
ashleymills | 0:714293de3836 | 131 | #endif |
ashleymills | 0:714293de3836 | 132 | CYASSL_API int SetIssuerBuffer(Cert*, const byte*, int); |
ashleymills | 0:714293de3836 | 133 | CYASSL_API int SetSubjectBuffer(Cert*, const byte*, int); |
ashleymills | 0:714293de3836 | 134 | CYASSL_API int SetAltNamesBuffer(Cert*, const byte*, int); |
ashleymills | 0:714293de3836 | 135 | CYASSL_API int SetDatesBuffer(Cert*, const byte*, int); |
ashleymills | 0:714293de3836 | 136 | |
ashleymills | 0:714293de3836 | 137 | #ifdef HAVE_NTRU |
ashleymills | 0:714293de3836 | 138 | CYASSL_API int MakeNtruCert(Cert*, byte* derBuffer, word32 derSz, |
ashleymills | 0:714293de3836 | 139 | const byte* ntruKey, word16 keySz, RNG*); |
ashleymills | 0:714293de3836 | 140 | #endif |
ashleymills | 0:714293de3836 | 141 | |
ashleymills | 0:714293de3836 | 142 | #endif /* CYASSL_CERT_GEN */ |
ashleymills | 0:714293de3836 | 143 | |
ashleymills | 0:714293de3836 | 144 | |
ashleymills | 0:714293de3836 | 145 | #if defined(CYASSL_KEY_GEN) || defined(CYASSL_CERT_GEN) |
ashleymills | 0:714293de3836 | 146 | CYASSL_API int DerToPem(const byte* der, word32 derSz, byte* output, |
ashleymills | 0:714293de3836 | 147 | word32 outputSz, int type); |
ashleymills | 0:714293de3836 | 148 | #endif |
ashleymills | 0:714293de3836 | 149 | |
ashleymills | 0:714293de3836 | 150 | |
ashleymills | 0:714293de3836 | 151 | #ifdef __cplusplus |
ashleymills | 0:714293de3836 | 152 | } /* extern "C" */ |
ashleymills | 0:714293de3836 | 153 | #endif |
ashleymills | 0:714293de3836 | 154 | |
ashleymills | 0:714293de3836 | 155 | #endif /* CTAO_CRYPT_ASN_PUBLIC_H */ |
ashleymills | 0:714293de3836 | 156 |