2011-08-25 23:41:19 +04:00
|
|
|
/* asn_public.h
|
2011-06-03 02:43:27 +04:00
|
|
|
*
|
2014-04-12 01:58:58 +04:00
|
|
|
* Copyright (C) 2006-2014 wolfSSL Inc.
|
2011-06-03 02:43:27 +04:00
|
|
|
*
|
|
|
|
* This file is part of CyaSSL.
|
|
|
|
*
|
|
|
|
* CyaSSL is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* CyaSSL is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2014-04-12 01:58:58 +04:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
2011-06-03 02:43:27 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef CTAO_CRYPT_ASN_PUBLIC_H
|
|
|
|
#define CTAO_CRYPT_ASN_PUBLIC_H
|
|
|
|
|
2011-08-25 23:41:19 +04:00
|
|
|
#include <cyassl/ctaocrypt/types.h>
|
2013-11-15 03:00:22 +04:00
|
|
|
#include <cyassl/ctaocrypt/ecc.h>
|
2011-06-04 00:01:45 +04:00
|
|
|
#ifdef CYASSL_CERT_GEN
|
2011-08-25 23:41:19 +04:00
|
|
|
#include <cyassl/ctaocrypt/rsa.h>
|
2011-06-04 00:01:45 +04:00
|
|
|
#endif
|
|
|
|
|
2011-06-03 02:43:27 +04:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2011-06-04 00:01:45 +04:00
|
|
|
/* Certificate file Type */
|
|
|
|
enum CertType {
|
|
|
|
CERT_TYPE = 0,
|
|
|
|
PRIVATEKEY_TYPE,
|
2011-11-01 04:33:40 +04:00
|
|
|
DH_PARAM_TYPE,
|
2012-05-17 04:04:56 +04:00
|
|
|
CRL_TYPE,
|
2013-04-12 01:03:18 +04:00
|
|
|
CA_TYPE,
|
2014-01-08 05:25:46 +04:00
|
|
|
ECC_PRIVATEKEY_TYPE,
|
|
|
|
CERTREQ_TYPE
|
2011-06-04 00:01:45 +04:00
|
|
|
};
|
|
|
|
|
2011-10-27 00:23:03 +04:00
|
|
|
|
|
|
|
/* Signature type, by OID sum */
|
|
|
|
enum Ctc_SigType {
|
|
|
|
CTC_SHAwDSA = 517,
|
|
|
|
CTC_MD2wRSA = 646,
|
|
|
|
CTC_MD5wRSA = 648,
|
|
|
|
CTC_SHAwRSA = 649,
|
|
|
|
CTC_SHAwECDSA = 520,
|
|
|
|
CTC_SHA256wRSA = 655,
|
2012-04-28 00:49:35 +04:00
|
|
|
CTC_SHA256wECDSA = 524,
|
|
|
|
CTC_SHA384wRSA = 656,
|
|
|
|
CTC_SHA384wECDSA = 525,
|
|
|
|
CTC_SHA512wRSA = 657,
|
|
|
|
CTC_SHA512wECDSA = 526
|
2011-10-27 00:23:03 +04:00
|
|
|
};
|
|
|
|
|
2014-05-23 18:42:37 +04:00
|
|
|
enum Ctc_Encoding {
|
|
|
|
CTC_UTF8 = 0x0c, /* utf8 */
|
|
|
|
CTC_PRINTABLE = 0x13 /* printable */
|
|
|
|
};
|
|
|
|
|
2011-10-27 00:23:03 +04:00
|
|
|
|
2011-06-04 00:01:45 +04:00
|
|
|
#ifdef CYASSL_CERT_GEN
|
|
|
|
|
2013-11-15 03:00:22 +04:00
|
|
|
#ifndef HAVE_ECC
|
|
|
|
typedef struct ecc_key ecc_key;
|
|
|
|
#endif
|
|
|
|
|
2011-06-04 00:01:45 +04:00
|
|
|
enum Ctc_Misc {
|
2012-04-05 23:48:28 +04:00
|
|
|
CTC_NAME_SIZE = 64,
|
2012-05-18 01:41:45 +04:00
|
|
|
CTC_DATE_SIZE = 32,
|
2012-04-05 23:48:28 +04:00
|
|
|
CTC_MAX_ALT_SIZE = 8192, /* may be huge */
|
|
|
|
CTC_SERIAL_SIZE = 8
|
2011-06-04 00:01:45 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct CertName {
|
|
|
|
char country[CTC_NAME_SIZE];
|
2014-05-23 18:11:46 +04:00
|
|
|
char countryEnc;
|
2011-06-04 00:01:45 +04:00
|
|
|
char state[CTC_NAME_SIZE];
|
2014-05-23 18:11:46 +04:00
|
|
|
char stateEnc;
|
2011-06-04 00:01:45 +04:00
|
|
|
char locality[CTC_NAME_SIZE];
|
2014-05-23 18:11:46 +04:00
|
|
|
char localityEnc;
|
2011-06-04 00:01:45 +04:00
|
|
|
char sur[CTC_NAME_SIZE];
|
2014-05-23 18:11:46 +04:00
|
|
|
char surEnc;
|
2011-06-04 00:01:45 +04:00
|
|
|
char org[CTC_NAME_SIZE];
|
2014-05-23 18:11:46 +04:00
|
|
|
char orgEnc;
|
2011-06-04 00:01:45 +04:00
|
|
|
char unit[CTC_NAME_SIZE];
|
2014-05-23 18:11:46 +04:00
|
|
|
char unitEnc;
|
2011-06-04 00:01:45 +04:00
|
|
|
char commonName[CTC_NAME_SIZE];
|
2014-05-23 18:11:46 +04:00
|
|
|
char commonNameEnc;
|
2011-06-04 00:01:45 +04:00
|
|
|
char email[CTC_NAME_SIZE]; /* !!!! email has to be last !!!! */
|
|
|
|
} CertName;
|
|
|
|
|
|
|
|
|
|
|
|
/* for user to fill for certificate generation */
|
|
|
|
typedef struct Cert {
|
|
|
|
int version; /* x509 version */
|
|
|
|
byte serial[CTC_SERIAL_SIZE]; /* serial number */
|
|
|
|
int sigType; /* signature algo type */
|
|
|
|
CertName issuer; /* issuer info */
|
|
|
|
int daysValid; /* validity days */
|
|
|
|
int selfSigned; /* self signed flag */
|
|
|
|
CertName subject; /* subject info */
|
2011-09-07 04:30:57 +04:00
|
|
|
int isCA; /* is this going to be a CA */
|
2011-06-04 00:01:45 +04:00
|
|
|
/* internal use only */
|
|
|
|
int bodySz; /* pre sign total size */
|
|
|
|
int keyType; /* public key type of subject */
|
2012-04-05 23:48:28 +04:00
|
|
|
#ifdef CYASSL_ALT_NAMES
|
2011-10-08 03:50:32 +04:00
|
|
|
byte altNames[CTC_MAX_ALT_SIZE]; /* altNames copy */
|
|
|
|
int altNamesSz; /* altNames size in bytes */
|
2012-05-18 01:41:45 +04:00
|
|
|
byte beforeDate[CTC_DATE_SIZE]; /* before date copy */
|
|
|
|
int beforeDateSz; /* size of copy */
|
|
|
|
byte afterDate[CTC_DATE_SIZE]; /* after date copy */
|
|
|
|
int afterDateSz; /* size of copy */
|
2012-04-05 23:48:28 +04:00
|
|
|
#endif
|
2014-01-10 02:17:55 +04:00
|
|
|
#ifdef CYASSL_CERT_REQ
|
|
|
|
char challengePw[CTC_NAME_SIZE];
|
|
|
|
#endif
|
2011-06-04 00:01:45 +04:00
|
|
|
} Cert;
|
|
|
|
|
|
|
|
|
2011-06-03 02:43:27 +04:00
|
|
|
|
|
|
|
|
|
|
|
/* Initialize and Set Certficate defaults:
|
|
|
|
version = 3 (0x2)
|
|
|
|
serial = 0 (Will be randomly generated)
|
2011-10-27 00:23:03 +04:00
|
|
|
sigType = SHA_WITH_RSA
|
2011-06-03 02:43:27 +04:00
|
|
|
issuer = blank
|
|
|
|
daysValid = 500
|
|
|
|
selfSigned = 1 (true) use subject as issuer
|
|
|
|
subject = blank
|
2011-09-07 04:30:57 +04:00
|
|
|
isCA = 0 (false)
|
2011-06-03 02:43:27 +04:00
|
|
|
keyType = RSA_KEY (default)
|
|
|
|
*/
|
|
|
|
CYASSL_API void InitCert(Cert*);
|
2013-11-15 08:34:39 +04:00
|
|
|
CYASSL_API int MakeCert(Cert*, byte* derBuffer, word32 derSz, RsaKey*,
|
|
|
|
ecc_key*, RNG*);
|
2014-01-08 05:25:46 +04:00
|
|
|
#ifdef CYASSL_CERT_REQ
|
|
|
|
CYASSL_API int MakeCertReq(Cert*, byte* derBuffer, word32 derSz, RsaKey*,
|
|
|
|
ecc_key*);
|
|
|
|
#endif
|
2013-11-20 04:56:49 +04:00
|
|
|
CYASSL_API int SignCert(int requestSz, int sigType, byte* derBuffer,
|
|
|
|
word32 derSz, RsaKey*, ecc_key*, RNG*);
|
2011-06-03 02:43:27 +04:00
|
|
|
CYASSL_API int MakeSelfCert(Cert*, byte* derBuffer, word32 derSz, RsaKey*,
|
|
|
|
RNG*);
|
|
|
|
CYASSL_API int SetIssuer(Cert*, const char*);
|
2011-08-18 00:07:52 +04:00
|
|
|
CYASSL_API int SetSubject(Cert*, const char*);
|
2012-04-05 23:48:28 +04:00
|
|
|
#ifdef CYASSL_ALT_NAMES
|
|
|
|
CYASSL_API int SetAltNames(Cert*, const char*);
|
|
|
|
#endif
|
2011-08-23 02:32:04 +04:00
|
|
|
CYASSL_API int SetIssuerBuffer(Cert*, const byte*, int);
|
|
|
|
CYASSL_API int SetSubjectBuffer(Cert*, const byte*, int);
|
2011-10-08 03:50:32 +04:00
|
|
|
CYASSL_API int SetAltNamesBuffer(Cert*, const byte*, int);
|
2012-05-18 01:41:45 +04:00
|
|
|
CYASSL_API int SetDatesBuffer(Cert*, const byte*, int);
|
2011-06-04 00:01:45 +04:00
|
|
|
|
|
|
|
#ifdef HAVE_NTRU
|
|
|
|
CYASSL_API int MakeNtruCert(Cert*, byte* derBuffer, word32 derSz,
|
|
|
|
const byte* ntruKey, word16 keySz, RNG*);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* CYASSL_CERT_GEN */
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(CYASSL_KEY_GEN) || defined(CYASSL_CERT_GEN)
|
|
|
|
CYASSL_API int DerToPem(const byte* der, word32 derSz, byte* output,
|
|
|
|
word32 outputSz, int type);
|
2011-06-03 02:43:27 +04:00
|
|
|
#endif
|
|
|
|
|
2013-11-15 03:00:22 +04:00
|
|
|
#ifdef HAVE_ECC
|
|
|
|
/* private key helpers */
|
|
|
|
CYASSL_API int EccPrivateKeyDecode(const byte* input,word32* inOutIdx,
|
|
|
|
ecc_key*,word32);
|
|
|
|
#endif
|
|
|
|
|
2011-06-03 02:43:27 +04:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
} /* extern "C" */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* CTAO_CRYPT_ASN_PUBLIC_H */
|
|
|
|
|