cyassl re-port with cellular comms, PSK test

Dependencies:   VodafoneUSBModem_bleedingedge2 mbed-rtos mbed-src

Committer:
ashleymills
Date:
Fri Apr 26 16:54:58 2013 +0000
Revision:
0:e979170e02e7
Basic operation of SSL with PSK working for cellular.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ashleymills 0:e979170e02e7 1 /* asn_public.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
ashleymills 0:e979170e02e7 23 #ifndef CTAO_CRYPT_ASN_PUBLIC_H
ashleymills 0:e979170e02e7 24 #define CTAO_CRYPT_ASN_PUBLIC_H
ashleymills 0:e979170e02e7 25
ashleymills 0:e979170e02e7 26 #include <cyassl/ctaocrypt/types.h>
ashleymills 0:e979170e02e7 27 #ifdef CYASSL_CERT_GEN
ashleymills 0:e979170e02e7 28 #include <cyassl/ctaocrypt/rsa.h>
ashleymills 0:e979170e02e7 29 #endif
ashleymills 0:e979170e02e7 30
ashleymills 0:e979170e02e7 31
ashleymills 0:e979170e02e7 32 #ifdef __cplusplus
ashleymills 0:e979170e02e7 33 extern "C" {
ashleymills 0:e979170e02e7 34 #endif
ashleymills 0:e979170e02e7 35
ashleymills 0:e979170e02e7 36
ashleymills 0:e979170e02e7 37 /* Certificate file Type */
ashleymills 0:e979170e02e7 38 enum CertType {
ashleymills 0:e979170e02e7 39 CERT_TYPE = 0,
ashleymills 0:e979170e02e7 40 PRIVATEKEY_TYPE,
ashleymills 0:e979170e02e7 41 DH_PARAM_TYPE,
ashleymills 0:e979170e02e7 42 CRL_TYPE,
ashleymills 0:e979170e02e7 43 CA_TYPE
ashleymills 0:e979170e02e7 44 };
ashleymills 0:e979170e02e7 45
ashleymills 0:e979170e02e7 46
ashleymills 0:e979170e02e7 47 /* Signature type, by OID sum */
ashleymills 0:e979170e02e7 48 enum Ctc_SigType {
ashleymills 0:e979170e02e7 49 CTC_SHAwDSA = 517,
ashleymills 0:e979170e02e7 50 CTC_MD2wRSA = 646,
ashleymills 0:e979170e02e7 51 CTC_MD5wRSA = 648,
ashleymills 0:e979170e02e7 52 CTC_SHAwRSA = 649,
ashleymills 0:e979170e02e7 53 CTC_SHAwECDSA = 520,
ashleymills 0:e979170e02e7 54 CTC_SHA256wRSA = 655,
ashleymills 0:e979170e02e7 55 CTC_SHA256wECDSA = 524,
ashleymills 0:e979170e02e7 56 CTC_SHA384wRSA = 656,
ashleymills 0:e979170e02e7 57 CTC_SHA384wECDSA = 525,
ashleymills 0:e979170e02e7 58 CTC_SHA512wRSA = 657,
ashleymills 0:e979170e02e7 59 CTC_SHA512wECDSA = 526
ashleymills 0:e979170e02e7 60 };
ashleymills 0:e979170e02e7 61
ashleymills 0:e979170e02e7 62
ashleymills 0:e979170e02e7 63 #ifdef CYASSL_CERT_GEN
ashleymills 0:e979170e02e7 64
ashleymills 0:e979170e02e7 65 enum Ctc_Misc {
ashleymills 0:e979170e02e7 66 CTC_NAME_SIZE = 64,
ashleymills 0:e979170e02e7 67 CTC_DATE_SIZE = 32,
ashleymills 0:e979170e02e7 68 CTC_MAX_ALT_SIZE = 8192, /* may be huge */
ashleymills 0:e979170e02e7 69 CTC_SERIAL_SIZE = 8
ashleymills 0:e979170e02e7 70 };
ashleymills 0:e979170e02e7 71
ashleymills 0:e979170e02e7 72 typedef struct CertName {
ashleymills 0:e979170e02e7 73 char country[CTC_NAME_SIZE];
ashleymills 0:e979170e02e7 74 char state[CTC_NAME_SIZE];
ashleymills 0:e979170e02e7 75 char locality[CTC_NAME_SIZE];
ashleymills 0:e979170e02e7 76 char sur[CTC_NAME_SIZE];
ashleymills 0:e979170e02e7 77 char org[CTC_NAME_SIZE];
ashleymills 0:e979170e02e7 78 char unit[CTC_NAME_SIZE];
ashleymills 0:e979170e02e7 79 char commonName[CTC_NAME_SIZE];
ashleymills 0:e979170e02e7 80 char email[CTC_NAME_SIZE]; /* !!!! email has to be last !!!! */
ashleymills 0:e979170e02e7 81 } CertName;
ashleymills 0:e979170e02e7 82
ashleymills 0:e979170e02e7 83
ashleymills 0:e979170e02e7 84 /* for user to fill for certificate generation */
ashleymills 0:e979170e02e7 85 typedef struct Cert {
ashleymills 0:e979170e02e7 86 int version; /* x509 version */
ashleymills 0:e979170e02e7 87 byte serial[CTC_SERIAL_SIZE]; /* serial number */
ashleymills 0:e979170e02e7 88 int sigType; /* signature algo type */
ashleymills 0:e979170e02e7 89 CertName issuer; /* issuer info */
ashleymills 0:e979170e02e7 90 int daysValid; /* validity days */
ashleymills 0:e979170e02e7 91 int selfSigned; /* self signed flag */
ashleymills 0:e979170e02e7 92 CertName subject; /* subject info */
ashleymills 0:e979170e02e7 93 int isCA; /* is this going to be a CA */
ashleymills 0:e979170e02e7 94 /* internal use only */
ashleymills 0:e979170e02e7 95 int bodySz; /* pre sign total size */
ashleymills 0:e979170e02e7 96 int keyType; /* public key type of subject */
ashleymills 0:e979170e02e7 97 #ifdef CYASSL_ALT_NAMES
ashleymills 0:e979170e02e7 98 byte altNames[CTC_MAX_ALT_SIZE]; /* altNames copy */
ashleymills 0:e979170e02e7 99 int altNamesSz; /* altNames size in bytes */
ashleymills 0:e979170e02e7 100 byte beforeDate[CTC_DATE_SIZE]; /* before date copy */
ashleymills 0:e979170e02e7 101 int beforeDateSz; /* size of copy */
ashleymills 0:e979170e02e7 102 byte afterDate[CTC_DATE_SIZE]; /* after date copy */
ashleymills 0:e979170e02e7 103 int afterDateSz; /* size of copy */
ashleymills 0:e979170e02e7 104 #endif
ashleymills 0:e979170e02e7 105 } Cert;
ashleymills 0:e979170e02e7 106
ashleymills 0:e979170e02e7 107
ashleymills 0:e979170e02e7 108
ashleymills 0:e979170e02e7 109
ashleymills 0:e979170e02e7 110 /* Initialize and Set Certficate defaults:
ashleymills 0:e979170e02e7 111 version = 3 (0x2)
ashleymills 0:e979170e02e7 112 serial = 0 (Will be randomly generated)
ashleymills 0:e979170e02e7 113 sigType = SHA_WITH_RSA
ashleymills 0:e979170e02e7 114 issuer = blank
ashleymills 0:e979170e02e7 115 daysValid = 500
ashleymills 0:e979170e02e7 116 selfSigned = 1 (true) use subject as issuer
ashleymills 0:e979170e02e7 117 subject = blank
ashleymills 0:e979170e02e7 118 isCA = 0 (false)
ashleymills 0:e979170e02e7 119 keyType = RSA_KEY (default)
ashleymills 0:e979170e02e7 120 */
ashleymills 0:e979170e02e7 121 CYASSL_API void InitCert(Cert*);
ashleymills 0:e979170e02e7 122 CYASSL_API int MakeCert(Cert*, byte* derBuffer, word32 derSz, RsaKey*, RNG*);
ashleymills 0:e979170e02e7 123 CYASSL_API int SignCert(Cert*, byte* derBuffer, word32 derSz, RsaKey*, RNG*);
ashleymills 0:e979170e02e7 124 CYASSL_API int MakeSelfCert(Cert*, byte* derBuffer, word32 derSz, RsaKey*,
ashleymills 0:e979170e02e7 125 RNG*);
ashleymills 0:e979170e02e7 126 CYASSL_API int SetIssuer(Cert*, const char*);
ashleymills 0:e979170e02e7 127 CYASSL_API int SetSubject(Cert*, const char*);
ashleymills 0:e979170e02e7 128 #ifdef CYASSL_ALT_NAMES
ashleymills 0:e979170e02e7 129 CYASSL_API int SetAltNames(Cert*, const char*);
ashleymills 0:e979170e02e7 130 #endif
ashleymills 0:e979170e02e7 131 CYASSL_API int SetIssuerBuffer(Cert*, const byte*, int);
ashleymills 0:e979170e02e7 132 CYASSL_API int SetSubjectBuffer(Cert*, const byte*, int);
ashleymills 0:e979170e02e7 133 CYASSL_API int SetAltNamesBuffer(Cert*, const byte*, int);
ashleymills 0:e979170e02e7 134 CYASSL_API int SetDatesBuffer(Cert*, const byte*, int);
ashleymills 0:e979170e02e7 135
ashleymills 0:e979170e02e7 136 #ifdef HAVE_NTRU
ashleymills 0:e979170e02e7 137 CYASSL_API int MakeNtruCert(Cert*, byte* derBuffer, word32 derSz,
ashleymills 0:e979170e02e7 138 const byte* ntruKey, word16 keySz, RNG*);
ashleymills 0:e979170e02e7 139 #endif
ashleymills 0:e979170e02e7 140
ashleymills 0:e979170e02e7 141 #endif /* CYASSL_CERT_GEN */
ashleymills 0:e979170e02e7 142
ashleymills 0:e979170e02e7 143
ashleymills 0:e979170e02e7 144 #if defined(CYASSL_KEY_GEN) || defined(CYASSL_CERT_GEN)
ashleymills 0:e979170e02e7 145 CYASSL_API int DerToPem(const byte* der, word32 derSz, byte* output,
ashleymills 0:e979170e02e7 146 word32 outputSz, int type);
ashleymills 0:e979170e02e7 147 #endif
ashleymills 0:e979170e02e7 148
ashleymills 0:e979170e02e7 149
ashleymills 0:e979170e02e7 150 #ifdef __cplusplus
ashleymills 0:e979170e02e7 151 } /* extern "C" */
ashleymills 0:e979170e02e7 152 #endif
ashleymills 0:e979170e02e7 153
ashleymills 0:e979170e02e7 154 #endif /* CTAO_CRYPT_ASN_PUBLIC_H */
ashleymills 0:e979170e02e7 155