2011-08-25 23:41:19 +04:00
|
|
|
/* internal.h
|
2011-02-05 22:14:47 +03:00
|
|
|
*
|
2013-02-06 00:44:17 +04:00
|
|
|
* Copyright (C) 2006-2013 wolfSSL Inc.
|
2011-02-05 22:14:47 +03: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
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef CYASSL_INT_H
|
|
|
|
#define CYASSL_INT_H
|
|
|
|
|
|
|
|
|
2012-10-30 02:39:42 +04:00
|
|
|
#include <cyassl/ctaocrypt/types.h>
|
2011-08-27 01:40:51 +04:00
|
|
|
#include <cyassl/ssl.h>
|
2012-05-17 04:04:56 +04:00
|
|
|
#include <cyassl/crl.h>
|
2011-08-25 23:41:19 +04:00
|
|
|
#include <cyassl/ctaocrypt/random.h>
|
|
|
|
#include <cyassl/ctaocrypt/des3.h>
|
|
|
|
#include <cyassl/ctaocrypt/hc128.h>
|
|
|
|
#include <cyassl/ctaocrypt/rabbit.h>
|
|
|
|
#include <cyassl/ctaocrypt/asn.h>
|
|
|
|
#include <cyassl/ctaocrypt/md5.h>
|
2013-03-08 05:44:40 +04:00
|
|
|
#include <cyassl/ctaocrypt/sha.h>
|
2011-08-25 23:41:19 +04:00
|
|
|
#include <cyassl/ctaocrypt/aes.h>
|
2013-01-21 22:53:42 +04:00
|
|
|
#include <cyassl/ctaocrypt/camellia.h>
|
2011-08-25 23:41:19 +04:00
|
|
|
#include <cyassl/ctaocrypt/logging.h>
|
2013-09-06 22:53:22 +04:00
|
|
|
#include <cyassl/ctaocrypt/hmac.h>
|
2012-11-28 10:17:25 +04:00
|
|
|
#ifndef NO_RC4
|
|
|
|
#include <cyassl/ctaocrypt/arc4.h>
|
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
#ifdef HAVE_ECC
|
2011-08-25 23:41:19 +04:00
|
|
|
#include <cyassl/ctaocrypt/ecc.h>
|
2011-02-05 22:14:47 +03:00
|
|
|
#endif
|
2011-02-28 23:21:06 +03:00
|
|
|
#ifndef NO_SHA256
|
2011-08-25 23:41:19 +04:00
|
|
|
#include <cyassl/ctaocrypt/sha256.h>
|
2011-02-28 23:21:06 +03:00
|
|
|
#endif
|
2012-05-03 01:45:30 +04:00
|
|
|
#ifdef HAVE_OCSP
|
|
|
|
#include <cyassl/ocsp.h>
|
|
|
|
#endif
|
2012-06-19 02:57:37 +04:00
|
|
|
#ifdef CYASSL_SHA512
|
|
|
|
#include <cyassl/ctaocrypt/sha512.h>
|
|
|
|
#endif
|
2013-05-16 20:47:27 +04:00
|
|
|
|
|
|
|
#ifdef HAVE_AESGCM
|
|
|
|
#include <cyassl/ctaocrypt/sha512.h>
|
|
|
|
#endif
|
|
|
|
|
2012-12-29 02:19:28 +04:00
|
|
|
#ifdef CYASSL_RIPEMD
|
|
|
|
#include <cyassl/ctaocrypt/ripemd.h>
|
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
#ifdef CYASSL_CALLBACKS
|
2013-04-09 02:34:54 +04:00
|
|
|
#include <cyassl/callbacks.h>
|
2011-02-05 22:14:47 +03:00
|
|
|
#include <signal.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_WINDOWS_API
|
2011-07-12 23:25:28 +04:00
|
|
|
#ifdef CYASSL_GAME_BUILD
|
|
|
|
#include "system/xtl.h"
|
|
|
|
#else
|
2011-12-15 23:42:31 +04:00
|
|
|
#if defined(_WIN32_WCE) || defined(WIN32_LEAN_AND_MEAN)
|
|
|
|
/* On WinCE winsock2.h must be included before windows.h */
|
|
|
|
#include <winsock2.h>
|
|
|
|
#endif
|
2011-07-12 23:25:28 +04:00
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
#elif defined(THREADX)
|
|
|
|
#ifndef SINGLE_THREADED
|
|
|
|
#include "tx_api.h"
|
|
|
|
#endif
|
|
|
|
#elif defined(MICRIUM)
|
|
|
|
/* do nothing, just don't pick Unix */
|
2012-08-16 04:00:11 +04:00
|
|
|
#elif defined(FREERTOS) || defined(CYASSL_SAFERTOS)
|
2012-08-02 19:54:41 +04:00
|
|
|
/* do nothing */
|
2012-08-14 03:10:05 +04:00
|
|
|
#elif defined(EBSNET)
|
|
|
|
/* do nothing */
|
2012-11-01 21:23:42 +04:00
|
|
|
#elif defined(FREESCALE_MQX)
|
|
|
|
/* do nothing */
|
2013-05-16 20:47:27 +04:00
|
|
|
#elif defined(CYASSL_MDK_ARM)
|
2013-11-07 05:29:01 +04:00
|
|
|
#if defined(CYASSL_MDK5)
|
|
|
|
#include "cmsis_os.h"
|
|
|
|
#else
|
|
|
|
#include <rtl.h>
|
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
#else
|
|
|
|
#ifndef SINGLE_THREADED
|
|
|
|
#define CYASSL_PTHREADS
|
|
|
|
#include <pthread.h>
|
|
|
|
#endif
|
|
|
|
#if defined(OPENSSL_EXTRA) || defined(GOAHEAD_WS)
|
|
|
|
#include <unistd.h> /* for close of BIO */
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2013-06-25 01:00:48 +04:00
|
|
|
|
2011-02-05 22:14:47 +03:00
|
|
|
#ifdef HAVE_LIBZ
|
|
|
|
#include "zlib.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
/* 4996 warning to use MS extensions e.g., strcpy_s instead of strncpy */
|
|
|
|
#pragma warning(disable: 4996)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NO_AES
|
|
|
|
#if !defined (ALIGN16)
|
|
|
|
#define ALIGN16
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2013-04-10 23:42:51 +04:00
|
|
|
#ifdef NO_SHA
|
|
|
|
#define SHA_DIGEST_SIZE 20
|
|
|
|
#endif
|
|
|
|
|
2011-04-26 22:29:40 +04:00
|
|
|
#ifdef NO_SHA256
|
|
|
|
#define SHA256_DIGEST_SIZE 32
|
|
|
|
#endif
|
|
|
|
|
2013-03-19 23:18:52 +04:00
|
|
|
|
2011-02-05 22:14:47 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef USE_WINDOWS_API
|
|
|
|
typedef unsigned int SOCKET_T;
|
|
|
|
#else
|
|
|
|
typedef int SOCKET_T;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
typedef byte word24[3];
|
|
|
|
|
2011-04-10 00:08:56 +04:00
|
|
|
/* used by ssl.c and cyassl_int.c */
|
|
|
|
void c32to24(word32 in, word24 out);
|
|
|
|
|
2011-02-05 22:14:47 +03:00
|
|
|
/* Define or comment out the cipher suites you'd like to be compiled in
|
|
|
|
make sure to use at least one BUILD_SSL_xxx or BUILD_TLS_xxx is defined
|
|
|
|
|
|
|
|
When adding cipher suites, add name to cipher_names, idx to cipher_name_idx
|
|
|
|
*/
|
2012-10-30 02:39:42 +04:00
|
|
|
#if !defined(NO_RSA) && !defined(NO_RC4)
|
2013-03-08 05:44:40 +04:00
|
|
|
#if !defined(NO_SHA)
|
2011-02-05 22:14:47 +03:00
|
|
|
#define BUILD_SSL_RSA_WITH_RC4_128_SHA
|
2013-03-08 05:44:40 +04:00
|
|
|
#endif
|
2013-03-12 04:37:08 +04:00
|
|
|
#if !defined(NO_MD5)
|
|
|
|
#define BUILD_SSL_RSA_WITH_RC4_128_MD5
|
|
|
|
#endif
|
|
|
|
#if !defined(NO_TLS) && defined(HAVE_NTRU) && !defined(NO_SHA)
|
2011-02-05 22:14:47 +03:00
|
|
|
#define BUILD_TLS_NTRU_RSA_WITH_RC4_128_SHA
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2012-10-30 02:39:42 +04:00
|
|
|
#if !defined(NO_RSA) && !defined(NO_DES3)
|
2013-03-08 05:44:40 +04:00
|
|
|
#if !defined(NO_SHA)
|
2011-02-05 22:14:47 +03:00
|
|
|
#define BUILD_SSL_RSA_WITH_3DES_EDE_CBC_SHA
|
|
|
|
#if !defined(NO_TLS) && defined(HAVE_NTRU)
|
|
|
|
#define BUILD_TLS_NTRU_RSA_WITH_3DES_EDE_CBC_SHA
|
|
|
|
#endif
|
2013-03-08 05:44:40 +04:00
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
#endif
|
|
|
|
|
2012-10-30 02:39:42 +04:00
|
|
|
#if !defined(NO_RSA) && !defined(NO_AES) && !defined(NO_TLS)
|
2013-03-08 05:44:40 +04:00
|
|
|
#if !defined(NO_SHA)
|
2011-02-05 22:14:47 +03:00
|
|
|
#define BUILD_TLS_RSA_WITH_AES_128_CBC_SHA
|
|
|
|
#define BUILD_TLS_RSA_WITH_AES_256_CBC_SHA
|
|
|
|
#if defined(HAVE_NTRU)
|
|
|
|
#define BUILD_TLS_NTRU_RSA_WITH_AES_128_CBC_SHA
|
|
|
|
#define BUILD_TLS_NTRU_RSA_WITH_AES_256_CBC_SHA
|
|
|
|
#endif
|
2013-03-08 05:44:40 +04:00
|
|
|
#endif
|
2011-03-04 22:13:28 +03:00
|
|
|
#if !defined (NO_SHA256)
|
|
|
|
#define BUILD_TLS_RSA_WITH_AES_128_CBC_SHA256
|
|
|
|
#define BUILD_TLS_RSA_WITH_AES_256_CBC_SHA256
|
|
|
|
#endif
|
2012-06-19 02:57:37 +04:00
|
|
|
#if defined (HAVE_AESGCM)
|
|
|
|
#define BUILD_TLS_RSA_WITH_AES_128_GCM_SHA256
|
2013-04-02 01:25:20 +04:00
|
|
|
#if defined (CYASSL_SHA384)
|
|
|
|
#define BUILD_TLS_RSA_WITH_AES_256_GCM_SHA384
|
|
|
|
#endif
|
2012-06-19 02:57:37 +04:00
|
|
|
#endif
|
2013-01-16 03:20:30 +04:00
|
|
|
#if defined (HAVE_AESCCM)
|
2013-03-22 22:30:12 +04:00
|
|
|
#define BUILD_TLS_RSA_WITH_AES_128_CCM_8
|
|
|
|
#define BUILD_TLS_RSA_WITH_AES_256_CCM_8
|
2013-01-16 03:20:30 +04:00
|
|
|
#endif
|
2013-10-24 22:30:51 +04:00
|
|
|
#if defined(HAVE_BLAKE2)
|
|
|
|
#define BUILD_TLS_RSA_WITH_AES_128_CBC_B2B256
|
|
|
|
#define BUILD_TLS_RSA_WITH_AES_256_CBC_B2B256
|
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
#endif
|
|
|
|
|
2013-01-21 22:53:42 +04:00
|
|
|
#if defined(HAVE_CAMELLIA) && !defined(NO_TLS)
|
|
|
|
#ifndef NO_RSA
|
2013-03-08 05:44:40 +04:00
|
|
|
#if !defined(NO_SHA)
|
2013-01-21 22:53:42 +04:00
|
|
|
#define BUILD_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA
|
|
|
|
#define BUILD_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA
|
2013-03-08 05:44:40 +04:00
|
|
|
#endif
|
2013-01-21 22:53:42 +04:00
|
|
|
#ifndef NO_SHA256
|
|
|
|
#define BUILD_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256
|
|
|
|
#define BUILD_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256
|
|
|
|
#endif
|
|
|
|
#if !defined(NO_DH) && defined(OPENSSL_EXTRA)
|
2013-03-08 05:44:40 +04:00
|
|
|
#if !defined(NO_SHA)
|
2013-01-21 22:53:42 +04:00
|
|
|
#define BUILD_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA
|
|
|
|
#define BUILD_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA
|
2013-03-08 05:44:40 +04:00
|
|
|
#endif
|
2013-01-21 22:53:42 +04:00
|
|
|
#ifndef NO_SHA256
|
|
|
|
#define BUILD_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256
|
|
|
|
#define BUILD_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2012-10-30 02:39:42 +04:00
|
|
|
#if !defined(NO_PSK) && !defined(NO_AES) && !defined(NO_TLS)
|
2013-03-08 05:44:40 +04:00
|
|
|
#if !defined(NO_SHA)
|
2012-10-30 02:39:42 +04:00
|
|
|
#define BUILD_TLS_PSK_WITH_AES_128_CBC_SHA
|
|
|
|
#define BUILD_TLS_PSK_WITH_AES_256_CBC_SHA
|
2013-03-08 05:44:40 +04:00
|
|
|
#endif
|
2012-11-21 02:52:17 +04:00
|
|
|
#ifndef NO_SHA256
|
|
|
|
#define BUILD_TLS_PSK_WITH_AES_128_CBC_SHA256
|
2013-03-22 22:30:12 +04:00
|
|
|
#ifdef HAVE_AESCCM
|
|
|
|
#define BUILD_TLS_PSK_WITH_AES_128_CCM_8
|
|
|
|
#define BUILD_TLS_PSK_WITH_AES_256_CCM_8
|
|
|
|
#endif
|
2012-11-21 02:52:17 +04:00
|
|
|
#endif
|
2012-10-30 02:39:42 +04:00
|
|
|
#endif
|
|
|
|
|
2012-10-20 07:52:22 +04:00
|
|
|
#if !defined(NO_TLS) && defined(HAVE_NULL_CIPHER)
|
2012-10-30 02:39:42 +04:00
|
|
|
#if !defined(NO_RSA)
|
2013-03-08 05:44:40 +04:00
|
|
|
#if !defined(NO_SHA)
|
2012-10-30 02:39:42 +04:00
|
|
|
#define BUILD_TLS_RSA_WITH_NULL_SHA
|
2013-03-08 05:44:40 +04:00
|
|
|
#endif
|
|
|
|
#ifndef NO_SHA256
|
2012-10-30 02:39:42 +04:00
|
|
|
#define BUILD_TLS_RSA_WITH_NULL_SHA256
|
2013-03-08 05:44:40 +04:00
|
|
|
#endif
|
2012-10-30 02:39:42 +04:00
|
|
|
#endif
|
2012-10-20 07:52:22 +04:00
|
|
|
#if !defined(NO_PSK)
|
2013-03-08 05:44:40 +04:00
|
|
|
#if !defined(NO_SHA)
|
2012-10-20 07:52:22 +04:00
|
|
|
#define BUILD_TLS_PSK_WITH_NULL_SHA
|
2013-03-08 05:44:40 +04:00
|
|
|
#endif
|
2012-11-21 02:52:17 +04:00
|
|
|
#ifndef NO_SHA256
|
2013-05-16 20:47:27 +04:00
|
|
|
#define BUILD_TLS_PSK_WITH_NULL_SHA256
|
2012-11-21 02:52:17 +04:00
|
|
|
#endif
|
2012-10-20 07:52:22 +04:00
|
|
|
#endif
|
2012-10-19 21:37:21 +04:00
|
|
|
#endif
|
|
|
|
|
2012-10-30 02:39:42 +04:00
|
|
|
#if !defined(NO_HC128) && !defined(NO_RSA) && !defined(NO_TLS)
|
2013-10-24 23:10:09 +04:00
|
|
|
#define BUILD_TLS_RSA_WITH_HC_128_MD5
|
2013-03-08 05:44:40 +04:00
|
|
|
#if !defined(NO_SHA)
|
2013-10-24 23:10:09 +04:00
|
|
|
#define BUILD_TLS_RSA_WITH_HC_128_SHA
|
2013-03-08 05:44:40 +04:00
|
|
|
#endif
|
2013-10-24 04:13:54 +04:00
|
|
|
#if defined(HAVE_BLAKE2)
|
2013-10-24 23:10:09 +04:00
|
|
|
#define BUILD_TLS_RSA_WITH_HC_128_B2B256
|
2013-10-24 04:13:54 +04:00
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
#endif
|
|
|
|
|
2012-10-30 02:39:42 +04:00
|
|
|
#if !defined(NO_RABBIT) && !defined(NO_TLS) && !defined(NO_RSA)
|
2013-03-08 05:44:40 +04:00
|
|
|
#if !defined(NO_SHA)
|
2013-10-24 22:52:21 +04:00
|
|
|
#define BUILD_TLS_RSA_WITH_RABBIT_SHA
|
2013-03-08 05:44:40 +04:00
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
#endif
|
|
|
|
|
2012-11-02 02:03:29 +04:00
|
|
|
#if !defined(NO_DH) && !defined(NO_AES) && !defined(NO_TLS) && \
|
|
|
|
!defined(NO_RSA) && defined(OPENSSL_EXTRA)
|
2013-03-08 05:44:40 +04:00
|
|
|
#if !defined(NO_SHA)
|
2011-02-05 22:14:47 +03:00
|
|
|
#define BUILD_TLS_DHE_RSA_WITH_AES_128_CBC_SHA
|
|
|
|
#define BUILD_TLS_DHE_RSA_WITH_AES_256_CBC_SHA
|
2013-03-08 05:44:40 +04:00
|
|
|
#endif
|
2011-04-26 20:32:18 +04:00
|
|
|
#if !defined (NO_SHA256)
|
|
|
|
#define BUILD_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256
|
|
|
|
#define BUILD_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256
|
2012-06-19 02:57:37 +04:00
|
|
|
#if defined (HAVE_AESGCM)
|
|
|
|
#define BUILD_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256
|
2013-04-02 01:25:20 +04:00
|
|
|
#if defined (CYASSL_SHA384)
|
|
|
|
#define BUILD_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384
|
|
|
|
#endif
|
2012-06-19 02:57:37 +04:00
|
|
|
#endif
|
2011-04-26 20:32:18 +04:00
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HAVE_ECC) && !defined(NO_TLS)
|
|
|
|
#if !defined(NO_AES)
|
2013-04-02 01:25:20 +04:00
|
|
|
#if !defined(NO_SHA)
|
|
|
|
#if !defined(NO_RSA)
|
|
|
|
#define BUILD_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
|
|
|
|
#define BUILD_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
|
|
|
|
#define BUILD_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA
|
|
|
|
#define BUILD_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
|
|
|
|
#define BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
|
|
|
|
|
|
|
|
#define BUILD_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA
|
|
|
|
#define BUILD_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA
|
|
|
|
#endif /* NO_SHA */
|
2013-03-05 01:25:46 +04:00
|
|
|
#ifndef NO_SHA256
|
2013-03-08 05:44:40 +04:00
|
|
|
#if !defined(NO_RSA)
|
|
|
|
#define BUILD_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
|
|
|
|
#define BUILD_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256
|
|
|
|
#endif
|
2013-03-05 01:25:46 +04:00
|
|
|
#define BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256
|
|
|
|
#define BUILD_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CYASSL_SHA384
|
2013-03-08 05:44:40 +04:00
|
|
|
#if !defined(NO_RSA)
|
|
|
|
#define BUILD_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
|
|
|
|
#define BUILD_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384
|
|
|
|
#endif
|
2013-03-05 01:25:46 +04:00
|
|
|
#define BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
|
|
|
|
#define BUILD_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384
|
|
|
|
#endif
|
|
|
|
|
2012-06-19 02:57:37 +04:00
|
|
|
#if defined (HAVE_AESGCM)
|
2013-03-08 05:44:40 +04:00
|
|
|
#if !defined(NO_RSA)
|
|
|
|
#define BUILD_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
|
|
|
|
#define BUILD_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256
|
2013-04-02 01:25:20 +04:00
|
|
|
#if defined(CYASSL_SHA384)
|
|
|
|
#define BUILD_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
|
|
|
|
#define BUILD_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384
|
|
|
|
#endif
|
2013-03-08 05:44:40 +04:00
|
|
|
#endif
|
|
|
|
|
2012-06-19 02:57:37 +04:00
|
|
|
#define BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
|
|
|
|
#define BUILD_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256
|
2013-04-02 01:25:20 +04:00
|
|
|
|
|
|
|
#if defined(CYASS_SHA384)
|
|
|
|
#define BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
|
|
|
|
#define BUILD_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384
|
|
|
|
#endif
|
2012-06-19 02:57:37 +04:00
|
|
|
#endif
|
2013-01-22 03:19:45 +04:00
|
|
|
#if defined (HAVE_AESCCM)
|
2013-03-22 22:30:12 +04:00
|
|
|
#define BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8
|
|
|
|
#define BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8
|
2013-01-22 03:19:45 +04:00
|
|
|
#endif
|
2013-04-02 01:25:20 +04:00
|
|
|
#endif /* NO_AES */
|
2011-02-05 22:14:47 +03:00
|
|
|
#if !defined(NO_RC4)
|
2013-03-08 05:44:40 +04:00
|
|
|
#if !defined(NO_SHA)
|
|
|
|
#if !defined(NO_RSA)
|
|
|
|
#define BUILD_TLS_ECDHE_RSA_WITH_RC4_128_SHA
|
|
|
|
#define BUILD_TLS_ECDH_RSA_WITH_RC4_128_SHA
|
|
|
|
#endif
|
2012-05-03 20:57:17 +04:00
|
|
|
|
2013-03-08 05:44:40 +04:00
|
|
|
#define BUILD_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA
|
|
|
|
#define BUILD_TLS_ECDH_ECDSA_WITH_RC4_128_SHA
|
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
#endif
|
|
|
|
#if !defined(NO_DES3)
|
2013-03-08 05:44:40 +04:00
|
|
|
#if !defined(NO_RSA)
|
|
|
|
#define BUILD_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA
|
|
|
|
#define BUILD_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA
|
|
|
|
#endif
|
2012-05-03 20:57:17 +04:00
|
|
|
|
2013-03-08 05:44:40 +04:00
|
|
|
#define BUILD_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA
|
2012-05-03 20:57:17 +04:00
|
|
|
#define BUILD_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA
|
2011-02-05 22:14:47 +03:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(BUILD_SSL_RSA_WITH_RC4_128_SHA) || \
|
|
|
|
defined(BUILD_SSL_RSA_WITH_RC4_128_MD5)
|
|
|
|
#define BUILD_ARC4
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(BUILD_SSL_RSA_WITH_3DES_EDE_CBC_SHA)
|
|
|
|
#define BUILD_DES3
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(BUILD_TLS_RSA_WITH_AES_128_CBC_SHA) || \
|
2013-03-08 05:44:40 +04:00
|
|
|
defined(BUILD_TLS_RSA_WITH_AES_256_CBC_SHA) || \
|
|
|
|
defined(BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256)
|
|
|
|
#undef BUILD_AES
|
2011-02-05 22:14:47 +03:00
|
|
|
#define BUILD_AES
|
|
|
|
#endif
|
|
|
|
|
2013-03-08 05:44:40 +04:00
|
|
|
#if defined(BUILD_TLS_RSA_WITH_AES_128_GCM_SHA256) || \
|
|
|
|
defined(BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256)
|
2012-06-26 20:30:48 +04:00
|
|
|
#define BUILD_AESGCM
|
|
|
|
#endif
|
|
|
|
|
2013-10-24 23:10:09 +04:00
|
|
|
#if defined(BUILD_TLS_RSA_WITH_HC_128_SHA) || \
|
|
|
|
defined(BUILD_TLS_RSA_WITH_HC_128_MD5) || \
|
|
|
|
defined(BUILD_TLS_RSA_WITH_HC_128_B2B256)
|
2011-02-05 22:14:47 +03:00
|
|
|
#define BUILD_HC128
|
|
|
|
#endif
|
|
|
|
|
2013-10-24 22:52:21 +04:00
|
|
|
#if defined(BUILD_TLS_RSA_WITH_RABBIT_SHA)
|
2011-02-05 22:14:47 +03:00
|
|
|
#define BUILD_RABBIT
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NO_DES3
|
|
|
|
#define DES_BLOCK_SIZE 8
|
2013-03-11 21:59:08 +04:00
|
|
|
#else
|
|
|
|
#undef BUILD_DES3
|
|
|
|
#define BUILD_DES3
|
2011-02-05 22:14:47 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NO_AES
|
|
|
|
#define AES_BLOCK_SIZE 16
|
2013-03-08 06:10:18 +04:00
|
|
|
#else
|
|
|
|
#undef BUILD_AES
|
|
|
|
#define BUILD_AES
|
2011-02-05 22:14:47 +03:00
|
|
|
#endif
|
|
|
|
|
2013-03-11 21:59:08 +04:00
|
|
|
#ifndef NO_RC4
|
|
|
|
#undef BUILD_ARC4
|
|
|
|
#define BUILD_ARC4
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-15 03:59:53 +04:00
|
|
|
#if defined(BUILD_AESGCM) || defined(HAVE_AESCCM)
|
|
|
|
#define HAVE_AEAD
|
|
|
|
#endif
|
|
|
|
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
/* actual cipher values, 2nd byte */
|
|
|
|
enum {
|
|
|
|
TLS_DHE_RSA_WITH_AES_256_CBC_SHA = 0x39,
|
|
|
|
TLS_DHE_RSA_WITH_AES_128_CBC_SHA = 0x33,
|
|
|
|
TLS_RSA_WITH_AES_256_CBC_SHA = 0x35,
|
|
|
|
TLS_RSA_WITH_AES_128_CBC_SHA = 0x2F,
|
2012-10-20 07:52:22 +04:00
|
|
|
TLS_RSA_WITH_NULL_SHA = 0x02,
|
2011-02-05 22:14:47 +03:00
|
|
|
TLS_PSK_WITH_AES_256_CBC_SHA = 0x8d,
|
2012-11-21 02:52:17 +04:00
|
|
|
TLS_PSK_WITH_AES_128_CBC_SHA256 = 0xae,
|
2011-02-05 22:14:47 +03:00
|
|
|
TLS_PSK_WITH_AES_128_CBC_SHA = 0x8c,
|
2012-11-21 02:52:17 +04:00
|
|
|
TLS_PSK_WITH_NULL_SHA256 = 0xb0,
|
2012-10-19 21:37:21 +04:00
|
|
|
TLS_PSK_WITH_NULL_SHA = 0x2c,
|
2011-02-05 22:14:47 +03:00
|
|
|
SSL_RSA_WITH_RC4_128_SHA = 0x05,
|
|
|
|
SSL_RSA_WITH_RC4_128_MD5 = 0x04,
|
|
|
|
SSL_RSA_WITH_3DES_EDE_CBC_SHA = 0x0A,
|
|
|
|
|
|
|
|
/* ECC suites, first byte is 0xC0 (ECC_BYTE) */
|
|
|
|
TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA = 0x14,
|
|
|
|
TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA = 0x13,
|
|
|
|
TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA = 0x0A,
|
|
|
|
TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA = 0x09,
|
|
|
|
TLS_ECDHE_RSA_WITH_RC4_128_SHA = 0x11,
|
|
|
|
TLS_ECDHE_ECDSA_WITH_RC4_128_SHA = 0x07,
|
|
|
|
TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA = 0x12,
|
|
|
|
TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA = 0x08,
|
2013-03-05 01:25:46 +04:00
|
|
|
TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 = 0x27,
|
|
|
|
TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 = 0x23,
|
|
|
|
TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 = 0x28,
|
|
|
|
TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 = 0x24,
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-03-05 01:25:46 +04:00
|
|
|
/* static ECDH, first byte is 0xC0 (ECC_BYTE) */
|
2012-05-03 20:57:17 +04:00
|
|
|
TLS_ECDH_RSA_WITH_AES_256_CBC_SHA = 0x0F,
|
|
|
|
TLS_ECDH_RSA_WITH_AES_128_CBC_SHA = 0x0E,
|
2012-05-03 19:18:59 +04:00
|
|
|
TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA = 0x05,
|
2012-05-03 20:57:17 +04:00
|
|
|
TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA = 0x04,
|
|
|
|
TLS_ECDH_RSA_WITH_RC4_128_SHA = 0x0C,
|
|
|
|
TLS_ECDH_ECDSA_WITH_RC4_128_SHA = 0x02,
|
|
|
|
TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA = 0x0D,
|
|
|
|
TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA = 0x03,
|
2013-03-05 01:25:46 +04:00
|
|
|
TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 = 0x29,
|
|
|
|
TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 = 0x25,
|
|
|
|
TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 = 0x2A,
|
|
|
|
TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 = 0x26,
|
2012-05-03 19:18:59 +04:00
|
|
|
|
2011-02-05 22:14:47 +03:00
|
|
|
/* CyaSSL extension - eSTREAM */
|
2013-10-24 23:10:09 +04:00
|
|
|
TLS_RSA_WITH_HC_128_MD5 = 0xFB,
|
|
|
|
TLS_RSA_WITH_HC_128_SHA = 0xFC,
|
|
|
|
TLS_RSA_WITH_RABBIT_SHA = 0xFD,
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-10-24 22:30:51 +04:00
|
|
|
/* CyaSSL extension - Blake2b 256 */
|
|
|
|
TLS_RSA_WITH_AES_128_CBC_B2B256 = 0xF8,
|
|
|
|
TLS_RSA_WITH_AES_256_CBC_B2B256 = 0xF9,
|
2013-10-24 23:10:09 +04:00
|
|
|
TLS_RSA_WITH_HC_128_B2B256 = 0xFA, /* eSTREAM too */
|
2013-10-24 22:30:51 +04:00
|
|
|
|
|
|
|
|
2011-02-05 22:14:47 +03:00
|
|
|
/* CyaSSL extension - NTRU */
|
2011-04-26 20:32:18 +04:00
|
|
|
TLS_NTRU_RSA_WITH_RC4_128_SHA = 0xe5,
|
|
|
|
TLS_NTRU_RSA_WITH_3DES_EDE_CBC_SHA = 0xe6,
|
|
|
|
TLS_NTRU_RSA_WITH_AES_128_CBC_SHA = 0xe7, /* clases w/ official SHA-256 */
|
|
|
|
TLS_NTRU_RSA_WITH_AES_256_CBC_SHA = 0xe8,
|
2011-03-04 22:13:28 +03:00
|
|
|
|
|
|
|
/* SHA256 */
|
2011-04-26 20:32:18 +04:00
|
|
|
TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 = 0x6b,
|
|
|
|
TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 = 0x67,
|
|
|
|
TLS_RSA_WITH_AES_256_CBC_SHA256 = 0x3d,
|
2012-06-19 02:57:37 +04:00
|
|
|
TLS_RSA_WITH_AES_128_CBC_SHA256 = 0x3c,
|
2012-10-20 07:52:22 +04:00
|
|
|
TLS_RSA_WITH_NULL_SHA256 = 0x3b,
|
2012-06-19 02:57:37 +04:00
|
|
|
|
|
|
|
/* AES-GCM */
|
|
|
|
TLS_RSA_WITH_AES_128_GCM_SHA256 = 0x9c,
|
|
|
|
TLS_RSA_WITH_AES_256_GCM_SHA384 = 0x9d,
|
|
|
|
TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 = 0x9e,
|
|
|
|
TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 = 0x9f,
|
|
|
|
|
|
|
|
/* ECC AES-GCM, first byte is 0xC0 (ECC_BYTE) */
|
|
|
|
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 = 0x2b,
|
|
|
|
TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 = 0x2c,
|
|
|
|
TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 = 0x2d,
|
|
|
|
TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 = 0x2e,
|
|
|
|
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 = 0x2f,
|
|
|
|
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 = 0x30,
|
|
|
|
TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 = 0x31,
|
2013-01-16 03:20:30 +04:00
|
|
|
TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 = 0x32,
|
|
|
|
|
|
|
|
/* AES-CCM, first byte is 0xC0 but isn't ECC,
|
|
|
|
* also, in some of the other AES-CCM suites
|
|
|
|
* there will be second byte number conflicts
|
|
|
|
* with non-ECC AES-GCM */
|
2013-03-22 22:30:12 +04:00
|
|
|
TLS_RSA_WITH_AES_128_CCM_8 = 0xa0,
|
|
|
|
TLS_RSA_WITH_AES_256_CCM_8 = 0xa1,
|
|
|
|
TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 = 0xc6, /* Still TBD, made up */
|
|
|
|
TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 = 0xc7, /* Still TBD, made up */
|
|
|
|
TLS_PSK_WITH_AES_128_CCM = 0xa4,
|
|
|
|
TLS_PSK_WITH_AES_256_CCM = 0xa5,
|
|
|
|
TLS_PSK_WITH_AES_128_CCM_8 = 0xa8,
|
|
|
|
TLS_PSK_WITH_AES_256_CCM_8 = 0xa9,
|
2013-01-21 22:53:42 +04:00
|
|
|
|
|
|
|
TLS_RSA_WITH_CAMELLIA_128_CBC_SHA = 0x41,
|
|
|
|
TLS_RSA_WITH_CAMELLIA_256_CBC_SHA = 0x84,
|
|
|
|
TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 = 0xba,
|
|
|
|
TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 = 0xc0,
|
|
|
|
TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA = 0x45,
|
|
|
|
TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA = 0x88,
|
|
|
|
TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 = 0xbe,
|
|
|
|
TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 = 0xc4
|
|
|
|
|
2011-02-05 22:14:47 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum Misc {
|
|
|
|
ECC_BYTE = 0xC0, /* ECC first cipher suite byte */
|
|
|
|
|
|
|
|
SEND_CERT = 1,
|
|
|
|
SEND_BLANK_CERT = 2,
|
|
|
|
|
|
|
|
DTLS_MAJOR = 0xfe, /* DTLS major version number */
|
|
|
|
DTLS_MINOR = 0xff, /* DTLS minor version number */
|
2013-03-07 11:02:33 +04:00
|
|
|
DTLSv1_2_MINOR = 0xfd, /* DTLS minor version number */
|
2011-02-05 22:14:47 +03:00
|
|
|
SSLv3_MAJOR = 3, /* SSLv3 and TLSv1+ major version number */
|
|
|
|
SSLv3_MINOR = 0, /* TLSv1 minor version number */
|
|
|
|
TLSv1_MINOR = 1, /* TLSv1 minor version number */
|
|
|
|
TLSv1_1_MINOR = 2, /* TLSv1_1 minor version number */
|
|
|
|
TLSv1_2_MINOR = 3, /* TLSv1_2 minor version number */
|
2012-10-10 03:13:05 +04:00
|
|
|
INVALID_BYTE = 0xff, /* Used to initialize cipher specs values */
|
2011-02-05 22:14:47 +03:00
|
|
|
NO_COMPRESSION = 0,
|
|
|
|
ZLIB_COMPRESSION = 221, /* CyaSSL zlib compression */
|
2012-07-09 21:02:34 +04:00
|
|
|
HELLO_EXT_SIG_ALGO = 13, /* ID for the sig_algo hello extension */
|
2011-02-05 22:14:47 +03:00
|
|
|
SECRET_LEN = 48, /* pre RSA and all master */
|
2011-05-17 21:42:57 +04:00
|
|
|
ENCRYPT_LEN = 512, /* allow 4096 bit static buffer */
|
2011-02-05 22:14:47 +03:00
|
|
|
SIZEOF_SENDER = 4, /* clnt or srvr */
|
2013-03-05 01:25:46 +04:00
|
|
|
FINISHED_SZ = 36, /* MD5_DIGEST_SIZE + SHA_DIGEST_SIZE */
|
2011-02-05 22:14:47 +03:00
|
|
|
MAX_RECORD_SIZE = 16384, /* 2^14, max size by standard */
|
2013-03-05 01:25:46 +04:00
|
|
|
MAX_MSG_EXTRA = 38 + MAX_DIGEST_SIZE,
|
|
|
|
/* max added to msg, mac + pad from */
|
|
|
|
/* RECORD_HEADER_SZ + BLOCK_SZ (pad) + Max
|
2012-07-17 22:52:13 +04:00
|
|
|
digest sz + BLOC_SZ (iv) + pad byte (1) */
|
2011-02-05 22:14:47 +03:00
|
|
|
MAX_COMP_EXTRA = 1024, /* max compression extra */
|
|
|
|
MAX_MTU = 1500, /* max expected MTU */
|
2013-05-17 21:29:34 +04:00
|
|
|
MAX_UDP_SIZE = 8192 - 100, /* was MAX_MTU - 100 */
|
2011-02-05 22:14:47 +03:00
|
|
|
MAX_DH_SZ = 612, /* 2240 p, pub, g + 2 byte size for each */
|
|
|
|
MAX_STR_VERSION = 8, /* string rep of protocol version */
|
|
|
|
|
|
|
|
PAD_MD5 = 48, /* pad length for finished */
|
|
|
|
PAD_SHA = 40, /* pad length for finished */
|
2012-12-28 04:35:43 +04:00
|
|
|
MAX_PAD_SIZE = 256, /* maximum length of padding */
|
|
|
|
COMPRESS_DUMMY_SIZE = 64, /* compression dummy round size */
|
|
|
|
COMPRESS_CONSTANT = 13, /* compression calc constant */
|
|
|
|
COMPRESS_UPPER = 55, /* compression calc numerator */
|
|
|
|
COMPRESS_LOWER = 64, /* compression calc denominator */
|
|
|
|
|
2011-02-05 22:14:47 +03:00
|
|
|
PEM_LINE_LEN = 80, /* PEM line max + fudge */
|
|
|
|
LENGTH_SZ = 2, /* length field for HMAC, data only */
|
|
|
|
VERSION_SZ = 2, /* length of proctocol version */
|
|
|
|
SEQ_SZ = 8, /* 64 bit sequence number */
|
|
|
|
BYTE3_LEN = 3, /* up to 24 bit byte lengths */
|
|
|
|
ALERT_SIZE = 2, /* level + description */
|
|
|
|
REQUEST_HEADER = 2, /* always use 2 bytes */
|
|
|
|
VERIFY_HEADER = 2, /* always use 2 bytes */
|
2013-02-19 02:36:50 +04:00
|
|
|
EXT_ID_SZ = 2, /* always use 2 bytes */
|
2011-11-02 01:05:14 +04:00
|
|
|
MAX_DH_SIZE = 513, /* 4096 bit plus possible leading 0 */
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
MAX_SUITE_SZ = 200, /* 100 suites for now! */
|
|
|
|
RAN_LEN = 32, /* random length */
|
|
|
|
SEED_LEN = RAN_LEN * 2, /* tls prf seed length */
|
|
|
|
ID_LEN = 32, /* session id length */
|
|
|
|
MAX_COOKIE_LEN = 32, /* max dtls cookie size */
|
2012-08-08 21:38:12 +04:00
|
|
|
COOKIE_SZ = 20, /* use a 20 byte cookie */
|
2011-02-05 22:14:47 +03:00
|
|
|
SUITE_LEN = 2, /* cipher suite sz length */
|
|
|
|
ENUM_LEN = 1, /* always a byte */
|
2013-05-22 01:37:50 +04:00
|
|
|
OPAQUE16_LEN = 2, /* always 2 bytes */
|
2011-02-05 22:14:47 +03:00
|
|
|
COMP_LEN = 1, /* compression length */
|
|
|
|
CURVE_LEN = 2, /* ecc named curve length */
|
2013-04-30 01:22:32 +04:00
|
|
|
SERVER_ID_LEN = 20, /* server session id length */
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-05-22 01:37:50 +04:00
|
|
|
HANDSHAKE_HEADER_SZ = 4, /* type + length(3) */
|
|
|
|
RECORD_HEADER_SZ = 5, /* type + version + len(2) */
|
|
|
|
CERT_HEADER_SZ = 3, /* always 3 bytes */
|
|
|
|
REQ_HEADER_SZ = 2, /* cert request header sz */
|
|
|
|
HINT_LEN_SZ = 2, /* length of hint size field */
|
2013-12-02 23:08:17 +04:00
|
|
|
TRUNCATED_HMAC_SZ = 10, /* length of hmac w/ truncated hmac extension */
|
2013-05-22 01:37:50 +04:00
|
|
|
HELLO_EXT_TYPE_SZ = 2, /* length of a hello extension type */
|
|
|
|
HELLO_EXT_SZ = 8, /* total length of the lazy hello extensions */
|
|
|
|
HELLO_EXT_LEN = 6, /* length of the lazy hello extensions */
|
|
|
|
HELLO_EXT_SIGALGO_SZ = 2, /* length of signature algo extension */
|
2013-02-19 02:36:50 +04:00
|
|
|
HELLO_EXT_SIGALGO_MAX = 32, /* number of items in the signature algo list */
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
DTLS_HANDSHAKE_HEADER_SZ = 12, /* normal + seq(2) + offset(3) + length(3) */
|
|
|
|
DTLS_RECORD_HEADER_SZ = 13, /* normal + epoch(2) + seq_num(6) */
|
|
|
|
DTLS_HANDSHAKE_EXTRA = 8, /* diff from normal */
|
|
|
|
DTLS_RECORD_EXTRA = 8, /* diff from normal */
|
2012-08-10 00:27:30 +04:00
|
|
|
DTLS_HANDSHAKE_SEQ_SZ = 2, /* handshake header sequence number */
|
|
|
|
DTLS_HANDSHAKE_FRAG_SZ = 3, /* fragment offset and length are 24 bit */
|
2012-09-14 20:35:34 +04:00
|
|
|
DTLS_POOL_SZ = 5, /* buffers to hold in the retry pool */
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
FINISHED_LABEL_SZ = 15, /* TLS finished label size */
|
|
|
|
TLS_FINISHED_SZ = 12, /* TLS has a shorter size */
|
|
|
|
MASTER_LABEL_SZ = 13, /* TLS master secret label sz */
|
|
|
|
KEY_LABEL_SZ = 13, /* TLS key block expansion sz */
|
|
|
|
MAX_PRF_HALF = 128, /* Maximum half secret len */
|
2013-03-22 22:30:12 +04:00
|
|
|
MAX_PRF_LABSEED = 128, /* Maximum label + seed len */
|
2011-03-04 22:13:28 +03:00
|
|
|
MAX_PRF_DIG = 224, /* Maximum digest len */
|
2011-02-05 22:14:47 +03:00
|
|
|
MAX_REQUEST_SZ = 256, /* Maximum cert req len (no auth yet */
|
|
|
|
SESSION_FLUSH_COUNT = 256, /* Flush session cache unless user turns off */
|
|
|
|
|
|
|
|
RC4_KEY_SIZE = 16, /* always 128bit */
|
|
|
|
DES_KEY_SIZE = 8, /* des */
|
|
|
|
DES3_KEY_SIZE = 24, /* 3 des ede */
|
|
|
|
DES_IV_SIZE = DES_BLOCK_SIZE,
|
|
|
|
AES_256_KEY_SIZE = 32, /* for 256 bit */
|
|
|
|
AES_192_KEY_SIZE = 24, /* for 192 bit */
|
|
|
|
AES_IV_SIZE = 16, /* always block size */
|
|
|
|
AES_128_KEY_SIZE = 16, /* for 128 bit */
|
|
|
|
|
2012-07-17 21:00:45 +04:00
|
|
|
AEAD_SEQ_OFFSET = 4, /* Auth Data: Sequence number */
|
|
|
|
AEAD_TYPE_OFFSET = 8, /* Auth Data: Type */
|
|
|
|
AEAD_VMAJ_OFFSET = 9, /* Auth Data: Major Version */
|
|
|
|
AEAD_VMIN_OFFSET = 10, /* Auth Data: Minor Version */
|
|
|
|
AEAD_LEN_OFFSET = 11, /* Auth Data: Length */
|
|
|
|
AEAD_AUTH_DATA_SZ = 13, /* Size of the data to authenticate */
|
2013-01-16 03:20:30 +04:00
|
|
|
AEAD_IMP_IV_SZ = 4, /* Size of the implicit IV */
|
|
|
|
AEAD_EXP_IV_SZ = 8, /* Size of the explicit IV */
|
|
|
|
AEAD_NONCE_SZ = AEAD_EXP_IV_SZ + AEAD_IMP_IV_SZ,
|
2012-07-17 21:00:45 +04:00
|
|
|
|
2013-03-22 22:30:12 +04:00
|
|
|
AES_GCM_AUTH_SZ = 16, /* AES-GCM Auth Tag length */
|
|
|
|
AES_CCM_16_AUTH_SZ = 16, /* AES-CCM-16 Auth Tag length */
|
|
|
|
AES_CCM_8_AUTH_SZ = 8, /* AES-CCM-8 Auth Tag Length */
|
|
|
|
|
2013-01-21 22:53:42 +04:00
|
|
|
CAMELLIA_128_KEY_SIZE = 16, /* for 128 bit */
|
|
|
|
CAMELLIA_192_KEY_SIZE = 24, /* for 192 bit */
|
|
|
|
CAMELLIA_256_KEY_SIZE = 32, /* for 256 bit */
|
|
|
|
CAMELLIA_IV_SIZE = 16, /* always block size */
|
|
|
|
|
2011-02-05 22:14:47 +03:00
|
|
|
HC_128_KEY_SIZE = 16, /* 128 bits */
|
|
|
|
HC_128_IV_SIZE = 16, /* also 128 bits */
|
|
|
|
|
|
|
|
RABBIT_KEY_SIZE = 16, /* 128 bits */
|
|
|
|
RABBIT_IV_SIZE = 8, /* 64 bits for iv */
|
|
|
|
|
|
|
|
EVP_SALT_SIZE = 8, /* evp salt size 64 bits */
|
|
|
|
|
|
|
|
ECDHE_SIZE = 32, /* ECHDE server size defaults to 256 bit */
|
|
|
|
MAX_EXPORT_ECC_SZ = 256, /* Export ANS X9.62 max future size */
|
|
|
|
|
|
|
|
MAX_HELLO_SZ = 128, /* max client or server hello */
|
|
|
|
MAX_CERT_VERIFY_SZ = 1024, /* max */
|
|
|
|
CLIENT_HELLO_FIRST = 35, /* Protocol + RAN_LEN + sizeof(id_len) */
|
|
|
|
MAX_SUITE_NAME = 48, /* maximum length of cipher suite string */
|
|
|
|
DEFAULT_TIMEOUT = 500, /* default resumption timeout in seconds */
|
2013-05-08 03:14:26 +04:00
|
|
|
|
|
|
|
DTLS_TIMEOUT_INIT = 1, /* default timeout init for DTLS receive */
|
|
|
|
DTLS_TIMEOUT_MAX = 64, /* default max timeout for DTLS receive */
|
|
|
|
DTLS_TIMEOUT_MULTIPLIER = 2, /* default timeout multiplier for DTLS recv */
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
MAX_PSK_ID_LEN = 128, /* max psk identity/hint supported */
|
|
|
|
MAX_PSK_KEY_LEN = 64, /* max psk key supported */
|
|
|
|
|
2013-02-15 04:00:45 +04:00
|
|
|
MAX_CYASSL_FILE_SIZE = 1024 * 1024 * 4, /* 4 mb file size alloc limit */
|
|
|
|
|
2012-03-12 21:31:45 +04:00
|
|
|
#ifdef FORTRESS
|
2012-03-19 22:30:48 +04:00
|
|
|
MAX_EX_DATA = 3, /* allow for three items of ex_data */
|
2012-03-12 21:31:45 +04:00
|
|
|
#endif
|
2012-11-05 22:40:06 +04:00
|
|
|
|
2011-02-05 22:14:47 +03:00
|
|
|
MAX_X509_SIZE = 2048, /* max static x509 buffer size */
|
2011-04-14 21:49:38 +04:00
|
|
|
CERT_MIN_SIZE = 256, /* min PEM cert size with header/footer */
|
2012-02-09 06:07:20 +04:00
|
|
|
MAX_FILENAME_SZ = 256, /* max file name length */
|
2011-02-05 22:14:47 +03:00
|
|
|
FILE_BUFFER_SIZE = 1024, /* default static file buffer size for input,
|
|
|
|
will use dynamic buffer if not big enough */
|
|
|
|
|
|
|
|
MAX_NTRU_PUB_KEY_SZ = 1027, /* NTRU max for now */
|
|
|
|
MAX_NTRU_ENCRYPT_SZ = 1027, /* NTRU max for now */
|
|
|
|
MAX_NTRU_BITS = 256, /* max symmetric bit strength */
|
|
|
|
NO_SNIFF = 0, /* not sniffing */
|
|
|
|
SNIFF = 1, /* currently sniffing */
|
|
|
|
|
2011-02-28 23:21:06 +03:00
|
|
|
HASH_SIG_SIZE = 2, /* default SHA1 RSA */
|
|
|
|
|
2013-02-02 00:21:38 +04:00
|
|
|
NO_CAVIUM_DEVICE = -2, /* invalid cavium device id */
|
|
|
|
|
2011-02-05 22:14:47 +03:00
|
|
|
NO_COPY = 0, /* should we copy static buffer for write */
|
2012-03-19 22:30:48 +04:00
|
|
|
COPY = 1 /* should we copy static buffer for write */
|
2011-02-05 22:14:47 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-03 03:03:41 +04:00
|
|
|
#ifdef SESSION_INDEX
|
|
|
|
/* Shift values for making a session index */
|
|
|
|
#define SESSIDX_ROW_SHIFT 4
|
|
|
|
#define SESSIDX_IDX_MASK 0x0F
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2012-11-05 22:40:06 +04:00
|
|
|
/* max cert chain peer depth */
|
|
|
|
#ifndef MAX_CHAIN_DEPTH
|
|
|
|
#define MAX_CHAIN_DEPTH 9
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2012-09-05 02:56:52 +04:00
|
|
|
/* don't use extra 3/4k stack space unless need to */
|
|
|
|
#ifdef HAVE_NTRU
|
|
|
|
#define MAX_ENCRYPT_SZ MAX_NTRU_ENCRYPT_SZ
|
|
|
|
#else
|
|
|
|
#define MAX_ENCRYPT_SZ ENCRYPT_LEN
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2011-02-05 22:14:47 +03:00
|
|
|
/* states */
|
|
|
|
enum states {
|
|
|
|
NULL_STATE = 0,
|
|
|
|
|
|
|
|
SERVER_HELLOVERIFYREQUEST_COMPLETE,
|
|
|
|
SERVER_HELLO_COMPLETE,
|
|
|
|
SERVER_CERT_COMPLETE,
|
|
|
|
SERVER_KEYEXCHANGE_COMPLETE,
|
|
|
|
SERVER_HELLODONE_COMPLETE,
|
|
|
|
SERVER_FINISHED_COMPLETE,
|
|
|
|
|
|
|
|
CLIENT_HELLO_COMPLETE,
|
|
|
|
CLIENT_KEYEXCHANGE_COMPLETE,
|
|
|
|
CLIENT_FINISHED_COMPLETE,
|
|
|
|
|
|
|
|
HANDSHAKE_DONE
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-03-08 05:44:40 +04:00
|
|
|
#if defined(__GNUC__)
|
|
|
|
#define CYASSL_PACK __attribute__ ((packed))
|
|
|
|
#else
|
|
|
|
#define CYASSL_PACK
|
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
/* SSL Version */
|
|
|
|
typedef struct ProtocolVersion {
|
|
|
|
byte major;
|
|
|
|
byte minor;
|
2013-03-08 05:44:40 +04:00
|
|
|
} CYASSL_PACK ProtocolVersion;
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
|
2011-04-27 02:41:16 +04:00
|
|
|
CYASSL_LOCAL ProtocolVersion MakeSSLv3(void);
|
|
|
|
CYASSL_LOCAL ProtocolVersion MakeTLSv1(void);
|
|
|
|
CYASSL_LOCAL ProtocolVersion MakeTLSv1_1(void);
|
|
|
|
CYASSL_LOCAL ProtocolVersion MakeTLSv1_2(void);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
#ifdef CYASSL_DTLS
|
2011-04-27 02:41:16 +04:00
|
|
|
CYASSL_LOCAL ProtocolVersion MakeDTLSv1(void);
|
2013-03-07 11:02:33 +04:00
|
|
|
CYASSL_LOCAL ProtocolVersion MakeDTLSv1_2(void);
|
2011-02-05 22:14:47 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
enum BIO_TYPE {
|
|
|
|
BIO_BUFFER = 1,
|
|
|
|
BIO_SOCKET = 2,
|
2012-04-27 03:27:27 +04:00
|
|
|
BIO_SSL = 3,
|
|
|
|
BIO_MEMORY = 4
|
2011-02-05 22:14:47 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-08-27 01:40:51 +04:00
|
|
|
/* CyaSSL BIO_METHOD type */
|
|
|
|
struct CYASSL_BIO_METHOD {
|
2011-02-05 22:14:47 +03:00
|
|
|
byte type; /* method type */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-08-27 01:40:51 +04:00
|
|
|
/* CyaSSL BIO type */
|
|
|
|
struct CYASSL_BIO {
|
|
|
|
byte type; /* method type */
|
|
|
|
byte close; /* close flag */
|
|
|
|
byte eof; /* eof flag */
|
|
|
|
CYASSL* ssl; /* possible associated ssl */
|
2012-04-27 03:27:27 +04:00
|
|
|
byte* mem; /* memory buffer */
|
|
|
|
int memLen; /* memory buffer length */
|
2011-08-27 01:40:51 +04:00
|
|
|
int fd; /* possible file descriptor */
|
|
|
|
CYASSL_BIO* prev; /* previous in chain */
|
|
|
|
CYASSL_BIO* next; /* next in chain */
|
2011-02-05 22:14:47 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-08-27 01:40:51 +04:00
|
|
|
/* CyaSSL method type */
|
|
|
|
struct CYASSL_METHOD {
|
2011-02-05 22:14:47 +03:00
|
|
|
ProtocolVersion version;
|
2011-07-13 00:23:32 +04:00
|
|
|
byte side; /* connection side, server or client */
|
|
|
|
byte downgrade; /* whether to downgrade version, default no */
|
2011-02-05 22:14:47 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* defautls to client */
|
2011-08-27 01:40:51 +04:00
|
|
|
CYASSL_LOCAL void InitSSL_Method(CYASSL_METHOD*, ProtocolVersion);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
/* for sniffer */
|
2011-08-27 01:40:51 +04:00
|
|
|
CYASSL_LOCAL int DoFinished(CYASSL* ssl, const byte* input, word32* inOutIdx,
|
2011-04-27 02:41:16 +04:00
|
|
|
int sniff);
|
2011-08-27 01:40:51 +04:00
|
|
|
CYASSL_LOCAL int DoApplicationData(CYASSL* ssl, byte* input, word32* inOutIdx);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
/* CyaSSL buffer type */
|
|
|
|
typedef struct buffer {
|
|
|
|
word32 length;
|
|
|
|
byte* buffer;
|
|
|
|
} buffer;
|
|
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
FORCED_FREE = 1,
|
|
|
|
NO_FORCED_FREE = 0
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* only use compression extra if using compression */
|
|
|
|
#ifdef HAVE_LIBZ
|
|
|
|
#define COMP_EXTRA MAX_COMP_EXTRA
|
|
|
|
#else
|
|
|
|
#define COMP_EXTRA 0
|
|
|
|
#endif
|
|
|
|
|
2012-07-21 00:04:03 +04:00
|
|
|
/* only the sniffer needs space in the buffer for extra MTU record(s) */
|
2011-02-05 22:14:47 +03:00
|
|
|
#ifdef CYASSL_SNIFFER
|
2012-07-21 00:04:03 +04:00
|
|
|
#define MTU_EXTRA MAX_MTU * 3
|
2011-02-05 22:14:47 +03:00
|
|
|
#else
|
|
|
|
#define MTU_EXTRA 0
|
|
|
|
#endif
|
|
|
|
|
2013-05-20 23:46:54 +04:00
|
|
|
|
|
|
|
/* embedded callbacks require large static buffers, make sure on */
|
|
|
|
#ifdef CYASSL_CALLBACKS
|
|
|
|
#undef LARGE_STATIC_BUFFERS
|
|
|
|
#define LARGE_STATIC_BUFFERS
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2012-10-25 04:37:57 +04:00
|
|
|
/* give user option to use 16K static buffers */
|
|
|
|
#if defined(LARGE_STATIC_BUFFERS)
|
2011-02-05 22:14:47 +03:00
|
|
|
#define RECORD_SIZE MAX_RECORD_SIZE
|
|
|
|
#else
|
|
|
|
#ifdef CYASSL_DTLS
|
2011-03-12 01:10:32 +03:00
|
|
|
#define RECORD_SIZE MAX_MTU
|
2011-02-05 22:14:47 +03:00
|
|
|
#else
|
|
|
|
#define RECORD_SIZE 128
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* user option to turn off 16K output option */
|
|
|
|
/* if using small static buffers (default) and SSL_write tries to write data
|
|
|
|
larger than the record we have, dynamically get it, unless user says only
|
|
|
|
write in static buffer chuncks */
|
|
|
|
#ifndef STATIC_CHUNKS_ONLY
|
|
|
|
#define OUTPUT_RECORD_SIZE MAX_RECORD_SIZE
|
|
|
|
#else
|
|
|
|
#define OUTPUT_RECORD_SIZE RECORD_SIZE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* CyaSSL input buffer
|
|
|
|
|
|
|
|
RFC 2246:
|
|
|
|
|
|
|
|
length
|
|
|
|
The length (in bytes) of the following TLSPlaintext.fragment.
|
|
|
|
The length should not exceed 2^14.
|
|
|
|
*/
|
2013-03-16 01:21:36 +04:00
|
|
|
#if defined(LARGE_STATIC_BUFFERS)
|
2012-09-15 08:19:06 +04:00
|
|
|
#define STATIC_BUFFER_LEN RECORD_HEADER_SZ + RECORD_SIZE + COMP_EXTRA + \
|
|
|
|
MTU_EXTRA + MAX_MSG_EXTRA
|
|
|
|
#else
|
|
|
|
/* zero length arrays may not be supported */
|
|
|
|
#define STATIC_BUFFER_LEN 1
|
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
word32 length; /* total buffer length used */
|
|
|
|
word32 idx; /* idx to part of length already consumed */
|
|
|
|
byte* buffer; /* place holder for static or dynamic buffer */
|
|
|
|
word32 bufferSize; /* current buffer size */
|
2013-01-02 23:39:12 +04:00
|
|
|
ALIGN16 byte staticBuffer[STATIC_BUFFER_LEN];
|
2013-03-28 02:11:49 +04:00
|
|
|
byte dynamicFlag; /* dynamic memory currently in use */
|
|
|
|
byte offset; /* alignment offset attempt */
|
2011-02-05 22:14:47 +03:00
|
|
|
} bufferStatic;
|
|
|
|
|
|
|
|
/* Cipher Suites holder */
|
|
|
|
typedef struct Suites {
|
|
|
|
int setSuites; /* user set suites from default */
|
|
|
|
byte suites[MAX_SUITE_SZ];
|
|
|
|
word16 suiteSz; /* suite length in bytes */
|
2013-02-19 02:36:50 +04:00
|
|
|
byte hashSigAlgo[HELLO_EXT_SIGALGO_MAX]; /* sig/algo to offer */
|
|
|
|
word16 hashSigAlgoSz; /* SigAlgo extension length in bytes */
|
|
|
|
byte hashAlgo; /* selected hash algorithm */
|
|
|
|
byte sigAlgo; /* selected sig algorithm */
|
2011-02-05 22:14:47 +03:00
|
|
|
} Suites;
|
|
|
|
|
|
|
|
|
2011-04-27 02:41:16 +04:00
|
|
|
CYASSL_LOCAL
|
2012-10-30 02:39:42 +04:00
|
|
|
void InitSuites(Suites*, ProtocolVersion,
|
|
|
|
byte, byte, byte, byte, byte, byte, int);
|
2011-04-27 02:41:16 +04:00
|
|
|
CYASSL_LOCAL
|
2011-10-29 05:43:07 +04:00
|
|
|
int SetCipherList(Suites*, const char* list);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
#ifndef PSK_TYPES_DEFINED
|
2011-08-27 01:40:51 +04:00
|
|
|
typedef unsigned int (*psk_client_callback)(CYASSL*, const char*, char*,
|
2011-02-05 22:14:47 +03:00
|
|
|
unsigned int, unsigned char*, unsigned int);
|
2011-08-27 01:40:51 +04:00
|
|
|
typedef unsigned int (*psk_server_callback)(CYASSL*, const char*,
|
2011-02-05 22:14:47 +03:00
|
|
|
unsigned char*, unsigned int);
|
|
|
|
#endif /* PSK_TYPES_DEFINED */
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef CYASSL_USER_IO
|
|
|
|
/* default IO callbacks */
|
2011-04-27 02:41:16 +04:00
|
|
|
CYASSL_LOCAL
|
2012-09-07 09:41:55 +04:00
|
|
|
int EmbedReceive(CYASSL *ssl, char *buf, int sz, void *ctx);
|
2011-04-27 02:41:16 +04:00
|
|
|
CYASSL_LOCAL
|
2012-09-07 09:41:55 +04:00
|
|
|
int EmbedSend(CYASSL *ssl, char *buf, int sz, void *ctx);
|
2013-01-04 05:19:56 +04:00
|
|
|
|
|
|
|
#ifdef HAVE_OCSP
|
|
|
|
CYASSL_LOCAL
|
|
|
|
int EmbedOcspLookup(void*, const char*, int, byte*, int, byte**);
|
|
|
|
CYASSL_LOCAL
|
|
|
|
void EmbedOcspRespFree(void*, byte*);
|
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-03-14 03:41:50 +04:00
|
|
|
#ifdef CYASSL_DTLS
|
|
|
|
CYASSL_LOCAL
|
|
|
|
int EmbedReceiveFrom(CYASSL *ssl, char *buf, int sz, void *ctx);
|
|
|
|
CYASSL_LOCAL
|
|
|
|
int EmbedSendTo(CYASSL *ssl, char *buf, int sz, void *ctx);
|
|
|
|
CYASSL_LOCAL
|
|
|
|
int EmbedGenerateCookie(CYASSL* ssl, byte *buf, int sz, void *ctx);
|
|
|
|
CYASSL_LOCAL
|
|
|
|
int IsUDP(void*);
|
|
|
|
#endif /* CYASSL_DTLS */
|
|
|
|
#endif /* CYASSL_USER_IO */
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-06-25 01:00:48 +04:00
|
|
|
#ifdef HAVE_NETX
|
|
|
|
CYASSL_LOCAL int NetX_Receive(CYASSL *ssl, char *buf, int sz, void *ctx);
|
|
|
|
CYASSL_LOCAL int NetX_Send(CYASSL *ssl, char *buf, int sz, void *ctx);
|
|
|
|
#endif /* HAVE_NETX */
|
|
|
|
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2011-08-27 01:40:51 +04:00
|
|
|
/* CyaSSL Cipher type just points back to SSL */
|
|
|
|
struct CYASSL_CIPHER {
|
|
|
|
CYASSL* ssl;
|
2011-02-05 22:14:47 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-05-29 20:11:37 +04:00
|
|
|
typedef struct OCSP_Entry OCSP_Entry;
|
|
|
|
|
2013-03-08 05:44:40 +04:00
|
|
|
#ifdef SHA_DIGEST_SIZE
|
2013-03-12 03:07:46 +04:00
|
|
|
#define OCSP_DIGEST_SIZE SHA_DIGEST_SIZE
|
2013-03-08 05:44:40 +04:00
|
|
|
#else
|
2013-03-12 03:07:46 +04:00
|
|
|
#define OCSP_DIGEST_SIZE 160
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NO_ASN
|
|
|
|
/* no_asn won't have */
|
|
|
|
typedef struct CertStatus CertStatus;
|
2013-03-08 05:44:40 +04:00
|
|
|
#endif
|
|
|
|
|
2012-05-29 20:11:37 +04:00
|
|
|
struct OCSP_Entry {
|
|
|
|
OCSP_Entry* next; /* next entry */
|
2013-03-08 05:44:40 +04:00
|
|
|
byte issuerHash[OCSP_DIGEST_SIZE]; /* issuer hash */
|
|
|
|
byte issuerKeyHash[OCSP_DIGEST_SIZE]; /* issuer public key hash */
|
2012-06-01 04:29:32 +04:00
|
|
|
CertStatus* status; /* OCSP response list */
|
2012-05-29 20:11:37 +04:00
|
|
|
int totalStatus; /* number on list */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* CyaSSL OCSP controller */
|
|
|
|
struct CYASSL_OCSP {
|
|
|
|
byte enabled;
|
|
|
|
byte useOverrideUrl;
|
2012-12-19 22:18:11 +04:00
|
|
|
byte useNonce;
|
2013-01-04 05:19:56 +04:00
|
|
|
char overrideUrl[80];
|
2012-06-01 04:29:32 +04:00
|
|
|
OCSP_Entry* ocspList;
|
2013-01-04 05:19:56 +04:00
|
|
|
void* IOCB_OcspCtx;
|
|
|
|
CallbackIOOcsp CBIOOcsp;
|
|
|
|
CallbackIOOcspRespFree CBIOOcspRespFree;
|
2012-05-29 20:11:37 +04:00
|
|
|
};
|
|
|
|
|
2013-03-08 05:44:40 +04:00
|
|
|
#ifndef MAX_DATE_SIZE
|
|
|
|
#define MAX_DATE_SIZE 32
|
|
|
|
#endif
|
2012-05-29 20:11:37 +04:00
|
|
|
|
2012-05-17 04:04:56 +04:00
|
|
|
typedef struct CRL_Entry CRL_Entry;
|
|
|
|
|
2013-03-08 05:44:40 +04:00
|
|
|
#ifdef SHA_DIGEST_SIZE
|
2013-03-12 03:07:46 +04:00
|
|
|
#define CRL_DIGEST_SIZE SHA_DIGEST_SIZE
|
2013-03-08 05:44:40 +04:00
|
|
|
#else
|
2013-03-12 03:07:46 +04:00
|
|
|
#define CRL_DIGEST_SIZE 160
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NO_ASN
|
|
|
|
typedef struct RevokedCert RevokedCert;
|
2013-03-08 05:44:40 +04:00
|
|
|
#endif
|
|
|
|
|
2012-05-17 04:04:56 +04:00
|
|
|
/* Complete CRL */
|
|
|
|
struct CRL_Entry {
|
|
|
|
CRL_Entry* next; /* next entry */
|
2013-03-08 05:44:40 +04:00
|
|
|
byte issuerHash[CRL_DIGEST_SIZE]; /* issuer hash */
|
|
|
|
/* byte crlHash[CRL_DIGEST_SIZE]; raw crl data hash */
|
2012-11-27 06:40:43 +04:00
|
|
|
/* restore the hash here if needed for optimized comparisons */
|
2012-05-17 04:04:56 +04:00
|
|
|
byte lastDate[MAX_DATE_SIZE]; /* last date updated */
|
|
|
|
byte nextDate[MAX_DATE_SIZE]; /* next update date */
|
2012-05-25 01:07:59 +04:00
|
|
|
byte lastDateFormat; /* last date format */
|
|
|
|
byte nextDateFormat; /* next date format */
|
2012-05-17 04:04:56 +04:00
|
|
|
RevokedCert* certs; /* revoked cert list */
|
|
|
|
int totalCerts; /* number on list */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-05-23 04:25:15 +04:00
|
|
|
typedef struct CRL_Monitor CRL_Monitor;
|
|
|
|
|
|
|
|
/* CRL directory monitor */
|
|
|
|
struct CRL_Monitor {
|
|
|
|
char* path; /* full dir path, if valid pointer we're using */
|
|
|
|
int type; /* PEM or ASN1 type */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-03-12 03:07:46 +04:00
|
|
|
#ifndef HAVE_CRL
|
|
|
|
typedef struct CYASSL_CRL CYASSL_CRL;
|
|
|
|
#endif
|
|
|
|
|
2012-05-17 04:04:56 +04:00
|
|
|
/* CyaSSL CRL controller */
|
|
|
|
struct CYASSL_CRL {
|
|
|
|
CYASSL_CERT_MANAGER* cm; /* pointer back to cert manager */
|
|
|
|
CRL_Entry* crlList; /* our CRL list */
|
|
|
|
CyaSSL_Mutex crlLock; /* CRL list lock */
|
2012-05-23 04:25:15 +04:00
|
|
|
CRL_Monitor monitors[2]; /* PEM and DER possible */
|
|
|
|
#ifdef HAVE_CRL_MONITOR
|
|
|
|
pthread_t tid; /* monitoring thread */
|
|
|
|
#endif
|
2012-05-17 04:04:56 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-03-12 03:07:46 +04:00
|
|
|
#ifdef NO_ASN
|
|
|
|
typedef struct Signer Signer;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2013-04-26 02:36:33 +04:00
|
|
|
#ifndef CA_TABLE_SIZE
|
|
|
|
#define CA_TABLE_SIZE 11
|
|
|
|
#endif
|
|
|
|
|
2012-05-04 05:07:31 +04:00
|
|
|
/* CyaSSL Certificate Manager */
|
|
|
|
struct CYASSL_CERT_MANAGER {
|
2013-04-26 02:36:33 +04:00
|
|
|
Signer* caTable[CA_TABLE_SIZE]; /* the CA signer table */
|
2012-05-04 05:07:31 +04:00
|
|
|
CyaSSL_Mutex caLock; /* CA list lock */
|
|
|
|
CallbackCACache caCacheCallback; /* CA cache addition callback */
|
|
|
|
void* heap; /* heap helper */
|
2012-05-17 04:04:56 +04:00
|
|
|
CYASSL_CRL* crl; /* CRL checker */
|
|
|
|
byte crlEnabled; /* is CRL on ? */
|
|
|
|
byte crlCheckAll; /* always leaf, but all ? */
|
|
|
|
CbMissingCRL cbMissingCRL; /* notify through cb of missing crl */
|
2012-05-04 05:07:31 +04:00
|
|
|
};
|
|
|
|
|
2013-05-02 22:34:26 +04:00
|
|
|
CYASSL_LOCAL int CM_SaveCertCache(CYASSL_CERT_MANAGER*, const char*);
|
|
|
|
CYASSL_LOCAL int CM_RestoreCertCache(CYASSL_CERT_MANAGER*, const char*);
|
|
|
|
CYASSL_LOCAL int CM_MemSaveCertCache(CYASSL_CERT_MANAGER*, void*, int, int*);
|
|
|
|
CYASSL_LOCAL int CM_MemRestoreCertCache(CYASSL_CERT_MANAGER*, const void*, int);
|
|
|
|
CYASSL_LOCAL int CM_GetCertCacheMemSize(CYASSL_CERT_MANAGER*);
|
2012-05-04 05:07:31 +04:00
|
|
|
|
2012-10-02 20:15:50 +04:00
|
|
|
/* CyaSSL Sock Addr */
|
|
|
|
struct CYASSL_SOCKADDR {
|
|
|
|
unsigned int sz; /* sockaddr size */
|
|
|
|
void* sa; /* pointer to the sockaddr_in or sockaddr_in6 */
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct CYASSL_DTLS_CTX {
|
|
|
|
CYASSL_SOCKADDR peer;
|
|
|
|
int fd;
|
|
|
|
} CYASSL_DTLS_CTX;
|
|
|
|
|
2013-05-22 01:37:50 +04:00
|
|
|
/* RFC 6066 TLS Extensions */
|
|
|
|
#ifdef HAVE_TLS_EXTENSIONS
|
|
|
|
|
|
|
|
typedef enum {
|
2013-06-19 22:45:06 +04:00
|
|
|
SERVER_NAME_INDICATION = 0,
|
2013-05-22 01:37:50 +04:00
|
|
|
MAX_FRAGMENT_LENGTH = 1,
|
2013-06-19 22:45:06 +04:00
|
|
|
/*CLIENT_CERTIFICATE_URL = 2,
|
2013-07-23 22:42:43 +04:00
|
|
|
TRUSTED_CA_KEYS = 3,*/
|
2013-05-22 01:37:50 +04:00
|
|
|
TRUNCATED_HMAC = 4,
|
2013-07-23 22:42:43 +04:00
|
|
|
/*STATUS_REQUEST = 5,
|
2013-05-22 01:37:50 +04:00
|
|
|
SIGNATURE_ALGORITHMS = 13,*/
|
|
|
|
} TLSX_Type;
|
|
|
|
|
|
|
|
typedef struct TLSX {
|
|
|
|
TLSX_Type type; /* Extension Type */
|
|
|
|
void* data; /* Extension Data */
|
|
|
|
byte resp; /* IsResponse Flag */
|
|
|
|
struct TLSX* next; /* List Behavior */
|
|
|
|
} TLSX;
|
|
|
|
|
|
|
|
CYASSL_LOCAL TLSX* TLSX_Find(TLSX* list, TLSX_Type type);
|
|
|
|
CYASSL_LOCAL void TLSX_FreeAll(TLSX* list);
|
|
|
|
|
|
|
|
#ifndef NO_CYASSL_CLIENT
|
|
|
|
CYASSL_LOCAL word16 TLSX_GetRequestSize(CYASSL* ssl);
|
|
|
|
CYASSL_LOCAL word16 TLSX_WriteRequest(CYASSL* ssl, byte* output);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef NO_CYASSL_SERVER
|
|
|
|
CYASSL_LOCAL word16 TLSX_GetResponseSize(CYASSL* ssl);
|
|
|
|
CYASSL_LOCAL word16 TLSX_WriteResponse(CYASSL* ssl, byte* output);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
CYASSL_LOCAL int TLSX_Parse(CYASSL* ssl, byte* input, word16 length,
|
|
|
|
byte isRequest, Suites *suites);
|
|
|
|
|
|
|
|
/* Server Name Indication */
|
|
|
|
#ifdef HAVE_SNI
|
|
|
|
|
|
|
|
typedef struct SNI {
|
2013-05-30 22:22:38 +04:00
|
|
|
byte type; /* SNI Type */
|
|
|
|
union { char* host_name; } data; /* SNI Data */
|
|
|
|
struct SNI* next; /* List Behavior */
|
|
|
|
#ifndef NO_CYASSL_SERVER
|
|
|
|
byte options; /* Behaviour options */
|
2013-06-19 22:45:06 +04:00
|
|
|
byte status; /* Matching result */
|
2013-05-30 22:22:38 +04:00
|
|
|
#endif
|
2013-05-22 01:37:50 +04:00
|
|
|
} SNI;
|
|
|
|
|
|
|
|
CYASSL_LOCAL int TLSX_UseSNI(TLSX** extensions, byte type, const void* data,
|
|
|
|
word16 size);
|
|
|
|
|
2013-05-30 22:22:38 +04:00
|
|
|
#ifndef NO_CYASSL_SERVER
|
2013-06-19 22:45:06 +04:00
|
|
|
CYASSL_LOCAL void TLSX_SNI_SetOptions(TLSX* extensions, byte type,
|
2013-05-30 22:22:38 +04:00
|
|
|
byte options);
|
2013-06-19 22:45:06 +04:00
|
|
|
CYASSL_LOCAL byte TLSX_SNI_Status(TLSX* extensions, byte type);
|
|
|
|
CYASSL_LOCAL word16 TLSX_SNI_GetRequest(TLSX* extensions, byte type,
|
|
|
|
void** data);
|
2013-11-20 00:13:32 +04:00
|
|
|
CYASSL_LOCAL int TLSX_SNI_GetFromBuffer(const byte* buffer, word32 bufferSz,
|
|
|
|
byte type, byte* sni, word32* inOutSz);
|
2013-05-30 22:22:38 +04:00
|
|
|
#endif
|
|
|
|
|
2013-05-22 01:37:50 +04:00
|
|
|
#endif /* HAVE_SNI */
|
|
|
|
|
2013-06-19 22:45:06 +04:00
|
|
|
/* Maximum Fragment Length */
|
|
|
|
#ifdef HAVE_MAX_FRAGMENT
|
|
|
|
|
|
|
|
CYASSL_LOCAL int TLSX_UseMaxFragment(TLSX** extensions, byte mfl);
|
|
|
|
|
|
|
|
#endif /* HAVE_MAX_FRAGMENT */
|
|
|
|
|
2013-07-23 22:42:43 +04:00
|
|
|
#ifdef HAVE_TRUNCATED_HMAC
|
|
|
|
|
|
|
|
#define TRUNCATED_HMAC_SIZE 10
|
|
|
|
|
|
|
|
CYASSL_LOCAL int TLSX_UseTruncatedHMAC(TLSX** extensions);
|
|
|
|
|
|
|
|
#endif /* HAVE_TRUNCATED_HMAC */
|
|
|
|
|
2013-05-22 01:37:50 +04:00
|
|
|
#endif /* HAVE_TLS_EXTENSIONS */
|
2012-10-02 20:15:50 +04:00
|
|
|
|
2011-08-27 01:40:51 +04:00
|
|
|
/* CyaSSL context type */
|
|
|
|
struct CYASSL_CTX {
|
|
|
|
CYASSL_METHOD* method;
|
2011-12-08 04:32:18 +04:00
|
|
|
CyaSSL_Mutex countMutex; /* reference count mutex */
|
|
|
|
int refCount; /* reference count */
|
2012-11-01 23:36:47 +04:00
|
|
|
#ifndef NO_CERTS
|
2011-02-05 22:14:47 +03:00
|
|
|
buffer certificate;
|
2011-04-10 00:08:56 +04:00
|
|
|
buffer certChain;
|
|
|
|
/* chain after self, in DER, with leading size for each cert */
|
2011-02-05 22:14:47 +03:00
|
|
|
buffer privateKey;
|
2011-11-02 01:05:14 +04:00
|
|
|
buffer serverDH_P;
|
|
|
|
buffer serverDH_G;
|
2012-05-04 05:07:31 +04:00
|
|
|
CYASSL_CERT_MANAGER* cm; /* our cert manager, ctx owns SSL will use */
|
2012-11-01 23:36:47 +04:00
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
Suites suites;
|
|
|
|
void* heap; /* for user memory overrides */
|
|
|
|
byte verifyPeer;
|
|
|
|
byte verifyNone;
|
|
|
|
byte failNoCert;
|
|
|
|
byte sessionCacheOff;
|
|
|
|
byte sessionCacheFlushOff;
|
|
|
|
byte sendVerify; /* for client side */
|
2012-10-30 02:39:42 +04:00
|
|
|
byte haveRSA; /* RSA available */
|
2011-02-05 22:14:47 +03:00
|
|
|
byte haveDH; /* server DH parms set by user */
|
|
|
|
byte haveNTRU; /* server private NTRU key loaded */
|
2012-08-09 02:09:26 +04:00
|
|
|
byte haveECDSAsig; /* server cert signed w/ ECDSA */
|
2012-05-03 19:18:59 +04:00
|
|
|
byte haveStaticECC; /* static server ECC private key */
|
2011-02-05 22:14:47 +03:00
|
|
|
byte partialWrite; /* only one msg per write call */
|
|
|
|
byte quietShutdown; /* don't send close notify */
|
2012-01-25 01:19:03 +04:00
|
|
|
byte groupMessages; /* group handshake messages before sending */
|
2011-02-05 22:14:47 +03:00
|
|
|
CallbackIORecv CBIORecv;
|
|
|
|
CallbackIOSend CBIOSend;
|
2013-03-14 03:41:50 +04:00
|
|
|
#ifdef CYASSL_DTLS
|
|
|
|
CallbackGenCookie CBIOCookie; /* gen cookie callback */
|
|
|
|
#endif
|
2012-01-27 00:43:48 +04:00
|
|
|
VerifyCallback verifyCallback; /* cert verification callback */
|
2012-02-15 05:46:04 +04:00
|
|
|
word32 timeout; /* session timeout */
|
2012-02-15 00:46:32 +04:00
|
|
|
#ifdef HAVE_ECC
|
|
|
|
word16 eccTempKeySz; /* in octets 20 - 66 */
|
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
#ifndef NO_PSK
|
|
|
|
byte havePSK; /* psk key set by user */
|
|
|
|
psk_client_callback client_psk_cb; /* client callback */
|
|
|
|
psk_server_callback server_psk_cb; /* server callback */
|
|
|
|
char server_hint[MAX_PSK_ID_LEN];
|
|
|
|
#endif /* NO_PSK */
|
2011-03-01 03:41:07 +03:00
|
|
|
#if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
|
2011-02-05 22:14:47 +03:00
|
|
|
pem_password_cb passwd_cb;
|
|
|
|
void* userdata;
|
|
|
|
#endif /* OPENSSL_EXTRA */
|
2012-05-03 01:45:30 +04:00
|
|
|
#ifdef HAVE_OCSP
|
|
|
|
CYASSL_OCSP ocsp;
|
|
|
|
#endif
|
2013-02-02 00:21:38 +04:00
|
|
|
#ifdef HAVE_CAVIUM
|
|
|
|
int devId; /* cavium device id to use */
|
|
|
|
#endif
|
2013-05-22 01:37:50 +04:00
|
|
|
#ifdef HAVE_TLS_EXTENSIONS
|
|
|
|
TLSX* extensions; /* RFC 6066 TLS Extensions data */
|
|
|
|
#endif
|
2013-08-10 04:27:15 +04:00
|
|
|
#ifdef ATOMIC_USER
|
2013-08-22 03:55:34 +04:00
|
|
|
CallbackMacEncrypt MacEncryptCb; /* Atomic User Mac/Encrypt Cb */
|
|
|
|
CallbackDecryptVerify DecryptVerifyCb; /* Atomic User Decrypt/Verify Cb */
|
2013-08-10 04:27:15 +04:00
|
|
|
#endif
|
2013-08-23 05:19:39 +04:00
|
|
|
#ifdef HAVE_PK_CALLBACKS
|
|
|
|
#ifdef HAVE_ECC
|
|
|
|
CallbackEccSign EccSignCb; /* User EccSign Callback handler */
|
|
|
|
CallbackEccVerify EccVerifyCb; /* User EccVerify Callback handler */
|
|
|
|
#endif /* HAVE_ECC */
|
2013-08-27 03:27:29 +04:00
|
|
|
#ifndef NO_RSA
|
|
|
|
CallbackRsaSign RsaSignCb; /* User RsaSign Callback handler */
|
|
|
|
CallbackRsaVerify RsaVerifyCb; /* User RsaVerify Callback handler */
|
2013-08-27 04:14:19 +04:00
|
|
|
CallbackRsaEnc RsaEncCb; /* User Rsa Public Encrypt handler */
|
|
|
|
CallbackRsaDec RsaDecCb; /* User Rsa Private Decrypt handler */
|
2013-08-27 03:27:29 +04:00
|
|
|
#endif /* NO_RSA */
|
2013-08-23 05:19:39 +04:00
|
|
|
#endif /* HAVE_PK_CALLBACKS */
|
2011-02-05 22:14:47 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-04-27 02:41:16 +04:00
|
|
|
CYASSL_LOCAL
|
2011-12-08 04:32:18 +04:00
|
|
|
int InitSSL_Ctx(CYASSL_CTX*, CYASSL_METHOD*);
|
2011-04-27 02:41:16 +04:00
|
|
|
CYASSL_LOCAL
|
2011-08-27 01:40:51 +04:00
|
|
|
void FreeSSL_Ctx(CYASSL_CTX*);
|
2011-04-27 02:41:16 +04:00
|
|
|
CYASSL_LOCAL
|
2011-08-27 01:40:51 +04:00
|
|
|
void SSL_CtxResourceFree(CYASSL_CTX*);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2011-04-27 02:41:16 +04:00
|
|
|
CYASSL_LOCAL
|
2011-08-27 01:40:51 +04:00
|
|
|
int DeriveTlsKeys(CYASSL* ssl);
|
2011-04-27 02:41:16 +04:00
|
|
|
CYASSL_LOCAL
|
2011-08-27 01:40:51 +04:00
|
|
|
int ProcessOldClientHello(CYASSL* ssl, const byte* input, word32* inOutIdx,
|
2011-02-05 22:14:47 +03:00
|
|
|
word32 inSz, word16 sz);
|
2012-11-01 23:36:47 +04:00
|
|
|
#ifndef NO_CERTS
|
|
|
|
CYASSL_LOCAL
|
|
|
|
int AddCA(CYASSL_CERT_MANAGER* ctx, buffer der, int type, int verify);
|
|
|
|
CYASSL_LOCAL
|
|
|
|
int AlreadySigner(CYASSL_CERT_MANAGER* cm, byte* hash);
|
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
/* All cipher suite related info */
|
|
|
|
typedef struct CipherSpecs {
|
|
|
|
byte bulk_cipher_algorithm;
|
2012-06-19 02:57:37 +04:00
|
|
|
byte cipher_type; /* block, stream, or aead */
|
2011-02-05 22:14:47 +03:00
|
|
|
byte mac_algorithm;
|
|
|
|
byte kea; /* key exchange algo */
|
|
|
|
byte sig_algo;
|
|
|
|
byte hash_size;
|
|
|
|
byte pad_size;
|
2012-05-03 19:18:59 +04:00
|
|
|
byte static_ecdh;
|
2011-02-05 22:14:47 +03:00
|
|
|
word16 key_size;
|
|
|
|
word16 iv_size;
|
|
|
|
word16 block_size;
|
2013-03-22 22:30:12 +04:00
|
|
|
word16 aead_mac_size;
|
2011-02-05 22:14:47 +03:00
|
|
|
} CipherSpecs;
|
|
|
|
|
|
|
|
|
2012-10-03 22:57:20 +04:00
|
|
|
void InitCipherSpecs(CipherSpecs* cs);
|
|
|
|
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
/* Supported Message Authentication Codes from page 43 */
|
|
|
|
enum MACAlgorithm {
|
2012-07-12 04:00:16 +04:00
|
|
|
no_mac,
|
2011-02-05 22:14:47 +03:00
|
|
|
md5_mac,
|
|
|
|
sha_mac,
|
2011-03-02 02:03:47 +03:00
|
|
|
sha224_mac,
|
|
|
|
sha256_mac,
|
|
|
|
sha384_mac,
|
|
|
|
sha512_mac,
|
2013-10-24 04:13:54 +04:00
|
|
|
rmd_mac,
|
|
|
|
blake2b_mac
|
2011-02-05 22:14:47 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Supported Key Exchange Protocols */
|
|
|
|
enum KeyExchangeAlgorithm {
|
2012-07-12 04:00:16 +04:00
|
|
|
no_kea,
|
2011-02-05 22:14:47 +03:00
|
|
|
rsa_kea,
|
|
|
|
diffie_hellman_kea,
|
|
|
|
fortezza_kea,
|
|
|
|
psk_kea,
|
|
|
|
ntru_kea,
|
2012-05-25 23:18:18 +04:00
|
|
|
ecc_diffie_hellman_kea,
|
|
|
|
ecc_static_diffie_hellman_kea /* for verify suite only */
|
2011-02-05 22:14:47 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Supported Authentication Schemes */
|
|
|
|
enum SignatureAlgorithm {
|
2012-07-12 04:00:16 +04:00
|
|
|
anonymous_sa_algo,
|
2011-02-05 22:14:47 +03:00
|
|
|
rsa_sa_algo,
|
|
|
|
dsa_sa_algo,
|
|
|
|
ecc_dsa_sa_algo
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Supprted ECC Curve Types */
|
|
|
|
enum EccCurves {
|
|
|
|
named_curve = 3
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Supprted ECC Named Curves */
|
|
|
|
enum EccNamedCurves {
|
|
|
|
secp256r1 = 0x17, /* default, OpenSSL also calls it prime256v1 */
|
|
|
|
secp384r1 = 0x18,
|
|
|
|
secp521r1 = 0x19,
|
|
|
|
|
|
|
|
secp160r1 = 0x10,
|
|
|
|
secp192r1 = 0x13, /* Openssl also call it prime192v1 */
|
|
|
|
secp224r1 = 0x15
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Valid client certificate request types from page 27 */
|
|
|
|
enum ClientCertificateType {
|
|
|
|
rsa_sign = 1,
|
|
|
|
dss_sign = 2,
|
|
|
|
rsa_fixed_dh = 3,
|
|
|
|
dss_fixed_dh = 4,
|
|
|
|
rsa_ephemeral_dh = 5,
|
|
|
|
dss_ephemeral_dh = 6,
|
|
|
|
fortezza_kea_cert = 20
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-06-19 02:57:37 +04:00
|
|
|
enum CipherType { stream, block, aead };
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
|
2013-10-09 01:59:59 +04:00
|
|
|
#ifdef CYASSL_DTLS
|
|
|
|
|
|
|
|
#ifdef WORD64_AVAILABLE
|
|
|
|
typedef word64 DtlsSeq;
|
|
|
|
#else
|
|
|
|
typedef word32 DtlsSeq;
|
|
|
|
#endif
|
|
|
|
#define DTLS_SEQ_BITS (sizeof(DtlsSeq) * CHAR_BIT)
|
|
|
|
|
|
|
|
typedef struct DtlsState {
|
|
|
|
DtlsSeq window; /* Sliding window for current epoch */
|
|
|
|
word16 nextEpoch; /* Expected epoch in next record */
|
|
|
|
word32 nextSeq; /* Expected sequence in next record */
|
|
|
|
|
|
|
|
word16 curEpoch; /* Received epoch in current record */
|
|
|
|
word32 curSeq; /* Received sequence in current record */
|
|
|
|
|
|
|
|
DtlsSeq prevWindow; /* Sliding window for old epoch */
|
|
|
|
word32 prevSeq; /* Next sequence in allowed old epoch */
|
|
|
|
} DtlsState;
|
|
|
|
|
|
|
|
#endif /* CYASSL_DTLS */
|
|
|
|
|
|
|
|
|
2011-02-05 22:14:47 +03:00
|
|
|
/* keys and secrets */
|
|
|
|
typedef struct Keys {
|
2013-03-05 01:25:46 +04:00
|
|
|
byte client_write_MAC_secret[MAX_DIGEST_SIZE]; /* max sizes */
|
|
|
|
byte server_write_MAC_secret[MAX_DIGEST_SIZE];
|
2011-02-05 22:14:47 +03:00
|
|
|
byte client_write_key[AES_256_KEY_SIZE]; /* max sizes */
|
|
|
|
byte server_write_key[AES_256_KEY_SIZE];
|
|
|
|
byte client_write_IV[AES_IV_SIZE]; /* max sizes */
|
|
|
|
byte server_write_IV[AES_IV_SIZE];
|
2013-01-15 03:59:53 +04:00
|
|
|
#ifdef HAVE_AEAD
|
2013-01-16 03:20:30 +04:00
|
|
|
byte aead_exp_IV[AEAD_EXP_IV_SZ];
|
|
|
|
byte aead_enc_imp_IV[AEAD_IMP_IV_SZ];
|
|
|
|
byte aead_dec_imp_IV[AEAD_IMP_IV_SZ];
|
2013-01-15 03:59:53 +04:00
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
word32 peer_sequence_number;
|
|
|
|
word32 sequence_number;
|
|
|
|
|
|
|
|
#ifdef CYASSL_DTLS
|
2013-10-09 01:59:59 +04:00
|
|
|
DtlsState dtls_state; /* Peer's state */
|
2012-09-15 06:30:50 +04:00
|
|
|
word16 dtls_peer_handshake_number;
|
|
|
|
word16 dtls_expected_peer_handshake_number;
|
2013-10-09 01:59:59 +04:00
|
|
|
|
|
|
|
word16 dtls_epoch; /* Current tx epoch */
|
|
|
|
word32 dtls_sequence_number; /* Current tx sequence */
|
|
|
|
word16 dtls_handshake_number; /* Current tx handshake seq */
|
2011-02-05 22:14:47 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
word32 encryptSz; /* last size of encrypted data */
|
2013-08-22 03:55:34 +04:00
|
|
|
word32 padSz; /* how much to advance after decrypt part */
|
2011-02-05 22:14:47 +03:00
|
|
|
byte encryptionOn; /* true after change cipher spec */
|
2012-09-04 22:37:47 +04:00
|
|
|
byte decryptedCur; /* only decrypt current record once */
|
2011-02-05 22:14:47 +03:00
|
|
|
} Keys;
|
|
|
|
|
|
|
|
|
|
|
|
/* cipher for now */
|
2012-09-05 23:30:51 +04:00
|
|
|
typedef struct Ciphers {
|
2011-02-05 22:14:47 +03:00
|
|
|
#ifdef BUILD_ARC4
|
2012-09-05 23:30:51 +04:00
|
|
|
Arc4* arc4;
|
2011-02-05 22:14:47 +03:00
|
|
|
#endif
|
|
|
|
#ifdef BUILD_DES3
|
2012-09-05 23:30:51 +04:00
|
|
|
Des3* des3;
|
2011-02-05 22:14:47 +03:00
|
|
|
#endif
|
2013-05-16 20:47:27 +04:00
|
|
|
#if defined(BUILD_AES) || defined(BUILD_AESGCM)
|
2012-09-05 23:30:51 +04:00
|
|
|
Aes* aes;
|
2011-02-05 22:14:47 +03:00
|
|
|
#endif
|
2013-01-21 22:53:42 +04:00
|
|
|
#ifdef HAVE_CAMELLIA
|
|
|
|
Camellia* cam;
|
|
|
|
#endif
|
2011-09-29 00:19:05 +04:00
|
|
|
#ifdef HAVE_HC128
|
2012-09-05 23:30:51 +04:00
|
|
|
HC128* hc128;
|
2011-02-05 22:14:47 +03:00
|
|
|
#endif
|
|
|
|
#ifdef BUILD_RABBIT
|
2012-09-05 23:30:51 +04:00
|
|
|
Rabbit* rabbit;
|
2011-02-05 22:14:47 +03:00
|
|
|
#endif
|
2012-10-01 22:32:05 +04:00
|
|
|
byte setup; /* have we set it up flag for detection */
|
2011-02-05 22:14:47 +03:00
|
|
|
} Ciphers;
|
|
|
|
|
|
|
|
|
2012-09-05 23:30:51 +04:00
|
|
|
CYASSL_LOCAL void InitCiphers(CYASSL* ssl);
|
|
|
|
CYASSL_LOCAL void FreeCiphers(CYASSL* ssl);
|
|
|
|
|
|
|
|
|
2011-02-05 22:14:47 +03:00
|
|
|
/* hashes type */
|
|
|
|
typedef struct Hashes {
|
2013-03-08 05:44:40 +04:00
|
|
|
#ifndef NO_OLD_TLS
|
2012-11-27 06:40:43 +04:00
|
|
|
byte md5[MD5_DIGEST_SIZE];
|
2013-02-19 02:36:50 +04:00
|
|
|
#endif
|
|
|
|
byte sha[SHA_DIGEST_SIZE];
|
|
|
|
#ifndef NO_SHA256
|
|
|
|
byte sha256[SHA256_DIGEST_SIZE];
|
|
|
|
#endif
|
|
|
|
#ifdef CYASSL_SHA384
|
|
|
|
byte sha384[SHA384_DIGEST_SIZE];
|
2012-11-27 06:40:43 +04:00
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
} Hashes;
|
|
|
|
|
|
|
|
|
|
|
|
/* Static x509 buffer */
|
|
|
|
typedef struct x509_buffer {
|
|
|
|
int length; /* actual size */
|
|
|
|
byte buffer[MAX_X509_SIZE]; /* max static cert size */
|
|
|
|
} x509_buffer;
|
|
|
|
|
|
|
|
|
|
|
|
/* CyaSSL X509_CHAIN, for no dynamic memory SESSION_CACHE */
|
2011-08-27 01:40:51 +04:00
|
|
|
struct CYASSL_X509_CHAIN {
|
2011-02-05 22:14:47 +03:00
|
|
|
int count; /* total number in chain */
|
|
|
|
x509_buffer certs[MAX_CHAIN_DEPTH]; /* only allow max depth 4 for now */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-08-27 01:40:51 +04:00
|
|
|
/* CyaSSL session type */
|
|
|
|
struct CYASSL_SESSION {
|
2013-04-30 01:22:32 +04:00
|
|
|
byte sessionID[ID_LEN]; /* id for protocol */
|
|
|
|
byte masterSecret[SECRET_LEN]; /* stored secret */
|
2011-02-05 22:14:47 +03:00
|
|
|
word32 bornOn; /* create time in seconds */
|
|
|
|
word32 timeout; /* timeout in seconds */
|
|
|
|
#ifdef SESSION_CERTS
|
2013-04-30 01:22:32 +04:00
|
|
|
CYASSL_X509_CHAIN chain; /* peer cert chain, static */
|
|
|
|
ProtocolVersion version; /* which version was used */
|
2011-02-05 22:14:47 +03:00
|
|
|
byte cipherSuite0; /* first byte, normally 0 */
|
|
|
|
byte cipherSuite; /* 2nd byte, actual suite */
|
|
|
|
#endif
|
2013-04-30 01:22:32 +04:00
|
|
|
#ifndef NO_CLIENT_CACHE
|
|
|
|
byte serverID[SERVER_ID_LEN]; /* for easier client lookup */
|
|
|
|
word16 idLen; /* serverID length */
|
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-04-27 02:41:16 +04:00
|
|
|
CYASSL_LOCAL
|
2011-08-27 01:40:51 +04:00
|
|
|
CYASSL_SESSION* GetSession(CYASSL*, byte*);
|
2011-04-27 02:41:16 +04:00
|
|
|
CYASSL_LOCAL
|
2011-08-27 01:40:51 +04:00
|
|
|
int SetSession(CYASSL*, CYASSL_SESSION*);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2011-08-27 01:40:51 +04:00
|
|
|
typedef void (*hmacfp) (CYASSL*, byte*, const byte*, word32, int, int);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-04-30 01:22:32 +04:00
|
|
|
#ifndef NO_CLIENT_CACHE
|
|
|
|
CYASSL_SESSION* GetSessionClient(CYASSL*, const byte*, int);
|
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
/* client connect state for nonblocking restart */
|
|
|
|
enum ConnectState {
|
|
|
|
CONNECT_BEGIN = 0,
|
|
|
|
CLIENT_HELLO_SENT,
|
|
|
|
HELLO_AGAIN, /* HELLO_AGAIN s for DTLS case */
|
|
|
|
HELLO_AGAIN_REPLY,
|
|
|
|
FIRST_REPLY_DONE,
|
|
|
|
FIRST_REPLY_FIRST,
|
|
|
|
FIRST_REPLY_SECOND,
|
|
|
|
FIRST_REPLY_THIRD,
|
|
|
|
FIRST_REPLY_FOURTH,
|
|
|
|
FINISHED_DONE,
|
|
|
|
SECOND_REPLY_DONE
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-08-05 02:42:55 +04:00
|
|
|
/* server accept state for nonblocking restart */
|
2011-02-05 22:14:47 +03:00
|
|
|
enum AcceptState {
|
|
|
|
ACCEPT_BEGIN = 0,
|
|
|
|
ACCEPT_CLIENT_HELLO_DONE,
|
|
|
|
HELLO_VERIFY_SENT,
|
|
|
|
ACCEPT_FIRST_REPLY_DONE,
|
|
|
|
SERVER_HELLO_SENT,
|
|
|
|
CERT_SENT,
|
|
|
|
KEY_EXCHANGE_SENT,
|
|
|
|
CERT_REQ_SENT,
|
|
|
|
SERVER_HELLO_DONE,
|
|
|
|
ACCEPT_SECOND_REPLY_DONE,
|
|
|
|
CHANGE_CIPHER_SENT,
|
|
|
|
ACCEPT_FINISHED_DONE,
|
|
|
|
ACCEPT_THIRD_REPLY_DONE
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct Buffers {
|
2012-11-01 23:36:47 +04:00
|
|
|
#ifndef NO_CERTS
|
2011-08-27 01:40:51 +04:00
|
|
|
buffer certificate; /* CYASSL_CTX owns, unless we own */
|
|
|
|
buffer key; /* CYASSL_CTX owns, unless we own */
|
|
|
|
buffer certChain; /* CYASSL_CTX owns */
|
2011-04-10 00:08:56 +04:00
|
|
|
/* chain after self, in DER, with leading size for each cert */
|
2011-11-02 01:05:14 +04:00
|
|
|
buffer serverDH_P; /* CYASSL_CTX owns, unless we own */
|
|
|
|
buffer serverDH_G; /* CYASSL_CTX owns, unless we own */
|
2011-02-05 22:14:47 +03:00
|
|
|
buffer serverDH_Pub;
|
|
|
|
buffer serverDH_Priv;
|
2012-11-01 23:36:47 +04:00
|
|
|
#endif
|
|
|
|
buffer domainName; /* for client check */
|
2011-02-05 22:14:47 +03:00
|
|
|
bufferStatic inputBuffer;
|
|
|
|
bufferStatic outputBuffer;
|
|
|
|
buffer clearOutputBuffer;
|
|
|
|
int prevSent; /* previous plain text bytes sent
|
|
|
|
when got WANT_WRITE */
|
|
|
|
int plainSz; /* plain text bytes in buffer to send
|
|
|
|
when got WANT_WRITE */
|
2011-04-05 04:42:50 +04:00
|
|
|
byte weOwnCert; /* SSL own cert flag */
|
|
|
|
byte weOwnKey; /* SSL own key flag */
|
2011-11-02 01:05:14 +04:00
|
|
|
byte weOwnDH; /* SSL own dh (p,g) flag */
|
2012-08-10 21:24:31 +04:00
|
|
|
#ifdef CYASSL_DTLS
|
2012-10-02 20:15:50 +04:00
|
|
|
CYASSL_DTLS_CTX dtlsCtx; /* DTLS connection context */
|
2012-08-10 21:24:31 +04:00
|
|
|
#endif
|
2013-08-23 05:19:39 +04:00
|
|
|
#ifdef HAVE_PK_CALLBACKS
|
|
|
|
#ifdef HAVE_ECC
|
|
|
|
buffer peerEccDsaKey; /* we own for Ecc Verify Callbacks */
|
|
|
|
#endif /* HAVE_ECC */
|
2013-08-27 03:27:29 +04:00
|
|
|
#ifndef NO_RSA
|
|
|
|
buffer peerRsaKey; /* we own for Rsa Verify Callbacks */
|
|
|
|
#endif /* NO_RSA */
|
2013-08-23 05:19:39 +04:00
|
|
|
#endif /* HAVE_PK_CALLBACKS */
|
2011-02-05 22:14:47 +03:00
|
|
|
} Buffers;
|
|
|
|
|
|
|
|
typedef struct Options {
|
|
|
|
byte sessionCacheOff;
|
|
|
|
byte sessionCacheFlushOff;
|
|
|
|
byte cipherSuite0; /* first byte, normally 0 */
|
|
|
|
byte cipherSuite; /* second byte, actual suite */
|
|
|
|
byte serverState;
|
|
|
|
byte clientState;
|
|
|
|
byte handShakeState;
|
|
|
|
byte side; /* client or server end */
|
|
|
|
byte verifyPeer;
|
|
|
|
byte verifyNone;
|
|
|
|
byte failNoCert;
|
|
|
|
byte downgrade; /* allow downgrade of versions */
|
|
|
|
byte sendVerify; /* false = 0, true = 1, sendBlank = 2 */
|
|
|
|
byte resuming;
|
2012-05-17 21:55:42 +04:00
|
|
|
byte haveSessionId; /* server may not send */
|
2011-02-05 22:14:47 +03:00
|
|
|
byte tls; /* using TLS ? */
|
|
|
|
byte tls1_1; /* using TLSv1.1+ ? */
|
|
|
|
byte dtls; /* using datagrams ? */
|
|
|
|
byte connReset; /* has the peer reset */
|
|
|
|
byte isClosed; /* if we consider conn closed */
|
|
|
|
byte closeNotify; /* we've recieved a close notify */
|
|
|
|
byte sentNotify; /* we've sent a close notify */
|
|
|
|
byte connectState; /* nonblocking resume */
|
|
|
|
byte acceptState; /* nonblocking resume */
|
|
|
|
byte usingCompression; /* are we using compression */
|
2012-10-30 02:39:42 +04:00
|
|
|
byte haveRSA; /* RSA available */
|
2011-02-05 22:14:47 +03:00
|
|
|
byte haveDH; /* server DH parms set by user */
|
|
|
|
byte haveNTRU; /* server NTRU private key loaded */
|
2012-08-09 02:09:26 +04:00
|
|
|
byte haveECDSAsig; /* server ECDSA signed cert */
|
2012-05-03 19:18:59 +04:00
|
|
|
byte haveStaticECC; /* static server ECC private key */
|
2011-02-05 22:14:47 +03:00
|
|
|
byte havePeerCert; /* do we have peer's cert */
|
2013-02-27 10:24:34 +04:00
|
|
|
byte havePeerVerify; /* and peer's cert verify */
|
2011-02-05 22:14:47 +03:00
|
|
|
byte usingPSK_cipher; /* whether we're using psk as cipher */
|
|
|
|
byte sendAlertState; /* nonblocking resume */
|
|
|
|
byte processReply; /* nonblocking resume */
|
|
|
|
byte partialWrite; /* only one msg per write call */
|
|
|
|
byte quietShutdown; /* don't send close notify */
|
2011-08-17 23:33:36 +04:00
|
|
|
byte certOnly; /* stop once we get cert */
|
2012-01-25 01:19:03 +04:00
|
|
|
byte groupMessages; /* group handshake messages */
|
2012-09-07 09:41:55 +04:00
|
|
|
byte usingNonblock; /* set when using nonblocking socket */
|
2012-09-15 08:19:06 +04:00
|
|
|
byte saveArrays; /* save array Memory for user get keys
|
|
|
|
or psk */
|
2011-02-05 22:14:47 +03:00
|
|
|
#ifndef NO_PSK
|
|
|
|
byte havePSK; /* psk key set by user */
|
|
|
|
psk_client_callback client_psk_cb;
|
|
|
|
psk_server_callback server_psk_cb;
|
|
|
|
#endif /* NO_PSK */
|
|
|
|
} Options;
|
|
|
|
|
|
|
|
typedef struct Arrays {
|
|
|
|
byte clientRandom[RAN_LEN];
|
|
|
|
byte serverRandom[RAN_LEN];
|
|
|
|
byte sessionID[ID_LEN];
|
|
|
|
byte preMasterSecret[ENCRYPT_LEN];
|
|
|
|
byte masterSecret[SECRET_LEN];
|
|
|
|
#ifdef CYASSL_DTLS
|
|
|
|
byte cookie[MAX_COOKIE_LEN];
|
2012-08-08 21:38:12 +04:00
|
|
|
byte cookieSz;
|
2011-02-05 22:14:47 +03:00
|
|
|
#endif
|
|
|
|
#ifndef NO_PSK
|
|
|
|
char client_identity[MAX_PSK_ID_LEN];
|
|
|
|
char server_hint[MAX_PSK_ID_LEN];
|
|
|
|
byte psk_key[MAX_PSK_KEY_LEN];
|
|
|
|
word32 psk_keySz; /* acutal size */
|
|
|
|
#endif
|
|
|
|
word32 preMasterSz; /* differs for DH, actual size */
|
|
|
|
} Arrays;
|
|
|
|
|
2013-03-08 05:44:40 +04:00
|
|
|
#ifndef ASN_NAME_MAX
|
|
|
|
#define ASN_NAME_MAX 256
|
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-10-18 01:31:20 +04:00
|
|
|
#ifndef MAX_DATE_SZ
|
|
|
|
#define MAX_DATE_SZ 32
|
|
|
|
#endif
|
|
|
|
|
2011-08-27 01:40:51 +04:00
|
|
|
struct CYASSL_X509_NAME {
|
2013-10-18 01:31:20 +04:00
|
|
|
char *name;
|
|
|
|
char staticName[ASN_NAME_MAX];
|
|
|
|
int dynamicName;
|
2011-02-05 22:14:47 +03:00
|
|
|
int sz;
|
2013-10-18 01:31:20 +04:00
|
|
|
#ifdef OPENSSL_EXTRA
|
|
|
|
DecodedName fullName;
|
|
|
|
#endif /* OPENSSL_EXTRA */
|
2011-02-05 22:14:47 +03:00
|
|
|
};
|
|
|
|
|
2013-03-08 05:44:40 +04:00
|
|
|
#ifndef EXTERNAL_SERIAL_SIZE
|
2013-03-12 03:07:46 +04:00
|
|
|
#define EXTERNAL_SERIAL_SIZE 32
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NO_ASN
|
|
|
|
typedef struct DNS_entry DNS_entry;
|
2013-03-08 05:44:40 +04:00
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2011-08-27 01:40:51 +04:00
|
|
|
struct CYASSL_X509 {
|
2013-10-18 01:31:20 +04:00
|
|
|
int version;
|
2011-08-27 01:40:51 +04:00
|
|
|
CYASSL_X509_NAME issuer;
|
|
|
|
CYASSL_X509_NAME subject;
|
|
|
|
int serialSz;
|
|
|
|
byte serial[EXTERNAL_SERIAL_SIZE];
|
2011-10-04 20:29:10 +04:00
|
|
|
char subjectCN[ASN_NAME_MAX]; /* common name short cut */
|
2013-08-17 20:01:15 +04:00
|
|
|
#ifdef CYASSL_SEP
|
|
|
|
int deviceTypeSz;
|
|
|
|
byte deviceType[EXTERNAL_SERIAL_SIZE];
|
|
|
|
int hwTypeSz;
|
|
|
|
byte hwType[EXTERNAL_SERIAL_SIZE];
|
|
|
|
int hwSerialNumSz;
|
|
|
|
byte hwSerialNum[EXTERNAL_SERIAL_SIZE];
|
2013-11-20 02:44:55 +04:00
|
|
|
#ifdef OPENSSL_EXTRA
|
|
|
|
byte certPolicySet;
|
|
|
|
byte certPolicyCrit;
|
|
|
|
#endif /* OPENSSL_EXTRA */
|
2013-08-17 20:01:15 +04:00
|
|
|
#endif
|
2013-10-18 01:31:20 +04:00
|
|
|
int notBeforeSz;
|
|
|
|
byte notBefore[MAX_DATE_SZ];
|
|
|
|
int notAfterSz;
|
|
|
|
byte notAfter[MAX_DATE_SZ];
|
2013-11-06 23:49:49 +04:00
|
|
|
int sigOID;
|
|
|
|
buffer sig;
|
2013-11-07 02:16:21 +04:00
|
|
|
int pubKeyOID;
|
2013-10-18 01:31:20 +04:00
|
|
|
buffer pubKey;
|
2013-11-20 02:44:55 +04:00
|
|
|
#ifdef HAVE_ECC
|
|
|
|
word32 pkCurveOID;
|
|
|
|
#endif /* HAVE_ECC */
|
2012-01-26 02:13:05 +04:00
|
|
|
buffer derCert; /* may need */
|
2012-08-01 04:45:48 +04:00
|
|
|
DNS_entry* altNames; /* alt names list */
|
|
|
|
DNS_entry* altNamesNext; /* hint for retrieval */
|
2013-04-23 22:50:06 +04:00
|
|
|
byte dynamicMemory; /* dynamic memory flag */
|
2013-11-20 02:44:55 +04:00
|
|
|
byte isCa;
|
|
|
|
#ifdef OPENSSL_EXTRA
|
|
|
|
word32 pathLength;
|
|
|
|
word16 keyUsage;
|
|
|
|
byte basicConstSet;
|
|
|
|
byte basicConstCrit;
|
|
|
|
byte basicConstPlSet;
|
|
|
|
byte subjAltNameSet;
|
|
|
|
byte subjAltNameCrit;
|
|
|
|
byte authKeyIdSet;
|
|
|
|
byte authKeyIdCrit;
|
2013-11-20 04:20:18 +04:00
|
|
|
byte* authKeyId;
|
|
|
|
word32 authKeyIdSz;
|
2013-11-20 02:44:55 +04:00
|
|
|
byte subjKeyIdSet;
|
|
|
|
byte subjKeyIdCrit;
|
2013-11-20 04:20:18 +04:00
|
|
|
byte* subjKeyId;
|
|
|
|
word32 subjKeyIdSz;
|
2013-11-20 02:44:55 +04:00
|
|
|
byte keyUsageSet;
|
|
|
|
byte keyUsageCrit;
|
|
|
|
#endif /* OPENSSL_EXTRA */
|
2011-02-05 22:14:47 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* record layer header for PlainText, Compressed, and CipherText */
|
|
|
|
typedef struct RecordLayerHeader {
|
|
|
|
byte type;
|
2012-11-29 04:34:41 +04:00
|
|
|
byte pvMajor;
|
|
|
|
byte pvMinor;
|
2011-02-05 22:14:47 +03:00
|
|
|
byte length[2];
|
|
|
|
} RecordLayerHeader;
|
|
|
|
|
|
|
|
|
|
|
|
/* record layer header for DTLS PlainText, Compressed, and CipherText */
|
|
|
|
typedef struct DtlsRecordLayerHeader {
|
|
|
|
byte type;
|
2012-11-29 04:34:41 +04:00
|
|
|
byte pvMajor;
|
|
|
|
byte pvMinor;
|
2011-02-05 22:14:47 +03:00
|
|
|
byte epoch[2]; /* increment on cipher state change */
|
|
|
|
byte sequence_number[6]; /* per record */
|
|
|
|
byte length[2];
|
|
|
|
} DtlsRecordLayerHeader;
|
|
|
|
|
|
|
|
|
2012-09-14 20:35:34 +04:00
|
|
|
typedef struct DtlsPool {
|
|
|
|
buffer buf[DTLS_POOL_SZ];
|
|
|
|
int used;
|
|
|
|
} DtlsPool;
|
|
|
|
|
2013-02-07 23:26:02 +04:00
|
|
|
typedef struct DtlsMsg {
|
|
|
|
struct DtlsMsg* next;
|
2013-02-20 00:51:02 +04:00
|
|
|
word32 seq; /* Handshake sequence number */
|
|
|
|
word32 sz; /* Length of whole mesage */
|
|
|
|
word32 fragSz; /* Length of fragments received */
|
2013-02-20 04:06:02 +04:00
|
|
|
byte type;
|
2013-02-20 20:35:33 +04:00
|
|
|
byte* buf;
|
2013-02-20 00:51:02 +04:00
|
|
|
byte* msg;
|
2013-02-07 23:26:02 +04:00
|
|
|
} DtlsMsg;
|
|
|
|
|
2012-09-14 20:35:34 +04:00
|
|
|
|
2013-06-25 01:00:48 +04:00
|
|
|
#ifdef HAVE_NETX
|
|
|
|
|
|
|
|
/* NETX I/O Callback default */
|
|
|
|
typedef struct NetX_Ctx {
|
|
|
|
NX_TCP_SOCKET* nxSocket; /* send/recv socket handle */
|
|
|
|
NX_PACKET* nxPacket; /* incoming packet handle for short reads */
|
|
|
|
ULONG nxOffset; /* offset already read from nxPacket */
|
|
|
|
ULONG nxWait; /* wait option flag */
|
|
|
|
} NetX_Ctx;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2011-08-27 01:40:51 +04:00
|
|
|
/* CyaSSL ssl type */
|
|
|
|
struct CYASSL {
|
|
|
|
CYASSL_CTX* ctx;
|
2011-02-05 22:14:47 +03:00
|
|
|
int error;
|
|
|
|
ProtocolVersion version; /* negotiated version */
|
|
|
|
ProtocolVersion chVersion; /* client hello version */
|
2012-09-05 21:17:48 +04:00
|
|
|
Suites* suites; /* only need during handshake */
|
2011-02-05 22:14:47 +03:00
|
|
|
Ciphers encrypt;
|
|
|
|
Ciphers decrypt;
|
|
|
|
CipherSpecs specs;
|
|
|
|
Keys keys;
|
|
|
|
int rfd; /* read file descriptor */
|
|
|
|
int wfd; /* write file descriptor */
|
2012-10-26 01:17:11 +04:00
|
|
|
int rflags; /* user read flags */
|
|
|
|
int wflags; /* user write flags */
|
2011-08-27 01:40:51 +04:00
|
|
|
CYASSL_BIO* biord; /* socket bio read to free/close */
|
|
|
|
CYASSL_BIO* biowr; /* socket bio write to free/close */
|
2011-02-05 22:14:47 +03:00
|
|
|
void* IOCB_ReadCtx;
|
|
|
|
void* IOCB_WriteCtx;
|
2012-09-06 03:18:29 +04:00
|
|
|
RNG* rng;
|
2013-03-08 05:44:40 +04:00
|
|
|
#ifndef NO_OLD_TLS
|
|
|
|
#ifndef NO_SHA
|
2011-02-05 22:14:47 +03:00
|
|
|
Sha hashSha; /* sha hash of handshake msgs */
|
2013-03-08 05:44:40 +04:00
|
|
|
#endif
|
2012-11-27 06:40:43 +04:00
|
|
|
#ifndef NO_MD5
|
|
|
|
Md5 hashMd5; /* md5 hash of handshake msgs */
|
|
|
|
#endif
|
2013-03-08 05:44:40 +04:00
|
|
|
#endif
|
2011-02-28 23:21:06 +03:00
|
|
|
#ifndef NO_SHA256
|
|
|
|
Sha256 hashSha256; /* sha256 hash of handshake msgs */
|
2012-06-26 20:30:48 +04:00
|
|
|
#endif
|
|
|
|
#ifdef CYASSL_SHA384
|
|
|
|
Sha384 hashSha384; /* sha384 hash of handshake msgs */
|
2011-02-28 23:21:06 +03:00
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
Hashes verifyHashes;
|
|
|
|
Hashes certHashes; /* for cert verify */
|
|
|
|
Buffers buffers;
|
|
|
|
Options options;
|
2012-09-15 08:19:06 +04:00
|
|
|
Arrays* arrays;
|
2011-08-27 01:40:51 +04:00
|
|
|
CYASSL_SESSION session;
|
2011-10-29 05:43:07 +04:00
|
|
|
VerifyCallback verifyCallback; /* cert verification callback */
|
2013-04-18 21:37:10 +04:00
|
|
|
void* verifyCbCtx; /* cert verify callback user ctx*/
|
2012-10-30 02:39:42 +04:00
|
|
|
#ifndef NO_RSA
|
2012-09-15 08:19:06 +04:00
|
|
|
RsaKey* peerRsaKey;
|
2011-02-05 22:14:47 +03:00
|
|
|
byte peerRsaKeyPresent;
|
2012-10-30 02:39:42 +04:00
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
#ifdef HAVE_NTRU
|
|
|
|
word16 peerNtruKeyLen;
|
|
|
|
byte peerNtruKey[MAX_NTRU_PUB_KEY_SZ];
|
|
|
|
byte peerNtruKeyPresent;
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ECC
|
2012-12-27 04:39:19 +04:00
|
|
|
ecc_key* peerEccKey; /* peer's ECDHE key */
|
|
|
|
ecc_key* peerEccDsaKey; /* peer's ECDSA key */
|
|
|
|
ecc_key* eccTempKey; /* private ECDHE key */
|
|
|
|
ecc_key* eccDsaKey; /* private ECDSA key */
|
2012-02-15 00:46:32 +04:00
|
|
|
word16 eccTempKeySz; /* in octets 20 - 66 */
|
|
|
|
byte peerEccKeyPresent;
|
|
|
|
byte peerEccDsaKeyPresent;
|
|
|
|
byte eccTempKeyPresent;
|
2011-02-05 22:14:47 +03:00
|
|
|
byte eccDsaKeyPresent;
|
|
|
|
#endif
|
|
|
|
hmacfp hmac;
|
|
|
|
void* heap; /* for user overrides */
|
|
|
|
RecordLayerHeader curRL;
|
|
|
|
word16 curSize;
|
2012-02-15 05:46:04 +04:00
|
|
|
word32 timeout; /* session timeout */
|
2011-08-27 01:40:51 +04:00
|
|
|
CYASSL_CIPHER cipher;
|
2011-02-05 22:14:47 +03:00
|
|
|
#ifdef HAVE_LIBZ
|
|
|
|
z_stream c_stream; /* compression stream */
|
|
|
|
z_stream d_stream; /* decompression stream */
|
|
|
|
byte didStreamInit; /* for stream init and end */
|
|
|
|
#endif
|
2012-09-07 09:41:55 +04:00
|
|
|
#ifdef CYASSL_DTLS
|
2013-05-08 03:14:26 +04:00
|
|
|
int dtls_timeout_init; /* starting timeout vaule */
|
2013-05-08 23:49:55 +04:00
|
|
|
int dtls_timeout_max; /* maximum timeout value */
|
2013-05-08 03:14:26 +04:00
|
|
|
int dtls_timeout; /* current timeout value, changes */
|
2012-09-14 20:35:34 +04:00
|
|
|
DtlsPool* dtls_pool;
|
2013-02-07 23:26:02 +04:00
|
|
|
DtlsMsg* dtls_msg_list;
|
2013-03-14 03:41:50 +04:00
|
|
|
void* IOCB_CookieCtx; /* gen cookie ctx */
|
2013-05-17 21:29:34 +04:00
|
|
|
word32 dtls_expected_rx;
|
2012-09-07 09:41:55 +04:00
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
#ifdef CYASSL_CALLBACKS
|
|
|
|
HandShakeInfo handShakeInfo; /* info saved during handshake */
|
|
|
|
TimeoutInfo timeoutInfo; /* info saved during handshake */
|
|
|
|
byte hsInfoOn; /* track handshake info */
|
|
|
|
byte toInfoOn; /* track timeout info */
|
|
|
|
#endif
|
2013-03-19 23:18:52 +04:00
|
|
|
#ifdef KEEP_PEER_CERT
|
2011-08-27 01:40:51 +04:00
|
|
|
CYASSL_X509 peerCert; /* X509 peer cert */
|
2011-02-05 22:14:47 +03:00
|
|
|
#endif
|
2012-03-16 21:50:04 +04:00
|
|
|
#ifdef FORTRESS
|
2012-03-24 01:39:37 +04:00
|
|
|
void* ex_data[MAX_EX_DATA]; /* external data, for Fortress */
|
2012-03-16 21:50:04 +04:00
|
|
|
#endif
|
2013-02-02 00:21:38 +04:00
|
|
|
#ifdef HAVE_CAVIUM
|
|
|
|
int devId; /* cavium device id to use */
|
2013-05-22 01:37:50 +04:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_TLS_EXTENSIONS
|
|
|
|
TLSX* extensions; /* RFC 6066 TLS Extensions data */
|
2013-06-19 22:45:06 +04:00
|
|
|
#ifdef HAVE_MAX_FRAGMENT
|
|
|
|
word16 max_fragment;
|
|
|
|
#endif
|
2013-07-23 22:42:43 +04:00
|
|
|
#ifdef HAVE_TRUNCATED_HMAC
|
|
|
|
byte truncated_hmac;
|
|
|
|
#endif
|
2013-06-25 01:00:48 +04:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_NETX
|
|
|
|
NetX_Ctx nxCtx; /* NetX IO Context */
|
2013-07-29 04:11:22 +04:00
|
|
|
#endif
|
|
|
|
#ifdef SESSION_INDEX
|
|
|
|
int sessionIndex; /* Session's location in the cache. */
|
2013-02-02 00:21:38 +04:00
|
|
|
#endif
|
2013-03-08 05:44:40 +04:00
|
|
|
CYASSL_ALERT_HISTORY alert_history;
|
2013-08-10 04:27:15 +04:00
|
|
|
#ifdef ATOMIC_USER
|
2013-08-22 03:55:34 +04:00
|
|
|
void* MacEncryptCtx; /* Atomic User Mac/Encrypt Callback Context */
|
|
|
|
void* DecryptVerifyCtx; /* Atomic User Decrypt/Verify Callback Context */
|
2013-08-10 04:27:15 +04:00
|
|
|
#endif
|
2013-08-23 05:19:39 +04:00
|
|
|
#ifdef HAVE_PK_CALLBACKS
|
|
|
|
#ifdef HAVE_ECC
|
|
|
|
void* EccSignCtx; /* Ecc Sign Callback Context */
|
|
|
|
void* EccVerifyCtx; /* Ecc Verify Callback Context */
|
|
|
|
#endif /* HAVE_ECC */
|
2013-08-27 03:27:29 +04:00
|
|
|
#ifndef NO_RSA
|
|
|
|
void* RsaSignCtx; /* Rsa Sign Callback Context */
|
|
|
|
void* RsaVerifyCtx; /* Rsa Verify Callback Context */
|
2013-08-27 04:14:19 +04:00
|
|
|
void* RsaEncCtx; /* Rsa Public Encrypt Callback Context */
|
|
|
|
void* RsaDecCtx; /* Rsa Private Decrypt Callback Context */
|
2013-08-27 03:27:29 +04:00
|
|
|
#endif /* NO_RSA */
|
2013-08-23 05:19:39 +04:00
|
|
|
#endif /* HAVE_PK_CALLBACKS */
|
2011-02-05 22:14:47 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-04-27 02:41:16 +04:00
|
|
|
CYASSL_LOCAL
|
2011-08-27 01:40:51 +04:00
|
|
|
int InitSSL(CYASSL*, CYASSL_CTX*);
|
2011-04-27 02:41:16 +04:00
|
|
|
CYASSL_LOCAL
|
2011-08-27 01:40:51 +04:00
|
|
|
void FreeSSL(CYASSL*);
|
|
|
|
CYASSL_API void SSL_ResourceFree(CYASSL*); /* Micrium uses */
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
IV_SZ = 32, /* max iv sz */
|
2012-11-01 21:23:42 +04:00
|
|
|
NAME_SZ = 80 /* max one line */
|
2011-02-05 22:14:47 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct EncryptedInfo {
|
2011-04-10 00:08:56 +04:00
|
|
|
char name[NAME_SZ]; /* encryption name */
|
|
|
|
byte iv[IV_SZ]; /* encrypted IV */
|
|
|
|
word32 ivSz; /* encrypted IV size */
|
|
|
|
long consumed; /* tracks PEM bytes consumed */
|
|
|
|
byte set; /* if encryption set */
|
2011-08-27 01:40:51 +04:00
|
|
|
CYASSL_CTX* ctx; /* CTX owner */
|
2011-02-05 22:14:47 +03:00
|
|
|
} EncryptedInfo;
|
|
|
|
|
2012-05-17 04:04:56 +04:00
|
|
|
|
2012-11-01 23:36:47 +04:00
|
|
|
#ifndef NO_CERTS
|
|
|
|
CYASSL_LOCAL int PemToDer(const unsigned char* buff, long sz, int type,
|
|
|
|
buffer* der, void* heap, EncryptedInfo* info,
|
|
|
|
int* eccKey);
|
|
|
|
|
|
|
|
CYASSL_LOCAL int ProcessFile(CYASSL_CTX* ctx, const char* fname, int format,
|
|
|
|
int type, CYASSL* ssl, int userChain,
|
|
|
|
CYASSL_CRL* crl);
|
|
|
|
#endif
|
2012-05-17 04:04:56 +04:00
|
|
|
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
#ifdef CYASSL_CALLBACKS
|
2011-04-27 02:41:16 +04:00
|
|
|
CYASSL_LOCAL
|
2011-02-05 22:14:47 +03:00
|
|
|
void InitHandShakeInfo(HandShakeInfo*);
|
2011-04-27 02:41:16 +04:00
|
|
|
CYASSL_LOCAL
|
2011-08-27 01:40:51 +04:00
|
|
|
void FinishHandShakeInfo(HandShakeInfo*, const CYASSL*);
|
2011-04-27 02:41:16 +04:00
|
|
|
CYASSL_LOCAL
|
2011-02-05 22:14:47 +03:00
|
|
|
void AddPacketName(const char*, HandShakeInfo*);
|
|
|
|
|
2011-04-27 02:41:16 +04:00
|
|
|
CYASSL_LOCAL
|
2011-02-05 22:14:47 +03:00
|
|
|
void InitTimeoutInfo(TimeoutInfo*);
|
2011-04-27 02:41:16 +04:00
|
|
|
CYASSL_LOCAL
|
2011-02-05 22:14:47 +03:00
|
|
|
void FreeTimeoutInfo(TimeoutInfo*, void*);
|
2011-04-27 02:41:16 +04:00
|
|
|
CYASSL_LOCAL
|
2011-02-05 22:14:47 +03:00
|
|
|
void AddPacketInfo(const char*, TimeoutInfo*, const byte*, int, void*);
|
2011-04-27 02:41:16 +04:00
|
|
|
CYASSL_LOCAL
|
2011-02-05 22:14:47 +03:00
|
|
|
void AddLateName(const char*, TimeoutInfo*);
|
2011-04-27 02:41:16 +04:00
|
|
|
CYASSL_LOCAL
|
2011-02-05 22:14:47 +03:00
|
|
|
void AddLateRecordHeader(const RecordLayerHeader* rl, TimeoutInfo* info);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* Record Layer Header identifier from page 12 */
|
|
|
|
enum ContentType {
|
|
|
|
no_type = 0,
|
|
|
|
change_cipher_spec = 20,
|
|
|
|
alert = 21,
|
|
|
|
handshake = 22,
|
|
|
|
application_data = 23
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* handshake header, same for each message type, pgs 20/21 */
|
|
|
|
typedef struct HandShakeHeader {
|
|
|
|
byte type;
|
|
|
|
word24 length;
|
|
|
|
} HandShakeHeader;
|
|
|
|
|
|
|
|
|
|
|
|
/* DTLS handshake header, same for each message type */
|
|
|
|
typedef struct DtlsHandShakeHeader {
|
|
|
|
byte type;
|
|
|
|
word24 length;
|
|
|
|
byte message_seq[2]; /* start at 0, restransmit gets same # */
|
|
|
|
word24 fragment_offset; /* bytes in previous fragments */
|
|
|
|
word24 fragment_length; /* length of this fragment */
|
|
|
|
} DtlsHandShakeHeader;
|
|
|
|
|
|
|
|
|
|
|
|
enum HandShakeType {
|
|
|
|
no_shake = -1,
|
|
|
|
hello_request = 0,
|
|
|
|
client_hello = 1,
|
|
|
|
server_hello = 2,
|
|
|
|
hello_verify_request = 3, /* DTLS addition */
|
2012-06-29 00:37:19 +04:00
|
|
|
session_ticket = 4,
|
2011-02-05 22:14:47 +03:00
|
|
|
certificate = 11,
|
|
|
|
server_key_exchange = 12,
|
|
|
|
certificate_request = 13,
|
|
|
|
server_hello_done = 14,
|
|
|
|
certificate_verify = 15,
|
|
|
|
client_key_exchange = 16,
|
|
|
|
finished = 20
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static const byte client[SIZEOF_SENDER] = { 0x43, 0x4C, 0x4E, 0x54 };
|
|
|
|
static const byte server[SIZEOF_SENDER] = { 0x53, 0x52, 0x56, 0x52 };
|
|
|
|
|
|
|
|
static const byte tls_client[FINISHED_LABEL_SZ + 1] = "client finished";
|
|
|
|
static const byte tls_server[FINISHED_LABEL_SZ + 1] = "server finished";
|
|
|
|
|
|
|
|
|
|
|
|
/* internal functions */
|
2011-08-27 01:40:51 +04:00
|
|
|
CYASSL_LOCAL int SendChangeCipher(CYASSL*);
|
|
|
|
CYASSL_LOCAL int SendData(CYASSL*, const void*, int);
|
|
|
|
CYASSL_LOCAL int SendCertificate(CYASSL*);
|
|
|
|
CYASSL_LOCAL int SendCertificateRequest(CYASSL*);
|
|
|
|
CYASSL_LOCAL int SendServerKeyExchange(CYASSL*);
|
|
|
|
CYASSL_LOCAL int SendBuffered(CYASSL*);
|
2012-11-17 00:16:00 +04:00
|
|
|
CYASSL_LOCAL int ReceiveData(CYASSL*, byte*, int, int);
|
2011-08-27 01:40:51 +04:00
|
|
|
CYASSL_LOCAL int SendFinished(CYASSL*);
|
|
|
|
CYASSL_LOCAL int SendAlert(CYASSL*, int, int);
|
|
|
|
CYASSL_LOCAL int ProcessReply(CYASSL*);
|
|
|
|
|
|
|
|
CYASSL_LOCAL int SetCipherSpecs(CYASSL*);
|
|
|
|
CYASSL_LOCAL int MakeMasterSecret(CYASSL*);
|
|
|
|
|
|
|
|
CYASSL_LOCAL int AddSession(CYASSL*);
|
|
|
|
CYASSL_LOCAL int DeriveKeys(CYASSL* ssl);
|
|
|
|
CYASSL_LOCAL int StoreKeys(CYASSL* ssl, const byte* keyData);
|
|
|
|
|
|
|
|
CYASSL_LOCAL int IsTLS(const CYASSL* ssl);
|
|
|
|
CYASSL_LOCAL int IsAtLeastTLSv1_2(const CYASSL* ssl);
|
|
|
|
|
2012-09-05 21:17:48 +04:00
|
|
|
CYASSL_LOCAL void FreeHandshakeResources(CYASSL* ssl);
|
2011-08-27 01:40:51 +04:00
|
|
|
CYASSL_LOCAL void ShrinkInputBuffer(CYASSL* ssl, int forcedFree);
|
|
|
|
CYASSL_LOCAL void ShrinkOutputBuffer(CYASSL* ssl);
|
2012-11-01 23:36:47 +04:00
|
|
|
#ifndef NO_CERTS
|
|
|
|
CYASSL_LOCAL Signer* GetCA(void* cm, byte* hash);
|
2013-04-29 23:08:16 +04:00
|
|
|
#ifndef NO_SKID
|
|
|
|
CYASSL_LOCAL Signer* GetCAByName(void* cm, byte* hash);
|
|
|
|
#endif
|
2012-11-01 23:36:47 +04:00
|
|
|
#endif
|
2011-08-27 01:40:51 +04:00
|
|
|
CYASSL_LOCAL void BuildTlsFinished(CYASSL* ssl, Hashes* hashes,
|
|
|
|
const byte* sender);
|
2012-09-15 08:19:06 +04:00
|
|
|
CYASSL_LOCAL void FreeArrays(CYASSL* ssl, int keep);
|
2013-05-13 23:32:47 +04:00
|
|
|
CYASSL_LOCAL int CheckAvailableSize(CYASSL *ssl, int size);
|
2012-10-25 04:37:57 +04:00
|
|
|
CYASSL_LOCAL int GrowInputBuffer(CYASSL* ssl, int size, int usedLength);
|
2012-09-15 08:19:06 +04:00
|
|
|
|
2011-04-28 04:31:08 +04:00
|
|
|
#ifndef NO_TLS
|
2011-08-27 01:40:51 +04:00
|
|
|
CYASSL_LOCAL int MakeTlsMasterSecret(CYASSL*);
|
2012-12-18 23:40:45 +04:00
|
|
|
CYASSL_LOCAL void TLS_hmac(CYASSL* ssl, byte* digest, const byte* in,
|
2011-04-28 04:31:08 +04:00
|
|
|
word32 sz, int content, int verify);
|
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
#ifndef NO_CYASSL_CLIENT
|
2011-08-27 01:40:51 +04:00
|
|
|
CYASSL_LOCAL int SendClientHello(CYASSL*);
|
|
|
|
CYASSL_LOCAL int SendClientKeyExchange(CYASSL*);
|
|
|
|
CYASSL_LOCAL int SendCertificateVerify(CYASSL*);
|
2011-02-05 22:14:47 +03:00
|
|
|
#endif /* NO_CYASSL_CLIENT */
|
|
|
|
|
|
|
|
#ifndef NO_CYASSL_SERVER
|
2011-08-27 01:40:51 +04:00
|
|
|
CYASSL_LOCAL int SendServerHello(CYASSL*);
|
|
|
|
CYASSL_LOCAL int SendServerHelloDone(CYASSL*);
|
2011-02-05 22:14:47 +03:00
|
|
|
#ifdef CYASSL_DTLS
|
2011-08-27 01:40:51 +04:00
|
|
|
CYASSL_LOCAL int SendHelloVerifyRequest(CYASSL*);
|
2011-02-05 22:14:47 +03:00
|
|
|
#endif
|
|
|
|
#endif /* NO_CYASSL_SERVER */
|
|
|
|
|
2012-09-14 20:35:34 +04:00
|
|
|
#ifdef CYASSL_DTLS
|
|
|
|
CYASSL_LOCAL int DtlsPoolInit(CYASSL*);
|
2012-09-17 20:52:20 +04:00
|
|
|
CYASSL_LOCAL int DtlsPoolSave(CYASSL*, const byte*, int);
|
2012-09-15 06:30:50 +04:00
|
|
|
CYASSL_LOCAL int DtlsPoolTimeout(CYASSL*);
|
2012-09-14 20:35:34 +04:00
|
|
|
CYASSL_LOCAL int DtlsPoolSend(CYASSL*);
|
|
|
|
CYASSL_LOCAL void DtlsPoolReset(CYASSL*);
|
2013-02-20 00:51:02 +04:00
|
|
|
|
|
|
|
CYASSL_LOCAL DtlsMsg* DtlsMsgNew(word32, void*);
|
2013-02-07 23:26:02 +04:00
|
|
|
CYASSL_LOCAL void DtlsMsgDelete(DtlsMsg*, void*);
|
2013-02-20 00:51:02 +04:00
|
|
|
CYASSL_LOCAL void DtlsMsgListDelete(DtlsMsg*, void*);
|
2013-02-20 04:06:02 +04:00
|
|
|
CYASSL_LOCAL void DtlsMsgSet(DtlsMsg*, word32, const byte*, byte,
|
|
|
|
word32, word32);
|
2013-02-20 00:51:02 +04:00
|
|
|
CYASSL_LOCAL DtlsMsg* DtlsMsgFind(DtlsMsg*, word32);
|
|
|
|
CYASSL_LOCAL DtlsMsg* DtlsMsgStore(DtlsMsg*, word32, const byte*, word32,
|
2013-02-20 04:06:02 +04:00
|
|
|
byte, word32, word32, void*);
|
2013-02-07 23:26:02 +04:00
|
|
|
CYASSL_LOCAL DtlsMsg* DtlsMsgInsert(DtlsMsg*, DtlsMsg*);
|
2012-09-14 20:35:34 +04:00
|
|
|
#endif /* CYASSL_DTLS */
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
#ifndef NO_TLS
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* NO_TLS */
|
|
|
|
|
|
|
|
|
2011-04-27 02:41:16 +04:00
|
|
|
CYASSL_LOCAL word32 LowResTimer(void);
|
2011-02-05 22:14:47 +03:00
|
|
|
|
2013-10-18 01:31:20 +04:00
|
|
|
CYASSL_LOCAL void InitX509Name(CYASSL_X509_NAME*, int);
|
|
|
|
CYASSL_LOCAL void FreeX509Name(CYASSL_X509_NAME* name);
|
2013-04-23 22:50:06 +04:00
|
|
|
CYASSL_LOCAL void InitX509(CYASSL_X509*, int);
|
|
|
|
CYASSL_LOCAL void FreeX509(CYASSL_X509*);
|
2013-05-10 02:29:25 +04:00
|
|
|
#ifndef NO_CERTS
|
|
|
|
CYASSL_LOCAL int CopyDecodedToX509(CYASSL_X509*, DecodedCert*);
|
|
|
|
#endif
|
2011-02-05 22:14:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
} /* extern "C" */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* CyaSSL_INT_H */
|
|
|
|
|