SSL/TLS Library
CyaSSL is SSL/TLS library for embedded systems.
src/internal.c@0:9d17e4342598, 2014-04-20 (annotated)
- Committer:
- wolfSSL
- Date:
- Sun Apr 20 12:40:57 2014 +0000
- Revision:
- 0:9d17e4342598
CyaSSL SSL/TLS Library 2.9.4;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wolfSSL | 0:9d17e4342598 | 1 | /* internal.c |
wolfSSL | 0:9d17e4342598 | 2 | * |
wolfSSL | 0:9d17e4342598 | 3 | * Copyright (C) 2006-2013 wolfSSL Inc. |
wolfSSL | 0:9d17e4342598 | 4 | * |
wolfSSL | 0:9d17e4342598 | 5 | * This file is part of CyaSSL. |
wolfSSL | 0:9d17e4342598 | 6 | * |
wolfSSL | 0:9d17e4342598 | 7 | * CyaSSL is free software; you can redistribute it and/or modify |
wolfSSL | 0:9d17e4342598 | 8 | * it under the terms of the GNU General Public License as published by |
wolfSSL | 0:9d17e4342598 | 9 | * the Free Software Foundation; either version 2 of the License, or |
wolfSSL | 0:9d17e4342598 | 10 | * (at your option) any later version. |
wolfSSL | 0:9d17e4342598 | 11 | * |
wolfSSL | 0:9d17e4342598 | 12 | * CyaSSL is distributed in the hope that it will be useful, |
wolfSSL | 0:9d17e4342598 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
wolfSSL | 0:9d17e4342598 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
wolfSSL | 0:9d17e4342598 | 15 | * GNU General Public License for more details. |
wolfSSL | 0:9d17e4342598 | 16 | * |
wolfSSL | 0:9d17e4342598 | 17 | * You should have received a copy of the GNU General Public License |
wolfSSL | 0:9d17e4342598 | 18 | * along with this program; if not, write to the Free Software |
wolfSSL | 0:9d17e4342598 | 19 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
wolfSSL | 0:9d17e4342598 | 20 | */ |
wolfSSL | 0:9d17e4342598 | 21 | |
wolfSSL | 0:9d17e4342598 | 22 | |
wolfSSL | 0:9d17e4342598 | 23 | #ifdef HAVE_CONFIG_H |
wolfSSL | 0:9d17e4342598 | 24 | #include <config.h> |
wolfSSL | 0:9d17e4342598 | 25 | #endif |
wolfSSL | 0:9d17e4342598 | 26 | |
wolfSSL | 0:9d17e4342598 | 27 | #include <cyassl/ctaocrypt/settings.h> |
wolfSSL | 0:9d17e4342598 | 28 | |
wolfSSL | 0:9d17e4342598 | 29 | #include <cyassl/internal.h> |
wolfSSL | 0:9d17e4342598 | 30 | #include <cyassl/error-ssl.h> |
wolfSSL | 0:9d17e4342598 | 31 | #include <cyassl/ctaocrypt/asn.h> |
wolfSSL | 0:9d17e4342598 | 32 | |
wolfSSL | 0:9d17e4342598 | 33 | #ifdef HAVE_LIBZ |
wolfSSL | 0:9d17e4342598 | 34 | #include "zlib.h" |
wolfSSL | 0:9d17e4342598 | 35 | #endif |
wolfSSL | 0:9d17e4342598 | 36 | |
wolfSSL | 0:9d17e4342598 | 37 | #ifdef HAVE_NTRU |
wolfSSL | 0:9d17e4342598 | 38 | #include "crypto_ntru.h" |
wolfSSL | 0:9d17e4342598 | 39 | #endif |
wolfSSL | 0:9d17e4342598 | 40 | |
wolfSSL | 0:9d17e4342598 | 41 | #if defined(DEBUG_CYASSL) || defined(SHOW_SECRETS) |
wolfSSL | 0:9d17e4342598 | 42 | #ifdef FREESCALE_MQX |
wolfSSL | 0:9d17e4342598 | 43 | #include <fio.h> |
wolfSSL | 0:9d17e4342598 | 44 | #else |
wolfSSL | 0:9d17e4342598 | 45 | #include <stdio.h> |
wolfSSL | 0:9d17e4342598 | 46 | #endif |
wolfSSL | 0:9d17e4342598 | 47 | #endif |
wolfSSL | 0:9d17e4342598 | 48 | |
wolfSSL | 0:9d17e4342598 | 49 | #ifdef __sun |
wolfSSL | 0:9d17e4342598 | 50 | #include <sys/filio.h> |
wolfSSL | 0:9d17e4342598 | 51 | #endif |
wolfSSL | 0:9d17e4342598 | 52 | |
wolfSSL | 0:9d17e4342598 | 53 | #ifndef TRUE |
wolfSSL | 0:9d17e4342598 | 54 | #define TRUE 1 |
wolfSSL | 0:9d17e4342598 | 55 | #endif |
wolfSSL | 0:9d17e4342598 | 56 | #ifndef FALSE |
wolfSSL | 0:9d17e4342598 | 57 | #define FALSE 0 |
wolfSSL | 0:9d17e4342598 | 58 | #endif |
wolfSSL | 0:9d17e4342598 | 59 | |
wolfSSL | 0:9d17e4342598 | 60 | |
wolfSSL | 0:9d17e4342598 | 61 | #if defined(OPENSSL_EXTRA) && defined(NO_DH) |
wolfSSL | 0:9d17e4342598 | 62 | #error OPENSSL_EXTRA needs DH, please remove NO_DH |
wolfSSL | 0:9d17e4342598 | 63 | #endif |
wolfSSL | 0:9d17e4342598 | 64 | |
wolfSSL | 0:9d17e4342598 | 65 | #if defined(CYASSL_CALLBACKS) && !defined(LARGE_STATIC_BUFFERS) |
wolfSSL | 0:9d17e4342598 | 66 | #error \ |
wolfSSL | 0:9d17e4342598 | 67 | CYASSL_CALLBACKS needs LARGE_STATIC_BUFFERS, please add LARGE_STATIC_BUFFERS |
wolfSSL | 0:9d17e4342598 | 68 | #endif |
wolfSSL | 0:9d17e4342598 | 69 | |
wolfSSL | 0:9d17e4342598 | 70 | |
wolfSSL | 0:9d17e4342598 | 71 | #ifndef NO_CYASSL_CLIENT |
wolfSSL | 0:9d17e4342598 | 72 | static int DoHelloVerifyRequest(CYASSL* ssl, const byte* input, word32*, |
wolfSSL | 0:9d17e4342598 | 73 | word32); |
wolfSSL | 0:9d17e4342598 | 74 | static int DoServerHello(CYASSL* ssl, const byte* input, word32*, word32); |
wolfSSL | 0:9d17e4342598 | 75 | static int DoServerKeyExchange(CYASSL* ssl, const byte* input, word32*, |
wolfSSL | 0:9d17e4342598 | 76 | word32); |
wolfSSL | 0:9d17e4342598 | 77 | #ifndef NO_CERTS |
wolfSSL | 0:9d17e4342598 | 78 | static int DoCertificateRequest(CYASSL* ssl, const byte* input, word32*, |
wolfSSL | 0:9d17e4342598 | 79 | word32); |
wolfSSL | 0:9d17e4342598 | 80 | #endif |
wolfSSL | 0:9d17e4342598 | 81 | #endif |
wolfSSL | 0:9d17e4342598 | 82 | |
wolfSSL | 0:9d17e4342598 | 83 | |
wolfSSL | 0:9d17e4342598 | 84 | #ifndef NO_CYASSL_SERVER |
wolfSSL | 0:9d17e4342598 | 85 | static int DoClientHello(CYASSL* ssl, const byte* input, word32*, word32); |
wolfSSL | 0:9d17e4342598 | 86 | static int DoClientKeyExchange(CYASSL* ssl, byte* input, word32*, word32); |
wolfSSL | 0:9d17e4342598 | 87 | #if !defined(NO_RSA) || defined(HAVE_ECC) |
wolfSSL | 0:9d17e4342598 | 88 | static int DoCertificateVerify(CYASSL* ssl, byte*, word32*, word32); |
wolfSSL | 0:9d17e4342598 | 89 | #endif |
wolfSSL | 0:9d17e4342598 | 90 | #endif |
wolfSSL | 0:9d17e4342598 | 91 | |
wolfSSL | 0:9d17e4342598 | 92 | |
wolfSSL | 0:9d17e4342598 | 93 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 94 | static INLINE int DtlsCheckWindow(DtlsState* state); |
wolfSSL | 0:9d17e4342598 | 95 | static INLINE int DtlsUpdateWindow(DtlsState* state); |
wolfSSL | 0:9d17e4342598 | 96 | #endif |
wolfSSL | 0:9d17e4342598 | 97 | |
wolfSSL | 0:9d17e4342598 | 98 | |
wolfSSL | 0:9d17e4342598 | 99 | typedef enum { |
wolfSSL | 0:9d17e4342598 | 100 | doProcessInit = 0, |
wolfSSL | 0:9d17e4342598 | 101 | #ifndef NO_CYASSL_SERVER |
wolfSSL | 0:9d17e4342598 | 102 | runProcessOldClientHello, |
wolfSSL | 0:9d17e4342598 | 103 | #endif |
wolfSSL | 0:9d17e4342598 | 104 | getRecordLayerHeader, |
wolfSSL | 0:9d17e4342598 | 105 | getData, |
wolfSSL | 0:9d17e4342598 | 106 | runProcessingOneMessage |
wolfSSL | 0:9d17e4342598 | 107 | } processReply; |
wolfSSL | 0:9d17e4342598 | 108 | |
wolfSSL | 0:9d17e4342598 | 109 | #ifndef NO_OLD_TLS |
wolfSSL | 0:9d17e4342598 | 110 | static int SSL_hmac(CYASSL* ssl, byte* digest, const byte* in, word32 sz, |
wolfSSL | 0:9d17e4342598 | 111 | int content, int verify); |
wolfSSL | 0:9d17e4342598 | 112 | |
wolfSSL | 0:9d17e4342598 | 113 | #endif |
wolfSSL | 0:9d17e4342598 | 114 | |
wolfSSL | 0:9d17e4342598 | 115 | #ifndef NO_CERTS |
wolfSSL | 0:9d17e4342598 | 116 | static void BuildCertHashes(CYASSL* ssl, Hashes* hashes); |
wolfSSL | 0:9d17e4342598 | 117 | #endif |
wolfSSL | 0:9d17e4342598 | 118 | |
wolfSSL | 0:9d17e4342598 | 119 | static void PickHashSigAlgo(CYASSL* ssl, |
wolfSSL | 0:9d17e4342598 | 120 | const byte* hashSigAlgo, word32 hashSigAlgoSz); |
wolfSSL | 0:9d17e4342598 | 121 | |
wolfSSL | 0:9d17e4342598 | 122 | #ifndef min |
wolfSSL | 0:9d17e4342598 | 123 | |
wolfSSL | 0:9d17e4342598 | 124 | static INLINE word32 min(word32 a, word32 b) |
wolfSSL | 0:9d17e4342598 | 125 | { |
wolfSSL | 0:9d17e4342598 | 126 | return a > b ? b : a; |
wolfSSL | 0:9d17e4342598 | 127 | } |
wolfSSL | 0:9d17e4342598 | 128 | |
wolfSSL | 0:9d17e4342598 | 129 | #endif /* min */ |
wolfSSL | 0:9d17e4342598 | 130 | |
wolfSSL | 0:9d17e4342598 | 131 | |
wolfSSL | 0:9d17e4342598 | 132 | int IsTLS(const CYASSL* ssl) |
wolfSSL | 0:9d17e4342598 | 133 | { |
wolfSSL | 0:9d17e4342598 | 134 | if (ssl->version.major == SSLv3_MAJOR && ssl->version.minor >=TLSv1_MINOR) |
wolfSSL | 0:9d17e4342598 | 135 | return 1; |
wolfSSL | 0:9d17e4342598 | 136 | |
wolfSSL | 0:9d17e4342598 | 137 | return 0; |
wolfSSL | 0:9d17e4342598 | 138 | } |
wolfSSL | 0:9d17e4342598 | 139 | |
wolfSSL | 0:9d17e4342598 | 140 | |
wolfSSL | 0:9d17e4342598 | 141 | int IsAtLeastTLSv1_2(const CYASSL* ssl) |
wolfSSL | 0:9d17e4342598 | 142 | { |
wolfSSL | 0:9d17e4342598 | 143 | if (ssl->version.major == SSLv3_MAJOR && ssl->version.minor >=TLSv1_2_MINOR) |
wolfSSL | 0:9d17e4342598 | 144 | return 1; |
wolfSSL | 0:9d17e4342598 | 145 | if (ssl->version.major == DTLS_MAJOR && ssl->version.minor <= DTLSv1_2_MINOR) |
wolfSSL | 0:9d17e4342598 | 146 | return 1; |
wolfSSL | 0:9d17e4342598 | 147 | |
wolfSSL | 0:9d17e4342598 | 148 | return 0; |
wolfSSL | 0:9d17e4342598 | 149 | } |
wolfSSL | 0:9d17e4342598 | 150 | |
wolfSSL | 0:9d17e4342598 | 151 | |
wolfSSL | 0:9d17e4342598 | 152 | #ifdef HAVE_NTRU |
wolfSSL | 0:9d17e4342598 | 153 | |
wolfSSL | 0:9d17e4342598 | 154 | static byte GetEntropy(ENTROPY_CMD cmd, byte* out) |
wolfSSL | 0:9d17e4342598 | 155 | { |
wolfSSL | 0:9d17e4342598 | 156 | /* TODO: add locking? */ |
wolfSSL | 0:9d17e4342598 | 157 | static RNG rng; |
wolfSSL | 0:9d17e4342598 | 158 | |
wolfSSL | 0:9d17e4342598 | 159 | if (cmd == INIT) { |
wolfSSL | 0:9d17e4342598 | 160 | int ret = InitRng(&rng); |
wolfSSL | 0:9d17e4342598 | 161 | if (ret == 0) |
wolfSSL | 0:9d17e4342598 | 162 | return 1; |
wolfSSL | 0:9d17e4342598 | 163 | else |
wolfSSL | 0:9d17e4342598 | 164 | return 0; |
wolfSSL | 0:9d17e4342598 | 165 | } |
wolfSSL | 0:9d17e4342598 | 166 | |
wolfSSL | 0:9d17e4342598 | 167 | if (out == NULL) |
wolfSSL | 0:9d17e4342598 | 168 | return 0; |
wolfSSL | 0:9d17e4342598 | 169 | |
wolfSSL | 0:9d17e4342598 | 170 | if (cmd == GET_BYTE_OF_ENTROPY) { |
wolfSSL | 0:9d17e4342598 | 171 | RNG_GenerateBlock(&rng, out, 1); |
wolfSSL | 0:9d17e4342598 | 172 | return 1; |
wolfSSL | 0:9d17e4342598 | 173 | } |
wolfSSL | 0:9d17e4342598 | 174 | |
wolfSSL | 0:9d17e4342598 | 175 | if (cmd == GET_NUM_BYTES_PER_BYTE_OF_ENTROPY) { |
wolfSSL | 0:9d17e4342598 | 176 | *out = 1; |
wolfSSL | 0:9d17e4342598 | 177 | return 1; |
wolfSSL | 0:9d17e4342598 | 178 | } |
wolfSSL | 0:9d17e4342598 | 179 | |
wolfSSL | 0:9d17e4342598 | 180 | return 0; |
wolfSSL | 0:9d17e4342598 | 181 | } |
wolfSSL | 0:9d17e4342598 | 182 | |
wolfSSL | 0:9d17e4342598 | 183 | #endif /* HAVE_NTRU */ |
wolfSSL | 0:9d17e4342598 | 184 | |
wolfSSL | 0:9d17e4342598 | 185 | /* used by ssl.c too */ |
wolfSSL | 0:9d17e4342598 | 186 | void c32to24(word32 in, word24 out) |
wolfSSL | 0:9d17e4342598 | 187 | { |
wolfSSL | 0:9d17e4342598 | 188 | out[0] = (in >> 16) & 0xff; |
wolfSSL | 0:9d17e4342598 | 189 | out[1] = (in >> 8) & 0xff; |
wolfSSL | 0:9d17e4342598 | 190 | out[2] = in & 0xff; |
wolfSSL | 0:9d17e4342598 | 191 | } |
wolfSSL | 0:9d17e4342598 | 192 | |
wolfSSL | 0:9d17e4342598 | 193 | |
wolfSSL | 0:9d17e4342598 | 194 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 195 | |
wolfSSL | 0:9d17e4342598 | 196 | static INLINE void c32to48(word32 in, byte out[6]) |
wolfSSL | 0:9d17e4342598 | 197 | { |
wolfSSL | 0:9d17e4342598 | 198 | out[0] = 0; |
wolfSSL | 0:9d17e4342598 | 199 | out[1] = 0; |
wolfSSL | 0:9d17e4342598 | 200 | out[2] = (in >> 24) & 0xff; |
wolfSSL | 0:9d17e4342598 | 201 | out[3] = (in >> 16) & 0xff; |
wolfSSL | 0:9d17e4342598 | 202 | out[4] = (in >> 8) & 0xff; |
wolfSSL | 0:9d17e4342598 | 203 | out[5] = in & 0xff; |
wolfSSL | 0:9d17e4342598 | 204 | } |
wolfSSL | 0:9d17e4342598 | 205 | |
wolfSSL | 0:9d17e4342598 | 206 | #endif /* CYASSL_DTLS */ |
wolfSSL | 0:9d17e4342598 | 207 | |
wolfSSL | 0:9d17e4342598 | 208 | |
wolfSSL | 0:9d17e4342598 | 209 | /* convert 16 bit integer to opaque */ |
wolfSSL | 0:9d17e4342598 | 210 | static INLINE void c16toa(word16 u16, byte* c) |
wolfSSL | 0:9d17e4342598 | 211 | { |
wolfSSL | 0:9d17e4342598 | 212 | c[0] = (u16 >> 8) & 0xff; |
wolfSSL | 0:9d17e4342598 | 213 | c[1] = u16 & 0xff; |
wolfSSL | 0:9d17e4342598 | 214 | } |
wolfSSL | 0:9d17e4342598 | 215 | |
wolfSSL | 0:9d17e4342598 | 216 | |
wolfSSL | 0:9d17e4342598 | 217 | /* convert 32 bit integer to opaque */ |
wolfSSL | 0:9d17e4342598 | 218 | static INLINE void c32toa(word32 u32, byte* c) |
wolfSSL | 0:9d17e4342598 | 219 | { |
wolfSSL | 0:9d17e4342598 | 220 | c[0] = (u32 >> 24) & 0xff; |
wolfSSL | 0:9d17e4342598 | 221 | c[1] = (u32 >> 16) & 0xff; |
wolfSSL | 0:9d17e4342598 | 222 | c[2] = (u32 >> 8) & 0xff; |
wolfSSL | 0:9d17e4342598 | 223 | c[3] = u32 & 0xff; |
wolfSSL | 0:9d17e4342598 | 224 | } |
wolfSSL | 0:9d17e4342598 | 225 | |
wolfSSL | 0:9d17e4342598 | 226 | |
wolfSSL | 0:9d17e4342598 | 227 | /* convert a 24 bit integer into a 32 bit one */ |
wolfSSL | 0:9d17e4342598 | 228 | static INLINE void c24to32(const word24 u24, word32* u32) |
wolfSSL | 0:9d17e4342598 | 229 | { |
wolfSSL | 0:9d17e4342598 | 230 | *u32 = (u24[0] << 16) | (u24[1] << 8) | u24[2]; |
wolfSSL | 0:9d17e4342598 | 231 | } |
wolfSSL | 0:9d17e4342598 | 232 | |
wolfSSL | 0:9d17e4342598 | 233 | |
wolfSSL | 0:9d17e4342598 | 234 | /* convert opaque to 16 bit integer */ |
wolfSSL | 0:9d17e4342598 | 235 | static INLINE void ato16(const byte* c, word16* u16) |
wolfSSL | 0:9d17e4342598 | 236 | { |
wolfSSL | 0:9d17e4342598 | 237 | *u16 = (word16) ((c[0] << 8) | (c[1])); |
wolfSSL | 0:9d17e4342598 | 238 | } |
wolfSSL | 0:9d17e4342598 | 239 | |
wolfSSL | 0:9d17e4342598 | 240 | |
wolfSSL | 0:9d17e4342598 | 241 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 242 | |
wolfSSL | 0:9d17e4342598 | 243 | /* convert opaque to 32 bit integer */ |
wolfSSL | 0:9d17e4342598 | 244 | static INLINE void ato32(const byte* c, word32* u32) |
wolfSSL | 0:9d17e4342598 | 245 | { |
wolfSSL | 0:9d17e4342598 | 246 | *u32 = (c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3]; |
wolfSSL | 0:9d17e4342598 | 247 | } |
wolfSSL | 0:9d17e4342598 | 248 | |
wolfSSL | 0:9d17e4342598 | 249 | #endif /* CYASSL_DTLS */ |
wolfSSL | 0:9d17e4342598 | 250 | |
wolfSSL | 0:9d17e4342598 | 251 | |
wolfSSL | 0:9d17e4342598 | 252 | #ifdef HAVE_LIBZ |
wolfSSL | 0:9d17e4342598 | 253 | |
wolfSSL | 0:9d17e4342598 | 254 | /* alloc user allocs to work with zlib */ |
wolfSSL | 0:9d17e4342598 | 255 | static void* myAlloc(void* opaque, unsigned int item, unsigned int size) |
wolfSSL | 0:9d17e4342598 | 256 | { |
wolfSSL | 0:9d17e4342598 | 257 | (void)opaque; |
wolfSSL | 0:9d17e4342598 | 258 | return XMALLOC(item * size, opaque, DYNAMIC_TYPE_LIBZ); |
wolfSSL | 0:9d17e4342598 | 259 | } |
wolfSSL | 0:9d17e4342598 | 260 | |
wolfSSL | 0:9d17e4342598 | 261 | |
wolfSSL | 0:9d17e4342598 | 262 | static void myFree(void* opaque, void* memory) |
wolfSSL | 0:9d17e4342598 | 263 | { |
wolfSSL | 0:9d17e4342598 | 264 | (void)opaque; |
wolfSSL | 0:9d17e4342598 | 265 | XFREE(memory, opaque, DYNAMIC_TYPE_LIBZ); |
wolfSSL | 0:9d17e4342598 | 266 | } |
wolfSSL | 0:9d17e4342598 | 267 | |
wolfSSL | 0:9d17e4342598 | 268 | |
wolfSSL | 0:9d17e4342598 | 269 | /* init zlib comp/decomp streams, 0 on success */ |
wolfSSL | 0:9d17e4342598 | 270 | static int InitStreams(CYASSL* ssl) |
wolfSSL | 0:9d17e4342598 | 271 | { |
wolfSSL | 0:9d17e4342598 | 272 | ssl->c_stream.zalloc = (alloc_func)myAlloc; |
wolfSSL | 0:9d17e4342598 | 273 | ssl->c_stream.zfree = (free_func)myFree; |
wolfSSL | 0:9d17e4342598 | 274 | ssl->c_stream.opaque = (voidpf)ssl->heap; |
wolfSSL | 0:9d17e4342598 | 275 | |
wolfSSL | 0:9d17e4342598 | 276 | if (deflateInit(&ssl->c_stream, Z_DEFAULT_COMPRESSION) != Z_OK) |
wolfSSL | 0:9d17e4342598 | 277 | return ZLIB_INIT_ERROR; |
wolfSSL | 0:9d17e4342598 | 278 | |
wolfSSL | 0:9d17e4342598 | 279 | ssl->didStreamInit = 1; |
wolfSSL | 0:9d17e4342598 | 280 | |
wolfSSL | 0:9d17e4342598 | 281 | ssl->d_stream.zalloc = (alloc_func)myAlloc; |
wolfSSL | 0:9d17e4342598 | 282 | ssl->d_stream.zfree = (free_func)myFree; |
wolfSSL | 0:9d17e4342598 | 283 | ssl->d_stream.opaque = (voidpf)ssl->heap; |
wolfSSL | 0:9d17e4342598 | 284 | |
wolfSSL | 0:9d17e4342598 | 285 | if (inflateInit(&ssl->d_stream) != Z_OK) return ZLIB_INIT_ERROR; |
wolfSSL | 0:9d17e4342598 | 286 | |
wolfSSL | 0:9d17e4342598 | 287 | return 0; |
wolfSSL | 0:9d17e4342598 | 288 | } |
wolfSSL | 0:9d17e4342598 | 289 | |
wolfSSL | 0:9d17e4342598 | 290 | |
wolfSSL | 0:9d17e4342598 | 291 | static void FreeStreams(CYASSL* ssl) |
wolfSSL | 0:9d17e4342598 | 292 | { |
wolfSSL | 0:9d17e4342598 | 293 | if (ssl->didStreamInit) { |
wolfSSL | 0:9d17e4342598 | 294 | deflateEnd(&ssl->c_stream); |
wolfSSL | 0:9d17e4342598 | 295 | inflateEnd(&ssl->d_stream); |
wolfSSL | 0:9d17e4342598 | 296 | } |
wolfSSL | 0:9d17e4342598 | 297 | } |
wolfSSL | 0:9d17e4342598 | 298 | |
wolfSSL | 0:9d17e4342598 | 299 | |
wolfSSL | 0:9d17e4342598 | 300 | /* compress in to out, return out size or error */ |
wolfSSL | 0:9d17e4342598 | 301 | static int myCompress(CYASSL* ssl, byte* in, int inSz, byte* out, int outSz) |
wolfSSL | 0:9d17e4342598 | 302 | { |
wolfSSL | 0:9d17e4342598 | 303 | int err; |
wolfSSL | 0:9d17e4342598 | 304 | int currTotal = (int)ssl->c_stream.total_out; |
wolfSSL | 0:9d17e4342598 | 305 | |
wolfSSL | 0:9d17e4342598 | 306 | ssl->c_stream.next_in = in; |
wolfSSL | 0:9d17e4342598 | 307 | ssl->c_stream.avail_in = inSz; |
wolfSSL | 0:9d17e4342598 | 308 | ssl->c_stream.next_out = out; |
wolfSSL | 0:9d17e4342598 | 309 | ssl->c_stream.avail_out = outSz; |
wolfSSL | 0:9d17e4342598 | 310 | |
wolfSSL | 0:9d17e4342598 | 311 | err = deflate(&ssl->c_stream, Z_SYNC_FLUSH); |
wolfSSL | 0:9d17e4342598 | 312 | if (err != Z_OK && err != Z_STREAM_END) return ZLIB_COMPRESS_ERROR; |
wolfSSL | 0:9d17e4342598 | 313 | |
wolfSSL | 0:9d17e4342598 | 314 | return (int)ssl->c_stream.total_out - currTotal; |
wolfSSL | 0:9d17e4342598 | 315 | } |
wolfSSL | 0:9d17e4342598 | 316 | |
wolfSSL | 0:9d17e4342598 | 317 | |
wolfSSL | 0:9d17e4342598 | 318 | /* decompress in to out, returnn out size or error */ |
wolfSSL | 0:9d17e4342598 | 319 | static int myDeCompress(CYASSL* ssl, byte* in,int inSz, byte* out,int outSz) |
wolfSSL | 0:9d17e4342598 | 320 | { |
wolfSSL | 0:9d17e4342598 | 321 | int err; |
wolfSSL | 0:9d17e4342598 | 322 | int currTotal = (int)ssl->d_stream.total_out; |
wolfSSL | 0:9d17e4342598 | 323 | |
wolfSSL | 0:9d17e4342598 | 324 | ssl->d_stream.next_in = in; |
wolfSSL | 0:9d17e4342598 | 325 | ssl->d_stream.avail_in = inSz; |
wolfSSL | 0:9d17e4342598 | 326 | ssl->d_stream.next_out = out; |
wolfSSL | 0:9d17e4342598 | 327 | ssl->d_stream.avail_out = outSz; |
wolfSSL | 0:9d17e4342598 | 328 | |
wolfSSL | 0:9d17e4342598 | 329 | err = inflate(&ssl->d_stream, Z_SYNC_FLUSH); |
wolfSSL | 0:9d17e4342598 | 330 | if (err != Z_OK && err != Z_STREAM_END) return ZLIB_DECOMPRESS_ERROR; |
wolfSSL | 0:9d17e4342598 | 331 | |
wolfSSL | 0:9d17e4342598 | 332 | return (int)ssl->d_stream.total_out - currTotal; |
wolfSSL | 0:9d17e4342598 | 333 | } |
wolfSSL | 0:9d17e4342598 | 334 | |
wolfSSL | 0:9d17e4342598 | 335 | #endif /* HAVE_LIBZ */ |
wolfSSL | 0:9d17e4342598 | 336 | |
wolfSSL | 0:9d17e4342598 | 337 | |
wolfSSL | 0:9d17e4342598 | 338 | void InitSSL_Method(CYASSL_METHOD* method, ProtocolVersion pv) |
wolfSSL | 0:9d17e4342598 | 339 | { |
wolfSSL | 0:9d17e4342598 | 340 | method->version = pv; |
wolfSSL | 0:9d17e4342598 | 341 | method->side = CYASSL_CLIENT_END; |
wolfSSL | 0:9d17e4342598 | 342 | method->downgrade = 0; |
wolfSSL | 0:9d17e4342598 | 343 | } |
wolfSSL | 0:9d17e4342598 | 344 | |
wolfSSL | 0:9d17e4342598 | 345 | |
wolfSSL | 0:9d17e4342598 | 346 | /* Initialze SSL context, return 0 on success */ |
wolfSSL | 0:9d17e4342598 | 347 | int InitSSL_Ctx(CYASSL_CTX* ctx, CYASSL_METHOD* method) |
wolfSSL | 0:9d17e4342598 | 348 | { |
wolfSSL | 0:9d17e4342598 | 349 | ctx->method = method; |
wolfSSL | 0:9d17e4342598 | 350 | ctx->refCount = 1; /* so either CTX_free or SSL_free can release */ |
wolfSSL | 0:9d17e4342598 | 351 | #ifndef NO_CERTS |
wolfSSL | 0:9d17e4342598 | 352 | ctx->certificate.buffer = 0; |
wolfSSL | 0:9d17e4342598 | 353 | ctx->certChain.buffer = 0; |
wolfSSL | 0:9d17e4342598 | 354 | ctx->privateKey.buffer = 0; |
wolfSSL | 0:9d17e4342598 | 355 | ctx->serverDH_P.buffer = 0; |
wolfSSL | 0:9d17e4342598 | 356 | ctx->serverDH_G.buffer = 0; |
wolfSSL | 0:9d17e4342598 | 357 | #endif |
wolfSSL | 0:9d17e4342598 | 358 | ctx->haveDH = 0; |
wolfSSL | 0:9d17e4342598 | 359 | ctx->haveNTRU = 0; /* start off */ |
wolfSSL | 0:9d17e4342598 | 360 | ctx->haveECDSAsig = 0; /* start off */ |
wolfSSL | 0:9d17e4342598 | 361 | ctx->haveStaticECC = 0; /* start off */ |
wolfSSL | 0:9d17e4342598 | 362 | ctx->heap = ctx; /* defaults to self */ |
wolfSSL | 0:9d17e4342598 | 363 | #ifndef NO_PSK |
wolfSSL | 0:9d17e4342598 | 364 | ctx->havePSK = 0; |
wolfSSL | 0:9d17e4342598 | 365 | ctx->server_hint[0] = 0; |
wolfSSL | 0:9d17e4342598 | 366 | ctx->client_psk_cb = 0; |
wolfSSL | 0:9d17e4342598 | 367 | ctx->server_psk_cb = 0; |
wolfSSL | 0:9d17e4342598 | 368 | #endif /* NO_PSK */ |
wolfSSL | 0:9d17e4342598 | 369 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 370 | ctx->eccTempKeySz = ECDHE_SIZE; |
wolfSSL | 0:9d17e4342598 | 371 | #endif |
wolfSSL | 0:9d17e4342598 | 372 | |
wolfSSL | 0:9d17e4342598 | 373 | #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER) |
wolfSSL | 0:9d17e4342598 | 374 | ctx->passwd_cb = 0; |
wolfSSL | 0:9d17e4342598 | 375 | ctx->userdata = 0; |
wolfSSL | 0:9d17e4342598 | 376 | #endif /* OPENSSL_EXTRA */ |
wolfSSL | 0:9d17e4342598 | 377 | |
wolfSSL | 0:9d17e4342598 | 378 | ctx->timeout = DEFAULT_TIMEOUT; |
wolfSSL | 0:9d17e4342598 | 379 | |
wolfSSL | 0:9d17e4342598 | 380 | #ifndef CYASSL_USER_IO |
wolfSSL | 0:9d17e4342598 | 381 | ctx->CBIORecv = EmbedReceive; |
wolfSSL | 0:9d17e4342598 | 382 | ctx->CBIOSend = EmbedSend; |
wolfSSL | 0:9d17e4342598 | 383 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 384 | if (method->version.major == DTLS_MAJOR) { |
wolfSSL | 0:9d17e4342598 | 385 | ctx->CBIORecv = EmbedReceiveFrom; |
wolfSSL | 0:9d17e4342598 | 386 | ctx->CBIOSend = EmbedSendTo; |
wolfSSL | 0:9d17e4342598 | 387 | ctx->CBIOCookie = EmbedGenerateCookie; |
wolfSSL | 0:9d17e4342598 | 388 | } |
wolfSSL | 0:9d17e4342598 | 389 | #endif |
wolfSSL | 0:9d17e4342598 | 390 | #else |
wolfSSL | 0:9d17e4342598 | 391 | /* user will set */ |
wolfSSL | 0:9d17e4342598 | 392 | ctx->CBIORecv = NULL; |
wolfSSL | 0:9d17e4342598 | 393 | ctx->CBIOSend = NULL; |
wolfSSL | 0:9d17e4342598 | 394 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 395 | ctx->CBIOCookie = NULL; |
wolfSSL | 0:9d17e4342598 | 396 | #endif |
wolfSSL | 0:9d17e4342598 | 397 | #endif /* CYASSL_USER_IO */ |
wolfSSL | 0:9d17e4342598 | 398 | #ifdef HAVE_NETX |
wolfSSL | 0:9d17e4342598 | 399 | ctx->CBIORecv = NetX_Receive; |
wolfSSL | 0:9d17e4342598 | 400 | ctx->CBIOSend = NetX_Send; |
wolfSSL | 0:9d17e4342598 | 401 | #endif |
wolfSSL | 0:9d17e4342598 | 402 | ctx->partialWrite = 0; |
wolfSSL | 0:9d17e4342598 | 403 | ctx->verifyCallback = 0; |
wolfSSL | 0:9d17e4342598 | 404 | |
wolfSSL | 0:9d17e4342598 | 405 | #ifndef NO_CERTS |
wolfSSL | 0:9d17e4342598 | 406 | ctx->cm = CyaSSL_CertManagerNew(); |
wolfSSL | 0:9d17e4342598 | 407 | #endif |
wolfSSL | 0:9d17e4342598 | 408 | #ifdef HAVE_NTRU |
wolfSSL | 0:9d17e4342598 | 409 | if (method->side == CYASSL_CLIENT_END) |
wolfSSL | 0:9d17e4342598 | 410 | ctx->haveNTRU = 1; /* always on cliet side */ |
wolfSSL | 0:9d17e4342598 | 411 | /* server can turn on by loading key */ |
wolfSSL | 0:9d17e4342598 | 412 | #endif |
wolfSSL | 0:9d17e4342598 | 413 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 414 | if (method->side == CYASSL_CLIENT_END) { |
wolfSSL | 0:9d17e4342598 | 415 | ctx->haveECDSAsig = 1; /* always on cliet side */ |
wolfSSL | 0:9d17e4342598 | 416 | ctx->haveStaticECC = 1; /* server can turn on by loading key */ |
wolfSSL | 0:9d17e4342598 | 417 | } |
wolfSSL | 0:9d17e4342598 | 418 | #endif |
wolfSSL | 0:9d17e4342598 | 419 | ctx->suites.setSuites = 0; /* user hasn't set yet */ |
wolfSSL | 0:9d17e4342598 | 420 | /* remove DH later if server didn't set, add psk later */ |
wolfSSL | 0:9d17e4342598 | 421 | InitSuites(&ctx->suites, method->version, TRUE, FALSE, TRUE, ctx->haveNTRU, |
wolfSSL | 0:9d17e4342598 | 422 | ctx->haveECDSAsig, ctx->haveStaticECC, method->side); |
wolfSSL | 0:9d17e4342598 | 423 | ctx->verifyPeer = 0; |
wolfSSL | 0:9d17e4342598 | 424 | ctx->verifyNone = 0; |
wolfSSL | 0:9d17e4342598 | 425 | ctx->failNoCert = 0; |
wolfSSL | 0:9d17e4342598 | 426 | ctx->sessionCacheOff = 0; /* initially on */ |
wolfSSL | 0:9d17e4342598 | 427 | ctx->sessionCacheFlushOff = 0; /* initially on */ |
wolfSSL | 0:9d17e4342598 | 428 | ctx->sendVerify = 0; |
wolfSSL | 0:9d17e4342598 | 429 | ctx->quietShutdown = 0; |
wolfSSL | 0:9d17e4342598 | 430 | ctx->groupMessages = 0; |
wolfSSL | 0:9d17e4342598 | 431 | #ifdef HAVE_CAVIUM |
wolfSSL | 0:9d17e4342598 | 432 | ctx->devId = NO_CAVIUM_DEVICE; |
wolfSSL | 0:9d17e4342598 | 433 | #endif |
wolfSSL | 0:9d17e4342598 | 434 | #ifdef HAVE_TLS_EXTENSIONS |
wolfSSL | 0:9d17e4342598 | 435 | ctx->extensions = NULL; |
wolfSSL | 0:9d17e4342598 | 436 | #endif |
wolfSSL | 0:9d17e4342598 | 437 | #ifdef ATOMIC_USER |
wolfSSL | 0:9d17e4342598 | 438 | ctx->MacEncryptCb = NULL; |
wolfSSL | 0:9d17e4342598 | 439 | ctx->DecryptVerifyCb = NULL; |
wolfSSL | 0:9d17e4342598 | 440 | #endif |
wolfSSL | 0:9d17e4342598 | 441 | #ifdef HAVE_PK_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 442 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 443 | ctx->EccSignCb = NULL; |
wolfSSL | 0:9d17e4342598 | 444 | ctx->EccVerifyCb = NULL; |
wolfSSL | 0:9d17e4342598 | 445 | #endif /* HAVE_ECC */ |
wolfSSL | 0:9d17e4342598 | 446 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 447 | ctx->RsaSignCb = NULL; |
wolfSSL | 0:9d17e4342598 | 448 | ctx->RsaVerifyCb = NULL; |
wolfSSL | 0:9d17e4342598 | 449 | ctx->RsaEncCb = NULL; |
wolfSSL | 0:9d17e4342598 | 450 | ctx->RsaDecCb = NULL; |
wolfSSL | 0:9d17e4342598 | 451 | #endif /* NO_RSA */ |
wolfSSL | 0:9d17e4342598 | 452 | #endif /* HAVE_PK_CALLBACKS */ |
wolfSSL | 0:9d17e4342598 | 453 | |
wolfSSL | 0:9d17e4342598 | 454 | if (InitMutex(&ctx->countMutex) < 0) { |
wolfSSL | 0:9d17e4342598 | 455 | CYASSL_MSG("Mutex error on CTX init"); |
wolfSSL | 0:9d17e4342598 | 456 | return BAD_MUTEX_E; |
wolfSSL | 0:9d17e4342598 | 457 | } |
wolfSSL | 0:9d17e4342598 | 458 | #ifndef NO_CERTS |
wolfSSL | 0:9d17e4342598 | 459 | if (ctx->cm == NULL) { |
wolfSSL | 0:9d17e4342598 | 460 | CYASSL_MSG("Bad Cert Manager New"); |
wolfSSL | 0:9d17e4342598 | 461 | return BAD_CERT_MANAGER_ERROR; |
wolfSSL | 0:9d17e4342598 | 462 | } |
wolfSSL | 0:9d17e4342598 | 463 | #endif |
wolfSSL | 0:9d17e4342598 | 464 | return 0; |
wolfSSL | 0:9d17e4342598 | 465 | } |
wolfSSL | 0:9d17e4342598 | 466 | |
wolfSSL | 0:9d17e4342598 | 467 | |
wolfSSL | 0:9d17e4342598 | 468 | /* In case contexts are held in array and don't want to free actual ctx */ |
wolfSSL | 0:9d17e4342598 | 469 | void SSL_CtxResourceFree(CYASSL_CTX* ctx) |
wolfSSL | 0:9d17e4342598 | 470 | { |
wolfSSL | 0:9d17e4342598 | 471 | XFREE(ctx->method, ctx->heap, DYNAMIC_TYPE_METHOD); |
wolfSSL | 0:9d17e4342598 | 472 | |
wolfSSL | 0:9d17e4342598 | 473 | #ifndef NO_CERTS |
wolfSSL | 0:9d17e4342598 | 474 | XFREE(ctx->serverDH_G.buffer, ctx->heap, DYNAMIC_TYPE_DH); |
wolfSSL | 0:9d17e4342598 | 475 | XFREE(ctx->serverDH_P.buffer, ctx->heap, DYNAMIC_TYPE_DH); |
wolfSSL | 0:9d17e4342598 | 476 | XFREE(ctx->privateKey.buffer, ctx->heap, DYNAMIC_TYPE_KEY); |
wolfSSL | 0:9d17e4342598 | 477 | XFREE(ctx->certificate.buffer, ctx->heap, DYNAMIC_TYPE_CERT); |
wolfSSL | 0:9d17e4342598 | 478 | XFREE(ctx->certChain.buffer, ctx->heap, DYNAMIC_TYPE_CERT); |
wolfSSL | 0:9d17e4342598 | 479 | CyaSSL_CertManagerFree(ctx->cm); |
wolfSSL | 0:9d17e4342598 | 480 | #endif |
wolfSSL | 0:9d17e4342598 | 481 | #ifdef HAVE_TLS_EXTENSIONS |
wolfSSL | 0:9d17e4342598 | 482 | TLSX_FreeAll(ctx->extensions); |
wolfSSL | 0:9d17e4342598 | 483 | #endif |
wolfSSL | 0:9d17e4342598 | 484 | } |
wolfSSL | 0:9d17e4342598 | 485 | |
wolfSSL | 0:9d17e4342598 | 486 | |
wolfSSL | 0:9d17e4342598 | 487 | void FreeSSL_Ctx(CYASSL_CTX* ctx) |
wolfSSL | 0:9d17e4342598 | 488 | { |
wolfSSL | 0:9d17e4342598 | 489 | int doFree = 0; |
wolfSSL | 0:9d17e4342598 | 490 | |
wolfSSL | 0:9d17e4342598 | 491 | if (LockMutex(&ctx->countMutex) != 0) { |
wolfSSL | 0:9d17e4342598 | 492 | CYASSL_MSG("Couldn't lock count mutex"); |
wolfSSL | 0:9d17e4342598 | 493 | return; |
wolfSSL | 0:9d17e4342598 | 494 | } |
wolfSSL | 0:9d17e4342598 | 495 | ctx->refCount--; |
wolfSSL | 0:9d17e4342598 | 496 | if (ctx->refCount == 0) |
wolfSSL | 0:9d17e4342598 | 497 | doFree = 1; |
wolfSSL | 0:9d17e4342598 | 498 | UnLockMutex(&ctx->countMutex); |
wolfSSL | 0:9d17e4342598 | 499 | |
wolfSSL | 0:9d17e4342598 | 500 | if (doFree) { |
wolfSSL | 0:9d17e4342598 | 501 | CYASSL_MSG("CTX ref count down to 0, doing full free"); |
wolfSSL | 0:9d17e4342598 | 502 | SSL_CtxResourceFree(ctx); |
wolfSSL | 0:9d17e4342598 | 503 | FreeMutex(&ctx->countMutex); |
wolfSSL | 0:9d17e4342598 | 504 | XFREE(ctx, ctx->heap, DYNAMIC_TYPE_CTX); |
wolfSSL | 0:9d17e4342598 | 505 | } |
wolfSSL | 0:9d17e4342598 | 506 | else { |
wolfSSL | 0:9d17e4342598 | 507 | (void)ctx; |
wolfSSL | 0:9d17e4342598 | 508 | CYASSL_MSG("CTX ref count not 0 yet, no free"); |
wolfSSL | 0:9d17e4342598 | 509 | } |
wolfSSL | 0:9d17e4342598 | 510 | } |
wolfSSL | 0:9d17e4342598 | 511 | |
wolfSSL | 0:9d17e4342598 | 512 | |
wolfSSL | 0:9d17e4342598 | 513 | /* Set cipher pointers to null */ |
wolfSSL | 0:9d17e4342598 | 514 | void InitCiphers(CYASSL* ssl) |
wolfSSL | 0:9d17e4342598 | 515 | { |
wolfSSL | 0:9d17e4342598 | 516 | #ifdef BUILD_ARC4 |
wolfSSL | 0:9d17e4342598 | 517 | ssl->encrypt.arc4 = NULL; |
wolfSSL | 0:9d17e4342598 | 518 | ssl->decrypt.arc4 = NULL; |
wolfSSL | 0:9d17e4342598 | 519 | #endif |
wolfSSL | 0:9d17e4342598 | 520 | #ifdef BUILD_DES3 |
wolfSSL | 0:9d17e4342598 | 521 | ssl->encrypt.des3 = NULL; |
wolfSSL | 0:9d17e4342598 | 522 | ssl->decrypt.des3 = NULL; |
wolfSSL | 0:9d17e4342598 | 523 | #endif |
wolfSSL | 0:9d17e4342598 | 524 | #ifdef BUILD_AES |
wolfSSL | 0:9d17e4342598 | 525 | ssl->encrypt.aes = NULL; |
wolfSSL | 0:9d17e4342598 | 526 | ssl->decrypt.aes = NULL; |
wolfSSL | 0:9d17e4342598 | 527 | #endif |
wolfSSL | 0:9d17e4342598 | 528 | #ifdef HAVE_CAMELLIA |
wolfSSL | 0:9d17e4342598 | 529 | ssl->encrypt.cam = NULL; |
wolfSSL | 0:9d17e4342598 | 530 | ssl->decrypt.cam = NULL; |
wolfSSL | 0:9d17e4342598 | 531 | #endif |
wolfSSL | 0:9d17e4342598 | 532 | #ifdef HAVE_HC128 |
wolfSSL | 0:9d17e4342598 | 533 | ssl->encrypt.hc128 = NULL; |
wolfSSL | 0:9d17e4342598 | 534 | ssl->decrypt.hc128 = NULL; |
wolfSSL | 0:9d17e4342598 | 535 | #endif |
wolfSSL | 0:9d17e4342598 | 536 | #ifdef BUILD_RABBIT |
wolfSSL | 0:9d17e4342598 | 537 | ssl->encrypt.rabbit = NULL; |
wolfSSL | 0:9d17e4342598 | 538 | ssl->decrypt.rabbit = NULL; |
wolfSSL | 0:9d17e4342598 | 539 | #endif |
wolfSSL | 0:9d17e4342598 | 540 | ssl->encrypt.setup = 0; |
wolfSSL | 0:9d17e4342598 | 541 | ssl->decrypt.setup = 0; |
wolfSSL | 0:9d17e4342598 | 542 | } |
wolfSSL | 0:9d17e4342598 | 543 | |
wolfSSL | 0:9d17e4342598 | 544 | |
wolfSSL | 0:9d17e4342598 | 545 | /* Free ciphers */ |
wolfSSL | 0:9d17e4342598 | 546 | void FreeCiphers(CYASSL* ssl) |
wolfSSL | 0:9d17e4342598 | 547 | { |
wolfSSL | 0:9d17e4342598 | 548 | (void)ssl; |
wolfSSL | 0:9d17e4342598 | 549 | #ifdef BUILD_ARC4 |
wolfSSL | 0:9d17e4342598 | 550 | #ifdef HAVE_CAVIUM |
wolfSSL | 0:9d17e4342598 | 551 | if (ssl->devId != NO_CAVIUM_DEVICE) { |
wolfSSL | 0:9d17e4342598 | 552 | Arc4FreeCavium(ssl->encrypt.arc4); |
wolfSSL | 0:9d17e4342598 | 553 | Arc4FreeCavium(ssl->decrypt.arc4); |
wolfSSL | 0:9d17e4342598 | 554 | } |
wolfSSL | 0:9d17e4342598 | 555 | #endif |
wolfSSL | 0:9d17e4342598 | 556 | XFREE(ssl->encrypt.arc4, ssl->heap, DYNAMIC_TYPE_CIPHER); |
wolfSSL | 0:9d17e4342598 | 557 | XFREE(ssl->decrypt.arc4, ssl->heap, DYNAMIC_TYPE_CIPHER); |
wolfSSL | 0:9d17e4342598 | 558 | #endif |
wolfSSL | 0:9d17e4342598 | 559 | #ifdef BUILD_DES3 |
wolfSSL | 0:9d17e4342598 | 560 | #ifdef HAVE_CAVIUM |
wolfSSL | 0:9d17e4342598 | 561 | if (ssl->devId != NO_CAVIUM_DEVICE) { |
wolfSSL | 0:9d17e4342598 | 562 | Des3_FreeCavium(ssl->encrypt.des3); |
wolfSSL | 0:9d17e4342598 | 563 | Des3_FreeCavium(ssl->decrypt.des3); |
wolfSSL | 0:9d17e4342598 | 564 | } |
wolfSSL | 0:9d17e4342598 | 565 | #endif |
wolfSSL | 0:9d17e4342598 | 566 | XFREE(ssl->encrypt.des3, ssl->heap, DYNAMIC_TYPE_CIPHER); |
wolfSSL | 0:9d17e4342598 | 567 | XFREE(ssl->decrypt.des3, ssl->heap, DYNAMIC_TYPE_CIPHER); |
wolfSSL | 0:9d17e4342598 | 568 | #endif |
wolfSSL | 0:9d17e4342598 | 569 | #ifdef BUILD_AES |
wolfSSL | 0:9d17e4342598 | 570 | #ifdef HAVE_CAVIUM |
wolfSSL | 0:9d17e4342598 | 571 | if (ssl->devId != NO_CAVIUM_DEVICE) { |
wolfSSL | 0:9d17e4342598 | 572 | AesFreeCavium(ssl->encrypt.aes); |
wolfSSL | 0:9d17e4342598 | 573 | AesFreeCavium(ssl->decrypt.aes); |
wolfSSL | 0:9d17e4342598 | 574 | } |
wolfSSL | 0:9d17e4342598 | 575 | #endif |
wolfSSL | 0:9d17e4342598 | 576 | XFREE(ssl->encrypt.aes, ssl->heap, DYNAMIC_TYPE_CIPHER); |
wolfSSL | 0:9d17e4342598 | 577 | XFREE(ssl->decrypt.aes, ssl->heap, DYNAMIC_TYPE_CIPHER); |
wolfSSL | 0:9d17e4342598 | 578 | #endif |
wolfSSL | 0:9d17e4342598 | 579 | #ifdef HAVE_CAMELLIA |
wolfSSL | 0:9d17e4342598 | 580 | XFREE(ssl->encrypt.cam, ssl->heap, DYNAMIC_TYPE_CIPHER); |
wolfSSL | 0:9d17e4342598 | 581 | XFREE(ssl->decrypt.cam, ssl->heap, DYNAMIC_TYPE_CIPHER); |
wolfSSL | 0:9d17e4342598 | 582 | #endif |
wolfSSL | 0:9d17e4342598 | 583 | #ifdef HAVE_HC128 |
wolfSSL | 0:9d17e4342598 | 584 | XFREE(ssl->encrypt.hc128, ssl->heap, DYNAMIC_TYPE_CIPHER); |
wolfSSL | 0:9d17e4342598 | 585 | XFREE(ssl->decrypt.hc128, ssl->heap, DYNAMIC_TYPE_CIPHER); |
wolfSSL | 0:9d17e4342598 | 586 | #endif |
wolfSSL | 0:9d17e4342598 | 587 | #ifdef BUILD_RABBIT |
wolfSSL | 0:9d17e4342598 | 588 | XFREE(ssl->encrypt.rabbit, ssl->heap, DYNAMIC_TYPE_CIPHER); |
wolfSSL | 0:9d17e4342598 | 589 | XFREE(ssl->decrypt.rabbit, ssl->heap, DYNAMIC_TYPE_CIPHER); |
wolfSSL | 0:9d17e4342598 | 590 | #endif |
wolfSSL | 0:9d17e4342598 | 591 | } |
wolfSSL | 0:9d17e4342598 | 592 | |
wolfSSL | 0:9d17e4342598 | 593 | |
wolfSSL | 0:9d17e4342598 | 594 | void InitCipherSpecs(CipherSpecs* cs) |
wolfSSL | 0:9d17e4342598 | 595 | { |
wolfSSL | 0:9d17e4342598 | 596 | cs->bulk_cipher_algorithm = INVALID_BYTE; |
wolfSSL | 0:9d17e4342598 | 597 | cs->cipher_type = INVALID_BYTE; |
wolfSSL | 0:9d17e4342598 | 598 | cs->mac_algorithm = INVALID_BYTE; |
wolfSSL | 0:9d17e4342598 | 599 | cs->kea = INVALID_BYTE; |
wolfSSL | 0:9d17e4342598 | 600 | cs->sig_algo = INVALID_BYTE; |
wolfSSL | 0:9d17e4342598 | 601 | |
wolfSSL | 0:9d17e4342598 | 602 | cs->hash_size = 0; |
wolfSSL | 0:9d17e4342598 | 603 | cs->static_ecdh = 0; |
wolfSSL | 0:9d17e4342598 | 604 | cs->key_size = 0; |
wolfSSL | 0:9d17e4342598 | 605 | cs->iv_size = 0; |
wolfSSL | 0:9d17e4342598 | 606 | cs->block_size = 0; |
wolfSSL | 0:9d17e4342598 | 607 | } |
wolfSSL | 0:9d17e4342598 | 608 | |
wolfSSL | 0:9d17e4342598 | 609 | |
wolfSSL | 0:9d17e4342598 | 610 | void InitSuites(Suites* suites, ProtocolVersion pv, byte haveRSA, byte havePSK, |
wolfSSL | 0:9d17e4342598 | 611 | byte haveDH, byte haveNTRU, byte haveECDSAsig, |
wolfSSL | 0:9d17e4342598 | 612 | byte haveStaticECC, int side) |
wolfSSL | 0:9d17e4342598 | 613 | { |
wolfSSL | 0:9d17e4342598 | 614 | word16 idx = 0; |
wolfSSL | 0:9d17e4342598 | 615 | int tls = pv.major == SSLv3_MAJOR && pv.minor >= TLSv1_MINOR; |
wolfSSL | 0:9d17e4342598 | 616 | int tls1_2 = pv.major == SSLv3_MAJOR && pv.minor >= TLSv1_2_MINOR; |
wolfSSL | 0:9d17e4342598 | 617 | int haveRSAsig = 1; |
wolfSSL | 0:9d17e4342598 | 618 | |
wolfSSL | 0:9d17e4342598 | 619 | (void)tls; /* shut up compiler */ |
wolfSSL | 0:9d17e4342598 | 620 | (void)tls1_2; |
wolfSSL | 0:9d17e4342598 | 621 | (void)haveDH; |
wolfSSL | 0:9d17e4342598 | 622 | (void)havePSK; |
wolfSSL | 0:9d17e4342598 | 623 | (void)haveNTRU; |
wolfSSL | 0:9d17e4342598 | 624 | (void)haveStaticECC; |
wolfSSL | 0:9d17e4342598 | 625 | |
wolfSSL | 0:9d17e4342598 | 626 | if (suites == NULL) { |
wolfSSL | 0:9d17e4342598 | 627 | CYASSL_MSG("InitSuites pointer error"); |
wolfSSL | 0:9d17e4342598 | 628 | return; |
wolfSSL | 0:9d17e4342598 | 629 | } |
wolfSSL | 0:9d17e4342598 | 630 | |
wolfSSL | 0:9d17e4342598 | 631 | if (suites->setSuites) |
wolfSSL | 0:9d17e4342598 | 632 | return; /* trust user settings, don't override */ |
wolfSSL | 0:9d17e4342598 | 633 | |
wolfSSL | 0:9d17e4342598 | 634 | if (side == CYASSL_SERVER_END && haveStaticECC) { |
wolfSSL | 0:9d17e4342598 | 635 | haveRSA = 0; /* can't do RSA with ECDSA key */ |
wolfSSL | 0:9d17e4342598 | 636 | (void)haveRSA; /* some builds won't read */ |
wolfSSL | 0:9d17e4342598 | 637 | } |
wolfSSL | 0:9d17e4342598 | 638 | |
wolfSSL | 0:9d17e4342598 | 639 | if (side == CYASSL_SERVER_END && haveECDSAsig) { |
wolfSSL | 0:9d17e4342598 | 640 | haveRSAsig = 0; /* can't have RSA sig if signed by ECDSA */ |
wolfSSL | 0:9d17e4342598 | 641 | (void)haveRSAsig; /* non ecc builds won't read */ |
wolfSSL | 0:9d17e4342598 | 642 | } |
wolfSSL | 0:9d17e4342598 | 643 | |
wolfSSL | 0:9d17e4342598 | 644 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 645 | if (pv.major == DTLS_MAJOR) { |
wolfSSL | 0:9d17e4342598 | 646 | tls = 1; |
wolfSSL | 0:9d17e4342598 | 647 | tls1_2 = pv.minor <= DTLSv1_2_MINOR; |
wolfSSL | 0:9d17e4342598 | 648 | } |
wolfSSL | 0:9d17e4342598 | 649 | #endif |
wolfSSL | 0:9d17e4342598 | 650 | |
wolfSSL | 0:9d17e4342598 | 651 | #ifdef HAVE_RENEGOTIATION_INDICATION |
wolfSSL | 0:9d17e4342598 | 652 | if (side == CYASSL_CLIENT_END) { |
wolfSSL | 0:9d17e4342598 | 653 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 654 | suites->suites[idx++] = TLS_EMPTY_RENEGOTIATION_INFO_SCSV; |
wolfSSL | 0:9d17e4342598 | 655 | } |
wolfSSL | 0:9d17e4342598 | 656 | #endif |
wolfSSL | 0:9d17e4342598 | 657 | |
wolfSSL | 0:9d17e4342598 | 658 | #ifdef BUILD_TLS_NTRU_RSA_WITH_AES_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 659 | if (tls && haveNTRU && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 660 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 661 | suites->suites[idx++] = TLS_NTRU_RSA_WITH_AES_256_CBC_SHA; |
wolfSSL | 0:9d17e4342598 | 662 | } |
wolfSSL | 0:9d17e4342598 | 663 | #endif |
wolfSSL | 0:9d17e4342598 | 664 | |
wolfSSL | 0:9d17e4342598 | 665 | #ifdef BUILD_TLS_NTRU_RSA_WITH_AES_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 666 | if (tls && haveNTRU && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 667 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 668 | suites->suites[idx++] = TLS_NTRU_RSA_WITH_AES_128_CBC_SHA; |
wolfSSL | 0:9d17e4342598 | 669 | } |
wolfSSL | 0:9d17e4342598 | 670 | #endif |
wolfSSL | 0:9d17e4342598 | 671 | |
wolfSSL | 0:9d17e4342598 | 672 | #ifdef BUILD_TLS_NTRU_RSA_WITH_RC4_128_SHA |
wolfSSL | 0:9d17e4342598 | 673 | if (tls && haveNTRU && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 674 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 675 | suites->suites[idx++] = TLS_NTRU_RSA_WITH_RC4_128_SHA; |
wolfSSL | 0:9d17e4342598 | 676 | } |
wolfSSL | 0:9d17e4342598 | 677 | #endif |
wolfSSL | 0:9d17e4342598 | 678 | |
wolfSSL | 0:9d17e4342598 | 679 | #ifdef BUILD_TLS_NTRU_RSA_WITH_3DES_EDE_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 680 | if (tls && haveNTRU && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 681 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 682 | suites->suites[idx++] = TLS_NTRU_RSA_WITH_3DES_EDE_CBC_SHA; |
wolfSSL | 0:9d17e4342598 | 683 | } |
wolfSSL | 0:9d17e4342598 | 684 | #endif |
wolfSSL | 0:9d17e4342598 | 685 | |
wolfSSL | 0:9d17e4342598 | 686 | #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 687 | if (tls1_2 && haveRSAsig) { |
wolfSSL | 0:9d17e4342598 | 688 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 689 | suites->suites[idx++] = TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256; |
wolfSSL | 0:9d17e4342598 | 690 | } |
wolfSSL | 0:9d17e4342598 | 691 | #endif |
wolfSSL | 0:9d17e4342598 | 692 | |
wolfSSL | 0:9d17e4342598 | 693 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 694 | if (tls1_2 && haveECDSAsig) { |
wolfSSL | 0:9d17e4342598 | 695 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 696 | suites->suites[idx++] = TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256; |
wolfSSL | 0:9d17e4342598 | 697 | } |
wolfSSL | 0:9d17e4342598 | 698 | #endif |
wolfSSL | 0:9d17e4342598 | 699 | |
wolfSSL | 0:9d17e4342598 | 700 | #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 701 | if (tls1_2 && haveRSAsig && haveStaticECC) { |
wolfSSL | 0:9d17e4342598 | 702 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 703 | suites->suites[idx++] = TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256; |
wolfSSL | 0:9d17e4342598 | 704 | } |
wolfSSL | 0:9d17e4342598 | 705 | #endif |
wolfSSL | 0:9d17e4342598 | 706 | |
wolfSSL | 0:9d17e4342598 | 707 | #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 708 | if (tls1_2 && haveECDSAsig && haveStaticECC) { |
wolfSSL | 0:9d17e4342598 | 709 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 710 | suites->suites[idx++] = TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256; |
wolfSSL | 0:9d17e4342598 | 711 | } |
wolfSSL | 0:9d17e4342598 | 712 | #endif |
wolfSSL | 0:9d17e4342598 | 713 | |
wolfSSL | 0:9d17e4342598 | 714 | #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 |
wolfSSL | 0:9d17e4342598 | 715 | if (tls1_2 && haveRSAsig) { |
wolfSSL | 0:9d17e4342598 | 716 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 717 | suites->suites[idx++] = TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384; |
wolfSSL | 0:9d17e4342598 | 718 | } |
wolfSSL | 0:9d17e4342598 | 719 | #endif |
wolfSSL | 0:9d17e4342598 | 720 | |
wolfSSL | 0:9d17e4342598 | 721 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 |
wolfSSL | 0:9d17e4342598 | 722 | if (tls1_2 && haveECDSAsig) { |
wolfSSL | 0:9d17e4342598 | 723 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 724 | suites->suites[idx++] = TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384; |
wolfSSL | 0:9d17e4342598 | 725 | } |
wolfSSL | 0:9d17e4342598 | 726 | #endif |
wolfSSL | 0:9d17e4342598 | 727 | |
wolfSSL | 0:9d17e4342598 | 728 | #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 |
wolfSSL | 0:9d17e4342598 | 729 | if (tls1_2 && haveRSAsig && haveStaticECC) { |
wolfSSL | 0:9d17e4342598 | 730 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 731 | suites->suites[idx++] = TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384; |
wolfSSL | 0:9d17e4342598 | 732 | } |
wolfSSL | 0:9d17e4342598 | 733 | #endif |
wolfSSL | 0:9d17e4342598 | 734 | |
wolfSSL | 0:9d17e4342598 | 735 | #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 |
wolfSSL | 0:9d17e4342598 | 736 | if (tls1_2 && haveECDSAsig && haveStaticECC) { |
wolfSSL | 0:9d17e4342598 | 737 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 738 | suites->suites[idx++] = TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384; |
wolfSSL | 0:9d17e4342598 | 739 | } |
wolfSSL | 0:9d17e4342598 | 740 | #endif |
wolfSSL | 0:9d17e4342598 | 741 | |
wolfSSL | 0:9d17e4342598 | 742 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 |
wolfSSL | 0:9d17e4342598 | 743 | if (tls1_2 && haveECDSAsig) { |
wolfSSL | 0:9d17e4342598 | 744 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 745 | suites->suites[idx++] = TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384; |
wolfSSL | 0:9d17e4342598 | 746 | } |
wolfSSL | 0:9d17e4342598 | 747 | #endif |
wolfSSL | 0:9d17e4342598 | 748 | |
wolfSSL | 0:9d17e4342598 | 749 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 750 | if (tls && haveECDSAsig) { |
wolfSSL | 0:9d17e4342598 | 751 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 752 | suites->suites[idx++] = TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA; |
wolfSSL | 0:9d17e4342598 | 753 | } |
wolfSSL | 0:9d17e4342598 | 754 | #endif |
wolfSSL | 0:9d17e4342598 | 755 | |
wolfSSL | 0:9d17e4342598 | 756 | #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 |
wolfSSL | 0:9d17e4342598 | 757 | if (tls1_2 && haveECDSAsig && haveStaticECC) { |
wolfSSL | 0:9d17e4342598 | 758 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 759 | suites->suites[idx++] = TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384; |
wolfSSL | 0:9d17e4342598 | 760 | } |
wolfSSL | 0:9d17e4342598 | 761 | #endif |
wolfSSL | 0:9d17e4342598 | 762 | |
wolfSSL | 0:9d17e4342598 | 763 | #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 764 | if (tls && haveECDSAsig && haveStaticECC) { |
wolfSSL | 0:9d17e4342598 | 765 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 766 | suites->suites[idx++] = TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA; |
wolfSSL | 0:9d17e4342598 | 767 | } |
wolfSSL | 0:9d17e4342598 | 768 | #endif |
wolfSSL | 0:9d17e4342598 | 769 | |
wolfSSL | 0:9d17e4342598 | 770 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 |
wolfSSL | 0:9d17e4342598 | 771 | if (tls1_2 && haveECDSAsig) { |
wolfSSL | 0:9d17e4342598 | 772 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 773 | suites->suites[idx++] = TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256; |
wolfSSL | 0:9d17e4342598 | 774 | } |
wolfSSL | 0:9d17e4342598 | 775 | #endif |
wolfSSL | 0:9d17e4342598 | 776 | |
wolfSSL | 0:9d17e4342598 | 777 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 778 | if (tls && haveECDSAsig) { |
wolfSSL | 0:9d17e4342598 | 779 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 780 | suites->suites[idx++] = TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA; |
wolfSSL | 0:9d17e4342598 | 781 | } |
wolfSSL | 0:9d17e4342598 | 782 | #endif |
wolfSSL | 0:9d17e4342598 | 783 | |
wolfSSL | 0:9d17e4342598 | 784 | #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 |
wolfSSL | 0:9d17e4342598 | 785 | if (tls1_2 && haveECDSAsig && haveStaticECC) { |
wolfSSL | 0:9d17e4342598 | 786 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 787 | suites->suites[idx++] = TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256; |
wolfSSL | 0:9d17e4342598 | 788 | } |
wolfSSL | 0:9d17e4342598 | 789 | #endif |
wolfSSL | 0:9d17e4342598 | 790 | |
wolfSSL | 0:9d17e4342598 | 791 | #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 792 | if (tls && haveECDSAsig && haveStaticECC) { |
wolfSSL | 0:9d17e4342598 | 793 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 794 | suites->suites[idx++] = TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA; |
wolfSSL | 0:9d17e4342598 | 795 | } |
wolfSSL | 0:9d17e4342598 | 796 | #endif |
wolfSSL | 0:9d17e4342598 | 797 | |
wolfSSL | 0:9d17e4342598 | 798 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA |
wolfSSL | 0:9d17e4342598 | 799 | if (tls && haveECDSAsig) { |
wolfSSL | 0:9d17e4342598 | 800 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 801 | suites->suites[idx++] = TLS_ECDHE_ECDSA_WITH_RC4_128_SHA; |
wolfSSL | 0:9d17e4342598 | 802 | } |
wolfSSL | 0:9d17e4342598 | 803 | #endif |
wolfSSL | 0:9d17e4342598 | 804 | |
wolfSSL | 0:9d17e4342598 | 805 | #ifdef BUILD_TLS_ECDH_ECDSA_WITH_RC4_128_SHA |
wolfSSL | 0:9d17e4342598 | 806 | if (tls && haveECDSAsig && haveStaticECC) { |
wolfSSL | 0:9d17e4342598 | 807 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 808 | suites->suites[idx++] = TLS_ECDH_ECDSA_WITH_RC4_128_SHA; |
wolfSSL | 0:9d17e4342598 | 809 | } |
wolfSSL | 0:9d17e4342598 | 810 | #endif |
wolfSSL | 0:9d17e4342598 | 811 | |
wolfSSL | 0:9d17e4342598 | 812 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 813 | if (tls && haveECDSAsig) { |
wolfSSL | 0:9d17e4342598 | 814 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 815 | suites->suites[idx++] = TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA; |
wolfSSL | 0:9d17e4342598 | 816 | } |
wolfSSL | 0:9d17e4342598 | 817 | #endif |
wolfSSL | 0:9d17e4342598 | 818 | |
wolfSSL | 0:9d17e4342598 | 819 | #ifdef BUILD_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 820 | if (tls && haveECDSAsig && haveStaticECC) { |
wolfSSL | 0:9d17e4342598 | 821 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 822 | suites->suites[idx++] = TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA; |
wolfSSL | 0:9d17e4342598 | 823 | } |
wolfSSL | 0:9d17e4342598 | 824 | #endif |
wolfSSL | 0:9d17e4342598 | 825 | |
wolfSSL | 0:9d17e4342598 | 826 | #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 |
wolfSSL | 0:9d17e4342598 | 827 | if (tls1_2 && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 828 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 829 | suites->suites[idx++] = TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384; |
wolfSSL | 0:9d17e4342598 | 830 | } |
wolfSSL | 0:9d17e4342598 | 831 | #endif |
wolfSSL | 0:9d17e4342598 | 832 | |
wolfSSL | 0:9d17e4342598 | 833 | #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 834 | if (tls && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 835 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 836 | suites->suites[idx++] = TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA; |
wolfSSL | 0:9d17e4342598 | 837 | } |
wolfSSL | 0:9d17e4342598 | 838 | #endif |
wolfSSL | 0:9d17e4342598 | 839 | |
wolfSSL | 0:9d17e4342598 | 840 | #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 |
wolfSSL | 0:9d17e4342598 | 841 | if (tls1_2 && haveRSAsig && haveStaticECC) { |
wolfSSL | 0:9d17e4342598 | 842 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 843 | suites->suites[idx++] = TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384; |
wolfSSL | 0:9d17e4342598 | 844 | } |
wolfSSL | 0:9d17e4342598 | 845 | #endif |
wolfSSL | 0:9d17e4342598 | 846 | |
wolfSSL | 0:9d17e4342598 | 847 | #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 848 | if (tls && haveRSAsig && haveStaticECC) { |
wolfSSL | 0:9d17e4342598 | 849 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 850 | suites->suites[idx++] = TLS_ECDH_RSA_WITH_AES_256_CBC_SHA; |
wolfSSL | 0:9d17e4342598 | 851 | } |
wolfSSL | 0:9d17e4342598 | 852 | #endif |
wolfSSL | 0:9d17e4342598 | 853 | |
wolfSSL | 0:9d17e4342598 | 854 | #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 |
wolfSSL | 0:9d17e4342598 | 855 | if (tls1_2 && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 856 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 857 | suites->suites[idx++] = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256; |
wolfSSL | 0:9d17e4342598 | 858 | } |
wolfSSL | 0:9d17e4342598 | 859 | #endif |
wolfSSL | 0:9d17e4342598 | 860 | |
wolfSSL | 0:9d17e4342598 | 861 | #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 862 | if (tls && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 863 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 864 | suites->suites[idx++] = TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA; |
wolfSSL | 0:9d17e4342598 | 865 | } |
wolfSSL | 0:9d17e4342598 | 866 | #endif |
wolfSSL | 0:9d17e4342598 | 867 | |
wolfSSL | 0:9d17e4342598 | 868 | #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 |
wolfSSL | 0:9d17e4342598 | 869 | if (tls1_2 && haveRSAsig && haveStaticECC) { |
wolfSSL | 0:9d17e4342598 | 870 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 871 | suites->suites[idx++] = TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256; |
wolfSSL | 0:9d17e4342598 | 872 | } |
wolfSSL | 0:9d17e4342598 | 873 | #endif |
wolfSSL | 0:9d17e4342598 | 874 | |
wolfSSL | 0:9d17e4342598 | 875 | #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 876 | if (tls && haveRSAsig && haveStaticECC) { |
wolfSSL | 0:9d17e4342598 | 877 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 878 | suites->suites[idx++] = TLS_ECDH_RSA_WITH_AES_128_CBC_SHA; |
wolfSSL | 0:9d17e4342598 | 879 | } |
wolfSSL | 0:9d17e4342598 | 880 | #endif |
wolfSSL | 0:9d17e4342598 | 881 | |
wolfSSL | 0:9d17e4342598 | 882 | #ifdef BUILD_TLS_ECDHE_RSA_WITH_RC4_128_SHA |
wolfSSL | 0:9d17e4342598 | 883 | if (tls && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 884 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 885 | suites->suites[idx++] = TLS_ECDHE_RSA_WITH_RC4_128_SHA; |
wolfSSL | 0:9d17e4342598 | 886 | } |
wolfSSL | 0:9d17e4342598 | 887 | #endif |
wolfSSL | 0:9d17e4342598 | 888 | |
wolfSSL | 0:9d17e4342598 | 889 | #ifdef BUILD_TLS_ECDH_RSA_WITH_RC4_128_SHA |
wolfSSL | 0:9d17e4342598 | 890 | if (tls && haveRSAsig && haveStaticECC) { |
wolfSSL | 0:9d17e4342598 | 891 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 892 | suites->suites[idx++] = TLS_ECDH_RSA_WITH_RC4_128_SHA; |
wolfSSL | 0:9d17e4342598 | 893 | } |
wolfSSL | 0:9d17e4342598 | 894 | #endif |
wolfSSL | 0:9d17e4342598 | 895 | |
wolfSSL | 0:9d17e4342598 | 896 | #ifdef BUILD_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 897 | if (tls && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 898 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 899 | suites->suites[idx++] = TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA; |
wolfSSL | 0:9d17e4342598 | 900 | } |
wolfSSL | 0:9d17e4342598 | 901 | #endif |
wolfSSL | 0:9d17e4342598 | 902 | |
wolfSSL | 0:9d17e4342598 | 903 | #ifdef BUILD_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 904 | if (tls && haveRSAsig && haveStaticECC) { |
wolfSSL | 0:9d17e4342598 | 905 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 906 | suites->suites[idx++] = TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA; |
wolfSSL | 0:9d17e4342598 | 907 | } |
wolfSSL | 0:9d17e4342598 | 908 | #endif |
wolfSSL | 0:9d17e4342598 | 909 | |
wolfSSL | 0:9d17e4342598 | 910 | #ifdef BUILD_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 |
wolfSSL | 0:9d17e4342598 | 911 | if (tls1_2 && haveDH && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 912 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 913 | suites->suites[idx++] = TLS_DHE_RSA_WITH_AES_256_GCM_SHA384; |
wolfSSL | 0:9d17e4342598 | 914 | } |
wolfSSL | 0:9d17e4342598 | 915 | #endif |
wolfSSL | 0:9d17e4342598 | 916 | |
wolfSSL | 0:9d17e4342598 | 917 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 |
wolfSSL | 0:9d17e4342598 | 918 | if (tls1_2 && haveECDSAsig) { |
wolfSSL | 0:9d17e4342598 | 919 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 920 | suites->suites[idx++] = TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8; |
wolfSSL | 0:9d17e4342598 | 921 | } |
wolfSSL | 0:9d17e4342598 | 922 | #endif |
wolfSSL | 0:9d17e4342598 | 923 | |
wolfSSL | 0:9d17e4342598 | 924 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 |
wolfSSL | 0:9d17e4342598 | 925 | if (tls1_2 && haveECDSAsig) { |
wolfSSL | 0:9d17e4342598 | 926 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 927 | suites->suites[idx++] = TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8; |
wolfSSL | 0:9d17e4342598 | 928 | } |
wolfSSL | 0:9d17e4342598 | 929 | #endif |
wolfSSL | 0:9d17e4342598 | 930 | |
wolfSSL | 0:9d17e4342598 | 931 | #ifdef BUILD_TLS_RSA_WITH_AES_128_CCM_8 |
wolfSSL | 0:9d17e4342598 | 932 | if (tls1_2 && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 933 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 934 | suites->suites[idx++] = TLS_RSA_WITH_AES_128_CCM_8; |
wolfSSL | 0:9d17e4342598 | 935 | } |
wolfSSL | 0:9d17e4342598 | 936 | #endif |
wolfSSL | 0:9d17e4342598 | 937 | |
wolfSSL | 0:9d17e4342598 | 938 | #ifdef BUILD_TLS_RSA_WITH_AES_256_CCM_8 |
wolfSSL | 0:9d17e4342598 | 939 | if (tls1_2 && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 940 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 941 | suites->suites[idx++] = TLS_RSA_WITH_AES_256_CCM_8; |
wolfSSL | 0:9d17e4342598 | 942 | } |
wolfSSL | 0:9d17e4342598 | 943 | #endif |
wolfSSL | 0:9d17e4342598 | 944 | |
wolfSSL | 0:9d17e4342598 | 945 | #ifdef BUILD_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 946 | if (tls1_2 && haveDH && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 947 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 948 | suites->suites[idx++] = TLS_DHE_RSA_WITH_AES_256_CBC_SHA256; |
wolfSSL | 0:9d17e4342598 | 949 | } |
wolfSSL | 0:9d17e4342598 | 950 | #endif |
wolfSSL | 0:9d17e4342598 | 951 | |
wolfSSL | 0:9d17e4342598 | 952 | #ifdef BUILD_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 |
wolfSSL | 0:9d17e4342598 | 953 | if (tls1_2 && haveDH && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 954 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 955 | suites->suites[idx++] = TLS_DHE_RSA_WITH_AES_128_GCM_SHA256; |
wolfSSL | 0:9d17e4342598 | 956 | } |
wolfSSL | 0:9d17e4342598 | 957 | #endif |
wolfSSL | 0:9d17e4342598 | 958 | |
wolfSSL | 0:9d17e4342598 | 959 | #ifdef BUILD_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 960 | if (tls1_2 && haveDH && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 961 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 962 | suites->suites[idx++] = TLS_DHE_RSA_WITH_AES_128_CBC_SHA256; |
wolfSSL | 0:9d17e4342598 | 963 | } |
wolfSSL | 0:9d17e4342598 | 964 | #endif |
wolfSSL | 0:9d17e4342598 | 965 | |
wolfSSL | 0:9d17e4342598 | 966 | #ifdef BUILD_TLS_DHE_RSA_WITH_AES_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 967 | if (tls && haveDH && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 968 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 969 | suites->suites[idx++] = TLS_DHE_RSA_WITH_AES_256_CBC_SHA; |
wolfSSL | 0:9d17e4342598 | 970 | } |
wolfSSL | 0:9d17e4342598 | 971 | #endif |
wolfSSL | 0:9d17e4342598 | 972 | |
wolfSSL | 0:9d17e4342598 | 973 | #ifdef BUILD_TLS_DHE_RSA_WITH_AES_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 974 | if (tls && haveDH && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 975 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 976 | suites->suites[idx++] = TLS_DHE_RSA_WITH_AES_128_CBC_SHA; |
wolfSSL | 0:9d17e4342598 | 977 | } |
wolfSSL | 0:9d17e4342598 | 978 | #endif |
wolfSSL | 0:9d17e4342598 | 979 | |
wolfSSL | 0:9d17e4342598 | 980 | #ifdef BUILD_TLS_RSA_WITH_AES_256_GCM_SHA384 |
wolfSSL | 0:9d17e4342598 | 981 | if (tls1_2 && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 982 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 983 | suites->suites[idx++] = TLS_RSA_WITH_AES_256_GCM_SHA384; |
wolfSSL | 0:9d17e4342598 | 984 | } |
wolfSSL | 0:9d17e4342598 | 985 | #endif |
wolfSSL | 0:9d17e4342598 | 986 | |
wolfSSL | 0:9d17e4342598 | 987 | #ifdef BUILD_TLS_RSA_WITH_AES_256_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 988 | if (tls1_2 && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 989 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 990 | suites->suites[idx++] = TLS_RSA_WITH_AES_256_CBC_SHA256; |
wolfSSL | 0:9d17e4342598 | 991 | } |
wolfSSL | 0:9d17e4342598 | 992 | #endif |
wolfSSL | 0:9d17e4342598 | 993 | |
wolfSSL | 0:9d17e4342598 | 994 | #ifdef BUILD_TLS_RSA_WITH_AES_128_GCM_SHA256 |
wolfSSL | 0:9d17e4342598 | 995 | if (tls1_2 && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 996 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 997 | suites->suites[idx++] = TLS_RSA_WITH_AES_128_GCM_SHA256; |
wolfSSL | 0:9d17e4342598 | 998 | } |
wolfSSL | 0:9d17e4342598 | 999 | #endif |
wolfSSL | 0:9d17e4342598 | 1000 | |
wolfSSL | 0:9d17e4342598 | 1001 | #ifdef BUILD_TLS_RSA_WITH_AES_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 1002 | if (tls1_2 && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 1003 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 1004 | suites->suites[idx++] = TLS_RSA_WITH_AES_128_CBC_SHA256; |
wolfSSL | 0:9d17e4342598 | 1005 | } |
wolfSSL | 0:9d17e4342598 | 1006 | #endif |
wolfSSL | 0:9d17e4342598 | 1007 | |
wolfSSL | 0:9d17e4342598 | 1008 | #ifdef BUILD_TLS_RSA_WITH_AES_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 1009 | if (tls && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 1010 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 1011 | suites->suites[idx++] = TLS_RSA_WITH_AES_256_CBC_SHA; |
wolfSSL | 0:9d17e4342598 | 1012 | } |
wolfSSL | 0:9d17e4342598 | 1013 | #endif |
wolfSSL | 0:9d17e4342598 | 1014 | |
wolfSSL | 0:9d17e4342598 | 1015 | #ifdef BUILD_TLS_RSA_WITH_AES_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 1016 | if (tls && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 1017 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 1018 | suites->suites[idx++] = TLS_RSA_WITH_AES_128_CBC_SHA; |
wolfSSL | 0:9d17e4342598 | 1019 | } |
wolfSSL | 0:9d17e4342598 | 1020 | #endif |
wolfSSL | 0:9d17e4342598 | 1021 | |
wolfSSL | 0:9d17e4342598 | 1022 | #ifdef BUILD_TLS_RSA_WITH_NULL_SHA |
wolfSSL | 0:9d17e4342598 | 1023 | if (tls && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 1024 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 1025 | suites->suites[idx++] = TLS_RSA_WITH_NULL_SHA; |
wolfSSL | 0:9d17e4342598 | 1026 | } |
wolfSSL | 0:9d17e4342598 | 1027 | #endif |
wolfSSL | 0:9d17e4342598 | 1028 | |
wolfSSL | 0:9d17e4342598 | 1029 | #ifdef BUILD_TLS_RSA_WITH_NULL_SHA256 |
wolfSSL | 0:9d17e4342598 | 1030 | if (tls && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 1031 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 1032 | suites->suites[idx++] = TLS_RSA_WITH_NULL_SHA256; |
wolfSSL | 0:9d17e4342598 | 1033 | } |
wolfSSL | 0:9d17e4342598 | 1034 | #endif |
wolfSSL | 0:9d17e4342598 | 1035 | |
wolfSSL | 0:9d17e4342598 | 1036 | #ifdef BUILD_TLS_PSK_WITH_AES_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 1037 | if (tls && havePSK) { |
wolfSSL | 0:9d17e4342598 | 1038 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 1039 | suites->suites[idx++] = TLS_PSK_WITH_AES_256_CBC_SHA; |
wolfSSL | 0:9d17e4342598 | 1040 | } |
wolfSSL | 0:9d17e4342598 | 1041 | #endif |
wolfSSL | 0:9d17e4342598 | 1042 | |
wolfSSL | 0:9d17e4342598 | 1043 | #ifdef BUILD_TLS_PSK_WITH_AES_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 1044 | if (tls && havePSK) { |
wolfSSL | 0:9d17e4342598 | 1045 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 1046 | suites->suites[idx++] = TLS_PSK_WITH_AES_128_CBC_SHA256; |
wolfSSL | 0:9d17e4342598 | 1047 | } |
wolfSSL | 0:9d17e4342598 | 1048 | #endif |
wolfSSL | 0:9d17e4342598 | 1049 | |
wolfSSL | 0:9d17e4342598 | 1050 | #ifdef BUILD_TLS_PSK_WITH_AES_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 1051 | if (tls && havePSK) { |
wolfSSL | 0:9d17e4342598 | 1052 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 1053 | suites->suites[idx++] = TLS_PSK_WITH_AES_128_CBC_SHA; |
wolfSSL | 0:9d17e4342598 | 1054 | } |
wolfSSL | 0:9d17e4342598 | 1055 | #endif |
wolfSSL | 0:9d17e4342598 | 1056 | |
wolfSSL | 0:9d17e4342598 | 1057 | #ifdef BUILD_TLS_PSK_WITH_AES_128_CCM_8 |
wolfSSL | 0:9d17e4342598 | 1058 | if (tls && havePSK) { |
wolfSSL | 0:9d17e4342598 | 1059 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 1060 | suites->suites[idx++] = TLS_PSK_WITH_AES_128_CCM_8; |
wolfSSL | 0:9d17e4342598 | 1061 | } |
wolfSSL | 0:9d17e4342598 | 1062 | #endif |
wolfSSL | 0:9d17e4342598 | 1063 | |
wolfSSL | 0:9d17e4342598 | 1064 | #ifdef BUILD_TLS_PSK_WITH_AES_256_CCM_8 |
wolfSSL | 0:9d17e4342598 | 1065 | if (tls && havePSK) { |
wolfSSL | 0:9d17e4342598 | 1066 | suites->suites[idx++] = ECC_BYTE; |
wolfSSL | 0:9d17e4342598 | 1067 | suites->suites[idx++] = TLS_PSK_WITH_AES_256_CCM_8; |
wolfSSL | 0:9d17e4342598 | 1068 | } |
wolfSSL | 0:9d17e4342598 | 1069 | #endif |
wolfSSL | 0:9d17e4342598 | 1070 | |
wolfSSL | 0:9d17e4342598 | 1071 | #ifdef BUILD_TLS_PSK_WITH_NULL_SHA256 |
wolfSSL | 0:9d17e4342598 | 1072 | if (tls && havePSK) { |
wolfSSL | 0:9d17e4342598 | 1073 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 1074 | suites->suites[idx++] = TLS_PSK_WITH_NULL_SHA256; |
wolfSSL | 0:9d17e4342598 | 1075 | } |
wolfSSL | 0:9d17e4342598 | 1076 | #endif |
wolfSSL | 0:9d17e4342598 | 1077 | |
wolfSSL | 0:9d17e4342598 | 1078 | #ifdef BUILD_TLS_PSK_WITH_NULL_SHA |
wolfSSL | 0:9d17e4342598 | 1079 | if (tls && havePSK) { |
wolfSSL | 0:9d17e4342598 | 1080 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 1081 | suites->suites[idx++] = TLS_PSK_WITH_NULL_SHA; |
wolfSSL | 0:9d17e4342598 | 1082 | } |
wolfSSL | 0:9d17e4342598 | 1083 | #endif |
wolfSSL | 0:9d17e4342598 | 1084 | |
wolfSSL | 0:9d17e4342598 | 1085 | #ifdef BUILD_SSL_RSA_WITH_RC4_128_SHA |
wolfSSL | 0:9d17e4342598 | 1086 | if (haveRSA ) { |
wolfSSL | 0:9d17e4342598 | 1087 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 1088 | suites->suites[idx++] = SSL_RSA_WITH_RC4_128_SHA; |
wolfSSL | 0:9d17e4342598 | 1089 | } |
wolfSSL | 0:9d17e4342598 | 1090 | #endif |
wolfSSL | 0:9d17e4342598 | 1091 | |
wolfSSL | 0:9d17e4342598 | 1092 | #ifdef BUILD_SSL_RSA_WITH_RC4_128_MD5 |
wolfSSL | 0:9d17e4342598 | 1093 | if (haveRSA ) { |
wolfSSL | 0:9d17e4342598 | 1094 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 1095 | suites->suites[idx++] = SSL_RSA_WITH_RC4_128_MD5; |
wolfSSL | 0:9d17e4342598 | 1096 | } |
wolfSSL | 0:9d17e4342598 | 1097 | #endif |
wolfSSL | 0:9d17e4342598 | 1098 | |
wolfSSL | 0:9d17e4342598 | 1099 | #ifdef BUILD_SSL_RSA_WITH_3DES_EDE_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 1100 | if (haveRSA ) { |
wolfSSL | 0:9d17e4342598 | 1101 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 1102 | suites->suites[idx++] = SSL_RSA_WITH_3DES_EDE_CBC_SHA; |
wolfSSL | 0:9d17e4342598 | 1103 | } |
wolfSSL | 0:9d17e4342598 | 1104 | #endif |
wolfSSL | 0:9d17e4342598 | 1105 | |
wolfSSL | 0:9d17e4342598 | 1106 | #ifdef BUILD_TLS_RSA_WITH_HC_128_MD5 |
wolfSSL | 0:9d17e4342598 | 1107 | if (tls && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 1108 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 1109 | suites->suites[idx++] = TLS_RSA_WITH_HC_128_MD5; |
wolfSSL | 0:9d17e4342598 | 1110 | } |
wolfSSL | 0:9d17e4342598 | 1111 | #endif |
wolfSSL | 0:9d17e4342598 | 1112 | |
wolfSSL | 0:9d17e4342598 | 1113 | #ifdef BUILD_TLS_RSA_WITH_HC_128_SHA |
wolfSSL | 0:9d17e4342598 | 1114 | if (tls && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 1115 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 1116 | suites->suites[idx++] = TLS_RSA_WITH_HC_128_SHA; |
wolfSSL | 0:9d17e4342598 | 1117 | } |
wolfSSL | 0:9d17e4342598 | 1118 | #endif |
wolfSSL | 0:9d17e4342598 | 1119 | |
wolfSSL | 0:9d17e4342598 | 1120 | #ifdef BUILD_TLS_RSA_WITH_HC_128_B2B256 |
wolfSSL | 0:9d17e4342598 | 1121 | if (tls && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 1122 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 1123 | suites->suites[idx++] = TLS_RSA_WITH_HC_128_B2B256; |
wolfSSL | 0:9d17e4342598 | 1124 | } |
wolfSSL | 0:9d17e4342598 | 1125 | #endif |
wolfSSL | 0:9d17e4342598 | 1126 | |
wolfSSL | 0:9d17e4342598 | 1127 | #ifdef BUILD_TLS_RSA_WITH_AES_128_CBC_B2B256 |
wolfSSL | 0:9d17e4342598 | 1128 | if (tls && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 1129 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 1130 | suites->suites[idx++] = TLS_RSA_WITH_AES_128_CBC_B2B256; |
wolfSSL | 0:9d17e4342598 | 1131 | } |
wolfSSL | 0:9d17e4342598 | 1132 | #endif |
wolfSSL | 0:9d17e4342598 | 1133 | |
wolfSSL | 0:9d17e4342598 | 1134 | #ifdef BUILD_TLS_RSA_WITH_AES_256_CBC_B2B256 |
wolfSSL | 0:9d17e4342598 | 1135 | if (tls && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 1136 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 1137 | suites->suites[idx++] = TLS_RSA_WITH_AES_256_CBC_B2B256; |
wolfSSL | 0:9d17e4342598 | 1138 | } |
wolfSSL | 0:9d17e4342598 | 1139 | #endif |
wolfSSL | 0:9d17e4342598 | 1140 | |
wolfSSL | 0:9d17e4342598 | 1141 | #ifdef BUILD_TLS_RSA_WITH_RABBIT_SHA |
wolfSSL | 0:9d17e4342598 | 1142 | if (tls && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 1143 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 1144 | suites->suites[idx++] = TLS_RSA_WITH_RABBIT_SHA; |
wolfSSL | 0:9d17e4342598 | 1145 | } |
wolfSSL | 0:9d17e4342598 | 1146 | #endif |
wolfSSL | 0:9d17e4342598 | 1147 | |
wolfSSL | 0:9d17e4342598 | 1148 | #ifdef BUILD_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 1149 | if (tls && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 1150 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 1151 | suites->suites[idx++] = TLS_RSA_WITH_CAMELLIA_128_CBC_SHA; |
wolfSSL | 0:9d17e4342598 | 1152 | } |
wolfSSL | 0:9d17e4342598 | 1153 | #endif |
wolfSSL | 0:9d17e4342598 | 1154 | |
wolfSSL | 0:9d17e4342598 | 1155 | #ifdef BUILD_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 1156 | if (tls && haveDH && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 1157 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 1158 | suites->suites[idx++] = TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA; |
wolfSSL | 0:9d17e4342598 | 1159 | } |
wolfSSL | 0:9d17e4342598 | 1160 | #endif |
wolfSSL | 0:9d17e4342598 | 1161 | |
wolfSSL | 0:9d17e4342598 | 1162 | #ifdef BUILD_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 1163 | if (tls && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 1164 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 1165 | suites->suites[idx++] = TLS_RSA_WITH_CAMELLIA_256_CBC_SHA; |
wolfSSL | 0:9d17e4342598 | 1166 | } |
wolfSSL | 0:9d17e4342598 | 1167 | #endif |
wolfSSL | 0:9d17e4342598 | 1168 | |
wolfSSL | 0:9d17e4342598 | 1169 | #ifdef BUILD_TLS_DHE_WITH_RSA_CAMELLIA_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 1170 | if (tls && haveDH && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 1171 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 1172 | suites->suites[idx++] = TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA; |
wolfSSL | 0:9d17e4342598 | 1173 | } |
wolfSSL | 0:9d17e4342598 | 1174 | #endif |
wolfSSL | 0:9d17e4342598 | 1175 | |
wolfSSL | 0:9d17e4342598 | 1176 | #ifdef BUILD_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 1177 | if (tls && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 1178 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 1179 | suites->suites[idx++] = TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256; |
wolfSSL | 0:9d17e4342598 | 1180 | } |
wolfSSL | 0:9d17e4342598 | 1181 | #endif |
wolfSSL | 0:9d17e4342598 | 1182 | |
wolfSSL | 0:9d17e4342598 | 1183 | #ifdef BUILD_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 1184 | if (tls && haveDH && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 1185 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 1186 | suites->suites[idx++] = TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256; |
wolfSSL | 0:9d17e4342598 | 1187 | } |
wolfSSL | 0:9d17e4342598 | 1188 | #endif |
wolfSSL | 0:9d17e4342598 | 1189 | |
wolfSSL | 0:9d17e4342598 | 1190 | #ifdef BUILD_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 1191 | if (tls && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 1192 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 1193 | suites->suites[idx++] = TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256; |
wolfSSL | 0:9d17e4342598 | 1194 | } |
wolfSSL | 0:9d17e4342598 | 1195 | #endif |
wolfSSL | 0:9d17e4342598 | 1196 | |
wolfSSL | 0:9d17e4342598 | 1197 | #ifdef BUILD_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 1198 | if (tls && haveDH && haveRSA) { |
wolfSSL | 0:9d17e4342598 | 1199 | suites->suites[idx++] = 0; |
wolfSSL | 0:9d17e4342598 | 1200 | suites->suites[idx++] = TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256; |
wolfSSL | 0:9d17e4342598 | 1201 | } |
wolfSSL | 0:9d17e4342598 | 1202 | #endif |
wolfSSL | 0:9d17e4342598 | 1203 | |
wolfSSL | 0:9d17e4342598 | 1204 | suites->suiteSz = idx; |
wolfSSL | 0:9d17e4342598 | 1205 | |
wolfSSL | 0:9d17e4342598 | 1206 | { |
wolfSSL | 0:9d17e4342598 | 1207 | idx = 0; |
wolfSSL | 0:9d17e4342598 | 1208 | |
wolfSSL | 0:9d17e4342598 | 1209 | if (haveECDSAsig) { |
wolfSSL | 0:9d17e4342598 | 1210 | #ifdef CYASSL_SHA384 |
wolfSSL | 0:9d17e4342598 | 1211 | suites->hashSigAlgo[idx++] = sha384_mac; |
wolfSSL | 0:9d17e4342598 | 1212 | suites->hashSigAlgo[idx++] = ecc_dsa_sa_algo; |
wolfSSL | 0:9d17e4342598 | 1213 | #endif |
wolfSSL | 0:9d17e4342598 | 1214 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 1215 | suites->hashSigAlgo[idx++] = sha256_mac; |
wolfSSL | 0:9d17e4342598 | 1216 | suites->hashSigAlgo[idx++] = ecc_dsa_sa_algo; |
wolfSSL | 0:9d17e4342598 | 1217 | #endif |
wolfSSL | 0:9d17e4342598 | 1218 | #ifndef NO_SHA |
wolfSSL | 0:9d17e4342598 | 1219 | suites->hashSigAlgo[idx++] = sha_mac; |
wolfSSL | 0:9d17e4342598 | 1220 | suites->hashSigAlgo[idx++] = ecc_dsa_sa_algo; |
wolfSSL | 0:9d17e4342598 | 1221 | #endif |
wolfSSL | 0:9d17e4342598 | 1222 | } |
wolfSSL | 0:9d17e4342598 | 1223 | |
wolfSSL | 0:9d17e4342598 | 1224 | if (haveRSAsig) { |
wolfSSL | 0:9d17e4342598 | 1225 | #ifdef CYASSL_SHA384 |
wolfSSL | 0:9d17e4342598 | 1226 | suites->hashSigAlgo[idx++] = sha384_mac; |
wolfSSL | 0:9d17e4342598 | 1227 | suites->hashSigAlgo[idx++] = rsa_sa_algo; |
wolfSSL | 0:9d17e4342598 | 1228 | #endif |
wolfSSL | 0:9d17e4342598 | 1229 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 1230 | suites->hashSigAlgo[idx++] = sha256_mac; |
wolfSSL | 0:9d17e4342598 | 1231 | suites->hashSigAlgo[idx++] = rsa_sa_algo; |
wolfSSL | 0:9d17e4342598 | 1232 | #endif |
wolfSSL | 0:9d17e4342598 | 1233 | #ifndef NO_SHA |
wolfSSL | 0:9d17e4342598 | 1234 | suites->hashSigAlgo[idx++] = sha_mac; |
wolfSSL | 0:9d17e4342598 | 1235 | suites->hashSigAlgo[idx++] = rsa_sa_algo; |
wolfSSL | 0:9d17e4342598 | 1236 | #endif |
wolfSSL | 0:9d17e4342598 | 1237 | } |
wolfSSL | 0:9d17e4342598 | 1238 | |
wolfSSL | 0:9d17e4342598 | 1239 | suites->hashSigAlgoSz = idx; |
wolfSSL | 0:9d17e4342598 | 1240 | } |
wolfSSL | 0:9d17e4342598 | 1241 | } |
wolfSSL | 0:9d17e4342598 | 1242 | |
wolfSSL | 0:9d17e4342598 | 1243 | |
wolfSSL | 0:9d17e4342598 | 1244 | #ifndef NO_CERTS |
wolfSSL | 0:9d17e4342598 | 1245 | |
wolfSSL | 0:9d17e4342598 | 1246 | |
wolfSSL | 0:9d17e4342598 | 1247 | void InitX509Name(CYASSL_X509_NAME* name, int dynamicFlag) |
wolfSSL | 0:9d17e4342598 | 1248 | { |
wolfSSL | 0:9d17e4342598 | 1249 | (void)dynamicFlag; |
wolfSSL | 0:9d17e4342598 | 1250 | |
wolfSSL | 0:9d17e4342598 | 1251 | if (name != NULL) { |
wolfSSL | 0:9d17e4342598 | 1252 | name->name = name->staticName; |
wolfSSL | 0:9d17e4342598 | 1253 | name->dynamicName = 0; |
wolfSSL | 0:9d17e4342598 | 1254 | #ifdef OPENSSL_EXTRA |
wolfSSL | 0:9d17e4342598 | 1255 | XMEMSET(&name->fullName, 0, sizeof(DecodedName)); |
wolfSSL | 0:9d17e4342598 | 1256 | #endif /* OPENSSL_EXTRA */ |
wolfSSL | 0:9d17e4342598 | 1257 | } |
wolfSSL | 0:9d17e4342598 | 1258 | } |
wolfSSL | 0:9d17e4342598 | 1259 | |
wolfSSL | 0:9d17e4342598 | 1260 | |
wolfSSL | 0:9d17e4342598 | 1261 | void FreeX509Name(CYASSL_X509_NAME* name) |
wolfSSL | 0:9d17e4342598 | 1262 | { |
wolfSSL | 0:9d17e4342598 | 1263 | if (name != NULL) { |
wolfSSL | 0:9d17e4342598 | 1264 | if (name->dynamicName) |
wolfSSL | 0:9d17e4342598 | 1265 | XFREE(name->name, NULL, DYNAMIC_TYPE_SUBJECT_CN); |
wolfSSL | 0:9d17e4342598 | 1266 | #ifdef OPENSSL_EXTRA |
wolfSSL | 0:9d17e4342598 | 1267 | if (name->fullName.fullName != NULL) |
wolfSSL | 0:9d17e4342598 | 1268 | XFREE(name->fullName.fullName, NULL, DYNAMIC_TYPE_X509); |
wolfSSL | 0:9d17e4342598 | 1269 | #endif /* OPENSSL_EXTRA */ |
wolfSSL | 0:9d17e4342598 | 1270 | } |
wolfSSL | 0:9d17e4342598 | 1271 | } |
wolfSSL | 0:9d17e4342598 | 1272 | |
wolfSSL | 0:9d17e4342598 | 1273 | |
wolfSSL | 0:9d17e4342598 | 1274 | /* Initialize CyaSSL X509 type */ |
wolfSSL | 0:9d17e4342598 | 1275 | void InitX509(CYASSL_X509* x509, int dynamicFlag) |
wolfSSL | 0:9d17e4342598 | 1276 | { |
wolfSSL | 0:9d17e4342598 | 1277 | InitX509Name(&x509->issuer, 0); |
wolfSSL | 0:9d17e4342598 | 1278 | InitX509Name(&x509->subject, 0); |
wolfSSL | 0:9d17e4342598 | 1279 | x509->version = 0; |
wolfSSL | 0:9d17e4342598 | 1280 | x509->pubKey.buffer = NULL; |
wolfSSL | 0:9d17e4342598 | 1281 | x509->sig.buffer = NULL; |
wolfSSL | 0:9d17e4342598 | 1282 | x509->derCert.buffer = NULL; |
wolfSSL | 0:9d17e4342598 | 1283 | x509->altNames = NULL; |
wolfSSL | 0:9d17e4342598 | 1284 | x509->altNamesNext = NULL; |
wolfSSL | 0:9d17e4342598 | 1285 | x509->dynamicMemory = (byte)dynamicFlag; |
wolfSSL | 0:9d17e4342598 | 1286 | x509->isCa = 0; |
wolfSSL | 0:9d17e4342598 | 1287 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 1288 | x509->pkCurveOID = 0; |
wolfSSL | 0:9d17e4342598 | 1289 | #endif /* HAVE_ECC */ |
wolfSSL | 0:9d17e4342598 | 1290 | #ifdef OPENSSL_EXTRA |
wolfSSL | 0:9d17e4342598 | 1291 | x509->pathLength = 0; |
wolfSSL | 0:9d17e4342598 | 1292 | x509->basicConstSet = 0; |
wolfSSL | 0:9d17e4342598 | 1293 | x509->basicConstCrit = 0; |
wolfSSL | 0:9d17e4342598 | 1294 | x509->basicConstPlSet = 0; |
wolfSSL | 0:9d17e4342598 | 1295 | x509->subjAltNameSet = 0; |
wolfSSL | 0:9d17e4342598 | 1296 | x509->subjAltNameCrit = 0; |
wolfSSL | 0:9d17e4342598 | 1297 | x509->authKeyIdSet = 0; |
wolfSSL | 0:9d17e4342598 | 1298 | x509->authKeyIdCrit = 0; |
wolfSSL | 0:9d17e4342598 | 1299 | x509->authKeyId = NULL; |
wolfSSL | 0:9d17e4342598 | 1300 | x509->authKeyIdSz = 0; |
wolfSSL | 0:9d17e4342598 | 1301 | x509->subjKeyIdSet = 0; |
wolfSSL | 0:9d17e4342598 | 1302 | x509->subjKeyIdCrit = 0; |
wolfSSL | 0:9d17e4342598 | 1303 | x509->subjKeyId = NULL; |
wolfSSL | 0:9d17e4342598 | 1304 | x509->subjKeyIdSz = 0; |
wolfSSL | 0:9d17e4342598 | 1305 | x509->keyUsageSet = 0; |
wolfSSL | 0:9d17e4342598 | 1306 | x509->keyUsageCrit = 0; |
wolfSSL | 0:9d17e4342598 | 1307 | x509->keyUsage = 0; |
wolfSSL | 0:9d17e4342598 | 1308 | #ifdef CYASSL_SEP |
wolfSSL | 0:9d17e4342598 | 1309 | x509->certPolicySet = 0; |
wolfSSL | 0:9d17e4342598 | 1310 | x509->certPolicyCrit = 0; |
wolfSSL | 0:9d17e4342598 | 1311 | #endif /* CYASSL_SEP */ |
wolfSSL | 0:9d17e4342598 | 1312 | #endif /* OPENSSL_EXTRA */ |
wolfSSL | 0:9d17e4342598 | 1313 | } |
wolfSSL | 0:9d17e4342598 | 1314 | |
wolfSSL | 0:9d17e4342598 | 1315 | |
wolfSSL | 0:9d17e4342598 | 1316 | /* Free CyaSSL X509 type */ |
wolfSSL | 0:9d17e4342598 | 1317 | void FreeX509(CYASSL_X509* x509) |
wolfSSL | 0:9d17e4342598 | 1318 | { |
wolfSSL | 0:9d17e4342598 | 1319 | if (x509 == NULL) |
wolfSSL | 0:9d17e4342598 | 1320 | return; |
wolfSSL | 0:9d17e4342598 | 1321 | |
wolfSSL | 0:9d17e4342598 | 1322 | FreeX509Name(&x509->issuer); |
wolfSSL | 0:9d17e4342598 | 1323 | FreeX509Name(&x509->subject); |
wolfSSL | 0:9d17e4342598 | 1324 | if (x509->pubKey.buffer) |
wolfSSL | 0:9d17e4342598 | 1325 | XFREE(x509->pubKey.buffer, NULL, DYNAMIC_TYPE_PUBLIC_KEY); |
wolfSSL | 0:9d17e4342598 | 1326 | XFREE(x509->derCert.buffer, NULL, DYNAMIC_TYPE_SUBJECT_CN); |
wolfSSL | 0:9d17e4342598 | 1327 | XFREE(x509->sig.buffer, NULL, DYNAMIC_TYPE_SIGNATURE); |
wolfSSL | 0:9d17e4342598 | 1328 | #ifdef OPENSSL_EXTRA |
wolfSSL | 0:9d17e4342598 | 1329 | XFREE(x509->authKeyId, NULL, 0); |
wolfSSL | 0:9d17e4342598 | 1330 | XFREE(x509->subjKeyId, NULL, 0); |
wolfSSL | 0:9d17e4342598 | 1331 | #endif /* OPENSSL_EXTRA */ |
wolfSSL | 0:9d17e4342598 | 1332 | if (x509->altNames) |
wolfSSL | 0:9d17e4342598 | 1333 | FreeAltNames(x509->altNames, NULL); |
wolfSSL | 0:9d17e4342598 | 1334 | if (x509->dynamicMemory) |
wolfSSL | 0:9d17e4342598 | 1335 | XFREE(x509, NULL, DYNAMIC_TYPE_X509); |
wolfSSL | 0:9d17e4342598 | 1336 | } |
wolfSSL | 0:9d17e4342598 | 1337 | |
wolfSSL | 0:9d17e4342598 | 1338 | #endif /* NO_CERTS */ |
wolfSSL | 0:9d17e4342598 | 1339 | |
wolfSSL | 0:9d17e4342598 | 1340 | |
wolfSSL | 0:9d17e4342598 | 1341 | /* init everything to 0, NULL, default values before calling anything that may |
wolfSSL | 0:9d17e4342598 | 1342 | fail so that desctructor has a "good" state to cleanup */ |
wolfSSL | 0:9d17e4342598 | 1343 | int InitSSL(CYASSL* ssl, CYASSL_CTX* ctx) |
wolfSSL | 0:9d17e4342598 | 1344 | { |
wolfSSL | 0:9d17e4342598 | 1345 | int ret; |
wolfSSL | 0:9d17e4342598 | 1346 | byte haveRSA = 0; |
wolfSSL | 0:9d17e4342598 | 1347 | byte havePSK = 0; |
wolfSSL | 0:9d17e4342598 | 1348 | |
wolfSSL | 0:9d17e4342598 | 1349 | ssl->ctx = ctx; /* only for passing to calls, options could change */ |
wolfSSL | 0:9d17e4342598 | 1350 | ssl->version = ctx->method->version; |
wolfSSL | 0:9d17e4342598 | 1351 | ssl->suites = NULL; |
wolfSSL | 0:9d17e4342598 | 1352 | |
wolfSSL | 0:9d17e4342598 | 1353 | #ifdef HAVE_LIBZ |
wolfSSL | 0:9d17e4342598 | 1354 | ssl->didStreamInit = 0; |
wolfSSL | 0:9d17e4342598 | 1355 | #endif |
wolfSSL | 0:9d17e4342598 | 1356 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 1357 | haveRSA = 1; |
wolfSSL | 0:9d17e4342598 | 1358 | #endif |
wolfSSL | 0:9d17e4342598 | 1359 | |
wolfSSL | 0:9d17e4342598 | 1360 | #ifndef NO_CERTS |
wolfSSL | 0:9d17e4342598 | 1361 | ssl->buffers.certificate.buffer = 0; |
wolfSSL | 0:9d17e4342598 | 1362 | ssl->buffers.key.buffer = 0; |
wolfSSL | 0:9d17e4342598 | 1363 | ssl->buffers.certChain.buffer = 0; |
wolfSSL | 0:9d17e4342598 | 1364 | #endif |
wolfSSL | 0:9d17e4342598 | 1365 | ssl->buffers.inputBuffer.length = 0; |
wolfSSL | 0:9d17e4342598 | 1366 | ssl->buffers.inputBuffer.idx = 0; |
wolfSSL | 0:9d17e4342598 | 1367 | ssl->buffers.inputBuffer.buffer = ssl->buffers.inputBuffer.staticBuffer; |
wolfSSL | 0:9d17e4342598 | 1368 | ssl->buffers.inputBuffer.bufferSize = STATIC_BUFFER_LEN; |
wolfSSL | 0:9d17e4342598 | 1369 | ssl->buffers.inputBuffer.dynamicFlag = 0; |
wolfSSL | 0:9d17e4342598 | 1370 | ssl->buffers.inputBuffer.offset = 0; |
wolfSSL | 0:9d17e4342598 | 1371 | ssl->buffers.outputBuffer.length = 0; |
wolfSSL | 0:9d17e4342598 | 1372 | ssl->buffers.outputBuffer.idx = 0; |
wolfSSL | 0:9d17e4342598 | 1373 | ssl->buffers.outputBuffer.buffer = ssl->buffers.outputBuffer.staticBuffer; |
wolfSSL | 0:9d17e4342598 | 1374 | ssl->buffers.outputBuffer.bufferSize = STATIC_BUFFER_LEN; |
wolfSSL | 0:9d17e4342598 | 1375 | ssl->buffers.outputBuffer.dynamicFlag = 0; |
wolfSSL | 0:9d17e4342598 | 1376 | ssl->buffers.outputBuffer.offset = 0; |
wolfSSL | 0:9d17e4342598 | 1377 | ssl->buffers.domainName.buffer = 0; |
wolfSSL | 0:9d17e4342598 | 1378 | #ifndef NO_CERTS |
wolfSSL | 0:9d17e4342598 | 1379 | ssl->buffers.serverDH_P.buffer = 0; |
wolfSSL | 0:9d17e4342598 | 1380 | ssl->buffers.serverDH_G.buffer = 0; |
wolfSSL | 0:9d17e4342598 | 1381 | ssl->buffers.serverDH_Pub.buffer = 0; |
wolfSSL | 0:9d17e4342598 | 1382 | ssl->buffers.serverDH_Priv.buffer = 0; |
wolfSSL | 0:9d17e4342598 | 1383 | #endif |
wolfSSL | 0:9d17e4342598 | 1384 | ssl->buffers.clearOutputBuffer.buffer = 0; |
wolfSSL | 0:9d17e4342598 | 1385 | ssl->buffers.clearOutputBuffer.length = 0; |
wolfSSL | 0:9d17e4342598 | 1386 | ssl->buffers.prevSent = 0; |
wolfSSL | 0:9d17e4342598 | 1387 | ssl->buffers.plainSz = 0; |
wolfSSL | 0:9d17e4342598 | 1388 | #ifdef HAVE_PK_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 1389 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 1390 | ssl->buffers.peerEccDsaKey.buffer = 0; |
wolfSSL | 0:9d17e4342598 | 1391 | ssl->buffers.peerEccDsaKey.length = 0; |
wolfSSL | 0:9d17e4342598 | 1392 | #endif /* HAVE_ECC */ |
wolfSSL | 0:9d17e4342598 | 1393 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 1394 | ssl->buffers.peerRsaKey.buffer = 0; |
wolfSSL | 0:9d17e4342598 | 1395 | ssl->buffers.peerRsaKey.length = 0; |
wolfSSL | 0:9d17e4342598 | 1396 | #endif /* NO_RSA */ |
wolfSSL | 0:9d17e4342598 | 1397 | #endif /* HAVE_PK_CALLBACKS */ |
wolfSSL | 0:9d17e4342598 | 1398 | |
wolfSSL | 0:9d17e4342598 | 1399 | #ifdef KEEP_PEER_CERT |
wolfSSL | 0:9d17e4342598 | 1400 | InitX509(&ssl->peerCert, 0); |
wolfSSL | 0:9d17e4342598 | 1401 | #endif |
wolfSSL | 0:9d17e4342598 | 1402 | |
wolfSSL | 0:9d17e4342598 | 1403 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 1404 | ssl->eccTempKeySz = ctx->eccTempKeySz; |
wolfSSL | 0:9d17e4342598 | 1405 | ssl->pkCurveOID = ctx->pkCurveOID; |
wolfSSL | 0:9d17e4342598 | 1406 | ssl->peerEccKeyPresent = 0; |
wolfSSL | 0:9d17e4342598 | 1407 | ssl->peerEccDsaKeyPresent = 0; |
wolfSSL | 0:9d17e4342598 | 1408 | ssl->eccDsaKeyPresent = 0; |
wolfSSL | 0:9d17e4342598 | 1409 | ssl->eccTempKeyPresent = 0; |
wolfSSL | 0:9d17e4342598 | 1410 | ssl->peerEccKey = NULL; |
wolfSSL | 0:9d17e4342598 | 1411 | ssl->peerEccDsaKey = NULL; |
wolfSSL | 0:9d17e4342598 | 1412 | ssl->eccDsaKey = NULL; |
wolfSSL | 0:9d17e4342598 | 1413 | ssl->eccTempKey = NULL; |
wolfSSL | 0:9d17e4342598 | 1414 | #endif |
wolfSSL | 0:9d17e4342598 | 1415 | |
wolfSSL | 0:9d17e4342598 | 1416 | ssl->timeout = ctx->timeout; |
wolfSSL | 0:9d17e4342598 | 1417 | ssl->rfd = -1; /* set to invalid descriptor */ |
wolfSSL | 0:9d17e4342598 | 1418 | ssl->wfd = -1; |
wolfSSL | 0:9d17e4342598 | 1419 | ssl->rflags = 0; /* no user flags yet */ |
wolfSSL | 0:9d17e4342598 | 1420 | ssl->wflags = 0; /* no user flags yet */ |
wolfSSL | 0:9d17e4342598 | 1421 | ssl->biord = 0; |
wolfSSL | 0:9d17e4342598 | 1422 | ssl->biowr = 0; |
wolfSSL | 0:9d17e4342598 | 1423 | |
wolfSSL | 0:9d17e4342598 | 1424 | ssl->IOCB_ReadCtx = &ssl->rfd; /* prevent invalid pointer access if not */ |
wolfSSL | 0:9d17e4342598 | 1425 | ssl->IOCB_WriteCtx = &ssl->wfd; /* correctly set */ |
wolfSSL | 0:9d17e4342598 | 1426 | #ifdef HAVE_NETX |
wolfSSL | 0:9d17e4342598 | 1427 | ssl->nxCtx.nxSocket = NULL; |
wolfSSL | 0:9d17e4342598 | 1428 | ssl->nxCtx.nxPacket = NULL; |
wolfSSL | 0:9d17e4342598 | 1429 | ssl->nxCtx.nxOffset = 0; |
wolfSSL | 0:9d17e4342598 | 1430 | ssl->nxCtx.nxWait = 0; |
wolfSSL | 0:9d17e4342598 | 1431 | ssl->IOCB_ReadCtx = &ssl->nxCtx; /* default NetX IO ctx, same for read */ |
wolfSSL | 0:9d17e4342598 | 1432 | ssl->IOCB_WriteCtx = &ssl->nxCtx; /* and write */ |
wolfSSL | 0:9d17e4342598 | 1433 | #endif |
wolfSSL | 0:9d17e4342598 | 1434 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 1435 | ssl->IOCB_CookieCtx = NULL; /* we don't use for default cb */ |
wolfSSL | 0:9d17e4342598 | 1436 | ssl->dtls_expected_rx = MAX_MTU; |
wolfSSL | 0:9d17e4342598 | 1437 | ssl->keys.dtls_state.window = 0; |
wolfSSL | 0:9d17e4342598 | 1438 | ssl->keys.dtls_state.nextEpoch = 0; |
wolfSSL | 0:9d17e4342598 | 1439 | ssl->keys.dtls_state.nextSeq = 0; |
wolfSSL | 0:9d17e4342598 | 1440 | #endif |
wolfSSL | 0:9d17e4342598 | 1441 | |
wolfSSL | 0:9d17e4342598 | 1442 | #ifndef NO_OLD_TLS |
wolfSSL | 0:9d17e4342598 | 1443 | #ifndef NO_MD5 |
wolfSSL | 0:9d17e4342598 | 1444 | InitMd5(&ssl->hashMd5); |
wolfSSL | 0:9d17e4342598 | 1445 | #endif |
wolfSSL | 0:9d17e4342598 | 1446 | #ifndef NO_SHA |
wolfSSL | 0:9d17e4342598 | 1447 | ret = InitSha(&ssl->hashSha); |
wolfSSL | 0:9d17e4342598 | 1448 | if (ret != 0) { |
wolfSSL | 0:9d17e4342598 | 1449 | return ret; |
wolfSSL | 0:9d17e4342598 | 1450 | } |
wolfSSL | 0:9d17e4342598 | 1451 | #endif |
wolfSSL | 0:9d17e4342598 | 1452 | #endif |
wolfSSL | 0:9d17e4342598 | 1453 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 1454 | ret = InitSha256(&ssl->hashSha256); |
wolfSSL | 0:9d17e4342598 | 1455 | if (ret != 0) { |
wolfSSL | 0:9d17e4342598 | 1456 | return ret; |
wolfSSL | 0:9d17e4342598 | 1457 | } |
wolfSSL | 0:9d17e4342598 | 1458 | #endif |
wolfSSL | 0:9d17e4342598 | 1459 | #ifdef CYASSL_SHA384 |
wolfSSL | 0:9d17e4342598 | 1460 | ret = InitSha384(&ssl->hashSha384); |
wolfSSL | 0:9d17e4342598 | 1461 | if (ret != 0) { |
wolfSSL | 0:9d17e4342598 | 1462 | return ret; |
wolfSSL | 0:9d17e4342598 | 1463 | } |
wolfSSL | 0:9d17e4342598 | 1464 | #endif |
wolfSSL | 0:9d17e4342598 | 1465 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 1466 | ssl->peerRsaKey = NULL; |
wolfSSL | 0:9d17e4342598 | 1467 | ssl->peerRsaKeyPresent = 0; |
wolfSSL | 0:9d17e4342598 | 1468 | #endif |
wolfSSL | 0:9d17e4342598 | 1469 | ssl->verifyCallback = ctx->verifyCallback; |
wolfSSL | 0:9d17e4342598 | 1470 | ssl->verifyCbCtx = NULL; |
wolfSSL | 0:9d17e4342598 | 1471 | ssl->options.side = ctx->method->side; |
wolfSSL | 0:9d17e4342598 | 1472 | ssl->options.downgrade = ctx->method->downgrade; |
wolfSSL | 0:9d17e4342598 | 1473 | ssl->error = 0; |
wolfSSL | 0:9d17e4342598 | 1474 | ssl->options.connReset = 0; |
wolfSSL | 0:9d17e4342598 | 1475 | ssl->options.isClosed = 0; |
wolfSSL | 0:9d17e4342598 | 1476 | ssl->options.closeNotify = 0; |
wolfSSL | 0:9d17e4342598 | 1477 | ssl->options.sentNotify = 0; |
wolfSSL | 0:9d17e4342598 | 1478 | ssl->options.usingCompression = 0; |
wolfSSL | 0:9d17e4342598 | 1479 | if (ssl->options.side == CYASSL_SERVER_END) |
wolfSSL | 0:9d17e4342598 | 1480 | ssl->options.haveDH = ctx->haveDH; |
wolfSSL | 0:9d17e4342598 | 1481 | else |
wolfSSL | 0:9d17e4342598 | 1482 | ssl->options.haveDH = 0; |
wolfSSL | 0:9d17e4342598 | 1483 | ssl->options.haveNTRU = ctx->haveNTRU; |
wolfSSL | 0:9d17e4342598 | 1484 | ssl->options.haveECDSAsig = ctx->haveECDSAsig; |
wolfSSL | 0:9d17e4342598 | 1485 | ssl->options.haveStaticECC = ctx->haveStaticECC; |
wolfSSL | 0:9d17e4342598 | 1486 | ssl->options.havePeerCert = 0; |
wolfSSL | 0:9d17e4342598 | 1487 | ssl->options.havePeerVerify = 0; |
wolfSSL | 0:9d17e4342598 | 1488 | ssl->options.usingPSK_cipher = 0; |
wolfSSL | 0:9d17e4342598 | 1489 | ssl->options.sendAlertState = 0; |
wolfSSL | 0:9d17e4342598 | 1490 | #ifndef NO_PSK |
wolfSSL | 0:9d17e4342598 | 1491 | havePSK = ctx->havePSK; |
wolfSSL | 0:9d17e4342598 | 1492 | ssl->options.havePSK = ctx->havePSK; |
wolfSSL | 0:9d17e4342598 | 1493 | ssl->options.client_psk_cb = ctx->client_psk_cb; |
wolfSSL | 0:9d17e4342598 | 1494 | ssl->options.server_psk_cb = ctx->server_psk_cb; |
wolfSSL | 0:9d17e4342598 | 1495 | #endif /* NO_PSK */ |
wolfSSL | 0:9d17e4342598 | 1496 | |
wolfSSL | 0:9d17e4342598 | 1497 | ssl->options.serverState = NULL_STATE; |
wolfSSL | 0:9d17e4342598 | 1498 | ssl->options.clientState = NULL_STATE; |
wolfSSL | 0:9d17e4342598 | 1499 | ssl->options.connectState = CONNECT_BEGIN; |
wolfSSL | 0:9d17e4342598 | 1500 | ssl->options.acceptState = ACCEPT_BEGIN; |
wolfSSL | 0:9d17e4342598 | 1501 | ssl->options.handShakeState = NULL_STATE; |
wolfSSL | 0:9d17e4342598 | 1502 | ssl->options.processReply = doProcessInit; |
wolfSSL | 0:9d17e4342598 | 1503 | |
wolfSSL | 0:9d17e4342598 | 1504 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 1505 | ssl->keys.dtls_sequence_number = 0; |
wolfSSL | 0:9d17e4342598 | 1506 | ssl->keys.dtls_state.curSeq = 0; |
wolfSSL | 0:9d17e4342598 | 1507 | ssl->keys.dtls_state.nextSeq = 0; |
wolfSSL | 0:9d17e4342598 | 1508 | ssl->keys.dtls_handshake_number = 0; |
wolfSSL | 0:9d17e4342598 | 1509 | ssl->keys.dtls_expected_peer_handshake_number = 0; |
wolfSSL | 0:9d17e4342598 | 1510 | ssl->keys.dtls_epoch = 0; |
wolfSSL | 0:9d17e4342598 | 1511 | ssl->keys.dtls_state.curEpoch = 0; |
wolfSSL | 0:9d17e4342598 | 1512 | ssl->keys.dtls_state.nextEpoch = 0; |
wolfSSL | 0:9d17e4342598 | 1513 | ssl->dtls_timeout_init = DTLS_TIMEOUT_INIT; |
wolfSSL | 0:9d17e4342598 | 1514 | ssl->dtls_timeout_max = DTLS_TIMEOUT_MAX; |
wolfSSL | 0:9d17e4342598 | 1515 | ssl->dtls_timeout = ssl->dtls_timeout_init; |
wolfSSL | 0:9d17e4342598 | 1516 | ssl->dtls_pool = NULL; |
wolfSSL | 0:9d17e4342598 | 1517 | ssl->dtls_msg_list = NULL; |
wolfSSL | 0:9d17e4342598 | 1518 | #endif |
wolfSSL | 0:9d17e4342598 | 1519 | ssl->keys.encryptSz = 0; |
wolfSSL | 0:9d17e4342598 | 1520 | ssl->keys.padSz = 0; |
wolfSSL | 0:9d17e4342598 | 1521 | ssl->keys.encryptionOn = 0; /* initially off */ |
wolfSSL | 0:9d17e4342598 | 1522 | ssl->keys.decryptedCur = 0; /* initially off */ |
wolfSSL | 0:9d17e4342598 | 1523 | ssl->options.sessionCacheOff = ctx->sessionCacheOff; |
wolfSSL | 0:9d17e4342598 | 1524 | ssl->options.sessionCacheFlushOff = ctx->sessionCacheFlushOff; |
wolfSSL | 0:9d17e4342598 | 1525 | |
wolfSSL | 0:9d17e4342598 | 1526 | ssl->options.verifyPeer = ctx->verifyPeer; |
wolfSSL | 0:9d17e4342598 | 1527 | ssl->options.verifyNone = ctx->verifyNone; |
wolfSSL | 0:9d17e4342598 | 1528 | ssl->options.failNoCert = ctx->failNoCert; |
wolfSSL | 0:9d17e4342598 | 1529 | ssl->options.sendVerify = ctx->sendVerify; |
wolfSSL | 0:9d17e4342598 | 1530 | |
wolfSSL | 0:9d17e4342598 | 1531 | ssl->options.resuming = 0; |
wolfSSL | 0:9d17e4342598 | 1532 | ssl->options.haveSessionId = 0; |
wolfSSL | 0:9d17e4342598 | 1533 | #ifndef NO_OLD_TLS |
wolfSSL | 0:9d17e4342598 | 1534 | ssl->hmac = SSL_hmac; /* default to SSLv3 */ |
wolfSSL | 0:9d17e4342598 | 1535 | #else |
wolfSSL | 0:9d17e4342598 | 1536 | ssl->hmac = TLS_hmac; |
wolfSSL | 0:9d17e4342598 | 1537 | #endif |
wolfSSL | 0:9d17e4342598 | 1538 | ssl->heap = ctx->heap; /* defaults to self */ |
wolfSSL | 0:9d17e4342598 | 1539 | ssl->options.tls = 0; |
wolfSSL | 0:9d17e4342598 | 1540 | ssl->options.tls1_1 = 0; |
wolfSSL | 0:9d17e4342598 | 1541 | ssl->options.dtls = ssl->version.major == DTLS_MAJOR; |
wolfSSL | 0:9d17e4342598 | 1542 | ssl->options.partialWrite = ctx->partialWrite; |
wolfSSL | 0:9d17e4342598 | 1543 | ssl->options.quietShutdown = ctx->quietShutdown; |
wolfSSL | 0:9d17e4342598 | 1544 | ssl->options.certOnly = 0; |
wolfSSL | 0:9d17e4342598 | 1545 | ssl->options.groupMessages = ctx->groupMessages; |
wolfSSL | 0:9d17e4342598 | 1546 | ssl->options.usingNonblock = 0; |
wolfSSL | 0:9d17e4342598 | 1547 | ssl->options.saveArrays = 0; |
wolfSSL | 0:9d17e4342598 | 1548 | |
wolfSSL | 0:9d17e4342598 | 1549 | #ifndef NO_CERTS |
wolfSSL | 0:9d17e4342598 | 1550 | /* ctx still owns certificate, certChain, key, dh, and cm */ |
wolfSSL | 0:9d17e4342598 | 1551 | ssl->buffers.certificate = ctx->certificate; |
wolfSSL | 0:9d17e4342598 | 1552 | ssl->buffers.certChain = ctx->certChain; |
wolfSSL | 0:9d17e4342598 | 1553 | ssl->buffers.key = ctx->privateKey; |
wolfSSL | 0:9d17e4342598 | 1554 | if (ssl->options.side == CYASSL_SERVER_END) { |
wolfSSL | 0:9d17e4342598 | 1555 | ssl->buffers.serverDH_P = ctx->serverDH_P; |
wolfSSL | 0:9d17e4342598 | 1556 | ssl->buffers.serverDH_G = ctx->serverDH_G; |
wolfSSL | 0:9d17e4342598 | 1557 | } |
wolfSSL | 0:9d17e4342598 | 1558 | #endif |
wolfSSL | 0:9d17e4342598 | 1559 | ssl->buffers.weOwnCert = 0; |
wolfSSL | 0:9d17e4342598 | 1560 | ssl->buffers.weOwnKey = 0; |
wolfSSL | 0:9d17e4342598 | 1561 | ssl->buffers.weOwnDH = 0; |
wolfSSL | 0:9d17e4342598 | 1562 | |
wolfSSL | 0:9d17e4342598 | 1563 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 1564 | ssl->buffers.dtlsCtx.fd = -1; |
wolfSSL | 0:9d17e4342598 | 1565 | ssl->buffers.dtlsCtx.peer.sa = NULL; |
wolfSSL | 0:9d17e4342598 | 1566 | ssl->buffers.dtlsCtx.peer.sz = 0; |
wolfSSL | 0:9d17e4342598 | 1567 | #endif |
wolfSSL | 0:9d17e4342598 | 1568 | |
wolfSSL | 0:9d17e4342598 | 1569 | #ifdef KEEP_PEER_CERT |
wolfSSL | 0:9d17e4342598 | 1570 | ssl->peerCert.issuer.sz = 0; |
wolfSSL | 0:9d17e4342598 | 1571 | ssl->peerCert.subject.sz = 0; |
wolfSSL | 0:9d17e4342598 | 1572 | #endif |
wolfSSL | 0:9d17e4342598 | 1573 | |
wolfSSL | 0:9d17e4342598 | 1574 | #ifdef SESSION_CERTS |
wolfSSL | 0:9d17e4342598 | 1575 | ssl->session.chain.count = 0; |
wolfSSL | 0:9d17e4342598 | 1576 | #endif |
wolfSSL | 0:9d17e4342598 | 1577 | |
wolfSSL | 0:9d17e4342598 | 1578 | #ifndef NO_CLIENT_CACHE |
wolfSSL | 0:9d17e4342598 | 1579 | ssl->session.idLen = 0; |
wolfSSL | 0:9d17e4342598 | 1580 | #endif |
wolfSSL | 0:9d17e4342598 | 1581 | |
wolfSSL | 0:9d17e4342598 | 1582 | ssl->cipher.ssl = ssl; |
wolfSSL | 0:9d17e4342598 | 1583 | |
wolfSSL | 0:9d17e4342598 | 1584 | #ifdef FORTRESS |
wolfSSL | 0:9d17e4342598 | 1585 | ssl->ex_data[0] = 0; |
wolfSSL | 0:9d17e4342598 | 1586 | ssl->ex_data[1] = 0; |
wolfSSL | 0:9d17e4342598 | 1587 | ssl->ex_data[2] = 0; |
wolfSSL | 0:9d17e4342598 | 1588 | #endif |
wolfSSL | 0:9d17e4342598 | 1589 | |
wolfSSL | 0:9d17e4342598 | 1590 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 1591 | ssl->hsInfoOn = 0; |
wolfSSL | 0:9d17e4342598 | 1592 | ssl->toInfoOn = 0; |
wolfSSL | 0:9d17e4342598 | 1593 | #endif |
wolfSSL | 0:9d17e4342598 | 1594 | |
wolfSSL | 0:9d17e4342598 | 1595 | #ifdef HAVE_CAVIUM |
wolfSSL | 0:9d17e4342598 | 1596 | ssl->devId = ctx->devId; |
wolfSSL | 0:9d17e4342598 | 1597 | #endif |
wolfSSL | 0:9d17e4342598 | 1598 | |
wolfSSL | 0:9d17e4342598 | 1599 | #ifdef HAVE_TLS_EXTENSIONS |
wolfSSL | 0:9d17e4342598 | 1600 | ssl->extensions = NULL; |
wolfSSL | 0:9d17e4342598 | 1601 | #ifdef HAVE_MAX_FRAGMENT |
wolfSSL | 0:9d17e4342598 | 1602 | ssl->max_fragment = MAX_RECORD_SIZE; |
wolfSSL | 0:9d17e4342598 | 1603 | #endif |
wolfSSL | 0:9d17e4342598 | 1604 | #ifdef HAVE_TRUNCATED_HMAC |
wolfSSL | 0:9d17e4342598 | 1605 | ssl->truncated_hmac = 0; |
wolfSSL | 0:9d17e4342598 | 1606 | #endif |
wolfSSL | 0:9d17e4342598 | 1607 | #endif |
wolfSSL | 0:9d17e4342598 | 1608 | |
wolfSSL | 0:9d17e4342598 | 1609 | ssl->rng = NULL; |
wolfSSL | 0:9d17e4342598 | 1610 | ssl->arrays = NULL; |
wolfSSL | 0:9d17e4342598 | 1611 | |
wolfSSL | 0:9d17e4342598 | 1612 | /* default alert state (none) */ |
wolfSSL | 0:9d17e4342598 | 1613 | ssl->alert_history.last_rx.code = -1; |
wolfSSL | 0:9d17e4342598 | 1614 | ssl->alert_history.last_rx.level = -1; |
wolfSSL | 0:9d17e4342598 | 1615 | ssl->alert_history.last_tx.code = -1; |
wolfSSL | 0:9d17e4342598 | 1616 | ssl->alert_history.last_tx.level = -1; |
wolfSSL | 0:9d17e4342598 | 1617 | |
wolfSSL | 0:9d17e4342598 | 1618 | InitCiphers(ssl); |
wolfSSL | 0:9d17e4342598 | 1619 | InitCipherSpecs(&ssl->specs); |
wolfSSL | 0:9d17e4342598 | 1620 | #ifdef ATOMIC_USER |
wolfSSL | 0:9d17e4342598 | 1621 | ssl->MacEncryptCtx = NULL; |
wolfSSL | 0:9d17e4342598 | 1622 | ssl->DecryptVerifyCtx = NULL; |
wolfSSL | 0:9d17e4342598 | 1623 | #endif |
wolfSSL | 0:9d17e4342598 | 1624 | #ifdef HAVE_PK_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 1625 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 1626 | ssl->EccSignCtx = NULL; |
wolfSSL | 0:9d17e4342598 | 1627 | ssl->EccVerifyCtx = NULL; |
wolfSSL | 0:9d17e4342598 | 1628 | #endif /* HAVE_ECC */ |
wolfSSL | 0:9d17e4342598 | 1629 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 1630 | ssl->RsaSignCtx = NULL; |
wolfSSL | 0:9d17e4342598 | 1631 | ssl->RsaVerifyCtx = NULL; |
wolfSSL | 0:9d17e4342598 | 1632 | ssl->RsaEncCtx = NULL; |
wolfSSL | 0:9d17e4342598 | 1633 | ssl->RsaDecCtx = NULL; |
wolfSSL | 0:9d17e4342598 | 1634 | #endif /* NO_RSA */ |
wolfSSL | 0:9d17e4342598 | 1635 | #endif /* HAVE_PK_CALLBACKS */ |
wolfSSL | 0:9d17e4342598 | 1636 | |
wolfSSL | 0:9d17e4342598 | 1637 | /* all done with init, now can return errors, call other stuff */ |
wolfSSL | 0:9d17e4342598 | 1638 | |
wolfSSL | 0:9d17e4342598 | 1639 | /* increment CTX reference count */ |
wolfSSL | 0:9d17e4342598 | 1640 | if (LockMutex(&ctx->countMutex) != 0) { |
wolfSSL | 0:9d17e4342598 | 1641 | CYASSL_MSG("Couldn't lock CTX count mutex"); |
wolfSSL | 0:9d17e4342598 | 1642 | return BAD_MUTEX_E; |
wolfSSL | 0:9d17e4342598 | 1643 | } |
wolfSSL | 0:9d17e4342598 | 1644 | ctx->refCount++; |
wolfSSL | 0:9d17e4342598 | 1645 | UnLockMutex(&ctx->countMutex); |
wolfSSL | 0:9d17e4342598 | 1646 | |
wolfSSL | 0:9d17e4342598 | 1647 | /* arrays */ |
wolfSSL | 0:9d17e4342598 | 1648 | ssl->arrays = (Arrays*)XMALLOC(sizeof(Arrays), ssl->heap, |
wolfSSL | 0:9d17e4342598 | 1649 | DYNAMIC_TYPE_ARRAYS); |
wolfSSL | 0:9d17e4342598 | 1650 | if (ssl->arrays == NULL) { |
wolfSSL | 0:9d17e4342598 | 1651 | CYASSL_MSG("Arrays Memory error"); |
wolfSSL | 0:9d17e4342598 | 1652 | return MEMORY_E; |
wolfSSL | 0:9d17e4342598 | 1653 | } |
wolfSSL | 0:9d17e4342598 | 1654 | XMEMSET(ssl->arrays, 0, sizeof(Arrays)); |
wolfSSL | 0:9d17e4342598 | 1655 | |
wolfSSL | 0:9d17e4342598 | 1656 | #ifndef NO_PSK |
wolfSSL | 0:9d17e4342598 | 1657 | ssl->arrays->client_identity[0] = 0; |
wolfSSL | 0:9d17e4342598 | 1658 | if (ctx->server_hint[0]) { /* set in CTX */ |
wolfSSL | 0:9d17e4342598 | 1659 | XSTRNCPY(ssl->arrays->server_hint, ctx->server_hint, MAX_PSK_ID_LEN); |
wolfSSL | 0:9d17e4342598 | 1660 | ssl->arrays->server_hint[MAX_PSK_ID_LEN - 1] = '\0'; |
wolfSSL | 0:9d17e4342598 | 1661 | } |
wolfSSL | 0:9d17e4342598 | 1662 | else |
wolfSSL | 0:9d17e4342598 | 1663 | ssl->arrays->server_hint[0] = 0; |
wolfSSL | 0:9d17e4342598 | 1664 | #endif /* NO_PSK */ |
wolfSSL | 0:9d17e4342598 | 1665 | |
wolfSSL | 0:9d17e4342598 | 1666 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 1667 | ssl->arrays->cookieSz = 0; |
wolfSSL | 0:9d17e4342598 | 1668 | #endif |
wolfSSL | 0:9d17e4342598 | 1669 | |
wolfSSL | 0:9d17e4342598 | 1670 | /* RNG */ |
wolfSSL | 0:9d17e4342598 | 1671 | ssl->rng = (RNG*)XMALLOC(sizeof(RNG), ssl->heap, DYNAMIC_TYPE_RNG); |
wolfSSL | 0:9d17e4342598 | 1672 | if (ssl->rng == NULL) { |
wolfSSL | 0:9d17e4342598 | 1673 | CYASSL_MSG("RNG Memory error"); |
wolfSSL | 0:9d17e4342598 | 1674 | return MEMORY_E; |
wolfSSL | 0:9d17e4342598 | 1675 | } |
wolfSSL | 0:9d17e4342598 | 1676 | |
wolfSSL | 0:9d17e4342598 | 1677 | if ( (ret = InitRng(ssl->rng)) != 0) { |
wolfSSL | 0:9d17e4342598 | 1678 | CYASSL_MSG("RNG Init error"); |
wolfSSL | 0:9d17e4342598 | 1679 | return ret; |
wolfSSL | 0:9d17e4342598 | 1680 | } |
wolfSSL | 0:9d17e4342598 | 1681 | |
wolfSSL | 0:9d17e4342598 | 1682 | /* suites */ |
wolfSSL | 0:9d17e4342598 | 1683 | ssl->suites = (Suites*)XMALLOC(sizeof(Suites), ssl->heap, |
wolfSSL | 0:9d17e4342598 | 1684 | DYNAMIC_TYPE_SUITES); |
wolfSSL | 0:9d17e4342598 | 1685 | if (ssl->suites == NULL) { |
wolfSSL | 0:9d17e4342598 | 1686 | CYASSL_MSG("Suites Memory error"); |
wolfSSL | 0:9d17e4342598 | 1687 | return MEMORY_E; |
wolfSSL | 0:9d17e4342598 | 1688 | } |
wolfSSL | 0:9d17e4342598 | 1689 | *ssl->suites = ctx->suites; |
wolfSSL | 0:9d17e4342598 | 1690 | |
wolfSSL | 0:9d17e4342598 | 1691 | /* peer key */ |
wolfSSL | 0:9d17e4342598 | 1692 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 1693 | ssl->peerRsaKey = (RsaKey*)XMALLOC(sizeof(RsaKey), ssl->heap, |
wolfSSL | 0:9d17e4342598 | 1694 | DYNAMIC_TYPE_RSA); |
wolfSSL | 0:9d17e4342598 | 1695 | if (ssl->peerRsaKey == NULL) { |
wolfSSL | 0:9d17e4342598 | 1696 | CYASSL_MSG("PeerRsaKey Memory error"); |
wolfSSL | 0:9d17e4342598 | 1697 | return MEMORY_E; |
wolfSSL | 0:9d17e4342598 | 1698 | } |
wolfSSL | 0:9d17e4342598 | 1699 | ret = InitRsaKey(ssl->peerRsaKey, ctx->heap); |
wolfSSL | 0:9d17e4342598 | 1700 | if (ret != 0) return ret; |
wolfSSL | 0:9d17e4342598 | 1701 | #endif |
wolfSSL | 0:9d17e4342598 | 1702 | #ifndef NO_CERTS |
wolfSSL | 0:9d17e4342598 | 1703 | /* make sure server has cert and key unless using PSK */ |
wolfSSL | 0:9d17e4342598 | 1704 | if (ssl->options.side == CYASSL_SERVER_END && !havePSK) |
wolfSSL | 0:9d17e4342598 | 1705 | if (!ssl->buffers.certificate.buffer || !ssl->buffers.key.buffer) { |
wolfSSL | 0:9d17e4342598 | 1706 | CYASSL_MSG("Server missing certificate and/or private key"); |
wolfSSL | 0:9d17e4342598 | 1707 | return NO_PRIVATE_KEY; |
wolfSSL | 0:9d17e4342598 | 1708 | } |
wolfSSL | 0:9d17e4342598 | 1709 | #endif |
wolfSSL | 0:9d17e4342598 | 1710 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 1711 | ssl->peerEccKey = (ecc_key*)XMALLOC(sizeof(ecc_key), |
wolfSSL | 0:9d17e4342598 | 1712 | ctx->heap, DYNAMIC_TYPE_ECC); |
wolfSSL | 0:9d17e4342598 | 1713 | if (ssl->peerEccKey == NULL) { |
wolfSSL | 0:9d17e4342598 | 1714 | CYASSL_MSG("PeerEccKey Memory error"); |
wolfSSL | 0:9d17e4342598 | 1715 | return MEMORY_E; |
wolfSSL | 0:9d17e4342598 | 1716 | } |
wolfSSL | 0:9d17e4342598 | 1717 | ssl->peerEccDsaKey = (ecc_key*)XMALLOC(sizeof(ecc_key), |
wolfSSL | 0:9d17e4342598 | 1718 | ctx->heap, DYNAMIC_TYPE_ECC); |
wolfSSL | 0:9d17e4342598 | 1719 | if (ssl->peerEccDsaKey == NULL) { |
wolfSSL | 0:9d17e4342598 | 1720 | CYASSL_MSG("PeerEccDsaKey Memory error"); |
wolfSSL | 0:9d17e4342598 | 1721 | return MEMORY_E; |
wolfSSL | 0:9d17e4342598 | 1722 | } |
wolfSSL | 0:9d17e4342598 | 1723 | ssl->eccDsaKey = (ecc_key*)XMALLOC(sizeof(ecc_key), |
wolfSSL | 0:9d17e4342598 | 1724 | ctx->heap, DYNAMIC_TYPE_ECC); |
wolfSSL | 0:9d17e4342598 | 1725 | if (ssl->eccDsaKey == NULL) { |
wolfSSL | 0:9d17e4342598 | 1726 | CYASSL_MSG("EccDsaKey Memory error"); |
wolfSSL | 0:9d17e4342598 | 1727 | return MEMORY_E; |
wolfSSL | 0:9d17e4342598 | 1728 | } |
wolfSSL | 0:9d17e4342598 | 1729 | ssl->eccTempKey = (ecc_key*)XMALLOC(sizeof(ecc_key), |
wolfSSL | 0:9d17e4342598 | 1730 | ctx->heap, DYNAMIC_TYPE_ECC); |
wolfSSL | 0:9d17e4342598 | 1731 | if (ssl->eccTempKey == NULL) { |
wolfSSL | 0:9d17e4342598 | 1732 | CYASSL_MSG("EccTempKey Memory error"); |
wolfSSL | 0:9d17e4342598 | 1733 | return MEMORY_E; |
wolfSSL | 0:9d17e4342598 | 1734 | } |
wolfSSL | 0:9d17e4342598 | 1735 | ecc_init(ssl->peerEccKey); |
wolfSSL | 0:9d17e4342598 | 1736 | ecc_init(ssl->peerEccDsaKey); |
wolfSSL | 0:9d17e4342598 | 1737 | ecc_init(ssl->eccDsaKey); |
wolfSSL | 0:9d17e4342598 | 1738 | ecc_init(ssl->eccTempKey); |
wolfSSL | 0:9d17e4342598 | 1739 | #endif |
wolfSSL | 0:9d17e4342598 | 1740 | |
wolfSSL | 0:9d17e4342598 | 1741 | /* make sure server has DH parms, and add PSK if there, add NTRU too */ |
wolfSSL | 0:9d17e4342598 | 1742 | if (ssl->options.side == CYASSL_SERVER_END) |
wolfSSL | 0:9d17e4342598 | 1743 | InitSuites(ssl->suites, ssl->version, haveRSA, havePSK, |
wolfSSL | 0:9d17e4342598 | 1744 | ssl->options.haveDH, ssl->options.haveNTRU, |
wolfSSL | 0:9d17e4342598 | 1745 | ssl->options.haveECDSAsig, ssl->options.haveStaticECC, |
wolfSSL | 0:9d17e4342598 | 1746 | ssl->options.side); |
wolfSSL | 0:9d17e4342598 | 1747 | else |
wolfSSL | 0:9d17e4342598 | 1748 | InitSuites(ssl->suites, ssl->version, haveRSA, havePSK, TRUE, |
wolfSSL | 0:9d17e4342598 | 1749 | ssl->options.haveNTRU, ssl->options.haveECDSAsig, |
wolfSSL | 0:9d17e4342598 | 1750 | ssl->options.haveStaticECC, ssl->options.side); |
wolfSSL | 0:9d17e4342598 | 1751 | |
wolfSSL | 0:9d17e4342598 | 1752 | return 0; |
wolfSSL | 0:9d17e4342598 | 1753 | } |
wolfSSL | 0:9d17e4342598 | 1754 | |
wolfSSL | 0:9d17e4342598 | 1755 | |
wolfSSL | 0:9d17e4342598 | 1756 | /* free use of temporary arrays */ |
wolfSSL | 0:9d17e4342598 | 1757 | void FreeArrays(CYASSL* ssl, int keep) |
wolfSSL | 0:9d17e4342598 | 1758 | { |
wolfSSL | 0:9d17e4342598 | 1759 | if (ssl->arrays && keep) { |
wolfSSL | 0:9d17e4342598 | 1760 | /* keeps session id for user retrieval */ |
wolfSSL | 0:9d17e4342598 | 1761 | XMEMCPY(ssl->session.sessionID, ssl->arrays->sessionID, ID_LEN); |
wolfSSL | 0:9d17e4342598 | 1762 | } |
wolfSSL | 0:9d17e4342598 | 1763 | XFREE(ssl->arrays, ssl->heap, DYNAMIC_TYPE_ARRAYS); |
wolfSSL | 0:9d17e4342598 | 1764 | ssl->arrays = NULL; |
wolfSSL | 0:9d17e4342598 | 1765 | } |
wolfSSL | 0:9d17e4342598 | 1766 | |
wolfSSL | 0:9d17e4342598 | 1767 | |
wolfSSL | 0:9d17e4342598 | 1768 | /* In case holding SSL object in array and don't want to free actual ssl */ |
wolfSSL | 0:9d17e4342598 | 1769 | void SSL_ResourceFree(CYASSL* ssl) |
wolfSSL | 0:9d17e4342598 | 1770 | { |
wolfSSL | 0:9d17e4342598 | 1771 | FreeCiphers(ssl); |
wolfSSL | 0:9d17e4342598 | 1772 | FreeArrays(ssl, 0); |
wolfSSL | 0:9d17e4342598 | 1773 | XFREE(ssl->rng, ssl->heap, DYNAMIC_TYPE_RNG); |
wolfSSL | 0:9d17e4342598 | 1774 | XFREE(ssl->suites, ssl->heap, DYNAMIC_TYPE_SUITES); |
wolfSSL | 0:9d17e4342598 | 1775 | XFREE(ssl->buffers.domainName.buffer, ssl->heap, DYNAMIC_TYPE_DOMAIN); |
wolfSSL | 0:9d17e4342598 | 1776 | |
wolfSSL | 0:9d17e4342598 | 1777 | #ifndef NO_CERTS |
wolfSSL | 0:9d17e4342598 | 1778 | XFREE(ssl->buffers.serverDH_Priv.buffer, ssl->heap, DYNAMIC_TYPE_DH); |
wolfSSL | 0:9d17e4342598 | 1779 | XFREE(ssl->buffers.serverDH_Pub.buffer, ssl->heap, DYNAMIC_TYPE_DH); |
wolfSSL | 0:9d17e4342598 | 1780 | /* parameters (p,g) may be owned by ctx */ |
wolfSSL | 0:9d17e4342598 | 1781 | if (ssl->buffers.weOwnDH || ssl->options.side == CYASSL_CLIENT_END) { |
wolfSSL | 0:9d17e4342598 | 1782 | XFREE(ssl->buffers.serverDH_G.buffer, ssl->heap, DYNAMIC_TYPE_DH); |
wolfSSL | 0:9d17e4342598 | 1783 | XFREE(ssl->buffers.serverDH_P.buffer, ssl->heap, DYNAMIC_TYPE_DH); |
wolfSSL | 0:9d17e4342598 | 1784 | } |
wolfSSL | 0:9d17e4342598 | 1785 | |
wolfSSL | 0:9d17e4342598 | 1786 | /* CYASSL_CTX always owns certChain */ |
wolfSSL | 0:9d17e4342598 | 1787 | if (ssl->buffers.weOwnCert) |
wolfSSL | 0:9d17e4342598 | 1788 | XFREE(ssl->buffers.certificate.buffer, ssl->heap, DYNAMIC_TYPE_CERT); |
wolfSSL | 0:9d17e4342598 | 1789 | if (ssl->buffers.weOwnKey) |
wolfSSL | 0:9d17e4342598 | 1790 | XFREE(ssl->buffers.key.buffer, ssl->heap, DYNAMIC_TYPE_KEY); |
wolfSSL | 0:9d17e4342598 | 1791 | #endif |
wolfSSL | 0:9d17e4342598 | 1792 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 1793 | if (ssl->peerRsaKey) { |
wolfSSL | 0:9d17e4342598 | 1794 | FreeRsaKey(ssl->peerRsaKey); |
wolfSSL | 0:9d17e4342598 | 1795 | XFREE(ssl->peerRsaKey, ssl->heap, DYNAMIC_TYPE_RSA); |
wolfSSL | 0:9d17e4342598 | 1796 | } |
wolfSSL | 0:9d17e4342598 | 1797 | #endif |
wolfSSL | 0:9d17e4342598 | 1798 | if (ssl->buffers.inputBuffer.dynamicFlag) |
wolfSSL | 0:9d17e4342598 | 1799 | ShrinkInputBuffer(ssl, FORCED_FREE); |
wolfSSL | 0:9d17e4342598 | 1800 | if (ssl->buffers.outputBuffer.dynamicFlag) |
wolfSSL | 0:9d17e4342598 | 1801 | ShrinkOutputBuffer(ssl); |
wolfSSL | 0:9d17e4342598 | 1802 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 1803 | if (ssl->dtls_pool != NULL) { |
wolfSSL | 0:9d17e4342598 | 1804 | DtlsPoolReset(ssl); |
wolfSSL | 0:9d17e4342598 | 1805 | XFREE(ssl->dtls_pool, ssl->heap, DYNAMIC_TYPE_NONE); |
wolfSSL | 0:9d17e4342598 | 1806 | } |
wolfSSL | 0:9d17e4342598 | 1807 | if (ssl->dtls_msg_list != NULL) { |
wolfSSL | 0:9d17e4342598 | 1808 | DtlsMsgListDelete(ssl->dtls_msg_list, ssl->heap); |
wolfSSL | 0:9d17e4342598 | 1809 | ssl->dtls_msg_list = NULL; |
wolfSSL | 0:9d17e4342598 | 1810 | } |
wolfSSL | 0:9d17e4342598 | 1811 | XFREE(ssl->buffers.dtlsCtx.peer.sa, ssl->heap, DYNAMIC_TYPE_SOCKADDR); |
wolfSSL | 0:9d17e4342598 | 1812 | ssl->buffers.dtlsCtx.peer.sa = NULL; |
wolfSSL | 0:9d17e4342598 | 1813 | #endif |
wolfSSL | 0:9d17e4342598 | 1814 | #if defined(KEEP_PEER_CERT) || defined(GOAHEAD_WS) |
wolfSSL | 0:9d17e4342598 | 1815 | FreeX509(&ssl->peerCert); |
wolfSSL | 0:9d17e4342598 | 1816 | #endif |
wolfSSL | 0:9d17e4342598 | 1817 | #if defined(OPENSSL_EXTRA) || defined(GOAHEAD_WS) |
wolfSSL | 0:9d17e4342598 | 1818 | CyaSSL_BIO_free(ssl->biord); |
wolfSSL | 0:9d17e4342598 | 1819 | if (ssl->biord != ssl->biowr) /* in case same as write */ |
wolfSSL | 0:9d17e4342598 | 1820 | CyaSSL_BIO_free(ssl->biowr); |
wolfSSL | 0:9d17e4342598 | 1821 | #endif |
wolfSSL | 0:9d17e4342598 | 1822 | #ifdef HAVE_LIBZ |
wolfSSL | 0:9d17e4342598 | 1823 | FreeStreams(ssl); |
wolfSSL | 0:9d17e4342598 | 1824 | #endif |
wolfSSL | 0:9d17e4342598 | 1825 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 1826 | if (ssl->peerEccKey) { |
wolfSSL | 0:9d17e4342598 | 1827 | if (ssl->peerEccKeyPresent) |
wolfSSL | 0:9d17e4342598 | 1828 | ecc_free(ssl->peerEccKey); |
wolfSSL | 0:9d17e4342598 | 1829 | XFREE(ssl->peerEccKey, ssl->heap, DYNAMIC_TYPE_ECC); |
wolfSSL | 0:9d17e4342598 | 1830 | } |
wolfSSL | 0:9d17e4342598 | 1831 | if (ssl->peerEccDsaKey) { |
wolfSSL | 0:9d17e4342598 | 1832 | if (ssl->peerEccDsaKeyPresent) |
wolfSSL | 0:9d17e4342598 | 1833 | ecc_free(ssl->peerEccDsaKey); |
wolfSSL | 0:9d17e4342598 | 1834 | XFREE(ssl->peerEccDsaKey, ssl->heap, DYNAMIC_TYPE_ECC); |
wolfSSL | 0:9d17e4342598 | 1835 | } |
wolfSSL | 0:9d17e4342598 | 1836 | if (ssl->eccTempKey) { |
wolfSSL | 0:9d17e4342598 | 1837 | if (ssl->eccTempKeyPresent) |
wolfSSL | 0:9d17e4342598 | 1838 | ecc_free(ssl->eccTempKey); |
wolfSSL | 0:9d17e4342598 | 1839 | XFREE(ssl->eccTempKey, ssl->heap, DYNAMIC_TYPE_ECC); |
wolfSSL | 0:9d17e4342598 | 1840 | } |
wolfSSL | 0:9d17e4342598 | 1841 | if (ssl->eccDsaKey) { |
wolfSSL | 0:9d17e4342598 | 1842 | if (ssl->eccDsaKeyPresent) |
wolfSSL | 0:9d17e4342598 | 1843 | ecc_free(ssl->eccDsaKey); |
wolfSSL | 0:9d17e4342598 | 1844 | XFREE(ssl->eccDsaKey, ssl->heap, DYNAMIC_TYPE_ECC); |
wolfSSL | 0:9d17e4342598 | 1845 | } |
wolfSSL | 0:9d17e4342598 | 1846 | #endif |
wolfSSL | 0:9d17e4342598 | 1847 | #ifdef HAVE_PK_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 1848 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 1849 | XFREE(ssl->buffers.peerEccDsaKey.buffer, ssl->heap, DYNAMIC_TYPE_ECC); |
wolfSSL | 0:9d17e4342598 | 1850 | #endif /* HAVE_ECC */ |
wolfSSL | 0:9d17e4342598 | 1851 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 1852 | XFREE(ssl->buffers.peerRsaKey.buffer, ssl->heap, DYNAMIC_TYPE_RSA); |
wolfSSL | 0:9d17e4342598 | 1853 | #endif /* NO_RSA */ |
wolfSSL | 0:9d17e4342598 | 1854 | #endif /* HAVE_PK_CALLBACKS */ |
wolfSSL | 0:9d17e4342598 | 1855 | #ifdef HAVE_TLS_EXTENSIONS |
wolfSSL | 0:9d17e4342598 | 1856 | TLSX_FreeAll(ssl->extensions); |
wolfSSL | 0:9d17e4342598 | 1857 | #endif |
wolfSSL | 0:9d17e4342598 | 1858 | #ifdef HAVE_NETX |
wolfSSL | 0:9d17e4342598 | 1859 | if (ssl->nxCtx.nxPacket) |
wolfSSL | 0:9d17e4342598 | 1860 | nx_packet_release(ssl->nxCtx.nxPacket); |
wolfSSL | 0:9d17e4342598 | 1861 | #endif |
wolfSSL | 0:9d17e4342598 | 1862 | } |
wolfSSL | 0:9d17e4342598 | 1863 | |
wolfSSL | 0:9d17e4342598 | 1864 | |
wolfSSL | 0:9d17e4342598 | 1865 | /* Free any handshake resources no longer needed */ |
wolfSSL | 0:9d17e4342598 | 1866 | void FreeHandshakeResources(CYASSL* ssl) |
wolfSSL | 0:9d17e4342598 | 1867 | { |
wolfSSL | 0:9d17e4342598 | 1868 | /* input buffer */ |
wolfSSL | 0:9d17e4342598 | 1869 | if (ssl->buffers.inputBuffer.dynamicFlag) |
wolfSSL | 0:9d17e4342598 | 1870 | ShrinkInputBuffer(ssl, NO_FORCED_FREE); |
wolfSSL | 0:9d17e4342598 | 1871 | |
wolfSSL | 0:9d17e4342598 | 1872 | /* suites */ |
wolfSSL | 0:9d17e4342598 | 1873 | XFREE(ssl->suites, ssl->heap, DYNAMIC_TYPE_SUITES); |
wolfSSL | 0:9d17e4342598 | 1874 | ssl->suites = NULL; |
wolfSSL | 0:9d17e4342598 | 1875 | |
wolfSSL | 0:9d17e4342598 | 1876 | /* RNG */ |
wolfSSL | 0:9d17e4342598 | 1877 | if (ssl->specs.cipher_type == stream || ssl->options.tls1_1 == 0) { |
wolfSSL | 0:9d17e4342598 | 1878 | XFREE(ssl->rng, ssl->heap, DYNAMIC_TYPE_RNG); |
wolfSSL | 0:9d17e4342598 | 1879 | ssl->rng = NULL; |
wolfSSL | 0:9d17e4342598 | 1880 | } |
wolfSSL | 0:9d17e4342598 | 1881 | |
wolfSSL | 0:9d17e4342598 | 1882 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 1883 | /* DTLS_POOL */ |
wolfSSL | 0:9d17e4342598 | 1884 | if (ssl->options.dtls && ssl->dtls_pool != NULL) { |
wolfSSL | 0:9d17e4342598 | 1885 | DtlsPoolReset(ssl); |
wolfSSL | 0:9d17e4342598 | 1886 | XFREE(ssl->dtls_pool, ssl->heap, DYNAMIC_TYPE_DTLS_POOL); |
wolfSSL | 0:9d17e4342598 | 1887 | ssl->dtls_pool = NULL; |
wolfSSL | 0:9d17e4342598 | 1888 | } |
wolfSSL | 0:9d17e4342598 | 1889 | #endif |
wolfSSL | 0:9d17e4342598 | 1890 | |
wolfSSL | 0:9d17e4342598 | 1891 | /* arrays */ |
wolfSSL | 0:9d17e4342598 | 1892 | if (ssl->options.saveArrays) |
wolfSSL | 0:9d17e4342598 | 1893 | FreeArrays(ssl, 1); |
wolfSSL | 0:9d17e4342598 | 1894 | |
wolfSSL | 0:9d17e4342598 | 1895 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 1896 | /* peerRsaKey */ |
wolfSSL | 0:9d17e4342598 | 1897 | if (ssl->peerRsaKey) { |
wolfSSL | 0:9d17e4342598 | 1898 | FreeRsaKey(ssl->peerRsaKey); |
wolfSSL | 0:9d17e4342598 | 1899 | XFREE(ssl->peerRsaKey, ssl->heap, DYNAMIC_TYPE_RSA); |
wolfSSL | 0:9d17e4342598 | 1900 | ssl->peerRsaKey = NULL; |
wolfSSL | 0:9d17e4342598 | 1901 | } |
wolfSSL | 0:9d17e4342598 | 1902 | #endif |
wolfSSL | 0:9d17e4342598 | 1903 | |
wolfSSL | 0:9d17e4342598 | 1904 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 1905 | if (ssl->peerEccKey) |
wolfSSL | 0:9d17e4342598 | 1906 | { |
wolfSSL | 0:9d17e4342598 | 1907 | if (ssl->peerEccKeyPresent) { |
wolfSSL | 0:9d17e4342598 | 1908 | ecc_free(ssl->peerEccKey); |
wolfSSL | 0:9d17e4342598 | 1909 | ssl->peerEccKeyPresent = 0; |
wolfSSL | 0:9d17e4342598 | 1910 | } |
wolfSSL | 0:9d17e4342598 | 1911 | XFREE(ssl->peerEccKey, ssl->heap, DYNAMIC_TYPE_ECC); |
wolfSSL | 0:9d17e4342598 | 1912 | ssl->peerEccKey = NULL; |
wolfSSL | 0:9d17e4342598 | 1913 | } |
wolfSSL | 0:9d17e4342598 | 1914 | if (ssl->peerEccDsaKey) |
wolfSSL | 0:9d17e4342598 | 1915 | { |
wolfSSL | 0:9d17e4342598 | 1916 | if (ssl->peerEccDsaKeyPresent) { |
wolfSSL | 0:9d17e4342598 | 1917 | ecc_free(ssl->peerEccDsaKey); |
wolfSSL | 0:9d17e4342598 | 1918 | ssl->peerEccDsaKeyPresent = 0; |
wolfSSL | 0:9d17e4342598 | 1919 | } |
wolfSSL | 0:9d17e4342598 | 1920 | XFREE(ssl->peerEccDsaKey, ssl->heap, DYNAMIC_TYPE_ECC); |
wolfSSL | 0:9d17e4342598 | 1921 | ssl->peerEccDsaKey = NULL; |
wolfSSL | 0:9d17e4342598 | 1922 | } |
wolfSSL | 0:9d17e4342598 | 1923 | if (ssl->eccTempKey) |
wolfSSL | 0:9d17e4342598 | 1924 | { |
wolfSSL | 0:9d17e4342598 | 1925 | if (ssl->eccTempKeyPresent) { |
wolfSSL | 0:9d17e4342598 | 1926 | ecc_free(ssl->eccTempKey); |
wolfSSL | 0:9d17e4342598 | 1927 | ssl->eccTempKeyPresent = 0; |
wolfSSL | 0:9d17e4342598 | 1928 | } |
wolfSSL | 0:9d17e4342598 | 1929 | XFREE(ssl->eccTempKey, ssl->heap, DYNAMIC_TYPE_ECC); |
wolfSSL | 0:9d17e4342598 | 1930 | ssl->eccTempKey = NULL; |
wolfSSL | 0:9d17e4342598 | 1931 | } |
wolfSSL | 0:9d17e4342598 | 1932 | if (ssl->eccDsaKey) |
wolfSSL | 0:9d17e4342598 | 1933 | { |
wolfSSL | 0:9d17e4342598 | 1934 | if (ssl->eccDsaKeyPresent) { |
wolfSSL | 0:9d17e4342598 | 1935 | ecc_free(ssl->eccDsaKey); |
wolfSSL | 0:9d17e4342598 | 1936 | ssl->eccDsaKeyPresent = 0; |
wolfSSL | 0:9d17e4342598 | 1937 | } |
wolfSSL | 0:9d17e4342598 | 1938 | XFREE(ssl->eccDsaKey, ssl->heap, DYNAMIC_TYPE_ECC); |
wolfSSL | 0:9d17e4342598 | 1939 | ssl->eccDsaKey = NULL; |
wolfSSL | 0:9d17e4342598 | 1940 | } |
wolfSSL | 0:9d17e4342598 | 1941 | #endif |
wolfSSL | 0:9d17e4342598 | 1942 | #ifdef HAVE_PK_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 1943 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 1944 | XFREE(ssl->buffers.peerEccDsaKey.buffer, ssl->heap, DYNAMIC_TYPE_ECC); |
wolfSSL | 0:9d17e4342598 | 1945 | ssl->buffers.peerEccDsaKey.buffer = NULL; |
wolfSSL | 0:9d17e4342598 | 1946 | #endif /* HAVE_ECC */ |
wolfSSL | 0:9d17e4342598 | 1947 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 1948 | XFREE(ssl->buffers.peerRsaKey.buffer, ssl->heap, DYNAMIC_TYPE_RSA); |
wolfSSL | 0:9d17e4342598 | 1949 | ssl->buffers.peerRsaKey.buffer = NULL; |
wolfSSL | 0:9d17e4342598 | 1950 | #endif /* NO_RSA */ |
wolfSSL | 0:9d17e4342598 | 1951 | #endif /* HAVE_PK_CALLBACKS */ |
wolfSSL | 0:9d17e4342598 | 1952 | } |
wolfSSL | 0:9d17e4342598 | 1953 | |
wolfSSL | 0:9d17e4342598 | 1954 | |
wolfSSL | 0:9d17e4342598 | 1955 | void FreeSSL(CYASSL* ssl) |
wolfSSL | 0:9d17e4342598 | 1956 | { |
wolfSSL | 0:9d17e4342598 | 1957 | FreeSSL_Ctx(ssl->ctx); /* will decrement and free underyling CTX if 0 */ |
wolfSSL | 0:9d17e4342598 | 1958 | SSL_ResourceFree(ssl); |
wolfSSL | 0:9d17e4342598 | 1959 | XFREE(ssl, ssl->heap, DYNAMIC_TYPE_SSL); |
wolfSSL | 0:9d17e4342598 | 1960 | } |
wolfSSL | 0:9d17e4342598 | 1961 | |
wolfSSL | 0:9d17e4342598 | 1962 | |
wolfSSL | 0:9d17e4342598 | 1963 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 1964 | |
wolfSSL | 0:9d17e4342598 | 1965 | int DtlsPoolInit(CYASSL* ssl) |
wolfSSL | 0:9d17e4342598 | 1966 | { |
wolfSSL | 0:9d17e4342598 | 1967 | if (ssl->dtls_pool == NULL) { |
wolfSSL | 0:9d17e4342598 | 1968 | DtlsPool *pool = (DtlsPool*)XMALLOC(sizeof(DtlsPool), |
wolfSSL | 0:9d17e4342598 | 1969 | ssl->heap, DYNAMIC_TYPE_DTLS_POOL); |
wolfSSL | 0:9d17e4342598 | 1970 | if (pool == NULL) { |
wolfSSL | 0:9d17e4342598 | 1971 | CYASSL_MSG("DTLS Buffer Pool Memory error"); |
wolfSSL | 0:9d17e4342598 | 1972 | return MEMORY_E; |
wolfSSL | 0:9d17e4342598 | 1973 | } |
wolfSSL | 0:9d17e4342598 | 1974 | else { |
wolfSSL | 0:9d17e4342598 | 1975 | int i; |
wolfSSL | 0:9d17e4342598 | 1976 | |
wolfSSL | 0:9d17e4342598 | 1977 | for (i = 0; i < DTLS_POOL_SZ; i++) { |
wolfSSL | 0:9d17e4342598 | 1978 | pool->buf[i].length = 0; |
wolfSSL | 0:9d17e4342598 | 1979 | pool->buf[i].buffer = NULL; |
wolfSSL | 0:9d17e4342598 | 1980 | } |
wolfSSL | 0:9d17e4342598 | 1981 | pool->used = 0; |
wolfSSL | 0:9d17e4342598 | 1982 | ssl->dtls_pool = pool; |
wolfSSL | 0:9d17e4342598 | 1983 | } |
wolfSSL | 0:9d17e4342598 | 1984 | } |
wolfSSL | 0:9d17e4342598 | 1985 | return 0; |
wolfSSL | 0:9d17e4342598 | 1986 | } |
wolfSSL | 0:9d17e4342598 | 1987 | |
wolfSSL | 0:9d17e4342598 | 1988 | |
wolfSSL | 0:9d17e4342598 | 1989 | int DtlsPoolSave(CYASSL* ssl, const byte *src, int sz) |
wolfSSL | 0:9d17e4342598 | 1990 | { |
wolfSSL | 0:9d17e4342598 | 1991 | DtlsPool *pool = ssl->dtls_pool; |
wolfSSL | 0:9d17e4342598 | 1992 | if (pool != NULL && pool->used < DTLS_POOL_SZ) { |
wolfSSL | 0:9d17e4342598 | 1993 | buffer *pBuf = &pool->buf[pool->used]; |
wolfSSL | 0:9d17e4342598 | 1994 | pBuf->buffer = (byte*)XMALLOC(sz, ssl->heap, DYNAMIC_TYPE_OUT_BUFFER); |
wolfSSL | 0:9d17e4342598 | 1995 | if (pBuf->buffer == NULL) { |
wolfSSL | 0:9d17e4342598 | 1996 | CYASSL_MSG("DTLS Buffer Memory error"); |
wolfSSL | 0:9d17e4342598 | 1997 | return MEMORY_ERROR; |
wolfSSL | 0:9d17e4342598 | 1998 | } |
wolfSSL | 0:9d17e4342598 | 1999 | XMEMCPY(pBuf->buffer, src, sz); |
wolfSSL | 0:9d17e4342598 | 2000 | pBuf->length = (word32)sz; |
wolfSSL | 0:9d17e4342598 | 2001 | pool->used++; |
wolfSSL | 0:9d17e4342598 | 2002 | } |
wolfSSL | 0:9d17e4342598 | 2003 | return 0; |
wolfSSL | 0:9d17e4342598 | 2004 | } |
wolfSSL | 0:9d17e4342598 | 2005 | |
wolfSSL | 0:9d17e4342598 | 2006 | |
wolfSSL | 0:9d17e4342598 | 2007 | void DtlsPoolReset(CYASSL* ssl) |
wolfSSL | 0:9d17e4342598 | 2008 | { |
wolfSSL | 0:9d17e4342598 | 2009 | DtlsPool *pool = ssl->dtls_pool; |
wolfSSL | 0:9d17e4342598 | 2010 | if (pool != NULL) { |
wolfSSL | 0:9d17e4342598 | 2011 | buffer *pBuf; |
wolfSSL | 0:9d17e4342598 | 2012 | int i, used; |
wolfSSL | 0:9d17e4342598 | 2013 | |
wolfSSL | 0:9d17e4342598 | 2014 | used = pool->used; |
wolfSSL | 0:9d17e4342598 | 2015 | for (i = 0, pBuf = &pool->buf[0]; i < used; i++, pBuf++) { |
wolfSSL | 0:9d17e4342598 | 2016 | XFREE(pBuf->buffer, ssl->heap, DYNAMIC_TYPE_OUT_BUFFER); |
wolfSSL | 0:9d17e4342598 | 2017 | pBuf->buffer = NULL; |
wolfSSL | 0:9d17e4342598 | 2018 | pBuf->length = 0; |
wolfSSL | 0:9d17e4342598 | 2019 | } |
wolfSSL | 0:9d17e4342598 | 2020 | pool->used = 0; |
wolfSSL | 0:9d17e4342598 | 2021 | } |
wolfSSL | 0:9d17e4342598 | 2022 | ssl->dtls_timeout = ssl->dtls_timeout_init; |
wolfSSL | 0:9d17e4342598 | 2023 | } |
wolfSSL | 0:9d17e4342598 | 2024 | |
wolfSSL | 0:9d17e4342598 | 2025 | |
wolfSSL | 0:9d17e4342598 | 2026 | int DtlsPoolTimeout(CYASSL* ssl) |
wolfSSL | 0:9d17e4342598 | 2027 | { |
wolfSSL | 0:9d17e4342598 | 2028 | int result = -1; |
wolfSSL | 0:9d17e4342598 | 2029 | if (ssl->dtls_timeout < ssl->dtls_timeout_max) { |
wolfSSL | 0:9d17e4342598 | 2030 | ssl->dtls_timeout *= DTLS_TIMEOUT_MULTIPLIER; |
wolfSSL | 0:9d17e4342598 | 2031 | result = 0; |
wolfSSL | 0:9d17e4342598 | 2032 | } |
wolfSSL | 0:9d17e4342598 | 2033 | return result; |
wolfSSL | 0:9d17e4342598 | 2034 | } |
wolfSSL | 0:9d17e4342598 | 2035 | |
wolfSSL | 0:9d17e4342598 | 2036 | |
wolfSSL | 0:9d17e4342598 | 2037 | int DtlsPoolSend(CYASSL* ssl) |
wolfSSL | 0:9d17e4342598 | 2038 | { |
wolfSSL | 0:9d17e4342598 | 2039 | int ret; |
wolfSSL | 0:9d17e4342598 | 2040 | DtlsPool *pool = ssl->dtls_pool; |
wolfSSL | 0:9d17e4342598 | 2041 | |
wolfSSL | 0:9d17e4342598 | 2042 | if (pool != NULL && pool->used > 0) { |
wolfSSL | 0:9d17e4342598 | 2043 | int i; |
wolfSSL | 0:9d17e4342598 | 2044 | for (i = 0; i < pool->used; i++) { |
wolfSSL | 0:9d17e4342598 | 2045 | int sendResult; |
wolfSSL | 0:9d17e4342598 | 2046 | buffer* buf = &pool->buf[i]; |
wolfSSL | 0:9d17e4342598 | 2047 | |
wolfSSL | 0:9d17e4342598 | 2048 | DtlsRecordLayerHeader* dtls = (DtlsRecordLayerHeader*)buf->buffer; |
wolfSSL | 0:9d17e4342598 | 2049 | |
wolfSSL | 0:9d17e4342598 | 2050 | word16 message_epoch; |
wolfSSL | 0:9d17e4342598 | 2051 | ato16(dtls->epoch, &message_epoch); |
wolfSSL | 0:9d17e4342598 | 2052 | if (message_epoch == ssl->keys.dtls_epoch) { |
wolfSSL | 0:9d17e4342598 | 2053 | /* Increment record sequence number on retransmitted handshake |
wolfSSL | 0:9d17e4342598 | 2054 | * messages */ |
wolfSSL | 0:9d17e4342598 | 2055 | c32to48(ssl->keys.dtls_sequence_number, dtls->sequence_number); |
wolfSSL | 0:9d17e4342598 | 2056 | ssl->keys.dtls_sequence_number++; |
wolfSSL | 0:9d17e4342598 | 2057 | } |
wolfSSL | 0:9d17e4342598 | 2058 | else { |
wolfSSL | 0:9d17e4342598 | 2059 | /* The Finished message is sent with the next epoch, keep its |
wolfSSL | 0:9d17e4342598 | 2060 | * sequence number */ |
wolfSSL | 0:9d17e4342598 | 2061 | } |
wolfSSL | 0:9d17e4342598 | 2062 | |
wolfSSL | 0:9d17e4342598 | 2063 | if ((ret = CheckAvailableSize(ssl, buf->length)) != 0) |
wolfSSL | 0:9d17e4342598 | 2064 | return ret; |
wolfSSL | 0:9d17e4342598 | 2065 | |
wolfSSL | 0:9d17e4342598 | 2066 | XMEMCPY(ssl->buffers.outputBuffer.buffer, buf->buffer, buf->length); |
wolfSSL | 0:9d17e4342598 | 2067 | ssl->buffers.outputBuffer.idx = 0; |
wolfSSL | 0:9d17e4342598 | 2068 | ssl->buffers.outputBuffer.length = buf->length; |
wolfSSL | 0:9d17e4342598 | 2069 | |
wolfSSL | 0:9d17e4342598 | 2070 | sendResult = SendBuffered(ssl); |
wolfSSL | 0:9d17e4342598 | 2071 | if (sendResult < 0) { |
wolfSSL | 0:9d17e4342598 | 2072 | return sendResult; |
wolfSSL | 0:9d17e4342598 | 2073 | } |
wolfSSL | 0:9d17e4342598 | 2074 | } |
wolfSSL | 0:9d17e4342598 | 2075 | } |
wolfSSL | 0:9d17e4342598 | 2076 | return 0; |
wolfSSL | 0:9d17e4342598 | 2077 | } |
wolfSSL | 0:9d17e4342598 | 2078 | |
wolfSSL | 0:9d17e4342598 | 2079 | |
wolfSSL | 0:9d17e4342598 | 2080 | /* functions for managing DTLS datagram reordering */ |
wolfSSL | 0:9d17e4342598 | 2081 | |
wolfSSL | 0:9d17e4342598 | 2082 | /* Need to allocate space for the handshake message header. The hashing |
wolfSSL | 0:9d17e4342598 | 2083 | * routines assume the message pointer is still within the buffer that |
wolfSSL | 0:9d17e4342598 | 2084 | * has the headers, and will include those headers in the hash. The store |
wolfSSL | 0:9d17e4342598 | 2085 | * routines need to take that into account as well. New will allocate |
wolfSSL | 0:9d17e4342598 | 2086 | * extra space for the headers. */ |
wolfSSL | 0:9d17e4342598 | 2087 | DtlsMsg* DtlsMsgNew(word32 sz, void* heap) |
wolfSSL | 0:9d17e4342598 | 2088 | { |
wolfSSL | 0:9d17e4342598 | 2089 | DtlsMsg* msg = NULL; |
wolfSSL | 0:9d17e4342598 | 2090 | |
wolfSSL | 0:9d17e4342598 | 2091 | msg = (DtlsMsg*)XMALLOC(sizeof(DtlsMsg), heap, DYNAMIC_TYPE_DTLS_MSG); |
wolfSSL | 0:9d17e4342598 | 2092 | |
wolfSSL | 0:9d17e4342598 | 2093 | if (msg != NULL) { |
wolfSSL | 0:9d17e4342598 | 2094 | msg->buf = (byte*)XMALLOC(sz + DTLS_HANDSHAKE_HEADER_SZ, |
wolfSSL | 0:9d17e4342598 | 2095 | heap, DYNAMIC_TYPE_NONE); |
wolfSSL | 0:9d17e4342598 | 2096 | if (msg->buf != NULL) { |
wolfSSL | 0:9d17e4342598 | 2097 | msg->next = NULL; |
wolfSSL | 0:9d17e4342598 | 2098 | msg->seq = 0; |
wolfSSL | 0:9d17e4342598 | 2099 | msg->sz = sz; |
wolfSSL | 0:9d17e4342598 | 2100 | msg->fragSz = 0; |
wolfSSL | 0:9d17e4342598 | 2101 | msg->msg = msg->buf + DTLS_HANDSHAKE_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 2102 | } |
wolfSSL | 0:9d17e4342598 | 2103 | else { |
wolfSSL | 0:9d17e4342598 | 2104 | XFREE(msg, heap, DYNAMIC_TYPE_DTLS_MSG); |
wolfSSL | 0:9d17e4342598 | 2105 | msg = NULL; |
wolfSSL | 0:9d17e4342598 | 2106 | } |
wolfSSL | 0:9d17e4342598 | 2107 | } |
wolfSSL | 0:9d17e4342598 | 2108 | |
wolfSSL | 0:9d17e4342598 | 2109 | return msg; |
wolfSSL | 0:9d17e4342598 | 2110 | } |
wolfSSL | 0:9d17e4342598 | 2111 | |
wolfSSL | 0:9d17e4342598 | 2112 | void DtlsMsgDelete(DtlsMsg* item, void* heap) |
wolfSSL | 0:9d17e4342598 | 2113 | { |
wolfSSL | 0:9d17e4342598 | 2114 | (void)heap; |
wolfSSL | 0:9d17e4342598 | 2115 | |
wolfSSL | 0:9d17e4342598 | 2116 | if (item != NULL) { |
wolfSSL | 0:9d17e4342598 | 2117 | if (item->buf != NULL) |
wolfSSL | 0:9d17e4342598 | 2118 | XFREE(item->buf, heap, DYNAMIC_TYPE_NONE); |
wolfSSL | 0:9d17e4342598 | 2119 | XFREE(item, heap, DYNAMIC_TYPE_DTLS_MSG); |
wolfSSL | 0:9d17e4342598 | 2120 | } |
wolfSSL | 0:9d17e4342598 | 2121 | } |
wolfSSL | 0:9d17e4342598 | 2122 | |
wolfSSL | 0:9d17e4342598 | 2123 | |
wolfSSL | 0:9d17e4342598 | 2124 | void DtlsMsgListDelete(DtlsMsg* head, void* heap) |
wolfSSL | 0:9d17e4342598 | 2125 | { |
wolfSSL | 0:9d17e4342598 | 2126 | DtlsMsg* next; |
wolfSSL | 0:9d17e4342598 | 2127 | while (head) { |
wolfSSL | 0:9d17e4342598 | 2128 | next = head->next; |
wolfSSL | 0:9d17e4342598 | 2129 | DtlsMsgDelete(head, heap); |
wolfSSL | 0:9d17e4342598 | 2130 | head = next; |
wolfSSL | 0:9d17e4342598 | 2131 | } |
wolfSSL | 0:9d17e4342598 | 2132 | } |
wolfSSL | 0:9d17e4342598 | 2133 | |
wolfSSL | 0:9d17e4342598 | 2134 | |
wolfSSL | 0:9d17e4342598 | 2135 | void DtlsMsgSet(DtlsMsg* msg, word32 seq, const byte* data, byte type, |
wolfSSL | 0:9d17e4342598 | 2136 | word32 fragOffset, word32 fragSz) |
wolfSSL | 0:9d17e4342598 | 2137 | { |
wolfSSL | 0:9d17e4342598 | 2138 | if (msg != NULL && data != NULL && msg->fragSz <= msg->sz) { |
wolfSSL | 0:9d17e4342598 | 2139 | msg->seq = seq; |
wolfSSL | 0:9d17e4342598 | 2140 | msg->type = type; |
wolfSSL | 0:9d17e4342598 | 2141 | msg->fragSz += fragSz; |
wolfSSL | 0:9d17e4342598 | 2142 | /* If fragOffset is zero, this is either a full message that is out |
wolfSSL | 0:9d17e4342598 | 2143 | * of order, or the first fragment of a fragmented message. Copy the |
wolfSSL | 0:9d17e4342598 | 2144 | * handshake message header as well as the message data. */ |
wolfSSL | 0:9d17e4342598 | 2145 | if (fragOffset == 0) |
wolfSSL | 0:9d17e4342598 | 2146 | XMEMCPY(msg->buf, data - DTLS_HANDSHAKE_HEADER_SZ, |
wolfSSL | 0:9d17e4342598 | 2147 | fragSz + DTLS_HANDSHAKE_HEADER_SZ); |
wolfSSL | 0:9d17e4342598 | 2148 | else { |
wolfSSL | 0:9d17e4342598 | 2149 | /* If fragOffet is non-zero, this is an additional fragment that |
wolfSSL | 0:9d17e4342598 | 2150 | * needs to be copied to its location in the message buffer. Also |
wolfSSL | 0:9d17e4342598 | 2151 | * copy the total size of the message over the fragment size. The |
wolfSSL | 0:9d17e4342598 | 2152 | * hash routines look at a defragmented message if it had actually |
wolfSSL | 0:9d17e4342598 | 2153 | * come across as a single handshake message. */ |
wolfSSL | 0:9d17e4342598 | 2154 | XMEMCPY(msg->msg + fragOffset, data, fragSz); |
wolfSSL | 0:9d17e4342598 | 2155 | c32to24(msg->sz, msg->msg - DTLS_HANDSHAKE_FRAG_SZ); |
wolfSSL | 0:9d17e4342598 | 2156 | } |
wolfSSL | 0:9d17e4342598 | 2157 | } |
wolfSSL | 0:9d17e4342598 | 2158 | } |
wolfSSL | 0:9d17e4342598 | 2159 | |
wolfSSL | 0:9d17e4342598 | 2160 | |
wolfSSL | 0:9d17e4342598 | 2161 | DtlsMsg* DtlsMsgFind(DtlsMsg* head, word32 seq) |
wolfSSL | 0:9d17e4342598 | 2162 | { |
wolfSSL | 0:9d17e4342598 | 2163 | while (head != NULL && head->seq != seq) { |
wolfSSL | 0:9d17e4342598 | 2164 | head = head->next; |
wolfSSL | 0:9d17e4342598 | 2165 | } |
wolfSSL | 0:9d17e4342598 | 2166 | return head; |
wolfSSL | 0:9d17e4342598 | 2167 | } |
wolfSSL | 0:9d17e4342598 | 2168 | |
wolfSSL | 0:9d17e4342598 | 2169 | |
wolfSSL | 0:9d17e4342598 | 2170 | DtlsMsg* DtlsMsgStore(DtlsMsg* head, word32 seq, const byte* data, |
wolfSSL | 0:9d17e4342598 | 2171 | word32 dataSz, byte type, word32 fragOffset, word32 fragSz, void* heap) |
wolfSSL | 0:9d17e4342598 | 2172 | { |
wolfSSL | 0:9d17e4342598 | 2173 | |
wolfSSL | 0:9d17e4342598 | 2174 | /* See if seq exists in the list. If it isn't in the list, make |
wolfSSL | 0:9d17e4342598 | 2175 | * a new item of size dataSz, copy fragSz bytes from data to msg->msg |
wolfSSL | 0:9d17e4342598 | 2176 | * starting at offset fragOffset, and add fragSz to msg->fragSz. If |
wolfSSL | 0:9d17e4342598 | 2177 | * the seq is in the list and it isn't full, copy fragSz bytes from |
wolfSSL | 0:9d17e4342598 | 2178 | * data to msg->msg starting at offset fragOffset, and add fragSz to |
wolfSSL | 0:9d17e4342598 | 2179 | * msg->fragSz. The new item should be inserted into the list in its |
wolfSSL | 0:9d17e4342598 | 2180 | * proper position. |
wolfSSL | 0:9d17e4342598 | 2181 | * |
wolfSSL | 0:9d17e4342598 | 2182 | * 1. Find seq in list, or where seq should go in list. If seq not in |
wolfSSL | 0:9d17e4342598 | 2183 | * list, create new item and insert into list. Either case, keep |
wolfSSL | 0:9d17e4342598 | 2184 | * pointer to item. |
wolfSSL | 0:9d17e4342598 | 2185 | * 2. If msg->fragSz + fragSz < sz, copy data to msg->msg at offset |
wolfSSL | 0:9d17e4342598 | 2186 | * fragOffset. Add fragSz to msg->fragSz. |
wolfSSL | 0:9d17e4342598 | 2187 | */ |
wolfSSL | 0:9d17e4342598 | 2188 | |
wolfSSL | 0:9d17e4342598 | 2189 | if (head != NULL) { |
wolfSSL | 0:9d17e4342598 | 2190 | DtlsMsg* cur = DtlsMsgFind(head, seq); |
wolfSSL | 0:9d17e4342598 | 2191 | if (cur == NULL) { |
wolfSSL | 0:9d17e4342598 | 2192 | cur = DtlsMsgNew(dataSz, heap); |
wolfSSL | 0:9d17e4342598 | 2193 | if (cur != NULL) { |
wolfSSL | 0:9d17e4342598 | 2194 | DtlsMsgSet(cur, seq, data, type, fragOffset, fragSz); |
wolfSSL | 0:9d17e4342598 | 2195 | head = DtlsMsgInsert(head, cur); |
wolfSSL | 0:9d17e4342598 | 2196 | } |
wolfSSL | 0:9d17e4342598 | 2197 | } |
wolfSSL | 0:9d17e4342598 | 2198 | else { |
wolfSSL | 0:9d17e4342598 | 2199 | DtlsMsgSet(cur, seq, data, type, fragOffset, fragSz); |
wolfSSL | 0:9d17e4342598 | 2200 | } |
wolfSSL | 0:9d17e4342598 | 2201 | } |
wolfSSL | 0:9d17e4342598 | 2202 | else { |
wolfSSL | 0:9d17e4342598 | 2203 | head = DtlsMsgNew(dataSz, heap); |
wolfSSL | 0:9d17e4342598 | 2204 | DtlsMsgSet(head, seq, data, type, fragOffset, fragSz); |
wolfSSL | 0:9d17e4342598 | 2205 | } |
wolfSSL | 0:9d17e4342598 | 2206 | |
wolfSSL | 0:9d17e4342598 | 2207 | return head; |
wolfSSL | 0:9d17e4342598 | 2208 | } |
wolfSSL | 0:9d17e4342598 | 2209 | |
wolfSSL | 0:9d17e4342598 | 2210 | |
wolfSSL | 0:9d17e4342598 | 2211 | /* DtlsMsgInsert() is an in-order insert. */ |
wolfSSL | 0:9d17e4342598 | 2212 | DtlsMsg* DtlsMsgInsert(DtlsMsg* head, DtlsMsg* item) |
wolfSSL | 0:9d17e4342598 | 2213 | { |
wolfSSL | 0:9d17e4342598 | 2214 | if (head == NULL || item->seq < head->seq) { |
wolfSSL | 0:9d17e4342598 | 2215 | item->next = head; |
wolfSSL | 0:9d17e4342598 | 2216 | head = item; |
wolfSSL | 0:9d17e4342598 | 2217 | } |
wolfSSL | 0:9d17e4342598 | 2218 | else if (head->next == NULL) { |
wolfSSL | 0:9d17e4342598 | 2219 | head->next = item; |
wolfSSL | 0:9d17e4342598 | 2220 | } |
wolfSSL | 0:9d17e4342598 | 2221 | else { |
wolfSSL | 0:9d17e4342598 | 2222 | DtlsMsg* cur = head->next; |
wolfSSL | 0:9d17e4342598 | 2223 | DtlsMsg* prev = head; |
wolfSSL | 0:9d17e4342598 | 2224 | while (cur) { |
wolfSSL | 0:9d17e4342598 | 2225 | if (item->seq < cur->seq) { |
wolfSSL | 0:9d17e4342598 | 2226 | item->next = cur; |
wolfSSL | 0:9d17e4342598 | 2227 | prev->next = item; |
wolfSSL | 0:9d17e4342598 | 2228 | break; |
wolfSSL | 0:9d17e4342598 | 2229 | } |
wolfSSL | 0:9d17e4342598 | 2230 | prev = cur; |
wolfSSL | 0:9d17e4342598 | 2231 | cur = cur->next; |
wolfSSL | 0:9d17e4342598 | 2232 | } |
wolfSSL | 0:9d17e4342598 | 2233 | if (cur == NULL) { |
wolfSSL | 0:9d17e4342598 | 2234 | prev->next = item; |
wolfSSL | 0:9d17e4342598 | 2235 | } |
wolfSSL | 0:9d17e4342598 | 2236 | } |
wolfSSL | 0:9d17e4342598 | 2237 | |
wolfSSL | 0:9d17e4342598 | 2238 | return head; |
wolfSSL | 0:9d17e4342598 | 2239 | } |
wolfSSL | 0:9d17e4342598 | 2240 | |
wolfSSL | 0:9d17e4342598 | 2241 | #endif /* CYASSL_DTLS */ |
wolfSSL | 0:9d17e4342598 | 2242 | |
wolfSSL | 0:9d17e4342598 | 2243 | #ifndef NO_OLD_TLS |
wolfSSL | 0:9d17e4342598 | 2244 | |
wolfSSL | 0:9d17e4342598 | 2245 | ProtocolVersion MakeSSLv3(void) |
wolfSSL | 0:9d17e4342598 | 2246 | { |
wolfSSL | 0:9d17e4342598 | 2247 | ProtocolVersion pv; |
wolfSSL | 0:9d17e4342598 | 2248 | pv.major = SSLv3_MAJOR; |
wolfSSL | 0:9d17e4342598 | 2249 | pv.minor = SSLv3_MINOR; |
wolfSSL | 0:9d17e4342598 | 2250 | |
wolfSSL | 0:9d17e4342598 | 2251 | return pv; |
wolfSSL | 0:9d17e4342598 | 2252 | } |
wolfSSL | 0:9d17e4342598 | 2253 | |
wolfSSL | 0:9d17e4342598 | 2254 | #endif /* NO_OLD_TLS */ |
wolfSSL | 0:9d17e4342598 | 2255 | |
wolfSSL | 0:9d17e4342598 | 2256 | |
wolfSSL | 0:9d17e4342598 | 2257 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 2258 | |
wolfSSL | 0:9d17e4342598 | 2259 | ProtocolVersion MakeDTLSv1(void) |
wolfSSL | 0:9d17e4342598 | 2260 | { |
wolfSSL | 0:9d17e4342598 | 2261 | ProtocolVersion pv; |
wolfSSL | 0:9d17e4342598 | 2262 | pv.major = DTLS_MAJOR; |
wolfSSL | 0:9d17e4342598 | 2263 | pv.minor = DTLS_MINOR; |
wolfSSL | 0:9d17e4342598 | 2264 | |
wolfSSL | 0:9d17e4342598 | 2265 | return pv; |
wolfSSL | 0:9d17e4342598 | 2266 | } |
wolfSSL | 0:9d17e4342598 | 2267 | |
wolfSSL | 0:9d17e4342598 | 2268 | ProtocolVersion MakeDTLSv1_2(void) |
wolfSSL | 0:9d17e4342598 | 2269 | { |
wolfSSL | 0:9d17e4342598 | 2270 | ProtocolVersion pv; |
wolfSSL | 0:9d17e4342598 | 2271 | pv.major = DTLS_MAJOR; |
wolfSSL | 0:9d17e4342598 | 2272 | pv.minor = DTLSv1_2_MINOR; |
wolfSSL | 0:9d17e4342598 | 2273 | |
wolfSSL | 0:9d17e4342598 | 2274 | return pv; |
wolfSSL | 0:9d17e4342598 | 2275 | } |
wolfSSL | 0:9d17e4342598 | 2276 | |
wolfSSL | 0:9d17e4342598 | 2277 | #endif /* CYASSL_DTLS */ |
wolfSSL | 0:9d17e4342598 | 2278 | |
wolfSSL | 0:9d17e4342598 | 2279 | |
wolfSSL | 0:9d17e4342598 | 2280 | |
wolfSSL | 0:9d17e4342598 | 2281 | |
wolfSSL | 0:9d17e4342598 | 2282 | #ifdef USE_WINDOWS_API |
wolfSSL | 0:9d17e4342598 | 2283 | |
wolfSSL | 0:9d17e4342598 | 2284 | word32 LowResTimer(void) |
wolfSSL | 0:9d17e4342598 | 2285 | { |
wolfSSL | 0:9d17e4342598 | 2286 | static int init = 0; |
wolfSSL | 0:9d17e4342598 | 2287 | static LARGE_INTEGER freq; |
wolfSSL | 0:9d17e4342598 | 2288 | LARGE_INTEGER count; |
wolfSSL | 0:9d17e4342598 | 2289 | |
wolfSSL | 0:9d17e4342598 | 2290 | if (!init) { |
wolfSSL | 0:9d17e4342598 | 2291 | QueryPerformanceFrequency(&freq); |
wolfSSL | 0:9d17e4342598 | 2292 | init = 1; |
wolfSSL | 0:9d17e4342598 | 2293 | } |
wolfSSL | 0:9d17e4342598 | 2294 | |
wolfSSL | 0:9d17e4342598 | 2295 | QueryPerformanceCounter(&count); |
wolfSSL | 0:9d17e4342598 | 2296 | |
wolfSSL | 0:9d17e4342598 | 2297 | return (word32)(count.QuadPart / freq.QuadPart); |
wolfSSL | 0:9d17e4342598 | 2298 | } |
wolfSSL | 0:9d17e4342598 | 2299 | |
wolfSSL | 0:9d17e4342598 | 2300 | #elif defined(HAVE_RTP_SYS) |
wolfSSL | 0:9d17e4342598 | 2301 | |
wolfSSL | 0:9d17e4342598 | 2302 | #include "rtptime.h" |
wolfSSL | 0:9d17e4342598 | 2303 | |
wolfSSL | 0:9d17e4342598 | 2304 | word32 LowResTimer(void) |
wolfSSL | 0:9d17e4342598 | 2305 | { |
wolfSSL | 0:9d17e4342598 | 2306 | return (word32)rtp_get_system_sec(); |
wolfSSL | 0:9d17e4342598 | 2307 | } |
wolfSSL | 0:9d17e4342598 | 2308 | |
wolfSSL | 0:9d17e4342598 | 2309 | |
wolfSSL | 0:9d17e4342598 | 2310 | #elif defined(MICRIUM) |
wolfSSL | 0:9d17e4342598 | 2311 | |
wolfSSL | 0:9d17e4342598 | 2312 | word32 LowResTimer(void) |
wolfSSL | 0:9d17e4342598 | 2313 | { |
wolfSSL | 0:9d17e4342598 | 2314 | NET_SECURE_OS_TICK clk; |
wolfSSL | 0:9d17e4342598 | 2315 | |
wolfSSL | 0:9d17e4342598 | 2316 | #if (NET_SECURE_MGR_CFG_EN == DEF_ENABLED) |
wolfSSL | 0:9d17e4342598 | 2317 | clk = NetSecure_OS_TimeGet(); |
wolfSSL | 0:9d17e4342598 | 2318 | #endif |
wolfSSL | 0:9d17e4342598 | 2319 | return (word32)clk; |
wolfSSL | 0:9d17e4342598 | 2320 | } |
wolfSSL | 0:9d17e4342598 | 2321 | |
wolfSSL | 0:9d17e4342598 | 2322 | |
wolfSSL | 0:9d17e4342598 | 2323 | #elif defined(MICROCHIP_TCPIP_V5) |
wolfSSL | 0:9d17e4342598 | 2324 | |
wolfSSL | 0:9d17e4342598 | 2325 | word32 LowResTimer(void) |
wolfSSL | 0:9d17e4342598 | 2326 | { |
wolfSSL | 0:9d17e4342598 | 2327 | return (word32) TickGet(); |
wolfSSL | 0:9d17e4342598 | 2328 | } |
wolfSSL | 0:9d17e4342598 | 2329 | |
wolfSSL | 0:9d17e4342598 | 2330 | |
wolfSSL | 0:9d17e4342598 | 2331 | #elif defined(MICROCHIP_TCPIP) |
wolfSSL | 0:9d17e4342598 | 2332 | |
wolfSSL | 0:9d17e4342598 | 2333 | #if defined(MICROCHIP_MPLAB_HARMONY) |
wolfSSL | 0:9d17e4342598 | 2334 | |
wolfSSL | 0:9d17e4342598 | 2335 | #include <system/tmr/sys_tmr.h> |
wolfSSL | 0:9d17e4342598 | 2336 | |
wolfSSL | 0:9d17e4342598 | 2337 | word32 LowResTimer(void) |
wolfSSL | 0:9d17e4342598 | 2338 | { |
wolfSSL | 0:9d17e4342598 | 2339 | return (word32) SYS_TMR_TickCountGet(); |
wolfSSL | 0:9d17e4342598 | 2340 | } |
wolfSSL | 0:9d17e4342598 | 2341 | |
wolfSSL | 0:9d17e4342598 | 2342 | #else |
wolfSSL | 0:9d17e4342598 | 2343 | |
wolfSSL | 0:9d17e4342598 | 2344 | word32 LowResTimer(void) |
wolfSSL | 0:9d17e4342598 | 2345 | { |
wolfSSL | 0:9d17e4342598 | 2346 | return (word32) SYS_TICK_Get(); |
wolfSSL | 0:9d17e4342598 | 2347 | } |
wolfSSL | 0:9d17e4342598 | 2348 | |
wolfSSL | 0:9d17e4342598 | 2349 | #endif |
wolfSSL | 0:9d17e4342598 | 2350 | |
wolfSSL | 0:9d17e4342598 | 2351 | #elif defined(FREESCALE_MQX) |
wolfSSL | 0:9d17e4342598 | 2352 | |
wolfSSL | 0:9d17e4342598 | 2353 | word32 LowResTimer(void) |
wolfSSL | 0:9d17e4342598 | 2354 | { |
wolfSSL | 0:9d17e4342598 | 2355 | TIME_STRUCT mqxTime; |
wolfSSL | 0:9d17e4342598 | 2356 | |
wolfSSL | 0:9d17e4342598 | 2357 | _time_get_elapsed(&mqxTime); |
wolfSSL | 0:9d17e4342598 | 2358 | |
wolfSSL | 0:9d17e4342598 | 2359 | return (word32) mqxTime.SECONDS; |
wolfSSL | 0:9d17e4342598 | 2360 | } |
wolfSSL | 0:9d17e4342598 | 2361 | |
wolfSSL | 0:9d17e4342598 | 2362 | |
wolfSSL | 0:9d17e4342598 | 2363 | #elif defined(USER_TICKS) |
wolfSSL | 0:9d17e4342598 | 2364 | #if 0 |
wolfSSL | 0:9d17e4342598 | 2365 | word32 LowResTimer(void) |
wolfSSL | 0:9d17e4342598 | 2366 | { |
wolfSSL | 0:9d17e4342598 | 2367 | /* |
wolfSSL | 0:9d17e4342598 | 2368 | write your own clock tick function if don't want time(0) |
wolfSSL | 0:9d17e4342598 | 2369 | needs second accuracy but doesn't have to correlated to EPOCH |
wolfSSL | 0:9d17e4342598 | 2370 | */ |
wolfSSL | 0:9d17e4342598 | 2371 | } |
wolfSSL | 0:9d17e4342598 | 2372 | #endif |
wolfSSL | 0:9d17e4342598 | 2373 | #else /* !USE_WINDOWS_API && !HAVE_RTP_SYS && !MICRIUM && !USER_TICKS */ |
wolfSSL | 0:9d17e4342598 | 2374 | |
wolfSSL | 0:9d17e4342598 | 2375 | #include <time.h> |
wolfSSL | 0:9d17e4342598 | 2376 | |
wolfSSL | 0:9d17e4342598 | 2377 | word32 LowResTimer(void) |
wolfSSL | 0:9d17e4342598 | 2378 | { |
wolfSSL | 0:9d17e4342598 | 2379 | return (word32)time(0); |
wolfSSL | 0:9d17e4342598 | 2380 | } |
wolfSSL | 0:9d17e4342598 | 2381 | |
wolfSSL | 0:9d17e4342598 | 2382 | |
wolfSSL | 0:9d17e4342598 | 2383 | #endif /* USE_WINDOWS_API */ |
wolfSSL | 0:9d17e4342598 | 2384 | |
wolfSSL | 0:9d17e4342598 | 2385 | |
wolfSSL | 0:9d17e4342598 | 2386 | /* add output to md5 and sha handshake hashes, exclude record header */ |
wolfSSL | 0:9d17e4342598 | 2387 | static void HashOutput(CYASSL* ssl, const byte* output, int sz, int ivSz) |
wolfSSL | 0:9d17e4342598 | 2388 | { |
wolfSSL | 0:9d17e4342598 | 2389 | const byte* adj = output + RECORD_HEADER_SZ + ivSz; |
wolfSSL | 0:9d17e4342598 | 2390 | sz -= RECORD_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 2391 | |
wolfSSL | 0:9d17e4342598 | 2392 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 2393 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 2394 | adj += DTLS_RECORD_EXTRA; |
wolfSSL | 0:9d17e4342598 | 2395 | sz -= DTLS_RECORD_EXTRA; |
wolfSSL | 0:9d17e4342598 | 2396 | } |
wolfSSL | 0:9d17e4342598 | 2397 | #endif |
wolfSSL | 0:9d17e4342598 | 2398 | #ifndef NO_OLD_TLS |
wolfSSL | 0:9d17e4342598 | 2399 | #ifndef NO_SHA |
wolfSSL | 0:9d17e4342598 | 2400 | ShaUpdate(&ssl->hashSha, adj, sz); |
wolfSSL | 0:9d17e4342598 | 2401 | #endif |
wolfSSL | 0:9d17e4342598 | 2402 | #ifndef NO_MD5 |
wolfSSL | 0:9d17e4342598 | 2403 | Md5Update(&ssl->hashMd5, adj, sz); |
wolfSSL | 0:9d17e4342598 | 2404 | #endif |
wolfSSL | 0:9d17e4342598 | 2405 | #endif |
wolfSSL | 0:9d17e4342598 | 2406 | |
wolfSSL | 0:9d17e4342598 | 2407 | if (IsAtLeastTLSv1_2(ssl)) { |
wolfSSL | 0:9d17e4342598 | 2408 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 2409 | Sha256Update(&ssl->hashSha256, adj, sz); |
wolfSSL | 0:9d17e4342598 | 2410 | #endif |
wolfSSL | 0:9d17e4342598 | 2411 | #ifdef CYASSL_SHA384 |
wolfSSL | 0:9d17e4342598 | 2412 | Sha384Update(&ssl->hashSha384, adj, sz); |
wolfSSL | 0:9d17e4342598 | 2413 | #endif |
wolfSSL | 0:9d17e4342598 | 2414 | } |
wolfSSL | 0:9d17e4342598 | 2415 | } |
wolfSSL | 0:9d17e4342598 | 2416 | |
wolfSSL | 0:9d17e4342598 | 2417 | |
wolfSSL | 0:9d17e4342598 | 2418 | /* add input to md5 and sha handshake hashes, include handshake header */ |
wolfSSL | 0:9d17e4342598 | 2419 | static void HashInput(CYASSL* ssl, const byte* input, int sz) |
wolfSSL | 0:9d17e4342598 | 2420 | { |
wolfSSL | 0:9d17e4342598 | 2421 | const byte* adj = input - HANDSHAKE_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 2422 | sz += HANDSHAKE_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 2423 | |
wolfSSL | 0:9d17e4342598 | 2424 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 2425 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 2426 | adj -= DTLS_HANDSHAKE_EXTRA; |
wolfSSL | 0:9d17e4342598 | 2427 | sz += DTLS_HANDSHAKE_EXTRA; |
wolfSSL | 0:9d17e4342598 | 2428 | } |
wolfSSL | 0:9d17e4342598 | 2429 | #endif |
wolfSSL | 0:9d17e4342598 | 2430 | |
wolfSSL | 0:9d17e4342598 | 2431 | #ifndef NO_OLD_TLS |
wolfSSL | 0:9d17e4342598 | 2432 | #ifndef NO_SHA |
wolfSSL | 0:9d17e4342598 | 2433 | ShaUpdate(&ssl->hashSha, adj, sz); |
wolfSSL | 0:9d17e4342598 | 2434 | #endif |
wolfSSL | 0:9d17e4342598 | 2435 | #ifndef NO_MD5 |
wolfSSL | 0:9d17e4342598 | 2436 | Md5Update(&ssl->hashMd5, adj, sz); |
wolfSSL | 0:9d17e4342598 | 2437 | #endif |
wolfSSL | 0:9d17e4342598 | 2438 | #endif |
wolfSSL | 0:9d17e4342598 | 2439 | |
wolfSSL | 0:9d17e4342598 | 2440 | if (IsAtLeastTLSv1_2(ssl)) { |
wolfSSL | 0:9d17e4342598 | 2441 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 2442 | Sha256Update(&ssl->hashSha256, adj, sz); |
wolfSSL | 0:9d17e4342598 | 2443 | #endif |
wolfSSL | 0:9d17e4342598 | 2444 | #ifdef CYASSL_SHA384 |
wolfSSL | 0:9d17e4342598 | 2445 | Sha384Update(&ssl->hashSha384, adj, sz); |
wolfSSL | 0:9d17e4342598 | 2446 | #endif |
wolfSSL | 0:9d17e4342598 | 2447 | } |
wolfSSL | 0:9d17e4342598 | 2448 | } |
wolfSSL | 0:9d17e4342598 | 2449 | |
wolfSSL | 0:9d17e4342598 | 2450 | |
wolfSSL | 0:9d17e4342598 | 2451 | /* add record layer header for message */ |
wolfSSL | 0:9d17e4342598 | 2452 | static void AddRecordHeader(byte* output, word32 length, byte type, CYASSL* ssl) |
wolfSSL | 0:9d17e4342598 | 2453 | { |
wolfSSL | 0:9d17e4342598 | 2454 | RecordLayerHeader* rl; |
wolfSSL | 0:9d17e4342598 | 2455 | |
wolfSSL | 0:9d17e4342598 | 2456 | /* record layer header */ |
wolfSSL | 0:9d17e4342598 | 2457 | rl = (RecordLayerHeader*)output; |
wolfSSL | 0:9d17e4342598 | 2458 | rl->type = type; |
wolfSSL | 0:9d17e4342598 | 2459 | rl->pvMajor = ssl->version.major; /* type and version same in each */ |
wolfSSL | 0:9d17e4342598 | 2460 | rl->pvMinor = ssl->version.minor; |
wolfSSL | 0:9d17e4342598 | 2461 | |
wolfSSL | 0:9d17e4342598 | 2462 | if (!ssl->options.dtls) |
wolfSSL | 0:9d17e4342598 | 2463 | c16toa((word16)length, rl->length); |
wolfSSL | 0:9d17e4342598 | 2464 | else { |
wolfSSL | 0:9d17e4342598 | 2465 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 2466 | DtlsRecordLayerHeader* dtls; |
wolfSSL | 0:9d17e4342598 | 2467 | |
wolfSSL | 0:9d17e4342598 | 2468 | /* dtls record layer header extensions */ |
wolfSSL | 0:9d17e4342598 | 2469 | dtls = (DtlsRecordLayerHeader*)output; |
wolfSSL | 0:9d17e4342598 | 2470 | c16toa(ssl->keys.dtls_epoch, dtls->epoch); |
wolfSSL | 0:9d17e4342598 | 2471 | c32to48(ssl->keys.dtls_sequence_number++, dtls->sequence_number); |
wolfSSL | 0:9d17e4342598 | 2472 | c16toa((word16)length, dtls->length); |
wolfSSL | 0:9d17e4342598 | 2473 | #endif |
wolfSSL | 0:9d17e4342598 | 2474 | } |
wolfSSL | 0:9d17e4342598 | 2475 | } |
wolfSSL | 0:9d17e4342598 | 2476 | |
wolfSSL | 0:9d17e4342598 | 2477 | |
wolfSSL | 0:9d17e4342598 | 2478 | /* add handshake header for message */ |
wolfSSL | 0:9d17e4342598 | 2479 | static void AddHandShakeHeader(byte* output, word32 length, byte type, |
wolfSSL | 0:9d17e4342598 | 2480 | CYASSL* ssl) |
wolfSSL | 0:9d17e4342598 | 2481 | { |
wolfSSL | 0:9d17e4342598 | 2482 | HandShakeHeader* hs; |
wolfSSL | 0:9d17e4342598 | 2483 | (void)ssl; |
wolfSSL | 0:9d17e4342598 | 2484 | |
wolfSSL | 0:9d17e4342598 | 2485 | /* handshake header */ |
wolfSSL | 0:9d17e4342598 | 2486 | hs = (HandShakeHeader*)output; |
wolfSSL | 0:9d17e4342598 | 2487 | hs->type = type; |
wolfSSL | 0:9d17e4342598 | 2488 | c32to24(length, hs->length); /* type and length same for each */ |
wolfSSL | 0:9d17e4342598 | 2489 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 2490 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 2491 | DtlsHandShakeHeader* dtls; |
wolfSSL | 0:9d17e4342598 | 2492 | |
wolfSSL | 0:9d17e4342598 | 2493 | /* dtls handshake header extensions */ |
wolfSSL | 0:9d17e4342598 | 2494 | dtls = (DtlsHandShakeHeader*)output; |
wolfSSL | 0:9d17e4342598 | 2495 | c16toa(ssl->keys.dtls_handshake_number++, dtls->message_seq); |
wolfSSL | 0:9d17e4342598 | 2496 | c32to24(0, dtls->fragment_offset); |
wolfSSL | 0:9d17e4342598 | 2497 | c32to24(length, dtls->fragment_length); |
wolfSSL | 0:9d17e4342598 | 2498 | } |
wolfSSL | 0:9d17e4342598 | 2499 | #endif |
wolfSSL | 0:9d17e4342598 | 2500 | } |
wolfSSL | 0:9d17e4342598 | 2501 | |
wolfSSL | 0:9d17e4342598 | 2502 | |
wolfSSL | 0:9d17e4342598 | 2503 | /* add both headers for handshake message */ |
wolfSSL | 0:9d17e4342598 | 2504 | static void AddHeaders(byte* output, word32 length, byte type, CYASSL* ssl) |
wolfSSL | 0:9d17e4342598 | 2505 | { |
wolfSSL | 0:9d17e4342598 | 2506 | if (!ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 2507 | AddRecordHeader(output, length + HANDSHAKE_HEADER_SZ, handshake, ssl); |
wolfSSL | 0:9d17e4342598 | 2508 | AddHandShakeHeader(output + RECORD_HEADER_SZ, length, type, ssl); |
wolfSSL | 0:9d17e4342598 | 2509 | } |
wolfSSL | 0:9d17e4342598 | 2510 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 2511 | else { |
wolfSSL | 0:9d17e4342598 | 2512 | AddRecordHeader(output, length+DTLS_HANDSHAKE_HEADER_SZ, handshake,ssl); |
wolfSSL | 0:9d17e4342598 | 2513 | AddHandShakeHeader(output + DTLS_RECORD_HEADER_SZ, length, type, ssl); |
wolfSSL | 0:9d17e4342598 | 2514 | } |
wolfSSL | 0:9d17e4342598 | 2515 | #endif |
wolfSSL | 0:9d17e4342598 | 2516 | } |
wolfSSL | 0:9d17e4342598 | 2517 | |
wolfSSL | 0:9d17e4342598 | 2518 | |
wolfSSL | 0:9d17e4342598 | 2519 | /* return bytes received, -1 on error */ |
wolfSSL | 0:9d17e4342598 | 2520 | static int Receive(CYASSL* ssl, byte* buf, word32 sz) |
wolfSSL | 0:9d17e4342598 | 2521 | { |
wolfSSL | 0:9d17e4342598 | 2522 | int recvd; |
wolfSSL | 0:9d17e4342598 | 2523 | |
wolfSSL | 0:9d17e4342598 | 2524 | if (ssl->ctx->CBIORecv == NULL) { |
wolfSSL | 0:9d17e4342598 | 2525 | CYASSL_MSG("Your IO Recv callback is null, please set"); |
wolfSSL | 0:9d17e4342598 | 2526 | return -1; |
wolfSSL | 0:9d17e4342598 | 2527 | } |
wolfSSL | 0:9d17e4342598 | 2528 | |
wolfSSL | 0:9d17e4342598 | 2529 | retry: |
wolfSSL | 0:9d17e4342598 | 2530 | recvd = ssl->ctx->CBIORecv(ssl, (char *)buf, (int)sz, ssl->IOCB_ReadCtx); |
wolfSSL | 0:9d17e4342598 | 2531 | if (recvd < 0) |
wolfSSL | 0:9d17e4342598 | 2532 | switch (recvd) { |
wolfSSL | 0:9d17e4342598 | 2533 | case CYASSL_CBIO_ERR_GENERAL: /* general/unknown error */ |
wolfSSL | 0:9d17e4342598 | 2534 | return -1; |
wolfSSL | 0:9d17e4342598 | 2535 | |
wolfSSL | 0:9d17e4342598 | 2536 | case CYASSL_CBIO_ERR_WANT_READ: /* want read, would block */ |
wolfSSL | 0:9d17e4342598 | 2537 | return WANT_READ; |
wolfSSL | 0:9d17e4342598 | 2538 | |
wolfSSL | 0:9d17e4342598 | 2539 | case CYASSL_CBIO_ERR_CONN_RST: /* connection reset */ |
wolfSSL | 0:9d17e4342598 | 2540 | #ifdef USE_WINDOWS_API |
wolfSSL | 0:9d17e4342598 | 2541 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 2542 | goto retry; |
wolfSSL | 0:9d17e4342598 | 2543 | } |
wolfSSL | 0:9d17e4342598 | 2544 | #endif |
wolfSSL | 0:9d17e4342598 | 2545 | ssl->options.connReset = 1; |
wolfSSL | 0:9d17e4342598 | 2546 | return -1; |
wolfSSL | 0:9d17e4342598 | 2547 | |
wolfSSL | 0:9d17e4342598 | 2548 | case CYASSL_CBIO_ERR_ISR: /* interrupt */ |
wolfSSL | 0:9d17e4342598 | 2549 | /* see if we got our timeout */ |
wolfSSL | 0:9d17e4342598 | 2550 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 2551 | if (ssl->toInfoOn) { |
wolfSSL | 0:9d17e4342598 | 2552 | struct itimerval timeout; |
wolfSSL | 0:9d17e4342598 | 2553 | getitimer(ITIMER_REAL, &timeout); |
wolfSSL | 0:9d17e4342598 | 2554 | if (timeout.it_value.tv_sec == 0 && |
wolfSSL | 0:9d17e4342598 | 2555 | timeout.it_value.tv_usec == 0) { |
wolfSSL | 0:9d17e4342598 | 2556 | XSTRNCPY(ssl->timeoutInfo.timeoutName, |
wolfSSL | 0:9d17e4342598 | 2557 | "recv() timeout", MAX_TIMEOUT_NAME_SZ); |
wolfSSL | 0:9d17e4342598 | 2558 | CYASSL_MSG("Got our timeout"); |
wolfSSL | 0:9d17e4342598 | 2559 | return WANT_READ; |
wolfSSL | 0:9d17e4342598 | 2560 | } |
wolfSSL | 0:9d17e4342598 | 2561 | } |
wolfSSL | 0:9d17e4342598 | 2562 | #endif |
wolfSSL | 0:9d17e4342598 | 2563 | goto retry; |
wolfSSL | 0:9d17e4342598 | 2564 | |
wolfSSL | 0:9d17e4342598 | 2565 | case CYASSL_CBIO_ERR_CONN_CLOSE: /* peer closed connection */ |
wolfSSL | 0:9d17e4342598 | 2566 | ssl->options.isClosed = 1; |
wolfSSL | 0:9d17e4342598 | 2567 | return -1; |
wolfSSL | 0:9d17e4342598 | 2568 | |
wolfSSL | 0:9d17e4342598 | 2569 | case CYASSL_CBIO_ERR_TIMEOUT: |
wolfSSL | 0:9d17e4342598 | 2570 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 2571 | if (DtlsPoolTimeout(ssl) == 0 && DtlsPoolSend(ssl) == 0) |
wolfSSL | 0:9d17e4342598 | 2572 | goto retry; |
wolfSSL | 0:9d17e4342598 | 2573 | else |
wolfSSL | 0:9d17e4342598 | 2574 | #endif |
wolfSSL | 0:9d17e4342598 | 2575 | return -1; |
wolfSSL | 0:9d17e4342598 | 2576 | |
wolfSSL | 0:9d17e4342598 | 2577 | default: |
wolfSSL | 0:9d17e4342598 | 2578 | return recvd; |
wolfSSL | 0:9d17e4342598 | 2579 | } |
wolfSSL | 0:9d17e4342598 | 2580 | |
wolfSSL | 0:9d17e4342598 | 2581 | return recvd; |
wolfSSL | 0:9d17e4342598 | 2582 | } |
wolfSSL | 0:9d17e4342598 | 2583 | |
wolfSSL | 0:9d17e4342598 | 2584 | |
wolfSSL | 0:9d17e4342598 | 2585 | /* Switch dynamic output buffer back to static, buffer is assumed clear */ |
wolfSSL | 0:9d17e4342598 | 2586 | void ShrinkOutputBuffer(CYASSL* ssl) |
wolfSSL | 0:9d17e4342598 | 2587 | { |
wolfSSL | 0:9d17e4342598 | 2588 | CYASSL_MSG("Shrinking output buffer\n"); |
wolfSSL | 0:9d17e4342598 | 2589 | XFREE(ssl->buffers.outputBuffer.buffer - ssl->buffers.outputBuffer.offset, |
wolfSSL | 0:9d17e4342598 | 2590 | ssl->heap, DYNAMIC_TYPE_OUT_BUFFER); |
wolfSSL | 0:9d17e4342598 | 2591 | ssl->buffers.outputBuffer.buffer = ssl->buffers.outputBuffer.staticBuffer; |
wolfSSL | 0:9d17e4342598 | 2592 | ssl->buffers.outputBuffer.bufferSize = STATIC_BUFFER_LEN; |
wolfSSL | 0:9d17e4342598 | 2593 | ssl->buffers.outputBuffer.dynamicFlag = 0; |
wolfSSL | 0:9d17e4342598 | 2594 | ssl->buffers.outputBuffer.offset = 0; |
wolfSSL | 0:9d17e4342598 | 2595 | } |
wolfSSL | 0:9d17e4342598 | 2596 | |
wolfSSL | 0:9d17e4342598 | 2597 | |
wolfSSL | 0:9d17e4342598 | 2598 | /* Switch dynamic input buffer back to static, keep any remaining input */ |
wolfSSL | 0:9d17e4342598 | 2599 | /* forced free means cleaning up */ |
wolfSSL | 0:9d17e4342598 | 2600 | void ShrinkInputBuffer(CYASSL* ssl, int forcedFree) |
wolfSSL | 0:9d17e4342598 | 2601 | { |
wolfSSL | 0:9d17e4342598 | 2602 | int usedLength = ssl->buffers.inputBuffer.length - |
wolfSSL | 0:9d17e4342598 | 2603 | ssl->buffers.inputBuffer.idx; |
wolfSSL | 0:9d17e4342598 | 2604 | if (!forcedFree && usedLength > STATIC_BUFFER_LEN) |
wolfSSL | 0:9d17e4342598 | 2605 | return; |
wolfSSL | 0:9d17e4342598 | 2606 | |
wolfSSL | 0:9d17e4342598 | 2607 | CYASSL_MSG("Shrinking input buffer\n"); |
wolfSSL | 0:9d17e4342598 | 2608 | |
wolfSSL | 0:9d17e4342598 | 2609 | if (!forcedFree && usedLength) |
wolfSSL | 0:9d17e4342598 | 2610 | XMEMCPY(ssl->buffers.inputBuffer.staticBuffer, |
wolfSSL | 0:9d17e4342598 | 2611 | ssl->buffers.inputBuffer.buffer + ssl->buffers.inputBuffer.idx, |
wolfSSL | 0:9d17e4342598 | 2612 | usedLength); |
wolfSSL | 0:9d17e4342598 | 2613 | |
wolfSSL | 0:9d17e4342598 | 2614 | XFREE(ssl->buffers.inputBuffer.buffer - ssl->buffers.inputBuffer.offset, |
wolfSSL | 0:9d17e4342598 | 2615 | ssl->heap, DYNAMIC_TYPE_IN_BUFFER); |
wolfSSL | 0:9d17e4342598 | 2616 | ssl->buffers.inputBuffer.buffer = ssl->buffers.inputBuffer.staticBuffer; |
wolfSSL | 0:9d17e4342598 | 2617 | ssl->buffers.inputBuffer.bufferSize = STATIC_BUFFER_LEN; |
wolfSSL | 0:9d17e4342598 | 2618 | ssl->buffers.inputBuffer.dynamicFlag = 0; |
wolfSSL | 0:9d17e4342598 | 2619 | ssl->buffers.inputBuffer.offset = 0; |
wolfSSL | 0:9d17e4342598 | 2620 | ssl->buffers.inputBuffer.idx = 0; |
wolfSSL | 0:9d17e4342598 | 2621 | ssl->buffers.inputBuffer.length = usedLength; |
wolfSSL | 0:9d17e4342598 | 2622 | } |
wolfSSL | 0:9d17e4342598 | 2623 | |
wolfSSL | 0:9d17e4342598 | 2624 | |
wolfSSL | 0:9d17e4342598 | 2625 | int SendBuffered(CYASSL* ssl) |
wolfSSL | 0:9d17e4342598 | 2626 | { |
wolfSSL | 0:9d17e4342598 | 2627 | if (ssl->ctx->CBIOSend == NULL) { |
wolfSSL | 0:9d17e4342598 | 2628 | CYASSL_MSG("Your IO Send callback is null, please set"); |
wolfSSL | 0:9d17e4342598 | 2629 | return SOCKET_ERROR_E; |
wolfSSL | 0:9d17e4342598 | 2630 | } |
wolfSSL | 0:9d17e4342598 | 2631 | |
wolfSSL | 0:9d17e4342598 | 2632 | while (ssl->buffers.outputBuffer.length > 0) { |
wolfSSL | 0:9d17e4342598 | 2633 | int sent = ssl->ctx->CBIOSend(ssl, |
wolfSSL | 0:9d17e4342598 | 2634 | (char*)ssl->buffers.outputBuffer.buffer + |
wolfSSL | 0:9d17e4342598 | 2635 | ssl->buffers.outputBuffer.idx, |
wolfSSL | 0:9d17e4342598 | 2636 | (int)ssl->buffers.outputBuffer.length, |
wolfSSL | 0:9d17e4342598 | 2637 | ssl->IOCB_WriteCtx); |
wolfSSL | 0:9d17e4342598 | 2638 | if (sent < 0) { |
wolfSSL | 0:9d17e4342598 | 2639 | switch (sent) { |
wolfSSL | 0:9d17e4342598 | 2640 | |
wolfSSL | 0:9d17e4342598 | 2641 | case CYASSL_CBIO_ERR_WANT_WRITE: /* would block */ |
wolfSSL | 0:9d17e4342598 | 2642 | return WANT_WRITE; |
wolfSSL | 0:9d17e4342598 | 2643 | |
wolfSSL | 0:9d17e4342598 | 2644 | case CYASSL_CBIO_ERR_CONN_RST: /* connection reset */ |
wolfSSL | 0:9d17e4342598 | 2645 | ssl->options.connReset = 1; |
wolfSSL | 0:9d17e4342598 | 2646 | break; |
wolfSSL | 0:9d17e4342598 | 2647 | |
wolfSSL | 0:9d17e4342598 | 2648 | case CYASSL_CBIO_ERR_ISR: /* interrupt */ |
wolfSSL | 0:9d17e4342598 | 2649 | /* see if we got our timeout */ |
wolfSSL | 0:9d17e4342598 | 2650 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 2651 | if (ssl->toInfoOn) { |
wolfSSL | 0:9d17e4342598 | 2652 | struct itimerval timeout; |
wolfSSL | 0:9d17e4342598 | 2653 | getitimer(ITIMER_REAL, &timeout); |
wolfSSL | 0:9d17e4342598 | 2654 | if (timeout.it_value.tv_sec == 0 && |
wolfSSL | 0:9d17e4342598 | 2655 | timeout.it_value.tv_usec == 0) { |
wolfSSL | 0:9d17e4342598 | 2656 | XSTRNCPY(ssl->timeoutInfo.timeoutName, |
wolfSSL | 0:9d17e4342598 | 2657 | "send() timeout", MAX_TIMEOUT_NAME_SZ); |
wolfSSL | 0:9d17e4342598 | 2658 | CYASSL_MSG("Got our timeout"); |
wolfSSL | 0:9d17e4342598 | 2659 | return WANT_WRITE; |
wolfSSL | 0:9d17e4342598 | 2660 | } |
wolfSSL | 0:9d17e4342598 | 2661 | } |
wolfSSL | 0:9d17e4342598 | 2662 | #endif |
wolfSSL | 0:9d17e4342598 | 2663 | continue; |
wolfSSL | 0:9d17e4342598 | 2664 | |
wolfSSL | 0:9d17e4342598 | 2665 | case CYASSL_CBIO_ERR_CONN_CLOSE: /* epipe / conn closed */ |
wolfSSL | 0:9d17e4342598 | 2666 | ssl->options.connReset = 1; /* treat same as reset */ |
wolfSSL | 0:9d17e4342598 | 2667 | break; |
wolfSSL | 0:9d17e4342598 | 2668 | |
wolfSSL | 0:9d17e4342598 | 2669 | default: |
wolfSSL | 0:9d17e4342598 | 2670 | return SOCKET_ERROR_E; |
wolfSSL | 0:9d17e4342598 | 2671 | } |
wolfSSL | 0:9d17e4342598 | 2672 | |
wolfSSL | 0:9d17e4342598 | 2673 | return SOCKET_ERROR_E; |
wolfSSL | 0:9d17e4342598 | 2674 | } |
wolfSSL | 0:9d17e4342598 | 2675 | |
wolfSSL | 0:9d17e4342598 | 2676 | ssl->buffers.outputBuffer.idx += sent; |
wolfSSL | 0:9d17e4342598 | 2677 | ssl->buffers.outputBuffer.length -= sent; |
wolfSSL | 0:9d17e4342598 | 2678 | } |
wolfSSL | 0:9d17e4342598 | 2679 | |
wolfSSL | 0:9d17e4342598 | 2680 | ssl->buffers.outputBuffer.idx = 0; |
wolfSSL | 0:9d17e4342598 | 2681 | |
wolfSSL | 0:9d17e4342598 | 2682 | if (ssl->buffers.outputBuffer.dynamicFlag) |
wolfSSL | 0:9d17e4342598 | 2683 | ShrinkOutputBuffer(ssl); |
wolfSSL | 0:9d17e4342598 | 2684 | |
wolfSSL | 0:9d17e4342598 | 2685 | return 0; |
wolfSSL | 0:9d17e4342598 | 2686 | } |
wolfSSL | 0:9d17e4342598 | 2687 | |
wolfSSL | 0:9d17e4342598 | 2688 | |
wolfSSL | 0:9d17e4342598 | 2689 | /* Grow the output buffer */ |
wolfSSL | 0:9d17e4342598 | 2690 | static INLINE int GrowOutputBuffer(CYASSL* ssl, int size) |
wolfSSL | 0:9d17e4342598 | 2691 | { |
wolfSSL | 0:9d17e4342598 | 2692 | byte* tmp; |
wolfSSL | 0:9d17e4342598 | 2693 | byte hdrSz = ssl->options.dtls ? DTLS_RECORD_HEADER_SZ : |
wolfSSL | 0:9d17e4342598 | 2694 | RECORD_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 2695 | byte align = CYASSL_GENERAL_ALIGNMENT; |
wolfSSL | 0:9d17e4342598 | 2696 | /* the encrypted data will be offset from the front of the buffer by |
wolfSSL | 0:9d17e4342598 | 2697 | the header, if the user wants encrypted alignment they need |
wolfSSL | 0:9d17e4342598 | 2698 | to define their alignment requirement */ |
wolfSSL | 0:9d17e4342598 | 2699 | |
wolfSSL | 0:9d17e4342598 | 2700 | if (align) { |
wolfSSL | 0:9d17e4342598 | 2701 | while (align < hdrSz) |
wolfSSL | 0:9d17e4342598 | 2702 | align *= 2; |
wolfSSL | 0:9d17e4342598 | 2703 | } |
wolfSSL | 0:9d17e4342598 | 2704 | |
wolfSSL | 0:9d17e4342598 | 2705 | tmp = (byte*) XMALLOC(size + ssl->buffers.outputBuffer.length + align, |
wolfSSL | 0:9d17e4342598 | 2706 | ssl->heap, DYNAMIC_TYPE_OUT_BUFFER); |
wolfSSL | 0:9d17e4342598 | 2707 | CYASSL_MSG("growing output buffer\n"); |
wolfSSL | 0:9d17e4342598 | 2708 | |
wolfSSL | 0:9d17e4342598 | 2709 | if (!tmp) return MEMORY_E; |
wolfSSL | 0:9d17e4342598 | 2710 | if (align) |
wolfSSL | 0:9d17e4342598 | 2711 | tmp += align - hdrSz; |
wolfSSL | 0:9d17e4342598 | 2712 | |
wolfSSL | 0:9d17e4342598 | 2713 | if (ssl->buffers.outputBuffer.length) |
wolfSSL | 0:9d17e4342598 | 2714 | XMEMCPY(tmp, ssl->buffers.outputBuffer.buffer, |
wolfSSL | 0:9d17e4342598 | 2715 | ssl->buffers.outputBuffer.length); |
wolfSSL | 0:9d17e4342598 | 2716 | |
wolfSSL | 0:9d17e4342598 | 2717 | if (ssl->buffers.outputBuffer.dynamicFlag) |
wolfSSL | 0:9d17e4342598 | 2718 | XFREE(ssl->buffers.outputBuffer.buffer - |
wolfSSL | 0:9d17e4342598 | 2719 | ssl->buffers.outputBuffer.offset, ssl->heap, |
wolfSSL | 0:9d17e4342598 | 2720 | DYNAMIC_TYPE_OUT_BUFFER); |
wolfSSL | 0:9d17e4342598 | 2721 | ssl->buffers.outputBuffer.dynamicFlag = 1; |
wolfSSL | 0:9d17e4342598 | 2722 | if (align) |
wolfSSL | 0:9d17e4342598 | 2723 | ssl->buffers.outputBuffer.offset = align - hdrSz; |
wolfSSL | 0:9d17e4342598 | 2724 | else |
wolfSSL | 0:9d17e4342598 | 2725 | ssl->buffers.outputBuffer.offset = 0; |
wolfSSL | 0:9d17e4342598 | 2726 | ssl->buffers.outputBuffer.buffer = tmp; |
wolfSSL | 0:9d17e4342598 | 2727 | ssl->buffers.outputBuffer.bufferSize = size + |
wolfSSL | 0:9d17e4342598 | 2728 | ssl->buffers.outputBuffer.length; |
wolfSSL | 0:9d17e4342598 | 2729 | return 0; |
wolfSSL | 0:9d17e4342598 | 2730 | } |
wolfSSL | 0:9d17e4342598 | 2731 | |
wolfSSL | 0:9d17e4342598 | 2732 | |
wolfSSL | 0:9d17e4342598 | 2733 | /* Grow the input buffer, should only be to read cert or big app data */ |
wolfSSL | 0:9d17e4342598 | 2734 | int GrowInputBuffer(CYASSL* ssl, int size, int usedLength) |
wolfSSL | 0:9d17e4342598 | 2735 | { |
wolfSSL | 0:9d17e4342598 | 2736 | byte* tmp; |
wolfSSL | 0:9d17e4342598 | 2737 | byte hdrSz = DTLS_RECORD_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 2738 | byte align = ssl->options.dtls ? CYASSL_GENERAL_ALIGNMENT : 0; |
wolfSSL | 0:9d17e4342598 | 2739 | /* the encrypted data will be offset from the front of the buffer by |
wolfSSL | 0:9d17e4342598 | 2740 | the dtls record header, if the user wants encrypted alignment they need |
wolfSSL | 0:9d17e4342598 | 2741 | to define their alignment requirement. in tls we read record header |
wolfSSL | 0:9d17e4342598 | 2742 | to get size of record and put actual data back at front, so don't need */ |
wolfSSL | 0:9d17e4342598 | 2743 | |
wolfSSL | 0:9d17e4342598 | 2744 | if (align) { |
wolfSSL | 0:9d17e4342598 | 2745 | while (align < hdrSz) |
wolfSSL | 0:9d17e4342598 | 2746 | align *= 2; |
wolfSSL | 0:9d17e4342598 | 2747 | } |
wolfSSL | 0:9d17e4342598 | 2748 | tmp = (byte*) XMALLOC(size + usedLength + align, ssl->heap, |
wolfSSL | 0:9d17e4342598 | 2749 | DYNAMIC_TYPE_IN_BUFFER); |
wolfSSL | 0:9d17e4342598 | 2750 | CYASSL_MSG("growing input buffer\n"); |
wolfSSL | 0:9d17e4342598 | 2751 | |
wolfSSL | 0:9d17e4342598 | 2752 | if (!tmp) return MEMORY_E; |
wolfSSL | 0:9d17e4342598 | 2753 | if (align) |
wolfSSL | 0:9d17e4342598 | 2754 | tmp += align - hdrSz; |
wolfSSL | 0:9d17e4342598 | 2755 | |
wolfSSL | 0:9d17e4342598 | 2756 | if (usedLength) |
wolfSSL | 0:9d17e4342598 | 2757 | XMEMCPY(tmp, ssl->buffers.inputBuffer.buffer + |
wolfSSL | 0:9d17e4342598 | 2758 | ssl->buffers.inputBuffer.idx, usedLength); |
wolfSSL | 0:9d17e4342598 | 2759 | |
wolfSSL | 0:9d17e4342598 | 2760 | if (ssl->buffers.inputBuffer.dynamicFlag) |
wolfSSL | 0:9d17e4342598 | 2761 | XFREE(ssl->buffers.inputBuffer.buffer - ssl->buffers.inputBuffer.offset, |
wolfSSL | 0:9d17e4342598 | 2762 | ssl->heap,DYNAMIC_TYPE_IN_BUFFER); |
wolfSSL | 0:9d17e4342598 | 2763 | |
wolfSSL | 0:9d17e4342598 | 2764 | ssl->buffers.inputBuffer.dynamicFlag = 1; |
wolfSSL | 0:9d17e4342598 | 2765 | if (align) |
wolfSSL | 0:9d17e4342598 | 2766 | ssl->buffers.inputBuffer.offset = align - hdrSz; |
wolfSSL | 0:9d17e4342598 | 2767 | else |
wolfSSL | 0:9d17e4342598 | 2768 | ssl->buffers.inputBuffer.offset = 0; |
wolfSSL | 0:9d17e4342598 | 2769 | ssl->buffers.inputBuffer.buffer = tmp; |
wolfSSL | 0:9d17e4342598 | 2770 | ssl->buffers.inputBuffer.bufferSize = size + usedLength; |
wolfSSL | 0:9d17e4342598 | 2771 | ssl->buffers.inputBuffer.idx = 0; |
wolfSSL | 0:9d17e4342598 | 2772 | ssl->buffers.inputBuffer.length = usedLength; |
wolfSSL | 0:9d17e4342598 | 2773 | |
wolfSSL | 0:9d17e4342598 | 2774 | return 0; |
wolfSSL | 0:9d17e4342598 | 2775 | } |
wolfSSL | 0:9d17e4342598 | 2776 | |
wolfSSL | 0:9d17e4342598 | 2777 | |
wolfSSL | 0:9d17e4342598 | 2778 | /* check available size into output buffer, make room if needed */ |
wolfSSL | 0:9d17e4342598 | 2779 | int CheckAvailableSize(CYASSL *ssl, int size) |
wolfSSL | 0:9d17e4342598 | 2780 | { |
wolfSSL | 0:9d17e4342598 | 2781 | if (ssl->buffers.outputBuffer.bufferSize - ssl->buffers.outputBuffer.length |
wolfSSL | 0:9d17e4342598 | 2782 | < (word32)size) { |
wolfSSL | 0:9d17e4342598 | 2783 | if (GrowOutputBuffer(ssl, size) < 0) |
wolfSSL | 0:9d17e4342598 | 2784 | return MEMORY_E; |
wolfSSL | 0:9d17e4342598 | 2785 | } |
wolfSSL | 0:9d17e4342598 | 2786 | |
wolfSSL | 0:9d17e4342598 | 2787 | return 0; |
wolfSSL | 0:9d17e4342598 | 2788 | } |
wolfSSL | 0:9d17e4342598 | 2789 | |
wolfSSL | 0:9d17e4342598 | 2790 | |
wolfSSL | 0:9d17e4342598 | 2791 | /* do all verify and sanity checks on record header */ |
wolfSSL | 0:9d17e4342598 | 2792 | static int GetRecordHeader(CYASSL* ssl, const byte* input, word32* inOutIdx, |
wolfSSL | 0:9d17e4342598 | 2793 | RecordLayerHeader* rh, word16 *size) |
wolfSSL | 0:9d17e4342598 | 2794 | { |
wolfSSL | 0:9d17e4342598 | 2795 | if (!ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 2796 | XMEMCPY(rh, input + *inOutIdx, RECORD_HEADER_SZ); |
wolfSSL | 0:9d17e4342598 | 2797 | *inOutIdx += RECORD_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 2798 | ato16(rh->length, size); |
wolfSSL | 0:9d17e4342598 | 2799 | } |
wolfSSL | 0:9d17e4342598 | 2800 | else { |
wolfSSL | 0:9d17e4342598 | 2801 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 2802 | /* type and version in same sport */ |
wolfSSL | 0:9d17e4342598 | 2803 | XMEMCPY(rh, input + *inOutIdx, ENUM_LEN + VERSION_SZ); |
wolfSSL | 0:9d17e4342598 | 2804 | *inOutIdx += ENUM_LEN + VERSION_SZ; |
wolfSSL | 0:9d17e4342598 | 2805 | ato16(input + *inOutIdx, &ssl->keys.dtls_state.curEpoch); |
wolfSSL | 0:9d17e4342598 | 2806 | *inOutIdx += 4; /* advance past epoch, skip first 2 seq bytes for now */ |
wolfSSL | 0:9d17e4342598 | 2807 | ato32(input + *inOutIdx, &ssl->keys.dtls_state.curSeq); |
wolfSSL | 0:9d17e4342598 | 2808 | *inOutIdx += 4; /* advance past rest of seq */ |
wolfSSL | 0:9d17e4342598 | 2809 | ato16(input + *inOutIdx, size); |
wolfSSL | 0:9d17e4342598 | 2810 | *inOutIdx += LENGTH_SZ; |
wolfSSL | 0:9d17e4342598 | 2811 | #endif |
wolfSSL | 0:9d17e4342598 | 2812 | } |
wolfSSL | 0:9d17e4342598 | 2813 | |
wolfSSL | 0:9d17e4342598 | 2814 | /* catch version mismatch */ |
wolfSSL | 0:9d17e4342598 | 2815 | if (rh->pvMajor != ssl->version.major || rh->pvMinor != ssl->version.minor){ |
wolfSSL | 0:9d17e4342598 | 2816 | if (ssl->options.side == CYASSL_SERVER_END && |
wolfSSL | 0:9d17e4342598 | 2817 | ssl->options.acceptState == ACCEPT_BEGIN) |
wolfSSL | 0:9d17e4342598 | 2818 | CYASSL_MSG("Client attempting to connect with different version"); |
wolfSSL | 0:9d17e4342598 | 2819 | else if (ssl->options.side == CYASSL_CLIENT_END && |
wolfSSL | 0:9d17e4342598 | 2820 | ssl->options.downgrade && |
wolfSSL | 0:9d17e4342598 | 2821 | ssl->options.connectState < FIRST_REPLY_DONE) |
wolfSSL | 0:9d17e4342598 | 2822 | CYASSL_MSG("Server attempting to accept with different version"); |
wolfSSL | 0:9d17e4342598 | 2823 | else { |
wolfSSL | 0:9d17e4342598 | 2824 | CYASSL_MSG("SSL version error"); |
wolfSSL | 0:9d17e4342598 | 2825 | return VERSION_ERROR; /* only use requested version */ |
wolfSSL | 0:9d17e4342598 | 2826 | } |
wolfSSL | 0:9d17e4342598 | 2827 | } |
wolfSSL | 0:9d17e4342598 | 2828 | |
wolfSSL | 0:9d17e4342598 | 2829 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 2830 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 2831 | if (DtlsCheckWindow(&ssl->keys.dtls_state) != 1) |
wolfSSL | 0:9d17e4342598 | 2832 | return SEQUENCE_ERROR; |
wolfSSL | 0:9d17e4342598 | 2833 | } |
wolfSSL | 0:9d17e4342598 | 2834 | #endif |
wolfSSL | 0:9d17e4342598 | 2835 | |
wolfSSL | 0:9d17e4342598 | 2836 | /* record layer length check */ |
wolfSSL | 0:9d17e4342598 | 2837 | #ifdef HAVE_MAX_FRAGMENT |
wolfSSL | 0:9d17e4342598 | 2838 | if (*size > (ssl->max_fragment + MAX_COMP_EXTRA + MAX_MSG_EXTRA)) |
wolfSSL | 0:9d17e4342598 | 2839 | return LENGTH_ERROR; |
wolfSSL | 0:9d17e4342598 | 2840 | #else |
wolfSSL | 0:9d17e4342598 | 2841 | if (*size > (MAX_RECORD_SIZE + MAX_COMP_EXTRA + MAX_MSG_EXTRA)) |
wolfSSL | 0:9d17e4342598 | 2842 | return LENGTH_ERROR; |
wolfSSL | 0:9d17e4342598 | 2843 | #endif |
wolfSSL | 0:9d17e4342598 | 2844 | |
wolfSSL | 0:9d17e4342598 | 2845 | /* verify record type here as well */ |
wolfSSL | 0:9d17e4342598 | 2846 | switch (rh->type) { |
wolfSSL | 0:9d17e4342598 | 2847 | case handshake: |
wolfSSL | 0:9d17e4342598 | 2848 | case change_cipher_spec: |
wolfSSL | 0:9d17e4342598 | 2849 | case application_data: |
wolfSSL | 0:9d17e4342598 | 2850 | case alert: |
wolfSSL | 0:9d17e4342598 | 2851 | break; |
wolfSSL | 0:9d17e4342598 | 2852 | case no_type: |
wolfSSL | 0:9d17e4342598 | 2853 | default: |
wolfSSL | 0:9d17e4342598 | 2854 | CYASSL_MSG("Unknown Record Type"); |
wolfSSL | 0:9d17e4342598 | 2855 | return UNKNOWN_RECORD_TYPE; |
wolfSSL | 0:9d17e4342598 | 2856 | } |
wolfSSL | 0:9d17e4342598 | 2857 | |
wolfSSL | 0:9d17e4342598 | 2858 | /* haven't decrypted this record yet */ |
wolfSSL | 0:9d17e4342598 | 2859 | ssl->keys.decryptedCur = 0; |
wolfSSL | 0:9d17e4342598 | 2860 | |
wolfSSL | 0:9d17e4342598 | 2861 | return 0; |
wolfSSL | 0:9d17e4342598 | 2862 | } |
wolfSSL | 0:9d17e4342598 | 2863 | |
wolfSSL | 0:9d17e4342598 | 2864 | |
wolfSSL | 0:9d17e4342598 | 2865 | static int GetHandShakeHeader(CYASSL* ssl, const byte* input, word32* inOutIdx, |
wolfSSL | 0:9d17e4342598 | 2866 | byte *type, word32 *size) |
wolfSSL | 0:9d17e4342598 | 2867 | { |
wolfSSL | 0:9d17e4342598 | 2868 | const byte *ptr = input + *inOutIdx; |
wolfSSL | 0:9d17e4342598 | 2869 | (void)ssl; |
wolfSSL | 0:9d17e4342598 | 2870 | *inOutIdx += HANDSHAKE_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 2871 | |
wolfSSL | 0:9d17e4342598 | 2872 | *type = ptr[0]; |
wolfSSL | 0:9d17e4342598 | 2873 | c24to32(&ptr[1], size); |
wolfSSL | 0:9d17e4342598 | 2874 | |
wolfSSL | 0:9d17e4342598 | 2875 | return 0; |
wolfSSL | 0:9d17e4342598 | 2876 | } |
wolfSSL | 0:9d17e4342598 | 2877 | |
wolfSSL | 0:9d17e4342598 | 2878 | |
wolfSSL | 0:9d17e4342598 | 2879 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 2880 | static int GetDtlsHandShakeHeader(CYASSL* ssl, const byte* input, |
wolfSSL | 0:9d17e4342598 | 2881 | word32* inOutIdx, byte *type, word32 *size, |
wolfSSL | 0:9d17e4342598 | 2882 | word32 *fragOffset, word32 *fragSz) |
wolfSSL | 0:9d17e4342598 | 2883 | { |
wolfSSL | 0:9d17e4342598 | 2884 | word32 idx = *inOutIdx; |
wolfSSL | 0:9d17e4342598 | 2885 | |
wolfSSL | 0:9d17e4342598 | 2886 | *inOutIdx += HANDSHAKE_HEADER_SZ + DTLS_HANDSHAKE_EXTRA; |
wolfSSL | 0:9d17e4342598 | 2887 | |
wolfSSL | 0:9d17e4342598 | 2888 | *type = input[idx++]; |
wolfSSL | 0:9d17e4342598 | 2889 | c24to32(input + idx, size); |
wolfSSL | 0:9d17e4342598 | 2890 | idx += BYTE3_LEN; |
wolfSSL | 0:9d17e4342598 | 2891 | |
wolfSSL | 0:9d17e4342598 | 2892 | ato16(input + idx, &ssl->keys.dtls_peer_handshake_number); |
wolfSSL | 0:9d17e4342598 | 2893 | idx += DTLS_HANDSHAKE_SEQ_SZ; |
wolfSSL | 0:9d17e4342598 | 2894 | |
wolfSSL | 0:9d17e4342598 | 2895 | c24to32(input + idx, fragOffset); |
wolfSSL | 0:9d17e4342598 | 2896 | idx += DTLS_HANDSHAKE_FRAG_SZ; |
wolfSSL | 0:9d17e4342598 | 2897 | c24to32(input + idx, fragSz); |
wolfSSL | 0:9d17e4342598 | 2898 | |
wolfSSL | 0:9d17e4342598 | 2899 | return 0; |
wolfSSL | 0:9d17e4342598 | 2900 | } |
wolfSSL | 0:9d17e4342598 | 2901 | #endif |
wolfSSL | 0:9d17e4342598 | 2902 | |
wolfSSL | 0:9d17e4342598 | 2903 | |
wolfSSL | 0:9d17e4342598 | 2904 | #ifndef NO_OLD_TLS |
wolfSSL | 0:9d17e4342598 | 2905 | /* fill with MD5 pad size since biggest required */ |
wolfSSL | 0:9d17e4342598 | 2906 | static const byte PAD1[PAD_MD5] = |
wolfSSL | 0:9d17e4342598 | 2907 | { 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, |
wolfSSL | 0:9d17e4342598 | 2908 | 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, |
wolfSSL | 0:9d17e4342598 | 2909 | 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, |
wolfSSL | 0:9d17e4342598 | 2910 | 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, |
wolfSSL | 0:9d17e4342598 | 2911 | 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, |
wolfSSL | 0:9d17e4342598 | 2912 | 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36 |
wolfSSL | 0:9d17e4342598 | 2913 | }; |
wolfSSL | 0:9d17e4342598 | 2914 | static const byte PAD2[PAD_MD5] = |
wolfSSL | 0:9d17e4342598 | 2915 | { 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, |
wolfSSL | 0:9d17e4342598 | 2916 | 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, |
wolfSSL | 0:9d17e4342598 | 2917 | 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, |
wolfSSL | 0:9d17e4342598 | 2918 | 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, |
wolfSSL | 0:9d17e4342598 | 2919 | 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, |
wolfSSL | 0:9d17e4342598 | 2920 | 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c |
wolfSSL | 0:9d17e4342598 | 2921 | }; |
wolfSSL | 0:9d17e4342598 | 2922 | |
wolfSSL | 0:9d17e4342598 | 2923 | /* calculate MD5 hash for finished */ |
wolfSSL | 0:9d17e4342598 | 2924 | static void BuildMD5(CYASSL* ssl, Hashes* hashes, const byte* sender) |
wolfSSL | 0:9d17e4342598 | 2925 | { |
wolfSSL | 0:9d17e4342598 | 2926 | byte md5_result[MD5_DIGEST_SIZE]; |
wolfSSL | 0:9d17e4342598 | 2927 | |
wolfSSL | 0:9d17e4342598 | 2928 | /* make md5 inner */ |
wolfSSL | 0:9d17e4342598 | 2929 | Md5Update(&ssl->hashMd5, sender, SIZEOF_SENDER); |
wolfSSL | 0:9d17e4342598 | 2930 | Md5Update(&ssl->hashMd5, ssl->arrays->masterSecret, SECRET_LEN); |
wolfSSL | 0:9d17e4342598 | 2931 | Md5Update(&ssl->hashMd5, PAD1, PAD_MD5); |
wolfSSL | 0:9d17e4342598 | 2932 | Md5Final(&ssl->hashMd5, md5_result); |
wolfSSL | 0:9d17e4342598 | 2933 | |
wolfSSL | 0:9d17e4342598 | 2934 | /* make md5 outer */ |
wolfSSL | 0:9d17e4342598 | 2935 | Md5Update(&ssl->hashMd5, ssl->arrays->masterSecret, SECRET_LEN); |
wolfSSL | 0:9d17e4342598 | 2936 | Md5Update(&ssl->hashMd5, PAD2, PAD_MD5); |
wolfSSL | 0:9d17e4342598 | 2937 | Md5Update(&ssl->hashMd5, md5_result, MD5_DIGEST_SIZE); |
wolfSSL | 0:9d17e4342598 | 2938 | |
wolfSSL | 0:9d17e4342598 | 2939 | Md5Final(&ssl->hashMd5, hashes->md5); |
wolfSSL | 0:9d17e4342598 | 2940 | } |
wolfSSL | 0:9d17e4342598 | 2941 | |
wolfSSL | 0:9d17e4342598 | 2942 | |
wolfSSL | 0:9d17e4342598 | 2943 | /* calculate SHA hash for finished */ |
wolfSSL | 0:9d17e4342598 | 2944 | static void BuildSHA(CYASSL* ssl, Hashes* hashes, const byte* sender) |
wolfSSL | 0:9d17e4342598 | 2945 | { |
wolfSSL | 0:9d17e4342598 | 2946 | byte sha_result[SHA_DIGEST_SIZE]; |
wolfSSL | 0:9d17e4342598 | 2947 | |
wolfSSL | 0:9d17e4342598 | 2948 | /* make sha inner */ |
wolfSSL | 0:9d17e4342598 | 2949 | ShaUpdate(&ssl->hashSha, sender, SIZEOF_SENDER); |
wolfSSL | 0:9d17e4342598 | 2950 | ShaUpdate(&ssl->hashSha, ssl->arrays->masterSecret, SECRET_LEN); |
wolfSSL | 0:9d17e4342598 | 2951 | ShaUpdate(&ssl->hashSha, PAD1, PAD_SHA); |
wolfSSL | 0:9d17e4342598 | 2952 | ShaFinal(&ssl->hashSha, sha_result); |
wolfSSL | 0:9d17e4342598 | 2953 | |
wolfSSL | 0:9d17e4342598 | 2954 | /* make sha outer */ |
wolfSSL | 0:9d17e4342598 | 2955 | ShaUpdate(&ssl->hashSha, ssl->arrays->masterSecret, SECRET_LEN); |
wolfSSL | 0:9d17e4342598 | 2956 | ShaUpdate(&ssl->hashSha, PAD2, PAD_SHA); |
wolfSSL | 0:9d17e4342598 | 2957 | ShaUpdate(&ssl->hashSha, sha_result, SHA_DIGEST_SIZE); |
wolfSSL | 0:9d17e4342598 | 2958 | |
wolfSSL | 0:9d17e4342598 | 2959 | ShaFinal(&ssl->hashSha, hashes->sha); |
wolfSSL | 0:9d17e4342598 | 2960 | } |
wolfSSL | 0:9d17e4342598 | 2961 | #endif |
wolfSSL | 0:9d17e4342598 | 2962 | |
wolfSSL | 0:9d17e4342598 | 2963 | |
wolfSSL | 0:9d17e4342598 | 2964 | static int BuildFinished(CYASSL* ssl, Hashes* hashes, const byte* sender) |
wolfSSL | 0:9d17e4342598 | 2965 | { |
wolfSSL | 0:9d17e4342598 | 2966 | /* store current states, building requires get_digest which resets state */ |
wolfSSL | 0:9d17e4342598 | 2967 | #ifndef NO_OLD_TLS |
wolfSSL | 0:9d17e4342598 | 2968 | #ifndef NO_MD5 |
wolfSSL | 0:9d17e4342598 | 2969 | Md5 md5 = ssl->hashMd5; |
wolfSSL | 0:9d17e4342598 | 2970 | #endif |
wolfSSL | 0:9d17e4342598 | 2971 | #ifndef NO_SHA |
wolfSSL | 0:9d17e4342598 | 2972 | Sha sha = ssl->hashSha; |
wolfSSL | 0:9d17e4342598 | 2973 | #endif |
wolfSSL | 0:9d17e4342598 | 2974 | #endif |
wolfSSL | 0:9d17e4342598 | 2975 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 2976 | Sha256 sha256 = ssl->hashSha256; |
wolfSSL | 0:9d17e4342598 | 2977 | #endif |
wolfSSL | 0:9d17e4342598 | 2978 | #ifdef CYASSL_SHA384 |
wolfSSL | 0:9d17e4342598 | 2979 | Sha384 sha384 = ssl->hashSha384; |
wolfSSL | 0:9d17e4342598 | 2980 | #endif |
wolfSSL | 0:9d17e4342598 | 2981 | |
wolfSSL | 0:9d17e4342598 | 2982 | int ret = 0; |
wolfSSL | 0:9d17e4342598 | 2983 | |
wolfSSL | 0:9d17e4342598 | 2984 | #ifndef NO_TLS |
wolfSSL | 0:9d17e4342598 | 2985 | if (ssl->options.tls) { |
wolfSSL | 0:9d17e4342598 | 2986 | ret = BuildTlsFinished(ssl, hashes, sender); |
wolfSSL | 0:9d17e4342598 | 2987 | } |
wolfSSL | 0:9d17e4342598 | 2988 | #endif |
wolfSSL | 0:9d17e4342598 | 2989 | #ifndef NO_OLD_TLS |
wolfSSL | 0:9d17e4342598 | 2990 | if (!ssl->options.tls) { |
wolfSSL | 0:9d17e4342598 | 2991 | BuildMD5(ssl, hashes, sender); |
wolfSSL | 0:9d17e4342598 | 2992 | BuildSHA(ssl, hashes, sender); |
wolfSSL | 0:9d17e4342598 | 2993 | } |
wolfSSL | 0:9d17e4342598 | 2994 | #endif |
wolfSSL | 0:9d17e4342598 | 2995 | |
wolfSSL | 0:9d17e4342598 | 2996 | /* restore */ |
wolfSSL | 0:9d17e4342598 | 2997 | #ifndef NO_OLD_TLS |
wolfSSL | 0:9d17e4342598 | 2998 | #ifndef NO_MD5 |
wolfSSL | 0:9d17e4342598 | 2999 | ssl->hashMd5 = md5; |
wolfSSL | 0:9d17e4342598 | 3000 | #endif |
wolfSSL | 0:9d17e4342598 | 3001 | #ifndef NO_SHA |
wolfSSL | 0:9d17e4342598 | 3002 | ssl->hashSha = sha; |
wolfSSL | 0:9d17e4342598 | 3003 | #endif |
wolfSSL | 0:9d17e4342598 | 3004 | #endif |
wolfSSL | 0:9d17e4342598 | 3005 | if (IsAtLeastTLSv1_2(ssl)) { |
wolfSSL | 0:9d17e4342598 | 3006 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 3007 | ssl->hashSha256 = sha256; |
wolfSSL | 0:9d17e4342598 | 3008 | #endif |
wolfSSL | 0:9d17e4342598 | 3009 | #ifdef CYASSL_SHA384 |
wolfSSL | 0:9d17e4342598 | 3010 | ssl->hashSha384 = sha384; |
wolfSSL | 0:9d17e4342598 | 3011 | #endif |
wolfSSL | 0:9d17e4342598 | 3012 | } |
wolfSSL | 0:9d17e4342598 | 3013 | |
wolfSSL | 0:9d17e4342598 | 3014 | return ret; |
wolfSSL | 0:9d17e4342598 | 3015 | } |
wolfSSL | 0:9d17e4342598 | 3016 | |
wolfSSL | 0:9d17e4342598 | 3017 | |
wolfSSL | 0:9d17e4342598 | 3018 | #ifndef NO_CERTS |
wolfSSL | 0:9d17e4342598 | 3019 | |
wolfSSL | 0:9d17e4342598 | 3020 | |
wolfSSL | 0:9d17e4342598 | 3021 | /* Match names with wildcards, each wildcard can represent a single name |
wolfSSL | 0:9d17e4342598 | 3022 | component or fragment but not mulitple names, i.e., |
wolfSSL | 0:9d17e4342598 | 3023 | *.z.com matches y.z.com but not x.y.z.com |
wolfSSL | 0:9d17e4342598 | 3024 | |
wolfSSL | 0:9d17e4342598 | 3025 | return 1 on success */ |
wolfSSL | 0:9d17e4342598 | 3026 | static int MatchDomainName(const char* pattern, int len, const char* str) |
wolfSSL | 0:9d17e4342598 | 3027 | { |
wolfSSL | 0:9d17e4342598 | 3028 | char p, s; |
wolfSSL | 0:9d17e4342598 | 3029 | |
wolfSSL | 0:9d17e4342598 | 3030 | if (pattern == NULL || str == NULL || len <= 0) |
wolfSSL | 0:9d17e4342598 | 3031 | return 0; |
wolfSSL | 0:9d17e4342598 | 3032 | |
wolfSSL | 0:9d17e4342598 | 3033 | while (len > 0) { |
wolfSSL | 0:9d17e4342598 | 3034 | |
wolfSSL | 0:9d17e4342598 | 3035 | p = (char)XTOLOWER(*pattern++); |
wolfSSL | 0:9d17e4342598 | 3036 | if (p == 0) |
wolfSSL | 0:9d17e4342598 | 3037 | break; |
wolfSSL | 0:9d17e4342598 | 3038 | |
wolfSSL | 0:9d17e4342598 | 3039 | if (p == '*') { |
wolfSSL | 0:9d17e4342598 | 3040 | while (--len > 0 && (p = (char)XTOLOWER(*pattern++)) == '*') |
wolfSSL | 0:9d17e4342598 | 3041 | ; |
wolfSSL | 0:9d17e4342598 | 3042 | |
wolfSSL | 0:9d17e4342598 | 3043 | if (len == 0) |
wolfSSL | 0:9d17e4342598 | 3044 | p = '\0'; |
wolfSSL | 0:9d17e4342598 | 3045 | |
wolfSSL | 0:9d17e4342598 | 3046 | while ( (s = (char)XTOLOWER(*str)) != '\0') { |
wolfSSL | 0:9d17e4342598 | 3047 | if (s == p) |
wolfSSL | 0:9d17e4342598 | 3048 | break; |
wolfSSL | 0:9d17e4342598 | 3049 | if (s == '.') |
wolfSSL | 0:9d17e4342598 | 3050 | return 0; |
wolfSSL | 0:9d17e4342598 | 3051 | str++; |
wolfSSL | 0:9d17e4342598 | 3052 | } |
wolfSSL | 0:9d17e4342598 | 3053 | } |
wolfSSL | 0:9d17e4342598 | 3054 | else { |
wolfSSL | 0:9d17e4342598 | 3055 | if (p != (char)XTOLOWER(*str)) |
wolfSSL | 0:9d17e4342598 | 3056 | return 0; |
wolfSSL | 0:9d17e4342598 | 3057 | } |
wolfSSL | 0:9d17e4342598 | 3058 | |
wolfSSL | 0:9d17e4342598 | 3059 | if (*str != '\0') |
wolfSSL | 0:9d17e4342598 | 3060 | str++; |
wolfSSL | 0:9d17e4342598 | 3061 | |
wolfSSL | 0:9d17e4342598 | 3062 | if (len > 0) |
wolfSSL | 0:9d17e4342598 | 3063 | len--; |
wolfSSL | 0:9d17e4342598 | 3064 | } |
wolfSSL | 0:9d17e4342598 | 3065 | |
wolfSSL | 0:9d17e4342598 | 3066 | return *str == '\0'; |
wolfSSL | 0:9d17e4342598 | 3067 | } |
wolfSSL | 0:9d17e4342598 | 3068 | |
wolfSSL | 0:9d17e4342598 | 3069 | |
wolfSSL | 0:9d17e4342598 | 3070 | /* try to find an altName match to domain, return 1 on success */ |
wolfSSL | 0:9d17e4342598 | 3071 | static int CheckAltNames(DecodedCert* dCert, char* domain) |
wolfSSL | 0:9d17e4342598 | 3072 | { |
wolfSSL | 0:9d17e4342598 | 3073 | int match = 0; |
wolfSSL | 0:9d17e4342598 | 3074 | DNS_entry* altName = NULL; |
wolfSSL | 0:9d17e4342598 | 3075 | |
wolfSSL | 0:9d17e4342598 | 3076 | CYASSL_MSG("Checking AltNames"); |
wolfSSL | 0:9d17e4342598 | 3077 | |
wolfSSL | 0:9d17e4342598 | 3078 | if (dCert) |
wolfSSL | 0:9d17e4342598 | 3079 | altName = dCert->altNames; |
wolfSSL | 0:9d17e4342598 | 3080 | |
wolfSSL | 0:9d17e4342598 | 3081 | while (altName) { |
wolfSSL | 0:9d17e4342598 | 3082 | CYASSL_MSG(" individual AltName check"); |
wolfSSL | 0:9d17e4342598 | 3083 | |
wolfSSL | 0:9d17e4342598 | 3084 | if (MatchDomainName(altName->name,(int)XSTRLEN(altName->name), domain)){ |
wolfSSL | 0:9d17e4342598 | 3085 | match = 1; |
wolfSSL | 0:9d17e4342598 | 3086 | break; |
wolfSSL | 0:9d17e4342598 | 3087 | } |
wolfSSL | 0:9d17e4342598 | 3088 | |
wolfSSL | 0:9d17e4342598 | 3089 | altName = altName->next; |
wolfSSL | 0:9d17e4342598 | 3090 | } |
wolfSSL | 0:9d17e4342598 | 3091 | |
wolfSSL | 0:9d17e4342598 | 3092 | return match; |
wolfSSL | 0:9d17e4342598 | 3093 | } |
wolfSSL | 0:9d17e4342598 | 3094 | |
wolfSSL | 0:9d17e4342598 | 3095 | |
wolfSSL | 0:9d17e4342598 | 3096 | #if defined(KEEP_PEER_CERT) || defined(SESSION_CERTS) |
wolfSSL | 0:9d17e4342598 | 3097 | |
wolfSSL | 0:9d17e4342598 | 3098 | /* Copy parts X509 needs from Decoded cert, 0 on success */ |
wolfSSL | 0:9d17e4342598 | 3099 | int CopyDecodedToX509(CYASSL_X509* x509, DecodedCert* dCert) |
wolfSSL | 0:9d17e4342598 | 3100 | { |
wolfSSL | 0:9d17e4342598 | 3101 | int ret = 0; |
wolfSSL | 0:9d17e4342598 | 3102 | |
wolfSSL | 0:9d17e4342598 | 3103 | if (x509 == NULL || dCert == NULL) |
wolfSSL | 0:9d17e4342598 | 3104 | return BAD_FUNC_ARG; |
wolfSSL | 0:9d17e4342598 | 3105 | |
wolfSSL | 0:9d17e4342598 | 3106 | x509->version = dCert->version + 1; |
wolfSSL | 0:9d17e4342598 | 3107 | |
wolfSSL | 0:9d17e4342598 | 3108 | XSTRNCPY(x509->issuer.name, dCert->issuer, ASN_NAME_MAX); |
wolfSSL | 0:9d17e4342598 | 3109 | x509->issuer.name[ASN_NAME_MAX - 1] = '\0'; |
wolfSSL | 0:9d17e4342598 | 3110 | x509->issuer.sz = (int)XSTRLEN(x509->issuer.name) + 1; |
wolfSSL | 0:9d17e4342598 | 3111 | #ifdef OPENSSL_EXTRA |
wolfSSL | 0:9d17e4342598 | 3112 | if (dCert->issuerName.fullName != NULL) { |
wolfSSL | 0:9d17e4342598 | 3113 | XMEMCPY(&x509->issuer.fullName, |
wolfSSL | 0:9d17e4342598 | 3114 | &dCert->issuerName, sizeof(DecodedName)); |
wolfSSL | 0:9d17e4342598 | 3115 | x509->issuer.fullName.fullName = (char*)XMALLOC( |
wolfSSL | 0:9d17e4342598 | 3116 | dCert->issuerName.fullNameLen, NULL, DYNAMIC_TYPE_X509); |
wolfSSL | 0:9d17e4342598 | 3117 | if (x509->issuer.fullName.fullName != NULL) |
wolfSSL | 0:9d17e4342598 | 3118 | XMEMCPY(x509->issuer.fullName.fullName, |
wolfSSL | 0:9d17e4342598 | 3119 | dCert->issuerName.fullName, dCert->issuerName.fullNameLen); |
wolfSSL | 0:9d17e4342598 | 3120 | } |
wolfSSL | 0:9d17e4342598 | 3121 | #endif /* OPENSSL_EXTRA */ |
wolfSSL | 0:9d17e4342598 | 3122 | |
wolfSSL | 0:9d17e4342598 | 3123 | XSTRNCPY(x509->subject.name, dCert->subject, ASN_NAME_MAX); |
wolfSSL | 0:9d17e4342598 | 3124 | x509->subject.name[ASN_NAME_MAX - 1] = '\0'; |
wolfSSL | 0:9d17e4342598 | 3125 | x509->subject.sz = (int)XSTRLEN(x509->subject.name) + 1; |
wolfSSL | 0:9d17e4342598 | 3126 | #ifdef OPENSSL_EXTRA |
wolfSSL | 0:9d17e4342598 | 3127 | if (dCert->subjectName.fullName != NULL) { |
wolfSSL | 0:9d17e4342598 | 3128 | XMEMCPY(&x509->subject.fullName, |
wolfSSL | 0:9d17e4342598 | 3129 | &dCert->subjectName, sizeof(DecodedName)); |
wolfSSL | 0:9d17e4342598 | 3130 | x509->subject.fullName.fullName = (char*)XMALLOC( |
wolfSSL | 0:9d17e4342598 | 3131 | dCert->subjectName.fullNameLen, NULL, DYNAMIC_TYPE_X509); |
wolfSSL | 0:9d17e4342598 | 3132 | if (x509->subject.fullName.fullName != NULL) |
wolfSSL | 0:9d17e4342598 | 3133 | XMEMCPY(x509->subject.fullName.fullName, |
wolfSSL | 0:9d17e4342598 | 3134 | dCert->subjectName.fullName, dCert->subjectName.fullNameLen); |
wolfSSL | 0:9d17e4342598 | 3135 | } |
wolfSSL | 0:9d17e4342598 | 3136 | #endif /* OPENSSL_EXTRA */ |
wolfSSL | 0:9d17e4342598 | 3137 | |
wolfSSL | 0:9d17e4342598 | 3138 | XMEMCPY(x509->serial, dCert->serial, EXTERNAL_SERIAL_SIZE); |
wolfSSL | 0:9d17e4342598 | 3139 | x509->serialSz = dCert->serialSz; |
wolfSSL | 0:9d17e4342598 | 3140 | if (dCert->subjectCNLen < ASN_NAME_MAX) { |
wolfSSL | 0:9d17e4342598 | 3141 | XMEMCPY(x509->subjectCN, dCert->subjectCN, dCert->subjectCNLen); |
wolfSSL | 0:9d17e4342598 | 3142 | x509->subjectCN[dCert->subjectCNLen] = '\0'; |
wolfSSL | 0:9d17e4342598 | 3143 | } |
wolfSSL | 0:9d17e4342598 | 3144 | else |
wolfSSL | 0:9d17e4342598 | 3145 | x509->subjectCN[0] = '\0'; |
wolfSSL | 0:9d17e4342598 | 3146 | |
wolfSSL | 0:9d17e4342598 | 3147 | #ifdef CYASSL_SEP |
wolfSSL | 0:9d17e4342598 | 3148 | { |
wolfSSL | 0:9d17e4342598 | 3149 | int minSz = min(dCert->deviceTypeSz, EXTERNAL_SERIAL_SIZE); |
wolfSSL | 0:9d17e4342598 | 3150 | if (minSz > 0) { |
wolfSSL | 0:9d17e4342598 | 3151 | x509->deviceTypeSz = minSz; |
wolfSSL | 0:9d17e4342598 | 3152 | XMEMCPY(x509->deviceType, dCert->deviceType, minSz); |
wolfSSL | 0:9d17e4342598 | 3153 | } |
wolfSSL | 0:9d17e4342598 | 3154 | else |
wolfSSL | 0:9d17e4342598 | 3155 | x509->deviceTypeSz = 0; |
wolfSSL | 0:9d17e4342598 | 3156 | minSz = min(dCert->hwTypeSz, EXTERNAL_SERIAL_SIZE); |
wolfSSL | 0:9d17e4342598 | 3157 | if (minSz != 0) { |
wolfSSL | 0:9d17e4342598 | 3158 | x509->hwTypeSz = minSz; |
wolfSSL | 0:9d17e4342598 | 3159 | XMEMCPY(x509->hwType, dCert->hwType, minSz); |
wolfSSL | 0:9d17e4342598 | 3160 | } |
wolfSSL | 0:9d17e4342598 | 3161 | else |
wolfSSL | 0:9d17e4342598 | 3162 | x509->hwTypeSz = 0; |
wolfSSL | 0:9d17e4342598 | 3163 | minSz = min(dCert->hwSerialNumSz, EXTERNAL_SERIAL_SIZE); |
wolfSSL | 0:9d17e4342598 | 3164 | if (minSz != 0) { |
wolfSSL | 0:9d17e4342598 | 3165 | x509->hwSerialNumSz = minSz; |
wolfSSL | 0:9d17e4342598 | 3166 | XMEMCPY(x509->hwSerialNum, dCert->hwSerialNum, minSz); |
wolfSSL | 0:9d17e4342598 | 3167 | } |
wolfSSL | 0:9d17e4342598 | 3168 | else |
wolfSSL | 0:9d17e4342598 | 3169 | x509->hwSerialNumSz = 0; |
wolfSSL | 0:9d17e4342598 | 3170 | } |
wolfSSL | 0:9d17e4342598 | 3171 | #endif /* CYASSL_SEP */ |
wolfSSL | 0:9d17e4342598 | 3172 | { |
wolfSSL | 0:9d17e4342598 | 3173 | int minSz = min(dCert->beforeDateLen, MAX_DATE_SZ); |
wolfSSL | 0:9d17e4342598 | 3174 | if (minSz != 0) { |
wolfSSL | 0:9d17e4342598 | 3175 | x509->notBeforeSz = minSz; |
wolfSSL | 0:9d17e4342598 | 3176 | XMEMCPY(x509->notBefore, dCert->beforeDate, minSz); |
wolfSSL | 0:9d17e4342598 | 3177 | } |
wolfSSL | 0:9d17e4342598 | 3178 | else |
wolfSSL | 0:9d17e4342598 | 3179 | x509->notBeforeSz = 0; |
wolfSSL | 0:9d17e4342598 | 3180 | minSz = min(dCert->afterDateLen, MAX_DATE_SZ); |
wolfSSL | 0:9d17e4342598 | 3181 | if (minSz != 0) { |
wolfSSL | 0:9d17e4342598 | 3182 | x509->notAfterSz = minSz; |
wolfSSL | 0:9d17e4342598 | 3183 | XMEMCPY(x509->notAfter, dCert->afterDate, minSz); |
wolfSSL | 0:9d17e4342598 | 3184 | } |
wolfSSL | 0:9d17e4342598 | 3185 | else |
wolfSSL | 0:9d17e4342598 | 3186 | x509->notAfterSz = 0; |
wolfSSL | 0:9d17e4342598 | 3187 | } |
wolfSSL | 0:9d17e4342598 | 3188 | |
wolfSSL | 0:9d17e4342598 | 3189 | if (dCert->publicKey != NULL && dCert->pubKeySize != 0) { |
wolfSSL | 0:9d17e4342598 | 3190 | x509->pubKey.buffer = (byte*)XMALLOC( |
wolfSSL | 0:9d17e4342598 | 3191 | dCert->pubKeySize, NULL, DYNAMIC_TYPE_PUBLIC_KEY); |
wolfSSL | 0:9d17e4342598 | 3192 | if (x509->pubKey.buffer != NULL) { |
wolfSSL | 0:9d17e4342598 | 3193 | x509->pubKeyOID = dCert->keyOID; |
wolfSSL | 0:9d17e4342598 | 3194 | x509->pubKey.length = dCert->pubKeySize; |
wolfSSL | 0:9d17e4342598 | 3195 | XMEMCPY(x509->pubKey.buffer, dCert->publicKey, dCert->pubKeySize); |
wolfSSL | 0:9d17e4342598 | 3196 | } |
wolfSSL | 0:9d17e4342598 | 3197 | else |
wolfSSL | 0:9d17e4342598 | 3198 | ret = MEMORY_E; |
wolfSSL | 0:9d17e4342598 | 3199 | } |
wolfSSL | 0:9d17e4342598 | 3200 | |
wolfSSL | 0:9d17e4342598 | 3201 | if (dCert->signature != NULL && dCert->sigLength != 0) { |
wolfSSL | 0:9d17e4342598 | 3202 | x509->sig.buffer = (byte*)XMALLOC( |
wolfSSL | 0:9d17e4342598 | 3203 | dCert->sigLength, NULL, DYNAMIC_TYPE_SIGNATURE); |
wolfSSL | 0:9d17e4342598 | 3204 | if (x509->sig.buffer == NULL) { |
wolfSSL | 0:9d17e4342598 | 3205 | ret = MEMORY_E; |
wolfSSL | 0:9d17e4342598 | 3206 | } |
wolfSSL | 0:9d17e4342598 | 3207 | else { |
wolfSSL | 0:9d17e4342598 | 3208 | XMEMCPY(x509->sig.buffer, dCert->signature, dCert->sigLength); |
wolfSSL | 0:9d17e4342598 | 3209 | x509->sig.length = dCert->sigLength; |
wolfSSL | 0:9d17e4342598 | 3210 | x509->sigOID = dCert->signatureOID; |
wolfSSL | 0:9d17e4342598 | 3211 | } |
wolfSSL | 0:9d17e4342598 | 3212 | } |
wolfSSL | 0:9d17e4342598 | 3213 | |
wolfSSL | 0:9d17e4342598 | 3214 | /* store cert for potential retrieval */ |
wolfSSL | 0:9d17e4342598 | 3215 | x509->derCert.buffer = (byte*)XMALLOC(dCert->maxIdx, NULL, |
wolfSSL | 0:9d17e4342598 | 3216 | DYNAMIC_TYPE_CERT); |
wolfSSL | 0:9d17e4342598 | 3217 | if (x509->derCert.buffer == NULL) { |
wolfSSL | 0:9d17e4342598 | 3218 | ret = MEMORY_E; |
wolfSSL | 0:9d17e4342598 | 3219 | } |
wolfSSL | 0:9d17e4342598 | 3220 | else { |
wolfSSL | 0:9d17e4342598 | 3221 | XMEMCPY(x509->derCert.buffer, dCert->source, dCert->maxIdx); |
wolfSSL | 0:9d17e4342598 | 3222 | x509->derCert.length = dCert->maxIdx; |
wolfSSL | 0:9d17e4342598 | 3223 | } |
wolfSSL | 0:9d17e4342598 | 3224 | |
wolfSSL | 0:9d17e4342598 | 3225 | x509->altNames = dCert->altNames; |
wolfSSL | 0:9d17e4342598 | 3226 | dCert->altNames = NULL; /* takes ownership */ |
wolfSSL | 0:9d17e4342598 | 3227 | x509->altNamesNext = x509->altNames; /* index hint */ |
wolfSSL | 0:9d17e4342598 | 3228 | |
wolfSSL | 0:9d17e4342598 | 3229 | x509->isCa = dCert->isCA; |
wolfSSL | 0:9d17e4342598 | 3230 | #ifdef OPENSSL_EXTRA |
wolfSSL | 0:9d17e4342598 | 3231 | x509->pathLength = dCert->pathLength; |
wolfSSL | 0:9d17e4342598 | 3232 | x509->keyUsage = dCert->extKeyUsage; |
wolfSSL | 0:9d17e4342598 | 3233 | |
wolfSSL | 0:9d17e4342598 | 3234 | x509->basicConstSet = dCert->extBasicConstSet; |
wolfSSL | 0:9d17e4342598 | 3235 | x509->basicConstCrit = dCert->extBasicConstCrit; |
wolfSSL | 0:9d17e4342598 | 3236 | x509->basicConstPlSet = dCert->extBasicConstPlSet; |
wolfSSL | 0:9d17e4342598 | 3237 | x509->subjAltNameSet = dCert->extSubjAltNameSet; |
wolfSSL | 0:9d17e4342598 | 3238 | x509->subjAltNameCrit = dCert->extSubjAltNameCrit; |
wolfSSL | 0:9d17e4342598 | 3239 | x509->authKeyIdSet = dCert->extAuthKeyIdSet; |
wolfSSL | 0:9d17e4342598 | 3240 | x509->authKeyIdCrit = dCert->extAuthKeyIdCrit; |
wolfSSL | 0:9d17e4342598 | 3241 | if (dCert->extAuthKeyIdSrc != NULL && dCert->extAuthKeyIdSz != 0) { |
wolfSSL | 0:9d17e4342598 | 3242 | x509->authKeyId = (byte*)XMALLOC(dCert->extAuthKeyIdSz, NULL, 0); |
wolfSSL | 0:9d17e4342598 | 3243 | if (x509->authKeyId != NULL) { |
wolfSSL | 0:9d17e4342598 | 3244 | XMEMCPY(x509->authKeyId, |
wolfSSL | 0:9d17e4342598 | 3245 | dCert->extAuthKeyIdSrc, dCert->extAuthKeyIdSz); |
wolfSSL | 0:9d17e4342598 | 3246 | x509->authKeyIdSz = dCert->extAuthKeyIdSz; |
wolfSSL | 0:9d17e4342598 | 3247 | } |
wolfSSL | 0:9d17e4342598 | 3248 | else |
wolfSSL | 0:9d17e4342598 | 3249 | ret = MEMORY_E; |
wolfSSL | 0:9d17e4342598 | 3250 | } |
wolfSSL | 0:9d17e4342598 | 3251 | x509->subjKeyIdSet = dCert->extSubjKeyIdSet; |
wolfSSL | 0:9d17e4342598 | 3252 | x509->subjKeyIdCrit = dCert->extSubjKeyIdCrit; |
wolfSSL | 0:9d17e4342598 | 3253 | if (dCert->extSubjKeyIdSrc != NULL && dCert->extSubjKeyIdSz != 0) { |
wolfSSL | 0:9d17e4342598 | 3254 | x509->subjKeyId = (byte*)XMALLOC(dCert->extSubjKeyIdSz, NULL, 0); |
wolfSSL | 0:9d17e4342598 | 3255 | if (x509->subjKeyId != NULL) { |
wolfSSL | 0:9d17e4342598 | 3256 | XMEMCPY(x509->subjKeyId, |
wolfSSL | 0:9d17e4342598 | 3257 | dCert->extSubjKeyIdSrc, dCert->extSubjKeyIdSz); |
wolfSSL | 0:9d17e4342598 | 3258 | x509->subjKeyIdSz = dCert->extSubjKeyIdSz; |
wolfSSL | 0:9d17e4342598 | 3259 | } |
wolfSSL | 0:9d17e4342598 | 3260 | else |
wolfSSL | 0:9d17e4342598 | 3261 | ret = MEMORY_E; |
wolfSSL | 0:9d17e4342598 | 3262 | } |
wolfSSL | 0:9d17e4342598 | 3263 | x509->keyUsageSet = dCert->extKeyUsageSet; |
wolfSSL | 0:9d17e4342598 | 3264 | x509->keyUsageCrit = dCert->extKeyUsageCrit; |
wolfSSL | 0:9d17e4342598 | 3265 | #ifdef CYASSL_SEP |
wolfSSL | 0:9d17e4342598 | 3266 | x509->certPolicySet = dCert->extCertPolicySet; |
wolfSSL | 0:9d17e4342598 | 3267 | x509->certPolicyCrit = dCert->extCertPolicyCrit; |
wolfSSL | 0:9d17e4342598 | 3268 | #endif /* CYASSL_SEP */ |
wolfSSL | 0:9d17e4342598 | 3269 | #endif /* OPENSSL_EXTRA */ |
wolfSSL | 0:9d17e4342598 | 3270 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 3271 | x509->pkCurveOID = dCert->pkCurveOID; |
wolfSSL | 0:9d17e4342598 | 3272 | #endif /* HAVE_ECC */ |
wolfSSL | 0:9d17e4342598 | 3273 | |
wolfSSL | 0:9d17e4342598 | 3274 | return ret; |
wolfSSL | 0:9d17e4342598 | 3275 | } |
wolfSSL | 0:9d17e4342598 | 3276 | |
wolfSSL | 0:9d17e4342598 | 3277 | #endif /* KEEP_PEER_CERT || SESSION_CERTS */ |
wolfSSL | 0:9d17e4342598 | 3278 | |
wolfSSL | 0:9d17e4342598 | 3279 | |
wolfSSL | 0:9d17e4342598 | 3280 | static int DoCertificate(CYASSL* ssl, byte* input, word32* inOutIdx, |
wolfSSL | 0:9d17e4342598 | 3281 | word32 size) |
wolfSSL | 0:9d17e4342598 | 3282 | { |
wolfSSL | 0:9d17e4342598 | 3283 | word32 listSz, begin = *inOutIdx; |
wolfSSL | 0:9d17e4342598 | 3284 | int ret = 0; |
wolfSSL | 0:9d17e4342598 | 3285 | int anyError = 0; |
wolfSSL | 0:9d17e4342598 | 3286 | int totalCerts = 0; /* number of certs in certs buffer */ |
wolfSSL | 0:9d17e4342598 | 3287 | int count; |
wolfSSL | 0:9d17e4342598 | 3288 | char domain[ASN_NAME_MAX]; |
wolfSSL | 0:9d17e4342598 | 3289 | buffer certs[MAX_CHAIN_DEPTH]; |
wolfSSL | 0:9d17e4342598 | 3290 | |
wolfSSL | 0:9d17e4342598 | 3291 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 3292 | if (ssl->hsInfoOn) AddPacketName("Certificate", &ssl->handShakeInfo); |
wolfSSL | 0:9d17e4342598 | 3293 | if (ssl->toInfoOn) AddLateName("Certificate", &ssl->timeoutInfo); |
wolfSSL | 0:9d17e4342598 | 3294 | #endif |
wolfSSL | 0:9d17e4342598 | 3295 | |
wolfSSL | 0:9d17e4342598 | 3296 | if ((*inOutIdx - begin) + OPAQUE24_LEN > size) |
wolfSSL | 0:9d17e4342598 | 3297 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 3298 | |
wolfSSL | 0:9d17e4342598 | 3299 | c24to32(input + *inOutIdx, &listSz); |
wolfSSL | 0:9d17e4342598 | 3300 | *inOutIdx += OPAQUE24_LEN; |
wolfSSL | 0:9d17e4342598 | 3301 | |
wolfSSL | 0:9d17e4342598 | 3302 | #ifdef HAVE_MAX_FRAGMENT |
wolfSSL | 0:9d17e4342598 | 3303 | if (listSz > ssl->max_fragment) |
wolfSSL | 0:9d17e4342598 | 3304 | return BUFFER_E; |
wolfSSL | 0:9d17e4342598 | 3305 | #else |
wolfSSL | 0:9d17e4342598 | 3306 | if (listSz > MAX_RECORD_SIZE) |
wolfSSL | 0:9d17e4342598 | 3307 | return BUFFER_E; |
wolfSSL | 0:9d17e4342598 | 3308 | #endif |
wolfSSL | 0:9d17e4342598 | 3309 | |
wolfSSL | 0:9d17e4342598 | 3310 | if ((*inOutIdx - begin) + listSz != size) |
wolfSSL | 0:9d17e4342598 | 3311 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 3312 | |
wolfSSL | 0:9d17e4342598 | 3313 | CYASSL_MSG("Loading peer's cert chain"); |
wolfSSL | 0:9d17e4342598 | 3314 | /* first put cert chain into buffer so can verify top down |
wolfSSL | 0:9d17e4342598 | 3315 | we're sent bottom up */ |
wolfSSL | 0:9d17e4342598 | 3316 | while (listSz) { |
wolfSSL | 0:9d17e4342598 | 3317 | word32 certSz; |
wolfSSL | 0:9d17e4342598 | 3318 | |
wolfSSL | 0:9d17e4342598 | 3319 | if (totalCerts >= MAX_CHAIN_DEPTH) |
wolfSSL | 0:9d17e4342598 | 3320 | return MAX_CHAIN_ERROR; |
wolfSSL | 0:9d17e4342598 | 3321 | |
wolfSSL | 0:9d17e4342598 | 3322 | if ((*inOutIdx - begin) + OPAQUE24_LEN > size) |
wolfSSL | 0:9d17e4342598 | 3323 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 3324 | |
wolfSSL | 0:9d17e4342598 | 3325 | c24to32(input + *inOutIdx, &certSz); |
wolfSSL | 0:9d17e4342598 | 3326 | *inOutIdx += OPAQUE24_LEN; |
wolfSSL | 0:9d17e4342598 | 3327 | |
wolfSSL | 0:9d17e4342598 | 3328 | if ((*inOutIdx - begin) + certSz > size) |
wolfSSL | 0:9d17e4342598 | 3329 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 3330 | |
wolfSSL | 0:9d17e4342598 | 3331 | certs[totalCerts].length = certSz; |
wolfSSL | 0:9d17e4342598 | 3332 | certs[totalCerts].buffer = input + *inOutIdx; |
wolfSSL | 0:9d17e4342598 | 3333 | |
wolfSSL | 0:9d17e4342598 | 3334 | #ifdef SESSION_CERTS |
wolfSSL | 0:9d17e4342598 | 3335 | if (ssl->session.chain.count < MAX_CHAIN_DEPTH && |
wolfSSL | 0:9d17e4342598 | 3336 | certSz < MAX_X509_SIZE) { |
wolfSSL | 0:9d17e4342598 | 3337 | ssl->session.chain.certs[ssl->session.chain.count].length = certSz; |
wolfSSL | 0:9d17e4342598 | 3338 | XMEMCPY(ssl->session.chain.certs[ssl->session.chain.count].buffer, |
wolfSSL | 0:9d17e4342598 | 3339 | input + *inOutIdx, certSz); |
wolfSSL | 0:9d17e4342598 | 3340 | ssl->session.chain.count++; |
wolfSSL | 0:9d17e4342598 | 3341 | } else { |
wolfSSL | 0:9d17e4342598 | 3342 | CYASSL_MSG("Couldn't store chain cert for session"); |
wolfSSL | 0:9d17e4342598 | 3343 | } |
wolfSSL | 0:9d17e4342598 | 3344 | #endif |
wolfSSL | 0:9d17e4342598 | 3345 | |
wolfSSL | 0:9d17e4342598 | 3346 | *inOutIdx += certSz; |
wolfSSL | 0:9d17e4342598 | 3347 | listSz -= certSz + CERT_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 3348 | |
wolfSSL | 0:9d17e4342598 | 3349 | totalCerts++; |
wolfSSL | 0:9d17e4342598 | 3350 | CYASSL_MSG(" Put another cert into chain"); |
wolfSSL | 0:9d17e4342598 | 3351 | } |
wolfSSL | 0:9d17e4342598 | 3352 | |
wolfSSL | 0:9d17e4342598 | 3353 | count = totalCerts; |
wolfSSL | 0:9d17e4342598 | 3354 | |
wolfSSL | 0:9d17e4342598 | 3355 | /* verify up to peer's first */ |
wolfSSL | 0:9d17e4342598 | 3356 | while (count > 1) { |
wolfSSL | 0:9d17e4342598 | 3357 | buffer myCert = certs[count - 1]; |
wolfSSL | 0:9d17e4342598 | 3358 | DecodedCert dCert; |
wolfSSL | 0:9d17e4342598 | 3359 | byte* subjectHash; |
wolfSSL | 0:9d17e4342598 | 3360 | |
wolfSSL | 0:9d17e4342598 | 3361 | InitDecodedCert(&dCert, myCert.buffer, myCert.length, ssl->heap); |
wolfSSL | 0:9d17e4342598 | 3362 | ret = ParseCertRelative(&dCert, CERT_TYPE, !ssl->options.verifyNone, |
wolfSSL | 0:9d17e4342598 | 3363 | ssl->ctx->cm); |
wolfSSL | 0:9d17e4342598 | 3364 | #ifndef NO_SKID |
wolfSSL | 0:9d17e4342598 | 3365 | subjectHash = dCert.extSubjKeyId; |
wolfSSL | 0:9d17e4342598 | 3366 | #else |
wolfSSL | 0:9d17e4342598 | 3367 | subjectHash = dCert.subjectHash; |
wolfSSL | 0:9d17e4342598 | 3368 | #endif |
wolfSSL | 0:9d17e4342598 | 3369 | |
wolfSSL | 0:9d17e4342598 | 3370 | if (ret == 0 && dCert.isCA == 0) { |
wolfSSL | 0:9d17e4342598 | 3371 | CYASSL_MSG("Chain cert is not a CA, not adding as one"); |
wolfSSL | 0:9d17e4342598 | 3372 | } |
wolfSSL | 0:9d17e4342598 | 3373 | else if (ret == 0 && ssl->options.verifyNone) { |
wolfSSL | 0:9d17e4342598 | 3374 | CYASSL_MSG("Chain cert not verified by option, not adding as CA"); |
wolfSSL | 0:9d17e4342598 | 3375 | } |
wolfSSL | 0:9d17e4342598 | 3376 | else if (ret == 0 && !AlreadySigner(ssl->ctx->cm, subjectHash)) { |
wolfSSL | 0:9d17e4342598 | 3377 | buffer add; |
wolfSSL | 0:9d17e4342598 | 3378 | add.length = myCert.length; |
wolfSSL | 0:9d17e4342598 | 3379 | add.buffer = (byte*)XMALLOC(myCert.length, ssl->heap, |
wolfSSL | 0:9d17e4342598 | 3380 | DYNAMIC_TYPE_CA); |
wolfSSL | 0:9d17e4342598 | 3381 | CYASSL_MSG("Adding CA from chain"); |
wolfSSL | 0:9d17e4342598 | 3382 | |
wolfSSL | 0:9d17e4342598 | 3383 | if (add.buffer == NULL) |
wolfSSL | 0:9d17e4342598 | 3384 | return MEMORY_E; |
wolfSSL | 0:9d17e4342598 | 3385 | XMEMCPY(add.buffer, myCert.buffer, myCert.length); |
wolfSSL | 0:9d17e4342598 | 3386 | |
wolfSSL | 0:9d17e4342598 | 3387 | ret = AddCA(ssl->ctx->cm, add, CYASSL_CHAIN_CA, |
wolfSSL | 0:9d17e4342598 | 3388 | ssl->ctx->verifyPeer); |
wolfSSL | 0:9d17e4342598 | 3389 | if (ret == 1) ret = 0; /* SSL_SUCCESS for external */ |
wolfSSL | 0:9d17e4342598 | 3390 | } |
wolfSSL | 0:9d17e4342598 | 3391 | else if (ret != 0) { |
wolfSSL | 0:9d17e4342598 | 3392 | CYASSL_MSG("Failed to verify CA from chain"); |
wolfSSL | 0:9d17e4342598 | 3393 | } |
wolfSSL | 0:9d17e4342598 | 3394 | else { |
wolfSSL | 0:9d17e4342598 | 3395 | CYASSL_MSG("Verified CA from chain and already had it"); |
wolfSSL | 0:9d17e4342598 | 3396 | } |
wolfSSL | 0:9d17e4342598 | 3397 | |
wolfSSL | 0:9d17e4342598 | 3398 | #ifdef HAVE_CRL |
wolfSSL | 0:9d17e4342598 | 3399 | if (ret == 0 && ssl->ctx->cm->crlEnabled && ssl->ctx->cm->crlCheckAll) { |
wolfSSL | 0:9d17e4342598 | 3400 | CYASSL_MSG("Doing Non Leaf CRL check"); |
wolfSSL | 0:9d17e4342598 | 3401 | ret = CheckCertCRL(ssl->ctx->cm->crl, &dCert); |
wolfSSL | 0:9d17e4342598 | 3402 | |
wolfSSL | 0:9d17e4342598 | 3403 | if (ret != 0) { |
wolfSSL | 0:9d17e4342598 | 3404 | CYASSL_MSG("\tCRL check not ok"); |
wolfSSL | 0:9d17e4342598 | 3405 | } |
wolfSSL | 0:9d17e4342598 | 3406 | } |
wolfSSL | 0:9d17e4342598 | 3407 | #endif /* HAVE_CRL */ |
wolfSSL | 0:9d17e4342598 | 3408 | |
wolfSSL | 0:9d17e4342598 | 3409 | if (ret != 0 && anyError == 0) |
wolfSSL | 0:9d17e4342598 | 3410 | anyError = ret; /* save error from last time */ |
wolfSSL | 0:9d17e4342598 | 3411 | |
wolfSSL | 0:9d17e4342598 | 3412 | FreeDecodedCert(&dCert); |
wolfSSL | 0:9d17e4342598 | 3413 | count--; |
wolfSSL | 0:9d17e4342598 | 3414 | } |
wolfSSL | 0:9d17e4342598 | 3415 | |
wolfSSL | 0:9d17e4342598 | 3416 | /* peer's, may not have one if blank client cert sent by TLSv1.2 */ |
wolfSSL | 0:9d17e4342598 | 3417 | if (count) { |
wolfSSL | 0:9d17e4342598 | 3418 | buffer myCert = certs[0]; |
wolfSSL | 0:9d17e4342598 | 3419 | DecodedCert dCert; |
wolfSSL | 0:9d17e4342598 | 3420 | int fatal = 0; |
wolfSSL | 0:9d17e4342598 | 3421 | |
wolfSSL | 0:9d17e4342598 | 3422 | CYASSL_MSG("Verifying Peer's cert"); |
wolfSSL | 0:9d17e4342598 | 3423 | |
wolfSSL | 0:9d17e4342598 | 3424 | InitDecodedCert(&dCert, myCert.buffer, myCert.length, ssl->heap); |
wolfSSL | 0:9d17e4342598 | 3425 | ret = ParseCertRelative(&dCert, CERT_TYPE, !ssl->options.verifyNone, |
wolfSSL | 0:9d17e4342598 | 3426 | ssl->ctx->cm); |
wolfSSL | 0:9d17e4342598 | 3427 | if (ret == 0) { |
wolfSSL | 0:9d17e4342598 | 3428 | CYASSL_MSG("Verified Peer's cert"); |
wolfSSL | 0:9d17e4342598 | 3429 | fatal = 0; |
wolfSSL | 0:9d17e4342598 | 3430 | } |
wolfSSL | 0:9d17e4342598 | 3431 | else if (ret == ASN_PARSE_E) { |
wolfSSL | 0:9d17e4342598 | 3432 | CYASSL_MSG("Got Peer cert ASN PARSE ERROR, fatal"); |
wolfSSL | 0:9d17e4342598 | 3433 | fatal = 1; |
wolfSSL | 0:9d17e4342598 | 3434 | } |
wolfSSL | 0:9d17e4342598 | 3435 | else { |
wolfSSL | 0:9d17e4342598 | 3436 | CYASSL_MSG("Failed to verify Peer's cert"); |
wolfSSL | 0:9d17e4342598 | 3437 | if (ssl->verifyCallback) { |
wolfSSL | 0:9d17e4342598 | 3438 | CYASSL_MSG("\tCallback override available, will continue"); |
wolfSSL | 0:9d17e4342598 | 3439 | fatal = 0; |
wolfSSL | 0:9d17e4342598 | 3440 | } |
wolfSSL | 0:9d17e4342598 | 3441 | else { |
wolfSSL | 0:9d17e4342598 | 3442 | CYASSL_MSG("\tNo callback override available, fatal"); |
wolfSSL | 0:9d17e4342598 | 3443 | fatal = 1; |
wolfSSL | 0:9d17e4342598 | 3444 | } |
wolfSSL | 0:9d17e4342598 | 3445 | } |
wolfSSL | 0:9d17e4342598 | 3446 | |
wolfSSL | 0:9d17e4342598 | 3447 | #ifdef HAVE_OCSP |
wolfSSL | 0:9d17e4342598 | 3448 | if (fatal == 0 && ssl->ctx->cm->ocspEnabled) { |
wolfSSL | 0:9d17e4342598 | 3449 | ret = CheckCertOCSP(ssl->ctx->cm->ocsp, &dCert); |
wolfSSL | 0:9d17e4342598 | 3450 | if (ret != 0) { |
wolfSSL | 0:9d17e4342598 | 3451 | CYASSL_MSG("\tOCSP Lookup not ok"); |
wolfSSL | 0:9d17e4342598 | 3452 | fatal = 0; |
wolfSSL | 0:9d17e4342598 | 3453 | } |
wolfSSL | 0:9d17e4342598 | 3454 | } |
wolfSSL | 0:9d17e4342598 | 3455 | #endif |
wolfSSL | 0:9d17e4342598 | 3456 | |
wolfSSL | 0:9d17e4342598 | 3457 | #ifdef HAVE_CRL |
wolfSSL | 0:9d17e4342598 | 3458 | if (fatal == 0 && ssl->ctx->cm->crlEnabled) { |
wolfSSL | 0:9d17e4342598 | 3459 | int doCrlLookup = 1; |
wolfSSL | 0:9d17e4342598 | 3460 | |
wolfSSL | 0:9d17e4342598 | 3461 | #ifdef HAVE_OCSP |
wolfSSL | 0:9d17e4342598 | 3462 | if (ssl->ctx->cm->ocspEnabled) { |
wolfSSL | 0:9d17e4342598 | 3463 | doCrlLookup = (ret == OCSP_CERT_UNKNOWN); |
wolfSSL | 0:9d17e4342598 | 3464 | } |
wolfSSL | 0:9d17e4342598 | 3465 | #endif /* HAVE_OCSP */ |
wolfSSL | 0:9d17e4342598 | 3466 | |
wolfSSL | 0:9d17e4342598 | 3467 | if (doCrlLookup) { |
wolfSSL | 0:9d17e4342598 | 3468 | CYASSL_MSG("Doing Leaf CRL check"); |
wolfSSL | 0:9d17e4342598 | 3469 | ret = CheckCertCRL(ssl->ctx->cm->crl, &dCert); |
wolfSSL | 0:9d17e4342598 | 3470 | |
wolfSSL | 0:9d17e4342598 | 3471 | if (ret != 0) { |
wolfSSL | 0:9d17e4342598 | 3472 | CYASSL_MSG("\tCRL check not ok"); |
wolfSSL | 0:9d17e4342598 | 3473 | fatal = 0; |
wolfSSL | 0:9d17e4342598 | 3474 | } |
wolfSSL | 0:9d17e4342598 | 3475 | } |
wolfSSL | 0:9d17e4342598 | 3476 | } |
wolfSSL | 0:9d17e4342598 | 3477 | |
wolfSSL | 0:9d17e4342598 | 3478 | #endif /* HAVE_CRL */ |
wolfSSL | 0:9d17e4342598 | 3479 | |
wolfSSL | 0:9d17e4342598 | 3480 | #ifdef KEEP_PEER_CERT |
wolfSSL | 0:9d17e4342598 | 3481 | { |
wolfSSL | 0:9d17e4342598 | 3482 | /* set X509 format for peer cert even if fatal */ |
wolfSSL | 0:9d17e4342598 | 3483 | int copyRet = CopyDecodedToX509(&ssl->peerCert, &dCert); |
wolfSSL | 0:9d17e4342598 | 3484 | if (copyRet == MEMORY_E) |
wolfSSL | 0:9d17e4342598 | 3485 | fatal = 1; |
wolfSSL | 0:9d17e4342598 | 3486 | } |
wolfSSL | 0:9d17e4342598 | 3487 | #endif |
wolfSSL | 0:9d17e4342598 | 3488 | |
wolfSSL | 0:9d17e4342598 | 3489 | if (fatal) { |
wolfSSL | 0:9d17e4342598 | 3490 | FreeDecodedCert(&dCert); |
wolfSSL | 0:9d17e4342598 | 3491 | ssl->error = ret; |
wolfSSL | 0:9d17e4342598 | 3492 | return ret; |
wolfSSL | 0:9d17e4342598 | 3493 | } |
wolfSSL | 0:9d17e4342598 | 3494 | ssl->options.havePeerCert = 1; |
wolfSSL | 0:9d17e4342598 | 3495 | |
wolfSSL | 0:9d17e4342598 | 3496 | /* store for callback use */ |
wolfSSL | 0:9d17e4342598 | 3497 | if (dCert.subjectCNLen < ASN_NAME_MAX) { |
wolfSSL | 0:9d17e4342598 | 3498 | XMEMCPY(domain, dCert.subjectCN, dCert.subjectCNLen); |
wolfSSL | 0:9d17e4342598 | 3499 | domain[dCert.subjectCNLen] = '\0'; |
wolfSSL | 0:9d17e4342598 | 3500 | } |
wolfSSL | 0:9d17e4342598 | 3501 | else |
wolfSSL | 0:9d17e4342598 | 3502 | domain[0] = '\0'; |
wolfSSL | 0:9d17e4342598 | 3503 | |
wolfSSL | 0:9d17e4342598 | 3504 | if (!ssl->options.verifyNone && ssl->buffers.domainName.buffer) { |
wolfSSL | 0:9d17e4342598 | 3505 | if (MatchDomainName(dCert.subjectCN, dCert.subjectCNLen, |
wolfSSL | 0:9d17e4342598 | 3506 | (char*)ssl->buffers.domainName.buffer) == 0) { |
wolfSSL | 0:9d17e4342598 | 3507 | CYASSL_MSG("DomainName match on common name failed"); |
wolfSSL | 0:9d17e4342598 | 3508 | if (CheckAltNames(&dCert, |
wolfSSL | 0:9d17e4342598 | 3509 | (char*)ssl->buffers.domainName.buffer) == 0 ) { |
wolfSSL | 0:9d17e4342598 | 3510 | CYASSL_MSG("DomainName match on alt names failed too"); |
wolfSSL | 0:9d17e4342598 | 3511 | ret = DOMAIN_NAME_MISMATCH; /* try to get peer key still */ |
wolfSSL | 0:9d17e4342598 | 3512 | } |
wolfSSL | 0:9d17e4342598 | 3513 | } |
wolfSSL | 0:9d17e4342598 | 3514 | } |
wolfSSL | 0:9d17e4342598 | 3515 | |
wolfSSL | 0:9d17e4342598 | 3516 | /* decode peer key */ |
wolfSSL | 0:9d17e4342598 | 3517 | switch (dCert.keyOID) { |
wolfSSL | 0:9d17e4342598 | 3518 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 3519 | case RSAk: |
wolfSSL | 0:9d17e4342598 | 3520 | { |
wolfSSL | 0:9d17e4342598 | 3521 | word32 idx = 0; |
wolfSSL | 0:9d17e4342598 | 3522 | if (RsaPublicKeyDecode(dCert.publicKey, &idx, |
wolfSSL | 0:9d17e4342598 | 3523 | ssl->peerRsaKey, dCert.pubKeySize) != 0) { |
wolfSSL | 0:9d17e4342598 | 3524 | ret = PEER_KEY_ERROR; |
wolfSSL | 0:9d17e4342598 | 3525 | } |
wolfSSL | 0:9d17e4342598 | 3526 | else { |
wolfSSL | 0:9d17e4342598 | 3527 | ssl->peerRsaKeyPresent = 1; |
wolfSSL | 0:9d17e4342598 | 3528 | #ifdef HAVE_PK_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 3529 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 3530 | ssl->buffers.peerRsaKey.buffer = |
wolfSSL | 0:9d17e4342598 | 3531 | XMALLOC(dCert.pubKeySize, |
wolfSSL | 0:9d17e4342598 | 3532 | ssl->heap, DYNAMIC_TYPE_RSA); |
wolfSSL | 0:9d17e4342598 | 3533 | if (ssl->buffers.peerRsaKey.buffer == NULL) |
wolfSSL | 0:9d17e4342598 | 3534 | ret = MEMORY_ERROR; |
wolfSSL | 0:9d17e4342598 | 3535 | else { |
wolfSSL | 0:9d17e4342598 | 3536 | XMEMCPY(ssl->buffers.peerRsaKey.buffer, |
wolfSSL | 0:9d17e4342598 | 3537 | dCert.publicKey, dCert.pubKeySize); |
wolfSSL | 0:9d17e4342598 | 3538 | ssl->buffers.peerRsaKey.length = |
wolfSSL | 0:9d17e4342598 | 3539 | dCert.pubKeySize; |
wolfSSL | 0:9d17e4342598 | 3540 | } |
wolfSSL | 0:9d17e4342598 | 3541 | #endif /* NO_RSA */ |
wolfSSL | 0:9d17e4342598 | 3542 | #endif /*HAVE_PK_CALLBACKS */ |
wolfSSL | 0:9d17e4342598 | 3543 | } |
wolfSSL | 0:9d17e4342598 | 3544 | } |
wolfSSL | 0:9d17e4342598 | 3545 | break; |
wolfSSL | 0:9d17e4342598 | 3546 | #endif /* NO_RSA */ |
wolfSSL | 0:9d17e4342598 | 3547 | #ifdef HAVE_NTRU |
wolfSSL | 0:9d17e4342598 | 3548 | case NTRUk: |
wolfSSL | 0:9d17e4342598 | 3549 | { |
wolfSSL | 0:9d17e4342598 | 3550 | if (dCert.pubKeySize > sizeof(ssl->peerNtruKey)) { |
wolfSSL | 0:9d17e4342598 | 3551 | ret = PEER_KEY_ERROR; |
wolfSSL | 0:9d17e4342598 | 3552 | } |
wolfSSL | 0:9d17e4342598 | 3553 | else { |
wolfSSL | 0:9d17e4342598 | 3554 | XMEMCPY(ssl->peerNtruKey, dCert.publicKey, dCert.pubKeySize); |
wolfSSL | 0:9d17e4342598 | 3555 | ssl->peerNtruKeyLen = (word16)dCert.pubKeySize; |
wolfSSL | 0:9d17e4342598 | 3556 | ssl->peerNtruKeyPresent = 1; |
wolfSSL | 0:9d17e4342598 | 3557 | } |
wolfSSL | 0:9d17e4342598 | 3558 | } |
wolfSSL | 0:9d17e4342598 | 3559 | break; |
wolfSSL | 0:9d17e4342598 | 3560 | #endif /* HAVE_NTRU */ |
wolfSSL | 0:9d17e4342598 | 3561 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 3562 | case ECDSAk: |
wolfSSL | 0:9d17e4342598 | 3563 | { |
wolfSSL | 0:9d17e4342598 | 3564 | if (ecc_import_x963(dCert.publicKey, dCert.pubKeySize, |
wolfSSL | 0:9d17e4342598 | 3565 | ssl->peerEccDsaKey) != 0) { |
wolfSSL | 0:9d17e4342598 | 3566 | ret = PEER_KEY_ERROR; |
wolfSSL | 0:9d17e4342598 | 3567 | } |
wolfSSL | 0:9d17e4342598 | 3568 | else { |
wolfSSL | 0:9d17e4342598 | 3569 | ssl->peerEccDsaKeyPresent = 1; |
wolfSSL | 0:9d17e4342598 | 3570 | #ifdef HAVE_PK_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 3571 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 3572 | ssl->buffers.peerEccDsaKey.buffer = |
wolfSSL | 0:9d17e4342598 | 3573 | XMALLOC(dCert.pubKeySize, |
wolfSSL | 0:9d17e4342598 | 3574 | ssl->heap, DYNAMIC_TYPE_ECC); |
wolfSSL | 0:9d17e4342598 | 3575 | if (ssl->buffers.peerEccDsaKey.buffer == NULL) |
wolfSSL | 0:9d17e4342598 | 3576 | ret = MEMORY_ERROR; |
wolfSSL | 0:9d17e4342598 | 3577 | else { |
wolfSSL | 0:9d17e4342598 | 3578 | XMEMCPY(ssl->buffers.peerEccDsaKey.buffer, |
wolfSSL | 0:9d17e4342598 | 3579 | dCert.publicKey, dCert.pubKeySize); |
wolfSSL | 0:9d17e4342598 | 3580 | ssl->buffers.peerEccDsaKey.length = |
wolfSSL | 0:9d17e4342598 | 3581 | dCert.pubKeySize; |
wolfSSL | 0:9d17e4342598 | 3582 | } |
wolfSSL | 0:9d17e4342598 | 3583 | #endif /* HAVE_ECC */ |
wolfSSL | 0:9d17e4342598 | 3584 | #endif /*HAVE_PK_CALLBACKS */ |
wolfSSL | 0:9d17e4342598 | 3585 | } |
wolfSSL | 0:9d17e4342598 | 3586 | } |
wolfSSL | 0:9d17e4342598 | 3587 | break; |
wolfSSL | 0:9d17e4342598 | 3588 | #endif /* HAVE_ECC */ |
wolfSSL | 0:9d17e4342598 | 3589 | default: |
wolfSSL | 0:9d17e4342598 | 3590 | break; |
wolfSSL | 0:9d17e4342598 | 3591 | } |
wolfSSL | 0:9d17e4342598 | 3592 | |
wolfSSL | 0:9d17e4342598 | 3593 | FreeDecodedCert(&dCert); |
wolfSSL | 0:9d17e4342598 | 3594 | } |
wolfSSL | 0:9d17e4342598 | 3595 | |
wolfSSL | 0:9d17e4342598 | 3596 | if (anyError != 0 && ret == 0) |
wolfSSL | 0:9d17e4342598 | 3597 | ret = anyError; |
wolfSSL | 0:9d17e4342598 | 3598 | |
wolfSSL | 0:9d17e4342598 | 3599 | if (ret == 0 && ssl->options.side == CYASSL_CLIENT_END) |
wolfSSL | 0:9d17e4342598 | 3600 | ssl->options.serverState = SERVER_CERT_COMPLETE; |
wolfSSL | 0:9d17e4342598 | 3601 | |
wolfSSL | 0:9d17e4342598 | 3602 | if (ret != 0) { |
wolfSSL | 0:9d17e4342598 | 3603 | if (!ssl->options.verifyNone) { |
wolfSSL | 0:9d17e4342598 | 3604 | int why = bad_certificate; |
wolfSSL | 0:9d17e4342598 | 3605 | if (ret == ASN_AFTER_DATE_E || ret == ASN_BEFORE_DATE_E) |
wolfSSL | 0:9d17e4342598 | 3606 | why = certificate_expired; |
wolfSSL | 0:9d17e4342598 | 3607 | if (ssl->verifyCallback) { |
wolfSSL | 0:9d17e4342598 | 3608 | int ok; |
wolfSSL | 0:9d17e4342598 | 3609 | CYASSL_X509_STORE_CTX store; |
wolfSSL | 0:9d17e4342598 | 3610 | |
wolfSSL | 0:9d17e4342598 | 3611 | store.error = ret; |
wolfSSL | 0:9d17e4342598 | 3612 | store.error_depth = totalCerts; |
wolfSSL | 0:9d17e4342598 | 3613 | store.discardSessionCerts = 0; |
wolfSSL | 0:9d17e4342598 | 3614 | store.domain = domain; |
wolfSSL | 0:9d17e4342598 | 3615 | store.userCtx = ssl->verifyCbCtx; |
wolfSSL | 0:9d17e4342598 | 3616 | #ifdef KEEP_PEER_CERT |
wolfSSL | 0:9d17e4342598 | 3617 | store.current_cert = &ssl->peerCert; |
wolfSSL | 0:9d17e4342598 | 3618 | #else |
wolfSSL | 0:9d17e4342598 | 3619 | store.current_cert = NULL; |
wolfSSL | 0:9d17e4342598 | 3620 | #endif |
wolfSSL | 0:9d17e4342598 | 3621 | #ifdef FORTRESS |
wolfSSL | 0:9d17e4342598 | 3622 | store.ex_data = ssl; |
wolfSSL | 0:9d17e4342598 | 3623 | #endif |
wolfSSL | 0:9d17e4342598 | 3624 | ok = ssl->verifyCallback(0, &store); |
wolfSSL | 0:9d17e4342598 | 3625 | if (ok) { |
wolfSSL | 0:9d17e4342598 | 3626 | CYASSL_MSG("Verify callback overriding error!"); |
wolfSSL | 0:9d17e4342598 | 3627 | ret = 0; |
wolfSSL | 0:9d17e4342598 | 3628 | } |
wolfSSL | 0:9d17e4342598 | 3629 | #ifdef SESSION_CERTS |
wolfSSL | 0:9d17e4342598 | 3630 | if (store.discardSessionCerts) { |
wolfSSL | 0:9d17e4342598 | 3631 | CYASSL_MSG("Verify callback requested discard sess certs"); |
wolfSSL | 0:9d17e4342598 | 3632 | ssl->session.chain.count = 0; |
wolfSSL | 0:9d17e4342598 | 3633 | } |
wolfSSL | 0:9d17e4342598 | 3634 | #endif |
wolfSSL | 0:9d17e4342598 | 3635 | } |
wolfSSL | 0:9d17e4342598 | 3636 | if (ret != 0) { |
wolfSSL | 0:9d17e4342598 | 3637 | SendAlert(ssl, alert_fatal, why); /* try to send */ |
wolfSSL | 0:9d17e4342598 | 3638 | ssl->options.isClosed = 1; |
wolfSSL | 0:9d17e4342598 | 3639 | } |
wolfSSL | 0:9d17e4342598 | 3640 | } |
wolfSSL | 0:9d17e4342598 | 3641 | ssl->error = ret; |
wolfSSL | 0:9d17e4342598 | 3642 | } |
wolfSSL | 0:9d17e4342598 | 3643 | #ifdef CYASSL_ALWAYS_VERIFY_CB |
wolfSSL | 0:9d17e4342598 | 3644 | else { |
wolfSSL | 0:9d17e4342598 | 3645 | if (ssl->verifyCallback) { |
wolfSSL | 0:9d17e4342598 | 3646 | int ok; |
wolfSSL | 0:9d17e4342598 | 3647 | CYASSL_X509_STORE_CTX store; |
wolfSSL | 0:9d17e4342598 | 3648 | |
wolfSSL | 0:9d17e4342598 | 3649 | store.error = ret; |
wolfSSL | 0:9d17e4342598 | 3650 | store.error_depth = totalCerts; |
wolfSSL | 0:9d17e4342598 | 3651 | store.discardSessionCerts = 0; |
wolfSSL | 0:9d17e4342598 | 3652 | store.domain = domain; |
wolfSSL | 0:9d17e4342598 | 3653 | store.userCtx = ssl->verifyCbCtx; |
wolfSSL | 0:9d17e4342598 | 3654 | #ifdef KEEP_PEER_CERT |
wolfSSL | 0:9d17e4342598 | 3655 | store.current_cert = &ssl->peerCert; |
wolfSSL | 0:9d17e4342598 | 3656 | #endif |
wolfSSL | 0:9d17e4342598 | 3657 | store.ex_data = ssl; |
wolfSSL | 0:9d17e4342598 | 3658 | |
wolfSSL | 0:9d17e4342598 | 3659 | ok = ssl->verifyCallback(1, &store); |
wolfSSL | 0:9d17e4342598 | 3660 | if (!ok) { |
wolfSSL | 0:9d17e4342598 | 3661 | CYASSL_MSG("Verify callback overriding valid certificate!"); |
wolfSSL | 0:9d17e4342598 | 3662 | ret = -1; |
wolfSSL | 0:9d17e4342598 | 3663 | SendAlert(ssl, alert_fatal, bad_certificate); |
wolfSSL | 0:9d17e4342598 | 3664 | ssl->options.isClosed = 1; |
wolfSSL | 0:9d17e4342598 | 3665 | } |
wolfSSL | 0:9d17e4342598 | 3666 | #ifdef SESSION_CERTS |
wolfSSL | 0:9d17e4342598 | 3667 | if (store.discardSessionCerts) { |
wolfSSL | 0:9d17e4342598 | 3668 | CYASSL_MSG("Verify callback requested discard sess certs"); |
wolfSSL | 0:9d17e4342598 | 3669 | ssl->session.chain.count = 0; |
wolfSSL | 0:9d17e4342598 | 3670 | } |
wolfSSL | 0:9d17e4342598 | 3671 | #endif |
wolfSSL | 0:9d17e4342598 | 3672 | } |
wolfSSL | 0:9d17e4342598 | 3673 | } |
wolfSSL | 0:9d17e4342598 | 3674 | #endif |
wolfSSL | 0:9d17e4342598 | 3675 | |
wolfSSL | 0:9d17e4342598 | 3676 | return ret; |
wolfSSL | 0:9d17e4342598 | 3677 | } |
wolfSSL | 0:9d17e4342598 | 3678 | |
wolfSSL | 0:9d17e4342598 | 3679 | #endif /* !NO_CERTS */ |
wolfSSL | 0:9d17e4342598 | 3680 | |
wolfSSL | 0:9d17e4342598 | 3681 | |
wolfSSL | 0:9d17e4342598 | 3682 | static int DoHelloRequest(CYASSL* ssl, const byte* input, word32* inOutIdx, |
wolfSSL | 0:9d17e4342598 | 3683 | word32 size, word32 totalSz) |
wolfSSL | 0:9d17e4342598 | 3684 | { |
wolfSSL | 0:9d17e4342598 | 3685 | int ret = 0; |
wolfSSL | 0:9d17e4342598 | 3686 | |
wolfSSL | 0:9d17e4342598 | 3687 | if (size) /* must be 0 */ |
wolfSSL | 0:9d17e4342598 | 3688 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 3689 | |
wolfSSL | 0:9d17e4342598 | 3690 | if (ssl->keys.encryptionOn) { |
wolfSSL | 0:9d17e4342598 | 3691 | byte verify[MAX_DIGEST_SIZE]; |
wolfSSL | 0:9d17e4342598 | 3692 | int padSz = ssl->keys.encryptSz - HANDSHAKE_HEADER_SZ - |
wolfSSL | 0:9d17e4342598 | 3693 | ssl->specs.hash_size; |
wolfSSL | 0:9d17e4342598 | 3694 | |
wolfSSL | 0:9d17e4342598 | 3695 | ret = ssl->hmac(ssl, verify, input + *inOutIdx - HANDSHAKE_HEADER_SZ, |
wolfSSL | 0:9d17e4342598 | 3696 | HANDSHAKE_HEADER_SZ, handshake, 1); |
wolfSSL | 0:9d17e4342598 | 3697 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 3698 | return ret; |
wolfSSL | 0:9d17e4342598 | 3699 | |
wolfSSL | 0:9d17e4342598 | 3700 | if (ssl->options.tls1_1 && ssl->specs.cipher_type == block) |
wolfSSL | 0:9d17e4342598 | 3701 | padSz -= ssl->specs.block_size; |
wolfSSL | 0:9d17e4342598 | 3702 | |
wolfSSL | 0:9d17e4342598 | 3703 | /* access beyond input + size should be checked against totalSz */ |
wolfSSL | 0:9d17e4342598 | 3704 | if ((word32) (*inOutIdx + ssl->specs.hash_size + padSz) > totalSz) |
wolfSSL | 0:9d17e4342598 | 3705 | return INCOMPLETE_DATA; |
wolfSSL | 0:9d17e4342598 | 3706 | |
wolfSSL | 0:9d17e4342598 | 3707 | /* verify */ |
wolfSSL | 0:9d17e4342598 | 3708 | if (XMEMCMP(input + *inOutIdx, verify, ssl->specs.hash_size) != 0) { |
wolfSSL | 0:9d17e4342598 | 3709 | CYASSL_MSG(" hello_request verify mac error"); |
wolfSSL | 0:9d17e4342598 | 3710 | return VERIFY_MAC_ERROR; |
wolfSSL | 0:9d17e4342598 | 3711 | } |
wolfSSL | 0:9d17e4342598 | 3712 | |
wolfSSL | 0:9d17e4342598 | 3713 | *inOutIdx += ssl->specs.hash_size + padSz; |
wolfSSL | 0:9d17e4342598 | 3714 | } |
wolfSSL | 0:9d17e4342598 | 3715 | |
wolfSSL | 0:9d17e4342598 | 3716 | if (ssl->options.side == CYASSL_SERVER_END) { |
wolfSSL | 0:9d17e4342598 | 3717 | SendAlert(ssl, alert_fatal, unexpected_message); /* try */ |
wolfSSL | 0:9d17e4342598 | 3718 | return FATAL_ERROR; |
wolfSSL | 0:9d17e4342598 | 3719 | } |
wolfSSL | 0:9d17e4342598 | 3720 | else |
wolfSSL | 0:9d17e4342598 | 3721 | return SendAlert(ssl, alert_warning, no_renegotiation); |
wolfSSL | 0:9d17e4342598 | 3722 | } |
wolfSSL | 0:9d17e4342598 | 3723 | |
wolfSSL | 0:9d17e4342598 | 3724 | |
wolfSSL | 0:9d17e4342598 | 3725 | int DoFinished(CYASSL* ssl, const byte* input, word32* inOutIdx, word32 size, |
wolfSSL | 0:9d17e4342598 | 3726 | word32 totalSz, int sniff) |
wolfSSL | 0:9d17e4342598 | 3727 | { |
wolfSSL | 0:9d17e4342598 | 3728 | word32 finishedSz = (ssl->options.tls ? TLS_FINISHED_SZ : FINISHED_SZ); |
wolfSSL | 0:9d17e4342598 | 3729 | |
wolfSSL | 0:9d17e4342598 | 3730 | if (finishedSz != size) |
wolfSSL | 0:9d17e4342598 | 3731 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 3732 | |
wolfSSL | 0:9d17e4342598 | 3733 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 3734 | if (ssl->hsInfoOn) AddPacketName("Finished", &ssl->handShakeInfo); |
wolfSSL | 0:9d17e4342598 | 3735 | if (ssl->toInfoOn) AddLateName("Finished", &ssl->timeoutInfo); |
wolfSSL | 0:9d17e4342598 | 3736 | #endif |
wolfSSL | 0:9d17e4342598 | 3737 | |
wolfSSL | 0:9d17e4342598 | 3738 | if (sniff == NO_SNIFF) { |
wolfSSL | 0:9d17e4342598 | 3739 | if (XMEMCMP(input + *inOutIdx, &ssl->verifyHashes, size) != 0) { |
wolfSSL | 0:9d17e4342598 | 3740 | CYASSL_MSG("Verify finished error on hashes"); |
wolfSSL | 0:9d17e4342598 | 3741 | return VERIFY_FINISHED_ERROR; |
wolfSSL | 0:9d17e4342598 | 3742 | } |
wolfSSL | 0:9d17e4342598 | 3743 | } |
wolfSSL | 0:9d17e4342598 | 3744 | |
wolfSSL | 0:9d17e4342598 | 3745 | /* increment beyond input + size should be checked against totalSz */ |
wolfSSL | 0:9d17e4342598 | 3746 | if (*inOutIdx + size + ssl->keys.padSz > totalSz) |
wolfSSL | 0:9d17e4342598 | 3747 | return INCOMPLETE_DATA; |
wolfSSL | 0:9d17e4342598 | 3748 | |
wolfSSL | 0:9d17e4342598 | 3749 | /* force input exhaustion at ProcessReply consuming padSz */ |
wolfSSL | 0:9d17e4342598 | 3750 | *inOutIdx += size + ssl->keys.padSz; |
wolfSSL | 0:9d17e4342598 | 3751 | |
wolfSSL | 0:9d17e4342598 | 3752 | if (ssl->options.side == CYASSL_CLIENT_END) { |
wolfSSL | 0:9d17e4342598 | 3753 | ssl->options.serverState = SERVER_FINISHED_COMPLETE; |
wolfSSL | 0:9d17e4342598 | 3754 | if (!ssl->options.resuming) { |
wolfSSL | 0:9d17e4342598 | 3755 | ssl->options.handShakeState = HANDSHAKE_DONE; |
wolfSSL | 0:9d17e4342598 | 3756 | |
wolfSSL | 0:9d17e4342598 | 3757 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 3758 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 3759 | /* Other side has received our Finished, go to next epoch */ |
wolfSSL | 0:9d17e4342598 | 3760 | ssl->keys.dtls_epoch++; |
wolfSSL | 0:9d17e4342598 | 3761 | ssl->keys.dtls_sequence_number = 1; |
wolfSSL | 0:9d17e4342598 | 3762 | } |
wolfSSL | 0:9d17e4342598 | 3763 | #endif |
wolfSSL | 0:9d17e4342598 | 3764 | } |
wolfSSL | 0:9d17e4342598 | 3765 | } |
wolfSSL | 0:9d17e4342598 | 3766 | else { |
wolfSSL | 0:9d17e4342598 | 3767 | ssl->options.clientState = CLIENT_FINISHED_COMPLETE; |
wolfSSL | 0:9d17e4342598 | 3768 | if (ssl->options.resuming) { |
wolfSSL | 0:9d17e4342598 | 3769 | ssl->options.handShakeState = HANDSHAKE_DONE; |
wolfSSL | 0:9d17e4342598 | 3770 | |
wolfSSL | 0:9d17e4342598 | 3771 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 3772 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 3773 | /* Other side has received our Finished, go to next epoch */ |
wolfSSL | 0:9d17e4342598 | 3774 | ssl->keys.dtls_epoch++; |
wolfSSL | 0:9d17e4342598 | 3775 | ssl->keys.dtls_sequence_number = 1; |
wolfSSL | 0:9d17e4342598 | 3776 | } |
wolfSSL | 0:9d17e4342598 | 3777 | #endif |
wolfSSL | 0:9d17e4342598 | 3778 | } |
wolfSSL | 0:9d17e4342598 | 3779 | } |
wolfSSL | 0:9d17e4342598 | 3780 | |
wolfSSL | 0:9d17e4342598 | 3781 | return 0; |
wolfSSL | 0:9d17e4342598 | 3782 | } |
wolfSSL | 0:9d17e4342598 | 3783 | |
wolfSSL | 0:9d17e4342598 | 3784 | |
wolfSSL | 0:9d17e4342598 | 3785 | static int DoHandShakeMsgType(CYASSL* ssl, byte* input, word32* inOutIdx, |
wolfSSL | 0:9d17e4342598 | 3786 | byte type, word32 size, word32 totalSz) |
wolfSSL | 0:9d17e4342598 | 3787 | { |
wolfSSL | 0:9d17e4342598 | 3788 | int ret = 0; |
wolfSSL | 0:9d17e4342598 | 3789 | (void)totalSz; |
wolfSSL | 0:9d17e4342598 | 3790 | |
wolfSSL | 0:9d17e4342598 | 3791 | CYASSL_ENTER("DoHandShakeMsgType"); |
wolfSSL | 0:9d17e4342598 | 3792 | |
wolfSSL | 0:9d17e4342598 | 3793 | /* make sure can read the message */ |
wolfSSL | 0:9d17e4342598 | 3794 | if (*inOutIdx + size > totalSz) |
wolfSSL | 0:9d17e4342598 | 3795 | return INCOMPLETE_DATA; |
wolfSSL | 0:9d17e4342598 | 3796 | |
wolfSSL | 0:9d17e4342598 | 3797 | HashInput(ssl, input + *inOutIdx, size); |
wolfSSL | 0:9d17e4342598 | 3798 | |
wolfSSL | 0:9d17e4342598 | 3799 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 3800 | /* add name later, add on record and handshake header part back on */ |
wolfSSL | 0:9d17e4342598 | 3801 | if (ssl->toInfoOn) { |
wolfSSL | 0:9d17e4342598 | 3802 | int add = RECORD_HEADER_SZ + HANDSHAKE_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 3803 | AddPacketInfo(0, &ssl->timeoutInfo, input + *inOutIdx - add, |
wolfSSL | 0:9d17e4342598 | 3804 | size + add, ssl->heap); |
wolfSSL | 0:9d17e4342598 | 3805 | AddLateRecordHeader(&ssl->curRL, &ssl->timeoutInfo); |
wolfSSL | 0:9d17e4342598 | 3806 | } |
wolfSSL | 0:9d17e4342598 | 3807 | #endif |
wolfSSL | 0:9d17e4342598 | 3808 | |
wolfSSL | 0:9d17e4342598 | 3809 | if (ssl->options.handShakeState == HANDSHAKE_DONE && type != hello_request){ |
wolfSSL | 0:9d17e4342598 | 3810 | CYASSL_MSG("HandShake message after handshake complete"); |
wolfSSL | 0:9d17e4342598 | 3811 | SendAlert(ssl, alert_fatal, unexpected_message); |
wolfSSL | 0:9d17e4342598 | 3812 | return OUT_OF_ORDER_E; |
wolfSSL | 0:9d17e4342598 | 3813 | } |
wolfSSL | 0:9d17e4342598 | 3814 | |
wolfSSL | 0:9d17e4342598 | 3815 | if (ssl->options.side == CYASSL_CLIENT_END && ssl->options.dtls == 0 && |
wolfSSL | 0:9d17e4342598 | 3816 | ssl->options.serverState == NULL_STATE && type != server_hello) { |
wolfSSL | 0:9d17e4342598 | 3817 | CYASSL_MSG("First server message not server hello"); |
wolfSSL | 0:9d17e4342598 | 3818 | SendAlert(ssl, alert_fatal, unexpected_message); |
wolfSSL | 0:9d17e4342598 | 3819 | return OUT_OF_ORDER_E; |
wolfSSL | 0:9d17e4342598 | 3820 | } |
wolfSSL | 0:9d17e4342598 | 3821 | |
wolfSSL | 0:9d17e4342598 | 3822 | if (ssl->options.side == CYASSL_CLIENT_END && ssl->options.dtls && |
wolfSSL | 0:9d17e4342598 | 3823 | type == server_hello_done && |
wolfSSL | 0:9d17e4342598 | 3824 | ssl->options.serverState < SERVER_HELLO_COMPLETE) { |
wolfSSL | 0:9d17e4342598 | 3825 | CYASSL_MSG("Server hello done received before server hello in DTLS"); |
wolfSSL | 0:9d17e4342598 | 3826 | SendAlert(ssl, alert_fatal, unexpected_message); |
wolfSSL | 0:9d17e4342598 | 3827 | return OUT_OF_ORDER_E; |
wolfSSL | 0:9d17e4342598 | 3828 | } |
wolfSSL | 0:9d17e4342598 | 3829 | |
wolfSSL | 0:9d17e4342598 | 3830 | if (ssl->options.side == CYASSL_SERVER_END && |
wolfSSL | 0:9d17e4342598 | 3831 | ssl->options.clientState == NULL_STATE && type != client_hello) { |
wolfSSL | 0:9d17e4342598 | 3832 | CYASSL_MSG("First client message not client hello"); |
wolfSSL | 0:9d17e4342598 | 3833 | SendAlert(ssl, alert_fatal, unexpected_message); |
wolfSSL | 0:9d17e4342598 | 3834 | return OUT_OF_ORDER_E; |
wolfSSL | 0:9d17e4342598 | 3835 | } |
wolfSSL | 0:9d17e4342598 | 3836 | |
wolfSSL | 0:9d17e4342598 | 3837 | |
wolfSSL | 0:9d17e4342598 | 3838 | switch (type) { |
wolfSSL | 0:9d17e4342598 | 3839 | |
wolfSSL | 0:9d17e4342598 | 3840 | case hello_request: |
wolfSSL | 0:9d17e4342598 | 3841 | CYASSL_MSG("processing hello request"); |
wolfSSL | 0:9d17e4342598 | 3842 | ret = DoHelloRequest(ssl, input, inOutIdx, size, totalSz); |
wolfSSL | 0:9d17e4342598 | 3843 | break; |
wolfSSL | 0:9d17e4342598 | 3844 | |
wolfSSL | 0:9d17e4342598 | 3845 | #ifndef NO_CYASSL_CLIENT |
wolfSSL | 0:9d17e4342598 | 3846 | case hello_verify_request: |
wolfSSL | 0:9d17e4342598 | 3847 | CYASSL_MSG("processing hello verify request"); |
wolfSSL | 0:9d17e4342598 | 3848 | ret = DoHelloVerifyRequest(ssl, input,inOutIdx, size); |
wolfSSL | 0:9d17e4342598 | 3849 | break; |
wolfSSL | 0:9d17e4342598 | 3850 | |
wolfSSL | 0:9d17e4342598 | 3851 | case server_hello: |
wolfSSL | 0:9d17e4342598 | 3852 | CYASSL_MSG("processing server hello"); |
wolfSSL | 0:9d17e4342598 | 3853 | ret = DoServerHello(ssl, input, inOutIdx, size); |
wolfSSL | 0:9d17e4342598 | 3854 | break; |
wolfSSL | 0:9d17e4342598 | 3855 | |
wolfSSL | 0:9d17e4342598 | 3856 | #ifndef NO_CERTS |
wolfSSL | 0:9d17e4342598 | 3857 | case certificate_request: |
wolfSSL | 0:9d17e4342598 | 3858 | CYASSL_MSG("processing certificate request"); |
wolfSSL | 0:9d17e4342598 | 3859 | ret = DoCertificateRequest(ssl, input, inOutIdx, size); |
wolfSSL | 0:9d17e4342598 | 3860 | break; |
wolfSSL | 0:9d17e4342598 | 3861 | #endif |
wolfSSL | 0:9d17e4342598 | 3862 | |
wolfSSL | 0:9d17e4342598 | 3863 | case server_key_exchange: |
wolfSSL | 0:9d17e4342598 | 3864 | CYASSL_MSG("processing server key exchange"); |
wolfSSL | 0:9d17e4342598 | 3865 | ret = DoServerKeyExchange(ssl, input, inOutIdx, size); |
wolfSSL | 0:9d17e4342598 | 3866 | break; |
wolfSSL | 0:9d17e4342598 | 3867 | #endif |
wolfSSL | 0:9d17e4342598 | 3868 | |
wolfSSL | 0:9d17e4342598 | 3869 | #ifndef NO_CERTS |
wolfSSL | 0:9d17e4342598 | 3870 | case certificate: |
wolfSSL | 0:9d17e4342598 | 3871 | CYASSL_MSG("processing certificate"); |
wolfSSL | 0:9d17e4342598 | 3872 | ret = DoCertificate(ssl, input, inOutIdx, size); |
wolfSSL | 0:9d17e4342598 | 3873 | break; |
wolfSSL | 0:9d17e4342598 | 3874 | #endif |
wolfSSL | 0:9d17e4342598 | 3875 | |
wolfSSL | 0:9d17e4342598 | 3876 | case server_hello_done: |
wolfSSL | 0:9d17e4342598 | 3877 | CYASSL_MSG("processing server hello done"); |
wolfSSL | 0:9d17e4342598 | 3878 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 3879 | if (ssl->hsInfoOn) |
wolfSSL | 0:9d17e4342598 | 3880 | AddPacketName("ServerHelloDone", &ssl->handShakeInfo); |
wolfSSL | 0:9d17e4342598 | 3881 | if (ssl->toInfoOn) |
wolfSSL | 0:9d17e4342598 | 3882 | AddLateName("ServerHelloDone", &ssl->timeoutInfo); |
wolfSSL | 0:9d17e4342598 | 3883 | #endif |
wolfSSL | 0:9d17e4342598 | 3884 | ssl->options.serverState = SERVER_HELLODONE_COMPLETE; |
wolfSSL | 0:9d17e4342598 | 3885 | break; |
wolfSSL | 0:9d17e4342598 | 3886 | |
wolfSSL | 0:9d17e4342598 | 3887 | case finished: |
wolfSSL | 0:9d17e4342598 | 3888 | CYASSL_MSG("processing finished"); |
wolfSSL | 0:9d17e4342598 | 3889 | ret = DoFinished(ssl, input, inOutIdx, size, totalSz, NO_SNIFF); |
wolfSSL | 0:9d17e4342598 | 3890 | break; |
wolfSSL | 0:9d17e4342598 | 3891 | |
wolfSSL | 0:9d17e4342598 | 3892 | #ifndef NO_CYASSL_SERVER |
wolfSSL | 0:9d17e4342598 | 3893 | case client_hello: |
wolfSSL | 0:9d17e4342598 | 3894 | CYASSL_MSG("processing client hello"); |
wolfSSL | 0:9d17e4342598 | 3895 | ret = DoClientHello(ssl, input, inOutIdx, size); |
wolfSSL | 0:9d17e4342598 | 3896 | break; |
wolfSSL | 0:9d17e4342598 | 3897 | |
wolfSSL | 0:9d17e4342598 | 3898 | case client_key_exchange: |
wolfSSL | 0:9d17e4342598 | 3899 | CYASSL_MSG("processing client key exchange"); |
wolfSSL | 0:9d17e4342598 | 3900 | ret = DoClientKeyExchange(ssl, input, inOutIdx, size); |
wolfSSL | 0:9d17e4342598 | 3901 | break; |
wolfSSL | 0:9d17e4342598 | 3902 | |
wolfSSL | 0:9d17e4342598 | 3903 | #if !defined(NO_RSA) || defined(HAVE_ECC) |
wolfSSL | 0:9d17e4342598 | 3904 | case certificate_verify: |
wolfSSL | 0:9d17e4342598 | 3905 | CYASSL_MSG("processing certificate verify"); |
wolfSSL | 0:9d17e4342598 | 3906 | ret = DoCertificateVerify(ssl, input, inOutIdx, size); |
wolfSSL | 0:9d17e4342598 | 3907 | break; |
wolfSSL | 0:9d17e4342598 | 3908 | #endif /* !NO_RSA || HAVE_ECC */ |
wolfSSL | 0:9d17e4342598 | 3909 | |
wolfSSL | 0:9d17e4342598 | 3910 | #endif /* !NO_CYASSL_SERVER */ |
wolfSSL | 0:9d17e4342598 | 3911 | |
wolfSSL | 0:9d17e4342598 | 3912 | default: |
wolfSSL | 0:9d17e4342598 | 3913 | CYASSL_MSG("Unknown handshake message type"); |
wolfSSL | 0:9d17e4342598 | 3914 | ret = UNKNOWN_HANDSHAKE_TYPE; |
wolfSSL | 0:9d17e4342598 | 3915 | break; |
wolfSSL | 0:9d17e4342598 | 3916 | } |
wolfSSL | 0:9d17e4342598 | 3917 | |
wolfSSL | 0:9d17e4342598 | 3918 | CYASSL_LEAVE("DoHandShakeMsgType()", ret); |
wolfSSL | 0:9d17e4342598 | 3919 | return ret; |
wolfSSL | 0:9d17e4342598 | 3920 | } |
wolfSSL | 0:9d17e4342598 | 3921 | |
wolfSSL | 0:9d17e4342598 | 3922 | |
wolfSSL | 0:9d17e4342598 | 3923 | static int DoHandShakeMsg(CYASSL* ssl, byte* input, word32* inOutIdx, |
wolfSSL | 0:9d17e4342598 | 3924 | word32 totalSz) |
wolfSSL | 0:9d17e4342598 | 3925 | { |
wolfSSL | 0:9d17e4342598 | 3926 | byte type; |
wolfSSL | 0:9d17e4342598 | 3927 | word32 size; |
wolfSSL | 0:9d17e4342598 | 3928 | int ret = 0; |
wolfSSL | 0:9d17e4342598 | 3929 | |
wolfSSL | 0:9d17e4342598 | 3930 | CYASSL_ENTER("DoHandShakeMsg()"); |
wolfSSL | 0:9d17e4342598 | 3931 | |
wolfSSL | 0:9d17e4342598 | 3932 | if (GetHandShakeHeader(ssl, input, inOutIdx, &type, &size) != 0) |
wolfSSL | 0:9d17e4342598 | 3933 | return PARSE_ERROR; |
wolfSSL | 0:9d17e4342598 | 3934 | |
wolfSSL | 0:9d17e4342598 | 3935 | ret = DoHandShakeMsgType(ssl, input, inOutIdx, type, size, totalSz); |
wolfSSL | 0:9d17e4342598 | 3936 | |
wolfSSL | 0:9d17e4342598 | 3937 | CYASSL_LEAVE("DoHandShakeMsg()", ret); |
wolfSSL | 0:9d17e4342598 | 3938 | return ret; |
wolfSSL | 0:9d17e4342598 | 3939 | } |
wolfSSL | 0:9d17e4342598 | 3940 | |
wolfSSL | 0:9d17e4342598 | 3941 | |
wolfSSL | 0:9d17e4342598 | 3942 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 3943 | |
wolfSSL | 0:9d17e4342598 | 3944 | static INLINE int DtlsCheckWindow(DtlsState* state) |
wolfSSL | 0:9d17e4342598 | 3945 | { |
wolfSSL | 0:9d17e4342598 | 3946 | word32 cur; |
wolfSSL | 0:9d17e4342598 | 3947 | word32 next; |
wolfSSL | 0:9d17e4342598 | 3948 | DtlsSeq window; |
wolfSSL | 0:9d17e4342598 | 3949 | |
wolfSSL | 0:9d17e4342598 | 3950 | if (state->curEpoch == state->nextEpoch) { |
wolfSSL | 0:9d17e4342598 | 3951 | next = state->nextSeq; |
wolfSSL | 0:9d17e4342598 | 3952 | window = state->window; |
wolfSSL | 0:9d17e4342598 | 3953 | } |
wolfSSL | 0:9d17e4342598 | 3954 | else if (state->curEpoch < state->nextEpoch) { |
wolfSSL | 0:9d17e4342598 | 3955 | next = state->prevSeq; |
wolfSSL | 0:9d17e4342598 | 3956 | window = state->prevWindow; |
wolfSSL | 0:9d17e4342598 | 3957 | } |
wolfSSL | 0:9d17e4342598 | 3958 | else { |
wolfSSL | 0:9d17e4342598 | 3959 | return 0; |
wolfSSL | 0:9d17e4342598 | 3960 | } |
wolfSSL | 0:9d17e4342598 | 3961 | |
wolfSSL | 0:9d17e4342598 | 3962 | cur = state->curSeq; |
wolfSSL | 0:9d17e4342598 | 3963 | |
wolfSSL | 0:9d17e4342598 | 3964 | if ((next > DTLS_SEQ_BITS) && (cur < next - DTLS_SEQ_BITS)) { |
wolfSSL | 0:9d17e4342598 | 3965 | return 0; |
wolfSSL | 0:9d17e4342598 | 3966 | } |
wolfSSL | 0:9d17e4342598 | 3967 | else if ((cur < next) && (window & (1 << (next - cur - 1)))) { |
wolfSSL | 0:9d17e4342598 | 3968 | return 0; |
wolfSSL | 0:9d17e4342598 | 3969 | } |
wolfSSL | 0:9d17e4342598 | 3970 | |
wolfSSL | 0:9d17e4342598 | 3971 | return 1; |
wolfSSL | 0:9d17e4342598 | 3972 | } |
wolfSSL | 0:9d17e4342598 | 3973 | |
wolfSSL | 0:9d17e4342598 | 3974 | |
wolfSSL | 0:9d17e4342598 | 3975 | static INLINE int DtlsUpdateWindow(DtlsState* state) |
wolfSSL | 0:9d17e4342598 | 3976 | { |
wolfSSL | 0:9d17e4342598 | 3977 | word32 cur; |
wolfSSL | 0:9d17e4342598 | 3978 | word32* next; |
wolfSSL | 0:9d17e4342598 | 3979 | DtlsSeq* window; |
wolfSSL | 0:9d17e4342598 | 3980 | |
wolfSSL | 0:9d17e4342598 | 3981 | if (state->curEpoch == state->nextEpoch) { |
wolfSSL | 0:9d17e4342598 | 3982 | next = &state->nextSeq; |
wolfSSL | 0:9d17e4342598 | 3983 | window = &state->window; |
wolfSSL | 0:9d17e4342598 | 3984 | } |
wolfSSL | 0:9d17e4342598 | 3985 | else { |
wolfSSL | 0:9d17e4342598 | 3986 | next = &state->prevSeq; |
wolfSSL | 0:9d17e4342598 | 3987 | window = &state->prevWindow; |
wolfSSL | 0:9d17e4342598 | 3988 | } |
wolfSSL | 0:9d17e4342598 | 3989 | |
wolfSSL | 0:9d17e4342598 | 3990 | cur = state->curSeq; |
wolfSSL | 0:9d17e4342598 | 3991 | |
wolfSSL | 0:9d17e4342598 | 3992 | if (cur < *next) { |
wolfSSL | 0:9d17e4342598 | 3993 | *window |= (1 << (*next - cur - 1)); |
wolfSSL | 0:9d17e4342598 | 3994 | } |
wolfSSL | 0:9d17e4342598 | 3995 | else { |
wolfSSL | 0:9d17e4342598 | 3996 | *window <<= (1 + cur - *next); |
wolfSSL | 0:9d17e4342598 | 3997 | *window |= 1; |
wolfSSL | 0:9d17e4342598 | 3998 | *next = cur + 1; |
wolfSSL | 0:9d17e4342598 | 3999 | } |
wolfSSL | 0:9d17e4342598 | 4000 | |
wolfSSL | 0:9d17e4342598 | 4001 | return 1; |
wolfSSL | 0:9d17e4342598 | 4002 | } |
wolfSSL | 0:9d17e4342598 | 4003 | |
wolfSSL | 0:9d17e4342598 | 4004 | |
wolfSSL | 0:9d17e4342598 | 4005 | static int DtlsMsgDrain(CYASSL* ssl) |
wolfSSL | 0:9d17e4342598 | 4006 | { |
wolfSSL | 0:9d17e4342598 | 4007 | DtlsMsg* item = ssl->dtls_msg_list; |
wolfSSL | 0:9d17e4342598 | 4008 | int ret = 0; |
wolfSSL | 0:9d17e4342598 | 4009 | |
wolfSSL | 0:9d17e4342598 | 4010 | /* While there is an item in the store list, and it is the expected |
wolfSSL | 0:9d17e4342598 | 4011 | * message, and it is complete, and there hasn't been an error in the |
wolfSSL | 0:9d17e4342598 | 4012 | * last messge... */ |
wolfSSL | 0:9d17e4342598 | 4013 | while (item != NULL && |
wolfSSL | 0:9d17e4342598 | 4014 | ssl->keys.dtls_expected_peer_handshake_number == item->seq && |
wolfSSL | 0:9d17e4342598 | 4015 | item->fragSz == item->sz && |
wolfSSL | 0:9d17e4342598 | 4016 | ret == 0) { |
wolfSSL | 0:9d17e4342598 | 4017 | word32 idx = 0; |
wolfSSL | 0:9d17e4342598 | 4018 | ssl->keys.dtls_expected_peer_handshake_number++; |
wolfSSL | 0:9d17e4342598 | 4019 | ret = DoHandShakeMsgType(ssl, item->msg, |
wolfSSL | 0:9d17e4342598 | 4020 | &idx, item->type, item->sz, item->sz); |
wolfSSL | 0:9d17e4342598 | 4021 | ssl->dtls_msg_list = item->next; |
wolfSSL | 0:9d17e4342598 | 4022 | DtlsMsgDelete(item, ssl->heap); |
wolfSSL | 0:9d17e4342598 | 4023 | item = ssl->dtls_msg_list; |
wolfSSL | 0:9d17e4342598 | 4024 | } |
wolfSSL | 0:9d17e4342598 | 4025 | |
wolfSSL | 0:9d17e4342598 | 4026 | return ret; |
wolfSSL | 0:9d17e4342598 | 4027 | } |
wolfSSL | 0:9d17e4342598 | 4028 | |
wolfSSL | 0:9d17e4342598 | 4029 | |
wolfSSL | 0:9d17e4342598 | 4030 | static int DoDtlsHandShakeMsg(CYASSL* ssl, byte* input, word32* inOutIdx, |
wolfSSL | 0:9d17e4342598 | 4031 | word32 totalSz) |
wolfSSL | 0:9d17e4342598 | 4032 | { |
wolfSSL | 0:9d17e4342598 | 4033 | byte type; |
wolfSSL | 0:9d17e4342598 | 4034 | word32 size; |
wolfSSL | 0:9d17e4342598 | 4035 | word32 fragOffset, fragSz; |
wolfSSL | 0:9d17e4342598 | 4036 | int ret = 0; |
wolfSSL | 0:9d17e4342598 | 4037 | |
wolfSSL | 0:9d17e4342598 | 4038 | CYASSL_ENTER("DoDtlsHandShakeMsg()"); |
wolfSSL | 0:9d17e4342598 | 4039 | if (GetDtlsHandShakeHeader(ssl, input, inOutIdx, &type, |
wolfSSL | 0:9d17e4342598 | 4040 | &size, &fragOffset, &fragSz) != 0) |
wolfSSL | 0:9d17e4342598 | 4041 | return PARSE_ERROR; |
wolfSSL | 0:9d17e4342598 | 4042 | |
wolfSSL | 0:9d17e4342598 | 4043 | if (*inOutIdx + fragSz > totalSz) |
wolfSSL | 0:9d17e4342598 | 4044 | return INCOMPLETE_DATA; |
wolfSSL | 0:9d17e4342598 | 4045 | |
wolfSSL | 0:9d17e4342598 | 4046 | /* Check the handshake sequence number first. If out of order, |
wolfSSL | 0:9d17e4342598 | 4047 | * add the current message to the list. If the message is in order, |
wolfSSL | 0:9d17e4342598 | 4048 | * but it is a fragment, add the current message to the list, then |
wolfSSL | 0:9d17e4342598 | 4049 | * check the head of the list to see if it is complete, if so, pop |
wolfSSL | 0:9d17e4342598 | 4050 | * it out as the current message. If the message is complete and in |
wolfSSL | 0:9d17e4342598 | 4051 | * order, process it. Check the head of the list to see if it is in |
wolfSSL | 0:9d17e4342598 | 4052 | * order, if so, process it. (Repeat until list exhausted.) If the |
wolfSSL | 0:9d17e4342598 | 4053 | * head is out of order, return for more processing. |
wolfSSL | 0:9d17e4342598 | 4054 | */ |
wolfSSL | 0:9d17e4342598 | 4055 | if (ssl->keys.dtls_peer_handshake_number > |
wolfSSL | 0:9d17e4342598 | 4056 | ssl->keys.dtls_expected_peer_handshake_number) { |
wolfSSL | 0:9d17e4342598 | 4057 | /* Current message is out of order. It will get stored in the list. |
wolfSSL | 0:9d17e4342598 | 4058 | * Storing also takes care of defragmentation. */ |
wolfSSL | 0:9d17e4342598 | 4059 | ssl->dtls_msg_list = DtlsMsgStore(ssl->dtls_msg_list, |
wolfSSL | 0:9d17e4342598 | 4060 | ssl->keys.dtls_peer_handshake_number, input + *inOutIdx, |
wolfSSL | 0:9d17e4342598 | 4061 | size, type, fragOffset, fragSz, ssl->heap); |
wolfSSL | 0:9d17e4342598 | 4062 | *inOutIdx += fragSz; |
wolfSSL | 0:9d17e4342598 | 4063 | ret = 0; |
wolfSSL | 0:9d17e4342598 | 4064 | } |
wolfSSL | 0:9d17e4342598 | 4065 | else if (ssl->keys.dtls_peer_handshake_number < |
wolfSSL | 0:9d17e4342598 | 4066 | ssl->keys.dtls_expected_peer_handshake_number) { |
wolfSSL | 0:9d17e4342598 | 4067 | /* Already saw this message and processed it. It can be ignored. */ |
wolfSSL | 0:9d17e4342598 | 4068 | *inOutIdx += fragSz; |
wolfSSL | 0:9d17e4342598 | 4069 | ret = 0; |
wolfSSL | 0:9d17e4342598 | 4070 | } |
wolfSSL | 0:9d17e4342598 | 4071 | else if (fragSz < size) { |
wolfSSL | 0:9d17e4342598 | 4072 | /* Since this branch is in order, but fragmented, dtls_msg_list will be |
wolfSSL | 0:9d17e4342598 | 4073 | * pointing to the message with this fragment in it. Check it to see |
wolfSSL | 0:9d17e4342598 | 4074 | * if it is completed. */ |
wolfSSL | 0:9d17e4342598 | 4075 | ssl->dtls_msg_list = DtlsMsgStore(ssl->dtls_msg_list, |
wolfSSL | 0:9d17e4342598 | 4076 | ssl->keys.dtls_peer_handshake_number, input + *inOutIdx, |
wolfSSL | 0:9d17e4342598 | 4077 | size, type, fragOffset, fragSz, ssl->heap); |
wolfSSL | 0:9d17e4342598 | 4078 | *inOutIdx += fragSz; |
wolfSSL | 0:9d17e4342598 | 4079 | ret = 0; |
wolfSSL | 0:9d17e4342598 | 4080 | if (ssl->dtls_msg_list != NULL && |
wolfSSL | 0:9d17e4342598 | 4081 | ssl->dtls_msg_list->fragSz >= ssl->dtls_msg_list->sz) |
wolfSSL | 0:9d17e4342598 | 4082 | ret = DtlsMsgDrain(ssl); |
wolfSSL | 0:9d17e4342598 | 4083 | } |
wolfSSL | 0:9d17e4342598 | 4084 | else { |
wolfSSL | 0:9d17e4342598 | 4085 | /* This branch is in order next, and a complete message. */ |
wolfSSL | 0:9d17e4342598 | 4086 | ssl->keys.dtls_expected_peer_handshake_number++; |
wolfSSL | 0:9d17e4342598 | 4087 | ret = DoHandShakeMsgType(ssl, input, inOutIdx, type, size, totalSz); |
wolfSSL | 0:9d17e4342598 | 4088 | if (ret == 0 && ssl->dtls_msg_list != NULL) |
wolfSSL | 0:9d17e4342598 | 4089 | ret = DtlsMsgDrain(ssl); |
wolfSSL | 0:9d17e4342598 | 4090 | } |
wolfSSL | 0:9d17e4342598 | 4091 | |
wolfSSL | 0:9d17e4342598 | 4092 | CYASSL_LEAVE("DoDtlsHandShakeMsg()", ret); |
wolfSSL | 0:9d17e4342598 | 4093 | return ret; |
wolfSSL | 0:9d17e4342598 | 4094 | } |
wolfSSL | 0:9d17e4342598 | 4095 | #endif |
wolfSSL | 0:9d17e4342598 | 4096 | |
wolfSSL | 0:9d17e4342598 | 4097 | |
wolfSSL | 0:9d17e4342598 | 4098 | static INLINE word32 GetSEQIncrement(CYASSL* ssl, int verify) |
wolfSSL | 0:9d17e4342598 | 4099 | { |
wolfSSL | 0:9d17e4342598 | 4100 | if (verify) |
wolfSSL | 0:9d17e4342598 | 4101 | return ssl->keys.peer_sequence_number++; |
wolfSSL | 0:9d17e4342598 | 4102 | else |
wolfSSL | 0:9d17e4342598 | 4103 | return ssl->keys.sequence_number++; |
wolfSSL | 0:9d17e4342598 | 4104 | } |
wolfSSL | 0:9d17e4342598 | 4105 | |
wolfSSL | 0:9d17e4342598 | 4106 | |
wolfSSL | 0:9d17e4342598 | 4107 | #ifdef HAVE_AEAD |
wolfSSL | 0:9d17e4342598 | 4108 | static INLINE void AeadIncrementExpIV(CYASSL* ssl) |
wolfSSL | 0:9d17e4342598 | 4109 | { |
wolfSSL | 0:9d17e4342598 | 4110 | int i; |
wolfSSL | 0:9d17e4342598 | 4111 | for (i = AEAD_EXP_IV_SZ-1; i >= 0; i--) { |
wolfSSL | 0:9d17e4342598 | 4112 | if (++ssl->keys.aead_exp_IV[i]) return; |
wolfSSL | 0:9d17e4342598 | 4113 | } |
wolfSSL | 0:9d17e4342598 | 4114 | } |
wolfSSL | 0:9d17e4342598 | 4115 | #endif |
wolfSSL | 0:9d17e4342598 | 4116 | |
wolfSSL | 0:9d17e4342598 | 4117 | |
wolfSSL | 0:9d17e4342598 | 4118 | static INLINE int Encrypt(CYASSL* ssl, byte* out, const byte* input, word16 sz) |
wolfSSL | 0:9d17e4342598 | 4119 | { |
wolfSSL | 0:9d17e4342598 | 4120 | (void)out; |
wolfSSL | 0:9d17e4342598 | 4121 | (void)input; |
wolfSSL | 0:9d17e4342598 | 4122 | (void)sz; |
wolfSSL | 0:9d17e4342598 | 4123 | |
wolfSSL | 0:9d17e4342598 | 4124 | if (ssl->encrypt.setup == 0) { |
wolfSSL | 0:9d17e4342598 | 4125 | CYASSL_MSG("Encrypt ciphers not setup"); |
wolfSSL | 0:9d17e4342598 | 4126 | return ENCRYPT_ERROR; |
wolfSSL | 0:9d17e4342598 | 4127 | } |
wolfSSL | 0:9d17e4342598 | 4128 | |
wolfSSL | 0:9d17e4342598 | 4129 | switch (ssl->specs.bulk_cipher_algorithm) { |
wolfSSL | 0:9d17e4342598 | 4130 | #ifdef BUILD_ARC4 |
wolfSSL | 0:9d17e4342598 | 4131 | case cyassl_rc4: |
wolfSSL | 0:9d17e4342598 | 4132 | Arc4Process(ssl->encrypt.arc4, out, input, sz); |
wolfSSL | 0:9d17e4342598 | 4133 | break; |
wolfSSL | 0:9d17e4342598 | 4134 | #endif |
wolfSSL | 0:9d17e4342598 | 4135 | |
wolfSSL | 0:9d17e4342598 | 4136 | #ifdef BUILD_DES3 |
wolfSSL | 0:9d17e4342598 | 4137 | case cyassl_triple_des: |
wolfSSL | 0:9d17e4342598 | 4138 | return Des3_CbcEncrypt(ssl->encrypt.des3, out, input, sz); |
wolfSSL | 0:9d17e4342598 | 4139 | #endif |
wolfSSL | 0:9d17e4342598 | 4140 | |
wolfSSL | 0:9d17e4342598 | 4141 | #ifdef BUILD_AES |
wolfSSL | 0:9d17e4342598 | 4142 | case cyassl_aes: |
wolfSSL | 0:9d17e4342598 | 4143 | return AesCbcEncrypt(ssl->encrypt.aes, out, input, sz); |
wolfSSL | 0:9d17e4342598 | 4144 | #endif |
wolfSSL | 0:9d17e4342598 | 4145 | |
wolfSSL | 0:9d17e4342598 | 4146 | #ifdef BUILD_AESGCM |
wolfSSL | 0:9d17e4342598 | 4147 | case cyassl_aes_gcm: |
wolfSSL | 0:9d17e4342598 | 4148 | { |
wolfSSL | 0:9d17e4342598 | 4149 | byte additional[AES_BLOCK_SIZE]; |
wolfSSL | 0:9d17e4342598 | 4150 | byte nonce[AEAD_NONCE_SZ]; |
wolfSSL | 0:9d17e4342598 | 4151 | const byte* additionalSrc = input - 5; |
wolfSSL | 0:9d17e4342598 | 4152 | |
wolfSSL | 0:9d17e4342598 | 4153 | XMEMSET(additional, 0, AES_BLOCK_SIZE); |
wolfSSL | 0:9d17e4342598 | 4154 | |
wolfSSL | 0:9d17e4342598 | 4155 | /* sequence number field is 64-bits, we only use 32-bits */ |
wolfSSL | 0:9d17e4342598 | 4156 | c32toa(GetSEQIncrement(ssl, 0), |
wolfSSL | 0:9d17e4342598 | 4157 | additional + AEAD_SEQ_OFFSET); |
wolfSSL | 0:9d17e4342598 | 4158 | |
wolfSSL | 0:9d17e4342598 | 4159 | /* Store the type, version. Unfortunately, they are in |
wolfSSL | 0:9d17e4342598 | 4160 | * the input buffer ahead of the plaintext. */ |
wolfSSL | 0:9d17e4342598 | 4161 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 4162 | if (ssl->options.dtls) |
wolfSSL | 0:9d17e4342598 | 4163 | additionalSrc -= DTLS_HANDSHAKE_EXTRA; |
wolfSSL | 0:9d17e4342598 | 4164 | #endif |
wolfSSL | 0:9d17e4342598 | 4165 | XMEMCPY(additional + AEAD_TYPE_OFFSET, additionalSrc, 3); |
wolfSSL | 0:9d17e4342598 | 4166 | |
wolfSSL | 0:9d17e4342598 | 4167 | /* Store the length of the plain text minus the explicit |
wolfSSL | 0:9d17e4342598 | 4168 | * IV length minus the authentication tag size. */ |
wolfSSL | 0:9d17e4342598 | 4169 | c16toa(sz - AEAD_EXP_IV_SZ - ssl->specs.aead_mac_size, |
wolfSSL | 0:9d17e4342598 | 4170 | additional + AEAD_LEN_OFFSET); |
wolfSSL | 0:9d17e4342598 | 4171 | XMEMCPY(nonce, |
wolfSSL | 0:9d17e4342598 | 4172 | ssl->keys.aead_enc_imp_IV, AEAD_IMP_IV_SZ); |
wolfSSL | 0:9d17e4342598 | 4173 | XMEMCPY(nonce + AEAD_IMP_IV_SZ, |
wolfSSL | 0:9d17e4342598 | 4174 | ssl->keys.aead_exp_IV, AEAD_EXP_IV_SZ); |
wolfSSL | 0:9d17e4342598 | 4175 | AesGcmEncrypt(ssl->encrypt.aes, |
wolfSSL | 0:9d17e4342598 | 4176 | out + AEAD_EXP_IV_SZ, input + AEAD_EXP_IV_SZ, |
wolfSSL | 0:9d17e4342598 | 4177 | sz - AEAD_EXP_IV_SZ - ssl->specs.aead_mac_size, |
wolfSSL | 0:9d17e4342598 | 4178 | nonce, AEAD_NONCE_SZ, |
wolfSSL | 0:9d17e4342598 | 4179 | out + sz - ssl->specs.aead_mac_size, |
wolfSSL | 0:9d17e4342598 | 4180 | ssl->specs.aead_mac_size, additional, |
wolfSSL | 0:9d17e4342598 | 4181 | AEAD_AUTH_DATA_SZ); |
wolfSSL | 0:9d17e4342598 | 4182 | AeadIncrementExpIV(ssl); |
wolfSSL | 0:9d17e4342598 | 4183 | XMEMSET(nonce, 0, AEAD_NONCE_SZ); |
wolfSSL | 0:9d17e4342598 | 4184 | } |
wolfSSL | 0:9d17e4342598 | 4185 | break; |
wolfSSL | 0:9d17e4342598 | 4186 | #endif |
wolfSSL | 0:9d17e4342598 | 4187 | |
wolfSSL | 0:9d17e4342598 | 4188 | #ifdef HAVE_AESCCM |
wolfSSL | 0:9d17e4342598 | 4189 | case cyassl_aes_ccm: |
wolfSSL | 0:9d17e4342598 | 4190 | { |
wolfSSL | 0:9d17e4342598 | 4191 | byte additional[AES_BLOCK_SIZE]; |
wolfSSL | 0:9d17e4342598 | 4192 | byte nonce[AEAD_NONCE_SZ]; |
wolfSSL | 0:9d17e4342598 | 4193 | const byte* additionalSrc = input - 5; |
wolfSSL | 0:9d17e4342598 | 4194 | |
wolfSSL | 0:9d17e4342598 | 4195 | XMEMSET(additional, 0, AES_BLOCK_SIZE); |
wolfSSL | 0:9d17e4342598 | 4196 | |
wolfSSL | 0:9d17e4342598 | 4197 | /* sequence number field is 64-bits, we only use 32-bits */ |
wolfSSL | 0:9d17e4342598 | 4198 | c32toa(GetSEQIncrement(ssl, 0), |
wolfSSL | 0:9d17e4342598 | 4199 | additional + AEAD_SEQ_OFFSET); |
wolfSSL | 0:9d17e4342598 | 4200 | |
wolfSSL | 0:9d17e4342598 | 4201 | /* Store the type, version. Unfortunately, they are in |
wolfSSL | 0:9d17e4342598 | 4202 | * the input buffer ahead of the plaintext. */ |
wolfSSL | 0:9d17e4342598 | 4203 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 4204 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 4205 | c16toa(ssl->keys.dtls_epoch, additional); |
wolfSSL | 0:9d17e4342598 | 4206 | additionalSrc -= DTLS_HANDSHAKE_EXTRA; |
wolfSSL | 0:9d17e4342598 | 4207 | } |
wolfSSL | 0:9d17e4342598 | 4208 | #endif |
wolfSSL | 0:9d17e4342598 | 4209 | XMEMCPY(additional + AEAD_TYPE_OFFSET, additionalSrc, 3); |
wolfSSL | 0:9d17e4342598 | 4210 | |
wolfSSL | 0:9d17e4342598 | 4211 | /* Store the length of the plain text minus the explicit |
wolfSSL | 0:9d17e4342598 | 4212 | * IV length minus the authentication tag size. */ |
wolfSSL | 0:9d17e4342598 | 4213 | c16toa(sz - AEAD_EXP_IV_SZ - ssl->specs.aead_mac_size, |
wolfSSL | 0:9d17e4342598 | 4214 | additional + AEAD_LEN_OFFSET); |
wolfSSL | 0:9d17e4342598 | 4215 | XMEMCPY(nonce, |
wolfSSL | 0:9d17e4342598 | 4216 | ssl->keys.aead_enc_imp_IV, AEAD_IMP_IV_SZ); |
wolfSSL | 0:9d17e4342598 | 4217 | XMEMCPY(nonce + AEAD_IMP_IV_SZ, |
wolfSSL | 0:9d17e4342598 | 4218 | ssl->keys.aead_exp_IV, AEAD_EXP_IV_SZ); |
wolfSSL | 0:9d17e4342598 | 4219 | AesCcmEncrypt(ssl->encrypt.aes, |
wolfSSL | 0:9d17e4342598 | 4220 | out + AEAD_EXP_IV_SZ, input + AEAD_EXP_IV_SZ, |
wolfSSL | 0:9d17e4342598 | 4221 | sz - AEAD_EXP_IV_SZ - ssl->specs.aead_mac_size, |
wolfSSL | 0:9d17e4342598 | 4222 | nonce, AEAD_NONCE_SZ, |
wolfSSL | 0:9d17e4342598 | 4223 | out + sz - ssl->specs.aead_mac_size, |
wolfSSL | 0:9d17e4342598 | 4224 | ssl->specs.aead_mac_size, |
wolfSSL | 0:9d17e4342598 | 4225 | additional, AEAD_AUTH_DATA_SZ); |
wolfSSL | 0:9d17e4342598 | 4226 | AeadIncrementExpIV(ssl); |
wolfSSL | 0:9d17e4342598 | 4227 | XMEMSET(nonce, 0, AEAD_NONCE_SZ); |
wolfSSL | 0:9d17e4342598 | 4228 | |
wolfSSL | 0:9d17e4342598 | 4229 | break; |
wolfSSL | 0:9d17e4342598 | 4230 | } |
wolfSSL | 0:9d17e4342598 | 4231 | #endif |
wolfSSL | 0:9d17e4342598 | 4232 | |
wolfSSL | 0:9d17e4342598 | 4233 | #ifdef HAVE_CAMELLIA |
wolfSSL | 0:9d17e4342598 | 4234 | case cyassl_camellia: |
wolfSSL | 0:9d17e4342598 | 4235 | CamelliaCbcEncrypt(ssl->encrypt.cam, out, input, sz); |
wolfSSL | 0:9d17e4342598 | 4236 | break; |
wolfSSL | 0:9d17e4342598 | 4237 | #endif |
wolfSSL | 0:9d17e4342598 | 4238 | |
wolfSSL | 0:9d17e4342598 | 4239 | #ifdef HAVE_HC128 |
wolfSSL | 0:9d17e4342598 | 4240 | case cyassl_hc128: |
wolfSSL | 0:9d17e4342598 | 4241 | return Hc128_Process(ssl->encrypt.hc128, out, input, sz); |
wolfSSL | 0:9d17e4342598 | 4242 | #endif |
wolfSSL | 0:9d17e4342598 | 4243 | |
wolfSSL | 0:9d17e4342598 | 4244 | #ifdef BUILD_RABBIT |
wolfSSL | 0:9d17e4342598 | 4245 | case cyassl_rabbit: |
wolfSSL | 0:9d17e4342598 | 4246 | return RabbitProcess(ssl->encrypt.rabbit, out, input, sz); |
wolfSSL | 0:9d17e4342598 | 4247 | #endif |
wolfSSL | 0:9d17e4342598 | 4248 | |
wolfSSL | 0:9d17e4342598 | 4249 | #ifdef HAVE_NULL_CIPHER |
wolfSSL | 0:9d17e4342598 | 4250 | case cyassl_cipher_null: |
wolfSSL | 0:9d17e4342598 | 4251 | if (input != out) { |
wolfSSL | 0:9d17e4342598 | 4252 | XMEMMOVE(out, input, sz); |
wolfSSL | 0:9d17e4342598 | 4253 | } |
wolfSSL | 0:9d17e4342598 | 4254 | break; |
wolfSSL | 0:9d17e4342598 | 4255 | #endif |
wolfSSL | 0:9d17e4342598 | 4256 | |
wolfSSL | 0:9d17e4342598 | 4257 | default: |
wolfSSL | 0:9d17e4342598 | 4258 | CYASSL_MSG("CyaSSL Encrypt programming error"); |
wolfSSL | 0:9d17e4342598 | 4259 | return ENCRYPT_ERROR; |
wolfSSL | 0:9d17e4342598 | 4260 | } |
wolfSSL | 0:9d17e4342598 | 4261 | |
wolfSSL | 0:9d17e4342598 | 4262 | return 0; |
wolfSSL | 0:9d17e4342598 | 4263 | } |
wolfSSL | 0:9d17e4342598 | 4264 | |
wolfSSL | 0:9d17e4342598 | 4265 | |
wolfSSL | 0:9d17e4342598 | 4266 | |
wolfSSL | 0:9d17e4342598 | 4267 | static INLINE int Decrypt(CYASSL* ssl, byte* plain, const byte* input, |
wolfSSL | 0:9d17e4342598 | 4268 | word16 sz) |
wolfSSL | 0:9d17e4342598 | 4269 | { |
wolfSSL | 0:9d17e4342598 | 4270 | (void)plain; |
wolfSSL | 0:9d17e4342598 | 4271 | (void)input; |
wolfSSL | 0:9d17e4342598 | 4272 | (void)sz; |
wolfSSL | 0:9d17e4342598 | 4273 | |
wolfSSL | 0:9d17e4342598 | 4274 | if (ssl->decrypt.setup == 0) { |
wolfSSL | 0:9d17e4342598 | 4275 | CYASSL_MSG("Decrypt ciphers not setup"); |
wolfSSL | 0:9d17e4342598 | 4276 | return DECRYPT_ERROR; |
wolfSSL | 0:9d17e4342598 | 4277 | } |
wolfSSL | 0:9d17e4342598 | 4278 | |
wolfSSL | 0:9d17e4342598 | 4279 | switch (ssl->specs.bulk_cipher_algorithm) { |
wolfSSL | 0:9d17e4342598 | 4280 | #ifdef BUILD_ARC4 |
wolfSSL | 0:9d17e4342598 | 4281 | case cyassl_rc4: |
wolfSSL | 0:9d17e4342598 | 4282 | Arc4Process(ssl->decrypt.arc4, plain, input, sz); |
wolfSSL | 0:9d17e4342598 | 4283 | break; |
wolfSSL | 0:9d17e4342598 | 4284 | #endif |
wolfSSL | 0:9d17e4342598 | 4285 | |
wolfSSL | 0:9d17e4342598 | 4286 | #ifdef BUILD_DES3 |
wolfSSL | 0:9d17e4342598 | 4287 | case cyassl_triple_des: |
wolfSSL | 0:9d17e4342598 | 4288 | return Des3_CbcDecrypt(ssl->decrypt.des3, plain, input, sz); |
wolfSSL | 0:9d17e4342598 | 4289 | #endif |
wolfSSL | 0:9d17e4342598 | 4290 | |
wolfSSL | 0:9d17e4342598 | 4291 | #ifdef BUILD_AES |
wolfSSL | 0:9d17e4342598 | 4292 | case cyassl_aes: |
wolfSSL | 0:9d17e4342598 | 4293 | return AesCbcDecrypt(ssl->decrypt.aes, plain, input, sz); |
wolfSSL | 0:9d17e4342598 | 4294 | #endif |
wolfSSL | 0:9d17e4342598 | 4295 | |
wolfSSL | 0:9d17e4342598 | 4296 | #ifdef BUILD_AESGCM |
wolfSSL | 0:9d17e4342598 | 4297 | case cyassl_aes_gcm: |
wolfSSL | 0:9d17e4342598 | 4298 | { |
wolfSSL | 0:9d17e4342598 | 4299 | byte additional[AES_BLOCK_SIZE]; |
wolfSSL | 0:9d17e4342598 | 4300 | byte nonce[AEAD_NONCE_SZ]; |
wolfSSL | 0:9d17e4342598 | 4301 | |
wolfSSL | 0:9d17e4342598 | 4302 | XMEMSET(additional, 0, AES_BLOCK_SIZE); |
wolfSSL | 0:9d17e4342598 | 4303 | |
wolfSSL | 0:9d17e4342598 | 4304 | /* sequence number field is 64-bits, we only use 32-bits */ |
wolfSSL | 0:9d17e4342598 | 4305 | c32toa(GetSEQIncrement(ssl, 1), additional + AEAD_SEQ_OFFSET); |
wolfSSL | 0:9d17e4342598 | 4306 | |
wolfSSL | 0:9d17e4342598 | 4307 | additional[AEAD_TYPE_OFFSET] = ssl->curRL.type; |
wolfSSL | 0:9d17e4342598 | 4308 | additional[AEAD_VMAJ_OFFSET] = ssl->curRL.pvMajor; |
wolfSSL | 0:9d17e4342598 | 4309 | additional[AEAD_VMIN_OFFSET] = ssl->curRL.pvMinor; |
wolfSSL | 0:9d17e4342598 | 4310 | |
wolfSSL | 0:9d17e4342598 | 4311 | c16toa(sz - AEAD_EXP_IV_SZ - ssl->specs.aead_mac_size, |
wolfSSL | 0:9d17e4342598 | 4312 | additional + AEAD_LEN_OFFSET); |
wolfSSL | 0:9d17e4342598 | 4313 | XMEMCPY(nonce, ssl->keys.aead_dec_imp_IV, AEAD_IMP_IV_SZ); |
wolfSSL | 0:9d17e4342598 | 4314 | XMEMCPY(nonce + AEAD_IMP_IV_SZ, input, AEAD_EXP_IV_SZ); |
wolfSSL | 0:9d17e4342598 | 4315 | if (AesGcmDecrypt(ssl->decrypt.aes, |
wolfSSL | 0:9d17e4342598 | 4316 | plain + AEAD_EXP_IV_SZ, |
wolfSSL | 0:9d17e4342598 | 4317 | input + AEAD_EXP_IV_SZ, |
wolfSSL | 0:9d17e4342598 | 4318 | sz - AEAD_EXP_IV_SZ - ssl->specs.aead_mac_size, |
wolfSSL | 0:9d17e4342598 | 4319 | nonce, AEAD_NONCE_SZ, |
wolfSSL | 0:9d17e4342598 | 4320 | input + sz - ssl->specs.aead_mac_size, |
wolfSSL | 0:9d17e4342598 | 4321 | ssl->specs.aead_mac_size, |
wolfSSL | 0:9d17e4342598 | 4322 | additional, AEAD_AUTH_DATA_SZ) < 0) { |
wolfSSL | 0:9d17e4342598 | 4323 | SendAlert(ssl, alert_fatal, bad_record_mac); |
wolfSSL | 0:9d17e4342598 | 4324 | XMEMSET(nonce, 0, AEAD_NONCE_SZ); |
wolfSSL | 0:9d17e4342598 | 4325 | return VERIFY_MAC_ERROR; |
wolfSSL | 0:9d17e4342598 | 4326 | } |
wolfSSL | 0:9d17e4342598 | 4327 | XMEMSET(nonce, 0, AEAD_NONCE_SZ); |
wolfSSL | 0:9d17e4342598 | 4328 | break; |
wolfSSL | 0:9d17e4342598 | 4329 | } |
wolfSSL | 0:9d17e4342598 | 4330 | #endif |
wolfSSL | 0:9d17e4342598 | 4331 | |
wolfSSL | 0:9d17e4342598 | 4332 | #ifdef HAVE_AESCCM |
wolfSSL | 0:9d17e4342598 | 4333 | case cyassl_aes_ccm: |
wolfSSL | 0:9d17e4342598 | 4334 | { |
wolfSSL | 0:9d17e4342598 | 4335 | byte additional[AES_BLOCK_SIZE]; |
wolfSSL | 0:9d17e4342598 | 4336 | byte nonce[AEAD_NONCE_SZ]; |
wolfSSL | 0:9d17e4342598 | 4337 | |
wolfSSL | 0:9d17e4342598 | 4338 | XMEMSET(additional, 0, AES_BLOCK_SIZE); |
wolfSSL | 0:9d17e4342598 | 4339 | |
wolfSSL | 0:9d17e4342598 | 4340 | /* sequence number field is 64-bits, we only use 32-bits */ |
wolfSSL | 0:9d17e4342598 | 4341 | c32toa(GetSEQIncrement(ssl, 1), additional + AEAD_SEQ_OFFSET); |
wolfSSL | 0:9d17e4342598 | 4342 | |
wolfSSL | 0:9d17e4342598 | 4343 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 4344 | if (ssl->options.dtls) |
wolfSSL | 0:9d17e4342598 | 4345 | c16toa(ssl->keys.dtls_state.curEpoch, additional); |
wolfSSL | 0:9d17e4342598 | 4346 | #endif |
wolfSSL | 0:9d17e4342598 | 4347 | |
wolfSSL | 0:9d17e4342598 | 4348 | additional[AEAD_TYPE_OFFSET] = ssl->curRL.type; |
wolfSSL | 0:9d17e4342598 | 4349 | additional[AEAD_VMAJ_OFFSET] = ssl->curRL.pvMajor; |
wolfSSL | 0:9d17e4342598 | 4350 | additional[AEAD_VMIN_OFFSET] = ssl->curRL.pvMinor; |
wolfSSL | 0:9d17e4342598 | 4351 | |
wolfSSL | 0:9d17e4342598 | 4352 | c16toa(sz - AEAD_EXP_IV_SZ - ssl->specs.aead_mac_size, |
wolfSSL | 0:9d17e4342598 | 4353 | additional + AEAD_LEN_OFFSET); |
wolfSSL | 0:9d17e4342598 | 4354 | XMEMCPY(nonce, ssl->keys.aead_dec_imp_IV, AEAD_IMP_IV_SZ); |
wolfSSL | 0:9d17e4342598 | 4355 | XMEMCPY(nonce + AEAD_IMP_IV_SZ, input, AEAD_EXP_IV_SZ); |
wolfSSL | 0:9d17e4342598 | 4356 | if (AesCcmDecrypt(ssl->decrypt.aes, |
wolfSSL | 0:9d17e4342598 | 4357 | plain + AEAD_EXP_IV_SZ, |
wolfSSL | 0:9d17e4342598 | 4358 | input + AEAD_EXP_IV_SZ, |
wolfSSL | 0:9d17e4342598 | 4359 | sz - AEAD_EXP_IV_SZ - ssl->specs.aead_mac_size, |
wolfSSL | 0:9d17e4342598 | 4360 | nonce, AEAD_NONCE_SZ, |
wolfSSL | 0:9d17e4342598 | 4361 | input + sz - ssl->specs.aead_mac_size, |
wolfSSL | 0:9d17e4342598 | 4362 | ssl->specs.aead_mac_size, |
wolfSSL | 0:9d17e4342598 | 4363 | additional, AEAD_AUTH_DATA_SZ) < 0) { |
wolfSSL | 0:9d17e4342598 | 4364 | SendAlert(ssl, alert_fatal, bad_record_mac); |
wolfSSL | 0:9d17e4342598 | 4365 | XMEMSET(nonce, 0, AEAD_NONCE_SZ); |
wolfSSL | 0:9d17e4342598 | 4366 | return VERIFY_MAC_ERROR; |
wolfSSL | 0:9d17e4342598 | 4367 | } |
wolfSSL | 0:9d17e4342598 | 4368 | XMEMSET(nonce, 0, AEAD_NONCE_SZ); |
wolfSSL | 0:9d17e4342598 | 4369 | break; |
wolfSSL | 0:9d17e4342598 | 4370 | } |
wolfSSL | 0:9d17e4342598 | 4371 | #endif |
wolfSSL | 0:9d17e4342598 | 4372 | |
wolfSSL | 0:9d17e4342598 | 4373 | #ifdef HAVE_CAMELLIA |
wolfSSL | 0:9d17e4342598 | 4374 | case cyassl_camellia: |
wolfSSL | 0:9d17e4342598 | 4375 | CamelliaCbcDecrypt(ssl->decrypt.cam, plain, input, sz); |
wolfSSL | 0:9d17e4342598 | 4376 | break; |
wolfSSL | 0:9d17e4342598 | 4377 | #endif |
wolfSSL | 0:9d17e4342598 | 4378 | |
wolfSSL | 0:9d17e4342598 | 4379 | #ifdef HAVE_HC128 |
wolfSSL | 0:9d17e4342598 | 4380 | case cyassl_hc128: |
wolfSSL | 0:9d17e4342598 | 4381 | return Hc128_Process(ssl->decrypt.hc128, plain, input, sz); |
wolfSSL | 0:9d17e4342598 | 4382 | #endif |
wolfSSL | 0:9d17e4342598 | 4383 | |
wolfSSL | 0:9d17e4342598 | 4384 | #ifdef BUILD_RABBIT |
wolfSSL | 0:9d17e4342598 | 4385 | case cyassl_rabbit: |
wolfSSL | 0:9d17e4342598 | 4386 | return RabbitProcess(ssl->decrypt.rabbit, plain, input, sz); |
wolfSSL | 0:9d17e4342598 | 4387 | #endif |
wolfSSL | 0:9d17e4342598 | 4388 | |
wolfSSL | 0:9d17e4342598 | 4389 | #ifdef HAVE_NULL_CIPHER |
wolfSSL | 0:9d17e4342598 | 4390 | case cyassl_cipher_null: |
wolfSSL | 0:9d17e4342598 | 4391 | if (input != plain) { |
wolfSSL | 0:9d17e4342598 | 4392 | XMEMMOVE(plain, input, sz); |
wolfSSL | 0:9d17e4342598 | 4393 | } |
wolfSSL | 0:9d17e4342598 | 4394 | break; |
wolfSSL | 0:9d17e4342598 | 4395 | #endif |
wolfSSL | 0:9d17e4342598 | 4396 | |
wolfSSL | 0:9d17e4342598 | 4397 | default: |
wolfSSL | 0:9d17e4342598 | 4398 | CYASSL_MSG("CyaSSL Decrypt programming error"); |
wolfSSL | 0:9d17e4342598 | 4399 | return DECRYPT_ERROR; |
wolfSSL | 0:9d17e4342598 | 4400 | } |
wolfSSL | 0:9d17e4342598 | 4401 | return 0; |
wolfSSL | 0:9d17e4342598 | 4402 | } |
wolfSSL | 0:9d17e4342598 | 4403 | |
wolfSSL | 0:9d17e4342598 | 4404 | |
wolfSSL | 0:9d17e4342598 | 4405 | /* check cipher text size for sanity */ |
wolfSSL | 0:9d17e4342598 | 4406 | static int SanityCheckCipherText(CYASSL* ssl, word32 encryptSz) |
wolfSSL | 0:9d17e4342598 | 4407 | { |
wolfSSL | 0:9d17e4342598 | 4408 | #ifdef HAVE_TRUNCATED_HMAC |
wolfSSL | 0:9d17e4342598 | 4409 | word32 minLength = ssl->truncated_hmac ? TRUNCATED_HMAC_SZ |
wolfSSL | 0:9d17e4342598 | 4410 | : ssl->specs.hash_size; |
wolfSSL | 0:9d17e4342598 | 4411 | #else |
wolfSSL | 0:9d17e4342598 | 4412 | word32 minLength = ssl->specs.hash_size; /* covers stream */ |
wolfSSL | 0:9d17e4342598 | 4413 | #endif |
wolfSSL | 0:9d17e4342598 | 4414 | |
wolfSSL | 0:9d17e4342598 | 4415 | if (ssl->specs.cipher_type == block) { |
wolfSSL | 0:9d17e4342598 | 4416 | if (encryptSz % ssl->specs.block_size) { |
wolfSSL | 0:9d17e4342598 | 4417 | CYASSL_MSG("Block ciphertext not block size"); |
wolfSSL | 0:9d17e4342598 | 4418 | return SANITY_CIPHER_E; |
wolfSSL | 0:9d17e4342598 | 4419 | } |
wolfSSL | 0:9d17e4342598 | 4420 | |
wolfSSL | 0:9d17e4342598 | 4421 | minLength++; /* pad byte */ |
wolfSSL | 0:9d17e4342598 | 4422 | |
wolfSSL | 0:9d17e4342598 | 4423 | if (ssl->specs.block_size > minLength) |
wolfSSL | 0:9d17e4342598 | 4424 | minLength = ssl->specs.block_size; |
wolfSSL | 0:9d17e4342598 | 4425 | |
wolfSSL | 0:9d17e4342598 | 4426 | if (ssl->options.tls1_1) |
wolfSSL | 0:9d17e4342598 | 4427 | minLength += ssl->specs.block_size; /* explicit IV */ |
wolfSSL | 0:9d17e4342598 | 4428 | } |
wolfSSL | 0:9d17e4342598 | 4429 | else if (ssl->specs.cipher_type == aead) { |
wolfSSL | 0:9d17e4342598 | 4430 | minLength = ssl->specs.aead_mac_size + AEAD_EXP_IV_SZ; |
wolfSSL | 0:9d17e4342598 | 4431 | /* explicit IV + authTag size */ |
wolfSSL | 0:9d17e4342598 | 4432 | } |
wolfSSL | 0:9d17e4342598 | 4433 | |
wolfSSL | 0:9d17e4342598 | 4434 | if (encryptSz < minLength) { |
wolfSSL | 0:9d17e4342598 | 4435 | CYASSL_MSG("Ciphertext not minimum size"); |
wolfSSL | 0:9d17e4342598 | 4436 | return SANITY_CIPHER_E; |
wolfSSL | 0:9d17e4342598 | 4437 | } |
wolfSSL | 0:9d17e4342598 | 4438 | |
wolfSSL | 0:9d17e4342598 | 4439 | return 0; |
wolfSSL | 0:9d17e4342598 | 4440 | } |
wolfSSL | 0:9d17e4342598 | 4441 | |
wolfSSL | 0:9d17e4342598 | 4442 | |
wolfSSL | 0:9d17e4342598 | 4443 | #ifndef NO_OLD_TLS |
wolfSSL | 0:9d17e4342598 | 4444 | |
wolfSSL | 0:9d17e4342598 | 4445 | static INLINE void Md5Rounds(int rounds, const byte* data, int sz) |
wolfSSL | 0:9d17e4342598 | 4446 | { |
wolfSSL | 0:9d17e4342598 | 4447 | Md5 md5; |
wolfSSL | 0:9d17e4342598 | 4448 | int i; |
wolfSSL | 0:9d17e4342598 | 4449 | |
wolfSSL | 0:9d17e4342598 | 4450 | InitMd5(&md5); |
wolfSSL | 0:9d17e4342598 | 4451 | |
wolfSSL | 0:9d17e4342598 | 4452 | for (i = 0; i < rounds; i++) |
wolfSSL | 0:9d17e4342598 | 4453 | Md5Update(&md5, data, sz); |
wolfSSL | 0:9d17e4342598 | 4454 | } |
wolfSSL | 0:9d17e4342598 | 4455 | |
wolfSSL | 0:9d17e4342598 | 4456 | |
wolfSSL | 0:9d17e4342598 | 4457 | |
wolfSSL | 0:9d17e4342598 | 4458 | /* do a dummy sha round */ |
wolfSSL | 0:9d17e4342598 | 4459 | static INLINE void ShaRounds(int rounds, const byte* data, int sz) |
wolfSSL | 0:9d17e4342598 | 4460 | { |
wolfSSL | 0:9d17e4342598 | 4461 | Sha sha; |
wolfSSL | 0:9d17e4342598 | 4462 | int i; |
wolfSSL | 0:9d17e4342598 | 4463 | |
wolfSSL | 0:9d17e4342598 | 4464 | InitSha(&sha); /* no error check on purpose, dummy round */ |
wolfSSL | 0:9d17e4342598 | 4465 | |
wolfSSL | 0:9d17e4342598 | 4466 | for (i = 0; i < rounds; i++) |
wolfSSL | 0:9d17e4342598 | 4467 | ShaUpdate(&sha, data, sz); |
wolfSSL | 0:9d17e4342598 | 4468 | } |
wolfSSL | 0:9d17e4342598 | 4469 | #endif |
wolfSSL | 0:9d17e4342598 | 4470 | |
wolfSSL | 0:9d17e4342598 | 4471 | |
wolfSSL | 0:9d17e4342598 | 4472 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 4473 | |
wolfSSL | 0:9d17e4342598 | 4474 | static INLINE void Sha256Rounds(int rounds, const byte* data, int sz) |
wolfSSL | 0:9d17e4342598 | 4475 | { |
wolfSSL | 0:9d17e4342598 | 4476 | Sha256 sha256; |
wolfSSL | 0:9d17e4342598 | 4477 | int i; |
wolfSSL | 0:9d17e4342598 | 4478 | |
wolfSSL | 0:9d17e4342598 | 4479 | InitSha256(&sha256); /* no error check on purpose, dummy round */ |
wolfSSL | 0:9d17e4342598 | 4480 | |
wolfSSL | 0:9d17e4342598 | 4481 | for (i = 0; i < rounds; i++) |
wolfSSL | 0:9d17e4342598 | 4482 | Sha256Update(&sha256, data, sz); |
wolfSSL | 0:9d17e4342598 | 4483 | } |
wolfSSL | 0:9d17e4342598 | 4484 | |
wolfSSL | 0:9d17e4342598 | 4485 | #endif |
wolfSSL | 0:9d17e4342598 | 4486 | |
wolfSSL | 0:9d17e4342598 | 4487 | |
wolfSSL | 0:9d17e4342598 | 4488 | #ifdef CYASSL_SHA384 |
wolfSSL | 0:9d17e4342598 | 4489 | |
wolfSSL | 0:9d17e4342598 | 4490 | static INLINE void Sha384Rounds(int rounds, const byte* data, int sz) |
wolfSSL | 0:9d17e4342598 | 4491 | { |
wolfSSL | 0:9d17e4342598 | 4492 | Sha384 sha384; |
wolfSSL | 0:9d17e4342598 | 4493 | int i; |
wolfSSL | 0:9d17e4342598 | 4494 | |
wolfSSL | 0:9d17e4342598 | 4495 | InitSha384(&sha384); /* no error check on purpose, dummy round */ |
wolfSSL | 0:9d17e4342598 | 4496 | |
wolfSSL | 0:9d17e4342598 | 4497 | for (i = 0; i < rounds; i++) |
wolfSSL | 0:9d17e4342598 | 4498 | Sha384Update(&sha384, data, sz); |
wolfSSL | 0:9d17e4342598 | 4499 | } |
wolfSSL | 0:9d17e4342598 | 4500 | |
wolfSSL | 0:9d17e4342598 | 4501 | #endif |
wolfSSL | 0:9d17e4342598 | 4502 | |
wolfSSL | 0:9d17e4342598 | 4503 | |
wolfSSL | 0:9d17e4342598 | 4504 | #ifdef CYASSL_SHA512 |
wolfSSL | 0:9d17e4342598 | 4505 | |
wolfSSL | 0:9d17e4342598 | 4506 | static INLINE void Sha512Rounds(int rounds, const byte* data, int sz) |
wolfSSL | 0:9d17e4342598 | 4507 | { |
wolfSSL | 0:9d17e4342598 | 4508 | Sha512 sha512; |
wolfSSL | 0:9d17e4342598 | 4509 | int i; |
wolfSSL | 0:9d17e4342598 | 4510 | |
wolfSSL | 0:9d17e4342598 | 4511 | InitSha512(&sha512); /* no error check on purpose, dummy round */ |
wolfSSL | 0:9d17e4342598 | 4512 | |
wolfSSL | 0:9d17e4342598 | 4513 | for (i = 0; i < rounds; i++) |
wolfSSL | 0:9d17e4342598 | 4514 | Sha512Update(&sha512, data, sz); |
wolfSSL | 0:9d17e4342598 | 4515 | } |
wolfSSL | 0:9d17e4342598 | 4516 | |
wolfSSL | 0:9d17e4342598 | 4517 | #endif |
wolfSSL | 0:9d17e4342598 | 4518 | |
wolfSSL | 0:9d17e4342598 | 4519 | |
wolfSSL | 0:9d17e4342598 | 4520 | #ifdef CYASSL_RIPEMD |
wolfSSL | 0:9d17e4342598 | 4521 | |
wolfSSL | 0:9d17e4342598 | 4522 | static INLINE void RmdRounds(int rounds, const byte* data, int sz) |
wolfSSL | 0:9d17e4342598 | 4523 | { |
wolfSSL | 0:9d17e4342598 | 4524 | RipeMd ripemd; |
wolfSSL | 0:9d17e4342598 | 4525 | int i; |
wolfSSL | 0:9d17e4342598 | 4526 | |
wolfSSL | 0:9d17e4342598 | 4527 | InitRipeMd(&ripemd); |
wolfSSL | 0:9d17e4342598 | 4528 | |
wolfSSL | 0:9d17e4342598 | 4529 | for (i = 0; i < rounds; i++) |
wolfSSL | 0:9d17e4342598 | 4530 | RipeMdUpdate(&ripemd, data, sz); |
wolfSSL | 0:9d17e4342598 | 4531 | } |
wolfSSL | 0:9d17e4342598 | 4532 | |
wolfSSL | 0:9d17e4342598 | 4533 | #endif |
wolfSSL | 0:9d17e4342598 | 4534 | |
wolfSSL | 0:9d17e4342598 | 4535 | |
wolfSSL | 0:9d17e4342598 | 4536 | /* Do dummy rounds */ |
wolfSSL | 0:9d17e4342598 | 4537 | static INLINE void DoRounds(int type, int rounds, const byte* data, int sz) |
wolfSSL | 0:9d17e4342598 | 4538 | { |
wolfSSL | 0:9d17e4342598 | 4539 | switch (type) { |
wolfSSL | 0:9d17e4342598 | 4540 | |
wolfSSL | 0:9d17e4342598 | 4541 | case no_mac : |
wolfSSL | 0:9d17e4342598 | 4542 | break; |
wolfSSL | 0:9d17e4342598 | 4543 | |
wolfSSL | 0:9d17e4342598 | 4544 | #ifndef NO_OLD_TLS |
wolfSSL | 0:9d17e4342598 | 4545 | #ifndef NO_MD5 |
wolfSSL | 0:9d17e4342598 | 4546 | case md5_mac : |
wolfSSL | 0:9d17e4342598 | 4547 | Md5Rounds(rounds, data, sz); |
wolfSSL | 0:9d17e4342598 | 4548 | break; |
wolfSSL | 0:9d17e4342598 | 4549 | #endif |
wolfSSL | 0:9d17e4342598 | 4550 | |
wolfSSL | 0:9d17e4342598 | 4551 | #ifndef NO_SHA |
wolfSSL | 0:9d17e4342598 | 4552 | case sha_mac : |
wolfSSL | 0:9d17e4342598 | 4553 | ShaRounds(rounds, data, sz); |
wolfSSL | 0:9d17e4342598 | 4554 | break; |
wolfSSL | 0:9d17e4342598 | 4555 | #endif |
wolfSSL | 0:9d17e4342598 | 4556 | #endif |
wolfSSL | 0:9d17e4342598 | 4557 | |
wolfSSL | 0:9d17e4342598 | 4558 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 4559 | case sha256_mac : |
wolfSSL | 0:9d17e4342598 | 4560 | Sha256Rounds(rounds, data, sz); |
wolfSSL | 0:9d17e4342598 | 4561 | break; |
wolfSSL | 0:9d17e4342598 | 4562 | #endif |
wolfSSL | 0:9d17e4342598 | 4563 | |
wolfSSL | 0:9d17e4342598 | 4564 | #ifdef CYASSL_SHA384 |
wolfSSL | 0:9d17e4342598 | 4565 | case sha384_mac : |
wolfSSL | 0:9d17e4342598 | 4566 | Sha384Rounds(rounds, data, sz); |
wolfSSL | 0:9d17e4342598 | 4567 | break; |
wolfSSL | 0:9d17e4342598 | 4568 | #endif |
wolfSSL | 0:9d17e4342598 | 4569 | |
wolfSSL | 0:9d17e4342598 | 4570 | #ifdef CYASSL_SHA512 |
wolfSSL | 0:9d17e4342598 | 4571 | case sha512_mac : |
wolfSSL | 0:9d17e4342598 | 4572 | Sha512Rounds(rounds, data, sz); |
wolfSSL | 0:9d17e4342598 | 4573 | break; |
wolfSSL | 0:9d17e4342598 | 4574 | #endif |
wolfSSL | 0:9d17e4342598 | 4575 | |
wolfSSL | 0:9d17e4342598 | 4576 | #ifdef CYASSL_RIPEMD |
wolfSSL | 0:9d17e4342598 | 4577 | case rmd_mac : |
wolfSSL | 0:9d17e4342598 | 4578 | RmdRounds(rounds, data, sz); |
wolfSSL | 0:9d17e4342598 | 4579 | break; |
wolfSSL | 0:9d17e4342598 | 4580 | #endif |
wolfSSL | 0:9d17e4342598 | 4581 | |
wolfSSL | 0:9d17e4342598 | 4582 | default: |
wolfSSL | 0:9d17e4342598 | 4583 | CYASSL_MSG("Bad round type"); |
wolfSSL | 0:9d17e4342598 | 4584 | break; |
wolfSSL | 0:9d17e4342598 | 4585 | } |
wolfSSL | 0:9d17e4342598 | 4586 | } |
wolfSSL | 0:9d17e4342598 | 4587 | |
wolfSSL | 0:9d17e4342598 | 4588 | |
wolfSSL | 0:9d17e4342598 | 4589 | /* do number of compression rounds on dummy data */ |
wolfSSL | 0:9d17e4342598 | 4590 | static INLINE void CompressRounds(CYASSL* ssl, int rounds, const byte* dummy) |
wolfSSL | 0:9d17e4342598 | 4591 | { |
wolfSSL | 0:9d17e4342598 | 4592 | if (rounds) |
wolfSSL | 0:9d17e4342598 | 4593 | DoRounds(ssl->specs.mac_algorithm, rounds, dummy, COMPRESS_LOWER); |
wolfSSL | 0:9d17e4342598 | 4594 | } |
wolfSSL | 0:9d17e4342598 | 4595 | |
wolfSSL | 0:9d17e4342598 | 4596 | |
wolfSSL | 0:9d17e4342598 | 4597 | /* check all length bytes for equality, return 0 on success */ |
wolfSSL | 0:9d17e4342598 | 4598 | static int ConstantCompare(const byte* a, const byte* b, int length) |
wolfSSL | 0:9d17e4342598 | 4599 | { |
wolfSSL | 0:9d17e4342598 | 4600 | int i; |
wolfSSL | 0:9d17e4342598 | 4601 | int good = 0; |
wolfSSL | 0:9d17e4342598 | 4602 | int bad = 0; |
wolfSSL | 0:9d17e4342598 | 4603 | |
wolfSSL | 0:9d17e4342598 | 4604 | for (i = 0; i < length; i++) { |
wolfSSL | 0:9d17e4342598 | 4605 | if (a[i] == b[i]) |
wolfSSL | 0:9d17e4342598 | 4606 | good++; |
wolfSSL | 0:9d17e4342598 | 4607 | else |
wolfSSL | 0:9d17e4342598 | 4608 | bad++; |
wolfSSL | 0:9d17e4342598 | 4609 | } |
wolfSSL | 0:9d17e4342598 | 4610 | |
wolfSSL | 0:9d17e4342598 | 4611 | if (good == length) |
wolfSSL | 0:9d17e4342598 | 4612 | return 0; |
wolfSSL | 0:9d17e4342598 | 4613 | else |
wolfSSL | 0:9d17e4342598 | 4614 | return 0 - bad; /* compare failed */ |
wolfSSL | 0:9d17e4342598 | 4615 | } |
wolfSSL | 0:9d17e4342598 | 4616 | |
wolfSSL | 0:9d17e4342598 | 4617 | |
wolfSSL | 0:9d17e4342598 | 4618 | /* check all length bytes for the pad value, return 0 on success */ |
wolfSSL | 0:9d17e4342598 | 4619 | static int PadCheck(const byte* input, byte pad, int length) |
wolfSSL | 0:9d17e4342598 | 4620 | { |
wolfSSL | 0:9d17e4342598 | 4621 | int i; |
wolfSSL | 0:9d17e4342598 | 4622 | int good = 0; |
wolfSSL | 0:9d17e4342598 | 4623 | int bad = 0; |
wolfSSL | 0:9d17e4342598 | 4624 | |
wolfSSL | 0:9d17e4342598 | 4625 | for (i = 0; i < length; i++) { |
wolfSSL | 0:9d17e4342598 | 4626 | if (input[i] == pad) |
wolfSSL | 0:9d17e4342598 | 4627 | good++; |
wolfSSL | 0:9d17e4342598 | 4628 | else |
wolfSSL | 0:9d17e4342598 | 4629 | bad++; |
wolfSSL | 0:9d17e4342598 | 4630 | } |
wolfSSL | 0:9d17e4342598 | 4631 | |
wolfSSL | 0:9d17e4342598 | 4632 | if (good == length) |
wolfSSL | 0:9d17e4342598 | 4633 | return 0; |
wolfSSL | 0:9d17e4342598 | 4634 | else |
wolfSSL | 0:9d17e4342598 | 4635 | return 0 - bad; /* pad check failed */ |
wolfSSL | 0:9d17e4342598 | 4636 | } |
wolfSSL | 0:9d17e4342598 | 4637 | |
wolfSSL | 0:9d17e4342598 | 4638 | |
wolfSSL | 0:9d17e4342598 | 4639 | /* get compression extra rounds */ |
wolfSSL | 0:9d17e4342598 | 4640 | static INLINE int GetRounds(int pLen, int padLen, int t) |
wolfSSL | 0:9d17e4342598 | 4641 | { |
wolfSSL | 0:9d17e4342598 | 4642 | int roundL1 = 1; /* round up flags */ |
wolfSSL | 0:9d17e4342598 | 4643 | int roundL2 = 1; |
wolfSSL | 0:9d17e4342598 | 4644 | |
wolfSSL | 0:9d17e4342598 | 4645 | int L1 = COMPRESS_CONSTANT + pLen - t; |
wolfSSL | 0:9d17e4342598 | 4646 | int L2 = COMPRESS_CONSTANT + pLen - padLen - 1 - t; |
wolfSSL | 0:9d17e4342598 | 4647 | |
wolfSSL | 0:9d17e4342598 | 4648 | L1 -= COMPRESS_UPPER; |
wolfSSL | 0:9d17e4342598 | 4649 | L2 -= COMPRESS_UPPER; |
wolfSSL | 0:9d17e4342598 | 4650 | |
wolfSSL | 0:9d17e4342598 | 4651 | if ( (L1 % COMPRESS_LOWER) == 0) |
wolfSSL | 0:9d17e4342598 | 4652 | roundL1 = 0; |
wolfSSL | 0:9d17e4342598 | 4653 | if ( (L2 % COMPRESS_LOWER) == 0) |
wolfSSL | 0:9d17e4342598 | 4654 | roundL2 = 0; |
wolfSSL | 0:9d17e4342598 | 4655 | |
wolfSSL | 0:9d17e4342598 | 4656 | L1 /= COMPRESS_LOWER; |
wolfSSL | 0:9d17e4342598 | 4657 | L2 /= COMPRESS_LOWER; |
wolfSSL | 0:9d17e4342598 | 4658 | |
wolfSSL | 0:9d17e4342598 | 4659 | L1 += roundL1; |
wolfSSL | 0:9d17e4342598 | 4660 | L2 += roundL2; |
wolfSSL | 0:9d17e4342598 | 4661 | |
wolfSSL | 0:9d17e4342598 | 4662 | return L1 - L2; |
wolfSSL | 0:9d17e4342598 | 4663 | } |
wolfSSL | 0:9d17e4342598 | 4664 | |
wolfSSL | 0:9d17e4342598 | 4665 | |
wolfSSL | 0:9d17e4342598 | 4666 | /* timing resistant pad/verify check, return 0 on success */ |
wolfSSL | 0:9d17e4342598 | 4667 | static int TimingPadVerify(CYASSL* ssl, const byte* input, int padLen, int t, |
wolfSSL | 0:9d17e4342598 | 4668 | int pLen, int content) |
wolfSSL | 0:9d17e4342598 | 4669 | { |
wolfSSL | 0:9d17e4342598 | 4670 | byte verify[MAX_DIGEST_SIZE]; |
wolfSSL | 0:9d17e4342598 | 4671 | byte dummy[MAX_PAD_SIZE]; |
wolfSSL | 0:9d17e4342598 | 4672 | int ret = 0; |
wolfSSL | 0:9d17e4342598 | 4673 | |
wolfSSL | 0:9d17e4342598 | 4674 | XMEMSET(dummy, 1, sizeof(dummy)); |
wolfSSL | 0:9d17e4342598 | 4675 | |
wolfSSL | 0:9d17e4342598 | 4676 | if ( (t + padLen + 1) > pLen) { |
wolfSSL | 0:9d17e4342598 | 4677 | CYASSL_MSG("Plain Len not long enough for pad/mac"); |
wolfSSL | 0:9d17e4342598 | 4678 | PadCheck(dummy, (byte)padLen, MAX_PAD_SIZE); |
wolfSSL | 0:9d17e4342598 | 4679 | ssl->hmac(ssl, verify, input, pLen - t, content, 1); /* still compare */ |
wolfSSL | 0:9d17e4342598 | 4680 | ConstantCompare(verify, input + pLen - t, t); |
wolfSSL | 0:9d17e4342598 | 4681 | |
wolfSSL | 0:9d17e4342598 | 4682 | return VERIFY_MAC_ERROR; |
wolfSSL | 0:9d17e4342598 | 4683 | } |
wolfSSL | 0:9d17e4342598 | 4684 | |
wolfSSL | 0:9d17e4342598 | 4685 | if (PadCheck(input + pLen - (padLen + 1), (byte)padLen, padLen + 1) != 0) { |
wolfSSL | 0:9d17e4342598 | 4686 | CYASSL_MSG("PadCheck failed"); |
wolfSSL | 0:9d17e4342598 | 4687 | PadCheck(dummy, (byte)padLen, MAX_PAD_SIZE - padLen - 1); |
wolfSSL | 0:9d17e4342598 | 4688 | ssl->hmac(ssl, verify, input, pLen - t, content, 1); /* still compare */ |
wolfSSL | 0:9d17e4342598 | 4689 | ConstantCompare(verify, input + pLen - t, t); |
wolfSSL | 0:9d17e4342598 | 4690 | |
wolfSSL | 0:9d17e4342598 | 4691 | return VERIFY_MAC_ERROR; |
wolfSSL | 0:9d17e4342598 | 4692 | } |
wolfSSL | 0:9d17e4342598 | 4693 | |
wolfSSL | 0:9d17e4342598 | 4694 | PadCheck(dummy, (byte)padLen, MAX_PAD_SIZE - padLen - 1); |
wolfSSL | 0:9d17e4342598 | 4695 | ret = ssl->hmac(ssl, verify, input, pLen - padLen - 1 - t, content, 1); |
wolfSSL | 0:9d17e4342598 | 4696 | |
wolfSSL | 0:9d17e4342598 | 4697 | CompressRounds(ssl, GetRounds(pLen, padLen, t), dummy); |
wolfSSL | 0:9d17e4342598 | 4698 | |
wolfSSL | 0:9d17e4342598 | 4699 | if (ConstantCompare(verify, input + (pLen - padLen - 1 - t), t) != 0) { |
wolfSSL | 0:9d17e4342598 | 4700 | CYASSL_MSG("Verify MAC compare failed"); |
wolfSSL | 0:9d17e4342598 | 4701 | return VERIFY_MAC_ERROR; |
wolfSSL | 0:9d17e4342598 | 4702 | } |
wolfSSL | 0:9d17e4342598 | 4703 | |
wolfSSL | 0:9d17e4342598 | 4704 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 4705 | return VERIFY_MAC_ERROR; |
wolfSSL | 0:9d17e4342598 | 4706 | return 0; |
wolfSSL | 0:9d17e4342598 | 4707 | } |
wolfSSL | 0:9d17e4342598 | 4708 | |
wolfSSL | 0:9d17e4342598 | 4709 | |
wolfSSL | 0:9d17e4342598 | 4710 | int DoApplicationData(CYASSL* ssl, byte* input, word32* inOutIdx) |
wolfSSL | 0:9d17e4342598 | 4711 | { |
wolfSSL | 0:9d17e4342598 | 4712 | word32 msgSz = ssl->keys.encryptSz; |
wolfSSL | 0:9d17e4342598 | 4713 | word32 idx = *inOutIdx; |
wolfSSL | 0:9d17e4342598 | 4714 | int dataSz; |
wolfSSL | 0:9d17e4342598 | 4715 | int ivExtra = 0; |
wolfSSL | 0:9d17e4342598 | 4716 | byte* rawData = input + idx; /* keep current for hmac */ |
wolfSSL | 0:9d17e4342598 | 4717 | #ifdef HAVE_LIBZ |
wolfSSL | 0:9d17e4342598 | 4718 | byte decomp[MAX_RECORD_SIZE + MAX_COMP_EXTRA]; |
wolfSSL | 0:9d17e4342598 | 4719 | #endif |
wolfSSL | 0:9d17e4342598 | 4720 | |
wolfSSL | 0:9d17e4342598 | 4721 | if (ssl->options.handShakeState != HANDSHAKE_DONE) { |
wolfSSL | 0:9d17e4342598 | 4722 | CYASSL_MSG("Received App data before handshake complete"); |
wolfSSL | 0:9d17e4342598 | 4723 | SendAlert(ssl, alert_fatal, unexpected_message); |
wolfSSL | 0:9d17e4342598 | 4724 | return OUT_OF_ORDER_E; |
wolfSSL | 0:9d17e4342598 | 4725 | } |
wolfSSL | 0:9d17e4342598 | 4726 | |
wolfSSL | 0:9d17e4342598 | 4727 | if (ssl->specs.cipher_type == block) { |
wolfSSL | 0:9d17e4342598 | 4728 | if (ssl->options.tls1_1) |
wolfSSL | 0:9d17e4342598 | 4729 | ivExtra = ssl->specs.block_size; |
wolfSSL | 0:9d17e4342598 | 4730 | } |
wolfSSL | 0:9d17e4342598 | 4731 | else if (ssl->specs.cipher_type == aead) { |
wolfSSL | 0:9d17e4342598 | 4732 | ivExtra = AEAD_EXP_IV_SZ; |
wolfSSL | 0:9d17e4342598 | 4733 | } |
wolfSSL | 0:9d17e4342598 | 4734 | |
wolfSSL | 0:9d17e4342598 | 4735 | dataSz = msgSz - ivExtra - ssl->keys.padSz; |
wolfSSL | 0:9d17e4342598 | 4736 | if (dataSz < 0) { |
wolfSSL | 0:9d17e4342598 | 4737 | CYASSL_MSG("App data buffer error, malicious input?"); |
wolfSSL | 0:9d17e4342598 | 4738 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 4739 | } |
wolfSSL | 0:9d17e4342598 | 4740 | |
wolfSSL | 0:9d17e4342598 | 4741 | /* read data */ |
wolfSSL | 0:9d17e4342598 | 4742 | if (dataSz) { |
wolfSSL | 0:9d17e4342598 | 4743 | int rawSz = dataSz; /* keep raw size for idx adjustment */ |
wolfSSL | 0:9d17e4342598 | 4744 | |
wolfSSL | 0:9d17e4342598 | 4745 | #ifdef HAVE_LIBZ |
wolfSSL | 0:9d17e4342598 | 4746 | if (ssl->options.usingCompression) { |
wolfSSL | 0:9d17e4342598 | 4747 | dataSz = myDeCompress(ssl, rawData, dataSz, decomp, sizeof(decomp)); |
wolfSSL | 0:9d17e4342598 | 4748 | if (dataSz < 0) return dataSz; |
wolfSSL | 0:9d17e4342598 | 4749 | } |
wolfSSL | 0:9d17e4342598 | 4750 | #endif |
wolfSSL | 0:9d17e4342598 | 4751 | idx += rawSz; |
wolfSSL | 0:9d17e4342598 | 4752 | |
wolfSSL | 0:9d17e4342598 | 4753 | ssl->buffers.clearOutputBuffer.buffer = rawData; |
wolfSSL | 0:9d17e4342598 | 4754 | ssl->buffers.clearOutputBuffer.length = dataSz; |
wolfSSL | 0:9d17e4342598 | 4755 | } |
wolfSSL | 0:9d17e4342598 | 4756 | |
wolfSSL | 0:9d17e4342598 | 4757 | idx += ssl->keys.padSz; |
wolfSSL | 0:9d17e4342598 | 4758 | |
wolfSSL | 0:9d17e4342598 | 4759 | #ifdef HAVE_LIBZ |
wolfSSL | 0:9d17e4342598 | 4760 | /* decompress could be bigger, overwrite after verify */ |
wolfSSL | 0:9d17e4342598 | 4761 | if (ssl->options.usingCompression) |
wolfSSL | 0:9d17e4342598 | 4762 | XMEMMOVE(rawData, decomp, dataSz); |
wolfSSL | 0:9d17e4342598 | 4763 | #endif |
wolfSSL | 0:9d17e4342598 | 4764 | |
wolfSSL | 0:9d17e4342598 | 4765 | *inOutIdx = idx; |
wolfSSL | 0:9d17e4342598 | 4766 | return 0; |
wolfSSL | 0:9d17e4342598 | 4767 | } |
wolfSSL | 0:9d17e4342598 | 4768 | |
wolfSSL | 0:9d17e4342598 | 4769 | |
wolfSSL | 0:9d17e4342598 | 4770 | /* process alert, return level */ |
wolfSSL | 0:9d17e4342598 | 4771 | static int DoAlert(CYASSL* ssl, byte* input, word32* inOutIdx, int* type, |
wolfSSL | 0:9d17e4342598 | 4772 | word32 totalSz) |
wolfSSL | 0:9d17e4342598 | 4773 | { |
wolfSSL | 0:9d17e4342598 | 4774 | byte level; |
wolfSSL | 0:9d17e4342598 | 4775 | byte code; |
wolfSSL | 0:9d17e4342598 | 4776 | |
wolfSSL | 0:9d17e4342598 | 4777 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 4778 | if (ssl->hsInfoOn) |
wolfSSL | 0:9d17e4342598 | 4779 | AddPacketName("Alert", &ssl->handShakeInfo); |
wolfSSL | 0:9d17e4342598 | 4780 | if (ssl->toInfoOn) |
wolfSSL | 0:9d17e4342598 | 4781 | /* add record header back on to info + 2 byte level, data */ |
wolfSSL | 0:9d17e4342598 | 4782 | AddPacketInfo("Alert", &ssl->timeoutInfo, input + *inOutIdx - |
wolfSSL | 0:9d17e4342598 | 4783 | RECORD_HEADER_SZ, 2 + RECORD_HEADER_SZ, ssl->heap); |
wolfSSL | 0:9d17e4342598 | 4784 | #endif |
wolfSSL | 0:9d17e4342598 | 4785 | |
wolfSSL | 0:9d17e4342598 | 4786 | /* make sure can read the message */ |
wolfSSL | 0:9d17e4342598 | 4787 | if (*inOutIdx + ALERT_SIZE > totalSz) |
wolfSSL | 0:9d17e4342598 | 4788 | return BUFFER_E; |
wolfSSL | 0:9d17e4342598 | 4789 | |
wolfSSL | 0:9d17e4342598 | 4790 | level = input[(*inOutIdx)++]; |
wolfSSL | 0:9d17e4342598 | 4791 | code = input[(*inOutIdx)++]; |
wolfSSL | 0:9d17e4342598 | 4792 | ssl->alert_history.last_rx.code = code; |
wolfSSL | 0:9d17e4342598 | 4793 | ssl->alert_history.last_rx.level = level; |
wolfSSL | 0:9d17e4342598 | 4794 | *type = code; |
wolfSSL | 0:9d17e4342598 | 4795 | if (level == alert_fatal) { |
wolfSSL | 0:9d17e4342598 | 4796 | ssl->options.isClosed = 1; /* Don't send close_notify */ |
wolfSSL | 0:9d17e4342598 | 4797 | } |
wolfSSL | 0:9d17e4342598 | 4798 | |
wolfSSL | 0:9d17e4342598 | 4799 | CYASSL_MSG("Got alert"); |
wolfSSL | 0:9d17e4342598 | 4800 | if (*type == close_notify) { |
wolfSSL | 0:9d17e4342598 | 4801 | CYASSL_MSG(" close notify"); |
wolfSSL | 0:9d17e4342598 | 4802 | ssl->options.closeNotify = 1; |
wolfSSL | 0:9d17e4342598 | 4803 | } |
wolfSSL | 0:9d17e4342598 | 4804 | CYASSL_ERROR(*type); |
wolfSSL | 0:9d17e4342598 | 4805 | |
wolfSSL | 0:9d17e4342598 | 4806 | if (ssl->keys.encryptionOn) { |
wolfSSL | 0:9d17e4342598 | 4807 | if (*inOutIdx + ssl->keys.padSz > totalSz) |
wolfSSL | 0:9d17e4342598 | 4808 | return BUFFER_E; |
wolfSSL | 0:9d17e4342598 | 4809 | *inOutIdx += ssl->keys.padSz; |
wolfSSL | 0:9d17e4342598 | 4810 | } |
wolfSSL | 0:9d17e4342598 | 4811 | |
wolfSSL | 0:9d17e4342598 | 4812 | return level; |
wolfSSL | 0:9d17e4342598 | 4813 | } |
wolfSSL | 0:9d17e4342598 | 4814 | |
wolfSSL | 0:9d17e4342598 | 4815 | static int GetInputData(CYASSL *ssl, word32 size) |
wolfSSL | 0:9d17e4342598 | 4816 | { |
wolfSSL | 0:9d17e4342598 | 4817 | int in; |
wolfSSL | 0:9d17e4342598 | 4818 | int inSz; |
wolfSSL | 0:9d17e4342598 | 4819 | int maxLength; |
wolfSSL | 0:9d17e4342598 | 4820 | int usedLength; |
wolfSSL | 0:9d17e4342598 | 4821 | int dtlsExtra = 0; |
wolfSSL | 0:9d17e4342598 | 4822 | |
wolfSSL | 0:9d17e4342598 | 4823 | |
wolfSSL | 0:9d17e4342598 | 4824 | /* check max input length */ |
wolfSSL | 0:9d17e4342598 | 4825 | usedLength = ssl->buffers.inputBuffer.length - ssl->buffers.inputBuffer.idx; |
wolfSSL | 0:9d17e4342598 | 4826 | maxLength = ssl->buffers.inputBuffer.bufferSize - usedLength; |
wolfSSL | 0:9d17e4342598 | 4827 | inSz = (int)(size - usedLength); /* from last partial read */ |
wolfSSL | 0:9d17e4342598 | 4828 | |
wolfSSL | 0:9d17e4342598 | 4829 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 4830 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 4831 | if (size < ssl->dtls_expected_rx) |
wolfSSL | 0:9d17e4342598 | 4832 | dtlsExtra = (int)(ssl->dtls_expected_rx - size); |
wolfSSL | 0:9d17e4342598 | 4833 | inSz = ssl->dtls_expected_rx; |
wolfSSL | 0:9d17e4342598 | 4834 | } |
wolfSSL | 0:9d17e4342598 | 4835 | #endif |
wolfSSL | 0:9d17e4342598 | 4836 | |
wolfSSL | 0:9d17e4342598 | 4837 | if (inSz > maxLength) { |
wolfSSL | 0:9d17e4342598 | 4838 | if (GrowInputBuffer(ssl, size + dtlsExtra, usedLength) < 0) |
wolfSSL | 0:9d17e4342598 | 4839 | return MEMORY_E; |
wolfSSL | 0:9d17e4342598 | 4840 | } |
wolfSSL | 0:9d17e4342598 | 4841 | |
wolfSSL | 0:9d17e4342598 | 4842 | if (inSz <= 0) |
wolfSSL | 0:9d17e4342598 | 4843 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 4844 | |
wolfSSL | 0:9d17e4342598 | 4845 | /* Put buffer data at start if not there */ |
wolfSSL | 0:9d17e4342598 | 4846 | if (usedLength > 0 && ssl->buffers.inputBuffer.idx != 0) |
wolfSSL | 0:9d17e4342598 | 4847 | XMEMMOVE(ssl->buffers.inputBuffer.buffer, |
wolfSSL | 0:9d17e4342598 | 4848 | ssl->buffers.inputBuffer.buffer + ssl->buffers.inputBuffer.idx, |
wolfSSL | 0:9d17e4342598 | 4849 | usedLength); |
wolfSSL | 0:9d17e4342598 | 4850 | |
wolfSSL | 0:9d17e4342598 | 4851 | /* remove processed data */ |
wolfSSL | 0:9d17e4342598 | 4852 | ssl->buffers.inputBuffer.idx = 0; |
wolfSSL | 0:9d17e4342598 | 4853 | ssl->buffers.inputBuffer.length = usedLength; |
wolfSSL | 0:9d17e4342598 | 4854 | |
wolfSSL | 0:9d17e4342598 | 4855 | /* read data from network */ |
wolfSSL | 0:9d17e4342598 | 4856 | do { |
wolfSSL | 0:9d17e4342598 | 4857 | in = Receive(ssl, |
wolfSSL | 0:9d17e4342598 | 4858 | ssl->buffers.inputBuffer.buffer + |
wolfSSL | 0:9d17e4342598 | 4859 | ssl->buffers.inputBuffer.length, |
wolfSSL | 0:9d17e4342598 | 4860 | inSz); |
wolfSSL | 0:9d17e4342598 | 4861 | if (in == -1) |
wolfSSL | 0:9d17e4342598 | 4862 | return SOCKET_ERROR_E; |
wolfSSL | 0:9d17e4342598 | 4863 | |
wolfSSL | 0:9d17e4342598 | 4864 | if (in == WANT_READ) |
wolfSSL | 0:9d17e4342598 | 4865 | return WANT_READ; |
wolfSSL | 0:9d17e4342598 | 4866 | |
wolfSSL | 0:9d17e4342598 | 4867 | if (in > inSz) |
wolfSSL | 0:9d17e4342598 | 4868 | return RECV_OVERFLOW_E; |
wolfSSL | 0:9d17e4342598 | 4869 | |
wolfSSL | 0:9d17e4342598 | 4870 | ssl->buffers.inputBuffer.length += in; |
wolfSSL | 0:9d17e4342598 | 4871 | inSz -= in; |
wolfSSL | 0:9d17e4342598 | 4872 | |
wolfSSL | 0:9d17e4342598 | 4873 | } while (ssl->buffers.inputBuffer.length < size); |
wolfSSL | 0:9d17e4342598 | 4874 | |
wolfSSL | 0:9d17e4342598 | 4875 | return 0; |
wolfSSL | 0:9d17e4342598 | 4876 | } |
wolfSSL | 0:9d17e4342598 | 4877 | |
wolfSSL | 0:9d17e4342598 | 4878 | |
wolfSSL | 0:9d17e4342598 | 4879 | static INLINE int VerifyMac(CYASSL* ssl, const byte* input, word32 msgSz, |
wolfSSL | 0:9d17e4342598 | 4880 | int content, word32* padSz) |
wolfSSL | 0:9d17e4342598 | 4881 | { |
wolfSSL | 0:9d17e4342598 | 4882 | int ivExtra = 0; |
wolfSSL | 0:9d17e4342598 | 4883 | int ret; |
wolfSSL | 0:9d17e4342598 | 4884 | word32 pad = 0; |
wolfSSL | 0:9d17e4342598 | 4885 | word32 padByte = 0; |
wolfSSL | 0:9d17e4342598 | 4886 | #ifdef HAVE_TRUNCATED_HMAC |
wolfSSL | 0:9d17e4342598 | 4887 | word32 digestSz = ssl->truncated_hmac ? TRUNCATED_HMAC_SZ |
wolfSSL | 0:9d17e4342598 | 4888 | : ssl->specs.hash_size; |
wolfSSL | 0:9d17e4342598 | 4889 | #else |
wolfSSL | 0:9d17e4342598 | 4890 | word32 digestSz = ssl->specs.hash_size; |
wolfSSL | 0:9d17e4342598 | 4891 | #endif |
wolfSSL | 0:9d17e4342598 | 4892 | byte verify[MAX_DIGEST_SIZE]; |
wolfSSL | 0:9d17e4342598 | 4893 | |
wolfSSL | 0:9d17e4342598 | 4894 | if (ssl->specs.cipher_type == block) { |
wolfSSL | 0:9d17e4342598 | 4895 | if (ssl->options.tls1_1) |
wolfSSL | 0:9d17e4342598 | 4896 | ivExtra = ssl->specs.block_size; |
wolfSSL | 0:9d17e4342598 | 4897 | pad = *(input + msgSz - ivExtra - 1); |
wolfSSL | 0:9d17e4342598 | 4898 | padByte = 1; |
wolfSSL | 0:9d17e4342598 | 4899 | |
wolfSSL | 0:9d17e4342598 | 4900 | if (ssl->options.tls) { |
wolfSSL | 0:9d17e4342598 | 4901 | ret = TimingPadVerify(ssl, input, pad, digestSz, msgSz - ivExtra, |
wolfSSL | 0:9d17e4342598 | 4902 | content); |
wolfSSL | 0:9d17e4342598 | 4903 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 4904 | return ret; |
wolfSSL | 0:9d17e4342598 | 4905 | } |
wolfSSL | 0:9d17e4342598 | 4906 | else { /* sslv3, some implementations have bad padding, but don't |
wolfSSL | 0:9d17e4342598 | 4907 | * allow bad read */ |
wolfSSL | 0:9d17e4342598 | 4908 | int badPadLen = 0; |
wolfSSL | 0:9d17e4342598 | 4909 | byte dummy[MAX_PAD_SIZE]; |
wolfSSL | 0:9d17e4342598 | 4910 | |
wolfSSL | 0:9d17e4342598 | 4911 | XMEMSET(dummy, 1, sizeof(dummy)); |
wolfSSL | 0:9d17e4342598 | 4912 | |
wolfSSL | 0:9d17e4342598 | 4913 | if (pad > (msgSz - digestSz - 1)) { |
wolfSSL | 0:9d17e4342598 | 4914 | CYASSL_MSG("Plain Len not long enough for pad/mac"); |
wolfSSL | 0:9d17e4342598 | 4915 | pad = 0; /* no bad read */ |
wolfSSL | 0:9d17e4342598 | 4916 | badPadLen = 1; |
wolfSSL | 0:9d17e4342598 | 4917 | } |
wolfSSL | 0:9d17e4342598 | 4918 | PadCheck(dummy, (byte)pad, MAX_PAD_SIZE); /* timing only */ |
wolfSSL | 0:9d17e4342598 | 4919 | ret = ssl->hmac(ssl, verify, input, msgSz - digestSz - pad - 1, |
wolfSSL | 0:9d17e4342598 | 4920 | content, 1); |
wolfSSL | 0:9d17e4342598 | 4921 | if (ConstantCompare(verify, input + msgSz - digestSz - pad - 1, |
wolfSSL | 0:9d17e4342598 | 4922 | digestSz) != 0) |
wolfSSL | 0:9d17e4342598 | 4923 | return VERIFY_MAC_ERROR; |
wolfSSL | 0:9d17e4342598 | 4924 | if (ret != 0 || badPadLen) |
wolfSSL | 0:9d17e4342598 | 4925 | return VERIFY_MAC_ERROR; |
wolfSSL | 0:9d17e4342598 | 4926 | } |
wolfSSL | 0:9d17e4342598 | 4927 | } |
wolfSSL | 0:9d17e4342598 | 4928 | else if (ssl->specs.cipher_type == stream) { |
wolfSSL | 0:9d17e4342598 | 4929 | ret = ssl->hmac(ssl, verify, input, msgSz - digestSz, content, 1); |
wolfSSL | 0:9d17e4342598 | 4930 | if (ConstantCompare(verify, input + msgSz - digestSz, digestSz) != 0){ |
wolfSSL | 0:9d17e4342598 | 4931 | return VERIFY_MAC_ERROR; |
wolfSSL | 0:9d17e4342598 | 4932 | } |
wolfSSL | 0:9d17e4342598 | 4933 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 4934 | return VERIFY_MAC_ERROR; |
wolfSSL | 0:9d17e4342598 | 4935 | } |
wolfSSL | 0:9d17e4342598 | 4936 | |
wolfSSL | 0:9d17e4342598 | 4937 | if (ssl->specs.cipher_type == aead) { |
wolfSSL | 0:9d17e4342598 | 4938 | *padSz = ssl->specs.aead_mac_size; |
wolfSSL | 0:9d17e4342598 | 4939 | } |
wolfSSL | 0:9d17e4342598 | 4940 | else { |
wolfSSL | 0:9d17e4342598 | 4941 | *padSz = digestSz + pad + padByte; |
wolfSSL | 0:9d17e4342598 | 4942 | } |
wolfSSL | 0:9d17e4342598 | 4943 | |
wolfSSL | 0:9d17e4342598 | 4944 | return 0; |
wolfSSL | 0:9d17e4342598 | 4945 | } |
wolfSSL | 0:9d17e4342598 | 4946 | |
wolfSSL | 0:9d17e4342598 | 4947 | |
wolfSSL | 0:9d17e4342598 | 4948 | /* process input requests, return 0 is done, 1 is call again to complete, and |
wolfSSL | 0:9d17e4342598 | 4949 | negative number is error */ |
wolfSSL | 0:9d17e4342598 | 4950 | int ProcessReply(CYASSL* ssl) |
wolfSSL | 0:9d17e4342598 | 4951 | { |
wolfSSL | 0:9d17e4342598 | 4952 | int ret = 0, type, readSz; |
wolfSSL | 0:9d17e4342598 | 4953 | int atomicUser = 0; |
wolfSSL | 0:9d17e4342598 | 4954 | word32 startIdx = 0; |
wolfSSL | 0:9d17e4342598 | 4955 | #ifndef NO_CYASSL_SERVER |
wolfSSL | 0:9d17e4342598 | 4956 | byte b0, b1; |
wolfSSL | 0:9d17e4342598 | 4957 | #endif |
wolfSSL | 0:9d17e4342598 | 4958 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 4959 | int used; |
wolfSSL | 0:9d17e4342598 | 4960 | #endif |
wolfSSL | 0:9d17e4342598 | 4961 | |
wolfSSL | 0:9d17e4342598 | 4962 | #ifdef ATOMIC_USER |
wolfSSL | 0:9d17e4342598 | 4963 | if (ssl->ctx->DecryptVerifyCb) |
wolfSSL | 0:9d17e4342598 | 4964 | atomicUser = 1; |
wolfSSL | 0:9d17e4342598 | 4965 | #endif |
wolfSSL | 0:9d17e4342598 | 4966 | |
wolfSSL | 0:9d17e4342598 | 4967 | if (ssl->error != 0 && ssl->error != WANT_READ && ssl->error != WANT_WRITE){ |
wolfSSL | 0:9d17e4342598 | 4968 | CYASSL_MSG("ProcessReply retry in error state, not allowed"); |
wolfSSL | 0:9d17e4342598 | 4969 | return ssl->error; |
wolfSSL | 0:9d17e4342598 | 4970 | } |
wolfSSL | 0:9d17e4342598 | 4971 | |
wolfSSL | 0:9d17e4342598 | 4972 | for (;;) { |
wolfSSL | 0:9d17e4342598 | 4973 | switch (ssl->options.processReply) { |
wolfSSL | 0:9d17e4342598 | 4974 | |
wolfSSL | 0:9d17e4342598 | 4975 | /* in the CYASSL_SERVER case, get the first byte for detecting |
wolfSSL | 0:9d17e4342598 | 4976 | * old client hello */ |
wolfSSL | 0:9d17e4342598 | 4977 | case doProcessInit: |
wolfSSL | 0:9d17e4342598 | 4978 | |
wolfSSL | 0:9d17e4342598 | 4979 | readSz = RECORD_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 4980 | |
wolfSSL | 0:9d17e4342598 | 4981 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 4982 | if (ssl->options.dtls) |
wolfSSL | 0:9d17e4342598 | 4983 | readSz = DTLS_RECORD_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 4984 | #endif |
wolfSSL | 0:9d17e4342598 | 4985 | |
wolfSSL | 0:9d17e4342598 | 4986 | /* get header or return error */ |
wolfSSL | 0:9d17e4342598 | 4987 | if (!ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 4988 | if ((ret = GetInputData(ssl, readSz)) < 0) |
wolfSSL | 0:9d17e4342598 | 4989 | return ret; |
wolfSSL | 0:9d17e4342598 | 4990 | } else { |
wolfSSL | 0:9d17e4342598 | 4991 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 4992 | /* read ahead may already have header */ |
wolfSSL | 0:9d17e4342598 | 4993 | used = ssl->buffers.inputBuffer.length - |
wolfSSL | 0:9d17e4342598 | 4994 | ssl->buffers.inputBuffer.idx; |
wolfSSL | 0:9d17e4342598 | 4995 | if (used < readSz) |
wolfSSL | 0:9d17e4342598 | 4996 | if ((ret = GetInputData(ssl, readSz)) < 0) |
wolfSSL | 0:9d17e4342598 | 4997 | return ret; |
wolfSSL | 0:9d17e4342598 | 4998 | #endif |
wolfSSL | 0:9d17e4342598 | 4999 | } |
wolfSSL | 0:9d17e4342598 | 5000 | |
wolfSSL | 0:9d17e4342598 | 5001 | #ifndef NO_CYASSL_SERVER |
wolfSSL | 0:9d17e4342598 | 5002 | |
wolfSSL | 0:9d17e4342598 | 5003 | /* see if sending SSLv2 client hello */ |
wolfSSL | 0:9d17e4342598 | 5004 | if ( ssl->options.side == CYASSL_SERVER_END && |
wolfSSL | 0:9d17e4342598 | 5005 | ssl->options.clientState == NULL_STATE && |
wolfSSL | 0:9d17e4342598 | 5006 | ssl->buffers.inputBuffer.buffer[ssl->buffers.inputBuffer.idx] |
wolfSSL | 0:9d17e4342598 | 5007 | != handshake) { |
wolfSSL | 0:9d17e4342598 | 5008 | ssl->options.processReply = runProcessOldClientHello; |
wolfSSL | 0:9d17e4342598 | 5009 | |
wolfSSL | 0:9d17e4342598 | 5010 | /* how many bytes need ProcessOldClientHello */ |
wolfSSL | 0:9d17e4342598 | 5011 | b0 = |
wolfSSL | 0:9d17e4342598 | 5012 | ssl->buffers.inputBuffer.buffer[ssl->buffers.inputBuffer.idx++]; |
wolfSSL | 0:9d17e4342598 | 5013 | b1 = |
wolfSSL | 0:9d17e4342598 | 5014 | ssl->buffers.inputBuffer.buffer[ssl->buffers.inputBuffer.idx++]; |
wolfSSL | 0:9d17e4342598 | 5015 | ssl->curSize = (word16)(((b0 & 0x7f) << 8) | b1); |
wolfSSL | 0:9d17e4342598 | 5016 | } |
wolfSSL | 0:9d17e4342598 | 5017 | else { |
wolfSSL | 0:9d17e4342598 | 5018 | ssl->options.processReply = getRecordLayerHeader; |
wolfSSL | 0:9d17e4342598 | 5019 | continue; |
wolfSSL | 0:9d17e4342598 | 5020 | } |
wolfSSL | 0:9d17e4342598 | 5021 | |
wolfSSL | 0:9d17e4342598 | 5022 | /* in the CYASSL_SERVER case, run the old client hello */ |
wolfSSL | 0:9d17e4342598 | 5023 | case runProcessOldClientHello: |
wolfSSL | 0:9d17e4342598 | 5024 | |
wolfSSL | 0:9d17e4342598 | 5025 | /* get sz bytes or return error */ |
wolfSSL | 0:9d17e4342598 | 5026 | if (!ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 5027 | if ((ret = GetInputData(ssl, ssl->curSize)) < 0) |
wolfSSL | 0:9d17e4342598 | 5028 | return ret; |
wolfSSL | 0:9d17e4342598 | 5029 | } else { |
wolfSSL | 0:9d17e4342598 | 5030 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 5031 | /* read ahead may already have */ |
wolfSSL | 0:9d17e4342598 | 5032 | used = ssl->buffers.inputBuffer.length - |
wolfSSL | 0:9d17e4342598 | 5033 | ssl->buffers.inputBuffer.idx; |
wolfSSL | 0:9d17e4342598 | 5034 | if (used < ssl->curSize) |
wolfSSL | 0:9d17e4342598 | 5035 | if ((ret = GetInputData(ssl, ssl->curSize)) < 0) |
wolfSSL | 0:9d17e4342598 | 5036 | return ret; |
wolfSSL | 0:9d17e4342598 | 5037 | #endif /* CYASSL_DTLS */ |
wolfSSL | 0:9d17e4342598 | 5038 | } |
wolfSSL | 0:9d17e4342598 | 5039 | |
wolfSSL | 0:9d17e4342598 | 5040 | ret = ProcessOldClientHello(ssl, ssl->buffers.inputBuffer.buffer, |
wolfSSL | 0:9d17e4342598 | 5041 | &ssl->buffers.inputBuffer.idx, |
wolfSSL | 0:9d17e4342598 | 5042 | ssl->buffers.inputBuffer.length - |
wolfSSL | 0:9d17e4342598 | 5043 | ssl->buffers.inputBuffer.idx, |
wolfSSL | 0:9d17e4342598 | 5044 | ssl->curSize); |
wolfSSL | 0:9d17e4342598 | 5045 | if (ret < 0) |
wolfSSL | 0:9d17e4342598 | 5046 | return ret; |
wolfSSL | 0:9d17e4342598 | 5047 | |
wolfSSL | 0:9d17e4342598 | 5048 | else if (ssl->buffers.inputBuffer.idx == |
wolfSSL | 0:9d17e4342598 | 5049 | ssl->buffers.inputBuffer.length) { |
wolfSSL | 0:9d17e4342598 | 5050 | ssl->options.processReply = doProcessInit; |
wolfSSL | 0:9d17e4342598 | 5051 | return 0; |
wolfSSL | 0:9d17e4342598 | 5052 | } |
wolfSSL | 0:9d17e4342598 | 5053 | |
wolfSSL | 0:9d17e4342598 | 5054 | #endif /* NO_CYASSL_SERVER */ |
wolfSSL | 0:9d17e4342598 | 5055 | |
wolfSSL | 0:9d17e4342598 | 5056 | /* get the record layer header */ |
wolfSSL | 0:9d17e4342598 | 5057 | case getRecordLayerHeader: |
wolfSSL | 0:9d17e4342598 | 5058 | |
wolfSSL | 0:9d17e4342598 | 5059 | ret = GetRecordHeader(ssl, ssl->buffers.inputBuffer.buffer, |
wolfSSL | 0:9d17e4342598 | 5060 | &ssl->buffers.inputBuffer.idx, |
wolfSSL | 0:9d17e4342598 | 5061 | &ssl->curRL, &ssl->curSize); |
wolfSSL | 0:9d17e4342598 | 5062 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 5063 | if (ssl->options.dtls && ret == SEQUENCE_ERROR) { |
wolfSSL | 0:9d17e4342598 | 5064 | ssl->options.processReply = doProcessInit; |
wolfSSL | 0:9d17e4342598 | 5065 | ssl->buffers.inputBuffer.length = 0; |
wolfSSL | 0:9d17e4342598 | 5066 | ssl->buffers.inputBuffer.idx = 0; |
wolfSSL | 0:9d17e4342598 | 5067 | continue; |
wolfSSL | 0:9d17e4342598 | 5068 | } |
wolfSSL | 0:9d17e4342598 | 5069 | #endif |
wolfSSL | 0:9d17e4342598 | 5070 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 5071 | return ret; |
wolfSSL | 0:9d17e4342598 | 5072 | |
wolfSSL | 0:9d17e4342598 | 5073 | ssl->options.processReply = getData; |
wolfSSL | 0:9d17e4342598 | 5074 | |
wolfSSL | 0:9d17e4342598 | 5075 | /* retrieve record layer data */ |
wolfSSL | 0:9d17e4342598 | 5076 | case getData: |
wolfSSL | 0:9d17e4342598 | 5077 | |
wolfSSL | 0:9d17e4342598 | 5078 | /* get sz bytes or return error */ |
wolfSSL | 0:9d17e4342598 | 5079 | if (!ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 5080 | if ((ret = GetInputData(ssl, ssl->curSize)) < 0) |
wolfSSL | 0:9d17e4342598 | 5081 | return ret; |
wolfSSL | 0:9d17e4342598 | 5082 | } else { |
wolfSSL | 0:9d17e4342598 | 5083 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 5084 | /* read ahead may already have */ |
wolfSSL | 0:9d17e4342598 | 5085 | used = ssl->buffers.inputBuffer.length - |
wolfSSL | 0:9d17e4342598 | 5086 | ssl->buffers.inputBuffer.idx; |
wolfSSL | 0:9d17e4342598 | 5087 | if (used < ssl->curSize) |
wolfSSL | 0:9d17e4342598 | 5088 | if ((ret = GetInputData(ssl, ssl->curSize)) < 0) |
wolfSSL | 0:9d17e4342598 | 5089 | return ret; |
wolfSSL | 0:9d17e4342598 | 5090 | #endif |
wolfSSL | 0:9d17e4342598 | 5091 | } |
wolfSSL | 0:9d17e4342598 | 5092 | |
wolfSSL | 0:9d17e4342598 | 5093 | ssl->options.processReply = runProcessingOneMessage; |
wolfSSL | 0:9d17e4342598 | 5094 | startIdx = ssl->buffers.inputBuffer.idx; /* in case > 1 msg per */ |
wolfSSL | 0:9d17e4342598 | 5095 | |
wolfSSL | 0:9d17e4342598 | 5096 | /* the record layer is here */ |
wolfSSL | 0:9d17e4342598 | 5097 | case runProcessingOneMessage: |
wolfSSL | 0:9d17e4342598 | 5098 | |
wolfSSL | 0:9d17e4342598 | 5099 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 5100 | if (ssl->options.dtls && |
wolfSSL | 0:9d17e4342598 | 5101 | ssl->keys.dtls_state.curEpoch < ssl->keys.dtls_state.nextEpoch) |
wolfSSL | 0:9d17e4342598 | 5102 | ssl->keys.decryptedCur = 1; |
wolfSSL | 0:9d17e4342598 | 5103 | #endif |
wolfSSL | 0:9d17e4342598 | 5104 | |
wolfSSL | 0:9d17e4342598 | 5105 | if (ssl->keys.encryptionOn && ssl->keys.decryptedCur == 0) |
wolfSSL | 0:9d17e4342598 | 5106 | { |
wolfSSL | 0:9d17e4342598 | 5107 | ret = SanityCheckCipherText(ssl, ssl->curSize); |
wolfSSL | 0:9d17e4342598 | 5108 | if (ret < 0) |
wolfSSL | 0:9d17e4342598 | 5109 | return ret; |
wolfSSL | 0:9d17e4342598 | 5110 | |
wolfSSL | 0:9d17e4342598 | 5111 | if (atomicUser) { |
wolfSSL | 0:9d17e4342598 | 5112 | #ifdef ATOMIC_USER |
wolfSSL | 0:9d17e4342598 | 5113 | ret = ssl->ctx->DecryptVerifyCb(ssl, |
wolfSSL | 0:9d17e4342598 | 5114 | ssl->buffers.inputBuffer.buffer + |
wolfSSL | 0:9d17e4342598 | 5115 | ssl->buffers.inputBuffer.idx, |
wolfSSL | 0:9d17e4342598 | 5116 | ssl->buffers.inputBuffer.buffer + |
wolfSSL | 0:9d17e4342598 | 5117 | ssl->buffers.inputBuffer.idx, |
wolfSSL | 0:9d17e4342598 | 5118 | ssl->curSize, ssl->curRL.type, 1, |
wolfSSL | 0:9d17e4342598 | 5119 | &ssl->keys.padSz, ssl->DecryptVerifyCtx); |
wolfSSL | 0:9d17e4342598 | 5120 | if (ssl->options.tls1_1 && ssl->specs.cipher_type == block) |
wolfSSL | 0:9d17e4342598 | 5121 | ssl->buffers.inputBuffer.idx += ssl->specs.block_size; |
wolfSSL | 0:9d17e4342598 | 5122 | /* go past TLSv1.1 IV */ |
wolfSSL | 0:9d17e4342598 | 5123 | if (ssl->specs.cipher_type == aead) |
wolfSSL | 0:9d17e4342598 | 5124 | ssl->buffers.inputBuffer.idx += AEAD_EXP_IV_SZ; |
wolfSSL | 0:9d17e4342598 | 5125 | #endif /* ATOMIC_USER */ |
wolfSSL | 0:9d17e4342598 | 5126 | } |
wolfSSL | 0:9d17e4342598 | 5127 | else { |
wolfSSL | 0:9d17e4342598 | 5128 | ret = Decrypt(ssl, ssl->buffers.inputBuffer.buffer + |
wolfSSL | 0:9d17e4342598 | 5129 | ssl->buffers.inputBuffer.idx, |
wolfSSL | 0:9d17e4342598 | 5130 | ssl->buffers.inputBuffer.buffer + |
wolfSSL | 0:9d17e4342598 | 5131 | ssl->buffers.inputBuffer.idx, |
wolfSSL | 0:9d17e4342598 | 5132 | ssl->curSize); |
wolfSSL | 0:9d17e4342598 | 5133 | if (ret < 0) { |
wolfSSL | 0:9d17e4342598 | 5134 | CYASSL_ERROR(ret); |
wolfSSL | 0:9d17e4342598 | 5135 | return DECRYPT_ERROR; |
wolfSSL | 0:9d17e4342598 | 5136 | } |
wolfSSL | 0:9d17e4342598 | 5137 | if (ssl->options.tls1_1 && ssl->specs.cipher_type == block) |
wolfSSL | 0:9d17e4342598 | 5138 | ssl->buffers.inputBuffer.idx += ssl->specs.block_size; |
wolfSSL | 0:9d17e4342598 | 5139 | /* go past TLSv1.1 IV */ |
wolfSSL | 0:9d17e4342598 | 5140 | if (ssl->specs.cipher_type == aead) |
wolfSSL | 0:9d17e4342598 | 5141 | ssl->buffers.inputBuffer.idx += AEAD_EXP_IV_SZ; |
wolfSSL | 0:9d17e4342598 | 5142 | |
wolfSSL | 0:9d17e4342598 | 5143 | ret = VerifyMac(ssl, ssl->buffers.inputBuffer.buffer + |
wolfSSL | 0:9d17e4342598 | 5144 | ssl->buffers.inputBuffer.idx, |
wolfSSL | 0:9d17e4342598 | 5145 | ssl->curSize, ssl->curRL.type, |
wolfSSL | 0:9d17e4342598 | 5146 | &ssl->keys.padSz); |
wolfSSL | 0:9d17e4342598 | 5147 | } |
wolfSSL | 0:9d17e4342598 | 5148 | if (ret < 0) { |
wolfSSL | 0:9d17e4342598 | 5149 | CYASSL_ERROR(ret); |
wolfSSL | 0:9d17e4342598 | 5150 | return DECRYPT_ERROR; |
wolfSSL | 0:9d17e4342598 | 5151 | } |
wolfSSL | 0:9d17e4342598 | 5152 | ssl->keys.encryptSz = ssl->curSize; |
wolfSSL | 0:9d17e4342598 | 5153 | ssl->keys.decryptedCur = 1; |
wolfSSL | 0:9d17e4342598 | 5154 | } |
wolfSSL | 0:9d17e4342598 | 5155 | |
wolfSSL | 0:9d17e4342598 | 5156 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 5157 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 5158 | DtlsUpdateWindow(&ssl->keys.dtls_state); |
wolfSSL | 0:9d17e4342598 | 5159 | #endif /* CYASSL_DTLS */ |
wolfSSL | 0:9d17e4342598 | 5160 | } |
wolfSSL | 0:9d17e4342598 | 5161 | |
wolfSSL | 0:9d17e4342598 | 5162 | CYASSL_MSG("received record layer msg"); |
wolfSSL | 0:9d17e4342598 | 5163 | |
wolfSSL | 0:9d17e4342598 | 5164 | switch (ssl->curRL.type) { |
wolfSSL | 0:9d17e4342598 | 5165 | case handshake : |
wolfSSL | 0:9d17e4342598 | 5166 | /* debugging in DoHandShakeMsg */ |
wolfSSL | 0:9d17e4342598 | 5167 | if (!ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 5168 | ret = DoHandShakeMsg(ssl, |
wolfSSL | 0:9d17e4342598 | 5169 | ssl->buffers.inputBuffer.buffer, |
wolfSSL | 0:9d17e4342598 | 5170 | &ssl->buffers.inputBuffer.idx, |
wolfSSL | 0:9d17e4342598 | 5171 | ssl->buffers.inputBuffer.length); |
wolfSSL | 0:9d17e4342598 | 5172 | } |
wolfSSL | 0:9d17e4342598 | 5173 | else { |
wolfSSL | 0:9d17e4342598 | 5174 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 5175 | ret = DoDtlsHandShakeMsg(ssl, |
wolfSSL | 0:9d17e4342598 | 5176 | ssl->buffers.inputBuffer.buffer, |
wolfSSL | 0:9d17e4342598 | 5177 | &ssl->buffers.inputBuffer.idx, |
wolfSSL | 0:9d17e4342598 | 5178 | ssl->buffers.inputBuffer.length); |
wolfSSL | 0:9d17e4342598 | 5179 | #endif |
wolfSSL | 0:9d17e4342598 | 5180 | } |
wolfSSL | 0:9d17e4342598 | 5181 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 5182 | return ret; |
wolfSSL | 0:9d17e4342598 | 5183 | break; |
wolfSSL | 0:9d17e4342598 | 5184 | |
wolfSSL | 0:9d17e4342598 | 5185 | case change_cipher_spec: |
wolfSSL | 0:9d17e4342598 | 5186 | CYASSL_MSG("got CHANGE CIPHER SPEC"); |
wolfSSL | 0:9d17e4342598 | 5187 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 5188 | if (ssl->hsInfoOn) |
wolfSSL | 0:9d17e4342598 | 5189 | AddPacketName("ChangeCipher", &ssl->handShakeInfo); |
wolfSSL | 0:9d17e4342598 | 5190 | /* add record header back on info */ |
wolfSSL | 0:9d17e4342598 | 5191 | if (ssl->toInfoOn) { |
wolfSSL | 0:9d17e4342598 | 5192 | AddPacketInfo("ChangeCipher", &ssl->timeoutInfo, |
wolfSSL | 0:9d17e4342598 | 5193 | ssl->buffers.inputBuffer.buffer + |
wolfSSL | 0:9d17e4342598 | 5194 | ssl->buffers.inputBuffer.idx - RECORD_HEADER_SZ, |
wolfSSL | 0:9d17e4342598 | 5195 | 1 + RECORD_HEADER_SZ, ssl->heap); |
wolfSSL | 0:9d17e4342598 | 5196 | AddLateRecordHeader(&ssl->curRL, &ssl->timeoutInfo); |
wolfSSL | 0:9d17e4342598 | 5197 | } |
wolfSSL | 0:9d17e4342598 | 5198 | #endif |
wolfSSL | 0:9d17e4342598 | 5199 | |
wolfSSL | 0:9d17e4342598 | 5200 | if (ssl->curSize != 1) { |
wolfSSL | 0:9d17e4342598 | 5201 | CYASSL_MSG("Malicious or corrupted ChangeCipher msg"); |
wolfSSL | 0:9d17e4342598 | 5202 | return LENGTH_ERROR; |
wolfSSL | 0:9d17e4342598 | 5203 | } |
wolfSSL | 0:9d17e4342598 | 5204 | #ifndef NO_CERTS |
wolfSSL | 0:9d17e4342598 | 5205 | if (ssl->options.side == CYASSL_SERVER_END && |
wolfSSL | 0:9d17e4342598 | 5206 | ssl->options.verifyPeer && |
wolfSSL | 0:9d17e4342598 | 5207 | ssl->options.havePeerCert) |
wolfSSL | 0:9d17e4342598 | 5208 | if (!ssl->options.havePeerVerify) { |
wolfSSL | 0:9d17e4342598 | 5209 | CYASSL_MSG("client didn't send cert verify"); |
wolfSSL | 0:9d17e4342598 | 5210 | return NO_PEER_VERIFY; |
wolfSSL | 0:9d17e4342598 | 5211 | } |
wolfSSL | 0:9d17e4342598 | 5212 | #endif |
wolfSSL | 0:9d17e4342598 | 5213 | |
wolfSSL | 0:9d17e4342598 | 5214 | |
wolfSSL | 0:9d17e4342598 | 5215 | ssl->buffers.inputBuffer.idx++; |
wolfSSL | 0:9d17e4342598 | 5216 | ssl->keys.encryptionOn = 1; |
wolfSSL | 0:9d17e4342598 | 5217 | |
wolfSSL | 0:9d17e4342598 | 5218 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 5219 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 5220 | DtlsPoolReset(ssl); |
wolfSSL | 0:9d17e4342598 | 5221 | ssl->keys.dtls_state.nextEpoch++; |
wolfSSL | 0:9d17e4342598 | 5222 | ssl->keys.dtls_state.nextSeq = 0; |
wolfSSL | 0:9d17e4342598 | 5223 | } |
wolfSSL | 0:9d17e4342598 | 5224 | #endif |
wolfSSL | 0:9d17e4342598 | 5225 | |
wolfSSL | 0:9d17e4342598 | 5226 | #ifdef HAVE_LIBZ |
wolfSSL | 0:9d17e4342598 | 5227 | if (ssl->options.usingCompression) |
wolfSSL | 0:9d17e4342598 | 5228 | if ( (ret = InitStreams(ssl)) != 0) |
wolfSSL | 0:9d17e4342598 | 5229 | return ret; |
wolfSSL | 0:9d17e4342598 | 5230 | #endif |
wolfSSL | 0:9d17e4342598 | 5231 | if (ssl->options.resuming && ssl->options.side == |
wolfSSL | 0:9d17e4342598 | 5232 | CYASSL_CLIENT_END) |
wolfSSL | 0:9d17e4342598 | 5233 | ret = BuildFinished(ssl, &ssl->verifyHashes, server); |
wolfSSL | 0:9d17e4342598 | 5234 | else if (!ssl->options.resuming && ssl->options.side == |
wolfSSL | 0:9d17e4342598 | 5235 | CYASSL_SERVER_END) |
wolfSSL | 0:9d17e4342598 | 5236 | ret = BuildFinished(ssl, &ssl->verifyHashes, client); |
wolfSSL | 0:9d17e4342598 | 5237 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 5238 | return ret; |
wolfSSL | 0:9d17e4342598 | 5239 | break; |
wolfSSL | 0:9d17e4342598 | 5240 | |
wolfSSL | 0:9d17e4342598 | 5241 | case application_data: |
wolfSSL | 0:9d17e4342598 | 5242 | CYASSL_MSG("got app DATA"); |
wolfSSL | 0:9d17e4342598 | 5243 | if ((ret = DoApplicationData(ssl, |
wolfSSL | 0:9d17e4342598 | 5244 | ssl->buffers.inputBuffer.buffer, |
wolfSSL | 0:9d17e4342598 | 5245 | &ssl->buffers.inputBuffer.idx)) |
wolfSSL | 0:9d17e4342598 | 5246 | != 0) { |
wolfSSL | 0:9d17e4342598 | 5247 | CYASSL_ERROR(ret); |
wolfSSL | 0:9d17e4342598 | 5248 | return ret; |
wolfSSL | 0:9d17e4342598 | 5249 | } |
wolfSSL | 0:9d17e4342598 | 5250 | break; |
wolfSSL | 0:9d17e4342598 | 5251 | |
wolfSSL | 0:9d17e4342598 | 5252 | case alert: |
wolfSSL | 0:9d17e4342598 | 5253 | CYASSL_MSG("got ALERT!"); |
wolfSSL | 0:9d17e4342598 | 5254 | ret = DoAlert(ssl, ssl->buffers.inputBuffer.buffer, |
wolfSSL | 0:9d17e4342598 | 5255 | &ssl->buffers.inputBuffer.idx, &type, |
wolfSSL | 0:9d17e4342598 | 5256 | ssl->buffers.inputBuffer.length); |
wolfSSL | 0:9d17e4342598 | 5257 | if (ret == alert_fatal) |
wolfSSL | 0:9d17e4342598 | 5258 | return FATAL_ERROR; |
wolfSSL | 0:9d17e4342598 | 5259 | else if (ret < 0) |
wolfSSL | 0:9d17e4342598 | 5260 | return ret; |
wolfSSL | 0:9d17e4342598 | 5261 | |
wolfSSL | 0:9d17e4342598 | 5262 | /* catch warnings that are handled as errors */ |
wolfSSL | 0:9d17e4342598 | 5263 | if (type == close_notify) |
wolfSSL | 0:9d17e4342598 | 5264 | return ssl->error = ZERO_RETURN; |
wolfSSL | 0:9d17e4342598 | 5265 | |
wolfSSL | 0:9d17e4342598 | 5266 | if (type == decrypt_error) |
wolfSSL | 0:9d17e4342598 | 5267 | return FATAL_ERROR; |
wolfSSL | 0:9d17e4342598 | 5268 | break; |
wolfSSL | 0:9d17e4342598 | 5269 | |
wolfSSL | 0:9d17e4342598 | 5270 | default: |
wolfSSL | 0:9d17e4342598 | 5271 | CYASSL_ERROR(UNKNOWN_RECORD_TYPE); |
wolfSSL | 0:9d17e4342598 | 5272 | return UNKNOWN_RECORD_TYPE; |
wolfSSL | 0:9d17e4342598 | 5273 | } |
wolfSSL | 0:9d17e4342598 | 5274 | |
wolfSSL | 0:9d17e4342598 | 5275 | ssl->options.processReply = doProcessInit; |
wolfSSL | 0:9d17e4342598 | 5276 | |
wolfSSL | 0:9d17e4342598 | 5277 | /* input exhausted? */ |
wolfSSL | 0:9d17e4342598 | 5278 | if (ssl->buffers.inputBuffer.idx == ssl->buffers.inputBuffer.length) |
wolfSSL | 0:9d17e4342598 | 5279 | return 0; |
wolfSSL | 0:9d17e4342598 | 5280 | /* more messages per record */ |
wolfSSL | 0:9d17e4342598 | 5281 | else if ((ssl->buffers.inputBuffer.idx - startIdx) < ssl->curSize) { |
wolfSSL | 0:9d17e4342598 | 5282 | CYASSL_MSG("More messages in record"); |
wolfSSL | 0:9d17e4342598 | 5283 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 5284 | /* read-ahead but dtls doesn't bundle messages per record */ |
wolfSSL | 0:9d17e4342598 | 5285 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 5286 | ssl->options.processReply = doProcessInit; |
wolfSSL | 0:9d17e4342598 | 5287 | continue; |
wolfSSL | 0:9d17e4342598 | 5288 | } |
wolfSSL | 0:9d17e4342598 | 5289 | #endif |
wolfSSL | 0:9d17e4342598 | 5290 | ssl->options.processReply = runProcessingOneMessage; |
wolfSSL | 0:9d17e4342598 | 5291 | continue; |
wolfSSL | 0:9d17e4342598 | 5292 | } |
wolfSSL | 0:9d17e4342598 | 5293 | /* more records */ |
wolfSSL | 0:9d17e4342598 | 5294 | else { |
wolfSSL | 0:9d17e4342598 | 5295 | CYASSL_MSG("More records in input"); |
wolfSSL | 0:9d17e4342598 | 5296 | ssl->options.processReply = doProcessInit; |
wolfSSL | 0:9d17e4342598 | 5297 | continue; |
wolfSSL | 0:9d17e4342598 | 5298 | } |
wolfSSL | 0:9d17e4342598 | 5299 | |
wolfSSL | 0:9d17e4342598 | 5300 | default: |
wolfSSL | 0:9d17e4342598 | 5301 | CYASSL_MSG("Bad process input state, programming error"); |
wolfSSL | 0:9d17e4342598 | 5302 | return INPUT_CASE_ERROR; |
wolfSSL | 0:9d17e4342598 | 5303 | } |
wolfSSL | 0:9d17e4342598 | 5304 | } |
wolfSSL | 0:9d17e4342598 | 5305 | } |
wolfSSL | 0:9d17e4342598 | 5306 | |
wolfSSL | 0:9d17e4342598 | 5307 | |
wolfSSL | 0:9d17e4342598 | 5308 | int SendChangeCipher(CYASSL* ssl) |
wolfSSL | 0:9d17e4342598 | 5309 | { |
wolfSSL | 0:9d17e4342598 | 5310 | byte *output; |
wolfSSL | 0:9d17e4342598 | 5311 | int sendSz = RECORD_HEADER_SZ + ENUM_LEN; |
wolfSSL | 0:9d17e4342598 | 5312 | int idx = RECORD_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 5313 | int ret; |
wolfSSL | 0:9d17e4342598 | 5314 | |
wolfSSL | 0:9d17e4342598 | 5315 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 5316 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 5317 | sendSz += DTLS_RECORD_EXTRA; |
wolfSSL | 0:9d17e4342598 | 5318 | idx += DTLS_RECORD_EXTRA; |
wolfSSL | 0:9d17e4342598 | 5319 | } |
wolfSSL | 0:9d17e4342598 | 5320 | #endif |
wolfSSL | 0:9d17e4342598 | 5321 | |
wolfSSL | 0:9d17e4342598 | 5322 | /* check for avalaible size */ |
wolfSSL | 0:9d17e4342598 | 5323 | if ((ret = CheckAvailableSize(ssl, sendSz)) != 0) |
wolfSSL | 0:9d17e4342598 | 5324 | return ret; |
wolfSSL | 0:9d17e4342598 | 5325 | |
wolfSSL | 0:9d17e4342598 | 5326 | /* get ouput buffer */ |
wolfSSL | 0:9d17e4342598 | 5327 | output = ssl->buffers.outputBuffer.buffer + |
wolfSSL | 0:9d17e4342598 | 5328 | ssl->buffers.outputBuffer.length; |
wolfSSL | 0:9d17e4342598 | 5329 | |
wolfSSL | 0:9d17e4342598 | 5330 | AddRecordHeader(output, 1, change_cipher_spec, ssl); |
wolfSSL | 0:9d17e4342598 | 5331 | |
wolfSSL | 0:9d17e4342598 | 5332 | output[idx] = 1; /* turn it on */ |
wolfSSL | 0:9d17e4342598 | 5333 | |
wolfSSL | 0:9d17e4342598 | 5334 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 5335 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 5336 | if ((ret = DtlsPoolSave(ssl, output, sendSz)) != 0) |
wolfSSL | 0:9d17e4342598 | 5337 | return ret; |
wolfSSL | 0:9d17e4342598 | 5338 | } |
wolfSSL | 0:9d17e4342598 | 5339 | #endif |
wolfSSL | 0:9d17e4342598 | 5340 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 5341 | if (ssl->hsInfoOn) AddPacketName("ChangeCipher", &ssl->handShakeInfo); |
wolfSSL | 0:9d17e4342598 | 5342 | if (ssl->toInfoOn) |
wolfSSL | 0:9d17e4342598 | 5343 | AddPacketInfo("ChangeCipher", &ssl->timeoutInfo, output, sendSz, |
wolfSSL | 0:9d17e4342598 | 5344 | ssl->heap); |
wolfSSL | 0:9d17e4342598 | 5345 | #endif |
wolfSSL | 0:9d17e4342598 | 5346 | ssl->buffers.outputBuffer.length += sendSz; |
wolfSSL | 0:9d17e4342598 | 5347 | |
wolfSSL | 0:9d17e4342598 | 5348 | if (ssl->options.groupMessages) |
wolfSSL | 0:9d17e4342598 | 5349 | return 0; |
wolfSSL | 0:9d17e4342598 | 5350 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 5351 | else if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 5352 | /* If using DTLS, force the ChangeCipherSpec message to be in the |
wolfSSL | 0:9d17e4342598 | 5353 | * same datagram as the finished message. */ |
wolfSSL | 0:9d17e4342598 | 5354 | return 0; |
wolfSSL | 0:9d17e4342598 | 5355 | } |
wolfSSL | 0:9d17e4342598 | 5356 | #endif |
wolfSSL | 0:9d17e4342598 | 5357 | else |
wolfSSL | 0:9d17e4342598 | 5358 | return SendBuffered(ssl); |
wolfSSL | 0:9d17e4342598 | 5359 | } |
wolfSSL | 0:9d17e4342598 | 5360 | |
wolfSSL | 0:9d17e4342598 | 5361 | |
wolfSSL | 0:9d17e4342598 | 5362 | #ifndef NO_OLD_TLS |
wolfSSL | 0:9d17e4342598 | 5363 | static int SSL_hmac(CYASSL* ssl, byte* digest, const byte* in, word32 sz, |
wolfSSL | 0:9d17e4342598 | 5364 | int content, int verify) |
wolfSSL | 0:9d17e4342598 | 5365 | { |
wolfSSL | 0:9d17e4342598 | 5366 | byte result[MAX_DIGEST_SIZE]; |
wolfSSL | 0:9d17e4342598 | 5367 | word32 digestSz = ssl->specs.hash_size; /* actual sizes */ |
wolfSSL | 0:9d17e4342598 | 5368 | word32 padSz = ssl->specs.pad_size; |
wolfSSL | 0:9d17e4342598 | 5369 | int ret = 0; |
wolfSSL | 0:9d17e4342598 | 5370 | |
wolfSSL | 0:9d17e4342598 | 5371 | Md5 md5; |
wolfSSL | 0:9d17e4342598 | 5372 | Sha sha; |
wolfSSL | 0:9d17e4342598 | 5373 | |
wolfSSL | 0:9d17e4342598 | 5374 | /* data */ |
wolfSSL | 0:9d17e4342598 | 5375 | byte seq[SEQ_SZ]; |
wolfSSL | 0:9d17e4342598 | 5376 | byte conLen[ENUM_LEN + LENGTH_SZ]; /* content & length */ |
wolfSSL | 0:9d17e4342598 | 5377 | const byte* macSecret = CyaSSL_GetMacSecret(ssl, verify); |
wolfSSL | 0:9d17e4342598 | 5378 | |
wolfSSL | 0:9d17e4342598 | 5379 | XMEMSET(seq, 0, SEQ_SZ); |
wolfSSL | 0:9d17e4342598 | 5380 | conLen[0] = (byte)content; |
wolfSSL | 0:9d17e4342598 | 5381 | c16toa((word16)sz, &conLen[ENUM_LEN]); |
wolfSSL | 0:9d17e4342598 | 5382 | c32toa(GetSEQIncrement(ssl, verify), &seq[sizeof(word32)]); |
wolfSSL | 0:9d17e4342598 | 5383 | |
wolfSSL | 0:9d17e4342598 | 5384 | if (ssl->specs.mac_algorithm == md5_mac) { |
wolfSSL | 0:9d17e4342598 | 5385 | InitMd5(&md5); |
wolfSSL | 0:9d17e4342598 | 5386 | /* inner */ |
wolfSSL | 0:9d17e4342598 | 5387 | Md5Update(&md5, macSecret, digestSz); |
wolfSSL | 0:9d17e4342598 | 5388 | Md5Update(&md5, PAD1, padSz); |
wolfSSL | 0:9d17e4342598 | 5389 | Md5Update(&md5, seq, SEQ_SZ); |
wolfSSL | 0:9d17e4342598 | 5390 | Md5Update(&md5, conLen, sizeof(conLen)); |
wolfSSL | 0:9d17e4342598 | 5391 | /* in buffer */ |
wolfSSL | 0:9d17e4342598 | 5392 | Md5Update(&md5, in, sz); |
wolfSSL | 0:9d17e4342598 | 5393 | Md5Final(&md5, result); |
wolfSSL | 0:9d17e4342598 | 5394 | /* outer */ |
wolfSSL | 0:9d17e4342598 | 5395 | Md5Update(&md5, macSecret, digestSz); |
wolfSSL | 0:9d17e4342598 | 5396 | Md5Update(&md5, PAD2, padSz); |
wolfSSL | 0:9d17e4342598 | 5397 | Md5Update(&md5, result, digestSz); |
wolfSSL | 0:9d17e4342598 | 5398 | Md5Final(&md5, digest); |
wolfSSL | 0:9d17e4342598 | 5399 | } |
wolfSSL | 0:9d17e4342598 | 5400 | else { |
wolfSSL | 0:9d17e4342598 | 5401 | ret = InitSha(&sha); |
wolfSSL | 0:9d17e4342598 | 5402 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 5403 | return ret; |
wolfSSL | 0:9d17e4342598 | 5404 | /* inner */ |
wolfSSL | 0:9d17e4342598 | 5405 | ShaUpdate(&sha, macSecret, digestSz); |
wolfSSL | 0:9d17e4342598 | 5406 | ShaUpdate(&sha, PAD1, padSz); |
wolfSSL | 0:9d17e4342598 | 5407 | ShaUpdate(&sha, seq, SEQ_SZ); |
wolfSSL | 0:9d17e4342598 | 5408 | ShaUpdate(&sha, conLen, sizeof(conLen)); |
wolfSSL | 0:9d17e4342598 | 5409 | /* in buffer */ |
wolfSSL | 0:9d17e4342598 | 5410 | ShaUpdate(&sha, in, sz); |
wolfSSL | 0:9d17e4342598 | 5411 | ShaFinal(&sha, result); |
wolfSSL | 0:9d17e4342598 | 5412 | /* outer */ |
wolfSSL | 0:9d17e4342598 | 5413 | ShaUpdate(&sha, macSecret, digestSz); |
wolfSSL | 0:9d17e4342598 | 5414 | ShaUpdate(&sha, PAD2, padSz); |
wolfSSL | 0:9d17e4342598 | 5415 | ShaUpdate(&sha, result, digestSz); |
wolfSSL | 0:9d17e4342598 | 5416 | ShaFinal(&sha, digest); |
wolfSSL | 0:9d17e4342598 | 5417 | } |
wolfSSL | 0:9d17e4342598 | 5418 | return 0; |
wolfSSL | 0:9d17e4342598 | 5419 | } |
wolfSSL | 0:9d17e4342598 | 5420 | |
wolfSSL | 0:9d17e4342598 | 5421 | #ifndef NO_CERTS |
wolfSSL | 0:9d17e4342598 | 5422 | static void BuildMD5_CertVerify(CYASSL* ssl, byte* digest) |
wolfSSL | 0:9d17e4342598 | 5423 | { |
wolfSSL | 0:9d17e4342598 | 5424 | byte md5_result[MD5_DIGEST_SIZE]; |
wolfSSL | 0:9d17e4342598 | 5425 | |
wolfSSL | 0:9d17e4342598 | 5426 | /* make md5 inner */ |
wolfSSL | 0:9d17e4342598 | 5427 | Md5Update(&ssl->hashMd5, ssl->arrays->masterSecret, SECRET_LEN); |
wolfSSL | 0:9d17e4342598 | 5428 | Md5Update(&ssl->hashMd5, PAD1, PAD_MD5); |
wolfSSL | 0:9d17e4342598 | 5429 | Md5Final(&ssl->hashMd5, md5_result); |
wolfSSL | 0:9d17e4342598 | 5430 | |
wolfSSL | 0:9d17e4342598 | 5431 | /* make md5 outer */ |
wolfSSL | 0:9d17e4342598 | 5432 | Md5Update(&ssl->hashMd5, ssl->arrays->masterSecret, SECRET_LEN); |
wolfSSL | 0:9d17e4342598 | 5433 | Md5Update(&ssl->hashMd5, PAD2, PAD_MD5); |
wolfSSL | 0:9d17e4342598 | 5434 | Md5Update(&ssl->hashMd5, md5_result, MD5_DIGEST_SIZE); |
wolfSSL | 0:9d17e4342598 | 5435 | |
wolfSSL | 0:9d17e4342598 | 5436 | Md5Final(&ssl->hashMd5, digest); |
wolfSSL | 0:9d17e4342598 | 5437 | } |
wolfSSL | 0:9d17e4342598 | 5438 | |
wolfSSL | 0:9d17e4342598 | 5439 | |
wolfSSL | 0:9d17e4342598 | 5440 | static void BuildSHA_CertVerify(CYASSL* ssl, byte* digest) |
wolfSSL | 0:9d17e4342598 | 5441 | { |
wolfSSL | 0:9d17e4342598 | 5442 | byte sha_result[SHA_DIGEST_SIZE]; |
wolfSSL | 0:9d17e4342598 | 5443 | |
wolfSSL | 0:9d17e4342598 | 5444 | /* make sha inner */ |
wolfSSL | 0:9d17e4342598 | 5445 | ShaUpdate(&ssl->hashSha, ssl->arrays->masterSecret, SECRET_LEN); |
wolfSSL | 0:9d17e4342598 | 5446 | ShaUpdate(&ssl->hashSha, PAD1, PAD_SHA); |
wolfSSL | 0:9d17e4342598 | 5447 | ShaFinal(&ssl->hashSha, sha_result); |
wolfSSL | 0:9d17e4342598 | 5448 | |
wolfSSL | 0:9d17e4342598 | 5449 | /* make sha outer */ |
wolfSSL | 0:9d17e4342598 | 5450 | ShaUpdate(&ssl->hashSha, ssl->arrays->masterSecret, SECRET_LEN); |
wolfSSL | 0:9d17e4342598 | 5451 | ShaUpdate(&ssl->hashSha, PAD2, PAD_SHA); |
wolfSSL | 0:9d17e4342598 | 5452 | ShaUpdate(&ssl->hashSha, sha_result, SHA_DIGEST_SIZE); |
wolfSSL | 0:9d17e4342598 | 5453 | |
wolfSSL | 0:9d17e4342598 | 5454 | ShaFinal(&ssl->hashSha, digest); |
wolfSSL | 0:9d17e4342598 | 5455 | } |
wolfSSL | 0:9d17e4342598 | 5456 | #endif /* NO_CERTS */ |
wolfSSL | 0:9d17e4342598 | 5457 | #endif /* NO_OLD_TLS */ |
wolfSSL | 0:9d17e4342598 | 5458 | |
wolfSSL | 0:9d17e4342598 | 5459 | |
wolfSSL | 0:9d17e4342598 | 5460 | #ifndef NO_CERTS |
wolfSSL | 0:9d17e4342598 | 5461 | |
wolfSSL | 0:9d17e4342598 | 5462 | static void BuildCertHashes(CYASSL* ssl, Hashes* hashes) |
wolfSSL | 0:9d17e4342598 | 5463 | { |
wolfSSL | 0:9d17e4342598 | 5464 | /* store current states, building requires get_digest which resets state */ |
wolfSSL | 0:9d17e4342598 | 5465 | #ifndef NO_OLD_TLS |
wolfSSL | 0:9d17e4342598 | 5466 | Md5 md5 = ssl->hashMd5; |
wolfSSL | 0:9d17e4342598 | 5467 | Sha sha = ssl->hashSha; |
wolfSSL | 0:9d17e4342598 | 5468 | #endif |
wolfSSL | 0:9d17e4342598 | 5469 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 5470 | Sha256 sha256 = ssl->hashSha256; |
wolfSSL | 0:9d17e4342598 | 5471 | #endif |
wolfSSL | 0:9d17e4342598 | 5472 | #ifdef CYASSL_SHA384 |
wolfSSL | 0:9d17e4342598 | 5473 | Sha384 sha384 = ssl->hashSha384; |
wolfSSL | 0:9d17e4342598 | 5474 | #endif |
wolfSSL | 0:9d17e4342598 | 5475 | |
wolfSSL | 0:9d17e4342598 | 5476 | if (ssl->options.tls) { |
wolfSSL | 0:9d17e4342598 | 5477 | #if ! defined( NO_OLD_TLS ) |
wolfSSL | 0:9d17e4342598 | 5478 | Md5Final(&ssl->hashMd5, hashes->md5); |
wolfSSL | 0:9d17e4342598 | 5479 | ShaFinal(&ssl->hashSha, hashes->sha); |
wolfSSL | 0:9d17e4342598 | 5480 | #endif |
wolfSSL | 0:9d17e4342598 | 5481 | if (IsAtLeastTLSv1_2(ssl)) { |
wolfSSL | 0:9d17e4342598 | 5482 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 5483 | Sha256Final(&ssl->hashSha256, hashes->sha256); |
wolfSSL | 0:9d17e4342598 | 5484 | #endif |
wolfSSL | 0:9d17e4342598 | 5485 | #ifdef CYASSL_SHA384 |
wolfSSL | 0:9d17e4342598 | 5486 | Sha384Final(&ssl->hashSha384, hashes->sha384); |
wolfSSL | 0:9d17e4342598 | 5487 | #endif |
wolfSSL | 0:9d17e4342598 | 5488 | } |
wolfSSL | 0:9d17e4342598 | 5489 | } |
wolfSSL | 0:9d17e4342598 | 5490 | #if ! defined( NO_OLD_TLS ) |
wolfSSL | 0:9d17e4342598 | 5491 | else { |
wolfSSL | 0:9d17e4342598 | 5492 | BuildMD5_CertVerify(ssl, hashes->md5); |
wolfSSL | 0:9d17e4342598 | 5493 | BuildSHA_CertVerify(ssl, hashes->sha); |
wolfSSL | 0:9d17e4342598 | 5494 | } |
wolfSSL | 0:9d17e4342598 | 5495 | |
wolfSSL | 0:9d17e4342598 | 5496 | /* restore */ |
wolfSSL | 0:9d17e4342598 | 5497 | ssl->hashMd5 = md5; |
wolfSSL | 0:9d17e4342598 | 5498 | ssl->hashSha = sha; |
wolfSSL | 0:9d17e4342598 | 5499 | #endif |
wolfSSL | 0:9d17e4342598 | 5500 | if (IsAtLeastTLSv1_2(ssl)) { |
wolfSSL | 0:9d17e4342598 | 5501 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 5502 | ssl->hashSha256 = sha256; |
wolfSSL | 0:9d17e4342598 | 5503 | #endif |
wolfSSL | 0:9d17e4342598 | 5504 | #ifdef CYASSL_SHA384 |
wolfSSL | 0:9d17e4342598 | 5505 | ssl->hashSha384 = sha384; |
wolfSSL | 0:9d17e4342598 | 5506 | #endif |
wolfSSL | 0:9d17e4342598 | 5507 | } |
wolfSSL | 0:9d17e4342598 | 5508 | } |
wolfSSL | 0:9d17e4342598 | 5509 | |
wolfSSL | 0:9d17e4342598 | 5510 | #endif /* CYASSL_LEANPSK */ |
wolfSSL | 0:9d17e4342598 | 5511 | |
wolfSSL | 0:9d17e4342598 | 5512 | /* Build SSL Message, encrypted */ |
wolfSSL | 0:9d17e4342598 | 5513 | static int BuildMessage(CYASSL* ssl, byte* output, const byte* input, int inSz, |
wolfSSL | 0:9d17e4342598 | 5514 | int type) |
wolfSSL | 0:9d17e4342598 | 5515 | { |
wolfSSL | 0:9d17e4342598 | 5516 | #ifdef HAVE_TRUNCATED_HMAC |
wolfSSL | 0:9d17e4342598 | 5517 | word32 digestSz = min(ssl->specs.hash_size, |
wolfSSL | 0:9d17e4342598 | 5518 | ssl->truncated_hmac ? TRUNCATED_HMAC_SZ : ssl->specs.hash_size); |
wolfSSL | 0:9d17e4342598 | 5519 | #else |
wolfSSL | 0:9d17e4342598 | 5520 | word32 digestSz = ssl->specs.hash_size; |
wolfSSL | 0:9d17e4342598 | 5521 | #endif |
wolfSSL | 0:9d17e4342598 | 5522 | word32 sz = RECORD_HEADER_SZ + inSz + digestSz; |
wolfSSL | 0:9d17e4342598 | 5523 | word32 pad = 0, i; |
wolfSSL | 0:9d17e4342598 | 5524 | word32 idx = RECORD_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 5525 | word32 ivSz = 0; /* TLSv1.1 IV */ |
wolfSSL | 0:9d17e4342598 | 5526 | word32 headerSz = RECORD_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 5527 | word16 size; |
wolfSSL | 0:9d17e4342598 | 5528 | byte iv[AES_BLOCK_SIZE]; /* max size */ |
wolfSSL | 0:9d17e4342598 | 5529 | int ret = 0; |
wolfSSL | 0:9d17e4342598 | 5530 | int atomicUser = 0; |
wolfSSL | 0:9d17e4342598 | 5531 | |
wolfSSL | 0:9d17e4342598 | 5532 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 5533 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 5534 | sz += DTLS_RECORD_EXTRA; |
wolfSSL | 0:9d17e4342598 | 5535 | idx += DTLS_RECORD_EXTRA; |
wolfSSL | 0:9d17e4342598 | 5536 | headerSz += DTLS_RECORD_EXTRA; |
wolfSSL | 0:9d17e4342598 | 5537 | } |
wolfSSL | 0:9d17e4342598 | 5538 | #endif |
wolfSSL | 0:9d17e4342598 | 5539 | |
wolfSSL | 0:9d17e4342598 | 5540 | #ifdef ATOMIC_USER |
wolfSSL | 0:9d17e4342598 | 5541 | if (ssl->ctx->MacEncryptCb) |
wolfSSL | 0:9d17e4342598 | 5542 | atomicUser = 1; |
wolfSSL | 0:9d17e4342598 | 5543 | #endif |
wolfSSL | 0:9d17e4342598 | 5544 | |
wolfSSL | 0:9d17e4342598 | 5545 | if (ssl->specs.cipher_type == block) { |
wolfSSL | 0:9d17e4342598 | 5546 | word32 blockSz = ssl->specs.block_size; |
wolfSSL | 0:9d17e4342598 | 5547 | if (ssl->options.tls1_1) { |
wolfSSL | 0:9d17e4342598 | 5548 | ivSz = blockSz; |
wolfSSL | 0:9d17e4342598 | 5549 | sz += ivSz; |
wolfSSL | 0:9d17e4342598 | 5550 | RNG_GenerateBlock(ssl->rng, iv, ivSz); |
wolfSSL | 0:9d17e4342598 | 5551 | } |
wolfSSL | 0:9d17e4342598 | 5552 | sz += 1; /* pad byte */ |
wolfSSL | 0:9d17e4342598 | 5553 | pad = (sz - headerSz) % blockSz; |
wolfSSL | 0:9d17e4342598 | 5554 | pad = blockSz - pad; |
wolfSSL | 0:9d17e4342598 | 5555 | sz += pad; |
wolfSSL | 0:9d17e4342598 | 5556 | } |
wolfSSL | 0:9d17e4342598 | 5557 | |
wolfSSL | 0:9d17e4342598 | 5558 | #ifdef HAVE_AEAD |
wolfSSL | 0:9d17e4342598 | 5559 | if (ssl->specs.cipher_type == aead) { |
wolfSSL | 0:9d17e4342598 | 5560 | ivSz = AEAD_EXP_IV_SZ; |
wolfSSL | 0:9d17e4342598 | 5561 | sz += (ivSz + ssl->specs.aead_mac_size - digestSz); |
wolfSSL | 0:9d17e4342598 | 5562 | XMEMCPY(iv, ssl->keys.aead_exp_IV, AEAD_EXP_IV_SZ); |
wolfSSL | 0:9d17e4342598 | 5563 | } |
wolfSSL | 0:9d17e4342598 | 5564 | #endif |
wolfSSL | 0:9d17e4342598 | 5565 | size = (word16)(sz - headerSz); /* include mac and digest */ |
wolfSSL | 0:9d17e4342598 | 5566 | AddRecordHeader(output, size, (byte)type, ssl); |
wolfSSL | 0:9d17e4342598 | 5567 | |
wolfSSL | 0:9d17e4342598 | 5568 | /* write to output */ |
wolfSSL | 0:9d17e4342598 | 5569 | if (ivSz) { |
wolfSSL | 0:9d17e4342598 | 5570 | XMEMCPY(output + idx, iv, min(ivSz, sizeof(iv))); |
wolfSSL | 0:9d17e4342598 | 5571 | idx += ivSz; |
wolfSSL | 0:9d17e4342598 | 5572 | } |
wolfSSL | 0:9d17e4342598 | 5573 | XMEMCPY(output + idx, input, inSz); |
wolfSSL | 0:9d17e4342598 | 5574 | idx += inSz; |
wolfSSL | 0:9d17e4342598 | 5575 | |
wolfSSL | 0:9d17e4342598 | 5576 | if (type == handshake) { |
wolfSSL | 0:9d17e4342598 | 5577 | HashOutput(ssl, output, headerSz + inSz, ivSz); |
wolfSSL | 0:9d17e4342598 | 5578 | } |
wolfSSL | 0:9d17e4342598 | 5579 | |
wolfSSL | 0:9d17e4342598 | 5580 | if (ssl->specs.cipher_type == block) { |
wolfSSL | 0:9d17e4342598 | 5581 | word32 tmpIdx = idx + digestSz; |
wolfSSL | 0:9d17e4342598 | 5582 | |
wolfSSL | 0:9d17e4342598 | 5583 | for (i = 0; i <= pad; i++) |
wolfSSL | 0:9d17e4342598 | 5584 | output[tmpIdx++] = (byte)pad; /* pad byte gets pad value too */ |
wolfSSL | 0:9d17e4342598 | 5585 | } |
wolfSSL | 0:9d17e4342598 | 5586 | |
wolfSSL | 0:9d17e4342598 | 5587 | if (atomicUser) { /* User Record Layer Callback handling */ |
wolfSSL | 0:9d17e4342598 | 5588 | #ifdef ATOMIC_USER |
wolfSSL | 0:9d17e4342598 | 5589 | if ( (ret = ssl->ctx->MacEncryptCb(ssl, output + idx, |
wolfSSL | 0:9d17e4342598 | 5590 | output + headerSz + ivSz, inSz, type, 0, |
wolfSSL | 0:9d17e4342598 | 5591 | output + headerSz, output + headerSz, size, |
wolfSSL | 0:9d17e4342598 | 5592 | ssl->MacEncryptCtx)) != 0) |
wolfSSL | 0:9d17e4342598 | 5593 | return ret; |
wolfSSL | 0:9d17e4342598 | 5594 | #endif |
wolfSSL | 0:9d17e4342598 | 5595 | } |
wolfSSL | 0:9d17e4342598 | 5596 | else { |
wolfSSL | 0:9d17e4342598 | 5597 | if (ssl->specs.cipher_type != aead) { |
wolfSSL | 0:9d17e4342598 | 5598 | #ifdef HAVE_TRUNCATED_HMAC |
wolfSSL | 0:9d17e4342598 | 5599 | if (ssl->truncated_hmac && ssl->specs.hash_size > digestSz) { |
wolfSSL | 0:9d17e4342598 | 5600 | byte hmac[MAX_DIGEST_SIZE]; |
wolfSSL | 0:9d17e4342598 | 5601 | |
wolfSSL | 0:9d17e4342598 | 5602 | ret = ssl->hmac(ssl, hmac, output + headerSz + ivSz, inSz, |
wolfSSL | 0:9d17e4342598 | 5603 | type, 0); |
wolfSSL | 0:9d17e4342598 | 5604 | XMEMCPY(output + idx, hmac, digestSz); |
wolfSSL | 0:9d17e4342598 | 5605 | } else |
wolfSSL | 0:9d17e4342598 | 5606 | #endif |
wolfSSL | 0:9d17e4342598 | 5607 | ret = ssl->hmac(ssl, output+idx, output + headerSz + ivSz, inSz, |
wolfSSL | 0:9d17e4342598 | 5608 | type, 0); |
wolfSSL | 0:9d17e4342598 | 5609 | } |
wolfSSL | 0:9d17e4342598 | 5610 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 5611 | return ret; |
wolfSSL | 0:9d17e4342598 | 5612 | |
wolfSSL | 0:9d17e4342598 | 5613 | if ( (ret = Encrypt(ssl, output + headerSz, output+headerSz,size)) != 0) |
wolfSSL | 0:9d17e4342598 | 5614 | return ret; |
wolfSSL | 0:9d17e4342598 | 5615 | } |
wolfSSL | 0:9d17e4342598 | 5616 | |
wolfSSL | 0:9d17e4342598 | 5617 | return sz; |
wolfSSL | 0:9d17e4342598 | 5618 | } |
wolfSSL | 0:9d17e4342598 | 5619 | |
wolfSSL | 0:9d17e4342598 | 5620 | |
wolfSSL | 0:9d17e4342598 | 5621 | int SendFinished(CYASSL* ssl) |
wolfSSL | 0:9d17e4342598 | 5622 | { |
wolfSSL | 0:9d17e4342598 | 5623 | int sendSz, |
wolfSSL | 0:9d17e4342598 | 5624 | finishedSz = ssl->options.tls ? TLS_FINISHED_SZ : |
wolfSSL | 0:9d17e4342598 | 5625 | FINISHED_SZ; |
wolfSSL | 0:9d17e4342598 | 5626 | byte input[FINISHED_SZ + DTLS_HANDSHAKE_HEADER_SZ]; /* max */ |
wolfSSL | 0:9d17e4342598 | 5627 | byte *output; |
wolfSSL | 0:9d17e4342598 | 5628 | Hashes* hashes; |
wolfSSL | 0:9d17e4342598 | 5629 | int ret; |
wolfSSL | 0:9d17e4342598 | 5630 | int headerSz = HANDSHAKE_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 5631 | |
wolfSSL | 0:9d17e4342598 | 5632 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 5633 | word32 sequence_number = ssl->keys.dtls_sequence_number; |
wolfSSL | 0:9d17e4342598 | 5634 | word16 epoch = ssl->keys.dtls_epoch; |
wolfSSL | 0:9d17e4342598 | 5635 | #endif |
wolfSSL | 0:9d17e4342598 | 5636 | |
wolfSSL | 0:9d17e4342598 | 5637 | |
wolfSSL | 0:9d17e4342598 | 5638 | /* check for available size */ |
wolfSSL | 0:9d17e4342598 | 5639 | if ((ret = CheckAvailableSize(ssl, sizeof(input) + MAX_MSG_EXTRA)) != 0) |
wolfSSL | 0:9d17e4342598 | 5640 | return ret; |
wolfSSL | 0:9d17e4342598 | 5641 | |
wolfSSL | 0:9d17e4342598 | 5642 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 5643 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 5644 | /* Send Finished message with the next epoch, but don't commit that |
wolfSSL | 0:9d17e4342598 | 5645 | * change until the other end confirms its reception. */ |
wolfSSL | 0:9d17e4342598 | 5646 | headerSz += DTLS_HANDSHAKE_EXTRA; |
wolfSSL | 0:9d17e4342598 | 5647 | ssl->keys.dtls_epoch++; |
wolfSSL | 0:9d17e4342598 | 5648 | ssl->keys.dtls_sequence_number = 0; /* reset after epoch change */ |
wolfSSL | 0:9d17e4342598 | 5649 | } |
wolfSSL | 0:9d17e4342598 | 5650 | #endif |
wolfSSL | 0:9d17e4342598 | 5651 | |
wolfSSL | 0:9d17e4342598 | 5652 | /* get ouput buffer */ |
wolfSSL | 0:9d17e4342598 | 5653 | output = ssl->buffers.outputBuffer.buffer + |
wolfSSL | 0:9d17e4342598 | 5654 | ssl->buffers.outputBuffer.length; |
wolfSSL | 0:9d17e4342598 | 5655 | |
wolfSSL | 0:9d17e4342598 | 5656 | AddHandShakeHeader(input, finishedSz, finished, ssl); |
wolfSSL | 0:9d17e4342598 | 5657 | |
wolfSSL | 0:9d17e4342598 | 5658 | /* make finished hashes */ |
wolfSSL | 0:9d17e4342598 | 5659 | hashes = (Hashes*)&input[headerSz]; |
wolfSSL | 0:9d17e4342598 | 5660 | ret = BuildFinished(ssl, hashes, |
wolfSSL | 0:9d17e4342598 | 5661 | ssl->options.side == CYASSL_CLIENT_END ? client : server); |
wolfSSL | 0:9d17e4342598 | 5662 | if (ret != 0) return ret; |
wolfSSL | 0:9d17e4342598 | 5663 | |
wolfSSL | 0:9d17e4342598 | 5664 | sendSz = BuildMessage(ssl, output, input, headerSz + finishedSz, handshake); |
wolfSSL | 0:9d17e4342598 | 5665 | |
wolfSSL | 0:9d17e4342598 | 5666 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 5667 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 5668 | ssl->keys.dtls_epoch = epoch; |
wolfSSL | 0:9d17e4342598 | 5669 | ssl->keys.dtls_sequence_number = sequence_number; |
wolfSSL | 0:9d17e4342598 | 5670 | } |
wolfSSL | 0:9d17e4342598 | 5671 | #endif |
wolfSSL | 0:9d17e4342598 | 5672 | |
wolfSSL | 0:9d17e4342598 | 5673 | if (sendSz < 0) |
wolfSSL | 0:9d17e4342598 | 5674 | return BUILD_MSG_ERROR; |
wolfSSL | 0:9d17e4342598 | 5675 | |
wolfSSL | 0:9d17e4342598 | 5676 | if (!ssl->options.resuming) { |
wolfSSL | 0:9d17e4342598 | 5677 | #ifndef NO_SESSION_CACHE |
wolfSSL | 0:9d17e4342598 | 5678 | AddSession(ssl); /* just try */ |
wolfSSL | 0:9d17e4342598 | 5679 | #endif |
wolfSSL | 0:9d17e4342598 | 5680 | if (ssl->options.side == CYASSL_CLIENT_END) { |
wolfSSL | 0:9d17e4342598 | 5681 | ret = BuildFinished(ssl, &ssl->verifyHashes, server); |
wolfSSL | 0:9d17e4342598 | 5682 | if (ret != 0) return ret; |
wolfSSL | 0:9d17e4342598 | 5683 | } |
wolfSSL | 0:9d17e4342598 | 5684 | else { |
wolfSSL | 0:9d17e4342598 | 5685 | ssl->options.handShakeState = HANDSHAKE_DONE; |
wolfSSL | 0:9d17e4342598 | 5686 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 5687 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 5688 | /* Other side will soon receive our Finished, go to next |
wolfSSL | 0:9d17e4342598 | 5689 | * epoch. */ |
wolfSSL | 0:9d17e4342598 | 5690 | ssl->keys.dtls_epoch++; |
wolfSSL | 0:9d17e4342598 | 5691 | ssl->keys.dtls_sequence_number = 1; |
wolfSSL | 0:9d17e4342598 | 5692 | } |
wolfSSL | 0:9d17e4342598 | 5693 | #endif |
wolfSSL | 0:9d17e4342598 | 5694 | } |
wolfSSL | 0:9d17e4342598 | 5695 | } |
wolfSSL | 0:9d17e4342598 | 5696 | else { |
wolfSSL | 0:9d17e4342598 | 5697 | if (ssl->options.side == CYASSL_CLIENT_END) { |
wolfSSL | 0:9d17e4342598 | 5698 | ssl->options.handShakeState = HANDSHAKE_DONE; |
wolfSSL | 0:9d17e4342598 | 5699 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 5700 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 5701 | /* Other side will soon receive our Finished, go to next |
wolfSSL | 0:9d17e4342598 | 5702 | * epoch. */ |
wolfSSL | 0:9d17e4342598 | 5703 | ssl->keys.dtls_epoch++; |
wolfSSL | 0:9d17e4342598 | 5704 | ssl->keys.dtls_sequence_number = 1; |
wolfSSL | 0:9d17e4342598 | 5705 | } |
wolfSSL | 0:9d17e4342598 | 5706 | #endif |
wolfSSL | 0:9d17e4342598 | 5707 | } |
wolfSSL | 0:9d17e4342598 | 5708 | else { |
wolfSSL | 0:9d17e4342598 | 5709 | ret = BuildFinished(ssl, &ssl->verifyHashes, client); |
wolfSSL | 0:9d17e4342598 | 5710 | if (ret != 0) return ret; |
wolfSSL | 0:9d17e4342598 | 5711 | } |
wolfSSL | 0:9d17e4342598 | 5712 | } |
wolfSSL | 0:9d17e4342598 | 5713 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 5714 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 5715 | if ((ret = DtlsPoolSave(ssl, output, sendSz)) != 0) |
wolfSSL | 0:9d17e4342598 | 5716 | return ret; |
wolfSSL | 0:9d17e4342598 | 5717 | } |
wolfSSL | 0:9d17e4342598 | 5718 | #endif |
wolfSSL | 0:9d17e4342598 | 5719 | |
wolfSSL | 0:9d17e4342598 | 5720 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 5721 | if (ssl->hsInfoOn) AddPacketName("Finished", &ssl->handShakeInfo); |
wolfSSL | 0:9d17e4342598 | 5722 | if (ssl->toInfoOn) |
wolfSSL | 0:9d17e4342598 | 5723 | AddPacketInfo("Finished", &ssl->timeoutInfo, output, sendSz, |
wolfSSL | 0:9d17e4342598 | 5724 | ssl->heap); |
wolfSSL | 0:9d17e4342598 | 5725 | #endif |
wolfSSL | 0:9d17e4342598 | 5726 | |
wolfSSL | 0:9d17e4342598 | 5727 | ssl->buffers.outputBuffer.length += sendSz; |
wolfSSL | 0:9d17e4342598 | 5728 | |
wolfSSL | 0:9d17e4342598 | 5729 | return SendBuffered(ssl); |
wolfSSL | 0:9d17e4342598 | 5730 | } |
wolfSSL | 0:9d17e4342598 | 5731 | |
wolfSSL | 0:9d17e4342598 | 5732 | #ifndef NO_CERTS |
wolfSSL | 0:9d17e4342598 | 5733 | int SendCertificate(CYASSL* ssl) |
wolfSSL | 0:9d17e4342598 | 5734 | { |
wolfSSL | 0:9d17e4342598 | 5735 | int sendSz, length, ret = 0; |
wolfSSL | 0:9d17e4342598 | 5736 | word32 i = RECORD_HEADER_SZ + HANDSHAKE_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 5737 | word32 certSz, listSz; |
wolfSSL | 0:9d17e4342598 | 5738 | byte* output = 0; |
wolfSSL | 0:9d17e4342598 | 5739 | |
wolfSSL | 0:9d17e4342598 | 5740 | if (ssl->options.usingPSK_cipher) return 0; /* not needed */ |
wolfSSL | 0:9d17e4342598 | 5741 | |
wolfSSL | 0:9d17e4342598 | 5742 | if (ssl->options.sendVerify == SEND_BLANK_CERT) { |
wolfSSL | 0:9d17e4342598 | 5743 | certSz = 0; |
wolfSSL | 0:9d17e4342598 | 5744 | length = CERT_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 5745 | listSz = 0; |
wolfSSL | 0:9d17e4342598 | 5746 | } |
wolfSSL | 0:9d17e4342598 | 5747 | else { |
wolfSSL | 0:9d17e4342598 | 5748 | certSz = ssl->buffers.certificate.length; |
wolfSSL | 0:9d17e4342598 | 5749 | /* list + cert size */ |
wolfSSL | 0:9d17e4342598 | 5750 | length = certSz + 2 * CERT_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 5751 | listSz = certSz + CERT_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 5752 | |
wolfSSL | 0:9d17e4342598 | 5753 | /* may need to send rest of chain, already has leading size(s) */ |
wolfSSL | 0:9d17e4342598 | 5754 | if (ssl->buffers.certChain.buffer) { |
wolfSSL | 0:9d17e4342598 | 5755 | length += ssl->buffers.certChain.length; |
wolfSSL | 0:9d17e4342598 | 5756 | listSz += ssl->buffers.certChain.length; |
wolfSSL | 0:9d17e4342598 | 5757 | } |
wolfSSL | 0:9d17e4342598 | 5758 | } |
wolfSSL | 0:9d17e4342598 | 5759 | sendSz = length + RECORD_HEADER_SZ + HANDSHAKE_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 5760 | |
wolfSSL | 0:9d17e4342598 | 5761 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 5762 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 5763 | sendSz += DTLS_RECORD_EXTRA + DTLS_HANDSHAKE_EXTRA; |
wolfSSL | 0:9d17e4342598 | 5764 | i += DTLS_RECORD_EXTRA + DTLS_HANDSHAKE_EXTRA; |
wolfSSL | 0:9d17e4342598 | 5765 | } |
wolfSSL | 0:9d17e4342598 | 5766 | #endif |
wolfSSL | 0:9d17e4342598 | 5767 | |
wolfSSL | 0:9d17e4342598 | 5768 | /* check for available size */ |
wolfSSL | 0:9d17e4342598 | 5769 | if ((ret = CheckAvailableSize(ssl, sendSz)) != 0) |
wolfSSL | 0:9d17e4342598 | 5770 | return ret; |
wolfSSL | 0:9d17e4342598 | 5771 | |
wolfSSL | 0:9d17e4342598 | 5772 | /* get ouput buffer */ |
wolfSSL | 0:9d17e4342598 | 5773 | output = ssl->buffers.outputBuffer.buffer + |
wolfSSL | 0:9d17e4342598 | 5774 | ssl->buffers.outputBuffer.length; |
wolfSSL | 0:9d17e4342598 | 5775 | |
wolfSSL | 0:9d17e4342598 | 5776 | AddHeaders(output, length, certificate, ssl); |
wolfSSL | 0:9d17e4342598 | 5777 | |
wolfSSL | 0:9d17e4342598 | 5778 | /* list total */ |
wolfSSL | 0:9d17e4342598 | 5779 | c32to24(listSz, output + i); |
wolfSSL | 0:9d17e4342598 | 5780 | i += CERT_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 5781 | |
wolfSSL | 0:9d17e4342598 | 5782 | /* member */ |
wolfSSL | 0:9d17e4342598 | 5783 | if (certSz) { |
wolfSSL | 0:9d17e4342598 | 5784 | c32to24(certSz, output + i); |
wolfSSL | 0:9d17e4342598 | 5785 | i += CERT_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 5786 | XMEMCPY(output + i, ssl->buffers.certificate.buffer, certSz); |
wolfSSL | 0:9d17e4342598 | 5787 | i += certSz; |
wolfSSL | 0:9d17e4342598 | 5788 | |
wolfSSL | 0:9d17e4342598 | 5789 | /* send rest of chain? */ |
wolfSSL | 0:9d17e4342598 | 5790 | if (ssl->buffers.certChain.buffer) { |
wolfSSL | 0:9d17e4342598 | 5791 | XMEMCPY(output + i, ssl->buffers.certChain.buffer, |
wolfSSL | 0:9d17e4342598 | 5792 | ssl->buffers.certChain.length); |
wolfSSL | 0:9d17e4342598 | 5793 | /* if add more to output adjust i |
wolfSSL | 0:9d17e4342598 | 5794 | i += ssl->buffers.certChain.length; */ |
wolfSSL | 0:9d17e4342598 | 5795 | } |
wolfSSL | 0:9d17e4342598 | 5796 | } |
wolfSSL | 0:9d17e4342598 | 5797 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 5798 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 5799 | if ((ret = DtlsPoolSave(ssl, output, sendSz)) != 0) |
wolfSSL | 0:9d17e4342598 | 5800 | return ret; |
wolfSSL | 0:9d17e4342598 | 5801 | } |
wolfSSL | 0:9d17e4342598 | 5802 | #endif |
wolfSSL | 0:9d17e4342598 | 5803 | HashOutput(ssl, output, sendSz, 0); |
wolfSSL | 0:9d17e4342598 | 5804 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 5805 | if (ssl->hsInfoOn) AddPacketName("Certificate", &ssl->handShakeInfo); |
wolfSSL | 0:9d17e4342598 | 5806 | if (ssl->toInfoOn) |
wolfSSL | 0:9d17e4342598 | 5807 | AddPacketInfo("Certificate", &ssl->timeoutInfo, output, sendSz, |
wolfSSL | 0:9d17e4342598 | 5808 | ssl->heap); |
wolfSSL | 0:9d17e4342598 | 5809 | #endif |
wolfSSL | 0:9d17e4342598 | 5810 | |
wolfSSL | 0:9d17e4342598 | 5811 | if (ssl->options.side == CYASSL_SERVER_END) |
wolfSSL | 0:9d17e4342598 | 5812 | ssl->options.serverState = SERVER_CERT_COMPLETE; |
wolfSSL | 0:9d17e4342598 | 5813 | |
wolfSSL | 0:9d17e4342598 | 5814 | ssl->buffers.outputBuffer.length += sendSz; |
wolfSSL | 0:9d17e4342598 | 5815 | if (ssl->options.groupMessages) |
wolfSSL | 0:9d17e4342598 | 5816 | return 0; |
wolfSSL | 0:9d17e4342598 | 5817 | else |
wolfSSL | 0:9d17e4342598 | 5818 | return SendBuffered(ssl); |
wolfSSL | 0:9d17e4342598 | 5819 | } |
wolfSSL | 0:9d17e4342598 | 5820 | |
wolfSSL | 0:9d17e4342598 | 5821 | |
wolfSSL | 0:9d17e4342598 | 5822 | int SendCertificateRequest(CYASSL* ssl) |
wolfSSL | 0:9d17e4342598 | 5823 | { |
wolfSSL | 0:9d17e4342598 | 5824 | byte *output; |
wolfSSL | 0:9d17e4342598 | 5825 | int ret; |
wolfSSL | 0:9d17e4342598 | 5826 | int sendSz; |
wolfSSL | 0:9d17e4342598 | 5827 | word32 i = RECORD_HEADER_SZ + HANDSHAKE_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 5828 | |
wolfSSL | 0:9d17e4342598 | 5829 | int typeTotal = 1; /* only rsa for now */ |
wolfSSL | 0:9d17e4342598 | 5830 | int reqSz = ENUM_LEN + typeTotal + REQ_HEADER_SZ; /* add auth later */ |
wolfSSL | 0:9d17e4342598 | 5831 | |
wolfSSL | 0:9d17e4342598 | 5832 | if (IsAtLeastTLSv1_2(ssl)) |
wolfSSL | 0:9d17e4342598 | 5833 | reqSz += LENGTH_SZ + ssl->suites->hashSigAlgoSz; |
wolfSSL | 0:9d17e4342598 | 5834 | |
wolfSSL | 0:9d17e4342598 | 5835 | if (ssl->options.usingPSK_cipher) return 0; /* not needed */ |
wolfSSL | 0:9d17e4342598 | 5836 | |
wolfSSL | 0:9d17e4342598 | 5837 | sendSz = RECORD_HEADER_SZ + HANDSHAKE_HEADER_SZ + reqSz; |
wolfSSL | 0:9d17e4342598 | 5838 | |
wolfSSL | 0:9d17e4342598 | 5839 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 5840 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 5841 | sendSz += DTLS_RECORD_EXTRA + DTLS_HANDSHAKE_EXTRA; |
wolfSSL | 0:9d17e4342598 | 5842 | i += DTLS_RECORD_EXTRA + DTLS_HANDSHAKE_EXTRA; |
wolfSSL | 0:9d17e4342598 | 5843 | } |
wolfSSL | 0:9d17e4342598 | 5844 | #endif |
wolfSSL | 0:9d17e4342598 | 5845 | /* check for available size */ |
wolfSSL | 0:9d17e4342598 | 5846 | if ((ret = CheckAvailableSize(ssl, sendSz)) != 0) |
wolfSSL | 0:9d17e4342598 | 5847 | return ret; |
wolfSSL | 0:9d17e4342598 | 5848 | |
wolfSSL | 0:9d17e4342598 | 5849 | /* get ouput buffer */ |
wolfSSL | 0:9d17e4342598 | 5850 | output = ssl->buffers.outputBuffer.buffer + |
wolfSSL | 0:9d17e4342598 | 5851 | ssl->buffers.outputBuffer.length; |
wolfSSL | 0:9d17e4342598 | 5852 | |
wolfSSL | 0:9d17e4342598 | 5853 | AddHeaders(output, reqSz, certificate_request, ssl); |
wolfSSL | 0:9d17e4342598 | 5854 | |
wolfSSL | 0:9d17e4342598 | 5855 | /* write to output */ |
wolfSSL | 0:9d17e4342598 | 5856 | output[i++] = (byte)typeTotal; /* # of types */ |
wolfSSL | 0:9d17e4342598 | 5857 | output[i++] = rsa_sign; |
wolfSSL | 0:9d17e4342598 | 5858 | |
wolfSSL | 0:9d17e4342598 | 5859 | /* supported hash/sig */ |
wolfSSL | 0:9d17e4342598 | 5860 | if (IsAtLeastTLSv1_2(ssl)) { |
wolfSSL | 0:9d17e4342598 | 5861 | c16toa(ssl->suites->hashSigAlgoSz, &output[i]); |
wolfSSL | 0:9d17e4342598 | 5862 | i += LENGTH_SZ; |
wolfSSL | 0:9d17e4342598 | 5863 | |
wolfSSL | 0:9d17e4342598 | 5864 | XMEMCPY(&output[i], |
wolfSSL | 0:9d17e4342598 | 5865 | ssl->suites->hashSigAlgo, ssl->suites->hashSigAlgoSz); |
wolfSSL | 0:9d17e4342598 | 5866 | i += ssl->suites->hashSigAlgoSz; |
wolfSSL | 0:9d17e4342598 | 5867 | } |
wolfSSL | 0:9d17e4342598 | 5868 | |
wolfSSL | 0:9d17e4342598 | 5869 | c16toa(0, &output[i]); /* auth's */ |
wolfSSL | 0:9d17e4342598 | 5870 | /* if add more to output, adjust i |
wolfSSL | 0:9d17e4342598 | 5871 | i += REQ_HEADER_SZ; */ |
wolfSSL | 0:9d17e4342598 | 5872 | |
wolfSSL | 0:9d17e4342598 | 5873 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 5874 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 5875 | if ((ret = DtlsPoolSave(ssl, output, sendSz)) != 0) |
wolfSSL | 0:9d17e4342598 | 5876 | return ret; |
wolfSSL | 0:9d17e4342598 | 5877 | } |
wolfSSL | 0:9d17e4342598 | 5878 | #endif |
wolfSSL | 0:9d17e4342598 | 5879 | HashOutput(ssl, output, sendSz, 0); |
wolfSSL | 0:9d17e4342598 | 5880 | |
wolfSSL | 0:9d17e4342598 | 5881 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 5882 | if (ssl->hsInfoOn) |
wolfSSL | 0:9d17e4342598 | 5883 | AddPacketName("CertificateRequest", &ssl->handShakeInfo); |
wolfSSL | 0:9d17e4342598 | 5884 | if (ssl->toInfoOn) |
wolfSSL | 0:9d17e4342598 | 5885 | AddPacketInfo("CertificateRequest", &ssl->timeoutInfo, output, |
wolfSSL | 0:9d17e4342598 | 5886 | sendSz, ssl->heap); |
wolfSSL | 0:9d17e4342598 | 5887 | #endif |
wolfSSL | 0:9d17e4342598 | 5888 | ssl->buffers.outputBuffer.length += sendSz; |
wolfSSL | 0:9d17e4342598 | 5889 | if (ssl->options.groupMessages) |
wolfSSL | 0:9d17e4342598 | 5890 | return 0; |
wolfSSL | 0:9d17e4342598 | 5891 | else |
wolfSSL | 0:9d17e4342598 | 5892 | return SendBuffered(ssl); |
wolfSSL | 0:9d17e4342598 | 5893 | } |
wolfSSL | 0:9d17e4342598 | 5894 | #endif /* !NO_CERTS */ |
wolfSSL | 0:9d17e4342598 | 5895 | |
wolfSSL | 0:9d17e4342598 | 5896 | |
wolfSSL | 0:9d17e4342598 | 5897 | int SendData(CYASSL* ssl, const void* data, int sz) |
wolfSSL | 0:9d17e4342598 | 5898 | { |
wolfSSL | 0:9d17e4342598 | 5899 | int sent = 0, /* plainText size */ |
wolfSSL | 0:9d17e4342598 | 5900 | sendSz, |
wolfSSL | 0:9d17e4342598 | 5901 | ret; |
wolfSSL | 0:9d17e4342598 | 5902 | |
wolfSSL | 0:9d17e4342598 | 5903 | if (ssl->error == WANT_WRITE) |
wolfSSL | 0:9d17e4342598 | 5904 | ssl->error = 0; |
wolfSSL | 0:9d17e4342598 | 5905 | |
wolfSSL | 0:9d17e4342598 | 5906 | if (ssl->options.handShakeState != HANDSHAKE_DONE) { |
wolfSSL | 0:9d17e4342598 | 5907 | int err; |
wolfSSL | 0:9d17e4342598 | 5908 | CYASSL_MSG("handshake not complete, trying to finish"); |
wolfSSL | 0:9d17e4342598 | 5909 | if ( (err = CyaSSL_negotiate(ssl)) != SSL_SUCCESS) |
wolfSSL | 0:9d17e4342598 | 5910 | return err; |
wolfSSL | 0:9d17e4342598 | 5911 | } |
wolfSSL | 0:9d17e4342598 | 5912 | |
wolfSSL | 0:9d17e4342598 | 5913 | /* last time system socket output buffer was full, try again to send */ |
wolfSSL | 0:9d17e4342598 | 5914 | if (ssl->buffers.outputBuffer.length > 0) { |
wolfSSL | 0:9d17e4342598 | 5915 | CYASSL_MSG("output buffer was full, trying to send again"); |
wolfSSL | 0:9d17e4342598 | 5916 | if ( (ssl->error = SendBuffered(ssl)) < 0) { |
wolfSSL | 0:9d17e4342598 | 5917 | CYASSL_ERROR(ssl->error); |
wolfSSL | 0:9d17e4342598 | 5918 | if (ssl->error == SOCKET_ERROR_E && ssl->options.connReset) |
wolfSSL | 0:9d17e4342598 | 5919 | return 0; /* peer reset */ |
wolfSSL | 0:9d17e4342598 | 5920 | return ssl->error; |
wolfSSL | 0:9d17e4342598 | 5921 | } |
wolfSSL | 0:9d17e4342598 | 5922 | else { |
wolfSSL | 0:9d17e4342598 | 5923 | /* advance sent to previous sent + plain size just sent */ |
wolfSSL | 0:9d17e4342598 | 5924 | sent = ssl->buffers.prevSent + ssl->buffers.plainSz; |
wolfSSL | 0:9d17e4342598 | 5925 | CYASSL_MSG("sent write buffered data"); |
wolfSSL | 0:9d17e4342598 | 5926 | } |
wolfSSL | 0:9d17e4342598 | 5927 | } |
wolfSSL | 0:9d17e4342598 | 5928 | |
wolfSSL | 0:9d17e4342598 | 5929 | for (;;) { |
wolfSSL | 0:9d17e4342598 | 5930 | #ifdef HAVE_MAX_FRAGMENT |
wolfSSL | 0:9d17e4342598 | 5931 | int len = min(sz - sent, min(ssl->max_fragment, OUTPUT_RECORD_SIZE)); |
wolfSSL | 0:9d17e4342598 | 5932 | #else |
wolfSSL | 0:9d17e4342598 | 5933 | int len = min(sz - sent, OUTPUT_RECORD_SIZE); |
wolfSSL | 0:9d17e4342598 | 5934 | #endif |
wolfSSL | 0:9d17e4342598 | 5935 | byte* out; |
wolfSSL | 0:9d17e4342598 | 5936 | byte* sendBuffer = (byte*)data + sent; /* may switch on comp */ |
wolfSSL | 0:9d17e4342598 | 5937 | int buffSz = len; /* may switch on comp */ |
wolfSSL | 0:9d17e4342598 | 5938 | #ifdef HAVE_LIBZ |
wolfSSL | 0:9d17e4342598 | 5939 | byte comp[MAX_RECORD_SIZE + MAX_COMP_EXTRA]; |
wolfSSL | 0:9d17e4342598 | 5940 | #endif |
wolfSSL | 0:9d17e4342598 | 5941 | |
wolfSSL | 0:9d17e4342598 | 5942 | if (sent == sz) break; |
wolfSSL | 0:9d17e4342598 | 5943 | |
wolfSSL | 0:9d17e4342598 | 5944 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 5945 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 5946 | len = min(len, MAX_UDP_SIZE); |
wolfSSL | 0:9d17e4342598 | 5947 | buffSz = len; |
wolfSSL | 0:9d17e4342598 | 5948 | } |
wolfSSL | 0:9d17e4342598 | 5949 | #endif |
wolfSSL | 0:9d17e4342598 | 5950 | |
wolfSSL | 0:9d17e4342598 | 5951 | /* check for available size */ |
wolfSSL | 0:9d17e4342598 | 5952 | if ((ret = CheckAvailableSize(ssl, len + COMP_EXTRA + |
wolfSSL | 0:9d17e4342598 | 5953 | MAX_MSG_EXTRA)) != 0) |
wolfSSL | 0:9d17e4342598 | 5954 | return ssl->error = ret; |
wolfSSL | 0:9d17e4342598 | 5955 | |
wolfSSL | 0:9d17e4342598 | 5956 | /* get ouput buffer */ |
wolfSSL | 0:9d17e4342598 | 5957 | out = ssl->buffers.outputBuffer.buffer + |
wolfSSL | 0:9d17e4342598 | 5958 | ssl->buffers.outputBuffer.length; |
wolfSSL | 0:9d17e4342598 | 5959 | |
wolfSSL | 0:9d17e4342598 | 5960 | #ifdef HAVE_LIBZ |
wolfSSL | 0:9d17e4342598 | 5961 | if (ssl->options.usingCompression) { |
wolfSSL | 0:9d17e4342598 | 5962 | buffSz = myCompress(ssl, sendBuffer, buffSz, comp, sizeof(comp)); |
wolfSSL | 0:9d17e4342598 | 5963 | if (buffSz < 0) { |
wolfSSL | 0:9d17e4342598 | 5964 | return buffSz; |
wolfSSL | 0:9d17e4342598 | 5965 | } |
wolfSSL | 0:9d17e4342598 | 5966 | sendBuffer = comp; |
wolfSSL | 0:9d17e4342598 | 5967 | } |
wolfSSL | 0:9d17e4342598 | 5968 | #endif |
wolfSSL | 0:9d17e4342598 | 5969 | sendSz = BuildMessage(ssl, out, sendBuffer, buffSz, |
wolfSSL | 0:9d17e4342598 | 5970 | application_data); |
wolfSSL | 0:9d17e4342598 | 5971 | |
wolfSSL | 0:9d17e4342598 | 5972 | ssl->buffers.outputBuffer.length += sendSz; |
wolfSSL | 0:9d17e4342598 | 5973 | |
wolfSSL | 0:9d17e4342598 | 5974 | if ( (ret = SendBuffered(ssl)) < 0) { |
wolfSSL | 0:9d17e4342598 | 5975 | CYASSL_ERROR(ret); |
wolfSSL | 0:9d17e4342598 | 5976 | /* store for next call if WANT_WRITE or user embedSend() that |
wolfSSL | 0:9d17e4342598 | 5977 | doesn't present like WANT_WRITE */ |
wolfSSL | 0:9d17e4342598 | 5978 | ssl->buffers.plainSz = len; |
wolfSSL | 0:9d17e4342598 | 5979 | ssl->buffers.prevSent = sent; |
wolfSSL | 0:9d17e4342598 | 5980 | if (ret == SOCKET_ERROR_E && ssl->options.connReset) |
wolfSSL | 0:9d17e4342598 | 5981 | return 0; /* peer reset */ |
wolfSSL | 0:9d17e4342598 | 5982 | return ssl->error = ret; |
wolfSSL | 0:9d17e4342598 | 5983 | } |
wolfSSL | 0:9d17e4342598 | 5984 | |
wolfSSL | 0:9d17e4342598 | 5985 | sent += len; |
wolfSSL | 0:9d17e4342598 | 5986 | |
wolfSSL | 0:9d17e4342598 | 5987 | /* only one message per attempt */ |
wolfSSL | 0:9d17e4342598 | 5988 | if (ssl->options.partialWrite == 1) { |
wolfSSL | 0:9d17e4342598 | 5989 | CYASSL_MSG("Paritial Write on, only sending one record"); |
wolfSSL | 0:9d17e4342598 | 5990 | break; |
wolfSSL | 0:9d17e4342598 | 5991 | } |
wolfSSL | 0:9d17e4342598 | 5992 | } |
wolfSSL | 0:9d17e4342598 | 5993 | |
wolfSSL | 0:9d17e4342598 | 5994 | return sent; |
wolfSSL | 0:9d17e4342598 | 5995 | } |
wolfSSL | 0:9d17e4342598 | 5996 | |
wolfSSL | 0:9d17e4342598 | 5997 | /* process input data */ |
wolfSSL | 0:9d17e4342598 | 5998 | int ReceiveData(CYASSL* ssl, byte* output, int sz, int peek) |
wolfSSL | 0:9d17e4342598 | 5999 | { |
wolfSSL | 0:9d17e4342598 | 6000 | int size; |
wolfSSL | 0:9d17e4342598 | 6001 | |
wolfSSL | 0:9d17e4342598 | 6002 | CYASSL_ENTER("ReceiveData()"); |
wolfSSL | 0:9d17e4342598 | 6003 | |
wolfSSL | 0:9d17e4342598 | 6004 | if (ssl->error == WANT_READ) |
wolfSSL | 0:9d17e4342598 | 6005 | ssl->error = 0; |
wolfSSL | 0:9d17e4342598 | 6006 | |
wolfSSL | 0:9d17e4342598 | 6007 | if (ssl->error != 0 && ssl->error != WANT_WRITE) { |
wolfSSL | 0:9d17e4342598 | 6008 | CYASSL_MSG("User calling CyaSSL_read in error state, not allowed"); |
wolfSSL | 0:9d17e4342598 | 6009 | return ssl->error; |
wolfSSL | 0:9d17e4342598 | 6010 | } |
wolfSSL | 0:9d17e4342598 | 6011 | |
wolfSSL | 0:9d17e4342598 | 6012 | if (ssl->options.handShakeState != HANDSHAKE_DONE) { |
wolfSSL | 0:9d17e4342598 | 6013 | int err; |
wolfSSL | 0:9d17e4342598 | 6014 | CYASSL_MSG("Handshake not complete, trying to finish"); |
wolfSSL | 0:9d17e4342598 | 6015 | if ( (err = CyaSSL_negotiate(ssl)) != SSL_SUCCESS) |
wolfSSL | 0:9d17e4342598 | 6016 | return err; |
wolfSSL | 0:9d17e4342598 | 6017 | } |
wolfSSL | 0:9d17e4342598 | 6018 | |
wolfSSL | 0:9d17e4342598 | 6019 | while (ssl->buffers.clearOutputBuffer.length == 0) |
wolfSSL | 0:9d17e4342598 | 6020 | if ( (ssl->error = ProcessReply(ssl)) < 0) { |
wolfSSL | 0:9d17e4342598 | 6021 | CYASSL_ERROR(ssl->error); |
wolfSSL | 0:9d17e4342598 | 6022 | if (ssl->error == ZERO_RETURN) { |
wolfSSL | 0:9d17e4342598 | 6023 | CYASSL_MSG("Zero return, no more data coming"); |
wolfSSL | 0:9d17e4342598 | 6024 | return 0; /* no more data coming */ |
wolfSSL | 0:9d17e4342598 | 6025 | } |
wolfSSL | 0:9d17e4342598 | 6026 | if (ssl->error == SOCKET_ERROR_E) { |
wolfSSL | 0:9d17e4342598 | 6027 | if (ssl->options.connReset || ssl->options.isClosed) { |
wolfSSL | 0:9d17e4342598 | 6028 | CYASSL_MSG("Peer reset or closed, connection done"); |
wolfSSL | 0:9d17e4342598 | 6029 | return 0; /* peer reset or closed */ |
wolfSSL | 0:9d17e4342598 | 6030 | } |
wolfSSL | 0:9d17e4342598 | 6031 | } |
wolfSSL | 0:9d17e4342598 | 6032 | return ssl->error; |
wolfSSL | 0:9d17e4342598 | 6033 | } |
wolfSSL | 0:9d17e4342598 | 6034 | |
wolfSSL | 0:9d17e4342598 | 6035 | if (sz < (int)ssl->buffers.clearOutputBuffer.length) |
wolfSSL | 0:9d17e4342598 | 6036 | size = sz; |
wolfSSL | 0:9d17e4342598 | 6037 | else |
wolfSSL | 0:9d17e4342598 | 6038 | size = ssl->buffers.clearOutputBuffer.length; |
wolfSSL | 0:9d17e4342598 | 6039 | |
wolfSSL | 0:9d17e4342598 | 6040 | XMEMCPY(output, ssl->buffers.clearOutputBuffer.buffer, size); |
wolfSSL | 0:9d17e4342598 | 6041 | |
wolfSSL | 0:9d17e4342598 | 6042 | if (peek == 0) { |
wolfSSL | 0:9d17e4342598 | 6043 | ssl->buffers.clearOutputBuffer.length -= size; |
wolfSSL | 0:9d17e4342598 | 6044 | ssl->buffers.clearOutputBuffer.buffer += size; |
wolfSSL | 0:9d17e4342598 | 6045 | } |
wolfSSL | 0:9d17e4342598 | 6046 | |
wolfSSL | 0:9d17e4342598 | 6047 | if (ssl->buffers.clearOutputBuffer.length == 0 && |
wolfSSL | 0:9d17e4342598 | 6048 | ssl->buffers.inputBuffer.dynamicFlag) |
wolfSSL | 0:9d17e4342598 | 6049 | ShrinkInputBuffer(ssl, NO_FORCED_FREE); |
wolfSSL | 0:9d17e4342598 | 6050 | |
wolfSSL | 0:9d17e4342598 | 6051 | CYASSL_LEAVE("ReceiveData()", size); |
wolfSSL | 0:9d17e4342598 | 6052 | return size; |
wolfSSL | 0:9d17e4342598 | 6053 | } |
wolfSSL | 0:9d17e4342598 | 6054 | |
wolfSSL | 0:9d17e4342598 | 6055 | |
wolfSSL | 0:9d17e4342598 | 6056 | /* send alert message */ |
wolfSSL | 0:9d17e4342598 | 6057 | int SendAlert(CYASSL* ssl, int severity, int type) |
wolfSSL | 0:9d17e4342598 | 6058 | { |
wolfSSL | 0:9d17e4342598 | 6059 | byte input[ALERT_SIZE]; |
wolfSSL | 0:9d17e4342598 | 6060 | byte *output; |
wolfSSL | 0:9d17e4342598 | 6061 | int sendSz; |
wolfSSL | 0:9d17e4342598 | 6062 | int ret; |
wolfSSL | 0:9d17e4342598 | 6063 | int dtlsExtra = 0; |
wolfSSL | 0:9d17e4342598 | 6064 | |
wolfSSL | 0:9d17e4342598 | 6065 | /* if sendalert is called again for nonbloking */ |
wolfSSL | 0:9d17e4342598 | 6066 | if (ssl->options.sendAlertState != 0) { |
wolfSSL | 0:9d17e4342598 | 6067 | ret = SendBuffered(ssl); |
wolfSSL | 0:9d17e4342598 | 6068 | if (ret == 0) |
wolfSSL | 0:9d17e4342598 | 6069 | ssl->options.sendAlertState = 0; |
wolfSSL | 0:9d17e4342598 | 6070 | return ret; |
wolfSSL | 0:9d17e4342598 | 6071 | } |
wolfSSL | 0:9d17e4342598 | 6072 | |
wolfSSL | 0:9d17e4342598 | 6073 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 6074 | if (ssl->options.dtls) |
wolfSSL | 0:9d17e4342598 | 6075 | dtlsExtra = DTLS_RECORD_EXTRA; |
wolfSSL | 0:9d17e4342598 | 6076 | #endif |
wolfSSL | 0:9d17e4342598 | 6077 | |
wolfSSL | 0:9d17e4342598 | 6078 | /* check for available size */ |
wolfSSL | 0:9d17e4342598 | 6079 | if ((ret = CheckAvailableSize(ssl, |
wolfSSL | 0:9d17e4342598 | 6080 | ALERT_SIZE + MAX_MSG_EXTRA + dtlsExtra)) != 0) |
wolfSSL | 0:9d17e4342598 | 6081 | return ret; |
wolfSSL | 0:9d17e4342598 | 6082 | |
wolfSSL | 0:9d17e4342598 | 6083 | /* get ouput buffer */ |
wolfSSL | 0:9d17e4342598 | 6084 | output = ssl->buffers.outputBuffer.buffer + |
wolfSSL | 0:9d17e4342598 | 6085 | ssl->buffers.outputBuffer.length; |
wolfSSL | 0:9d17e4342598 | 6086 | |
wolfSSL | 0:9d17e4342598 | 6087 | input[0] = (byte)severity; |
wolfSSL | 0:9d17e4342598 | 6088 | input[1] = (byte)type; |
wolfSSL | 0:9d17e4342598 | 6089 | ssl->alert_history.last_tx.code = type; |
wolfSSL | 0:9d17e4342598 | 6090 | ssl->alert_history.last_tx.level = severity; |
wolfSSL | 0:9d17e4342598 | 6091 | if (severity == alert_fatal) { |
wolfSSL | 0:9d17e4342598 | 6092 | ssl->options.isClosed = 1; /* Don't send close_notify */ |
wolfSSL | 0:9d17e4342598 | 6093 | } |
wolfSSL | 0:9d17e4342598 | 6094 | |
wolfSSL | 0:9d17e4342598 | 6095 | /* only send encrypted alert if handshake actually complete, otherwise |
wolfSSL | 0:9d17e4342598 | 6096 | other side may not be able to handle it */ |
wolfSSL | 0:9d17e4342598 | 6097 | if (ssl->keys.encryptionOn && ssl->options.handShakeState == HANDSHAKE_DONE) |
wolfSSL | 0:9d17e4342598 | 6098 | sendSz = BuildMessage(ssl, output, input, ALERT_SIZE, alert); |
wolfSSL | 0:9d17e4342598 | 6099 | else { |
wolfSSL | 0:9d17e4342598 | 6100 | |
wolfSSL | 0:9d17e4342598 | 6101 | AddRecordHeader(output, ALERT_SIZE, alert, ssl); |
wolfSSL | 0:9d17e4342598 | 6102 | output += RECORD_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 6103 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 6104 | if (ssl->options.dtls) |
wolfSSL | 0:9d17e4342598 | 6105 | output += DTLS_RECORD_EXTRA; |
wolfSSL | 0:9d17e4342598 | 6106 | #endif |
wolfSSL | 0:9d17e4342598 | 6107 | XMEMCPY(output, input, ALERT_SIZE); |
wolfSSL | 0:9d17e4342598 | 6108 | |
wolfSSL | 0:9d17e4342598 | 6109 | sendSz = RECORD_HEADER_SZ + ALERT_SIZE; |
wolfSSL | 0:9d17e4342598 | 6110 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 6111 | if (ssl->options.dtls) |
wolfSSL | 0:9d17e4342598 | 6112 | sendSz += DTLS_RECORD_EXTRA; |
wolfSSL | 0:9d17e4342598 | 6113 | #endif |
wolfSSL | 0:9d17e4342598 | 6114 | } |
wolfSSL | 0:9d17e4342598 | 6115 | |
wolfSSL | 0:9d17e4342598 | 6116 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 6117 | if (ssl->hsInfoOn) |
wolfSSL | 0:9d17e4342598 | 6118 | AddPacketName("Alert", &ssl->handShakeInfo); |
wolfSSL | 0:9d17e4342598 | 6119 | if (ssl->toInfoOn) |
wolfSSL | 0:9d17e4342598 | 6120 | AddPacketInfo("Alert", &ssl->timeoutInfo, output, sendSz,ssl->heap); |
wolfSSL | 0:9d17e4342598 | 6121 | #endif |
wolfSSL | 0:9d17e4342598 | 6122 | |
wolfSSL | 0:9d17e4342598 | 6123 | ssl->buffers.outputBuffer.length += sendSz; |
wolfSSL | 0:9d17e4342598 | 6124 | ssl->options.sendAlertState = 1; |
wolfSSL | 0:9d17e4342598 | 6125 | |
wolfSSL | 0:9d17e4342598 | 6126 | return SendBuffered(ssl); |
wolfSSL | 0:9d17e4342598 | 6127 | } |
wolfSSL | 0:9d17e4342598 | 6128 | |
wolfSSL | 0:9d17e4342598 | 6129 | |
wolfSSL | 0:9d17e4342598 | 6130 | |
wolfSSL | 0:9d17e4342598 | 6131 | void SetErrorString(int error, char* str) |
wolfSSL | 0:9d17e4342598 | 6132 | { |
wolfSSL | 0:9d17e4342598 | 6133 | const int max = CYASSL_MAX_ERROR_SZ; /* shorthand */ |
wolfSSL | 0:9d17e4342598 | 6134 | |
wolfSSL | 0:9d17e4342598 | 6135 | #ifdef NO_ERROR_STRINGS |
wolfSSL | 0:9d17e4342598 | 6136 | |
wolfSSL | 0:9d17e4342598 | 6137 | (void)error; |
wolfSSL | 0:9d17e4342598 | 6138 | XSTRNCPY(str, "no support for error strings built in", max); |
wolfSSL | 0:9d17e4342598 | 6139 | |
wolfSSL | 0:9d17e4342598 | 6140 | #else |
wolfSSL | 0:9d17e4342598 | 6141 | |
wolfSSL | 0:9d17e4342598 | 6142 | /* pass to CTaoCrypt */ |
wolfSSL | 0:9d17e4342598 | 6143 | if (error < MAX_CODE_E && error > MIN_CODE_E) { |
wolfSSL | 0:9d17e4342598 | 6144 | CTaoCryptErrorString(error, str); |
wolfSSL | 0:9d17e4342598 | 6145 | return; |
wolfSSL | 0:9d17e4342598 | 6146 | } |
wolfSSL | 0:9d17e4342598 | 6147 | |
wolfSSL | 0:9d17e4342598 | 6148 | switch (error) { |
wolfSSL | 0:9d17e4342598 | 6149 | |
wolfSSL | 0:9d17e4342598 | 6150 | case UNSUPPORTED_SUITE : |
wolfSSL | 0:9d17e4342598 | 6151 | XSTRNCPY(str, "unsupported cipher suite", max); |
wolfSSL | 0:9d17e4342598 | 6152 | break; |
wolfSSL | 0:9d17e4342598 | 6153 | |
wolfSSL | 0:9d17e4342598 | 6154 | case INPUT_CASE_ERROR : |
wolfSSL | 0:9d17e4342598 | 6155 | XSTRNCPY(str, "input state error", max); |
wolfSSL | 0:9d17e4342598 | 6156 | break; |
wolfSSL | 0:9d17e4342598 | 6157 | |
wolfSSL | 0:9d17e4342598 | 6158 | case PREFIX_ERROR : |
wolfSSL | 0:9d17e4342598 | 6159 | XSTRNCPY(str, "bad index to key rounds", max); |
wolfSSL | 0:9d17e4342598 | 6160 | break; |
wolfSSL | 0:9d17e4342598 | 6161 | |
wolfSSL | 0:9d17e4342598 | 6162 | case MEMORY_ERROR : |
wolfSSL | 0:9d17e4342598 | 6163 | XSTRNCPY(str, "out of memory", max); |
wolfSSL | 0:9d17e4342598 | 6164 | break; |
wolfSSL | 0:9d17e4342598 | 6165 | |
wolfSSL | 0:9d17e4342598 | 6166 | case VERIFY_FINISHED_ERROR : |
wolfSSL | 0:9d17e4342598 | 6167 | XSTRNCPY(str, "verify problem on finished", max); |
wolfSSL | 0:9d17e4342598 | 6168 | break; |
wolfSSL | 0:9d17e4342598 | 6169 | |
wolfSSL | 0:9d17e4342598 | 6170 | case VERIFY_MAC_ERROR : |
wolfSSL | 0:9d17e4342598 | 6171 | XSTRNCPY(str, "verify mac problem", max); |
wolfSSL | 0:9d17e4342598 | 6172 | break; |
wolfSSL | 0:9d17e4342598 | 6173 | |
wolfSSL | 0:9d17e4342598 | 6174 | case PARSE_ERROR : |
wolfSSL | 0:9d17e4342598 | 6175 | XSTRNCPY(str, "parse error on header", max); |
wolfSSL | 0:9d17e4342598 | 6176 | break; |
wolfSSL | 0:9d17e4342598 | 6177 | |
wolfSSL | 0:9d17e4342598 | 6178 | case SIDE_ERROR : |
wolfSSL | 0:9d17e4342598 | 6179 | XSTRNCPY(str, "wrong client/server type", max); |
wolfSSL | 0:9d17e4342598 | 6180 | break; |
wolfSSL | 0:9d17e4342598 | 6181 | |
wolfSSL | 0:9d17e4342598 | 6182 | case NO_PEER_CERT : |
wolfSSL | 0:9d17e4342598 | 6183 | XSTRNCPY(str, "peer didn't send cert", max); |
wolfSSL | 0:9d17e4342598 | 6184 | break; |
wolfSSL | 0:9d17e4342598 | 6185 | |
wolfSSL | 0:9d17e4342598 | 6186 | case UNKNOWN_HANDSHAKE_TYPE : |
wolfSSL | 0:9d17e4342598 | 6187 | XSTRNCPY(str, "weird handshake type", max); |
wolfSSL | 0:9d17e4342598 | 6188 | break; |
wolfSSL | 0:9d17e4342598 | 6189 | |
wolfSSL | 0:9d17e4342598 | 6190 | case SOCKET_ERROR_E : |
wolfSSL | 0:9d17e4342598 | 6191 | XSTRNCPY(str, "error state on socket", max); |
wolfSSL | 0:9d17e4342598 | 6192 | break; |
wolfSSL | 0:9d17e4342598 | 6193 | |
wolfSSL | 0:9d17e4342598 | 6194 | case SOCKET_NODATA : |
wolfSSL | 0:9d17e4342598 | 6195 | XSTRNCPY(str, "expected data, not there", max); |
wolfSSL | 0:9d17e4342598 | 6196 | break; |
wolfSSL | 0:9d17e4342598 | 6197 | |
wolfSSL | 0:9d17e4342598 | 6198 | case INCOMPLETE_DATA : |
wolfSSL | 0:9d17e4342598 | 6199 | XSTRNCPY(str, "don't have enough data to complete task", max); |
wolfSSL | 0:9d17e4342598 | 6200 | break; |
wolfSSL | 0:9d17e4342598 | 6201 | |
wolfSSL | 0:9d17e4342598 | 6202 | case UNKNOWN_RECORD_TYPE : |
wolfSSL | 0:9d17e4342598 | 6203 | XSTRNCPY(str, "unknown type in record hdr", max); |
wolfSSL | 0:9d17e4342598 | 6204 | break; |
wolfSSL | 0:9d17e4342598 | 6205 | |
wolfSSL | 0:9d17e4342598 | 6206 | case DECRYPT_ERROR : |
wolfSSL | 0:9d17e4342598 | 6207 | XSTRNCPY(str, "error during decryption", max); |
wolfSSL | 0:9d17e4342598 | 6208 | break; |
wolfSSL | 0:9d17e4342598 | 6209 | |
wolfSSL | 0:9d17e4342598 | 6210 | case FATAL_ERROR : |
wolfSSL | 0:9d17e4342598 | 6211 | XSTRNCPY(str, "revcd alert fatal error", max); |
wolfSSL | 0:9d17e4342598 | 6212 | break; |
wolfSSL | 0:9d17e4342598 | 6213 | |
wolfSSL | 0:9d17e4342598 | 6214 | case ENCRYPT_ERROR : |
wolfSSL | 0:9d17e4342598 | 6215 | XSTRNCPY(str, "error during encryption", max); |
wolfSSL | 0:9d17e4342598 | 6216 | break; |
wolfSSL | 0:9d17e4342598 | 6217 | |
wolfSSL | 0:9d17e4342598 | 6218 | case FREAD_ERROR : |
wolfSSL | 0:9d17e4342598 | 6219 | XSTRNCPY(str, "fread problem", max); |
wolfSSL | 0:9d17e4342598 | 6220 | break; |
wolfSSL | 0:9d17e4342598 | 6221 | |
wolfSSL | 0:9d17e4342598 | 6222 | case NO_PEER_KEY : |
wolfSSL | 0:9d17e4342598 | 6223 | XSTRNCPY(str, "need peer's key", max); |
wolfSSL | 0:9d17e4342598 | 6224 | break; |
wolfSSL | 0:9d17e4342598 | 6225 | |
wolfSSL | 0:9d17e4342598 | 6226 | case NO_PRIVATE_KEY : |
wolfSSL | 0:9d17e4342598 | 6227 | XSTRNCPY(str, "need the private key", max); |
wolfSSL | 0:9d17e4342598 | 6228 | break; |
wolfSSL | 0:9d17e4342598 | 6229 | |
wolfSSL | 0:9d17e4342598 | 6230 | case NO_DH_PARAMS : |
wolfSSL | 0:9d17e4342598 | 6231 | XSTRNCPY(str, "server missing DH params", max); |
wolfSSL | 0:9d17e4342598 | 6232 | break; |
wolfSSL | 0:9d17e4342598 | 6233 | |
wolfSSL | 0:9d17e4342598 | 6234 | case RSA_PRIVATE_ERROR : |
wolfSSL | 0:9d17e4342598 | 6235 | XSTRNCPY(str, "error during rsa priv op", max); |
wolfSSL | 0:9d17e4342598 | 6236 | break; |
wolfSSL | 0:9d17e4342598 | 6237 | |
wolfSSL | 0:9d17e4342598 | 6238 | case MATCH_SUITE_ERROR : |
wolfSSL | 0:9d17e4342598 | 6239 | XSTRNCPY(str, "can't match cipher suite", max); |
wolfSSL | 0:9d17e4342598 | 6240 | break; |
wolfSSL | 0:9d17e4342598 | 6241 | |
wolfSSL | 0:9d17e4342598 | 6242 | case BUILD_MSG_ERROR : |
wolfSSL | 0:9d17e4342598 | 6243 | XSTRNCPY(str, "build message failure", max); |
wolfSSL | 0:9d17e4342598 | 6244 | break; |
wolfSSL | 0:9d17e4342598 | 6245 | |
wolfSSL | 0:9d17e4342598 | 6246 | case BAD_HELLO : |
wolfSSL | 0:9d17e4342598 | 6247 | XSTRNCPY(str, "client hello malformed", max); |
wolfSSL | 0:9d17e4342598 | 6248 | break; |
wolfSSL | 0:9d17e4342598 | 6249 | |
wolfSSL | 0:9d17e4342598 | 6250 | case DOMAIN_NAME_MISMATCH : |
wolfSSL | 0:9d17e4342598 | 6251 | XSTRNCPY(str, "peer subject name mismatch", max); |
wolfSSL | 0:9d17e4342598 | 6252 | break; |
wolfSSL | 0:9d17e4342598 | 6253 | |
wolfSSL | 0:9d17e4342598 | 6254 | case WANT_READ : |
wolfSSL | 0:9d17e4342598 | 6255 | case SSL_ERROR_WANT_READ : |
wolfSSL | 0:9d17e4342598 | 6256 | XSTRNCPY(str, "non-blocking socket wants data to be read", max); |
wolfSSL | 0:9d17e4342598 | 6257 | break; |
wolfSSL | 0:9d17e4342598 | 6258 | |
wolfSSL | 0:9d17e4342598 | 6259 | case NOT_READY_ERROR : |
wolfSSL | 0:9d17e4342598 | 6260 | XSTRNCPY(str, "handshake layer not ready yet, complete first", max); |
wolfSSL | 0:9d17e4342598 | 6261 | break; |
wolfSSL | 0:9d17e4342598 | 6262 | |
wolfSSL | 0:9d17e4342598 | 6263 | case PMS_VERSION_ERROR : |
wolfSSL | 0:9d17e4342598 | 6264 | XSTRNCPY(str, "premaster secret version mismatch error", max); |
wolfSSL | 0:9d17e4342598 | 6265 | break; |
wolfSSL | 0:9d17e4342598 | 6266 | |
wolfSSL | 0:9d17e4342598 | 6267 | case VERSION_ERROR : |
wolfSSL | 0:9d17e4342598 | 6268 | XSTRNCPY(str, "record layer version error", max); |
wolfSSL | 0:9d17e4342598 | 6269 | break; |
wolfSSL | 0:9d17e4342598 | 6270 | |
wolfSSL | 0:9d17e4342598 | 6271 | case WANT_WRITE : |
wolfSSL | 0:9d17e4342598 | 6272 | case SSL_ERROR_WANT_WRITE : |
wolfSSL | 0:9d17e4342598 | 6273 | XSTRNCPY(str, "non-blocking socket write buffer full", max); |
wolfSSL | 0:9d17e4342598 | 6274 | break; |
wolfSSL | 0:9d17e4342598 | 6275 | |
wolfSSL | 0:9d17e4342598 | 6276 | case BUFFER_ERROR : |
wolfSSL | 0:9d17e4342598 | 6277 | XSTRNCPY(str, "malformed buffer input error", max); |
wolfSSL | 0:9d17e4342598 | 6278 | break; |
wolfSSL | 0:9d17e4342598 | 6279 | |
wolfSSL | 0:9d17e4342598 | 6280 | case VERIFY_CERT_ERROR : |
wolfSSL | 0:9d17e4342598 | 6281 | XSTRNCPY(str, "verify problem on certificate", max); |
wolfSSL | 0:9d17e4342598 | 6282 | break; |
wolfSSL | 0:9d17e4342598 | 6283 | |
wolfSSL | 0:9d17e4342598 | 6284 | case VERIFY_SIGN_ERROR : |
wolfSSL | 0:9d17e4342598 | 6285 | XSTRNCPY(str, "verify problem based on signature", max); |
wolfSSL | 0:9d17e4342598 | 6286 | break; |
wolfSSL | 0:9d17e4342598 | 6287 | |
wolfSSL | 0:9d17e4342598 | 6288 | case CLIENT_ID_ERROR : |
wolfSSL | 0:9d17e4342598 | 6289 | XSTRNCPY(str, "psk client identity error", max); |
wolfSSL | 0:9d17e4342598 | 6290 | break; |
wolfSSL | 0:9d17e4342598 | 6291 | |
wolfSSL | 0:9d17e4342598 | 6292 | case SERVER_HINT_ERROR: |
wolfSSL | 0:9d17e4342598 | 6293 | XSTRNCPY(str, "psk server hint error", max); |
wolfSSL | 0:9d17e4342598 | 6294 | break; |
wolfSSL | 0:9d17e4342598 | 6295 | |
wolfSSL | 0:9d17e4342598 | 6296 | case PSK_KEY_ERROR: |
wolfSSL | 0:9d17e4342598 | 6297 | XSTRNCPY(str, "psk key callback error", max); |
wolfSSL | 0:9d17e4342598 | 6298 | break; |
wolfSSL | 0:9d17e4342598 | 6299 | |
wolfSSL | 0:9d17e4342598 | 6300 | case NTRU_KEY_ERROR: |
wolfSSL | 0:9d17e4342598 | 6301 | XSTRNCPY(str, "NTRU key error", max); |
wolfSSL | 0:9d17e4342598 | 6302 | break; |
wolfSSL | 0:9d17e4342598 | 6303 | |
wolfSSL | 0:9d17e4342598 | 6304 | case NTRU_DRBG_ERROR: |
wolfSSL | 0:9d17e4342598 | 6305 | XSTRNCPY(str, "NTRU drbg error", max); |
wolfSSL | 0:9d17e4342598 | 6306 | break; |
wolfSSL | 0:9d17e4342598 | 6307 | |
wolfSSL | 0:9d17e4342598 | 6308 | case NTRU_ENCRYPT_ERROR: |
wolfSSL | 0:9d17e4342598 | 6309 | XSTRNCPY(str, "NTRU encrypt error", max); |
wolfSSL | 0:9d17e4342598 | 6310 | break; |
wolfSSL | 0:9d17e4342598 | 6311 | |
wolfSSL | 0:9d17e4342598 | 6312 | case NTRU_DECRYPT_ERROR: |
wolfSSL | 0:9d17e4342598 | 6313 | XSTRNCPY(str, "NTRU decrypt error", max); |
wolfSSL | 0:9d17e4342598 | 6314 | break; |
wolfSSL | 0:9d17e4342598 | 6315 | |
wolfSSL | 0:9d17e4342598 | 6316 | case ZLIB_INIT_ERROR: |
wolfSSL | 0:9d17e4342598 | 6317 | XSTRNCPY(str, "zlib init error", max); |
wolfSSL | 0:9d17e4342598 | 6318 | break; |
wolfSSL | 0:9d17e4342598 | 6319 | |
wolfSSL | 0:9d17e4342598 | 6320 | case ZLIB_COMPRESS_ERROR: |
wolfSSL | 0:9d17e4342598 | 6321 | XSTRNCPY(str, "zlib compress error", max); |
wolfSSL | 0:9d17e4342598 | 6322 | break; |
wolfSSL | 0:9d17e4342598 | 6323 | |
wolfSSL | 0:9d17e4342598 | 6324 | case ZLIB_DECOMPRESS_ERROR: |
wolfSSL | 0:9d17e4342598 | 6325 | XSTRNCPY(str, "zlib decompress error", max); |
wolfSSL | 0:9d17e4342598 | 6326 | break; |
wolfSSL | 0:9d17e4342598 | 6327 | |
wolfSSL | 0:9d17e4342598 | 6328 | case GETTIME_ERROR: |
wolfSSL | 0:9d17e4342598 | 6329 | XSTRNCPY(str, "gettimeofday() error", max); |
wolfSSL | 0:9d17e4342598 | 6330 | break; |
wolfSSL | 0:9d17e4342598 | 6331 | |
wolfSSL | 0:9d17e4342598 | 6332 | case GETITIMER_ERROR: |
wolfSSL | 0:9d17e4342598 | 6333 | XSTRNCPY(str, "getitimer() error", max); |
wolfSSL | 0:9d17e4342598 | 6334 | break; |
wolfSSL | 0:9d17e4342598 | 6335 | |
wolfSSL | 0:9d17e4342598 | 6336 | case SIGACT_ERROR: |
wolfSSL | 0:9d17e4342598 | 6337 | XSTRNCPY(str, "sigaction() error", max); |
wolfSSL | 0:9d17e4342598 | 6338 | break; |
wolfSSL | 0:9d17e4342598 | 6339 | |
wolfSSL | 0:9d17e4342598 | 6340 | case SETITIMER_ERROR: |
wolfSSL | 0:9d17e4342598 | 6341 | XSTRNCPY(str, "setitimer() error", max); |
wolfSSL | 0:9d17e4342598 | 6342 | break; |
wolfSSL | 0:9d17e4342598 | 6343 | |
wolfSSL | 0:9d17e4342598 | 6344 | case LENGTH_ERROR: |
wolfSSL | 0:9d17e4342598 | 6345 | XSTRNCPY(str, "record layer length error", max); |
wolfSSL | 0:9d17e4342598 | 6346 | break; |
wolfSSL | 0:9d17e4342598 | 6347 | |
wolfSSL | 0:9d17e4342598 | 6348 | case PEER_KEY_ERROR: |
wolfSSL | 0:9d17e4342598 | 6349 | XSTRNCPY(str, "cant decode peer key", max); |
wolfSSL | 0:9d17e4342598 | 6350 | break; |
wolfSSL | 0:9d17e4342598 | 6351 | |
wolfSSL | 0:9d17e4342598 | 6352 | case ZERO_RETURN: |
wolfSSL | 0:9d17e4342598 | 6353 | case SSL_ERROR_ZERO_RETURN: |
wolfSSL | 0:9d17e4342598 | 6354 | XSTRNCPY(str, "peer sent close notify alert", max); |
wolfSSL | 0:9d17e4342598 | 6355 | break; |
wolfSSL | 0:9d17e4342598 | 6356 | |
wolfSSL | 0:9d17e4342598 | 6357 | case ECC_CURVETYPE_ERROR: |
wolfSSL | 0:9d17e4342598 | 6358 | XSTRNCPY(str, "Bad ECC Curve Type or unsupported", max); |
wolfSSL | 0:9d17e4342598 | 6359 | break; |
wolfSSL | 0:9d17e4342598 | 6360 | |
wolfSSL | 0:9d17e4342598 | 6361 | case ECC_CURVE_ERROR: |
wolfSSL | 0:9d17e4342598 | 6362 | XSTRNCPY(str, "Bad ECC Curve or unsupported", max); |
wolfSSL | 0:9d17e4342598 | 6363 | break; |
wolfSSL | 0:9d17e4342598 | 6364 | |
wolfSSL | 0:9d17e4342598 | 6365 | case ECC_PEERKEY_ERROR: |
wolfSSL | 0:9d17e4342598 | 6366 | XSTRNCPY(str, "Bad ECC Peer Key", max); |
wolfSSL | 0:9d17e4342598 | 6367 | break; |
wolfSSL | 0:9d17e4342598 | 6368 | |
wolfSSL | 0:9d17e4342598 | 6369 | case ECC_MAKEKEY_ERROR: |
wolfSSL | 0:9d17e4342598 | 6370 | XSTRNCPY(str, "ECC Make Key failure", max); |
wolfSSL | 0:9d17e4342598 | 6371 | break; |
wolfSSL | 0:9d17e4342598 | 6372 | |
wolfSSL | 0:9d17e4342598 | 6373 | case ECC_EXPORT_ERROR: |
wolfSSL | 0:9d17e4342598 | 6374 | XSTRNCPY(str, "ECC Export Key failure", max); |
wolfSSL | 0:9d17e4342598 | 6375 | break; |
wolfSSL | 0:9d17e4342598 | 6376 | |
wolfSSL | 0:9d17e4342598 | 6377 | case ECC_SHARED_ERROR: |
wolfSSL | 0:9d17e4342598 | 6378 | XSTRNCPY(str, "ECC DHE shared failure", max); |
wolfSSL | 0:9d17e4342598 | 6379 | break; |
wolfSSL | 0:9d17e4342598 | 6380 | |
wolfSSL | 0:9d17e4342598 | 6381 | case NOT_CA_ERROR: |
wolfSSL | 0:9d17e4342598 | 6382 | XSTRNCPY(str, "Not a CA by basic constraint error", max); |
wolfSSL | 0:9d17e4342598 | 6383 | break; |
wolfSSL | 0:9d17e4342598 | 6384 | |
wolfSSL | 0:9d17e4342598 | 6385 | case BAD_PATH_ERROR: |
wolfSSL | 0:9d17e4342598 | 6386 | XSTRNCPY(str, "Bad path for opendir error", max); |
wolfSSL | 0:9d17e4342598 | 6387 | break; |
wolfSSL | 0:9d17e4342598 | 6388 | |
wolfSSL | 0:9d17e4342598 | 6389 | case BAD_CERT_MANAGER_ERROR: |
wolfSSL | 0:9d17e4342598 | 6390 | XSTRNCPY(str, "Bad Cert Manager error", max); |
wolfSSL | 0:9d17e4342598 | 6391 | break; |
wolfSSL | 0:9d17e4342598 | 6392 | |
wolfSSL | 0:9d17e4342598 | 6393 | case OCSP_CERT_REVOKED: |
wolfSSL | 0:9d17e4342598 | 6394 | XSTRNCPY(str, "OCSP Cert revoked", max); |
wolfSSL | 0:9d17e4342598 | 6395 | break; |
wolfSSL | 0:9d17e4342598 | 6396 | |
wolfSSL | 0:9d17e4342598 | 6397 | case CRL_CERT_REVOKED: |
wolfSSL | 0:9d17e4342598 | 6398 | XSTRNCPY(str, "CRL Cert revoked", max); |
wolfSSL | 0:9d17e4342598 | 6399 | break; |
wolfSSL | 0:9d17e4342598 | 6400 | |
wolfSSL | 0:9d17e4342598 | 6401 | case CRL_MISSING: |
wolfSSL | 0:9d17e4342598 | 6402 | XSTRNCPY(str, "CRL missing, not loaded", max); |
wolfSSL | 0:9d17e4342598 | 6403 | break; |
wolfSSL | 0:9d17e4342598 | 6404 | |
wolfSSL | 0:9d17e4342598 | 6405 | case MONITOR_RUNNING_E: |
wolfSSL | 0:9d17e4342598 | 6406 | XSTRNCPY(str, "CRL monitor already running", max); |
wolfSSL | 0:9d17e4342598 | 6407 | break; |
wolfSSL | 0:9d17e4342598 | 6408 | |
wolfSSL | 0:9d17e4342598 | 6409 | case THREAD_CREATE_E: |
wolfSSL | 0:9d17e4342598 | 6410 | XSTRNCPY(str, "Thread creation problem", max); |
wolfSSL | 0:9d17e4342598 | 6411 | break; |
wolfSSL | 0:9d17e4342598 | 6412 | |
wolfSSL | 0:9d17e4342598 | 6413 | case OCSP_NEED_URL: |
wolfSSL | 0:9d17e4342598 | 6414 | XSTRNCPY(str, "OCSP need URL", max); |
wolfSSL | 0:9d17e4342598 | 6415 | break; |
wolfSSL | 0:9d17e4342598 | 6416 | |
wolfSSL | 0:9d17e4342598 | 6417 | case OCSP_CERT_UNKNOWN: |
wolfSSL | 0:9d17e4342598 | 6418 | XSTRNCPY(str, "OCSP Cert unknown", max); |
wolfSSL | 0:9d17e4342598 | 6419 | break; |
wolfSSL | 0:9d17e4342598 | 6420 | |
wolfSSL | 0:9d17e4342598 | 6421 | case OCSP_LOOKUP_FAIL: |
wolfSSL | 0:9d17e4342598 | 6422 | XSTRNCPY(str, "OCSP Responder lookup fail", max); |
wolfSSL | 0:9d17e4342598 | 6423 | break; |
wolfSSL | 0:9d17e4342598 | 6424 | |
wolfSSL | 0:9d17e4342598 | 6425 | case MAX_CHAIN_ERROR: |
wolfSSL | 0:9d17e4342598 | 6426 | XSTRNCPY(str, "Maximum Chain Depth Exceeded", max); |
wolfSSL | 0:9d17e4342598 | 6427 | break; |
wolfSSL | 0:9d17e4342598 | 6428 | |
wolfSSL | 0:9d17e4342598 | 6429 | case COOKIE_ERROR: |
wolfSSL | 0:9d17e4342598 | 6430 | XSTRNCPY(str, "DTLS Cookie Error", max); |
wolfSSL | 0:9d17e4342598 | 6431 | break; |
wolfSSL | 0:9d17e4342598 | 6432 | |
wolfSSL | 0:9d17e4342598 | 6433 | case SEQUENCE_ERROR: |
wolfSSL | 0:9d17e4342598 | 6434 | XSTRNCPY(str, "DTLS Sequence Error", max); |
wolfSSL | 0:9d17e4342598 | 6435 | break; |
wolfSSL | 0:9d17e4342598 | 6436 | |
wolfSSL | 0:9d17e4342598 | 6437 | case SUITES_ERROR: |
wolfSSL | 0:9d17e4342598 | 6438 | XSTRNCPY(str, "Suites Pointer Error", max); |
wolfSSL | 0:9d17e4342598 | 6439 | break; |
wolfSSL | 0:9d17e4342598 | 6440 | |
wolfSSL | 0:9d17e4342598 | 6441 | case SSL_NO_PEM_HEADER: |
wolfSSL | 0:9d17e4342598 | 6442 | XSTRNCPY(str, "No PEM Header Error", max); |
wolfSSL | 0:9d17e4342598 | 6443 | break; |
wolfSSL | 0:9d17e4342598 | 6444 | |
wolfSSL | 0:9d17e4342598 | 6445 | case OUT_OF_ORDER_E: |
wolfSSL | 0:9d17e4342598 | 6446 | XSTRNCPY(str, "Out of order message, fatal", max); |
wolfSSL | 0:9d17e4342598 | 6447 | break; |
wolfSSL | 0:9d17e4342598 | 6448 | |
wolfSSL | 0:9d17e4342598 | 6449 | case BAD_KEA_TYPE_E: |
wolfSSL | 0:9d17e4342598 | 6450 | XSTRNCPY(str, "Bad KEA type found", max); |
wolfSSL | 0:9d17e4342598 | 6451 | break; |
wolfSSL | 0:9d17e4342598 | 6452 | |
wolfSSL | 0:9d17e4342598 | 6453 | case SANITY_CIPHER_E: |
wolfSSL | 0:9d17e4342598 | 6454 | XSTRNCPY(str, "Sanity check on ciphertext failed", max); |
wolfSSL | 0:9d17e4342598 | 6455 | break; |
wolfSSL | 0:9d17e4342598 | 6456 | |
wolfSSL | 0:9d17e4342598 | 6457 | case RECV_OVERFLOW_E: |
wolfSSL | 0:9d17e4342598 | 6458 | XSTRNCPY(str, "Receive callback returned more than requested", max); |
wolfSSL | 0:9d17e4342598 | 6459 | break; |
wolfSSL | 0:9d17e4342598 | 6460 | |
wolfSSL | 0:9d17e4342598 | 6461 | case GEN_COOKIE_E: |
wolfSSL | 0:9d17e4342598 | 6462 | XSTRNCPY(str, "Generate Cookie Error", max); |
wolfSSL | 0:9d17e4342598 | 6463 | break; |
wolfSSL | 0:9d17e4342598 | 6464 | |
wolfSSL | 0:9d17e4342598 | 6465 | case NO_PEER_VERIFY: |
wolfSSL | 0:9d17e4342598 | 6466 | XSTRNCPY(str, "Need peer certificate verify Error", max); |
wolfSSL | 0:9d17e4342598 | 6467 | break; |
wolfSSL | 0:9d17e4342598 | 6468 | |
wolfSSL | 0:9d17e4342598 | 6469 | case FWRITE_ERROR: |
wolfSSL | 0:9d17e4342598 | 6470 | XSTRNCPY(str, "fwrite Error", max); |
wolfSSL | 0:9d17e4342598 | 6471 | break; |
wolfSSL | 0:9d17e4342598 | 6472 | |
wolfSSL | 0:9d17e4342598 | 6473 | case CACHE_MATCH_ERROR: |
wolfSSL | 0:9d17e4342598 | 6474 | XSTRNCPY(str, "Cache restore header match Error", max); |
wolfSSL | 0:9d17e4342598 | 6475 | break; |
wolfSSL | 0:9d17e4342598 | 6476 | |
wolfSSL | 0:9d17e4342598 | 6477 | case UNKNOWN_SNI_HOST_NAME_E: |
wolfSSL | 0:9d17e4342598 | 6478 | XSTRNCPY(str, "Unrecognized host name Error", max); |
wolfSSL | 0:9d17e4342598 | 6479 | break; |
wolfSSL | 0:9d17e4342598 | 6480 | |
wolfSSL | 0:9d17e4342598 | 6481 | default : |
wolfSSL | 0:9d17e4342598 | 6482 | XSTRNCPY(str, "unknown error number", max); |
wolfSSL | 0:9d17e4342598 | 6483 | } |
wolfSSL | 0:9d17e4342598 | 6484 | |
wolfSSL | 0:9d17e4342598 | 6485 | #endif /* NO_ERROR_STRINGS */ |
wolfSSL | 0:9d17e4342598 | 6486 | } |
wolfSSL | 0:9d17e4342598 | 6487 | |
wolfSSL | 0:9d17e4342598 | 6488 | |
wolfSSL | 0:9d17e4342598 | 6489 | |
wolfSSL | 0:9d17e4342598 | 6490 | /* be sure to add to cipher_name_idx too !!!! */ |
wolfSSL | 0:9d17e4342598 | 6491 | static const char* const cipher_names[] = |
wolfSSL | 0:9d17e4342598 | 6492 | { |
wolfSSL | 0:9d17e4342598 | 6493 | #ifdef BUILD_SSL_RSA_WITH_RC4_128_SHA |
wolfSSL | 0:9d17e4342598 | 6494 | "RC4-SHA", |
wolfSSL | 0:9d17e4342598 | 6495 | #endif |
wolfSSL | 0:9d17e4342598 | 6496 | |
wolfSSL | 0:9d17e4342598 | 6497 | #ifdef BUILD_SSL_RSA_WITH_RC4_128_MD5 |
wolfSSL | 0:9d17e4342598 | 6498 | "RC4-MD5", |
wolfSSL | 0:9d17e4342598 | 6499 | #endif |
wolfSSL | 0:9d17e4342598 | 6500 | |
wolfSSL | 0:9d17e4342598 | 6501 | #ifdef BUILD_SSL_RSA_WITH_3DES_EDE_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6502 | "DES-CBC3-SHA", |
wolfSSL | 0:9d17e4342598 | 6503 | #endif |
wolfSSL | 0:9d17e4342598 | 6504 | |
wolfSSL | 0:9d17e4342598 | 6505 | #ifdef BUILD_TLS_RSA_WITH_AES_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6506 | "AES128-SHA", |
wolfSSL | 0:9d17e4342598 | 6507 | #endif |
wolfSSL | 0:9d17e4342598 | 6508 | |
wolfSSL | 0:9d17e4342598 | 6509 | #ifdef BUILD_TLS_RSA_WITH_AES_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6510 | "AES256-SHA", |
wolfSSL | 0:9d17e4342598 | 6511 | #endif |
wolfSSL | 0:9d17e4342598 | 6512 | |
wolfSSL | 0:9d17e4342598 | 6513 | #ifdef BUILD_TLS_RSA_WITH_NULL_SHA |
wolfSSL | 0:9d17e4342598 | 6514 | "NULL-SHA", |
wolfSSL | 0:9d17e4342598 | 6515 | #endif |
wolfSSL | 0:9d17e4342598 | 6516 | |
wolfSSL | 0:9d17e4342598 | 6517 | #ifdef BUILD_TLS_RSA_WITH_NULL_SHA256 |
wolfSSL | 0:9d17e4342598 | 6518 | "NULL-SHA256", |
wolfSSL | 0:9d17e4342598 | 6519 | #endif |
wolfSSL | 0:9d17e4342598 | 6520 | |
wolfSSL | 0:9d17e4342598 | 6521 | #ifdef BUILD_TLS_DHE_RSA_WITH_AES_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6522 | "DHE-RSA-AES128-SHA", |
wolfSSL | 0:9d17e4342598 | 6523 | #endif |
wolfSSL | 0:9d17e4342598 | 6524 | |
wolfSSL | 0:9d17e4342598 | 6525 | #ifdef BUILD_TLS_DHE_RSA_WITH_AES_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6526 | "DHE-RSA-AES256-SHA", |
wolfSSL | 0:9d17e4342598 | 6527 | #endif |
wolfSSL | 0:9d17e4342598 | 6528 | |
wolfSSL | 0:9d17e4342598 | 6529 | #ifdef BUILD_TLS_PSK_WITH_AES_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 6530 | "PSK-AES128-CBC-SHA256", |
wolfSSL | 0:9d17e4342598 | 6531 | #endif |
wolfSSL | 0:9d17e4342598 | 6532 | |
wolfSSL | 0:9d17e4342598 | 6533 | #ifdef BUILD_TLS_PSK_WITH_AES_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6534 | "PSK-AES128-CBC-SHA", |
wolfSSL | 0:9d17e4342598 | 6535 | #endif |
wolfSSL | 0:9d17e4342598 | 6536 | |
wolfSSL | 0:9d17e4342598 | 6537 | #ifdef BUILD_TLS_PSK_WITH_AES_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6538 | "PSK-AES256-CBC-SHA", |
wolfSSL | 0:9d17e4342598 | 6539 | #endif |
wolfSSL | 0:9d17e4342598 | 6540 | |
wolfSSL | 0:9d17e4342598 | 6541 | #ifdef BUILD_TLS_PSK_WITH_AES_128_CCM_8 |
wolfSSL | 0:9d17e4342598 | 6542 | "PSK-AES128-CCM-8", |
wolfSSL | 0:9d17e4342598 | 6543 | #endif |
wolfSSL | 0:9d17e4342598 | 6544 | |
wolfSSL | 0:9d17e4342598 | 6545 | #ifdef BUILD_TLS_PSK_WITH_AES_256_CCM_8 |
wolfSSL | 0:9d17e4342598 | 6546 | "PSK-AES256-CCM-8", |
wolfSSL | 0:9d17e4342598 | 6547 | #endif |
wolfSSL | 0:9d17e4342598 | 6548 | |
wolfSSL | 0:9d17e4342598 | 6549 | #ifdef BUILD_TLS_PSK_WITH_NULL_SHA256 |
wolfSSL | 0:9d17e4342598 | 6550 | "PSK-NULL-SHA256", |
wolfSSL | 0:9d17e4342598 | 6551 | #endif |
wolfSSL | 0:9d17e4342598 | 6552 | |
wolfSSL | 0:9d17e4342598 | 6553 | #ifdef BUILD_TLS_PSK_WITH_NULL_SHA |
wolfSSL | 0:9d17e4342598 | 6554 | "PSK-NULL-SHA", |
wolfSSL | 0:9d17e4342598 | 6555 | #endif |
wolfSSL | 0:9d17e4342598 | 6556 | |
wolfSSL | 0:9d17e4342598 | 6557 | #ifdef BUILD_TLS_RSA_WITH_HC_128_MD5 |
wolfSSL | 0:9d17e4342598 | 6558 | "HC128-MD5", |
wolfSSL | 0:9d17e4342598 | 6559 | #endif |
wolfSSL | 0:9d17e4342598 | 6560 | |
wolfSSL | 0:9d17e4342598 | 6561 | #ifdef BUILD_TLS_RSA_WITH_HC_128_SHA |
wolfSSL | 0:9d17e4342598 | 6562 | "HC128-SHA", |
wolfSSL | 0:9d17e4342598 | 6563 | #endif |
wolfSSL | 0:9d17e4342598 | 6564 | |
wolfSSL | 0:9d17e4342598 | 6565 | #ifdef BUILD_TLS_RSA_WITH_HC_128_B2B256 |
wolfSSL | 0:9d17e4342598 | 6566 | "HC128-B2B256", |
wolfSSL | 0:9d17e4342598 | 6567 | #endif |
wolfSSL | 0:9d17e4342598 | 6568 | |
wolfSSL | 0:9d17e4342598 | 6569 | #ifdef BUILD_TLS_RSA_WITH_AES_128_CBC_B2B256 |
wolfSSL | 0:9d17e4342598 | 6570 | "AES128-B2B256", |
wolfSSL | 0:9d17e4342598 | 6571 | #endif |
wolfSSL | 0:9d17e4342598 | 6572 | |
wolfSSL | 0:9d17e4342598 | 6573 | #ifdef BUILD_TLS_RSA_WITH_AES_256_CBC_B2B256 |
wolfSSL | 0:9d17e4342598 | 6574 | "AES256-B2B256", |
wolfSSL | 0:9d17e4342598 | 6575 | #endif |
wolfSSL | 0:9d17e4342598 | 6576 | |
wolfSSL | 0:9d17e4342598 | 6577 | #ifdef BUILD_TLS_RSA_WITH_RABBIT_SHA |
wolfSSL | 0:9d17e4342598 | 6578 | "RABBIT-SHA", |
wolfSSL | 0:9d17e4342598 | 6579 | #endif |
wolfSSL | 0:9d17e4342598 | 6580 | |
wolfSSL | 0:9d17e4342598 | 6581 | #ifdef BUILD_TLS_NTRU_RSA_WITH_RC4_128_SHA |
wolfSSL | 0:9d17e4342598 | 6582 | "NTRU-RC4-SHA", |
wolfSSL | 0:9d17e4342598 | 6583 | #endif |
wolfSSL | 0:9d17e4342598 | 6584 | |
wolfSSL | 0:9d17e4342598 | 6585 | #ifdef BUILD_TLS_NTRU_RSA_WITH_3DES_EDE_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6586 | "NTRU-DES-CBC3-SHA", |
wolfSSL | 0:9d17e4342598 | 6587 | #endif |
wolfSSL | 0:9d17e4342598 | 6588 | |
wolfSSL | 0:9d17e4342598 | 6589 | #ifdef BUILD_TLS_NTRU_RSA_WITH_AES_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6590 | "NTRU-AES128-SHA", |
wolfSSL | 0:9d17e4342598 | 6591 | #endif |
wolfSSL | 0:9d17e4342598 | 6592 | |
wolfSSL | 0:9d17e4342598 | 6593 | #ifdef BUILD_TLS_NTRU_RSA_WITH_AES_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6594 | "NTRU-AES256-SHA", |
wolfSSL | 0:9d17e4342598 | 6595 | #endif |
wolfSSL | 0:9d17e4342598 | 6596 | |
wolfSSL | 0:9d17e4342598 | 6597 | #ifdef BUILD_TLS_RSA_WITH_AES_128_CCM_8 |
wolfSSL | 0:9d17e4342598 | 6598 | "AES128-CCM-8", |
wolfSSL | 0:9d17e4342598 | 6599 | #endif |
wolfSSL | 0:9d17e4342598 | 6600 | |
wolfSSL | 0:9d17e4342598 | 6601 | #ifdef BUILD_TLS_RSA_WITH_AES_256_CCM_8 |
wolfSSL | 0:9d17e4342598 | 6602 | "AES256-CCM-8", |
wolfSSL | 0:9d17e4342598 | 6603 | #endif |
wolfSSL | 0:9d17e4342598 | 6604 | |
wolfSSL | 0:9d17e4342598 | 6605 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 |
wolfSSL | 0:9d17e4342598 | 6606 | "ECDHE-ECDSA-AES128-CCM-8", |
wolfSSL | 0:9d17e4342598 | 6607 | #endif |
wolfSSL | 0:9d17e4342598 | 6608 | |
wolfSSL | 0:9d17e4342598 | 6609 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 |
wolfSSL | 0:9d17e4342598 | 6610 | "ECDHE-ECDSA-AES256-CCM-8", |
wolfSSL | 0:9d17e4342598 | 6611 | #endif |
wolfSSL | 0:9d17e4342598 | 6612 | |
wolfSSL | 0:9d17e4342598 | 6613 | #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6614 | "ECDHE-RSA-AES128-SHA", |
wolfSSL | 0:9d17e4342598 | 6615 | #endif |
wolfSSL | 0:9d17e4342598 | 6616 | |
wolfSSL | 0:9d17e4342598 | 6617 | #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6618 | "ECDHE-RSA-AES256-SHA", |
wolfSSL | 0:9d17e4342598 | 6619 | #endif |
wolfSSL | 0:9d17e4342598 | 6620 | |
wolfSSL | 0:9d17e4342598 | 6621 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6622 | "ECDHE-ECDSA-AES128-SHA", |
wolfSSL | 0:9d17e4342598 | 6623 | #endif |
wolfSSL | 0:9d17e4342598 | 6624 | |
wolfSSL | 0:9d17e4342598 | 6625 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6626 | "ECDHE-ECDSA-AES256-SHA", |
wolfSSL | 0:9d17e4342598 | 6627 | #endif |
wolfSSL | 0:9d17e4342598 | 6628 | |
wolfSSL | 0:9d17e4342598 | 6629 | #ifdef BUILD_TLS_ECDHE_RSA_WITH_RC4_128_SHA |
wolfSSL | 0:9d17e4342598 | 6630 | "ECDHE-RSA-RC4-SHA", |
wolfSSL | 0:9d17e4342598 | 6631 | #endif |
wolfSSL | 0:9d17e4342598 | 6632 | |
wolfSSL | 0:9d17e4342598 | 6633 | #ifdef BUILD_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6634 | "ECDHE-RSA-DES-CBC3-SHA", |
wolfSSL | 0:9d17e4342598 | 6635 | #endif |
wolfSSL | 0:9d17e4342598 | 6636 | |
wolfSSL | 0:9d17e4342598 | 6637 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA |
wolfSSL | 0:9d17e4342598 | 6638 | "ECDHE-ECDSA-RC4-SHA", |
wolfSSL | 0:9d17e4342598 | 6639 | #endif |
wolfSSL | 0:9d17e4342598 | 6640 | |
wolfSSL | 0:9d17e4342598 | 6641 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6642 | "ECDHE-ECDSA-DES-CBC3-SHA", |
wolfSSL | 0:9d17e4342598 | 6643 | #endif |
wolfSSL | 0:9d17e4342598 | 6644 | |
wolfSSL | 0:9d17e4342598 | 6645 | #ifdef BUILD_TLS_RSA_WITH_AES_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 6646 | "AES128-SHA256", |
wolfSSL | 0:9d17e4342598 | 6647 | #endif |
wolfSSL | 0:9d17e4342598 | 6648 | |
wolfSSL | 0:9d17e4342598 | 6649 | #ifdef BUILD_TLS_RSA_WITH_AES_256_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 6650 | "AES256-SHA256", |
wolfSSL | 0:9d17e4342598 | 6651 | #endif |
wolfSSL | 0:9d17e4342598 | 6652 | |
wolfSSL | 0:9d17e4342598 | 6653 | #ifdef BUILD_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 6654 | "DHE-RSA-AES128-SHA256", |
wolfSSL | 0:9d17e4342598 | 6655 | #endif |
wolfSSL | 0:9d17e4342598 | 6656 | |
wolfSSL | 0:9d17e4342598 | 6657 | #ifdef BUILD_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 6658 | "DHE-RSA-AES256-SHA256", |
wolfSSL | 0:9d17e4342598 | 6659 | #endif |
wolfSSL | 0:9d17e4342598 | 6660 | |
wolfSSL | 0:9d17e4342598 | 6661 | #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6662 | "ECDH-RSA-AES128-SHA", |
wolfSSL | 0:9d17e4342598 | 6663 | #endif |
wolfSSL | 0:9d17e4342598 | 6664 | |
wolfSSL | 0:9d17e4342598 | 6665 | #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6666 | "ECDH-RSA-AES256-SHA", |
wolfSSL | 0:9d17e4342598 | 6667 | #endif |
wolfSSL | 0:9d17e4342598 | 6668 | |
wolfSSL | 0:9d17e4342598 | 6669 | #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6670 | "ECDH-ECDSA-AES128-SHA", |
wolfSSL | 0:9d17e4342598 | 6671 | #endif |
wolfSSL | 0:9d17e4342598 | 6672 | |
wolfSSL | 0:9d17e4342598 | 6673 | #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6674 | "ECDH-ECDSA-AES256-SHA", |
wolfSSL | 0:9d17e4342598 | 6675 | #endif |
wolfSSL | 0:9d17e4342598 | 6676 | |
wolfSSL | 0:9d17e4342598 | 6677 | #ifdef BUILD_TLS_ECDH_RSA_WITH_RC4_128_SHA |
wolfSSL | 0:9d17e4342598 | 6678 | "ECDH-RSA-RC4-SHA", |
wolfSSL | 0:9d17e4342598 | 6679 | #endif |
wolfSSL | 0:9d17e4342598 | 6680 | |
wolfSSL | 0:9d17e4342598 | 6681 | #ifdef BUILD_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6682 | "ECDH-RSA-DES-CBC3-SHA", |
wolfSSL | 0:9d17e4342598 | 6683 | #endif |
wolfSSL | 0:9d17e4342598 | 6684 | |
wolfSSL | 0:9d17e4342598 | 6685 | #ifdef BUILD_TLS_ECDH_ECDSA_WITH_RC4_128_SHA |
wolfSSL | 0:9d17e4342598 | 6686 | "ECDH-ECDSA-RC4-SHA", |
wolfSSL | 0:9d17e4342598 | 6687 | #endif |
wolfSSL | 0:9d17e4342598 | 6688 | |
wolfSSL | 0:9d17e4342598 | 6689 | #ifdef BUILD_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6690 | "ECDH-ECDSA-DES-CBC3-SHA", |
wolfSSL | 0:9d17e4342598 | 6691 | #endif |
wolfSSL | 0:9d17e4342598 | 6692 | |
wolfSSL | 0:9d17e4342598 | 6693 | #ifdef BUILD_TLS_RSA_WITH_AES_128_GCM_SHA256 |
wolfSSL | 0:9d17e4342598 | 6694 | "AES128-GCM-SHA256", |
wolfSSL | 0:9d17e4342598 | 6695 | #endif |
wolfSSL | 0:9d17e4342598 | 6696 | |
wolfSSL | 0:9d17e4342598 | 6697 | #ifdef BUILD_TLS_RSA_WITH_AES_256_GCM_SHA384 |
wolfSSL | 0:9d17e4342598 | 6698 | "AES256-GCM-SHA384", |
wolfSSL | 0:9d17e4342598 | 6699 | #endif |
wolfSSL | 0:9d17e4342598 | 6700 | |
wolfSSL | 0:9d17e4342598 | 6701 | #ifdef BUILD_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 |
wolfSSL | 0:9d17e4342598 | 6702 | "DHE-RSA-AES128-GCM-SHA256", |
wolfSSL | 0:9d17e4342598 | 6703 | #endif |
wolfSSL | 0:9d17e4342598 | 6704 | |
wolfSSL | 0:9d17e4342598 | 6705 | #ifdef BUILD_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 |
wolfSSL | 0:9d17e4342598 | 6706 | "DHE-RSA-AES256-GCM-SHA384", |
wolfSSL | 0:9d17e4342598 | 6707 | #endif |
wolfSSL | 0:9d17e4342598 | 6708 | |
wolfSSL | 0:9d17e4342598 | 6709 | #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 |
wolfSSL | 0:9d17e4342598 | 6710 | "ECDHE-RSA-AES128-GCM-SHA256", |
wolfSSL | 0:9d17e4342598 | 6711 | #endif |
wolfSSL | 0:9d17e4342598 | 6712 | |
wolfSSL | 0:9d17e4342598 | 6713 | #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 |
wolfSSL | 0:9d17e4342598 | 6714 | "ECDHE-RSA-AES256-GCM-SHA384", |
wolfSSL | 0:9d17e4342598 | 6715 | #endif |
wolfSSL | 0:9d17e4342598 | 6716 | |
wolfSSL | 0:9d17e4342598 | 6717 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 |
wolfSSL | 0:9d17e4342598 | 6718 | "ECDHE-ECDSA-AES128-GCM-SHA256", |
wolfSSL | 0:9d17e4342598 | 6719 | #endif |
wolfSSL | 0:9d17e4342598 | 6720 | |
wolfSSL | 0:9d17e4342598 | 6721 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 |
wolfSSL | 0:9d17e4342598 | 6722 | "ECDHE-ECDSA-AES256-GCM-SHA384", |
wolfSSL | 0:9d17e4342598 | 6723 | #endif |
wolfSSL | 0:9d17e4342598 | 6724 | |
wolfSSL | 0:9d17e4342598 | 6725 | #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 |
wolfSSL | 0:9d17e4342598 | 6726 | "ECDH-RSA-AES128-GCM-SHA256", |
wolfSSL | 0:9d17e4342598 | 6727 | #endif |
wolfSSL | 0:9d17e4342598 | 6728 | |
wolfSSL | 0:9d17e4342598 | 6729 | #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 |
wolfSSL | 0:9d17e4342598 | 6730 | "ECDH-RSA-AES256-GCM-SHA384", |
wolfSSL | 0:9d17e4342598 | 6731 | #endif |
wolfSSL | 0:9d17e4342598 | 6732 | |
wolfSSL | 0:9d17e4342598 | 6733 | #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 |
wolfSSL | 0:9d17e4342598 | 6734 | "ECDH-ECDSA-AES128-GCM-SHA256", |
wolfSSL | 0:9d17e4342598 | 6735 | #endif |
wolfSSL | 0:9d17e4342598 | 6736 | |
wolfSSL | 0:9d17e4342598 | 6737 | #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 |
wolfSSL | 0:9d17e4342598 | 6738 | "ECDH-ECDSA-AES256-GCM-SHA384", |
wolfSSL | 0:9d17e4342598 | 6739 | #endif |
wolfSSL | 0:9d17e4342598 | 6740 | |
wolfSSL | 0:9d17e4342598 | 6741 | #ifdef BUILD_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6742 | "CAMELLIA128-SHA", |
wolfSSL | 0:9d17e4342598 | 6743 | #endif |
wolfSSL | 0:9d17e4342598 | 6744 | |
wolfSSL | 0:9d17e4342598 | 6745 | #ifdef BUILD_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6746 | "DHE-RSA-CAMELLIA128-SHA", |
wolfSSL | 0:9d17e4342598 | 6747 | #endif |
wolfSSL | 0:9d17e4342598 | 6748 | |
wolfSSL | 0:9d17e4342598 | 6749 | #ifdef BUILD_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6750 | "CAMELLIA256-SHA", |
wolfSSL | 0:9d17e4342598 | 6751 | #endif |
wolfSSL | 0:9d17e4342598 | 6752 | |
wolfSSL | 0:9d17e4342598 | 6753 | #ifdef BUILD_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6754 | "DHE-RSA-CAMELLIA256-SHA", |
wolfSSL | 0:9d17e4342598 | 6755 | #endif |
wolfSSL | 0:9d17e4342598 | 6756 | |
wolfSSL | 0:9d17e4342598 | 6757 | #ifdef BUILD_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 6758 | "CAMELLIA128-SHA256", |
wolfSSL | 0:9d17e4342598 | 6759 | #endif |
wolfSSL | 0:9d17e4342598 | 6760 | |
wolfSSL | 0:9d17e4342598 | 6761 | #ifdef BUILD_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 6762 | "DHE-RSA-CAMELLIA128-SHA256", |
wolfSSL | 0:9d17e4342598 | 6763 | #endif |
wolfSSL | 0:9d17e4342598 | 6764 | |
wolfSSL | 0:9d17e4342598 | 6765 | #ifdef BUILD_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 6766 | "CAMELLIA256-SHA256", |
wolfSSL | 0:9d17e4342598 | 6767 | #endif |
wolfSSL | 0:9d17e4342598 | 6768 | |
wolfSSL | 0:9d17e4342598 | 6769 | #ifdef BUILD_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 6770 | "DHE-RSA-CAMELLIA256-SHA256", |
wolfSSL | 0:9d17e4342598 | 6771 | #endif |
wolfSSL | 0:9d17e4342598 | 6772 | |
wolfSSL | 0:9d17e4342598 | 6773 | #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 6774 | "ECDHE-RSA-AES128-SHA256", |
wolfSSL | 0:9d17e4342598 | 6775 | #endif |
wolfSSL | 0:9d17e4342598 | 6776 | |
wolfSSL | 0:9d17e4342598 | 6777 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 6778 | "ECDHE-ECDSA-AES128-SHA256", |
wolfSSL | 0:9d17e4342598 | 6779 | #endif |
wolfSSL | 0:9d17e4342598 | 6780 | |
wolfSSL | 0:9d17e4342598 | 6781 | #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 6782 | "ECDH-RSA-AES128-SHA256", |
wolfSSL | 0:9d17e4342598 | 6783 | #endif |
wolfSSL | 0:9d17e4342598 | 6784 | |
wolfSSL | 0:9d17e4342598 | 6785 | #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 6786 | "ECDH-ECDSA-AES128-SHA256", |
wolfSSL | 0:9d17e4342598 | 6787 | #endif |
wolfSSL | 0:9d17e4342598 | 6788 | |
wolfSSL | 0:9d17e4342598 | 6789 | #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 |
wolfSSL | 0:9d17e4342598 | 6790 | "ECDHE-RSA-AES256-SHA384", |
wolfSSL | 0:9d17e4342598 | 6791 | #endif |
wolfSSL | 0:9d17e4342598 | 6792 | |
wolfSSL | 0:9d17e4342598 | 6793 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 |
wolfSSL | 0:9d17e4342598 | 6794 | "ECDHE-ECDSA-AES256-SHA384", |
wolfSSL | 0:9d17e4342598 | 6795 | #endif |
wolfSSL | 0:9d17e4342598 | 6796 | |
wolfSSL | 0:9d17e4342598 | 6797 | #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 |
wolfSSL | 0:9d17e4342598 | 6798 | "ECDH-RSA-AES256-SHA384", |
wolfSSL | 0:9d17e4342598 | 6799 | #endif |
wolfSSL | 0:9d17e4342598 | 6800 | |
wolfSSL | 0:9d17e4342598 | 6801 | #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 |
wolfSSL | 0:9d17e4342598 | 6802 | "ECDH-ECDSA-AES256-SHA384", |
wolfSSL | 0:9d17e4342598 | 6803 | #endif |
wolfSSL | 0:9d17e4342598 | 6804 | |
wolfSSL | 0:9d17e4342598 | 6805 | }; |
wolfSSL | 0:9d17e4342598 | 6806 | |
wolfSSL | 0:9d17e4342598 | 6807 | |
wolfSSL | 0:9d17e4342598 | 6808 | |
wolfSSL | 0:9d17e4342598 | 6809 | /* cipher suite number that matches above name table */ |
wolfSSL | 0:9d17e4342598 | 6810 | static int cipher_name_idx[] = |
wolfSSL | 0:9d17e4342598 | 6811 | { |
wolfSSL | 0:9d17e4342598 | 6812 | |
wolfSSL | 0:9d17e4342598 | 6813 | #ifdef BUILD_SSL_RSA_WITH_RC4_128_SHA |
wolfSSL | 0:9d17e4342598 | 6814 | SSL_RSA_WITH_RC4_128_SHA, |
wolfSSL | 0:9d17e4342598 | 6815 | #endif |
wolfSSL | 0:9d17e4342598 | 6816 | |
wolfSSL | 0:9d17e4342598 | 6817 | #ifdef BUILD_SSL_RSA_WITH_RC4_128_MD5 |
wolfSSL | 0:9d17e4342598 | 6818 | SSL_RSA_WITH_RC4_128_MD5, |
wolfSSL | 0:9d17e4342598 | 6819 | #endif |
wolfSSL | 0:9d17e4342598 | 6820 | |
wolfSSL | 0:9d17e4342598 | 6821 | #ifdef BUILD_SSL_RSA_WITH_3DES_EDE_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6822 | SSL_RSA_WITH_3DES_EDE_CBC_SHA, |
wolfSSL | 0:9d17e4342598 | 6823 | #endif |
wolfSSL | 0:9d17e4342598 | 6824 | |
wolfSSL | 0:9d17e4342598 | 6825 | #ifdef BUILD_TLS_RSA_WITH_AES_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6826 | TLS_RSA_WITH_AES_128_CBC_SHA, |
wolfSSL | 0:9d17e4342598 | 6827 | #endif |
wolfSSL | 0:9d17e4342598 | 6828 | |
wolfSSL | 0:9d17e4342598 | 6829 | #ifdef BUILD_TLS_RSA_WITH_AES_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6830 | TLS_RSA_WITH_AES_256_CBC_SHA, |
wolfSSL | 0:9d17e4342598 | 6831 | #endif |
wolfSSL | 0:9d17e4342598 | 6832 | |
wolfSSL | 0:9d17e4342598 | 6833 | #ifdef BUILD_TLS_RSA_WITH_NULL_SHA |
wolfSSL | 0:9d17e4342598 | 6834 | TLS_RSA_WITH_NULL_SHA, |
wolfSSL | 0:9d17e4342598 | 6835 | #endif |
wolfSSL | 0:9d17e4342598 | 6836 | |
wolfSSL | 0:9d17e4342598 | 6837 | #ifdef BUILD_TLS_RSA_WITH_NULL_SHA256 |
wolfSSL | 0:9d17e4342598 | 6838 | TLS_RSA_WITH_NULL_SHA256, |
wolfSSL | 0:9d17e4342598 | 6839 | #endif |
wolfSSL | 0:9d17e4342598 | 6840 | |
wolfSSL | 0:9d17e4342598 | 6841 | #ifdef BUILD_TLS_DHE_RSA_WITH_AES_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6842 | TLS_DHE_RSA_WITH_AES_128_CBC_SHA, |
wolfSSL | 0:9d17e4342598 | 6843 | #endif |
wolfSSL | 0:9d17e4342598 | 6844 | |
wolfSSL | 0:9d17e4342598 | 6845 | #ifdef BUILD_TLS_DHE_RSA_WITH_AES_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6846 | TLS_DHE_RSA_WITH_AES_256_CBC_SHA, |
wolfSSL | 0:9d17e4342598 | 6847 | #endif |
wolfSSL | 0:9d17e4342598 | 6848 | |
wolfSSL | 0:9d17e4342598 | 6849 | #ifdef BUILD_TLS_PSK_WITH_AES_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 6850 | TLS_PSK_WITH_AES_128_CBC_SHA256, |
wolfSSL | 0:9d17e4342598 | 6851 | #endif |
wolfSSL | 0:9d17e4342598 | 6852 | |
wolfSSL | 0:9d17e4342598 | 6853 | #ifdef BUILD_TLS_PSK_WITH_AES_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6854 | TLS_PSK_WITH_AES_128_CBC_SHA, |
wolfSSL | 0:9d17e4342598 | 6855 | #endif |
wolfSSL | 0:9d17e4342598 | 6856 | |
wolfSSL | 0:9d17e4342598 | 6857 | #ifdef BUILD_TLS_PSK_WITH_AES_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6858 | TLS_PSK_WITH_AES_256_CBC_SHA, |
wolfSSL | 0:9d17e4342598 | 6859 | #endif |
wolfSSL | 0:9d17e4342598 | 6860 | |
wolfSSL | 0:9d17e4342598 | 6861 | #ifdef BUILD_TLS_PSK_WITH_AES_128_CCM_8 |
wolfSSL | 0:9d17e4342598 | 6862 | TLS_PSK_WITH_AES_128_CCM_8, |
wolfSSL | 0:9d17e4342598 | 6863 | #endif |
wolfSSL | 0:9d17e4342598 | 6864 | |
wolfSSL | 0:9d17e4342598 | 6865 | #ifdef BUILD_TLS_PSK_WITH_AES_256_CCM_8 |
wolfSSL | 0:9d17e4342598 | 6866 | TLS_PSK_WITH_AES_256_CCM_8, |
wolfSSL | 0:9d17e4342598 | 6867 | #endif |
wolfSSL | 0:9d17e4342598 | 6868 | |
wolfSSL | 0:9d17e4342598 | 6869 | #ifdef BUILD_TLS_PSK_WITH_NULL_SHA256 |
wolfSSL | 0:9d17e4342598 | 6870 | TLS_PSK_WITH_NULL_SHA256, |
wolfSSL | 0:9d17e4342598 | 6871 | #endif |
wolfSSL | 0:9d17e4342598 | 6872 | |
wolfSSL | 0:9d17e4342598 | 6873 | #ifdef BUILD_TLS_PSK_WITH_NULL_SHA |
wolfSSL | 0:9d17e4342598 | 6874 | TLS_PSK_WITH_NULL_SHA, |
wolfSSL | 0:9d17e4342598 | 6875 | #endif |
wolfSSL | 0:9d17e4342598 | 6876 | |
wolfSSL | 0:9d17e4342598 | 6877 | #ifdef BUILD_TLS_RSA_WITH_HC_128_MD5 |
wolfSSL | 0:9d17e4342598 | 6878 | TLS_RSA_WITH_HC_128_MD5, |
wolfSSL | 0:9d17e4342598 | 6879 | #endif |
wolfSSL | 0:9d17e4342598 | 6880 | |
wolfSSL | 0:9d17e4342598 | 6881 | #ifdef BUILD_TLS_RSA_WITH_HC_128_SHA |
wolfSSL | 0:9d17e4342598 | 6882 | TLS_RSA_WITH_HC_128_SHA, |
wolfSSL | 0:9d17e4342598 | 6883 | #endif |
wolfSSL | 0:9d17e4342598 | 6884 | |
wolfSSL | 0:9d17e4342598 | 6885 | #ifdef BUILD_TLS_RSA_WITH_HC_128_B2B256 |
wolfSSL | 0:9d17e4342598 | 6886 | TLS_RSA_WITH_HC_128_B2B256, |
wolfSSL | 0:9d17e4342598 | 6887 | #endif |
wolfSSL | 0:9d17e4342598 | 6888 | |
wolfSSL | 0:9d17e4342598 | 6889 | #ifdef BUILD_TLS_RSA_WITH_AES_128_CBC_B2B256 |
wolfSSL | 0:9d17e4342598 | 6890 | TLS_RSA_WITH_AES_128_CBC_B2B256, |
wolfSSL | 0:9d17e4342598 | 6891 | #endif |
wolfSSL | 0:9d17e4342598 | 6892 | |
wolfSSL | 0:9d17e4342598 | 6893 | #ifdef BUILD_TLS_RSA_WITH_AES_256_CBC_B2B256 |
wolfSSL | 0:9d17e4342598 | 6894 | TLS_RSA_WITH_AES_256_CBC_B2B256, |
wolfSSL | 0:9d17e4342598 | 6895 | #endif |
wolfSSL | 0:9d17e4342598 | 6896 | |
wolfSSL | 0:9d17e4342598 | 6897 | #ifdef BUILD_TLS_RSA_WITH_RABBIT_SHA |
wolfSSL | 0:9d17e4342598 | 6898 | TLS_RSA_WITH_RABBIT_SHA, |
wolfSSL | 0:9d17e4342598 | 6899 | #endif |
wolfSSL | 0:9d17e4342598 | 6900 | |
wolfSSL | 0:9d17e4342598 | 6901 | #ifdef BUILD_TLS_NTRU_RSA_WITH_RC4_128_SHA |
wolfSSL | 0:9d17e4342598 | 6902 | TLS_NTRU_RSA_WITH_RC4_128_SHA, |
wolfSSL | 0:9d17e4342598 | 6903 | #endif |
wolfSSL | 0:9d17e4342598 | 6904 | |
wolfSSL | 0:9d17e4342598 | 6905 | #ifdef BUILD_TLS_NTRU_RSA_WITH_3DES_EDE_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6906 | TLS_NTRU_RSA_WITH_3DES_EDE_CBC_SHA, |
wolfSSL | 0:9d17e4342598 | 6907 | #endif |
wolfSSL | 0:9d17e4342598 | 6908 | |
wolfSSL | 0:9d17e4342598 | 6909 | #ifdef BUILD_TLS_NTRU_RSA_WITH_AES_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6910 | TLS_NTRU_RSA_WITH_AES_128_CBC_SHA, |
wolfSSL | 0:9d17e4342598 | 6911 | #endif |
wolfSSL | 0:9d17e4342598 | 6912 | |
wolfSSL | 0:9d17e4342598 | 6913 | #ifdef BUILD_TLS_NTRU_RSA_WITH_AES_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6914 | TLS_NTRU_RSA_WITH_AES_256_CBC_SHA, |
wolfSSL | 0:9d17e4342598 | 6915 | #endif |
wolfSSL | 0:9d17e4342598 | 6916 | |
wolfSSL | 0:9d17e4342598 | 6917 | #ifdef BUILD_TLS_RSA_WITH_AES_128_CCM_8 |
wolfSSL | 0:9d17e4342598 | 6918 | TLS_RSA_WITH_AES_128_CCM_8, |
wolfSSL | 0:9d17e4342598 | 6919 | #endif |
wolfSSL | 0:9d17e4342598 | 6920 | |
wolfSSL | 0:9d17e4342598 | 6921 | #ifdef BUILD_TLS_RSA_WITH_AES_256_CCM_8 |
wolfSSL | 0:9d17e4342598 | 6922 | TLS_RSA_WITH_AES_256_CCM_8, |
wolfSSL | 0:9d17e4342598 | 6923 | #endif |
wolfSSL | 0:9d17e4342598 | 6924 | |
wolfSSL | 0:9d17e4342598 | 6925 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 |
wolfSSL | 0:9d17e4342598 | 6926 | TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8, |
wolfSSL | 0:9d17e4342598 | 6927 | #endif |
wolfSSL | 0:9d17e4342598 | 6928 | |
wolfSSL | 0:9d17e4342598 | 6929 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 |
wolfSSL | 0:9d17e4342598 | 6930 | TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8, |
wolfSSL | 0:9d17e4342598 | 6931 | #endif |
wolfSSL | 0:9d17e4342598 | 6932 | |
wolfSSL | 0:9d17e4342598 | 6933 | #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6934 | TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, |
wolfSSL | 0:9d17e4342598 | 6935 | #endif |
wolfSSL | 0:9d17e4342598 | 6936 | |
wolfSSL | 0:9d17e4342598 | 6937 | #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6938 | TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, |
wolfSSL | 0:9d17e4342598 | 6939 | #endif |
wolfSSL | 0:9d17e4342598 | 6940 | |
wolfSSL | 0:9d17e4342598 | 6941 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6942 | TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, |
wolfSSL | 0:9d17e4342598 | 6943 | #endif |
wolfSSL | 0:9d17e4342598 | 6944 | |
wolfSSL | 0:9d17e4342598 | 6945 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6946 | TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, |
wolfSSL | 0:9d17e4342598 | 6947 | #endif |
wolfSSL | 0:9d17e4342598 | 6948 | |
wolfSSL | 0:9d17e4342598 | 6949 | #ifdef BUILD_TLS_ECDHE_RSA_WITH_RC4_128_SHA |
wolfSSL | 0:9d17e4342598 | 6950 | TLS_ECDHE_RSA_WITH_RC4_128_SHA, |
wolfSSL | 0:9d17e4342598 | 6951 | #endif |
wolfSSL | 0:9d17e4342598 | 6952 | |
wolfSSL | 0:9d17e4342598 | 6953 | #ifdef BUILD_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6954 | TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, |
wolfSSL | 0:9d17e4342598 | 6955 | #endif |
wolfSSL | 0:9d17e4342598 | 6956 | |
wolfSSL | 0:9d17e4342598 | 6957 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA |
wolfSSL | 0:9d17e4342598 | 6958 | TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, |
wolfSSL | 0:9d17e4342598 | 6959 | #endif |
wolfSSL | 0:9d17e4342598 | 6960 | |
wolfSSL | 0:9d17e4342598 | 6961 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6962 | TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, |
wolfSSL | 0:9d17e4342598 | 6963 | #endif |
wolfSSL | 0:9d17e4342598 | 6964 | |
wolfSSL | 0:9d17e4342598 | 6965 | #ifdef BUILD_TLS_RSA_WITH_AES_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 6966 | TLS_RSA_WITH_AES_128_CBC_SHA256, |
wolfSSL | 0:9d17e4342598 | 6967 | #endif |
wolfSSL | 0:9d17e4342598 | 6968 | |
wolfSSL | 0:9d17e4342598 | 6969 | #ifdef BUILD_TLS_RSA_WITH_AES_256_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 6970 | TLS_RSA_WITH_AES_256_CBC_SHA256, |
wolfSSL | 0:9d17e4342598 | 6971 | #endif |
wolfSSL | 0:9d17e4342598 | 6972 | |
wolfSSL | 0:9d17e4342598 | 6973 | #ifdef BUILD_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 6974 | TLS_DHE_RSA_WITH_AES_128_CBC_SHA256, |
wolfSSL | 0:9d17e4342598 | 6975 | #endif |
wolfSSL | 0:9d17e4342598 | 6976 | |
wolfSSL | 0:9d17e4342598 | 6977 | #ifdef BUILD_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 6978 | TLS_DHE_RSA_WITH_AES_256_CBC_SHA256, |
wolfSSL | 0:9d17e4342598 | 6979 | #endif |
wolfSSL | 0:9d17e4342598 | 6980 | |
wolfSSL | 0:9d17e4342598 | 6981 | #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6982 | TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, |
wolfSSL | 0:9d17e4342598 | 6983 | #endif |
wolfSSL | 0:9d17e4342598 | 6984 | |
wolfSSL | 0:9d17e4342598 | 6985 | #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6986 | TLS_ECDH_RSA_WITH_AES_256_CBC_SHA, |
wolfSSL | 0:9d17e4342598 | 6987 | #endif |
wolfSSL | 0:9d17e4342598 | 6988 | |
wolfSSL | 0:9d17e4342598 | 6989 | #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6990 | TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, |
wolfSSL | 0:9d17e4342598 | 6991 | #endif |
wolfSSL | 0:9d17e4342598 | 6992 | |
wolfSSL | 0:9d17e4342598 | 6993 | #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 6994 | TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA, |
wolfSSL | 0:9d17e4342598 | 6995 | #endif |
wolfSSL | 0:9d17e4342598 | 6996 | |
wolfSSL | 0:9d17e4342598 | 6997 | #ifdef BUILD_TLS_ECDH_RSA_WITH_RC4_128_SHA |
wolfSSL | 0:9d17e4342598 | 6998 | TLS_ECDH_RSA_WITH_RC4_128_SHA, |
wolfSSL | 0:9d17e4342598 | 6999 | #endif |
wolfSSL | 0:9d17e4342598 | 7000 | |
wolfSSL | 0:9d17e4342598 | 7001 | #ifdef BUILD_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 7002 | TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, |
wolfSSL | 0:9d17e4342598 | 7003 | #endif |
wolfSSL | 0:9d17e4342598 | 7004 | |
wolfSSL | 0:9d17e4342598 | 7005 | #ifdef BUILD_TLS_ECDH_ECDSA_WITH_RC4_128_SHA |
wolfSSL | 0:9d17e4342598 | 7006 | TLS_ECDH_ECDSA_WITH_RC4_128_SHA, |
wolfSSL | 0:9d17e4342598 | 7007 | #endif |
wolfSSL | 0:9d17e4342598 | 7008 | |
wolfSSL | 0:9d17e4342598 | 7009 | #ifdef BUILD_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 7010 | TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, |
wolfSSL | 0:9d17e4342598 | 7011 | #endif |
wolfSSL | 0:9d17e4342598 | 7012 | |
wolfSSL | 0:9d17e4342598 | 7013 | #ifdef BUILD_TLS_RSA_WITH_AES_128_GCM_SHA256 |
wolfSSL | 0:9d17e4342598 | 7014 | TLS_RSA_WITH_AES_128_GCM_SHA256, |
wolfSSL | 0:9d17e4342598 | 7015 | #endif |
wolfSSL | 0:9d17e4342598 | 7016 | |
wolfSSL | 0:9d17e4342598 | 7017 | #ifdef BUILD_TLS_RSA_WITH_AES_256_GCM_SHA384 |
wolfSSL | 0:9d17e4342598 | 7018 | TLS_RSA_WITH_AES_256_GCM_SHA384, |
wolfSSL | 0:9d17e4342598 | 7019 | #endif |
wolfSSL | 0:9d17e4342598 | 7020 | |
wolfSSL | 0:9d17e4342598 | 7021 | #ifdef BUILD_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 |
wolfSSL | 0:9d17e4342598 | 7022 | TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, |
wolfSSL | 0:9d17e4342598 | 7023 | #endif |
wolfSSL | 0:9d17e4342598 | 7024 | |
wolfSSL | 0:9d17e4342598 | 7025 | #ifdef BUILD_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 |
wolfSSL | 0:9d17e4342598 | 7026 | TLS_DHE_RSA_WITH_AES_256_GCM_SHA384, |
wolfSSL | 0:9d17e4342598 | 7027 | #endif |
wolfSSL | 0:9d17e4342598 | 7028 | |
wolfSSL | 0:9d17e4342598 | 7029 | #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 |
wolfSSL | 0:9d17e4342598 | 7030 | TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
wolfSSL | 0:9d17e4342598 | 7031 | #endif |
wolfSSL | 0:9d17e4342598 | 7032 | |
wolfSSL | 0:9d17e4342598 | 7033 | #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 |
wolfSSL | 0:9d17e4342598 | 7034 | TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, |
wolfSSL | 0:9d17e4342598 | 7035 | #endif |
wolfSSL | 0:9d17e4342598 | 7036 | |
wolfSSL | 0:9d17e4342598 | 7037 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 |
wolfSSL | 0:9d17e4342598 | 7038 | TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, |
wolfSSL | 0:9d17e4342598 | 7039 | #endif |
wolfSSL | 0:9d17e4342598 | 7040 | |
wolfSSL | 0:9d17e4342598 | 7041 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 |
wolfSSL | 0:9d17e4342598 | 7042 | TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, |
wolfSSL | 0:9d17e4342598 | 7043 | #endif |
wolfSSL | 0:9d17e4342598 | 7044 | |
wolfSSL | 0:9d17e4342598 | 7045 | #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 |
wolfSSL | 0:9d17e4342598 | 7046 | TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, |
wolfSSL | 0:9d17e4342598 | 7047 | #endif |
wolfSSL | 0:9d17e4342598 | 7048 | |
wolfSSL | 0:9d17e4342598 | 7049 | #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 |
wolfSSL | 0:9d17e4342598 | 7050 | TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384, |
wolfSSL | 0:9d17e4342598 | 7051 | #endif |
wolfSSL | 0:9d17e4342598 | 7052 | |
wolfSSL | 0:9d17e4342598 | 7053 | #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 |
wolfSSL | 0:9d17e4342598 | 7054 | TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, |
wolfSSL | 0:9d17e4342598 | 7055 | #endif |
wolfSSL | 0:9d17e4342598 | 7056 | |
wolfSSL | 0:9d17e4342598 | 7057 | #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 |
wolfSSL | 0:9d17e4342598 | 7058 | TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384, |
wolfSSL | 0:9d17e4342598 | 7059 | #endif |
wolfSSL | 0:9d17e4342598 | 7060 | |
wolfSSL | 0:9d17e4342598 | 7061 | #ifdef BUILD_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 7062 | TLS_RSA_WITH_CAMELLIA_128_CBC_SHA, |
wolfSSL | 0:9d17e4342598 | 7063 | #endif |
wolfSSL | 0:9d17e4342598 | 7064 | |
wolfSSL | 0:9d17e4342598 | 7065 | #ifdef BUILD_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 7066 | TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA, |
wolfSSL | 0:9d17e4342598 | 7067 | #endif |
wolfSSL | 0:9d17e4342598 | 7068 | |
wolfSSL | 0:9d17e4342598 | 7069 | #ifdef BUILD_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 7070 | TLS_RSA_WITH_CAMELLIA_256_CBC_SHA, |
wolfSSL | 0:9d17e4342598 | 7071 | #endif |
wolfSSL | 0:9d17e4342598 | 7072 | |
wolfSSL | 0:9d17e4342598 | 7073 | #ifdef BUILD_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA |
wolfSSL | 0:9d17e4342598 | 7074 | TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA, |
wolfSSL | 0:9d17e4342598 | 7075 | #endif |
wolfSSL | 0:9d17e4342598 | 7076 | |
wolfSSL | 0:9d17e4342598 | 7077 | #ifdef BUILD_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 7078 | TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256, |
wolfSSL | 0:9d17e4342598 | 7079 | #endif |
wolfSSL | 0:9d17e4342598 | 7080 | |
wolfSSL | 0:9d17e4342598 | 7081 | #ifdef BUILD_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 7082 | TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256, |
wolfSSL | 0:9d17e4342598 | 7083 | #endif |
wolfSSL | 0:9d17e4342598 | 7084 | |
wolfSSL | 0:9d17e4342598 | 7085 | #ifdef BUILD_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 7086 | TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256, |
wolfSSL | 0:9d17e4342598 | 7087 | #endif |
wolfSSL | 0:9d17e4342598 | 7088 | |
wolfSSL | 0:9d17e4342598 | 7089 | #ifdef BUILD_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 7090 | TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256, |
wolfSSL | 0:9d17e4342598 | 7091 | #endif |
wolfSSL | 0:9d17e4342598 | 7092 | |
wolfSSL | 0:9d17e4342598 | 7093 | #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 7094 | TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, |
wolfSSL | 0:9d17e4342598 | 7095 | #endif |
wolfSSL | 0:9d17e4342598 | 7096 | |
wolfSSL | 0:9d17e4342598 | 7097 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 7098 | TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, |
wolfSSL | 0:9d17e4342598 | 7099 | #endif |
wolfSSL | 0:9d17e4342598 | 7100 | |
wolfSSL | 0:9d17e4342598 | 7101 | #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 7102 | TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, |
wolfSSL | 0:9d17e4342598 | 7103 | #endif |
wolfSSL | 0:9d17e4342598 | 7104 | |
wolfSSL | 0:9d17e4342598 | 7105 | #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 |
wolfSSL | 0:9d17e4342598 | 7106 | TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, |
wolfSSL | 0:9d17e4342598 | 7107 | #endif |
wolfSSL | 0:9d17e4342598 | 7108 | |
wolfSSL | 0:9d17e4342598 | 7109 | #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 |
wolfSSL | 0:9d17e4342598 | 7110 | TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, |
wolfSSL | 0:9d17e4342598 | 7111 | #endif |
wolfSSL | 0:9d17e4342598 | 7112 | |
wolfSSL | 0:9d17e4342598 | 7113 | #ifdef BUILD_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 |
wolfSSL | 0:9d17e4342598 | 7114 | TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, |
wolfSSL | 0:9d17e4342598 | 7115 | #endif |
wolfSSL | 0:9d17e4342598 | 7116 | |
wolfSSL | 0:9d17e4342598 | 7117 | #ifdef BUILD_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 |
wolfSSL | 0:9d17e4342598 | 7118 | TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384, |
wolfSSL | 0:9d17e4342598 | 7119 | #endif |
wolfSSL | 0:9d17e4342598 | 7120 | |
wolfSSL | 0:9d17e4342598 | 7121 | #ifdef BUILD_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 |
wolfSSL | 0:9d17e4342598 | 7122 | TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 |
wolfSSL | 0:9d17e4342598 | 7123 | #endif |
wolfSSL | 0:9d17e4342598 | 7124 | }; |
wolfSSL | 0:9d17e4342598 | 7125 | |
wolfSSL | 0:9d17e4342598 | 7126 | |
wolfSSL | 0:9d17e4342598 | 7127 | /* return true if set, else false */ |
wolfSSL | 0:9d17e4342598 | 7128 | /* only supports full name from cipher_name[] delimited by : */ |
wolfSSL | 0:9d17e4342598 | 7129 | int SetCipherList(Suites* s, const char* list) |
wolfSSL | 0:9d17e4342598 | 7130 | { |
wolfSSL | 0:9d17e4342598 | 7131 | int ret = 0, i; |
wolfSSL | 0:9d17e4342598 | 7132 | char name[MAX_SUITE_NAME]; |
wolfSSL | 0:9d17e4342598 | 7133 | |
wolfSSL | 0:9d17e4342598 | 7134 | char needle[] = ":"; |
wolfSSL | 0:9d17e4342598 | 7135 | char* haystack = (char*)list; |
wolfSSL | 0:9d17e4342598 | 7136 | char* prev; |
wolfSSL | 0:9d17e4342598 | 7137 | |
wolfSSL | 0:9d17e4342598 | 7138 | const int suiteSz = sizeof(cipher_names) / sizeof(cipher_names[0]); |
wolfSSL | 0:9d17e4342598 | 7139 | int idx = 0; |
wolfSSL | 0:9d17e4342598 | 7140 | int haveRSA = 0, haveECDSA = 0; |
wolfSSL | 0:9d17e4342598 | 7141 | |
wolfSSL | 0:9d17e4342598 | 7142 | if (s == NULL) { |
wolfSSL | 0:9d17e4342598 | 7143 | CYASSL_MSG("SetCipherList suite pointer error"); |
wolfSSL | 0:9d17e4342598 | 7144 | return 0; |
wolfSSL | 0:9d17e4342598 | 7145 | } |
wolfSSL | 0:9d17e4342598 | 7146 | |
wolfSSL | 0:9d17e4342598 | 7147 | if (!list) |
wolfSSL | 0:9d17e4342598 | 7148 | return 0; |
wolfSSL | 0:9d17e4342598 | 7149 | |
wolfSSL | 0:9d17e4342598 | 7150 | if (*list == 0) return 1; /* CyaSSL default */ |
wolfSSL | 0:9d17e4342598 | 7151 | |
wolfSSL | 0:9d17e4342598 | 7152 | if (XSTRNCMP(haystack, "ALL", 3) == 0) return 1; /* CyaSSL defualt */ |
wolfSSL | 0:9d17e4342598 | 7153 | |
wolfSSL | 0:9d17e4342598 | 7154 | for(;;) { |
wolfSSL | 0:9d17e4342598 | 7155 | word32 len; |
wolfSSL | 0:9d17e4342598 | 7156 | prev = haystack; |
wolfSSL | 0:9d17e4342598 | 7157 | haystack = XSTRSTR(haystack, needle); |
wolfSSL | 0:9d17e4342598 | 7158 | |
wolfSSL | 0:9d17e4342598 | 7159 | if (!haystack) /* last cipher */ |
wolfSSL | 0:9d17e4342598 | 7160 | len = min(sizeof(name), (word32)XSTRLEN(prev)); |
wolfSSL | 0:9d17e4342598 | 7161 | else |
wolfSSL | 0:9d17e4342598 | 7162 | len = min(sizeof(name), (word32)(haystack - prev)); |
wolfSSL | 0:9d17e4342598 | 7163 | |
wolfSSL | 0:9d17e4342598 | 7164 | XSTRNCPY(name, prev, len); |
wolfSSL | 0:9d17e4342598 | 7165 | name[(len == sizeof(name)) ? len - 1 : len] = 0; |
wolfSSL | 0:9d17e4342598 | 7166 | |
wolfSSL | 0:9d17e4342598 | 7167 | for (i = 0; i < suiteSz; i++) |
wolfSSL | 0:9d17e4342598 | 7168 | if (XSTRNCMP(name, cipher_names[i], sizeof(name)) == 0) { |
wolfSSL | 0:9d17e4342598 | 7169 | if (XSTRSTR(name, "EC") || XSTRSTR(name, "CCM")) |
wolfSSL | 0:9d17e4342598 | 7170 | s->suites[idx++] = ECC_BYTE; /* ECC suite */ |
wolfSSL | 0:9d17e4342598 | 7171 | else |
wolfSSL | 0:9d17e4342598 | 7172 | s->suites[idx++] = 0x00; /* normal */ |
wolfSSL | 0:9d17e4342598 | 7173 | s->suites[idx++] = (byte)cipher_name_idx[i]; |
wolfSSL | 0:9d17e4342598 | 7174 | |
wolfSSL | 0:9d17e4342598 | 7175 | /* The suites are either ECDSA, RSA, or PSK. The RSA suites |
wolfSSL | 0:9d17e4342598 | 7176 | * don't necessarily have RSA in the name. */ |
wolfSSL | 0:9d17e4342598 | 7177 | if ((haveECDSA == 0) && XSTRSTR(name, "ECDSA")) { |
wolfSSL | 0:9d17e4342598 | 7178 | haveECDSA = 1; |
wolfSSL | 0:9d17e4342598 | 7179 | } |
wolfSSL | 0:9d17e4342598 | 7180 | else if ((haveRSA == 0) && (XSTRSTR(name, "PSK") == NULL)) { |
wolfSSL | 0:9d17e4342598 | 7181 | haveRSA = 1; |
wolfSSL | 0:9d17e4342598 | 7182 | } |
wolfSSL | 0:9d17e4342598 | 7183 | |
wolfSSL | 0:9d17e4342598 | 7184 | if (!ret) ret = 1; /* found at least one */ |
wolfSSL | 0:9d17e4342598 | 7185 | break; |
wolfSSL | 0:9d17e4342598 | 7186 | } |
wolfSSL | 0:9d17e4342598 | 7187 | if (!haystack) break; |
wolfSSL | 0:9d17e4342598 | 7188 | haystack++; |
wolfSSL | 0:9d17e4342598 | 7189 | } |
wolfSSL | 0:9d17e4342598 | 7190 | |
wolfSSL | 0:9d17e4342598 | 7191 | if (ret) { |
wolfSSL | 0:9d17e4342598 | 7192 | s->setSuites = 1; |
wolfSSL | 0:9d17e4342598 | 7193 | s->suiteSz = (word16)idx; |
wolfSSL | 0:9d17e4342598 | 7194 | |
wolfSSL | 0:9d17e4342598 | 7195 | idx = 0; |
wolfSSL | 0:9d17e4342598 | 7196 | |
wolfSSL | 0:9d17e4342598 | 7197 | if (haveECDSA) { |
wolfSSL | 0:9d17e4342598 | 7198 | #ifdef CYASSL_SHA384 |
wolfSSL | 0:9d17e4342598 | 7199 | s->hashSigAlgo[idx++] = sha384_mac; |
wolfSSL | 0:9d17e4342598 | 7200 | s->hashSigAlgo[idx++] = ecc_dsa_sa_algo; |
wolfSSL | 0:9d17e4342598 | 7201 | #endif |
wolfSSL | 0:9d17e4342598 | 7202 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 7203 | s->hashSigAlgo[idx++] = sha256_mac; |
wolfSSL | 0:9d17e4342598 | 7204 | s->hashSigAlgo[idx++] = ecc_dsa_sa_algo; |
wolfSSL | 0:9d17e4342598 | 7205 | #endif |
wolfSSL | 0:9d17e4342598 | 7206 | s->hashSigAlgo[idx++] = sha_mac; |
wolfSSL | 0:9d17e4342598 | 7207 | s->hashSigAlgo[idx++] = ecc_dsa_sa_algo; |
wolfSSL | 0:9d17e4342598 | 7208 | } |
wolfSSL | 0:9d17e4342598 | 7209 | |
wolfSSL | 0:9d17e4342598 | 7210 | if (haveRSA) { |
wolfSSL | 0:9d17e4342598 | 7211 | #ifdef CYASSL_SHA384 |
wolfSSL | 0:9d17e4342598 | 7212 | s->hashSigAlgo[idx++] = sha384_mac; |
wolfSSL | 0:9d17e4342598 | 7213 | s->hashSigAlgo[idx++] = rsa_sa_algo; |
wolfSSL | 0:9d17e4342598 | 7214 | #endif |
wolfSSL | 0:9d17e4342598 | 7215 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 7216 | s->hashSigAlgo[idx++] = sha256_mac; |
wolfSSL | 0:9d17e4342598 | 7217 | s->hashSigAlgo[idx++] = rsa_sa_algo; |
wolfSSL | 0:9d17e4342598 | 7218 | #endif |
wolfSSL | 0:9d17e4342598 | 7219 | s->hashSigAlgo[idx++] = sha_mac; |
wolfSSL | 0:9d17e4342598 | 7220 | s->hashSigAlgo[idx++] = rsa_sa_algo; |
wolfSSL | 0:9d17e4342598 | 7221 | } |
wolfSSL | 0:9d17e4342598 | 7222 | |
wolfSSL | 0:9d17e4342598 | 7223 | s->hashSigAlgoSz = (word16)idx; |
wolfSSL | 0:9d17e4342598 | 7224 | } |
wolfSSL | 0:9d17e4342598 | 7225 | |
wolfSSL | 0:9d17e4342598 | 7226 | return ret; |
wolfSSL | 0:9d17e4342598 | 7227 | } |
wolfSSL | 0:9d17e4342598 | 7228 | |
wolfSSL | 0:9d17e4342598 | 7229 | |
wolfSSL | 0:9d17e4342598 | 7230 | static void PickHashSigAlgo(CYASSL* ssl, |
wolfSSL | 0:9d17e4342598 | 7231 | const byte* hashSigAlgo, word32 hashSigAlgoSz) |
wolfSSL | 0:9d17e4342598 | 7232 | { |
wolfSSL | 0:9d17e4342598 | 7233 | word32 i; |
wolfSSL | 0:9d17e4342598 | 7234 | |
wolfSSL | 0:9d17e4342598 | 7235 | ssl->suites->sigAlgo = ssl->specs.sig_algo; |
wolfSSL | 0:9d17e4342598 | 7236 | ssl->suites->hashAlgo = sha_mac; |
wolfSSL | 0:9d17e4342598 | 7237 | |
wolfSSL | 0:9d17e4342598 | 7238 | for (i = 0; i < hashSigAlgoSz; i += 2) { |
wolfSSL | 0:9d17e4342598 | 7239 | if (hashSigAlgo[i+1] == ssl->specs.sig_algo) { |
wolfSSL | 0:9d17e4342598 | 7240 | if (hashSigAlgo[i] == sha_mac) { |
wolfSSL | 0:9d17e4342598 | 7241 | break; |
wolfSSL | 0:9d17e4342598 | 7242 | } |
wolfSSL | 0:9d17e4342598 | 7243 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 7244 | else if (hashSigAlgo[i] == sha256_mac) { |
wolfSSL | 0:9d17e4342598 | 7245 | ssl->suites->hashAlgo = sha256_mac; |
wolfSSL | 0:9d17e4342598 | 7246 | break; |
wolfSSL | 0:9d17e4342598 | 7247 | } |
wolfSSL | 0:9d17e4342598 | 7248 | #endif |
wolfSSL | 0:9d17e4342598 | 7249 | #ifdef CYASSL_SHA384 |
wolfSSL | 0:9d17e4342598 | 7250 | else if (hashSigAlgo[i] == sha384_mac) { |
wolfSSL | 0:9d17e4342598 | 7251 | ssl->suites->hashAlgo = sha384_mac; |
wolfSSL | 0:9d17e4342598 | 7252 | break; |
wolfSSL | 0:9d17e4342598 | 7253 | } |
wolfSSL | 0:9d17e4342598 | 7254 | #endif |
wolfSSL | 0:9d17e4342598 | 7255 | } |
wolfSSL | 0:9d17e4342598 | 7256 | } |
wolfSSL | 0:9d17e4342598 | 7257 | } |
wolfSSL | 0:9d17e4342598 | 7258 | |
wolfSSL | 0:9d17e4342598 | 7259 | |
wolfSSL | 0:9d17e4342598 | 7260 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 7261 | |
wolfSSL | 0:9d17e4342598 | 7262 | /* Initialisze HandShakeInfo */ |
wolfSSL | 0:9d17e4342598 | 7263 | void InitHandShakeInfo(HandShakeInfo* info) |
wolfSSL | 0:9d17e4342598 | 7264 | { |
wolfSSL | 0:9d17e4342598 | 7265 | int i; |
wolfSSL | 0:9d17e4342598 | 7266 | |
wolfSSL | 0:9d17e4342598 | 7267 | info->cipherName[0] = 0; |
wolfSSL | 0:9d17e4342598 | 7268 | for (i = 0; i < MAX_PACKETS_HANDSHAKE; i++) |
wolfSSL | 0:9d17e4342598 | 7269 | info->packetNames[i][0] = 0; |
wolfSSL | 0:9d17e4342598 | 7270 | info->numberPackets = 0; |
wolfSSL | 0:9d17e4342598 | 7271 | info->negotiationError = 0; |
wolfSSL | 0:9d17e4342598 | 7272 | } |
wolfSSL | 0:9d17e4342598 | 7273 | |
wolfSSL | 0:9d17e4342598 | 7274 | /* Set Final HandShakeInfo parameters */ |
wolfSSL | 0:9d17e4342598 | 7275 | void FinishHandShakeInfo(HandShakeInfo* info, const CYASSL* ssl) |
wolfSSL | 0:9d17e4342598 | 7276 | { |
wolfSSL | 0:9d17e4342598 | 7277 | int i; |
wolfSSL | 0:9d17e4342598 | 7278 | int sz = sizeof(cipher_name_idx)/sizeof(int); |
wolfSSL | 0:9d17e4342598 | 7279 | |
wolfSSL | 0:9d17e4342598 | 7280 | for (i = 0; i < sz; i++) |
wolfSSL | 0:9d17e4342598 | 7281 | if (ssl->options.cipherSuite == (byte)cipher_name_idx[i]) { |
wolfSSL | 0:9d17e4342598 | 7282 | if (ssl->options.cipherSuite0 == ECC_BYTE) |
wolfSSL | 0:9d17e4342598 | 7283 | continue; /* ECC suites at end */ |
wolfSSL | 0:9d17e4342598 | 7284 | XSTRNCPY(info->cipherName, cipher_names[i], MAX_CIPHERNAME_SZ); |
wolfSSL | 0:9d17e4342598 | 7285 | break; |
wolfSSL | 0:9d17e4342598 | 7286 | } |
wolfSSL | 0:9d17e4342598 | 7287 | |
wolfSSL | 0:9d17e4342598 | 7288 | /* error max and min are negative numbers */ |
wolfSSL | 0:9d17e4342598 | 7289 | if (ssl->error <= MIN_PARAM_ERR && ssl->error >= MAX_PARAM_ERR) |
wolfSSL | 0:9d17e4342598 | 7290 | info->negotiationError = ssl->error; |
wolfSSL | 0:9d17e4342598 | 7291 | } |
wolfSSL | 0:9d17e4342598 | 7292 | |
wolfSSL | 0:9d17e4342598 | 7293 | |
wolfSSL | 0:9d17e4342598 | 7294 | /* Add name to info packet names, increase packet name count */ |
wolfSSL | 0:9d17e4342598 | 7295 | void AddPacketName(const char* name, HandShakeInfo* info) |
wolfSSL | 0:9d17e4342598 | 7296 | { |
wolfSSL | 0:9d17e4342598 | 7297 | if (info->numberPackets < MAX_PACKETS_HANDSHAKE) { |
wolfSSL | 0:9d17e4342598 | 7298 | XSTRNCPY(info->packetNames[info->numberPackets++], name, |
wolfSSL | 0:9d17e4342598 | 7299 | MAX_PACKETNAME_SZ); |
wolfSSL | 0:9d17e4342598 | 7300 | } |
wolfSSL | 0:9d17e4342598 | 7301 | } |
wolfSSL | 0:9d17e4342598 | 7302 | |
wolfSSL | 0:9d17e4342598 | 7303 | |
wolfSSL | 0:9d17e4342598 | 7304 | /* Initialisze TimeoutInfo */ |
wolfSSL | 0:9d17e4342598 | 7305 | void InitTimeoutInfo(TimeoutInfo* info) |
wolfSSL | 0:9d17e4342598 | 7306 | { |
wolfSSL | 0:9d17e4342598 | 7307 | int i; |
wolfSSL | 0:9d17e4342598 | 7308 | |
wolfSSL | 0:9d17e4342598 | 7309 | info->timeoutName[0] = 0; |
wolfSSL | 0:9d17e4342598 | 7310 | info->flags = 0; |
wolfSSL | 0:9d17e4342598 | 7311 | |
wolfSSL | 0:9d17e4342598 | 7312 | for (i = 0; i < MAX_PACKETS_HANDSHAKE; i++) { |
wolfSSL | 0:9d17e4342598 | 7313 | info->packets[i].packetName[0] = 0; |
wolfSSL | 0:9d17e4342598 | 7314 | info->packets[i].timestamp.tv_sec = 0; |
wolfSSL | 0:9d17e4342598 | 7315 | info->packets[i].timestamp.tv_usec = 0; |
wolfSSL | 0:9d17e4342598 | 7316 | info->packets[i].bufferValue = 0; |
wolfSSL | 0:9d17e4342598 | 7317 | info->packets[i].valueSz = 0; |
wolfSSL | 0:9d17e4342598 | 7318 | } |
wolfSSL | 0:9d17e4342598 | 7319 | info->numberPackets = 0; |
wolfSSL | 0:9d17e4342598 | 7320 | info->timeoutValue.tv_sec = 0; |
wolfSSL | 0:9d17e4342598 | 7321 | info->timeoutValue.tv_usec = 0; |
wolfSSL | 0:9d17e4342598 | 7322 | } |
wolfSSL | 0:9d17e4342598 | 7323 | |
wolfSSL | 0:9d17e4342598 | 7324 | |
wolfSSL | 0:9d17e4342598 | 7325 | /* Free TimeoutInfo */ |
wolfSSL | 0:9d17e4342598 | 7326 | void FreeTimeoutInfo(TimeoutInfo* info, void* heap) |
wolfSSL | 0:9d17e4342598 | 7327 | { |
wolfSSL | 0:9d17e4342598 | 7328 | int i; |
wolfSSL | 0:9d17e4342598 | 7329 | (void)heap; |
wolfSSL | 0:9d17e4342598 | 7330 | for (i = 0; i < MAX_PACKETS_HANDSHAKE; i++) |
wolfSSL | 0:9d17e4342598 | 7331 | if (info->packets[i].bufferValue) { |
wolfSSL | 0:9d17e4342598 | 7332 | XFREE(info->packets[i].bufferValue, heap, DYNAMIC_TYPE_INFO); |
wolfSSL | 0:9d17e4342598 | 7333 | info->packets[i].bufferValue = 0; |
wolfSSL | 0:9d17e4342598 | 7334 | } |
wolfSSL | 0:9d17e4342598 | 7335 | |
wolfSSL | 0:9d17e4342598 | 7336 | } |
wolfSSL | 0:9d17e4342598 | 7337 | |
wolfSSL | 0:9d17e4342598 | 7338 | |
wolfSSL | 0:9d17e4342598 | 7339 | /* Add PacketInfo to TimeoutInfo */ |
wolfSSL | 0:9d17e4342598 | 7340 | void AddPacketInfo(const char* name, TimeoutInfo* info, const byte* data, |
wolfSSL | 0:9d17e4342598 | 7341 | int sz, void* heap) |
wolfSSL | 0:9d17e4342598 | 7342 | { |
wolfSSL | 0:9d17e4342598 | 7343 | if (info->numberPackets < (MAX_PACKETS_HANDSHAKE - 1)) { |
wolfSSL | 0:9d17e4342598 | 7344 | Timeval currTime; |
wolfSSL | 0:9d17e4342598 | 7345 | |
wolfSSL | 0:9d17e4342598 | 7346 | /* may add name after */ |
wolfSSL | 0:9d17e4342598 | 7347 | if (name) |
wolfSSL | 0:9d17e4342598 | 7348 | XSTRNCPY(info->packets[info->numberPackets].packetName, name, |
wolfSSL | 0:9d17e4342598 | 7349 | MAX_PACKETNAME_SZ); |
wolfSSL | 0:9d17e4342598 | 7350 | |
wolfSSL | 0:9d17e4342598 | 7351 | /* add data, put in buffer if bigger than static buffer */ |
wolfSSL | 0:9d17e4342598 | 7352 | info->packets[info->numberPackets].valueSz = sz; |
wolfSSL | 0:9d17e4342598 | 7353 | if (sz < MAX_VALUE_SZ) |
wolfSSL | 0:9d17e4342598 | 7354 | XMEMCPY(info->packets[info->numberPackets].value, data, sz); |
wolfSSL | 0:9d17e4342598 | 7355 | else { |
wolfSSL | 0:9d17e4342598 | 7356 | info->packets[info->numberPackets].bufferValue = |
wolfSSL | 0:9d17e4342598 | 7357 | XMALLOC(sz, heap, DYNAMIC_TYPE_INFO); |
wolfSSL | 0:9d17e4342598 | 7358 | if (!info->packets[info->numberPackets].bufferValue) |
wolfSSL | 0:9d17e4342598 | 7359 | /* let next alloc catch, just don't fill, not fatal here */ |
wolfSSL | 0:9d17e4342598 | 7360 | info->packets[info->numberPackets].valueSz = 0; |
wolfSSL | 0:9d17e4342598 | 7361 | else |
wolfSSL | 0:9d17e4342598 | 7362 | XMEMCPY(info->packets[info->numberPackets].bufferValue, |
wolfSSL | 0:9d17e4342598 | 7363 | data, sz); |
wolfSSL | 0:9d17e4342598 | 7364 | } |
wolfSSL | 0:9d17e4342598 | 7365 | gettimeofday(&currTime, 0); |
wolfSSL | 0:9d17e4342598 | 7366 | info->packets[info->numberPackets].timestamp.tv_sec = |
wolfSSL | 0:9d17e4342598 | 7367 | currTime.tv_sec; |
wolfSSL | 0:9d17e4342598 | 7368 | info->packets[info->numberPackets].timestamp.tv_usec = |
wolfSSL | 0:9d17e4342598 | 7369 | currTime.tv_usec; |
wolfSSL | 0:9d17e4342598 | 7370 | info->numberPackets++; |
wolfSSL | 0:9d17e4342598 | 7371 | } |
wolfSSL | 0:9d17e4342598 | 7372 | } |
wolfSSL | 0:9d17e4342598 | 7373 | |
wolfSSL | 0:9d17e4342598 | 7374 | |
wolfSSL | 0:9d17e4342598 | 7375 | /* Add packet name to previsouly added packet info */ |
wolfSSL | 0:9d17e4342598 | 7376 | void AddLateName(const char* name, TimeoutInfo* info) |
wolfSSL | 0:9d17e4342598 | 7377 | { |
wolfSSL | 0:9d17e4342598 | 7378 | /* make sure we have a valid previous one */ |
wolfSSL | 0:9d17e4342598 | 7379 | if (info->numberPackets > 0 && info->numberPackets < |
wolfSSL | 0:9d17e4342598 | 7380 | MAX_PACKETS_HANDSHAKE) { |
wolfSSL | 0:9d17e4342598 | 7381 | XSTRNCPY(info->packets[info->numberPackets - 1].packetName, name, |
wolfSSL | 0:9d17e4342598 | 7382 | MAX_PACKETNAME_SZ); |
wolfSSL | 0:9d17e4342598 | 7383 | } |
wolfSSL | 0:9d17e4342598 | 7384 | } |
wolfSSL | 0:9d17e4342598 | 7385 | |
wolfSSL | 0:9d17e4342598 | 7386 | /* Add record header to previsouly added packet info */ |
wolfSSL | 0:9d17e4342598 | 7387 | void AddLateRecordHeader(const RecordLayerHeader* rl, TimeoutInfo* info) |
wolfSSL | 0:9d17e4342598 | 7388 | { |
wolfSSL | 0:9d17e4342598 | 7389 | /* make sure we have a valid previous one */ |
wolfSSL | 0:9d17e4342598 | 7390 | if (info->numberPackets > 0 && info->numberPackets < |
wolfSSL | 0:9d17e4342598 | 7391 | MAX_PACKETS_HANDSHAKE) { |
wolfSSL | 0:9d17e4342598 | 7392 | if (info->packets[info->numberPackets - 1].bufferValue) |
wolfSSL | 0:9d17e4342598 | 7393 | XMEMCPY(info->packets[info->numberPackets - 1].bufferValue, rl, |
wolfSSL | 0:9d17e4342598 | 7394 | RECORD_HEADER_SZ); |
wolfSSL | 0:9d17e4342598 | 7395 | else |
wolfSSL | 0:9d17e4342598 | 7396 | XMEMCPY(info->packets[info->numberPackets - 1].value, rl, |
wolfSSL | 0:9d17e4342598 | 7397 | RECORD_HEADER_SZ); |
wolfSSL | 0:9d17e4342598 | 7398 | } |
wolfSSL | 0:9d17e4342598 | 7399 | } |
wolfSSL | 0:9d17e4342598 | 7400 | |
wolfSSL | 0:9d17e4342598 | 7401 | #endif /* CYASSL_CALLBACKS */ |
wolfSSL | 0:9d17e4342598 | 7402 | |
wolfSSL | 0:9d17e4342598 | 7403 | |
wolfSSL | 0:9d17e4342598 | 7404 | |
wolfSSL | 0:9d17e4342598 | 7405 | /* client only parts */ |
wolfSSL | 0:9d17e4342598 | 7406 | #ifndef NO_CYASSL_CLIENT |
wolfSSL | 0:9d17e4342598 | 7407 | |
wolfSSL | 0:9d17e4342598 | 7408 | int SendClientHello(CYASSL* ssl) |
wolfSSL | 0:9d17e4342598 | 7409 | { |
wolfSSL | 0:9d17e4342598 | 7410 | byte *output; |
wolfSSL | 0:9d17e4342598 | 7411 | word32 length, idx = RECORD_HEADER_SZ + HANDSHAKE_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 7412 | int sendSz; |
wolfSSL | 0:9d17e4342598 | 7413 | int idSz = ssl->options.resuming ? ID_LEN : 0; |
wolfSSL | 0:9d17e4342598 | 7414 | int ret; |
wolfSSL | 0:9d17e4342598 | 7415 | |
wolfSSL | 0:9d17e4342598 | 7416 | if (ssl->suites == NULL) { |
wolfSSL | 0:9d17e4342598 | 7417 | CYASSL_MSG("Bad suites pointer in SendClientHello"); |
wolfSSL | 0:9d17e4342598 | 7418 | return SUITES_ERROR; |
wolfSSL | 0:9d17e4342598 | 7419 | } |
wolfSSL | 0:9d17e4342598 | 7420 | |
wolfSSL | 0:9d17e4342598 | 7421 | length = VERSION_SZ + RAN_LEN |
wolfSSL | 0:9d17e4342598 | 7422 | + idSz + ENUM_LEN |
wolfSSL | 0:9d17e4342598 | 7423 | + ssl->suites->suiteSz + SUITE_LEN |
wolfSSL | 0:9d17e4342598 | 7424 | + COMP_LEN + ENUM_LEN; |
wolfSSL | 0:9d17e4342598 | 7425 | |
wolfSSL | 0:9d17e4342598 | 7426 | #ifdef HAVE_TLS_EXTENSIONS |
wolfSSL | 0:9d17e4342598 | 7427 | length += TLSX_GetRequestSize(ssl); |
wolfSSL | 0:9d17e4342598 | 7428 | #else |
wolfSSL | 0:9d17e4342598 | 7429 | if (IsAtLeastTLSv1_2(ssl) && ssl->suites->hashSigAlgoSz) { |
wolfSSL | 0:9d17e4342598 | 7430 | length += ssl->suites->hashSigAlgoSz + HELLO_EXT_SZ; |
wolfSSL | 0:9d17e4342598 | 7431 | } |
wolfSSL | 0:9d17e4342598 | 7432 | #endif |
wolfSSL | 0:9d17e4342598 | 7433 | sendSz = length + HANDSHAKE_HEADER_SZ + RECORD_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 7434 | |
wolfSSL | 0:9d17e4342598 | 7435 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 7436 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 7437 | length += ENUM_LEN; /* cookie */ |
wolfSSL | 0:9d17e4342598 | 7438 | if (ssl->arrays->cookieSz != 0) length += ssl->arrays->cookieSz; |
wolfSSL | 0:9d17e4342598 | 7439 | sendSz = length + DTLS_HANDSHAKE_HEADER_SZ + DTLS_RECORD_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 7440 | idx += DTLS_HANDSHAKE_EXTRA + DTLS_RECORD_EXTRA; |
wolfSSL | 0:9d17e4342598 | 7441 | } |
wolfSSL | 0:9d17e4342598 | 7442 | #endif |
wolfSSL | 0:9d17e4342598 | 7443 | |
wolfSSL | 0:9d17e4342598 | 7444 | /* check for available size */ |
wolfSSL | 0:9d17e4342598 | 7445 | if ((ret = CheckAvailableSize(ssl, sendSz)) != 0) |
wolfSSL | 0:9d17e4342598 | 7446 | return ret; |
wolfSSL | 0:9d17e4342598 | 7447 | |
wolfSSL | 0:9d17e4342598 | 7448 | /* get ouput buffer */ |
wolfSSL | 0:9d17e4342598 | 7449 | output = ssl->buffers.outputBuffer.buffer + |
wolfSSL | 0:9d17e4342598 | 7450 | ssl->buffers.outputBuffer.length; |
wolfSSL | 0:9d17e4342598 | 7451 | |
wolfSSL | 0:9d17e4342598 | 7452 | AddHeaders(output, length, client_hello, ssl); |
wolfSSL | 0:9d17e4342598 | 7453 | |
wolfSSL | 0:9d17e4342598 | 7454 | /* client hello, first version */ |
wolfSSL | 0:9d17e4342598 | 7455 | output[idx++] = ssl->version.major; |
wolfSSL | 0:9d17e4342598 | 7456 | output[idx++] = ssl->version.minor; |
wolfSSL | 0:9d17e4342598 | 7457 | ssl->chVersion = ssl->version; /* store in case changed */ |
wolfSSL | 0:9d17e4342598 | 7458 | |
wolfSSL | 0:9d17e4342598 | 7459 | /* then random */ |
wolfSSL | 0:9d17e4342598 | 7460 | if (ssl->options.connectState == CONNECT_BEGIN) { |
wolfSSL | 0:9d17e4342598 | 7461 | RNG_GenerateBlock(ssl->rng, output + idx, RAN_LEN); |
wolfSSL | 0:9d17e4342598 | 7462 | |
wolfSSL | 0:9d17e4342598 | 7463 | /* store random */ |
wolfSSL | 0:9d17e4342598 | 7464 | XMEMCPY(ssl->arrays->clientRandom, output + idx, RAN_LEN); |
wolfSSL | 0:9d17e4342598 | 7465 | } else { |
wolfSSL | 0:9d17e4342598 | 7466 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 7467 | /* send same random on hello again */ |
wolfSSL | 0:9d17e4342598 | 7468 | XMEMCPY(output + idx, ssl->arrays->clientRandom, RAN_LEN); |
wolfSSL | 0:9d17e4342598 | 7469 | #endif |
wolfSSL | 0:9d17e4342598 | 7470 | } |
wolfSSL | 0:9d17e4342598 | 7471 | idx += RAN_LEN; |
wolfSSL | 0:9d17e4342598 | 7472 | |
wolfSSL | 0:9d17e4342598 | 7473 | /* then session id */ |
wolfSSL | 0:9d17e4342598 | 7474 | output[idx++] = (byte)idSz; |
wolfSSL | 0:9d17e4342598 | 7475 | if (idSz) { |
wolfSSL | 0:9d17e4342598 | 7476 | XMEMCPY(output + idx, ssl->session.sessionID, ID_LEN); |
wolfSSL | 0:9d17e4342598 | 7477 | idx += ID_LEN; |
wolfSSL | 0:9d17e4342598 | 7478 | } |
wolfSSL | 0:9d17e4342598 | 7479 | |
wolfSSL | 0:9d17e4342598 | 7480 | /* then DTLS cookie */ |
wolfSSL | 0:9d17e4342598 | 7481 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 7482 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 7483 | byte cookieSz = ssl->arrays->cookieSz; |
wolfSSL | 0:9d17e4342598 | 7484 | |
wolfSSL | 0:9d17e4342598 | 7485 | output[idx++] = cookieSz; |
wolfSSL | 0:9d17e4342598 | 7486 | if (cookieSz) { |
wolfSSL | 0:9d17e4342598 | 7487 | XMEMCPY(&output[idx], ssl->arrays->cookie, cookieSz); |
wolfSSL | 0:9d17e4342598 | 7488 | idx += cookieSz; |
wolfSSL | 0:9d17e4342598 | 7489 | } |
wolfSSL | 0:9d17e4342598 | 7490 | } |
wolfSSL | 0:9d17e4342598 | 7491 | #endif |
wolfSSL | 0:9d17e4342598 | 7492 | /* then cipher suites */ |
wolfSSL | 0:9d17e4342598 | 7493 | c16toa(ssl->suites->suiteSz, output + idx); |
wolfSSL | 0:9d17e4342598 | 7494 | idx += 2; |
wolfSSL | 0:9d17e4342598 | 7495 | XMEMCPY(output + idx, &ssl->suites->suites, ssl->suites->suiteSz); |
wolfSSL | 0:9d17e4342598 | 7496 | idx += ssl->suites->suiteSz; |
wolfSSL | 0:9d17e4342598 | 7497 | |
wolfSSL | 0:9d17e4342598 | 7498 | /* last, compression */ |
wolfSSL | 0:9d17e4342598 | 7499 | output[idx++] = COMP_LEN; |
wolfSSL | 0:9d17e4342598 | 7500 | if (ssl->options.usingCompression) |
wolfSSL | 0:9d17e4342598 | 7501 | output[idx++] = ZLIB_COMPRESSION; |
wolfSSL | 0:9d17e4342598 | 7502 | else |
wolfSSL | 0:9d17e4342598 | 7503 | output[idx++] = NO_COMPRESSION; |
wolfSSL | 0:9d17e4342598 | 7504 | |
wolfSSL | 0:9d17e4342598 | 7505 | #ifdef HAVE_TLS_EXTENSIONS |
wolfSSL | 0:9d17e4342598 | 7506 | idx += TLSX_WriteRequest(ssl, output + idx); |
wolfSSL | 0:9d17e4342598 | 7507 | |
wolfSSL | 0:9d17e4342598 | 7508 | (void)idx; /* suppress analyzer warning, keep idx current */ |
wolfSSL | 0:9d17e4342598 | 7509 | #else |
wolfSSL | 0:9d17e4342598 | 7510 | if (IsAtLeastTLSv1_2(ssl) && ssl->suites->hashSigAlgoSz) |
wolfSSL | 0:9d17e4342598 | 7511 | { |
wolfSSL | 0:9d17e4342598 | 7512 | int i; |
wolfSSL | 0:9d17e4342598 | 7513 | /* add in the extensions length */ |
wolfSSL | 0:9d17e4342598 | 7514 | c16toa(HELLO_EXT_LEN + ssl->suites->hashSigAlgoSz, output + idx); |
wolfSSL | 0:9d17e4342598 | 7515 | idx += 2; |
wolfSSL | 0:9d17e4342598 | 7516 | |
wolfSSL | 0:9d17e4342598 | 7517 | c16toa(HELLO_EXT_SIG_ALGO, output + idx); |
wolfSSL | 0:9d17e4342598 | 7518 | idx += 2; |
wolfSSL | 0:9d17e4342598 | 7519 | c16toa(HELLO_EXT_SIGALGO_SZ+ssl->suites->hashSigAlgoSz, output+idx); |
wolfSSL | 0:9d17e4342598 | 7520 | idx += 2; |
wolfSSL | 0:9d17e4342598 | 7521 | c16toa(ssl->suites->hashSigAlgoSz, output + idx); |
wolfSSL | 0:9d17e4342598 | 7522 | idx += 2; |
wolfSSL | 0:9d17e4342598 | 7523 | for (i = 0; i < ssl->suites->hashSigAlgoSz; i++, idx++) { |
wolfSSL | 0:9d17e4342598 | 7524 | output[idx] = ssl->suites->hashSigAlgo[i]; |
wolfSSL | 0:9d17e4342598 | 7525 | } |
wolfSSL | 0:9d17e4342598 | 7526 | } |
wolfSSL | 0:9d17e4342598 | 7527 | #endif |
wolfSSL | 0:9d17e4342598 | 7528 | |
wolfSSL | 0:9d17e4342598 | 7529 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 7530 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 7531 | if ((ret = DtlsPoolSave(ssl, output, sendSz)) != 0) |
wolfSSL | 0:9d17e4342598 | 7532 | return ret; |
wolfSSL | 0:9d17e4342598 | 7533 | } |
wolfSSL | 0:9d17e4342598 | 7534 | #endif |
wolfSSL | 0:9d17e4342598 | 7535 | HashOutput(ssl, output, sendSz, 0); |
wolfSSL | 0:9d17e4342598 | 7536 | |
wolfSSL | 0:9d17e4342598 | 7537 | ssl->options.clientState = CLIENT_HELLO_COMPLETE; |
wolfSSL | 0:9d17e4342598 | 7538 | |
wolfSSL | 0:9d17e4342598 | 7539 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 7540 | if (ssl->hsInfoOn) AddPacketName("ClientHello", &ssl->handShakeInfo); |
wolfSSL | 0:9d17e4342598 | 7541 | if (ssl->toInfoOn) |
wolfSSL | 0:9d17e4342598 | 7542 | AddPacketInfo("ClientHello", &ssl->timeoutInfo, output, sendSz, |
wolfSSL | 0:9d17e4342598 | 7543 | ssl->heap); |
wolfSSL | 0:9d17e4342598 | 7544 | #endif |
wolfSSL | 0:9d17e4342598 | 7545 | |
wolfSSL | 0:9d17e4342598 | 7546 | ssl->buffers.outputBuffer.length += sendSz; |
wolfSSL | 0:9d17e4342598 | 7547 | |
wolfSSL | 0:9d17e4342598 | 7548 | return SendBuffered(ssl); |
wolfSSL | 0:9d17e4342598 | 7549 | } |
wolfSSL | 0:9d17e4342598 | 7550 | |
wolfSSL | 0:9d17e4342598 | 7551 | |
wolfSSL | 0:9d17e4342598 | 7552 | static int DoHelloVerifyRequest(CYASSL* ssl, const byte* input, |
wolfSSL | 0:9d17e4342598 | 7553 | word32* inOutIdx, word32 size) |
wolfSSL | 0:9d17e4342598 | 7554 | { |
wolfSSL | 0:9d17e4342598 | 7555 | ProtocolVersion pv; |
wolfSSL | 0:9d17e4342598 | 7556 | byte cookieSz; |
wolfSSL | 0:9d17e4342598 | 7557 | word32 begin = *inOutIdx; |
wolfSSL | 0:9d17e4342598 | 7558 | |
wolfSSL | 0:9d17e4342598 | 7559 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 7560 | if (ssl->hsInfoOn) AddPacketName("HelloVerifyRequest", |
wolfSSL | 0:9d17e4342598 | 7561 | &ssl->handShakeInfo); |
wolfSSL | 0:9d17e4342598 | 7562 | if (ssl->toInfoOn) AddLateName("HelloVerifyRequest", &ssl->timeoutInfo); |
wolfSSL | 0:9d17e4342598 | 7563 | #endif |
wolfSSL | 0:9d17e4342598 | 7564 | |
wolfSSL | 0:9d17e4342598 | 7565 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 7566 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 7567 | DtlsPoolReset(ssl); |
wolfSSL | 0:9d17e4342598 | 7568 | } |
wolfSSL | 0:9d17e4342598 | 7569 | #endif |
wolfSSL | 0:9d17e4342598 | 7570 | |
wolfSSL | 0:9d17e4342598 | 7571 | if ((*inOutIdx - begin) + OPAQUE16_LEN + OPAQUE8_LEN > size) |
wolfSSL | 0:9d17e4342598 | 7572 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 7573 | |
wolfSSL | 0:9d17e4342598 | 7574 | XMEMCPY(&pv, input + *inOutIdx, OPAQUE16_LEN); |
wolfSSL | 0:9d17e4342598 | 7575 | *inOutIdx += OPAQUE16_LEN; |
wolfSSL | 0:9d17e4342598 | 7576 | |
wolfSSL | 0:9d17e4342598 | 7577 | cookieSz = input[(*inOutIdx)++]; |
wolfSSL | 0:9d17e4342598 | 7578 | |
wolfSSL | 0:9d17e4342598 | 7579 | if (cookieSz) { |
wolfSSL | 0:9d17e4342598 | 7580 | if ((*inOutIdx - begin) + cookieSz > size) |
wolfSSL | 0:9d17e4342598 | 7581 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 7582 | |
wolfSSL | 0:9d17e4342598 | 7583 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 7584 | if (cookieSz <= MAX_COOKIE_LEN) { |
wolfSSL | 0:9d17e4342598 | 7585 | XMEMCPY(ssl->arrays->cookie, input + *inOutIdx, cookieSz); |
wolfSSL | 0:9d17e4342598 | 7586 | ssl->arrays->cookieSz = cookieSz; |
wolfSSL | 0:9d17e4342598 | 7587 | } |
wolfSSL | 0:9d17e4342598 | 7588 | #endif |
wolfSSL | 0:9d17e4342598 | 7589 | *inOutIdx += cookieSz; |
wolfSSL | 0:9d17e4342598 | 7590 | } |
wolfSSL | 0:9d17e4342598 | 7591 | |
wolfSSL | 0:9d17e4342598 | 7592 | ssl->options.serverState = SERVER_HELLOVERIFYREQUEST_COMPLETE; |
wolfSSL | 0:9d17e4342598 | 7593 | return 0; |
wolfSSL | 0:9d17e4342598 | 7594 | } |
wolfSSL | 0:9d17e4342598 | 7595 | |
wolfSSL | 0:9d17e4342598 | 7596 | |
wolfSSL | 0:9d17e4342598 | 7597 | static int DoServerHello(CYASSL* ssl, const byte* input, word32* inOutIdx, |
wolfSSL | 0:9d17e4342598 | 7598 | word32 helloSz) |
wolfSSL | 0:9d17e4342598 | 7599 | { |
wolfSSL | 0:9d17e4342598 | 7600 | byte b; |
wolfSSL | 0:9d17e4342598 | 7601 | ProtocolVersion pv; |
wolfSSL | 0:9d17e4342598 | 7602 | byte compression; |
wolfSSL | 0:9d17e4342598 | 7603 | word32 i = *inOutIdx; |
wolfSSL | 0:9d17e4342598 | 7604 | word32 begin = i; |
wolfSSL | 0:9d17e4342598 | 7605 | |
wolfSSL | 0:9d17e4342598 | 7606 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 7607 | if (ssl->hsInfoOn) AddPacketName("ServerHello", &ssl->handShakeInfo); |
wolfSSL | 0:9d17e4342598 | 7608 | if (ssl->toInfoOn) AddLateName("ServerHello", &ssl->timeoutInfo); |
wolfSSL | 0:9d17e4342598 | 7609 | #endif |
wolfSSL | 0:9d17e4342598 | 7610 | |
wolfSSL | 0:9d17e4342598 | 7611 | /* protocol version, random and session id length check */ |
wolfSSL | 0:9d17e4342598 | 7612 | if ((i - begin) + OPAQUE16_LEN + RAN_LEN + OPAQUE8_LEN > helloSz) |
wolfSSL | 0:9d17e4342598 | 7613 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 7614 | |
wolfSSL | 0:9d17e4342598 | 7615 | /* protocol version */ |
wolfSSL | 0:9d17e4342598 | 7616 | XMEMCPY(&pv, input + i, OPAQUE16_LEN); |
wolfSSL | 0:9d17e4342598 | 7617 | i += OPAQUE16_LEN; |
wolfSSL | 0:9d17e4342598 | 7618 | |
wolfSSL | 0:9d17e4342598 | 7619 | if (pv.minor > ssl->version.minor) { |
wolfSSL | 0:9d17e4342598 | 7620 | CYASSL_MSG("Server using higher version, fatal error"); |
wolfSSL | 0:9d17e4342598 | 7621 | return VERSION_ERROR; |
wolfSSL | 0:9d17e4342598 | 7622 | } |
wolfSSL | 0:9d17e4342598 | 7623 | else if (pv.minor < ssl->version.minor) { |
wolfSSL | 0:9d17e4342598 | 7624 | CYASSL_MSG("server using lower version"); |
wolfSSL | 0:9d17e4342598 | 7625 | |
wolfSSL | 0:9d17e4342598 | 7626 | if (!ssl->options.downgrade) { |
wolfSSL | 0:9d17e4342598 | 7627 | CYASSL_MSG(" no downgrade allowed, fatal error"); |
wolfSSL | 0:9d17e4342598 | 7628 | return VERSION_ERROR; |
wolfSSL | 0:9d17e4342598 | 7629 | } |
wolfSSL | 0:9d17e4342598 | 7630 | |
wolfSSL | 0:9d17e4342598 | 7631 | if (pv.minor == SSLv3_MINOR) { |
wolfSSL | 0:9d17e4342598 | 7632 | /* turn off tls */ |
wolfSSL | 0:9d17e4342598 | 7633 | CYASSL_MSG(" downgrading to SSLv3"); |
wolfSSL | 0:9d17e4342598 | 7634 | ssl->options.tls = 0; |
wolfSSL | 0:9d17e4342598 | 7635 | ssl->options.tls1_1 = 0; |
wolfSSL | 0:9d17e4342598 | 7636 | ssl->version.minor = SSLv3_MINOR; |
wolfSSL | 0:9d17e4342598 | 7637 | } |
wolfSSL | 0:9d17e4342598 | 7638 | else if (pv.minor == TLSv1_MINOR) { |
wolfSSL | 0:9d17e4342598 | 7639 | /* turn off tls 1.1+ */ |
wolfSSL | 0:9d17e4342598 | 7640 | CYASSL_MSG(" downgrading to TLSv1"); |
wolfSSL | 0:9d17e4342598 | 7641 | ssl->options.tls1_1 = 0; |
wolfSSL | 0:9d17e4342598 | 7642 | ssl->version.minor = TLSv1_MINOR; |
wolfSSL | 0:9d17e4342598 | 7643 | } |
wolfSSL | 0:9d17e4342598 | 7644 | else if (pv.minor == TLSv1_1_MINOR) { |
wolfSSL | 0:9d17e4342598 | 7645 | CYASSL_MSG(" downgrading to TLSv1.1"); |
wolfSSL | 0:9d17e4342598 | 7646 | ssl->version.minor = TLSv1_1_MINOR; |
wolfSSL | 0:9d17e4342598 | 7647 | } |
wolfSSL | 0:9d17e4342598 | 7648 | } |
wolfSSL | 0:9d17e4342598 | 7649 | |
wolfSSL | 0:9d17e4342598 | 7650 | /* random */ |
wolfSSL | 0:9d17e4342598 | 7651 | XMEMCPY(ssl->arrays->serverRandom, input + i, RAN_LEN); |
wolfSSL | 0:9d17e4342598 | 7652 | i += RAN_LEN; |
wolfSSL | 0:9d17e4342598 | 7653 | |
wolfSSL | 0:9d17e4342598 | 7654 | /* session id */ |
wolfSSL | 0:9d17e4342598 | 7655 | b = input[i++]; |
wolfSSL | 0:9d17e4342598 | 7656 | |
wolfSSL | 0:9d17e4342598 | 7657 | if (b == ID_LEN) { |
wolfSSL | 0:9d17e4342598 | 7658 | if ((i - begin) + ID_LEN > helloSz) |
wolfSSL | 0:9d17e4342598 | 7659 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 7660 | |
wolfSSL | 0:9d17e4342598 | 7661 | XMEMCPY(ssl->arrays->sessionID, input + i, min(b, ID_LEN)); |
wolfSSL | 0:9d17e4342598 | 7662 | i += ID_LEN; |
wolfSSL | 0:9d17e4342598 | 7663 | ssl->options.haveSessionId = 1; |
wolfSSL | 0:9d17e4342598 | 7664 | } |
wolfSSL | 0:9d17e4342598 | 7665 | else if (b) { |
wolfSSL | 0:9d17e4342598 | 7666 | CYASSL_MSG("Invalid session ID size"); |
wolfSSL | 0:9d17e4342598 | 7667 | return BUFFER_ERROR; /* session ID nor 0 neither 32 bytes long */ |
wolfSSL | 0:9d17e4342598 | 7668 | } |
wolfSSL | 0:9d17e4342598 | 7669 | |
wolfSSL | 0:9d17e4342598 | 7670 | /* suite and compression */ |
wolfSSL | 0:9d17e4342598 | 7671 | if ((i - begin) + OPAQUE16_LEN + OPAQUE8_LEN > helloSz) |
wolfSSL | 0:9d17e4342598 | 7672 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 7673 | |
wolfSSL | 0:9d17e4342598 | 7674 | ssl->options.cipherSuite0 = input[i++]; |
wolfSSL | 0:9d17e4342598 | 7675 | ssl->options.cipherSuite = input[i++]; |
wolfSSL | 0:9d17e4342598 | 7676 | compression = input[i++]; |
wolfSSL | 0:9d17e4342598 | 7677 | |
wolfSSL | 0:9d17e4342598 | 7678 | if (compression != ZLIB_COMPRESSION && ssl->options.usingCompression) { |
wolfSSL | 0:9d17e4342598 | 7679 | CYASSL_MSG("Server refused compression, turning off"); |
wolfSSL | 0:9d17e4342598 | 7680 | ssl->options.usingCompression = 0; /* turn off if server refused */ |
wolfSSL | 0:9d17e4342598 | 7681 | } |
wolfSSL | 0:9d17e4342598 | 7682 | |
wolfSSL | 0:9d17e4342598 | 7683 | *inOutIdx = i; |
wolfSSL | 0:9d17e4342598 | 7684 | |
wolfSSL | 0:9d17e4342598 | 7685 | /* tls extensions */ |
wolfSSL | 0:9d17e4342598 | 7686 | if ( (i - begin) < helloSz) { |
wolfSSL | 0:9d17e4342598 | 7687 | #ifdef HAVE_TLS_EXTENSIONS |
wolfSSL | 0:9d17e4342598 | 7688 | if (IsTLS(ssl)) { |
wolfSSL | 0:9d17e4342598 | 7689 | int ret = 0; |
wolfSSL | 0:9d17e4342598 | 7690 | word16 totalExtSz; |
wolfSSL | 0:9d17e4342598 | 7691 | Suites clSuites; /* just for compatibility right now */ |
wolfSSL | 0:9d17e4342598 | 7692 | |
wolfSSL | 0:9d17e4342598 | 7693 | if ((i - begin) + OPAQUE16_LEN > helloSz) |
wolfSSL | 0:9d17e4342598 | 7694 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 7695 | |
wolfSSL | 0:9d17e4342598 | 7696 | ato16(&input[i], &totalExtSz); |
wolfSSL | 0:9d17e4342598 | 7697 | i += OPAQUE16_LEN; |
wolfSSL | 0:9d17e4342598 | 7698 | |
wolfSSL | 0:9d17e4342598 | 7699 | if ((i - begin) + totalExtSz > helloSz) |
wolfSSL | 0:9d17e4342598 | 7700 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 7701 | |
wolfSSL | 0:9d17e4342598 | 7702 | if ((ret = TLSX_Parse(ssl, (byte *) input + i, |
wolfSSL | 0:9d17e4342598 | 7703 | totalExtSz, 0, &clSuites))) |
wolfSSL | 0:9d17e4342598 | 7704 | return ret; |
wolfSSL | 0:9d17e4342598 | 7705 | |
wolfSSL | 0:9d17e4342598 | 7706 | i += totalExtSz; |
wolfSSL | 0:9d17e4342598 | 7707 | *inOutIdx = i; |
wolfSSL | 0:9d17e4342598 | 7708 | } |
wolfSSL | 0:9d17e4342598 | 7709 | else |
wolfSSL | 0:9d17e4342598 | 7710 | #endif |
wolfSSL | 0:9d17e4342598 | 7711 | *inOutIdx = begin + helloSz; /* skip extensions */ |
wolfSSL | 0:9d17e4342598 | 7712 | } |
wolfSSL | 0:9d17e4342598 | 7713 | |
wolfSSL | 0:9d17e4342598 | 7714 | ssl->options.serverState = SERVER_HELLO_COMPLETE; |
wolfSSL | 0:9d17e4342598 | 7715 | |
wolfSSL | 0:9d17e4342598 | 7716 | if (ssl->options.resuming) { |
wolfSSL | 0:9d17e4342598 | 7717 | if (ssl->options.haveSessionId && XMEMCMP(ssl->arrays->sessionID, |
wolfSSL | 0:9d17e4342598 | 7718 | ssl->session.sessionID, ID_LEN) == 0) { |
wolfSSL | 0:9d17e4342598 | 7719 | if (SetCipherSpecs(ssl) == 0) { |
wolfSSL | 0:9d17e4342598 | 7720 | int ret = -1; |
wolfSSL | 0:9d17e4342598 | 7721 | |
wolfSSL | 0:9d17e4342598 | 7722 | XMEMCPY(ssl->arrays->masterSecret, |
wolfSSL | 0:9d17e4342598 | 7723 | ssl->session.masterSecret, SECRET_LEN); |
wolfSSL | 0:9d17e4342598 | 7724 | #ifdef NO_OLD_TLS |
wolfSSL | 0:9d17e4342598 | 7725 | ret = DeriveTlsKeys(ssl); |
wolfSSL | 0:9d17e4342598 | 7726 | #else |
wolfSSL | 0:9d17e4342598 | 7727 | #ifndef NO_TLS |
wolfSSL | 0:9d17e4342598 | 7728 | if (ssl->options.tls) |
wolfSSL | 0:9d17e4342598 | 7729 | ret = DeriveTlsKeys(ssl); |
wolfSSL | 0:9d17e4342598 | 7730 | #endif |
wolfSSL | 0:9d17e4342598 | 7731 | if (!ssl->options.tls) |
wolfSSL | 0:9d17e4342598 | 7732 | ret = DeriveKeys(ssl); |
wolfSSL | 0:9d17e4342598 | 7733 | #endif |
wolfSSL | 0:9d17e4342598 | 7734 | ssl->options.serverState = SERVER_HELLODONE_COMPLETE; |
wolfSSL | 0:9d17e4342598 | 7735 | |
wolfSSL | 0:9d17e4342598 | 7736 | return ret; |
wolfSSL | 0:9d17e4342598 | 7737 | } |
wolfSSL | 0:9d17e4342598 | 7738 | else { |
wolfSSL | 0:9d17e4342598 | 7739 | CYASSL_MSG("Unsupported cipher suite, DoServerHello"); |
wolfSSL | 0:9d17e4342598 | 7740 | return UNSUPPORTED_SUITE; |
wolfSSL | 0:9d17e4342598 | 7741 | } |
wolfSSL | 0:9d17e4342598 | 7742 | } |
wolfSSL | 0:9d17e4342598 | 7743 | else { |
wolfSSL | 0:9d17e4342598 | 7744 | CYASSL_MSG("Server denied resumption attempt"); |
wolfSSL | 0:9d17e4342598 | 7745 | ssl->options.resuming = 0; /* server denied resumption try */ |
wolfSSL | 0:9d17e4342598 | 7746 | } |
wolfSSL | 0:9d17e4342598 | 7747 | } |
wolfSSL | 0:9d17e4342598 | 7748 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 7749 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 7750 | DtlsPoolReset(ssl); |
wolfSSL | 0:9d17e4342598 | 7751 | } |
wolfSSL | 0:9d17e4342598 | 7752 | #endif |
wolfSSL | 0:9d17e4342598 | 7753 | |
wolfSSL | 0:9d17e4342598 | 7754 | return SetCipherSpecs(ssl); |
wolfSSL | 0:9d17e4342598 | 7755 | } |
wolfSSL | 0:9d17e4342598 | 7756 | |
wolfSSL | 0:9d17e4342598 | 7757 | |
wolfSSL | 0:9d17e4342598 | 7758 | #ifndef NO_CERTS |
wolfSSL | 0:9d17e4342598 | 7759 | /* just read in and ignore for now TODO: */ |
wolfSSL | 0:9d17e4342598 | 7760 | static int DoCertificateRequest(CYASSL* ssl, const byte* input, word32* |
wolfSSL | 0:9d17e4342598 | 7761 | inOutIdx, word32 size) |
wolfSSL | 0:9d17e4342598 | 7762 | { |
wolfSSL | 0:9d17e4342598 | 7763 | word16 len; |
wolfSSL | 0:9d17e4342598 | 7764 | word32 begin = *inOutIdx; |
wolfSSL | 0:9d17e4342598 | 7765 | |
wolfSSL | 0:9d17e4342598 | 7766 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 7767 | if (ssl->hsInfoOn) |
wolfSSL | 0:9d17e4342598 | 7768 | AddPacketName("CertificateRequest", &ssl->handShakeInfo); |
wolfSSL | 0:9d17e4342598 | 7769 | if (ssl->toInfoOn) |
wolfSSL | 0:9d17e4342598 | 7770 | AddLateName("CertificateRequest", &ssl->timeoutInfo); |
wolfSSL | 0:9d17e4342598 | 7771 | #endif |
wolfSSL | 0:9d17e4342598 | 7772 | |
wolfSSL | 0:9d17e4342598 | 7773 | if ((*inOutIdx - begin) + OPAQUE8_LEN > size) |
wolfSSL | 0:9d17e4342598 | 7774 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 7775 | |
wolfSSL | 0:9d17e4342598 | 7776 | len = input[(*inOutIdx)++]; |
wolfSSL | 0:9d17e4342598 | 7777 | |
wolfSSL | 0:9d17e4342598 | 7778 | if ((*inOutIdx - begin) + len > size) |
wolfSSL | 0:9d17e4342598 | 7779 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 7780 | |
wolfSSL | 0:9d17e4342598 | 7781 | /* types, read in here */ |
wolfSSL | 0:9d17e4342598 | 7782 | *inOutIdx += len; |
wolfSSL | 0:9d17e4342598 | 7783 | |
wolfSSL | 0:9d17e4342598 | 7784 | /* signature and hash signature algorithm */ |
wolfSSL | 0:9d17e4342598 | 7785 | if (IsAtLeastTLSv1_2(ssl)) { |
wolfSSL | 0:9d17e4342598 | 7786 | if ((*inOutIdx - begin) + OPAQUE16_LEN > size) |
wolfSSL | 0:9d17e4342598 | 7787 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 7788 | |
wolfSSL | 0:9d17e4342598 | 7789 | ato16(input + *inOutIdx, &len); |
wolfSSL | 0:9d17e4342598 | 7790 | *inOutIdx += OPAQUE16_LEN; |
wolfSSL | 0:9d17e4342598 | 7791 | |
wolfSSL | 0:9d17e4342598 | 7792 | if ((*inOutIdx - begin) + len > size) |
wolfSSL | 0:9d17e4342598 | 7793 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 7794 | |
wolfSSL | 0:9d17e4342598 | 7795 | PickHashSigAlgo(ssl, input + *inOutIdx, len); |
wolfSSL | 0:9d17e4342598 | 7796 | *inOutIdx += len; |
wolfSSL | 0:9d17e4342598 | 7797 | } |
wolfSSL | 0:9d17e4342598 | 7798 | |
wolfSSL | 0:9d17e4342598 | 7799 | /* authorities */ |
wolfSSL | 0:9d17e4342598 | 7800 | if ((*inOutIdx - begin) + OPAQUE16_LEN > size) |
wolfSSL | 0:9d17e4342598 | 7801 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 7802 | |
wolfSSL | 0:9d17e4342598 | 7803 | ato16(input + *inOutIdx, &len); |
wolfSSL | 0:9d17e4342598 | 7804 | *inOutIdx += OPAQUE16_LEN; |
wolfSSL | 0:9d17e4342598 | 7805 | |
wolfSSL | 0:9d17e4342598 | 7806 | if ((*inOutIdx - begin) + len > size) |
wolfSSL | 0:9d17e4342598 | 7807 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 7808 | |
wolfSSL | 0:9d17e4342598 | 7809 | while (len) { |
wolfSSL | 0:9d17e4342598 | 7810 | word16 dnSz; |
wolfSSL | 0:9d17e4342598 | 7811 | |
wolfSSL | 0:9d17e4342598 | 7812 | if ((*inOutIdx - begin) + OPAQUE16_LEN > size) |
wolfSSL | 0:9d17e4342598 | 7813 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 7814 | |
wolfSSL | 0:9d17e4342598 | 7815 | ato16(input + *inOutIdx, &dnSz); |
wolfSSL | 0:9d17e4342598 | 7816 | *inOutIdx += OPAQUE16_LEN; |
wolfSSL | 0:9d17e4342598 | 7817 | |
wolfSSL | 0:9d17e4342598 | 7818 | if ((*inOutIdx - begin) + dnSz > size) |
wolfSSL | 0:9d17e4342598 | 7819 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 7820 | |
wolfSSL | 0:9d17e4342598 | 7821 | *inOutIdx += dnSz; |
wolfSSL | 0:9d17e4342598 | 7822 | len -= OPAQUE16_LEN + dnSz; |
wolfSSL | 0:9d17e4342598 | 7823 | } |
wolfSSL | 0:9d17e4342598 | 7824 | |
wolfSSL | 0:9d17e4342598 | 7825 | /* don't send client cert or cert verify if user hasn't provided |
wolfSSL | 0:9d17e4342598 | 7826 | cert and private key */ |
wolfSSL | 0:9d17e4342598 | 7827 | if (ssl->buffers.certificate.buffer && ssl->buffers.key.buffer) |
wolfSSL | 0:9d17e4342598 | 7828 | ssl->options.sendVerify = SEND_CERT; |
wolfSSL | 0:9d17e4342598 | 7829 | else if (IsTLS(ssl)) |
wolfSSL | 0:9d17e4342598 | 7830 | ssl->options.sendVerify = SEND_BLANK_CERT; |
wolfSSL | 0:9d17e4342598 | 7831 | |
wolfSSL | 0:9d17e4342598 | 7832 | return 0; |
wolfSSL | 0:9d17e4342598 | 7833 | } |
wolfSSL | 0:9d17e4342598 | 7834 | #endif /* !NO_CERTS */ |
wolfSSL | 0:9d17e4342598 | 7835 | |
wolfSSL | 0:9d17e4342598 | 7836 | |
wolfSSL | 0:9d17e4342598 | 7837 | static int DoServerKeyExchange(CYASSL* ssl, const byte* input, |
wolfSSL | 0:9d17e4342598 | 7838 | word32* inOutIdx, word32 size) |
wolfSSL | 0:9d17e4342598 | 7839 | { |
wolfSSL | 0:9d17e4342598 | 7840 | word16 length = 0; |
wolfSSL | 0:9d17e4342598 | 7841 | word32 begin = *inOutIdx; |
wolfSSL | 0:9d17e4342598 | 7842 | int ret = 0; |
wolfSSL | 0:9d17e4342598 | 7843 | |
wolfSSL | 0:9d17e4342598 | 7844 | (void)length; /* shut up compiler warnings */ |
wolfSSL | 0:9d17e4342598 | 7845 | (void)begin; |
wolfSSL | 0:9d17e4342598 | 7846 | (void)ssl; |
wolfSSL | 0:9d17e4342598 | 7847 | (void)input; |
wolfSSL | 0:9d17e4342598 | 7848 | (void)size; |
wolfSSL | 0:9d17e4342598 | 7849 | (void)ret; |
wolfSSL | 0:9d17e4342598 | 7850 | |
wolfSSL | 0:9d17e4342598 | 7851 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 7852 | if (ssl->hsInfoOn) |
wolfSSL | 0:9d17e4342598 | 7853 | AddPacketName("ServerKeyExchange", &ssl->handShakeInfo); |
wolfSSL | 0:9d17e4342598 | 7854 | if (ssl->toInfoOn) |
wolfSSL | 0:9d17e4342598 | 7855 | AddLateName("ServerKeyExchange", &ssl->timeoutInfo); |
wolfSSL | 0:9d17e4342598 | 7856 | #endif |
wolfSSL | 0:9d17e4342598 | 7857 | |
wolfSSL | 0:9d17e4342598 | 7858 | #ifndef NO_PSK |
wolfSSL | 0:9d17e4342598 | 7859 | if (ssl->specs.kea == psk_kea) { |
wolfSSL | 0:9d17e4342598 | 7860 | |
wolfSSL | 0:9d17e4342598 | 7861 | if ((*inOutIdx - begin) + OPAQUE16_LEN > size) |
wolfSSL | 0:9d17e4342598 | 7862 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 7863 | |
wolfSSL | 0:9d17e4342598 | 7864 | ato16(input + *inOutIdx, &length); |
wolfSSL | 0:9d17e4342598 | 7865 | *inOutIdx += OPAQUE16_LEN; |
wolfSSL | 0:9d17e4342598 | 7866 | |
wolfSSL | 0:9d17e4342598 | 7867 | if ((*inOutIdx - begin) + length > size) |
wolfSSL | 0:9d17e4342598 | 7868 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 7869 | |
wolfSSL | 0:9d17e4342598 | 7870 | XMEMCPY(ssl->arrays->server_hint, input + *inOutIdx, |
wolfSSL | 0:9d17e4342598 | 7871 | min(length, MAX_PSK_ID_LEN)); |
wolfSSL | 0:9d17e4342598 | 7872 | |
wolfSSL | 0:9d17e4342598 | 7873 | ssl->arrays->server_hint[min(length, MAX_PSK_ID_LEN - 1)] = 0; |
wolfSSL | 0:9d17e4342598 | 7874 | *inOutIdx += length; |
wolfSSL | 0:9d17e4342598 | 7875 | |
wolfSSL | 0:9d17e4342598 | 7876 | return 0; |
wolfSSL | 0:9d17e4342598 | 7877 | } |
wolfSSL | 0:9d17e4342598 | 7878 | #endif |
wolfSSL | 0:9d17e4342598 | 7879 | #ifdef OPENSSL_EXTRA |
wolfSSL | 0:9d17e4342598 | 7880 | if (ssl->specs.kea == diffie_hellman_kea) |
wolfSSL | 0:9d17e4342598 | 7881 | { |
wolfSSL | 0:9d17e4342598 | 7882 | /* p */ |
wolfSSL | 0:9d17e4342598 | 7883 | if ((*inOutIdx - begin) + OPAQUE16_LEN > size) |
wolfSSL | 0:9d17e4342598 | 7884 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 7885 | |
wolfSSL | 0:9d17e4342598 | 7886 | ato16(input + *inOutIdx, &length); |
wolfSSL | 0:9d17e4342598 | 7887 | *inOutIdx += OPAQUE16_LEN; |
wolfSSL | 0:9d17e4342598 | 7888 | |
wolfSSL | 0:9d17e4342598 | 7889 | if ((*inOutIdx - begin) + length > size) |
wolfSSL | 0:9d17e4342598 | 7890 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 7891 | |
wolfSSL | 0:9d17e4342598 | 7892 | ssl->buffers.serverDH_P.buffer = (byte*) XMALLOC(length, ssl->heap, |
wolfSSL | 0:9d17e4342598 | 7893 | DYNAMIC_TYPE_DH); |
wolfSSL | 0:9d17e4342598 | 7894 | |
wolfSSL | 0:9d17e4342598 | 7895 | if (ssl->buffers.serverDH_P.buffer) |
wolfSSL | 0:9d17e4342598 | 7896 | ssl->buffers.serverDH_P.length = length; |
wolfSSL | 0:9d17e4342598 | 7897 | else |
wolfSSL | 0:9d17e4342598 | 7898 | return MEMORY_ERROR; |
wolfSSL | 0:9d17e4342598 | 7899 | |
wolfSSL | 0:9d17e4342598 | 7900 | XMEMCPY(ssl->buffers.serverDH_P.buffer, input + *inOutIdx, length); |
wolfSSL | 0:9d17e4342598 | 7901 | *inOutIdx += length; |
wolfSSL | 0:9d17e4342598 | 7902 | |
wolfSSL | 0:9d17e4342598 | 7903 | /* g */ |
wolfSSL | 0:9d17e4342598 | 7904 | if ((*inOutIdx - begin) + OPAQUE16_LEN > size) |
wolfSSL | 0:9d17e4342598 | 7905 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 7906 | |
wolfSSL | 0:9d17e4342598 | 7907 | ato16(input + *inOutIdx, &length); |
wolfSSL | 0:9d17e4342598 | 7908 | *inOutIdx += OPAQUE16_LEN; |
wolfSSL | 0:9d17e4342598 | 7909 | |
wolfSSL | 0:9d17e4342598 | 7910 | if ((*inOutIdx - begin) + length > size) |
wolfSSL | 0:9d17e4342598 | 7911 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 7912 | |
wolfSSL | 0:9d17e4342598 | 7913 | ssl->buffers.serverDH_G.buffer = (byte*) XMALLOC(length, ssl->heap, |
wolfSSL | 0:9d17e4342598 | 7914 | DYNAMIC_TYPE_DH); |
wolfSSL | 0:9d17e4342598 | 7915 | |
wolfSSL | 0:9d17e4342598 | 7916 | if (ssl->buffers.serverDH_G.buffer) |
wolfSSL | 0:9d17e4342598 | 7917 | ssl->buffers.serverDH_G.length = length; |
wolfSSL | 0:9d17e4342598 | 7918 | else |
wolfSSL | 0:9d17e4342598 | 7919 | return MEMORY_ERROR; |
wolfSSL | 0:9d17e4342598 | 7920 | |
wolfSSL | 0:9d17e4342598 | 7921 | XMEMCPY(ssl->buffers.serverDH_G.buffer, input + *inOutIdx, length); |
wolfSSL | 0:9d17e4342598 | 7922 | *inOutIdx += length; |
wolfSSL | 0:9d17e4342598 | 7923 | |
wolfSSL | 0:9d17e4342598 | 7924 | /* pub */ |
wolfSSL | 0:9d17e4342598 | 7925 | if ((*inOutIdx - begin) + OPAQUE16_LEN > size) |
wolfSSL | 0:9d17e4342598 | 7926 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 7927 | |
wolfSSL | 0:9d17e4342598 | 7928 | ato16(input + *inOutIdx, &length); |
wolfSSL | 0:9d17e4342598 | 7929 | *inOutIdx += OPAQUE16_LEN; |
wolfSSL | 0:9d17e4342598 | 7930 | |
wolfSSL | 0:9d17e4342598 | 7931 | if ((*inOutIdx - begin) + length > size) |
wolfSSL | 0:9d17e4342598 | 7932 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 7933 | |
wolfSSL | 0:9d17e4342598 | 7934 | ssl->buffers.serverDH_Pub.buffer = (byte*) XMALLOC(length, ssl->heap, |
wolfSSL | 0:9d17e4342598 | 7935 | DYNAMIC_TYPE_DH); |
wolfSSL | 0:9d17e4342598 | 7936 | |
wolfSSL | 0:9d17e4342598 | 7937 | if (ssl->buffers.serverDH_Pub.buffer) |
wolfSSL | 0:9d17e4342598 | 7938 | ssl->buffers.serverDH_Pub.length = length; |
wolfSSL | 0:9d17e4342598 | 7939 | else |
wolfSSL | 0:9d17e4342598 | 7940 | return MEMORY_ERROR; |
wolfSSL | 0:9d17e4342598 | 7941 | |
wolfSSL | 0:9d17e4342598 | 7942 | XMEMCPY(ssl->buffers.serverDH_Pub.buffer, input + *inOutIdx, length); |
wolfSSL | 0:9d17e4342598 | 7943 | *inOutIdx += length; |
wolfSSL | 0:9d17e4342598 | 7944 | } /* dh_kea */ |
wolfSSL | 0:9d17e4342598 | 7945 | #endif /* OPENSSL_EXTRA */ |
wolfSSL | 0:9d17e4342598 | 7946 | |
wolfSSL | 0:9d17e4342598 | 7947 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 7948 | if (ssl->specs.kea == ecc_diffie_hellman_kea) |
wolfSSL | 0:9d17e4342598 | 7949 | { |
wolfSSL | 0:9d17e4342598 | 7950 | byte b; |
wolfSSL | 0:9d17e4342598 | 7951 | |
wolfSSL | 0:9d17e4342598 | 7952 | if ((*inOutIdx - begin) + ENUM_LEN + OPAQUE16_LEN + OPAQUE8_LEN > size) |
wolfSSL | 0:9d17e4342598 | 7953 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 7954 | |
wolfSSL | 0:9d17e4342598 | 7955 | b = input[(*inOutIdx)++]; |
wolfSSL | 0:9d17e4342598 | 7956 | |
wolfSSL | 0:9d17e4342598 | 7957 | if (b != named_curve) |
wolfSSL | 0:9d17e4342598 | 7958 | return ECC_CURVETYPE_ERROR; |
wolfSSL | 0:9d17e4342598 | 7959 | |
wolfSSL | 0:9d17e4342598 | 7960 | *inOutIdx += 1; /* curve type, eat leading 0 */ |
wolfSSL | 0:9d17e4342598 | 7961 | b = input[(*inOutIdx)++]; |
wolfSSL | 0:9d17e4342598 | 7962 | |
wolfSSL | 0:9d17e4342598 | 7963 | if (b != secp256r1 && b != secp384r1 && b != secp521r1 && b != |
wolfSSL | 0:9d17e4342598 | 7964 | secp160r1 && b != secp192r1 && b != secp224r1) |
wolfSSL | 0:9d17e4342598 | 7965 | return ECC_CURVE_ERROR; |
wolfSSL | 0:9d17e4342598 | 7966 | |
wolfSSL | 0:9d17e4342598 | 7967 | length = input[(*inOutIdx)++]; |
wolfSSL | 0:9d17e4342598 | 7968 | |
wolfSSL | 0:9d17e4342598 | 7969 | if ((*inOutIdx - begin) + length > size) |
wolfSSL | 0:9d17e4342598 | 7970 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 7971 | |
wolfSSL | 0:9d17e4342598 | 7972 | if (ecc_import_x963(input + *inOutIdx, length, ssl->peerEccKey) != 0) |
wolfSSL | 0:9d17e4342598 | 7973 | return ECC_PEERKEY_ERROR; |
wolfSSL | 0:9d17e4342598 | 7974 | |
wolfSSL | 0:9d17e4342598 | 7975 | *inOutIdx += length; |
wolfSSL | 0:9d17e4342598 | 7976 | ssl->peerEccKeyPresent = 1; |
wolfSSL | 0:9d17e4342598 | 7977 | } |
wolfSSL | 0:9d17e4342598 | 7978 | #endif /* HAVE_ECC */ |
wolfSSL | 0:9d17e4342598 | 7979 | |
wolfSSL | 0:9d17e4342598 | 7980 | #if defined(OPENSSL_EXTRA) || defined(HAVE_ECC) |
wolfSSL | 0:9d17e4342598 | 7981 | { |
wolfSSL | 0:9d17e4342598 | 7982 | #ifndef NO_OLD_TLS |
wolfSSL | 0:9d17e4342598 | 7983 | Md5 md5; |
wolfSSL | 0:9d17e4342598 | 7984 | Sha sha; |
wolfSSL | 0:9d17e4342598 | 7985 | #endif |
wolfSSL | 0:9d17e4342598 | 7986 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 7987 | Sha256 sha256; |
wolfSSL | 0:9d17e4342598 | 7988 | byte hash256[SHA256_DIGEST_SIZE]; |
wolfSSL | 0:9d17e4342598 | 7989 | #endif |
wolfSSL | 0:9d17e4342598 | 7990 | #ifdef CYASSL_SHA384 |
wolfSSL | 0:9d17e4342598 | 7991 | Sha384 sha384; |
wolfSSL | 0:9d17e4342598 | 7992 | byte hash384[SHA384_DIGEST_SIZE]; |
wolfSSL | 0:9d17e4342598 | 7993 | #endif |
wolfSSL | 0:9d17e4342598 | 7994 | byte hash[FINISHED_SZ]; |
wolfSSL | 0:9d17e4342598 | 7995 | byte messageVerify[MAX_DH_SZ]; |
wolfSSL | 0:9d17e4342598 | 7996 | byte hashAlgo = sha_mac; |
wolfSSL | 0:9d17e4342598 | 7997 | byte sigAlgo = ssl->specs.sig_algo; |
wolfSSL | 0:9d17e4342598 | 7998 | word16 verifySz = (word16) (*inOutIdx - begin); |
wolfSSL | 0:9d17e4342598 | 7999 | |
wolfSSL | 0:9d17e4342598 | 8000 | /* save message for hash verify */ |
wolfSSL | 0:9d17e4342598 | 8001 | if (verifySz > sizeof(messageVerify)) |
wolfSSL | 0:9d17e4342598 | 8002 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 8003 | |
wolfSSL | 0:9d17e4342598 | 8004 | XMEMCPY(messageVerify, input + begin, verifySz); |
wolfSSL | 0:9d17e4342598 | 8005 | |
wolfSSL | 0:9d17e4342598 | 8006 | if (IsAtLeastTLSv1_2(ssl)) { |
wolfSSL | 0:9d17e4342598 | 8007 | if ((*inOutIdx - begin) + ENUM_LEN + ENUM_LEN > size) |
wolfSSL | 0:9d17e4342598 | 8008 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 8009 | |
wolfSSL | 0:9d17e4342598 | 8010 | hashAlgo = input[(*inOutIdx)++]; |
wolfSSL | 0:9d17e4342598 | 8011 | sigAlgo = input[(*inOutIdx)++]; |
wolfSSL | 0:9d17e4342598 | 8012 | } |
wolfSSL | 0:9d17e4342598 | 8013 | |
wolfSSL | 0:9d17e4342598 | 8014 | /* signature */ |
wolfSSL | 0:9d17e4342598 | 8015 | if ((*inOutIdx - begin) + OPAQUE16_LEN > size) |
wolfSSL | 0:9d17e4342598 | 8016 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 8017 | |
wolfSSL | 0:9d17e4342598 | 8018 | ato16(input + *inOutIdx, &length); |
wolfSSL | 0:9d17e4342598 | 8019 | *inOutIdx += OPAQUE16_LEN; |
wolfSSL | 0:9d17e4342598 | 8020 | |
wolfSSL | 0:9d17e4342598 | 8021 | if ((*inOutIdx - begin) + length > size) |
wolfSSL | 0:9d17e4342598 | 8022 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 8023 | |
wolfSSL | 0:9d17e4342598 | 8024 | /* inOutIdx updated at the end of the function */ |
wolfSSL | 0:9d17e4342598 | 8025 | |
wolfSSL | 0:9d17e4342598 | 8026 | /* verify signature */ |
wolfSSL | 0:9d17e4342598 | 8027 | #ifndef NO_OLD_TLS |
wolfSSL | 0:9d17e4342598 | 8028 | /* md5 */ |
wolfSSL | 0:9d17e4342598 | 8029 | InitMd5(&md5); |
wolfSSL | 0:9d17e4342598 | 8030 | Md5Update(&md5, ssl->arrays->clientRandom, RAN_LEN); |
wolfSSL | 0:9d17e4342598 | 8031 | Md5Update(&md5, ssl->arrays->serverRandom, RAN_LEN); |
wolfSSL | 0:9d17e4342598 | 8032 | Md5Update(&md5, messageVerify, verifySz); |
wolfSSL | 0:9d17e4342598 | 8033 | Md5Final(&md5, hash); |
wolfSSL | 0:9d17e4342598 | 8034 | |
wolfSSL | 0:9d17e4342598 | 8035 | /* sha */ |
wolfSSL | 0:9d17e4342598 | 8036 | ret = InitSha(&sha); |
wolfSSL | 0:9d17e4342598 | 8037 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 8038 | return ret; |
wolfSSL | 0:9d17e4342598 | 8039 | ShaUpdate(&sha, ssl->arrays->clientRandom, RAN_LEN); |
wolfSSL | 0:9d17e4342598 | 8040 | ShaUpdate(&sha, ssl->arrays->serverRandom, RAN_LEN); |
wolfSSL | 0:9d17e4342598 | 8041 | ShaUpdate(&sha, messageVerify, verifySz); |
wolfSSL | 0:9d17e4342598 | 8042 | ShaFinal(&sha, hash + MD5_DIGEST_SIZE); |
wolfSSL | 0:9d17e4342598 | 8043 | #endif |
wolfSSL | 0:9d17e4342598 | 8044 | |
wolfSSL | 0:9d17e4342598 | 8045 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 8046 | ret = InitSha256(&sha256); |
wolfSSL | 0:9d17e4342598 | 8047 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 8048 | return ret; |
wolfSSL | 0:9d17e4342598 | 8049 | Sha256Update(&sha256, ssl->arrays->clientRandom, RAN_LEN); |
wolfSSL | 0:9d17e4342598 | 8050 | Sha256Update(&sha256, ssl->arrays->serverRandom, RAN_LEN); |
wolfSSL | 0:9d17e4342598 | 8051 | Sha256Update(&sha256, messageVerify, verifySz); |
wolfSSL | 0:9d17e4342598 | 8052 | Sha256Final(&sha256, hash256); |
wolfSSL | 0:9d17e4342598 | 8053 | #endif |
wolfSSL | 0:9d17e4342598 | 8054 | |
wolfSSL | 0:9d17e4342598 | 8055 | #ifdef CYASSL_SHA384 |
wolfSSL | 0:9d17e4342598 | 8056 | ret = InitSha384(&sha384); |
wolfSSL | 0:9d17e4342598 | 8057 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 8058 | return ret; |
wolfSSL | 0:9d17e4342598 | 8059 | Sha384Update(&sha384, ssl->arrays->clientRandom, RAN_LEN); |
wolfSSL | 0:9d17e4342598 | 8060 | Sha384Update(&sha384, ssl->arrays->serverRandom, RAN_LEN); |
wolfSSL | 0:9d17e4342598 | 8061 | Sha384Update(&sha384, messageVerify, verifySz); |
wolfSSL | 0:9d17e4342598 | 8062 | Sha384Final(&sha384, hash384); |
wolfSSL | 0:9d17e4342598 | 8063 | #endif |
wolfSSL | 0:9d17e4342598 | 8064 | |
wolfSSL | 0:9d17e4342598 | 8065 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 8066 | /* rsa */ |
wolfSSL | 0:9d17e4342598 | 8067 | if (sigAlgo == rsa_sa_algo) |
wolfSSL | 0:9d17e4342598 | 8068 | { |
wolfSSL | 0:9d17e4342598 | 8069 | byte* out = NULL; |
wolfSSL | 0:9d17e4342598 | 8070 | byte doUserRsa = 0; |
wolfSSL | 0:9d17e4342598 | 8071 | |
wolfSSL | 0:9d17e4342598 | 8072 | #ifdef HAVE_PK_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 8073 | if (ssl->ctx->RsaVerifyCb) |
wolfSSL | 0:9d17e4342598 | 8074 | doUserRsa = 1; |
wolfSSL | 0:9d17e4342598 | 8075 | #endif /*HAVE_PK_CALLBACKS */ |
wolfSSL | 0:9d17e4342598 | 8076 | |
wolfSSL | 0:9d17e4342598 | 8077 | if (!ssl->peerRsaKeyPresent) |
wolfSSL | 0:9d17e4342598 | 8078 | return NO_PEER_KEY; |
wolfSSL | 0:9d17e4342598 | 8079 | |
wolfSSL | 0:9d17e4342598 | 8080 | if (doUserRsa) { |
wolfSSL | 0:9d17e4342598 | 8081 | #ifdef HAVE_PK_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 8082 | ret = ssl->ctx->RsaVerifyCb(ssl, input + *inOutIdx, length, |
wolfSSL | 0:9d17e4342598 | 8083 | &out, |
wolfSSL | 0:9d17e4342598 | 8084 | ssl->buffers.peerRsaKey.buffer, |
wolfSSL | 0:9d17e4342598 | 8085 | ssl->buffers.peerRsaKey.length, |
wolfSSL | 0:9d17e4342598 | 8086 | ssl->RsaVerifyCtx); |
wolfSSL | 0:9d17e4342598 | 8087 | #endif /*HAVE_PK_CALLBACKS */ |
wolfSSL | 0:9d17e4342598 | 8088 | } |
wolfSSL | 0:9d17e4342598 | 8089 | else { |
wolfSSL | 0:9d17e4342598 | 8090 | ret = RsaSSL_VerifyInline((byte *) input + *inOutIdx, length, |
wolfSSL | 0:9d17e4342598 | 8091 | &out, ssl->peerRsaKey); |
wolfSSL | 0:9d17e4342598 | 8092 | } |
wolfSSL | 0:9d17e4342598 | 8093 | |
wolfSSL | 0:9d17e4342598 | 8094 | if (IsAtLeastTLSv1_2(ssl)) { |
wolfSSL | 0:9d17e4342598 | 8095 | byte encodedSig[MAX_ENCODED_SIG_SZ]; |
wolfSSL | 0:9d17e4342598 | 8096 | word32 encSigSz; |
wolfSSL | 0:9d17e4342598 | 8097 | #ifndef NO_OLD_TLS |
wolfSSL | 0:9d17e4342598 | 8098 | byte* digest = &hash[MD5_DIGEST_SIZE]; |
wolfSSL | 0:9d17e4342598 | 8099 | int typeH = SHAh; |
wolfSSL | 0:9d17e4342598 | 8100 | int digestSz = SHA_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 8101 | #else |
wolfSSL | 0:9d17e4342598 | 8102 | byte* digest = hash256; |
wolfSSL | 0:9d17e4342598 | 8103 | int typeH = SHA256h; |
wolfSSL | 0:9d17e4342598 | 8104 | int digestSz = SHA256_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 8105 | #endif |
wolfSSL | 0:9d17e4342598 | 8106 | |
wolfSSL | 0:9d17e4342598 | 8107 | if (hashAlgo == sha_mac) { |
wolfSSL | 0:9d17e4342598 | 8108 | #ifndef NO_SHA |
wolfSSL | 0:9d17e4342598 | 8109 | digest = &hash[MD5_DIGEST_SIZE]; |
wolfSSL | 0:9d17e4342598 | 8110 | typeH = SHAh; |
wolfSSL | 0:9d17e4342598 | 8111 | digestSz = SHA_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 8112 | #endif |
wolfSSL | 0:9d17e4342598 | 8113 | } |
wolfSSL | 0:9d17e4342598 | 8114 | else if (hashAlgo == sha256_mac) { |
wolfSSL | 0:9d17e4342598 | 8115 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 8116 | digest = hash256; |
wolfSSL | 0:9d17e4342598 | 8117 | typeH = SHA256h; |
wolfSSL | 0:9d17e4342598 | 8118 | digestSz = SHA256_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 8119 | #endif |
wolfSSL | 0:9d17e4342598 | 8120 | } |
wolfSSL | 0:9d17e4342598 | 8121 | else if (hashAlgo == sha384_mac) { |
wolfSSL | 0:9d17e4342598 | 8122 | #ifdef CYASSL_SHA384 |
wolfSSL | 0:9d17e4342598 | 8123 | digest = hash384; |
wolfSSL | 0:9d17e4342598 | 8124 | typeH = SHA384h; |
wolfSSL | 0:9d17e4342598 | 8125 | digestSz = SHA384_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 8126 | #endif |
wolfSSL | 0:9d17e4342598 | 8127 | } |
wolfSSL | 0:9d17e4342598 | 8128 | |
wolfSSL | 0:9d17e4342598 | 8129 | encSigSz = EncodeSignature(encodedSig, digest, digestSz, typeH); |
wolfSSL | 0:9d17e4342598 | 8130 | |
wolfSSL | 0:9d17e4342598 | 8131 | if (encSigSz != (word32)ret || !out || XMEMCMP(out, encodedSig, |
wolfSSL | 0:9d17e4342598 | 8132 | min(encSigSz, MAX_ENCODED_SIG_SZ)) != 0) |
wolfSSL | 0:9d17e4342598 | 8133 | return VERIFY_SIGN_ERROR; |
wolfSSL | 0:9d17e4342598 | 8134 | } |
wolfSSL | 0:9d17e4342598 | 8135 | else { |
wolfSSL | 0:9d17e4342598 | 8136 | if (ret != sizeof(hash) || !out || XMEMCMP(out, |
wolfSSL | 0:9d17e4342598 | 8137 | hash, sizeof(hash)) != 0) |
wolfSSL | 0:9d17e4342598 | 8138 | return VERIFY_SIGN_ERROR; |
wolfSSL | 0:9d17e4342598 | 8139 | } |
wolfSSL | 0:9d17e4342598 | 8140 | } else |
wolfSSL | 0:9d17e4342598 | 8141 | #endif |
wolfSSL | 0:9d17e4342598 | 8142 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 8143 | /* ecdsa */ |
wolfSSL | 0:9d17e4342598 | 8144 | if (sigAlgo == ecc_dsa_sa_algo) { |
wolfSSL | 0:9d17e4342598 | 8145 | int verify = 0; |
wolfSSL | 0:9d17e4342598 | 8146 | #ifndef NO_OLD_TLS |
wolfSSL | 0:9d17e4342598 | 8147 | byte* digest = &hash[MD5_DIGEST_SIZE]; |
wolfSSL | 0:9d17e4342598 | 8148 | word32 digestSz = SHA_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 8149 | #else |
wolfSSL | 0:9d17e4342598 | 8150 | byte* digest = hash256; |
wolfSSL | 0:9d17e4342598 | 8151 | word32 digestSz = SHA256_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 8152 | #endif |
wolfSSL | 0:9d17e4342598 | 8153 | byte doUserEcc = 0; |
wolfSSL | 0:9d17e4342598 | 8154 | |
wolfSSL | 0:9d17e4342598 | 8155 | #ifdef HAVE_PK_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 8156 | if (ssl->ctx->EccVerifyCb) |
wolfSSL | 0:9d17e4342598 | 8157 | doUserEcc = 1; |
wolfSSL | 0:9d17e4342598 | 8158 | #endif |
wolfSSL | 0:9d17e4342598 | 8159 | |
wolfSSL | 0:9d17e4342598 | 8160 | if (!ssl->peerEccDsaKeyPresent) |
wolfSSL | 0:9d17e4342598 | 8161 | return NO_PEER_KEY; |
wolfSSL | 0:9d17e4342598 | 8162 | |
wolfSSL | 0:9d17e4342598 | 8163 | if (IsAtLeastTLSv1_2(ssl)) { |
wolfSSL | 0:9d17e4342598 | 8164 | if (hashAlgo == sha_mac) { |
wolfSSL | 0:9d17e4342598 | 8165 | #ifndef NO_SHA |
wolfSSL | 0:9d17e4342598 | 8166 | digest = &hash[MD5_DIGEST_SIZE]; |
wolfSSL | 0:9d17e4342598 | 8167 | digestSz = SHA_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 8168 | #endif |
wolfSSL | 0:9d17e4342598 | 8169 | } |
wolfSSL | 0:9d17e4342598 | 8170 | else if (hashAlgo == sha256_mac) { |
wolfSSL | 0:9d17e4342598 | 8171 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 8172 | digest = hash256; |
wolfSSL | 0:9d17e4342598 | 8173 | digestSz = SHA256_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 8174 | #endif |
wolfSSL | 0:9d17e4342598 | 8175 | } |
wolfSSL | 0:9d17e4342598 | 8176 | else if (hashAlgo == sha384_mac) { |
wolfSSL | 0:9d17e4342598 | 8177 | #ifdef CYASSL_SHA384 |
wolfSSL | 0:9d17e4342598 | 8178 | digest = hash384; |
wolfSSL | 0:9d17e4342598 | 8179 | digestSz = SHA384_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 8180 | #endif |
wolfSSL | 0:9d17e4342598 | 8181 | } |
wolfSSL | 0:9d17e4342598 | 8182 | } |
wolfSSL | 0:9d17e4342598 | 8183 | if (doUserEcc) { |
wolfSSL | 0:9d17e4342598 | 8184 | #ifdef HAVE_PK_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 8185 | ret = ssl->ctx->EccVerifyCb(ssl, input + *inOutIdx, length, |
wolfSSL | 0:9d17e4342598 | 8186 | digest, digestSz, |
wolfSSL | 0:9d17e4342598 | 8187 | ssl->buffers.peerEccDsaKey.buffer, |
wolfSSL | 0:9d17e4342598 | 8188 | ssl->buffers.peerEccDsaKey.length, |
wolfSSL | 0:9d17e4342598 | 8189 | &verify, ssl->EccVerifyCtx); |
wolfSSL | 0:9d17e4342598 | 8190 | #endif |
wolfSSL | 0:9d17e4342598 | 8191 | } |
wolfSSL | 0:9d17e4342598 | 8192 | else { |
wolfSSL | 0:9d17e4342598 | 8193 | ret = ecc_verify_hash(input + *inOutIdx, length, |
wolfSSL | 0:9d17e4342598 | 8194 | digest, digestSz, &verify, ssl->peerEccDsaKey); |
wolfSSL | 0:9d17e4342598 | 8195 | } |
wolfSSL | 0:9d17e4342598 | 8196 | if (ret != 0 || verify == 0) |
wolfSSL | 0:9d17e4342598 | 8197 | return VERIFY_SIGN_ERROR; |
wolfSSL | 0:9d17e4342598 | 8198 | } |
wolfSSL | 0:9d17e4342598 | 8199 | else |
wolfSSL | 0:9d17e4342598 | 8200 | #endif /* HAVE_ECC */ |
wolfSSL | 0:9d17e4342598 | 8201 | return ALGO_ID_E; |
wolfSSL | 0:9d17e4342598 | 8202 | |
wolfSSL | 0:9d17e4342598 | 8203 | /* signature length */ |
wolfSSL | 0:9d17e4342598 | 8204 | *inOutIdx += length; |
wolfSSL | 0:9d17e4342598 | 8205 | |
wolfSSL | 0:9d17e4342598 | 8206 | ssl->options.serverState = SERVER_KEYEXCHANGE_COMPLETE; |
wolfSSL | 0:9d17e4342598 | 8207 | |
wolfSSL | 0:9d17e4342598 | 8208 | return 0; |
wolfSSL | 0:9d17e4342598 | 8209 | } |
wolfSSL | 0:9d17e4342598 | 8210 | #else /* HAVE_OPENSSL or HAVE_ECC */ |
wolfSSL | 0:9d17e4342598 | 8211 | return NOT_COMPILED_IN; /* not supported by build */ |
wolfSSL | 0:9d17e4342598 | 8212 | #endif /* HAVE_OPENSSL or HAVE_ECC */ |
wolfSSL | 0:9d17e4342598 | 8213 | } |
wolfSSL | 0:9d17e4342598 | 8214 | |
wolfSSL | 0:9d17e4342598 | 8215 | |
wolfSSL | 0:9d17e4342598 | 8216 | int SendClientKeyExchange(CYASSL* ssl) |
wolfSSL | 0:9d17e4342598 | 8217 | { |
wolfSSL | 0:9d17e4342598 | 8218 | byte encSecret[MAX_ENCRYPT_SZ]; |
wolfSSL | 0:9d17e4342598 | 8219 | word32 encSz = 0; |
wolfSSL | 0:9d17e4342598 | 8220 | word32 idx = 0; |
wolfSSL | 0:9d17e4342598 | 8221 | int ret = 0; |
wolfSSL | 0:9d17e4342598 | 8222 | byte doUserRsa = 0; |
wolfSSL | 0:9d17e4342598 | 8223 | |
wolfSSL | 0:9d17e4342598 | 8224 | (void)doUserRsa; |
wolfSSL | 0:9d17e4342598 | 8225 | |
wolfSSL | 0:9d17e4342598 | 8226 | #ifdef HAVE_PK_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 8227 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 8228 | if (ssl->ctx->RsaEncCb) |
wolfSSL | 0:9d17e4342598 | 8229 | doUserRsa = 1; |
wolfSSL | 0:9d17e4342598 | 8230 | #endif /* NO_RSA */ |
wolfSSL | 0:9d17e4342598 | 8231 | #endif /*HAVE_PK_CALLBACKS */ |
wolfSSL | 0:9d17e4342598 | 8232 | |
wolfSSL | 0:9d17e4342598 | 8233 | switch (ssl->specs.kea) { |
wolfSSL | 0:9d17e4342598 | 8234 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 8235 | case rsa_kea: |
wolfSSL | 0:9d17e4342598 | 8236 | RNG_GenerateBlock(ssl->rng, ssl->arrays->preMasterSecret, |
wolfSSL | 0:9d17e4342598 | 8237 | SECRET_LEN); |
wolfSSL | 0:9d17e4342598 | 8238 | ssl->arrays->preMasterSecret[0] = ssl->chVersion.major; |
wolfSSL | 0:9d17e4342598 | 8239 | ssl->arrays->preMasterSecret[1] = ssl->chVersion.minor; |
wolfSSL | 0:9d17e4342598 | 8240 | ssl->arrays->preMasterSz = SECRET_LEN; |
wolfSSL | 0:9d17e4342598 | 8241 | |
wolfSSL | 0:9d17e4342598 | 8242 | if (ssl->peerRsaKeyPresent == 0) |
wolfSSL | 0:9d17e4342598 | 8243 | return NO_PEER_KEY; |
wolfSSL | 0:9d17e4342598 | 8244 | |
wolfSSL | 0:9d17e4342598 | 8245 | if (doUserRsa) { |
wolfSSL | 0:9d17e4342598 | 8246 | #ifdef HAVE_PK_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 8247 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 8248 | encSz = sizeof(encSecret); |
wolfSSL | 0:9d17e4342598 | 8249 | ret = ssl->ctx->RsaEncCb(ssl, |
wolfSSL | 0:9d17e4342598 | 8250 | ssl->arrays->preMasterSecret, |
wolfSSL | 0:9d17e4342598 | 8251 | SECRET_LEN, |
wolfSSL | 0:9d17e4342598 | 8252 | encSecret, &encSz, |
wolfSSL | 0:9d17e4342598 | 8253 | ssl->buffers.peerRsaKey.buffer, |
wolfSSL | 0:9d17e4342598 | 8254 | ssl->buffers.peerRsaKey.length, |
wolfSSL | 0:9d17e4342598 | 8255 | ssl->RsaEncCtx); |
wolfSSL | 0:9d17e4342598 | 8256 | #endif /* NO_RSA */ |
wolfSSL | 0:9d17e4342598 | 8257 | #endif /*HAVE_PK_CALLBACKS */ |
wolfSSL | 0:9d17e4342598 | 8258 | } |
wolfSSL | 0:9d17e4342598 | 8259 | else { |
wolfSSL | 0:9d17e4342598 | 8260 | ret = RsaPublicEncrypt(ssl->arrays->preMasterSecret, |
wolfSSL | 0:9d17e4342598 | 8261 | SECRET_LEN, encSecret, sizeof(encSecret), |
wolfSSL | 0:9d17e4342598 | 8262 | ssl->peerRsaKey, ssl->rng); |
wolfSSL | 0:9d17e4342598 | 8263 | if (ret > 0) { |
wolfSSL | 0:9d17e4342598 | 8264 | encSz = ret; |
wolfSSL | 0:9d17e4342598 | 8265 | ret = 0; /* set success to 0 */ |
wolfSSL | 0:9d17e4342598 | 8266 | } |
wolfSSL | 0:9d17e4342598 | 8267 | } |
wolfSSL | 0:9d17e4342598 | 8268 | break; |
wolfSSL | 0:9d17e4342598 | 8269 | #endif |
wolfSSL | 0:9d17e4342598 | 8270 | #ifdef OPENSSL_EXTRA |
wolfSSL | 0:9d17e4342598 | 8271 | case diffie_hellman_kea: |
wolfSSL | 0:9d17e4342598 | 8272 | { |
wolfSSL | 0:9d17e4342598 | 8273 | buffer serverP = ssl->buffers.serverDH_P; |
wolfSSL | 0:9d17e4342598 | 8274 | buffer serverG = ssl->buffers.serverDH_G; |
wolfSSL | 0:9d17e4342598 | 8275 | buffer serverPub = ssl->buffers.serverDH_Pub; |
wolfSSL | 0:9d17e4342598 | 8276 | byte priv[ENCRYPT_LEN]; |
wolfSSL | 0:9d17e4342598 | 8277 | word32 privSz = 0; |
wolfSSL | 0:9d17e4342598 | 8278 | DhKey key; |
wolfSSL | 0:9d17e4342598 | 8279 | |
wolfSSL | 0:9d17e4342598 | 8280 | if (serverP.buffer == 0 || serverG.buffer == 0 || |
wolfSSL | 0:9d17e4342598 | 8281 | serverPub.buffer == 0) |
wolfSSL | 0:9d17e4342598 | 8282 | return NO_PEER_KEY; |
wolfSSL | 0:9d17e4342598 | 8283 | |
wolfSSL | 0:9d17e4342598 | 8284 | InitDhKey(&key); |
wolfSSL | 0:9d17e4342598 | 8285 | ret = DhSetKey(&key, serverP.buffer, serverP.length, |
wolfSSL | 0:9d17e4342598 | 8286 | serverG.buffer, serverG.length); |
wolfSSL | 0:9d17e4342598 | 8287 | if (ret == 0) |
wolfSSL | 0:9d17e4342598 | 8288 | /* for DH, encSecret is Yc, agree is pre-master */ |
wolfSSL | 0:9d17e4342598 | 8289 | ret = DhGenerateKeyPair(&key, ssl->rng, priv, &privSz, |
wolfSSL | 0:9d17e4342598 | 8290 | encSecret, &encSz); |
wolfSSL | 0:9d17e4342598 | 8291 | if (ret == 0) |
wolfSSL | 0:9d17e4342598 | 8292 | ret = DhAgree(&key, ssl->arrays->preMasterSecret, |
wolfSSL | 0:9d17e4342598 | 8293 | &ssl->arrays->preMasterSz, priv, privSz, |
wolfSSL | 0:9d17e4342598 | 8294 | serverPub.buffer, serverPub.length); |
wolfSSL | 0:9d17e4342598 | 8295 | FreeDhKey(&key); |
wolfSSL | 0:9d17e4342598 | 8296 | } |
wolfSSL | 0:9d17e4342598 | 8297 | break; |
wolfSSL | 0:9d17e4342598 | 8298 | #endif /* OPENSSL_EXTRA */ |
wolfSSL | 0:9d17e4342598 | 8299 | #ifndef NO_PSK |
wolfSSL | 0:9d17e4342598 | 8300 | case psk_kea: |
wolfSSL | 0:9d17e4342598 | 8301 | { |
wolfSSL | 0:9d17e4342598 | 8302 | byte* pms = ssl->arrays->preMasterSecret; |
wolfSSL | 0:9d17e4342598 | 8303 | |
wolfSSL | 0:9d17e4342598 | 8304 | ssl->arrays->psk_keySz = ssl->options.client_psk_cb(ssl, |
wolfSSL | 0:9d17e4342598 | 8305 | ssl->arrays->server_hint, ssl->arrays->client_identity, |
wolfSSL | 0:9d17e4342598 | 8306 | MAX_PSK_ID_LEN, ssl->arrays->psk_key, MAX_PSK_KEY_LEN); |
wolfSSL | 0:9d17e4342598 | 8307 | if (ssl->arrays->psk_keySz == 0 || |
wolfSSL | 0:9d17e4342598 | 8308 | ssl->arrays->psk_keySz > MAX_PSK_KEY_LEN) |
wolfSSL | 0:9d17e4342598 | 8309 | return PSK_KEY_ERROR; |
wolfSSL | 0:9d17e4342598 | 8310 | encSz = (word32)XSTRLEN(ssl->arrays->client_identity); |
wolfSSL | 0:9d17e4342598 | 8311 | if (encSz > MAX_PSK_ID_LEN) return CLIENT_ID_ERROR; |
wolfSSL | 0:9d17e4342598 | 8312 | XMEMCPY(encSecret, ssl->arrays->client_identity, encSz); |
wolfSSL | 0:9d17e4342598 | 8313 | |
wolfSSL | 0:9d17e4342598 | 8314 | /* make psk pre master secret */ |
wolfSSL | 0:9d17e4342598 | 8315 | /* length of key + length 0s + length of key + key */ |
wolfSSL | 0:9d17e4342598 | 8316 | c16toa((word16)ssl->arrays->psk_keySz, pms); |
wolfSSL | 0:9d17e4342598 | 8317 | pms += 2; |
wolfSSL | 0:9d17e4342598 | 8318 | XMEMSET(pms, 0, ssl->arrays->psk_keySz); |
wolfSSL | 0:9d17e4342598 | 8319 | pms += ssl->arrays->psk_keySz; |
wolfSSL | 0:9d17e4342598 | 8320 | c16toa((word16)ssl->arrays->psk_keySz, pms); |
wolfSSL | 0:9d17e4342598 | 8321 | pms += 2; |
wolfSSL | 0:9d17e4342598 | 8322 | XMEMCPY(pms, ssl->arrays->psk_key, ssl->arrays->psk_keySz); |
wolfSSL | 0:9d17e4342598 | 8323 | ssl->arrays->preMasterSz = ssl->arrays->psk_keySz * 2 + 4; |
wolfSSL | 0:9d17e4342598 | 8324 | XMEMSET(ssl->arrays->psk_key, 0, ssl->arrays->psk_keySz); |
wolfSSL | 0:9d17e4342598 | 8325 | ssl->arrays->psk_keySz = 0; /* No further need */ |
wolfSSL | 0:9d17e4342598 | 8326 | } |
wolfSSL | 0:9d17e4342598 | 8327 | break; |
wolfSSL | 0:9d17e4342598 | 8328 | #endif /* NO_PSK */ |
wolfSSL | 0:9d17e4342598 | 8329 | #ifdef HAVE_NTRU |
wolfSSL | 0:9d17e4342598 | 8330 | case ntru_kea: |
wolfSSL | 0:9d17e4342598 | 8331 | { |
wolfSSL | 0:9d17e4342598 | 8332 | word32 rc; |
wolfSSL | 0:9d17e4342598 | 8333 | word16 cipherLen = sizeof(encSecret); |
wolfSSL | 0:9d17e4342598 | 8334 | DRBG_HANDLE drbg; |
wolfSSL | 0:9d17e4342598 | 8335 | static uint8_t const cyasslStr[] = { |
wolfSSL | 0:9d17e4342598 | 8336 | 'C', 'y', 'a', 'S', 'S', 'L', ' ', 'N', 'T', 'R', 'U' |
wolfSSL | 0:9d17e4342598 | 8337 | }; |
wolfSSL | 0:9d17e4342598 | 8338 | |
wolfSSL | 0:9d17e4342598 | 8339 | RNG_GenerateBlock(ssl->rng, ssl->arrays->preMasterSecret, |
wolfSSL | 0:9d17e4342598 | 8340 | SECRET_LEN); |
wolfSSL | 0:9d17e4342598 | 8341 | ssl->arrays->preMasterSz = SECRET_LEN; |
wolfSSL | 0:9d17e4342598 | 8342 | |
wolfSSL | 0:9d17e4342598 | 8343 | if (ssl->peerNtruKeyPresent == 0) |
wolfSSL | 0:9d17e4342598 | 8344 | return NO_PEER_KEY; |
wolfSSL | 0:9d17e4342598 | 8345 | |
wolfSSL | 0:9d17e4342598 | 8346 | rc = crypto_drbg_instantiate(MAX_NTRU_BITS, cyasslStr, |
wolfSSL | 0:9d17e4342598 | 8347 | sizeof(cyasslStr), GetEntropy, |
wolfSSL | 0:9d17e4342598 | 8348 | &drbg); |
wolfSSL | 0:9d17e4342598 | 8349 | if (rc != DRBG_OK) |
wolfSSL | 0:9d17e4342598 | 8350 | return NTRU_DRBG_ERROR; |
wolfSSL | 0:9d17e4342598 | 8351 | |
wolfSSL | 0:9d17e4342598 | 8352 | rc = crypto_ntru_encrypt(drbg, ssl->peerNtruKeyLen, |
wolfSSL | 0:9d17e4342598 | 8353 | ssl->peerNtruKey, |
wolfSSL | 0:9d17e4342598 | 8354 | ssl->arrays->preMasterSz, |
wolfSSL | 0:9d17e4342598 | 8355 | ssl->arrays->preMasterSecret, |
wolfSSL | 0:9d17e4342598 | 8356 | &cipherLen, encSecret); |
wolfSSL | 0:9d17e4342598 | 8357 | crypto_drbg_uninstantiate(drbg); |
wolfSSL | 0:9d17e4342598 | 8358 | if (rc != NTRU_OK) |
wolfSSL | 0:9d17e4342598 | 8359 | return NTRU_ENCRYPT_ERROR; |
wolfSSL | 0:9d17e4342598 | 8360 | |
wolfSSL | 0:9d17e4342598 | 8361 | encSz = cipherLen; |
wolfSSL | 0:9d17e4342598 | 8362 | ret = 0; |
wolfSSL | 0:9d17e4342598 | 8363 | } |
wolfSSL | 0:9d17e4342598 | 8364 | break; |
wolfSSL | 0:9d17e4342598 | 8365 | #endif /* HAVE_NTRU */ |
wolfSSL | 0:9d17e4342598 | 8366 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 8367 | case ecc_diffie_hellman_kea: |
wolfSSL | 0:9d17e4342598 | 8368 | { |
wolfSSL | 0:9d17e4342598 | 8369 | ecc_key myKey; |
wolfSSL | 0:9d17e4342598 | 8370 | ecc_key* peerKey = NULL; |
wolfSSL | 0:9d17e4342598 | 8371 | word32 size = sizeof(encSecret); |
wolfSSL | 0:9d17e4342598 | 8372 | |
wolfSSL | 0:9d17e4342598 | 8373 | if (ssl->specs.static_ecdh) { |
wolfSSL | 0:9d17e4342598 | 8374 | /* TODO: EccDsa is really fixed Ecc change naming */ |
wolfSSL | 0:9d17e4342598 | 8375 | if (!ssl->peerEccDsaKeyPresent || !ssl->peerEccDsaKey->dp) |
wolfSSL | 0:9d17e4342598 | 8376 | return NO_PEER_KEY; |
wolfSSL | 0:9d17e4342598 | 8377 | peerKey = ssl->peerEccDsaKey; |
wolfSSL | 0:9d17e4342598 | 8378 | } |
wolfSSL | 0:9d17e4342598 | 8379 | else { |
wolfSSL | 0:9d17e4342598 | 8380 | if (!ssl->peerEccKeyPresent || !ssl->peerEccKey->dp) |
wolfSSL | 0:9d17e4342598 | 8381 | return NO_PEER_KEY; |
wolfSSL | 0:9d17e4342598 | 8382 | peerKey = ssl->peerEccKey; |
wolfSSL | 0:9d17e4342598 | 8383 | } |
wolfSSL | 0:9d17e4342598 | 8384 | |
wolfSSL | 0:9d17e4342598 | 8385 | if (peerKey == NULL) |
wolfSSL | 0:9d17e4342598 | 8386 | return NO_PEER_KEY; |
wolfSSL | 0:9d17e4342598 | 8387 | |
wolfSSL | 0:9d17e4342598 | 8388 | ecc_init(&myKey); |
wolfSSL | 0:9d17e4342598 | 8389 | ret = ecc_make_key(ssl->rng, peerKey->dp->size, &myKey); |
wolfSSL | 0:9d17e4342598 | 8390 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 8391 | return ECC_MAKEKEY_ERROR; |
wolfSSL | 0:9d17e4342598 | 8392 | |
wolfSSL | 0:9d17e4342598 | 8393 | /* precede export with 1 byte length */ |
wolfSSL | 0:9d17e4342598 | 8394 | ret = ecc_export_x963(&myKey, encSecret + 1, &size); |
wolfSSL | 0:9d17e4342598 | 8395 | encSecret[0] = (byte)size; |
wolfSSL | 0:9d17e4342598 | 8396 | encSz = size + 1; |
wolfSSL | 0:9d17e4342598 | 8397 | |
wolfSSL | 0:9d17e4342598 | 8398 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 8399 | ret = ECC_EXPORT_ERROR; |
wolfSSL | 0:9d17e4342598 | 8400 | else { |
wolfSSL | 0:9d17e4342598 | 8401 | size = sizeof(ssl->arrays->preMasterSecret); |
wolfSSL | 0:9d17e4342598 | 8402 | ret = ecc_shared_secret(&myKey, peerKey, |
wolfSSL | 0:9d17e4342598 | 8403 | ssl->arrays->preMasterSecret, &size); |
wolfSSL | 0:9d17e4342598 | 8404 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 8405 | ret = ECC_SHARED_ERROR; |
wolfSSL | 0:9d17e4342598 | 8406 | } |
wolfSSL | 0:9d17e4342598 | 8407 | |
wolfSSL | 0:9d17e4342598 | 8408 | ssl->arrays->preMasterSz = size; |
wolfSSL | 0:9d17e4342598 | 8409 | ecc_free(&myKey); |
wolfSSL | 0:9d17e4342598 | 8410 | } |
wolfSSL | 0:9d17e4342598 | 8411 | break; |
wolfSSL | 0:9d17e4342598 | 8412 | #endif /* HAVE_ECC */ |
wolfSSL | 0:9d17e4342598 | 8413 | default: |
wolfSSL | 0:9d17e4342598 | 8414 | return ALGO_ID_E; /* unsupported kea */ |
wolfSSL | 0:9d17e4342598 | 8415 | } |
wolfSSL | 0:9d17e4342598 | 8416 | |
wolfSSL | 0:9d17e4342598 | 8417 | if (ret == 0) { |
wolfSSL | 0:9d17e4342598 | 8418 | byte *output; |
wolfSSL | 0:9d17e4342598 | 8419 | int sendSz; |
wolfSSL | 0:9d17e4342598 | 8420 | word32 tlsSz = 0; |
wolfSSL | 0:9d17e4342598 | 8421 | |
wolfSSL | 0:9d17e4342598 | 8422 | if (ssl->options.tls || ssl->specs.kea == diffie_hellman_kea) |
wolfSSL | 0:9d17e4342598 | 8423 | tlsSz = 2; |
wolfSSL | 0:9d17e4342598 | 8424 | |
wolfSSL | 0:9d17e4342598 | 8425 | if (ssl->specs.kea == ecc_diffie_hellman_kea) /* always off */ |
wolfSSL | 0:9d17e4342598 | 8426 | tlsSz = 0; |
wolfSSL | 0:9d17e4342598 | 8427 | |
wolfSSL | 0:9d17e4342598 | 8428 | sendSz = encSz + tlsSz + HANDSHAKE_HEADER_SZ + RECORD_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 8429 | idx = HANDSHAKE_HEADER_SZ + RECORD_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 8430 | |
wolfSSL | 0:9d17e4342598 | 8431 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 8432 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 8433 | sendSz += DTLS_HANDSHAKE_EXTRA + DTLS_RECORD_EXTRA; |
wolfSSL | 0:9d17e4342598 | 8434 | idx += DTLS_HANDSHAKE_EXTRA + DTLS_RECORD_EXTRA; |
wolfSSL | 0:9d17e4342598 | 8435 | } |
wolfSSL | 0:9d17e4342598 | 8436 | #endif |
wolfSSL | 0:9d17e4342598 | 8437 | |
wolfSSL | 0:9d17e4342598 | 8438 | /* check for available size */ |
wolfSSL | 0:9d17e4342598 | 8439 | if ((ret = CheckAvailableSize(ssl, sendSz)) != 0) |
wolfSSL | 0:9d17e4342598 | 8440 | return ret; |
wolfSSL | 0:9d17e4342598 | 8441 | |
wolfSSL | 0:9d17e4342598 | 8442 | /* get ouput buffer */ |
wolfSSL | 0:9d17e4342598 | 8443 | output = ssl->buffers.outputBuffer.buffer + |
wolfSSL | 0:9d17e4342598 | 8444 | ssl->buffers.outputBuffer.length; |
wolfSSL | 0:9d17e4342598 | 8445 | |
wolfSSL | 0:9d17e4342598 | 8446 | AddHeaders(output, encSz + tlsSz, client_key_exchange, ssl); |
wolfSSL | 0:9d17e4342598 | 8447 | |
wolfSSL | 0:9d17e4342598 | 8448 | if (tlsSz) { |
wolfSSL | 0:9d17e4342598 | 8449 | c16toa((word16)encSz, &output[idx]); |
wolfSSL | 0:9d17e4342598 | 8450 | idx += 2; |
wolfSSL | 0:9d17e4342598 | 8451 | } |
wolfSSL | 0:9d17e4342598 | 8452 | XMEMCPY(output + idx, encSecret, encSz); |
wolfSSL | 0:9d17e4342598 | 8453 | /* if add more to output, adjust idx |
wolfSSL | 0:9d17e4342598 | 8454 | idx += encSz; */ |
wolfSSL | 0:9d17e4342598 | 8455 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 8456 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 8457 | if ((ret = DtlsPoolSave(ssl, output, sendSz)) != 0) |
wolfSSL | 0:9d17e4342598 | 8458 | return ret; |
wolfSSL | 0:9d17e4342598 | 8459 | } |
wolfSSL | 0:9d17e4342598 | 8460 | #endif |
wolfSSL | 0:9d17e4342598 | 8461 | HashOutput(ssl, output, sendSz, 0); |
wolfSSL | 0:9d17e4342598 | 8462 | |
wolfSSL | 0:9d17e4342598 | 8463 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 8464 | if (ssl->hsInfoOn) |
wolfSSL | 0:9d17e4342598 | 8465 | AddPacketName("ClientKeyExchange", &ssl->handShakeInfo); |
wolfSSL | 0:9d17e4342598 | 8466 | if (ssl->toInfoOn) |
wolfSSL | 0:9d17e4342598 | 8467 | AddPacketInfo("ClientKeyExchange", &ssl->timeoutInfo, |
wolfSSL | 0:9d17e4342598 | 8468 | output, sendSz, ssl->heap); |
wolfSSL | 0:9d17e4342598 | 8469 | #endif |
wolfSSL | 0:9d17e4342598 | 8470 | |
wolfSSL | 0:9d17e4342598 | 8471 | ssl->buffers.outputBuffer.length += sendSz; |
wolfSSL | 0:9d17e4342598 | 8472 | |
wolfSSL | 0:9d17e4342598 | 8473 | if (ssl->options.groupMessages) |
wolfSSL | 0:9d17e4342598 | 8474 | ret = 0; |
wolfSSL | 0:9d17e4342598 | 8475 | else |
wolfSSL | 0:9d17e4342598 | 8476 | ret = SendBuffered(ssl); |
wolfSSL | 0:9d17e4342598 | 8477 | } |
wolfSSL | 0:9d17e4342598 | 8478 | |
wolfSSL | 0:9d17e4342598 | 8479 | if (ret == 0 || ret == WANT_WRITE) { |
wolfSSL | 0:9d17e4342598 | 8480 | int tmpRet = MakeMasterSecret(ssl); |
wolfSSL | 0:9d17e4342598 | 8481 | if (tmpRet != 0) |
wolfSSL | 0:9d17e4342598 | 8482 | ret = tmpRet; /* save WANT_WRITE unless more serious */ |
wolfSSL | 0:9d17e4342598 | 8483 | ssl->options.clientState = CLIENT_KEYEXCHANGE_COMPLETE; |
wolfSSL | 0:9d17e4342598 | 8484 | } |
wolfSSL | 0:9d17e4342598 | 8485 | /* No further need for PMS */ |
wolfSSL | 0:9d17e4342598 | 8486 | XMEMSET(ssl->arrays->preMasterSecret, 0, ssl->arrays->preMasterSz); |
wolfSSL | 0:9d17e4342598 | 8487 | ssl->arrays->preMasterSz = 0; |
wolfSSL | 0:9d17e4342598 | 8488 | |
wolfSSL | 0:9d17e4342598 | 8489 | return ret; |
wolfSSL | 0:9d17e4342598 | 8490 | } |
wolfSSL | 0:9d17e4342598 | 8491 | |
wolfSSL | 0:9d17e4342598 | 8492 | #ifndef NO_CERTS |
wolfSSL | 0:9d17e4342598 | 8493 | int SendCertificateVerify(CYASSL* ssl) |
wolfSSL | 0:9d17e4342598 | 8494 | { |
wolfSSL | 0:9d17e4342598 | 8495 | byte *output; |
wolfSSL | 0:9d17e4342598 | 8496 | int sendSz = 0, length, ret; |
wolfSSL | 0:9d17e4342598 | 8497 | word32 idx = 0; |
wolfSSL | 0:9d17e4342598 | 8498 | word32 sigOutSz = 0; |
wolfSSL | 0:9d17e4342598 | 8499 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 8500 | RsaKey key; |
wolfSSL | 0:9d17e4342598 | 8501 | int initRsaKey = 0; |
wolfSSL | 0:9d17e4342598 | 8502 | #endif |
wolfSSL | 0:9d17e4342598 | 8503 | int usingEcc = 0; |
wolfSSL | 0:9d17e4342598 | 8504 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 8505 | ecc_key eccKey; |
wolfSSL | 0:9d17e4342598 | 8506 | #endif |
wolfSSL | 0:9d17e4342598 | 8507 | |
wolfSSL | 0:9d17e4342598 | 8508 | (void)idx; |
wolfSSL | 0:9d17e4342598 | 8509 | |
wolfSSL | 0:9d17e4342598 | 8510 | if (ssl->options.sendVerify == SEND_BLANK_CERT) |
wolfSSL | 0:9d17e4342598 | 8511 | return 0; /* sent blank cert, can't verify */ |
wolfSSL | 0:9d17e4342598 | 8512 | |
wolfSSL | 0:9d17e4342598 | 8513 | /* check for available size */ |
wolfSSL | 0:9d17e4342598 | 8514 | if ((ret = CheckAvailableSize(ssl, MAX_CERT_VERIFY_SZ)) != 0) |
wolfSSL | 0:9d17e4342598 | 8515 | return ret; |
wolfSSL | 0:9d17e4342598 | 8516 | |
wolfSSL | 0:9d17e4342598 | 8517 | /* get ouput buffer */ |
wolfSSL | 0:9d17e4342598 | 8518 | output = ssl->buffers.outputBuffer.buffer + |
wolfSSL | 0:9d17e4342598 | 8519 | ssl->buffers.outputBuffer.length; |
wolfSSL | 0:9d17e4342598 | 8520 | |
wolfSSL | 0:9d17e4342598 | 8521 | BuildCertHashes(ssl, &ssl->certHashes); |
wolfSSL | 0:9d17e4342598 | 8522 | |
wolfSSL | 0:9d17e4342598 | 8523 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 8524 | ecc_init(&eccKey); |
wolfSSL | 0:9d17e4342598 | 8525 | #endif |
wolfSSL | 0:9d17e4342598 | 8526 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 8527 | ret = InitRsaKey(&key, ssl->heap); |
wolfSSL | 0:9d17e4342598 | 8528 | if (ret == 0) initRsaKey = 1; |
wolfSSL | 0:9d17e4342598 | 8529 | if (ret == 0) |
wolfSSL | 0:9d17e4342598 | 8530 | ret = RsaPrivateKeyDecode(ssl->buffers.key.buffer, &idx, &key, |
wolfSSL | 0:9d17e4342598 | 8531 | ssl->buffers.key.length); |
wolfSSL | 0:9d17e4342598 | 8532 | if (ret == 0) |
wolfSSL | 0:9d17e4342598 | 8533 | sigOutSz = RsaEncryptSize(&key); |
wolfSSL | 0:9d17e4342598 | 8534 | else |
wolfSSL | 0:9d17e4342598 | 8535 | #endif |
wolfSSL | 0:9d17e4342598 | 8536 | { |
wolfSSL | 0:9d17e4342598 | 8537 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 8538 | CYASSL_MSG("Trying ECC client cert, RSA didn't work"); |
wolfSSL | 0:9d17e4342598 | 8539 | |
wolfSSL | 0:9d17e4342598 | 8540 | idx = 0; |
wolfSSL | 0:9d17e4342598 | 8541 | ret = EccPrivateKeyDecode(ssl->buffers.key.buffer, &idx, &eccKey, |
wolfSSL | 0:9d17e4342598 | 8542 | ssl->buffers.key.length); |
wolfSSL | 0:9d17e4342598 | 8543 | if (ret == 0) { |
wolfSSL | 0:9d17e4342598 | 8544 | CYASSL_MSG("Using ECC client cert"); |
wolfSSL | 0:9d17e4342598 | 8545 | usingEcc = 1; |
wolfSSL | 0:9d17e4342598 | 8546 | sigOutSz = MAX_ENCODED_SIG_SZ; |
wolfSSL | 0:9d17e4342598 | 8547 | } |
wolfSSL | 0:9d17e4342598 | 8548 | else { |
wolfSSL | 0:9d17e4342598 | 8549 | CYASSL_MSG("Bad client cert type"); |
wolfSSL | 0:9d17e4342598 | 8550 | } |
wolfSSL | 0:9d17e4342598 | 8551 | #endif |
wolfSSL | 0:9d17e4342598 | 8552 | } |
wolfSSL | 0:9d17e4342598 | 8553 | if (ret == 0) { |
wolfSSL | 0:9d17e4342598 | 8554 | byte* verify = (byte*)&output[RECORD_HEADER_SZ + |
wolfSSL | 0:9d17e4342598 | 8555 | HANDSHAKE_HEADER_SZ]; |
wolfSSL | 0:9d17e4342598 | 8556 | #ifndef NO_OLD_TLS |
wolfSSL | 0:9d17e4342598 | 8557 | byte* signBuffer = ssl->certHashes.md5; |
wolfSSL | 0:9d17e4342598 | 8558 | #else |
wolfSSL | 0:9d17e4342598 | 8559 | byte* signBuffer = NULL; |
wolfSSL | 0:9d17e4342598 | 8560 | #endif |
wolfSSL | 0:9d17e4342598 | 8561 | word32 signSz = FINISHED_SZ; |
wolfSSL | 0:9d17e4342598 | 8562 | byte encodedSig[MAX_ENCODED_SIG_SZ]; |
wolfSSL | 0:9d17e4342598 | 8563 | word32 extraSz = 0; /* tls 1.2 hash/sig */ |
wolfSSL | 0:9d17e4342598 | 8564 | |
wolfSSL | 0:9d17e4342598 | 8565 | (void)encodedSig; |
wolfSSL | 0:9d17e4342598 | 8566 | (void)signSz; |
wolfSSL | 0:9d17e4342598 | 8567 | (void)signBuffer; |
wolfSSL | 0:9d17e4342598 | 8568 | |
wolfSSL | 0:9d17e4342598 | 8569 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 8570 | if (ssl->options.dtls) |
wolfSSL | 0:9d17e4342598 | 8571 | verify += DTLS_RECORD_EXTRA + DTLS_HANDSHAKE_EXTRA; |
wolfSSL | 0:9d17e4342598 | 8572 | #endif |
wolfSSL | 0:9d17e4342598 | 8573 | length = sigOutSz; |
wolfSSL | 0:9d17e4342598 | 8574 | if (IsAtLeastTLSv1_2(ssl)) { |
wolfSSL | 0:9d17e4342598 | 8575 | verify[0] = ssl->suites->hashAlgo; |
wolfSSL | 0:9d17e4342598 | 8576 | verify[1] = usingEcc ? ecc_dsa_sa_algo : rsa_sa_algo; |
wolfSSL | 0:9d17e4342598 | 8577 | extraSz = HASH_SIG_SIZE; |
wolfSSL | 0:9d17e4342598 | 8578 | } |
wolfSSL | 0:9d17e4342598 | 8579 | |
wolfSSL | 0:9d17e4342598 | 8580 | if (usingEcc) { |
wolfSSL | 0:9d17e4342598 | 8581 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 8582 | word32 localSz = MAX_ENCODED_SIG_SZ; |
wolfSSL | 0:9d17e4342598 | 8583 | word32 digestSz; |
wolfSSL | 0:9d17e4342598 | 8584 | byte* digest; |
wolfSSL | 0:9d17e4342598 | 8585 | byte doUserEcc = 0; |
wolfSSL | 0:9d17e4342598 | 8586 | #ifndef NO_OLD_TLS |
wolfSSL | 0:9d17e4342598 | 8587 | /* old tls default */ |
wolfSSL | 0:9d17e4342598 | 8588 | digestSz = SHA_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 8589 | digest = ssl->certHashes.sha; |
wolfSSL | 0:9d17e4342598 | 8590 | #else |
wolfSSL | 0:9d17e4342598 | 8591 | /* new tls default */ |
wolfSSL | 0:9d17e4342598 | 8592 | digestSz = SHA256_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 8593 | digest = ssl->certHashes.sha256; |
wolfSSL | 0:9d17e4342598 | 8594 | #endif |
wolfSSL | 0:9d17e4342598 | 8595 | |
wolfSSL | 0:9d17e4342598 | 8596 | #ifdef HAVE_PK_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 8597 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 8598 | if (ssl->ctx->EccSignCb) |
wolfSSL | 0:9d17e4342598 | 8599 | doUserEcc = 1; |
wolfSSL | 0:9d17e4342598 | 8600 | #endif /* HAVE_ECC */ |
wolfSSL | 0:9d17e4342598 | 8601 | #endif /*HAVE_PK_CALLBACKS */ |
wolfSSL | 0:9d17e4342598 | 8602 | |
wolfSSL | 0:9d17e4342598 | 8603 | if (IsAtLeastTLSv1_2(ssl)) { |
wolfSSL | 0:9d17e4342598 | 8604 | if (ssl->suites->hashAlgo == sha_mac) { |
wolfSSL | 0:9d17e4342598 | 8605 | #ifndef NO_SHA |
wolfSSL | 0:9d17e4342598 | 8606 | digest = ssl->certHashes.sha; |
wolfSSL | 0:9d17e4342598 | 8607 | digestSz = SHA_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 8608 | #endif |
wolfSSL | 0:9d17e4342598 | 8609 | } |
wolfSSL | 0:9d17e4342598 | 8610 | else if (ssl->suites->hashAlgo == sha256_mac) { |
wolfSSL | 0:9d17e4342598 | 8611 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 8612 | digest = ssl->certHashes.sha256; |
wolfSSL | 0:9d17e4342598 | 8613 | digestSz = SHA256_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 8614 | #endif |
wolfSSL | 0:9d17e4342598 | 8615 | } |
wolfSSL | 0:9d17e4342598 | 8616 | else if (ssl->suites->hashAlgo == sha384_mac) { |
wolfSSL | 0:9d17e4342598 | 8617 | #ifdef CYASSL_SHA384 |
wolfSSL | 0:9d17e4342598 | 8618 | digest = ssl->certHashes.sha384; |
wolfSSL | 0:9d17e4342598 | 8619 | digestSz = SHA384_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 8620 | #endif |
wolfSSL | 0:9d17e4342598 | 8621 | } |
wolfSSL | 0:9d17e4342598 | 8622 | } |
wolfSSL | 0:9d17e4342598 | 8623 | |
wolfSSL | 0:9d17e4342598 | 8624 | if (doUserEcc) { |
wolfSSL | 0:9d17e4342598 | 8625 | #ifdef HAVE_PK_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 8626 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 8627 | ret = ssl->ctx->EccSignCb(ssl, digest, digestSz, |
wolfSSL | 0:9d17e4342598 | 8628 | encodedSig, &localSz, |
wolfSSL | 0:9d17e4342598 | 8629 | ssl->buffers.key.buffer, |
wolfSSL | 0:9d17e4342598 | 8630 | ssl->buffers.key.length, |
wolfSSL | 0:9d17e4342598 | 8631 | ssl->EccSignCtx); |
wolfSSL | 0:9d17e4342598 | 8632 | #endif /* HAVE_ECC */ |
wolfSSL | 0:9d17e4342598 | 8633 | #endif /*HAVE_PK_CALLBACKS */ |
wolfSSL | 0:9d17e4342598 | 8634 | } |
wolfSSL | 0:9d17e4342598 | 8635 | else { |
wolfSSL | 0:9d17e4342598 | 8636 | ret = ecc_sign_hash(digest, digestSz, encodedSig, |
wolfSSL | 0:9d17e4342598 | 8637 | &localSz, ssl->rng, &eccKey); |
wolfSSL | 0:9d17e4342598 | 8638 | } |
wolfSSL | 0:9d17e4342598 | 8639 | if (ret == 0) { |
wolfSSL | 0:9d17e4342598 | 8640 | length = localSz; |
wolfSSL | 0:9d17e4342598 | 8641 | c16toa((word16)length, verify + extraSz); /* prepend hdr */ |
wolfSSL | 0:9d17e4342598 | 8642 | XMEMCPY(verify + extraSz + VERIFY_HEADER,encodedSig,length); |
wolfSSL | 0:9d17e4342598 | 8643 | } |
wolfSSL | 0:9d17e4342598 | 8644 | #endif |
wolfSSL | 0:9d17e4342598 | 8645 | } |
wolfSSL | 0:9d17e4342598 | 8646 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 8647 | else { |
wolfSSL | 0:9d17e4342598 | 8648 | byte doUserRsa = 0; |
wolfSSL | 0:9d17e4342598 | 8649 | |
wolfSSL | 0:9d17e4342598 | 8650 | #ifdef HAVE_PK_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 8651 | if (ssl->ctx->RsaSignCb) |
wolfSSL | 0:9d17e4342598 | 8652 | doUserRsa = 1; |
wolfSSL | 0:9d17e4342598 | 8653 | #endif /*HAVE_PK_CALLBACKS */ |
wolfSSL | 0:9d17e4342598 | 8654 | |
wolfSSL | 0:9d17e4342598 | 8655 | if (IsAtLeastTLSv1_2(ssl)) { |
wolfSSL | 0:9d17e4342598 | 8656 | #ifndef NO_OLD_TLS |
wolfSSL | 0:9d17e4342598 | 8657 | byte* digest = ssl->certHashes.sha; |
wolfSSL | 0:9d17e4342598 | 8658 | int digestSz = SHA_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 8659 | int typeH = SHAh; |
wolfSSL | 0:9d17e4342598 | 8660 | #else |
wolfSSL | 0:9d17e4342598 | 8661 | byte* digest = ssl->certHashes.sha256; |
wolfSSL | 0:9d17e4342598 | 8662 | int digestSz = SHA256_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 8663 | int typeH = SHA256h; |
wolfSSL | 0:9d17e4342598 | 8664 | #endif |
wolfSSL | 0:9d17e4342598 | 8665 | |
wolfSSL | 0:9d17e4342598 | 8666 | if (ssl->suites->hashAlgo == sha_mac) { |
wolfSSL | 0:9d17e4342598 | 8667 | #ifndef NO_SHA |
wolfSSL | 0:9d17e4342598 | 8668 | digest = ssl->certHashes.sha; |
wolfSSL | 0:9d17e4342598 | 8669 | typeH = SHAh; |
wolfSSL | 0:9d17e4342598 | 8670 | digestSz = SHA_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 8671 | #endif |
wolfSSL | 0:9d17e4342598 | 8672 | } |
wolfSSL | 0:9d17e4342598 | 8673 | else if (ssl->suites->hashAlgo == sha256_mac) { |
wolfSSL | 0:9d17e4342598 | 8674 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 8675 | digest = ssl->certHashes.sha256; |
wolfSSL | 0:9d17e4342598 | 8676 | typeH = SHA256h; |
wolfSSL | 0:9d17e4342598 | 8677 | digestSz = SHA256_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 8678 | #endif |
wolfSSL | 0:9d17e4342598 | 8679 | } |
wolfSSL | 0:9d17e4342598 | 8680 | else if (ssl->suites->hashAlgo == sha384_mac) { |
wolfSSL | 0:9d17e4342598 | 8681 | #ifdef CYASSL_SHA384 |
wolfSSL | 0:9d17e4342598 | 8682 | digest = ssl->certHashes.sha384; |
wolfSSL | 0:9d17e4342598 | 8683 | typeH = SHA384h; |
wolfSSL | 0:9d17e4342598 | 8684 | digestSz = SHA384_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 8685 | #endif |
wolfSSL | 0:9d17e4342598 | 8686 | } |
wolfSSL | 0:9d17e4342598 | 8687 | |
wolfSSL | 0:9d17e4342598 | 8688 | signSz = EncodeSignature(encodedSig, digest,digestSz,typeH); |
wolfSSL | 0:9d17e4342598 | 8689 | signBuffer = encodedSig; |
wolfSSL | 0:9d17e4342598 | 8690 | } |
wolfSSL | 0:9d17e4342598 | 8691 | |
wolfSSL | 0:9d17e4342598 | 8692 | c16toa((word16)length, verify + extraSz); /* prepend hdr */ |
wolfSSL | 0:9d17e4342598 | 8693 | if (doUserRsa) { |
wolfSSL | 0:9d17e4342598 | 8694 | #ifdef HAVE_PK_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 8695 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 8696 | word32 ioLen = ENCRYPT_LEN; |
wolfSSL | 0:9d17e4342598 | 8697 | ret = ssl->ctx->RsaSignCb(ssl, signBuffer, signSz, |
wolfSSL | 0:9d17e4342598 | 8698 | verify + extraSz + VERIFY_HEADER, |
wolfSSL | 0:9d17e4342598 | 8699 | &ioLen, |
wolfSSL | 0:9d17e4342598 | 8700 | ssl->buffers.key.buffer, |
wolfSSL | 0:9d17e4342598 | 8701 | ssl->buffers.key.length, |
wolfSSL | 0:9d17e4342598 | 8702 | ssl->RsaSignCtx); |
wolfSSL | 0:9d17e4342598 | 8703 | #endif /* NO_RSA */ |
wolfSSL | 0:9d17e4342598 | 8704 | #endif /*HAVE_PK_CALLBACKS */ |
wolfSSL | 0:9d17e4342598 | 8705 | } |
wolfSSL | 0:9d17e4342598 | 8706 | else { |
wolfSSL | 0:9d17e4342598 | 8707 | ret = RsaSSL_Sign(signBuffer, signSz, verify + extraSz + |
wolfSSL | 0:9d17e4342598 | 8708 | VERIFY_HEADER, ENCRYPT_LEN, &key, ssl->rng); |
wolfSSL | 0:9d17e4342598 | 8709 | } |
wolfSSL | 0:9d17e4342598 | 8710 | |
wolfSSL | 0:9d17e4342598 | 8711 | if (ret > 0) |
wolfSSL | 0:9d17e4342598 | 8712 | ret = 0; /* RSA reset */ |
wolfSSL | 0:9d17e4342598 | 8713 | } |
wolfSSL | 0:9d17e4342598 | 8714 | #endif |
wolfSSL | 0:9d17e4342598 | 8715 | if (ret == 0) { |
wolfSSL | 0:9d17e4342598 | 8716 | AddHeaders(output, length + extraSz + VERIFY_HEADER, |
wolfSSL | 0:9d17e4342598 | 8717 | certificate_verify, ssl); |
wolfSSL | 0:9d17e4342598 | 8718 | |
wolfSSL | 0:9d17e4342598 | 8719 | sendSz = RECORD_HEADER_SZ + HANDSHAKE_HEADER_SZ + length + |
wolfSSL | 0:9d17e4342598 | 8720 | extraSz + VERIFY_HEADER; |
wolfSSL | 0:9d17e4342598 | 8721 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 8722 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 8723 | sendSz += DTLS_RECORD_EXTRA + DTLS_HANDSHAKE_EXTRA; |
wolfSSL | 0:9d17e4342598 | 8724 | if ((ret = DtlsPoolSave(ssl, output, sendSz)) != 0) |
wolfSSL | 0:9d17e4342598 | 8725 | return ret; |
wolfSSL | 0:9d17e4342598 | 8726 | } |
wolfSSL | 0:9d17e4342598 | 8727 | #endif |
wolfSSL | 0:9d17e4342598 | 8728 | HashOutput(ssl, output, sendSz, 0); |
wolfSSL | 0:9d17e4342598 | 8729 | } |
wolfSSL | 0:9d17e4342598 | 8730 | } |
wolfSSL | 0:9d17e4342598 | 8731 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 8732 | if (initRsaKey) |
wolfSSL | 0:9d17e4342598 | 8733 | FreeRsaKey(&key); |
wolfSSL | 0:9d17e4342598 | 8734 | #endif |
wolfSSL | 0:9d17e4342598 | 8735 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 8736 | ecc_free(&eccKey); |
wolfSSL | 0:9d17e4342598 | 8737 | #endif |
wolfSSL | 0:9d17e4342598 | 8738 | |
wolfSSL | 0:9d17e4342598 | 8739 | if (ret == 0) { |
wolfSSL | 0:9d17e4342598 | 8740 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 8741 | if (ssl->hsInfoOn) |
wolfSSL | 0:9d17e4342598 | 8742 | AddPacketName("CertificateVerify", &ssl->handShakeInfo); |
wolfSSL | 0:9d17e4342598 | 8743 | if (ssl->toInfoOn) |
wolfSSL | 0:9d17e4342598 | 8744 | AddPacketInfo("CertificateVerify", &ssl->timeoutInfo, |
wolfSSL | 0:9d17e4342598 | 8745 | output, sendSz, ssl->heap); |
wolfSSL | 0:9d17e4342598 | 8746 | #endif |
wolfSSL | 0:9d17e4342598 | 8747 | ssl->buffers.outputBuffer.length += sendSz; |
wolfSSL | 0:9d17e4342598 | 8748 | if (ssl->options.groupMessages) |
wolfSSL | 0:9d17e4342598 | 8749 | return 0; |
wolfSSL | 0:9d17e4342598 | 8750 | else |
wolfSSL | 0:9d17e4342598 | 8751 | return SendBuffered(ssl); |
wolfSSL | 0:9d17e4342598 | 8752 | } |
wolfSSL | 0:9d17e4342598 | 8753 | else |
wolfSSL | 0:9d17e4342598 | 8754 | return ret; |
wolfSSL | 0:9d17e4342598 | 8755 | } |
wolfSSL | 0:9d17e4342598 | 8756 | #endif /* NO_CERTS */ |
wolfSSL | 0:9d17e4342598 | 8757 | |
wolfSSL | 0:9d17e4342598 | 8758 | |
wolfSSL | 0:9d17e4342598 | 8759 | #endif /* NO_CYASSL_CLIENT */ |
wolfSSL | 0:9d17e4342598 | 8760 | |
wolfSSL | 0:9d17e4342598 | 8761 | |
wolfSSL | 0:9d17e4342598 | 8762 | #ifndef NO_CYASSL_SERVER |
wolfSSL | 0:9d17e4342598 | 8763 | |
wolfSSL | 0:9d17e4342598 | 8764 | int SendServerHello(CYASSL* ssl) |
wolfSSL | 0:9d17e4342598 | 8765 | { |
wolfSSL | 0:9d17e4342598 | 8766 | byte *output; |
wolfSSL | 0:9d17e4342598 | 8767 | word32 length, idx = RECORD_HEADER_SZ + HANDSHAKE_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 8768 | int sendSz; |
wolfSSL | 0:9d17e4342598 | 8769 | int ret; |
wolfSSL | 0:9d17e4342598 | 8770 | |
wolfSSL | 0:9d17e4342598 | 8771 | length = VERSION_SZ + RAN_LEN |
wolfSSL | 0:9d17e4342598 | 8772 | + ID_LEN + ENUM_LEN |
wolfSSL | 0:9d17e4342598 | 8773 | + SUITE_LEN |
wolfSSL | 0:9d17e4342598 | 8774 | + ENUM_LEN; |
wolfSSL | 0:9d17e4342598 | 8775 | |
wolfSSL | 0:9d17e4342598 | 8776 | #ifdef HAVE_TLS_EXTENSIONS |
wolfSSL | 0:9d17e4342598 | 8777 | length += TLSX_GetResponseSize(ssl); |
wolfSSL | 0:9d17e4342598 | 8778 | #endif |
wolfSSL | 0:9d17e4342598 | 8779 | |
wolfSSL | 0:9d17e4342598 | 8780 | /* check for avalaible size */ |
wolfSSL | 0:9d17e4342598 | 8781 | if ((ret = CheckAvailableSize(ssl, MAX_HELLO_SZ)) != 0) |
wolfSSL | 0:9d17e4342598 | 8782 | return ret; |
wolfSSL | 0:9d17e4342598 | 8783 | |
wolfSSL | 0:9d17e4342598 | 8784 | /* get ouput buffer */ |
wolfSSL | 0:9d17e4342598 | 8785 | output = ssl->buffers.outputBuffer.buffer + |
wolfSSL | 0:9d17e4342598 | 8786 | ssl->buffers.outputBuffer.length; |
wolfSSL | 0:9d17e4342598 | 8787 | |
wolfSSL | 0:9d17e4342598 | 8788 | sendSz = length + HANDSHAKE_HEADER_SZ + RECORD_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 8789 | AddHeaders(output, length, server_hello, ssl); |
wolfSSL | 0:9d17e4342598 | 8790 | |
wolfSSL | 0:9d17e4342598 | 8791 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 8792 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 8793 | idx += DTLS_RECORD_EXTRA + DTLS_HANDSHAKE_EXTRA; |
wolfSSL | 0:9d17e4342598 | 8794 | sendSz += DTLS_RECORD_EXTRA + DTLS_HANDSHAKE_EXTRA; |
wolfSSL | 0:9d17e4342598 | 8795 | } |
wolfSSL | 0:9d17e4342598 | 8796 | #endif |
wolfSSL | 0:9d17e4342598 | 8797 | /* now write to output */ |
wolfSSL | 0:9d17e4342598 | 8798 | /* first version */ |
wolfSSL | 0:9d17e4342598 | 8799 | output[idx++] = ssl->version.major; |
wolfSSL | 0:9d17e4342598 | 8800 | output[idx++] = ssl->version.minor; |
wolfSSL | 0:9d17e4342598 | 8801 | |
wolfSSL | 0:9d17e4342598 | 8802 | /* then random */ |
wolfSSL | 0:9d17e4342598 | 8803 | if (!ssl->options.resuming) |
wolfSSL | 0:9d17e4342598 | 8804 | RNG_GenerateBlock(ssl->rng, ssl->arrays->serverRandom, RAN_LEN); |
wolfSSL | 0:9d17e4342598 | 8805 | XMEMCPY(output + idx, ssl->arrays->serverRandom, RAN_LEN); |
wolfSSL | 0:9d17e4342598 | 8806 | idx += RAN_LEN; |
wolfSSL | 0:9d17e4342598 | 8807 | |
wolfSSL | 0:9d17e4342598 | 8808 | #ifdef SHOW_SECRETS |
wolfSSL | 0:9d17e4342598 | 8809 | { |
wolfSSL | 0:9d17e4342598 | 8810 | int j; |
wolfSSL | 0:9d17e4342598 | 8811 | printf("server random: "); |
wolfSSL | 0:9d17e4342598 | 8812 | for (j = 0; j < RAN_LEN; j++) |
wolfSSL | 0:9d17e4342598 | 8813 | printf("%02x", ssl->arrays->serverRandom[j]); |
wolfSSL | 0:9d17e4342598 | 8814 | printf("\n"); |
wolfSSL | 0:9d17e4342598 | 8815 | } |
wolfSSL | 0:9d17e4342598 | 8816 | #endif |
wolfSSL | 0:9d17e4342598 | 8817 | /* then session id */ |
wolfSSL | 0:9d17e4342598 | 8818 | output[idx++] = ID_LEN; |
wolfSSL | 0:9d17e4342598 | 8819 | if (!ssl->options.resuming) |
wolfSSL | 0:9d17e4342598 | 8820 | RNG_GenerateBlock(ssl->rng, ssl->arrays->sessionID, ID_LEN); |
wolfSSL | 0:9d17e4342598 | 8821 | XMEMCPY(output + idx, ssl->arrays->sessionID, ID_LEN); |
wolfSSL | 0:9d17e4342598 | 8822 | idx += ID_LEN; |
wolfSSL | 0:9d17e4342598 | 8823 | |
wolfSSL | 0:9d17e4342598 | 8824 | /* then cipher suite */ |
wolfSSL | 0:9d17e4342598 | 8825 | output[idx++] = ssl->options.cipherSuite0; |
wolfSSL | 0:9d17e4342598 | 8826 | output[idx++] = ssl->options.cipherSuite; |
wolfSSL | 0:9d17e4342598 | 8827 | |
wolfSSL | 0:9d17e4342598 | 8828 | /* then compression */ |
wolfSSL | 0:9d17e4342598 | 8829 | if (ssl->options.usingCompression) |
wolfSSL | 0:9d17e4342598 | 8830 | output[idx++] = ZLIB_COMPRESSION; |
wolfSSL | 0:9d17e4342598 | 8831 | else |
wolfSSL | 0:9d17e4342598 | 8832 | output[idx++] = NO_COMPRESSION; |
wolfSSL | 0:9d17e4342598 | 8833 | |
wolfSSL | 0:9d17e4342598 | 8834 | /* last, extensions */ |
wolfSSL | 0:9d17e4342598 | 8835 | #ifdef HAVE_TLS_EXTENSIONS |
wolfSSL | 0:9d17e4342598 | 8836 | if (IsTLS(ssl)) |
wolfSSL | 0:9d17e4342598 | 8837 | TLSX_WriteResponse(ssl, output + idx); |
wolfSSL | 0:9d17e4342598 | 8838 | #endif |
wolfSSL | 0:9d17e4342598 | 8839 | |
wolfSSL | 0:9d17e4342598 | 8840 | ssl->buffers.outputBuffer.length += sendSz; |
wolfSSL | 0:9d17e4342598 | 8841 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 8842 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 8843 | if ((ret = DtlsPoolSave(ssl, output, sendSz)) != 0) |
wolfSSL | 0:9d17e4342598 | 8844 | return ret; |
wolfSSL | 0:9d17e4342598 | 8845 | } |
wolfSSL | 0:9d17e4342598 | 8846 | #endif |
wolfSSL | 0:9d17e4342598 | 8847 | HashOutput(ssl, output, sendSz, 0); |
wolfSSL | 0:9d17e4342598 | 8848 | |
wolfSSL | 0:9d17e4342598 | 8849 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 8850 | if (ssl->hsInfoOn) |
wolfSSL | 0:9d17e4342598 | 8851 | AddPacketName("ServerHello", &ssl->handShakeInfo); |
wolfSSL | 0:9d17e4342598 | 8852 | if (ssl->toInfoOn) |
wolfSSL | 0:9d17e4342598 | 8853 | AddPacketInfo("ServerHello", &ssl->timeoutInfo, output, sendSz, |
wolfSSL | 0:9d17e4342598 | 8854 | ssl->heap); |
wolfSSL | 0:9d17e4342598 | 8855 | #endif |
wolfSSL | 0:9d17e4342598 | 8856 | |
wolfSSL | 0:9d17e4342598 | 8857 | ssl->options.serverState = SERVER_HELLO_COMPLETE; |
wolfSSL | 0:9d17e4342598 | 8858 | |
wolfSSL | 0:9d17e4342598 | 8859 | if (ssl->options.groupMessages) |
wolfSSL | 0:9d17e4342598 | 8860 | return 0; |
wolfSSL | 0:9d17e4342598 | 8861 | else |
wolfSSL | 0:9d17e4342598 | 8862 | return SendBuffered(ssl); |
wolfSSL | 0:9d17e4342598 | 8863 | } |
wolfSSL | 0:9d17e4342598 | 8864 | |
wolfSSL | 0:9d17e4342598 | 8865 | |
wolfSSL | 0:9d17e4342598 | 8866 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 8867 | |
wolfSSL | 0:9d17e4342598 | 8868 | static byte SetCurveId(int size) |
wolfSSL | 0:9d17e4342598 | 8869 | { |
wolfSSL | 0:9d17e4342598 | 8870 | switch(size) { |
wolfSSL | 0:9d17e4342598 | 8871 | case 20: |
wolfSSL | 0:9d17e4342598 | 8872 | return secp160r1; |
wolfSSL | 0:9d17e4342598 | 8873 | case 24: |
wolfSSL | 0:9d17e4342598 | 8874 | return secp192r1; |
wolfSSL | 0:9d17e4342598 | 8875 | case 28: |
wolfSSL | 0:9d17e4342598 | 8876 | return secp224r1; |
wolfSSL | 0:9d17e4342598 | 8877 | case 32: |
wolfSSL | 0:9d17e4342598 | 8878 | return secp256r1; |
wolfSSL | 0:9d17e4342598 | 8879 | case 48: |
wolfSSL | 0:9d17e4342598 | 8880 | return secp384r1; |
wolfSSL | 0:9d17e4342598 | 8881 | case 66: |
wolfSSL | 0:9d17e4342598 | 8882 | return secp521r1; |
wolfSSL | 0:9d17e4342598 | 8883 | default: |
wolfSSL | 0:9d17e4342598 | 8884 | return 0; |
wolfSSL | 0:9d17e4342598 | 8885 | } |
wolfSSL | 0:9d17e4342598 | 8886 | } |
wolfSSL | 0:9d17e4342598 | 8887 | |
wolfSSL | 0:9d17e4342598 | 8888 | #endif /* HAVE_ECC */ |
wolfSSL | 0:9d17e4342598 | 8889 | |
wolfSSL | 0:9d17e4342598 | 8890 | |
wolfSSL | 0:9d17e4342598 | 8891 | int SendServerKeyExchange(CYASSL* ssl) |
wolfSSL | 0:9d17e4342598 | 8892 | { |
wolfSSL | 0:9d17e4342598 | 8893 | int ret = 0; |
wolfSSL | 0:9d17e4342598 | 8894 | (void)ssl; |
wolfSSL | 0:9d17e4342598 | 8895 | |
wolfSSL | 0:9d17e4342598 | 8896 | #ifndef NO_PSK |
wolfSSL | 0:9d17e4342598 | 8897 | if (ssl->specs.kea == psk_kea) |
wolfSSL | 0:9d17e4342598 | 8898 | { |
wolfSSL | 0:9d17e4342598 | 8899 | byte *output; |
wolfSSL | 0:9d17e4342598 | 8900 | word32 length, idx = RECORD_HEADER_SZ + HANDSHAKE_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 8901 | int sendSz; |
wolfSSL | 0:9d17e4342598 | 8902 | if (ssl->arrays->server_hint[0] == 0) return 0; /* don't send */ |
wolfSSL | 0:9d17e4342598 | 8903 | |
wolfSSL | 0:9d17e4342598 | 8904 | /* include size part */ |
wolfSSL | 0:9d17e4342598 | 8905 | length = (word32)XSTRLEN(ssl->arrays->server_hint); |
wolfSSL | 0:9d17e4342598 | 8906 | if (length > MAX_PSK_ID_LEN) return SERVER_HINT_ERROR; |
wolfSSL | 0:9d17e4342598 | 8907 | length += HINT_LEN_SZ; |
wolfSSL | 0:9d17e4342598 | 8908 | sendSz = length + HANDSHAKE_HEADER_SZ + RECORD_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 8909 | |
wolfSSL | 0:9d17e4342598 | 8910 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 8911 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 8912 | sendSz += DTLS_RECORD_EXTRA + DTLS_HANDSHAKE_EXTRA; |
wolfSSL | 0:9d17e4342598 | 8913 | idx += DTLS_RECORD_EXTRA + DTLS_HANDSHAKE_EXTRA; |
wolfSSL | 0:9d17e4342598 | 8914 | } |
wolfSSL | 0:9d17e4342598 | 8915 | #endif |
wolfSSL | 0:9d17e4342598 | 8916 | /* check for available size */ |
wolfSSL | 0:9d17e4342598 | 8917 | if ((ret = CheckAvailableSize(ssl, sendSz)) != 0) |
wolfSSL | 0:9d17e4342598 | 8918 | return ret; |
wolfSSL | 0:9d17e4342598 | 8919 | |
wolfSSL | 0:9d17e4342598 | 8920 | /* get ouput buffer */ |
wolfSSL | 0:9d17e4342598 | 8921 | output = ssl->buffers.outputBuffer.buffer + |
wolfSSL | 0:9d17e4342598 | 8922 | ssl->buffers.outputBuffer.length; |
wolfSSL | 0:9d17e4342598 | 8923 | |
wolfSSL | 0:9d17e4342598 | 8924 | AddHeaders(output, length, server_key_exchange, ssl); |
wolfSSL | 0:9d17e4342598 | 8925 | |
wolfSSL | 0:9d17e4342598 | 8926 | /* key data */ |
wolfSSL | 0:9d17e4342598 | 8927 | c16toa((word16)(length - HINT_LEN_SZ), output + idx); |
wolfSSL | 0:9d17e4342598 | 8928 | idx += HINT_LEN_SZ; |
wolfSSL | 0:9d17e4342598 | 8929 | XMEMCPY(output + idx, ssl->arrays->server_hint,length -HINT_LEN_SZ); |
wolfSSL | 0:9d17e4342598 | 8930 | |
wolfSSL | 0:9d17e4342598 | 8931 | HashOutput(ssl, output, sendSz, 0); |
wolfSSL | 0:9d17e4342598 | 8932 | |
wolfSSL | 0:9d17e4342598 | 8933 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 8934 | if (ssl->hsInfoOn) |
wolfSSL | 0:9d17e4342598 | 8935 | AddPacketName("ServerKeyExchange", &ssl->handShakeInfo); |
wolfSSL | 0:9d17e4342598 | 8936 | if (ssl->toInfoOn) |
wolfSSL | 0:9d17e4342598 | 8937 | AddPacketInfo("ServerKeyExchange", &ssl->timeoutInfo, |
wolfSSL | 0:9d17e4342598 | 8938 | output, sendSz, ssl->heap); |
wolfSSL | 0:9d17e4342598 | 8939 | #endif |
wolfSSL | 0:9d17e4342598 | 8940 | |
wolfSSL | 0:9d17e4342598 | 8941 | ssl->buffers.outputBuffer.length += sendSz; |
wolfSSL | 0:9d17e4342598 | 8942 | if (ssl->options.groupMessages) |
wolfSSL | 0:9d17e4342598 | 8943 | ret = 0; |
wolfSSL | 0:9d17e4342598 | 8944 | else |
wolfSSL | 0:9d17e4342598 | 8945 | ret = SendBuffered(ssl); |
wolfSSL | 0:9d17e4342598 | 8946 | ssl->options.serverState = SERVER_KEYEXCHANGE_COMPLETE; |
wolfSSL | 0:9d17e4342598 | 8947 | } |
wolfSSL | 0:9d17e4342598 | 8948 | #endif /*NO_PSK */ |
wolfSSL | 0:9d17e4342598 | 8949 | |
wolfSSL | 0:9d17e4342598 | 8950 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 8951 | if (ssl->specs.kea == ecc_diffie_hellman_kea) |
wolfSSL | 0:9d17e4342598 | 8952 | { |
wolfSSL | 0:9d17e4342598 | 8953 | byte *output; |
wolfSSL | 0:9d17e4342598 | 8954 | word32 length, idx = RECORD_HEADER_SZ + HANDSHAKE_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 8955 | int sendSz; |
wolfSSL | 0:9d17e4342598 | 8956 | byte exportBuf[MAX_EXPORT_ECC_SZ]; |
wolfSSL | 0:9d17e4342598 | 8957 | word32 expSz = sizeof(exportBuf); |
wolfSSL | 0:9d17e4342598 | 8958 | word32 sigSz; |
wolfSSL | 0:9d17e4342598 | 8959 | word32 preSigSz, preSigIdx; |
wolfSSL | 0:9d17e4342598 | 8960 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 8961 | RsaKey rsaKey; |
wolfSSL | 0:9d17e4342598 | 8962 | #endif |
wolfSSL | 0:9d17e4342598 | 8963 | ecc_key dsaKey; |
wolfSSL | 0:9d17e4342598 | 8964 | |
wolfSSL | 0:9d17e4342598 | 8965 | if (ssl->specs.static_ecdh) { |
wolfSSL | 0:9d17e4342598 | 8966 | CYASSL_MSG("Using Static ECDH, not sending ServerKeyExchagne"); |
wolfSSL | 0:9d17e4342598 | 8967 | return 0; |
wolfSSL | 0:9d17e4342598 | 8968 | } |
wolfSSL | 0:9d17e4342598 | 8969 | |
wolfSSL | 0:9d17e4342598 | 8970 | /* curve type, named curve, length(1) */ |
wolfSSL | 0:9d17e4342598 | 8971 | length = ENUM_LEN + CURVE_LEN + ENUM_LEN; |
wolfSSL | 0:9d17e4342598 | 8972 | /* pub key size */ |
wolfSSL | 0:9d17e4342598 | 8973 | CYASSL_MSG("Using ephemeral ECDH"); |
wolfSSL | 0:9d17e4342598 | 8974 | if (ecc_export_x963(ssl->eccTempKey, exportBuf, &expSz) != 0) |
wolfSSL | 0:9d17e4342598 | 8975 | return ECC_EXPORT_ERROR; |
wolfSSL | 0:9d17e4342598 | 8976 | length += expSz; |
wolfSSL | 0:9d17e4342598 | 8977 | |
wolfSSL | 0:9d17e4342598 | 8978 | preSigSz = length; |
wolfSSL | 0:9d17e4342598 | 8979 | preSigIdx = idx; |
wolfSSL | 0:9d17e4342598 | 8980 | |
wolfSSL | 0:9d17e4342598 | 8981 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 8982 | ret = InitRsaKey(&rsaKey, ssl->heap); |
wolfSSL | 0:9d17e4342598 | 8983 | if (ret != 0) return ret; |
wolfSSL | 0:9d17e4342598 | 8984 | #endif |
wolfSSL | 0:9d17e4342598 | 8985 | ecc_init(&dsaKey); |
wolfSSL | 0:9d17e4342598 | 8986 | |
wolfSSL | 0:9d17e4342598 | 8987 | /* sig length */ |
wolfSSL | 0:9d17e4342598 | 8988 | length += LENGTH_SZ; |
wolfSSL | 0:9d17e4342598 | 8989 | |
wolfSSL | 0:9d17e4342598 | 8990 | if (!ssl->buffers.key.buffer) { |
wolfSSL | 0:9d17e4342598 | 8991 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 8992 | FreeRsaKey(&rsaKey); |
wolfSSL | 0:9d17e4342598 | 8993 | #endif |
wolfSSL | 0:9d17e4342598 | 8994 | ecc_free(&dsaKey); |
wolfSSL | 0:9d17e4342598 | 8995 | return NO_PRIVATE_KEY; |
wolfSSL | 0:9d17e4342598 | 8996 | } |
wolfSSL | 0:9d17e4342598 | 8997 | |
wolfSSL | 0:9d17e4342598 | 8998 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 8999 | if (ssl->specs.sig_algo == rsa_sa_algo) { |
wolfSSL | 0:9d17e4342598 | 9000 | /* rsa sig size */ |
wolfSSL | 0:9d17e4342598 | 9001 | word32 i = 0; |
wolfSSL | 0:9d17e4342598 | 9002 | ret = RsaPrivateKeyDecode(ssl->buffers.key.buffer, &i, |
wolfSSL | 0:9d17e4342598 | 9003 | &rsaKey, ssl->buffers.key.length); |
wolfSSL | 0:9d17e4342598 | 9004 | if (ret != 0) return ret; |
wolfSSL | 0:9d17e4342598 | 9005 | sigSz = RsaEncryptSize(&rsaKey); |
wolfSSL | 0:9d17e4342598 | 9006 | } else |
wolfSSL | 0:9d17e4342598 | 9007 | #endif |
wolfSSL | 0:9d17e4342598 | 9008 | if (ssl->specs.sig_algo == ecc_dsa_sa_algo) { |
wolfSSL | 0:9d17e4342598 | 9009 | /* ecdsa sig size */ |
wolfSSL | 0:9d17e4342598 | 9010 | word32 i = 0; |
wolfSSL | 0:9d17e4342598 | 9011 | ret = EccPrivateKeyDecode(ssl->buffers.key.buffer, &i, |
wolfSSL | 0:9d17e4342598 | 9012 | &dsaKey, ssl->buffers.key.length); |
wolfSSL | 0:9d17e4342598 | 9013 | if (ret != 0) return ret; |
wolfSSL | 0:9d17e4342598 | 9014 | sigSz = ecc_sig_size(&dsaKey); /* worst case estimate */ |
wolfSSL | 0:9d17e4342598 | 9015 | } |
wolfSSL | 0:9d17e4342598 | 9016 | else { |
wolfSSL | 0:9d17e4342598 | 9017 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 9018 | FreeRsaKey(&rsaKey); |
wolfSSL | 0:9d17e4342598 | 9019 | #endif |
wolfSSL | 0:9d17e4342598 | 9020 | ecc_free(&dsaKey); |
wolfSSL | 0:9d17e4342598 | 9021 | return ALGO_ID_E; /* unsupported type */ |
wolfSSL | 0:9d17e4342598 | 9022 | } |
wolfSSL | 0:9d17e4342598 | 9023 | length += sigSz; |
wolfSSL | 0:9d17e4342598 | 9024 | |
wolfSSL | 0:9d17e4342598 | 9025 | if (IsAtLeastTLSv1_2(ssl)) |
wolfSSL | 0:9d17e4342598 | 9026 | length += HASH_SIG_SIZE; |
wolfSSL | 0:9d17e4342598 | 9027 | |
wolfSSL | 0:9d17e4342598 | 9028 | sendSz = length + HANDSHAKE_HEADER_SZ + RECORD_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 9029 | |
wolfSSL | 0:9d17e4342598 | 9030 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 9031 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 9032 | sendSz += DTLS_RECORD_EXTRA + DTLS_HANDSHAKE_EXTRA; |
wolfSSL | 0:9d17e4342598 | 9033 | idx += DTLS_RECORD_EXTRA + DTLS_HANDSHAKE_EXTRA; |
wolfSSL | 0:9d17e4342598 | 9034 | preSigIdx = idx; |
wolfSSL | 0:9d17e4342598 | 9035 | } |
wolfSSL | 0:9d17e4342598 | 9036 | #endif |
wolfSSL | 0:9d17e4342598 | 9037 | /* check for available size */ |
wolfSSL | 0:9d17e4342598 | 9038 | if ((ret = CheckAvailableSize(ssl, sendSz)) != 0) { |
wolfSSL | 0:9d17e4342598 | 9039 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 9040 | FreeRsaKey(&rsaKey); |
wolfSSL | 0:9d17e4342598 | 9041 | #endif |
wolfSSL | 0:9d17e4342598 | 9042 | ecc_free(&dsaKey); |
wolfSSL | 0:9d17e4342598 | 9043 | return ret; |
wolfSSL | 0:9d17e4342598 | 9044 | } |
wolfSSL | 0:9d17e4342598 | 9045 | |
wolfSSL | 0:9d17e4342598 | 9046 | /* get ouput buffer */ |
wolfSSL | 0:9d17e4342598 | 9047 | output = ssl->buffers.outputBuffer.buffer + |
wolfSSL | 0:9d17e4342598 | 9048 | ssl->buffers.outputBuffer.length; |
wolfSSL | 0:9d17e4342598 | 9049 | |
wolfSSL | 0:9d17e4342598 | 9050 | /* record and message headers will be added below, when we're sure |
wolfSSL | 0:9d17e4342598 | 9051 | of the sig length */ |
wolfSSL | 0:9d17e4342598 | 9052 | |
wolfSSL | 0:9d17e4342598 | 9053 | /* key exchange data */ |
wolfSSL | 0:9d17e4342598 | 9054 | output[idx++] = named_curve; |
wolfSSL | 0:9d17e4342598 | 9055 | output[idx++] = 0x00; /* leading zero */ |
wolfSSL | 0:9d17e4342598 | 9056 | output[idx++] = SetCurveId(ecc_size(ssl->eccTempKey)); |
wolfSSL | 0:9d17e4342598 | 9057 | output[idx++] = (byte)expSz; |
wolfSSL | 0:9d17e4342598 | 9058 | XMEMCPY(output + idx, exportBuf, expSz); |
wolfSSL | 0:9d17e4342598 | 9059 | idx += expSz; |
wolfSSL | 0:9d17e4342598 | 9060 | if (IsAtLeastTLSv1_2(ssl)) { |
wolfSSL | 0:9d17e4342598 | 9061 | output[idx++] = ssl->suites->hashAlgo; |
wolfSSL | 0:9d17e4342598 | 9062 | output[idx++] = ssl->suites->sigAlgo; |
wolfSSL | 0:9d17e4342598 | 9063 | } |
wolfSSL | 0:9d17e4342598 | 9064 | |
wolfSSL | 0:9d17e4342598 | 9065 | /* Signtaure length will be written later, when we're sure what it |
wolfSSL | 0:9d17e4342598 | 9066 | is */ |
wolfSSL | 0:9d17e4342598 | 9067 | |
wolfSSL | 0:9d17e4342598 | 9068 | /* do signature */ |
wolfSSL | 0:9d17e4342598 | 9069 | { |
wolfSSL | 0:9d17e4342598 | 9070 | #ifndef NO_OLD_TLS |
wolfSSL | 0:9d17e4342598 | 9071 | Md5 md5; |
wolfSSL | 0:9d17e4342598 | 9072 | Sha sha; |
wolfSSL | 0:9d17e4342598 | 9073 | #endif |
wolfSSL | 0:9d17e4342598 | 9074 | byte hash[FINISHED_SZ]; |
wolfSSL | 0:9d17e4342598 | 9075 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 9076 | Sha256 sha256; |
wolfSSL | 0:9d17e4342598 | 9077 | byte hash256[SHA256_DIGEST_SIZE]; |
wolfSSL | 0:9d17e4342598 | 9078 | #endif |
wolfSSL | 0:9d17e4342598 | 9079 | #ifdef CYASSL_SHA384 |
wolfSSL | 0:9d17e4342598 | 9080 | Sha384 sha384; |
wolfSSL | 0:9d17e4342598 | 9081 | byte hash384[SHA384_DIGEST_SIZE]; |
wolfSSL | 0:9d17e4342598 | 9082 | #endif |
wolfSSL | 0:9d17e4342598 | 9083 | |
wolfSSL | 0:9d17e4342598 | 9084 | #ifndef NO_OLD_TLS |
wolfSSL | 0:9d17e4342598 | 9085 | /* md5 */ |
wolfSSL | 0:9d17e4342598 | 9086 | InitMd5(&md5); |
wolfSSL | 0:9d17e4342598 | 9087 | Md5Update(&md5, ssl->arrays->clientRandom, RAN_LEN); |
wolfSSL | 0:9d17e4342598 | 9088 | Md5Update(&md5, ssl->arrays->serverRandom, RAN_LEN); |
wolfSSL | 0:9d17e4342598 | 9089 | Md5Update(&md5, output + preSigIdx, preSigSz); |
wolfSSL | 0:9d17e4342598 | 9090 | Md5Final(&md5, hash); |
wolfSSL | 0:9d17e4342598 | 9091 | |
wolfSSL | 0:9d17e4342598 | 9092 | /* sha */ |
wolfSSL | 0:9d17e4342598 | 9093 | ret = InitSha(&sha); |
wolfSSL | 0:9d17e4342598 | 9094 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 9095 | return ret; |
wolfSSL | 0:9d17e4342598 | 9096 | ShaUpdate(&sha, ssl->arrays->clientRandom, RAN_LEN); |
wolfSSL | 0:9d17e4342598 | 9097 | ShaUpdate(&sha, ssl->arrays->serverRandom, RAN_LEN); |
wolfSSL | 0:9d17e4342598 | 9098 | ShaUpdate(&sha, output + preSigIdx, preSigSz); |
wolfSSL | 0:9d17e4342598 | 9099 | ShaFinal(&sha, &hash[MD5_DIGEST_SIZE]); |
wolfSSL | 0:9d17e4342598 | 9100 | #endif |
wolfSSL | 0:9d17e4342598 | 9101 | |
wolfSSL | 0:9d17e4342598 | 9102 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 9103 | ret = InitSha256(&sha256); |
wolfSSL | 0:9d17e4342598 | 9104 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 9105 | return ret; |
wolfSSL | 0:9d17e4342598 | 9106 | Sha256Update(&sha256, ssl->arrays->clientRandom, RAN_LEN); |
wolfSSL | 0:9d17e4342598 | 9107 | Sha256Update(&sha256, ssl->arrays->serverRandom, RAN_LEN); |
wolfSSL | 0:9d17e4342598 | 9108 | Sha256Update(&sha256, output + preSigIdx, preSigSz); |
wolfSSL | 0:9d17e4342598 | 9109 | Sha256Final(&sha256, hash256); |
wolfSSL | 0:9d17e4342598 | 9110 | #endif |
wolfSSL | 0:9d17e4342598 | 9111 | |
wolfSSL | 0:9d17e4342598 | 9112 | #ifdef CYASSL_SHA384 |
wolfSSL | 0:9d17e4342598 | 9113 | ret = InitSha384(&sha384); |
wolfSSL | 0:9d17e4342598 | 9114 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 9115 | return ret; |
wolfSSL | 0:9d17e4342598 | 9116 | Sha384Update(&sha384, ssl->arrays->clientRandom, RAN_LEN); |
wolfSSL | 0:9d17e4342598 | 9117 | Sha384Update(&sha384, ssl->arrays->serverRandom, RAN_LEN); |
wolfSSL | 0:9d17e4342598 | 9118 | Sha384Update(&sha384, output + preSigIdx, preSigSz); |
wolfSSL | 0:9d17e4342598 | 9119 | Sha384Final(&sha384, hash384); |
wolfSSL | 0:9d17e4342598 | 9120 | #endif |
wolfSSL | 0:9d17e4342598 | 9121 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 9122 | if (ssl->suites->sigAlgo == rsa_sa_algo) { |
wolfSSL | 0:9d17e4342598 | 9123 | byte* signBuffer = hash; |
wolfSSL | 0:9d17e4342598 | 9124 | word32 signSz = sizeof(hash); |
wolfSSL | 0:9d17e4342598 | 9125 | byte encodedSig[MAX_ENCODED_SIG_SZ]; |
wolfSSL | 0:9d17e4342598 | 9126 | byte doUserRsa = 0; |
wolfSSL | 0:9d17e4342598 | 9127 | |
wolfSSL | 0:9d17e4342598 | 9128 | #ifdef HAVE_PK_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 9129 | if (ssl->ctx->RsaSignCb) |
wolfSSL | 0:9d17e4342598 | 9130 | doUserRsa = 1; |
wolfSSL | 0:9d17e4342598 | 9131 | #endif /*HAVE_PK_CALLBACKS */ |
wolfSSL | 0:9d17e4342598 | 9132 | |
wolfSSL | 0:9d17e4342598 | 9133 | if (IsAtLeastTLSv1_2(ssl)) { |
wolfSSL | 0:9d17e4342598 | 9134 | byte* digest = &hash[MD5_DIGEST_SIZE]; |
wolfSSL | 0:9d17e4342598 | 9135 | int typeH = SHAh; |
wolfSSL | 0:9d17e4342598 | 9136 | int digestSz = SHA_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 9137 | |
wolfSSL | 0:9d17e4342598 | 9138 | if (ssl->suites->hashAlgo == sha256_mac) { |
wolfSSL | 0:9d17e4342598 | 9139 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 9140 | digest = hash256; |
wolfSSL | 0:9d17e4342598 | 9141 | typeH = SHA256h; |
wolfSSL | 0:9d17e4342598 | 9142 | digestSz = SHA256_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 9143 | #endif |
wolfSSL | 0:9d17e4342598 | 9144 | } |
wolfSSL | 0:9d17e4342598 | 9145 | else if (ssl->suites->hashAlgo == sha384_mac) { |
wolfSSL | 0:9d17e4342598 | 9146 | #ifdef CYASSL_SHA384 |
wolfSSL | 0:9d17e4342598 | 9147 | digest = hash384; |
wolfSSL | 0:9d17e4342598 | 9148 | typeH = SHA384h; |
wolfSSL | 0:9d17e4342598 | 9149 | digestSz = SHA384_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 9150 | #endif |
wolfSSL | 0:9d17e4342598 | 9151 | } |
wolfSSL | 0:9d17e4342598 | 9152 | |
wolfSSL | 0:9d17e4342598 | 9153 | signSz = EncodeSignature(encodedSig, digest, digestSz, |
wolfSSL | 0:9d17e4342598 | 9154 | typeH); |
wolfSSL | 0:9d17e4342598 | 9155 | signBuffer = encodedSig; |
wolfSSL | 0:9d17e4342598 | 9156 | } |
wolfSSL | 0:9d17e4342598 | 9157 | /* write sig size here */ |
wolfSSL | 0:9d17e4342598 | 9158 | c16toa((word16)sigSz, output + idx); |
wolfSSL | 0:9d17e4342598 | 9159 | idx += LENGTH_SZ; |
wolfSSL | 0:9d17e4342598 | 9160 | |
wolfSSL | 0:9d17e4342598 | 9161 | if (doUserRsa) { |
wolfSSL | 0:9d17e4342598 | 9162 | #ifdef HAVE_PK_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 9163 | word32 ioLen = sigSz; |
wolfSSL | 0:9d17e4342598 | 9164 | ret = ssl->ctx->RsaSignCb(ssl, signBuffer, signSz, |
wolfSSL | 0:9d17e4342598 | 9165 | output + idx, |
wolfSSL | 0:9d17e4342598 | 9166 | &ioLen, |
wolfSSL | 0:9d17e4342598 | 9167 | ssl->buffers.key.buffer, |
wolfSSL | 0:9d17e4342598 | 9168 | ssl->buffers.key.length, |
wolfSSL | 0:9d17e4342598 | 9169 | ssl->RsaSignCtx); |
wolfSSL | 0:9d17e4342598 | 9170 | #endif /*HAVE_PK_CALLBACKS */ |
wolfSSL | 0:9d17e4342598 | 9171 | } |
wolfSSL | 0:9d17e4342598 | 9172 | else { |
wolfSSL | 0:9d17e4342598 | 9173 | ret = RsaSSL_Sign(signBuffer, signSz, output + idx, |
wolfSSL | 0:9d17e4342598 | 9174 | sigSz, &rsaKey, ssl->rng); |
wolfSSL | 0:9d17e4342598 | 9175 | if (ret > 0) |
wolfSSL | 0:9d17e4342598 | 9176 | ret = 0; /* reset on success */ |
wolfSSL | 0:9d17e4342598 | 9177 | } |
wolfSSL | 0:9d17e4342598 | 9178 | FreeRsaKey(&rsaKey); |
wolfSSL | 0:9d17e4342598 | 9179 | ecc_free(&dsaKey); |
wolfSSL | 0:9d17e4342598 | 9180 | if (ret < 0) |
wolfSSL | 0:9d17e4342598 | 9181 | return ret; |
wolfSSL | 0:9d17e4342598 | 9182 | } else |
wolfSSL | 0:9d17e4342598 | 9183 | #endif |
wolfSSL | 0:9d17e4342598 | 9184 | if (ssl->suites->sigAlgo == ecc_dsa_sa_algo) { |
wolfSSL | 0:9d17e4342598 | 9185 | #ifndef NO_OLD_TLS |
wolfSSL | 0:9d17e4342598 | 9186 | byte* digest = &hash[MD5_DIGEST_SIZE]; |
wolfSSL | 0:9d17e4342598 | 9187 | word32 digestSz = SHA_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 9188 | #else |
wolfSSL | 0:9d17e4342598 | 9189 | byte* digest = hash256; |
wolfSSL | 0:9d17e4342598 | 9190 | word32 digestSz = SHA256_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 9191 | #endif |
wolfSSL | 0:9d17e4342598 | 9192 | word32 sz = sigSz; |
wolfSSL | 0:9d17e4342598 | 9193 | byte doUserEcc = 0; |
wolfSSL | 0:9d17e4342598 | 9194 | |
wolfSSL | 0:9d17e4342598 | 9195 | #ifdef HAVE_PK_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 9196 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 9197 | if (ssl->ctx->EccSignCb) |
wolfSSL | 0:9d17e4342598 | 9198 | doUserEcc = 1; |
wolfSSL | 0:9d17e4342598 | 9199 | #endif /* HAVE_ECC */ |
wolfSSL | 0:9d17e4342598 | 9200 | #endif /*HAVE_PK_CALLBACKS */ |
wolfSSL | 0:9d17e4342598 | 9201 | |
wolfSSL | 0:9d17e4342598 | 9202 | if (IsAtLeastTLSv1_2(ssl)) { |
wolfSSL | 0:9d17e4342598 | 9203 | if (ssl->suites->hashAlgo == sha_mac) { |
wolfSSL | 0:9d17e4342598 | 9204 | #ifndef NO_SHA |
wolfSSL | 0:9d17e4342598 | 9205 | digest = &hash[MD5_DIGEST_SIZE]; |
wolfSSL | 0:9d17e4342598 | 9206 | digestSz = SHA_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 9207 | #endif |
wolfSSL | 0:9d17e4342598 | 9208 | } |
wolfSSL | 0:9d17e4342598 | 9209 | else if (ssl->suites->hashAlgo == sha256_mac) { |
wolfSSL | 0:9d17e4342598 | 9210 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 9211 | digest = hash256; |
wolfSSL | 0:9d17e4342598 | 9212 | digestSz = SHA256_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 9213 | #endif |
wolfSSL | 0:9d17e4342598 | 9214 | } |
wolfSSL | 0:9d17e4342598 | 9215 | else if (ssl->suites->hashAlgo == sha384_mac) { |
wolfSSL | 0:9d17e4342598 | 9216 | #ifdef CYASSL_SHA384 |
wolfSSL | 0:9d17e4342598 | 9217 | digest = hash384; |
wolfSSL | 0:9d17e4342598 | 9218 | digestSz = SHA384_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 9219 | #endif |
wolfSSL | 0:9d17e4342598 | 9220 | } |
wolfSSL | 0:9d17e4342598 | 9221 | } |
wolfSSL | 0:9d17e4342598 | 9222 | |
wolfSSL | 0:9d17e4342598 | 9223 | if (doUserEcc) { |
wolfSSL | 0:9d17e4342598 | 9224 | #ifdef HAVE_PK_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 9225 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 9226 | ret = ssl->ctx->EccSignCb(ssl, digest, digestSz, |
wolfSSL | 0:9d17e4342598 | 9227 | output + LENGTH_SZ + idx, &sz, |
wolfSSL | 0:9d17e4342598 | 9228 | ssl->buffers.key.buffer, |
wolfSSL | 0:9d17e4342598 | 9229 | ssl->buffers.key.length, |
wolfSSL | 0:9d17e4342598 | 9230 | ssl->EccSignCtx); |
wolfSSL | 0:9d17e4342598 | 9231 | #endif /* HAVE_ECC */ |
wolfSSL | 0:9d17e4342598 | 9232 | #endif /*HAVE_PK_CALLBACKS */ |
wolfSSL | 0:9d17e4342598 | 9233 | } |
wolfSSL | 0:9d17e4342598 | 9234 | else { |
wolfSSL | 0:9d17e4342598 | 9235 | ret = ecc_sign_hash(digest, digestSz, |
wolfSSL | 0:9d17e4342598 | 9236 | output + LENGTH_SZ + idx, &sz, ssl->rng, &dsaKey); |
wolfSSL | 0:9d17e4342598 | 9237 | } |
wolfSSL | 0:9d17e4342598 | 9238 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 9239 | FreeRsaKey(&rsaKey); |
wolfSSL | 0:9d17e4342598 | 9240 | #endif |
wolfSSL | 0:9d17e4342598 | 9241 | ecc_free(&dsaKey); |
wolfSSL | 0:9d17e4342598 | 9242 | if (ret < 0) return ret; |
wolfSSL | 0:9d17e4342598 | 9243 | |
wolfSSL | 0:9d17e4342598 | 9244 | /* Now that we know the real sig size, write it. */ |
wolfSSL | 0:9d17e4342598 | 9245 | c16toa((word16)sz, output + idx); |
wolfSSL | 0:9d17e4342598 | 9246 | |
wolfSSL | 0:9d17e4342598 | 9247 | /* And adjust length and sendSz from estimates */ |
wolfSSL | 0:9d17e4342598 | 9248 | length += sz - sigSz; |
wolfSSL | 0:9d17e4342598 | 9249 | sendSz += sz - sigSz; |
wolfSSL | 0:9d17e4342598 | 9250 | } |
wolfSSL | 0:9d17e4342598 | 9251 | } |
wolfSSL | 0:9d17e4342598 | 9252 | |
wolfSSL | 0:9d17e4342598 | 9253 | AddHeaders(output, length, server_key_exchange, ssl); |
wolfSSL | 0:9d17e4342598 | 9254 | HashOutput(ssl, output, sendSz, 0); |
wolfSSL | 0:9d17e4342598 | 9255 | |
wolfSSL | 0:9d17e4342598 | 9256 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 9257 | if (ssl->hsInfoOn) |
wolfSSL | 0:9d17e4342598 | 9258 | AddPacketName("ServerKeyExchange", &ssl->handShakeInfo); |
wolfSSL | 0:9d17e4342598 | 9259 | if (ssl->toInfoOn) |
wolfSSL | 0:9d17e4342598 | 9260 | AddPacketInfo("ServerKeyExchange", &ssl->timeoutInfo, |
wolfSSL | 0:9d17e4342598 | 9261 | output, sendSz, ssl->heap); |
wolfSSL | 0:9d17e4342598 | 9262 | #endif |
wolfSSL | 0:9d17e4342598 | 9263 | |
wolfSSL | 0:9d17e4342598 | 9264 | ssl->buffers.outputBuffer.length += sendSz; |
wolfSSL | 0:9d17e4342598 | 9265 | if (ssl->options.groupMessages) |
wolfSSL | 0:9d17e4342598 | 9266 | ret = 0; |
wolfSSL | 0:9d17e4342598 | 9267 | else |
wolfSSL | 0:9d17e4342598 | 9268 | ret = SendBuffered(ssl); |
wolfSSL | 0:9d17e4342598 | 9269 | ssl->options.serverState = SERVER_KEYEXCHANGE_COMPLETE; |
wolfSSL | 0:9d17e4342598 | 9270 | } |
wolfSSL | 0:9d17e4342598 | 9271 | #endif /* HAVE_ECC */ |
wolfSSL | 0:9d17e4342598 | 9272 | |
wolfSSL | 0:9d17e4342598 | 9273 | #ifdef OPENSSL_EXTRA |
wolfSSL | 0:9d17e4342598 | 9274 | if (ssl->specs.kea == diffie_hellman_kea) { |
wolfSSL | 0:9d17e4342598 | 9275 | byte *output; |
wolfSSL | 0:9d17e4342598 | 9276 | word32 length = 0, idx = RECORD_HEADER_SZ + HANDSHAKE_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 9277 | int sendSz; |
wolfSSL | 0:9d17e4342598 | 9278 | word32 sigSz = 0, i = 0; |
wolfSSL | 0:9d17e4342598 | 9279 | word32 preSigSz = 0, preSigIdx = 0; |
wolfSSL | 0:9d17e4342598 | 9280 | RsaKey rsaKey; |
wolfSSL | 0:9d17e4342598 | 9281 | DhKey dhKey; |
wolfSSL | 0:9d17e4342598 | 9282 | |
wolfSSL | 0:9d17e4342598 | 9283 | if (ssl->buffers.serverDH_P.buffer == NULL || |
wolfSSL | 0:9d17e4342598 | 9284 | ssl->buffers.serverDH_G.buffer == NULL) |
wolfSSL | 0:9d17e4342598 | 9285 | return NO_DH_PARAMS; |
wolfSSL | 0:9d17e4342598 | 9286 | |
wolfSSL | 0:9d17e4342598 | 9287 | if (ssl->buffers.serverDH_Pub.buffer == NULL) { |
wolfSSL | 0:9d17e4342598 | 9288 | ssl->buffers.serverDH_Pub.buffer = (byte*)XMALLOC( |
wolfSSL | 0:9d17e4342598 | 9289 | ssl->buffers.serverDH_P.length + 2, ssl->ctx->heap, |
wolfSSL | 0:9d17e4342598 | 9290 | DYNAMIC_TYPE_DH); |
wolfSSL | 0:9d17e4342598 | 9291 | if (ssl->buffers.serverDH_Pub.buffer == NULL) |
wolfSSL | 0:9d17e4342598 | 9292 | return MEMORY_E; |
wolfSSL | 0:9d17e4342598 | 9293 | } |
wolfSSL | 0:9d17e4342598 | 9294 | |
wolfSSL | 0:9d17e4342598 | 9295 | if (ssl->buffers.serverDH_Priv.buffer == NULL) { |
wolfSSL | 0:9d17e4342598 | 9296 | ssl->buffers.serverDH_Priv.buffer = (byte*)XMALLOC( |
wolfSSL | 0:9d17e4342598 | 9297 | ssl->buffers.serverDH_P.length + 2, ssl->ctx->heap, |
wolfSSL | 0:9d17e4342598 | 9298 | DYNAMIC_TYPE_DH); |
wolfSSL | 0:9d17e4342598 | 9299 | if (ssl->buffers.serverDH_Priv.buffer == NULL) |
wolfSSL | 0:9d17e4342598 | 9300 | return MEMORY_E; |
wolfSSL | 0:9d17e4342598 | 9301 | } |
wolfSSL | 0:9d17e4342598 | 9302 | |
wolfSSL | 0:9d17e4342598 | 9303 | InitDhKey(&dhKey); |
wolfSSL | 0:9d17e4342598 | 9304 | ret = DhSetKey(&dhKey, ssl->buffers.serverDH_P.buffer, |
wolfSSL | 0:9d17e4342598 | 9305 | ssl->buffers.serverDH_P.length, |
wolfSSL | 0:9d17e4342598 | 9306 | ssl->buffers.serverDH_G.buffer, |
wolfSSL | 0:9d17e4342598 | 9307 | ssl->buffers.serverDH_G.length); |
wolfSSL | 0:9d17e4342598 | 9308 | if (ret == 0) |
wolfSSL | 0:9d17e4342598 | 9309 | ret = DhGenerateKeyPair(&dhKey, ssl->rng, |
wolfSSL | 0:9d17e4342598 | 9310 | ssl->buffers.serverDH_Priv.buffer, |
wolfSSL | 0:9d17e4342598 | 9311 | &ssl->buffers.serverDH_Priv.length, |
wolfSSL | 0:9d17e4342598 | 9312 | ssl->buffers.serverDH_Pub.buffer, |
wolfSSL | 0:9d17e4342598 | 9313 | &ssl->buffers.serverDH_Pub.length); |
wolfSSL | 0:9d17e4342598 | 9314 | FreeDhKey(&dhKey); |
wolfSSL | 0:9d17e4342598 | 9315 | |
wolfSSL | 0:9d17e4342598 | 9316 | if (ret == 0) { |
wolfSSL | 0:9d17e4342598 | 9317 | ret = InitRsaKey(&rsaKey, ssl->heap); |
wolfSSL | 0:9d17e4342598 | 9318 | if (ret != 0) return ret; |
wolfSSL | 0:9d17e4342598 | 9319 | } |
wolfSSL | 0:9d17e4342598 | 9320 | if (ret == 0) { |
wolfSSL | 0:9d17e4342598 | 9321 | length = LENGTH_SZ * 3; /* p, g, pub */ |
wolfSSL | 0:9d17e4342598 | 9322 | length += ssl->buffers.serverDH_P.length + |
wolfSSL | 0:9d17e4342598 | 9323 | ssl->buffers.serverDH_G.length + |
wolfSSL | 0:9d17e4342598 | 9324 | ssl->buffers.serverDH_Pub.length; |
wolfSSL | 0:9d17e4342598 | 9325 | |
wolfSSL | 0:9d17e4342598 | 9326 | preSigIdx = idx; |
wolfSSL | 0:9d17e4342598 | 9327 | preSigSz = length; |
wolfSSL | 0:9d17e4342598 | 9328 | |
wolfSSL | 0:9d17e4342598 | 9329 | /* sig length */ |
wolfSSL | 0:9d17e4342598 | 9330 | length += LENGTH_SZ; |
wolfSSL | 0:9d17e4342598 | 9331 | |
wolfSSL | 0:9d17e4342598 | 9332 | if (!ssl->buffers.key.buffer) |
wolfSSL | 0:9d17e4342598 | 9333 | return NO_PRIVATE_KEY; |
wolfSSL | 0:9d17e4342598 | 9334 | |
wolfSSL | 0:9d17e4342598 | 9335 | ret = RsaPrivateKeyDecode(ssl->buffers.key.buffer, &i, &rsaKey, |
wolfSSL | 0:9d17e4342598 | 9336 | ssl->buffers.key.length); |
wolfSSL | 0:9d17e4342598 | 9337 | if (ret == 0) { |
wolfSSL | 0:9d17e4342598 | 9338 | sigSz = RsaEncryptSize(&rsaKey); |
wolfSSL | 0:9d17e4342598 | 9339 | length += sigSz; |
wolfSSL | 0:9d17e4342598 | 9340 | } |
wolfSSL | 0:9d17e4342598 | 9341 | } |
wolfSSL | 0:9d17e4342598 | 9342 | if (ret != 0) { |
wolfSSL | 0:9d17e4342598 | 9343 | FreeRsaKey(&rsaKey); |
wolfSSL | 0:9d17e4342598 | 9344 | return ret; |
wolfSSL | 0:9d17e4342598 | 9345 | } |
wolfSSL | 0:9d17e4342598 | 9346 | |
wolfSSL | 0:9d17e4342598 | 9347 | if (IsAtLeastTLSv1_2(ssl)) |
wolfSSL | 0:9d17e4342598 | 9348 | length += HASH_SIG_SIZE; |
wolfSSL | 0:9d17e4342598 | 9349 | |
wolfSSL | 0:9d17e4342598 | 9350 | sendSz = length + HANDSHAKE_HEADER_SZ + RECORD_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 9351 | |
wolfSSL | 0:9d17e4342598 | 9352 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 9353 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 9354 | sendSz += DTLS_RECORD_EXTRA + DTLS_HANDSHAKE_EXTRA; |
wolfSSL | 0:9d17e4342598 | 9355 | idx += DTLS_RECORD_EXTRA + DTLS_HANDSHAKE_EXTRA; |
wolfSSL | 0:9d17e4342598 | 9356 | preSigIdx = idx; |
wolfSSL | 0:9d17e4342598 | 9357 | } |
wolfSSL | 0:9d17e4342598 | 9358 | #endif |
wolfSSL | 0:9d17e4342598 | 9359 | /* check for available size */ |
wolfSSL | 0:9d17e4342598 | 9360 | if ((ret = CheckAvailableSize(ssl, sendSz)) != 0) { |
wolfSSL | 0:9d17e4342598 | 9361 | FreeRsaKey(&rsaKey); |
wolfSSL | 0:9d17e4342598 | 9362 | return ret; |
wolfSSL | 0:9d17e4342598 | 9363 | } |
wolfSSL | 0:9d17e4342598 | 9364 | |
wolfSSL | 0:9d17e4342598 | 9365 | /* get ouput buffer */ |
wolfSSL | 0:9d17e4342598 | 9366 | output = ssl->buffers.outputBuffer.buffer + |
wolfSSL | 0:9d17e4342598 | 9367 | ssl->buffers.outputBuffer.length; |
wolfSSL | 0:9d17e4342598 | 9368 | |
wolfSSL | 0:9d17e4342598 | 9369 | AddHeaders(output, length, server_key_exchange, ssl); |
wolfSSL | 0:9d17e4342598 | 9370 | |
wolfSSL | 0:9d17e4342598 | 9371 | /* add p, g, pub */ |
wolfSSL | 0:9d17e4342598 | 9372 | c16toa((word16)ssl->buffers.serverDH_P.length, output + idx); |
wolfSSL | 0:9d17e4342598 | 9373 | idx += LENGTH_SZ; |
wolfSSL | 0:9d17e4342598 | 9374 | XMEMCPY(output + idx, ssl->buffers.serverDH_P.buffer, |
wolfSSL | 0:9d17e4342598 | 9375 | ssl->buffers.serverDH_P.length); |
wolfSSL | 0:9d17e4342598 | 9376 | idx += ssl->buffers.serverDH_P.length; |
wolfSSL | 0:9d17e4342598 | 9377 | |
wolfSSL | 0:9d17e4342598 | 9378 | /* g */ |
wolfSSL | 0:9d17e4342598 | 9379 | c16toa((word16)ssl->buffers.serverDH_G.length, output + idx); |
wolfSSL | 0:9d17e4342598 | 9380 | idx += LENGTH_SZ; |
wolfSSL | 0:9d17e4342598 | 9381 | XMEMCPY(output + idx, ssl->buffers.serverDH_G.buffer, |
wolfSSL | 0:9d17e4342598 | 9382 | ssl->buffers.serverDH_G.length); |
wolfSSL | 0:9d17e4342598 | 9383 | idx += ssl->buffers.serverDH_G.length; |
wolfSSL | 0:9d17e4342598 | 9384 | |
wolfSSL | 0:9d17e4342598 | 9385 | /* pub */ |
wolfSSL | 0:9d17e4342598 | 9386 | c16toa((word16)ssl->buffers.serverDH_Pub.length, output + idx); |
wolfSSL | 0:9d17e4342598 | 9387 | idx += LENGTH_SZ; |
wolfSSL | 0:9d17e4342598 | 9388 | XMEMCPY(output + idx, ssl->buffers.serverDH_Pub.buffer, |
wolfSSL | 0:9d17e4342598 | 9389 | ssl->buffers.serverDH_Pub.length); |
wolfSSL | 0:9d17e4342598 | 9390 | idx += ssl->buffers.serverDH_Pub.length; |
wolfSSL | 0:9d17e4342598 | 9391 | |
wolfSSL | 0:9d17e4342598 | 9392 | /* Add signature */ |
wolfSSL | 0:9d17e4342598 | 9393 | if (IsAtLeastTLSv1_2(ssl)) { |
wolfSSL | 0:9d17e4342598 | 9394 | output[idx++] = ssl->suites->hashAlgo; |
wolfSSL | 0:9d17e4342598 | 9395 | output[idx++] = ssl->suites->sigAlgo; |
wolfSSL | 0:9d17e4342598 | 9396 | } |
wolfSSL | 0:9d17e4342598 | 9397 | /* size */ |
wolfSSL | 0:9d17e4342598 | 9398 | c16toa((word16)sigSz, output + idx); |
wolfSSL | 0:9d17e4342598 | 9399 | idx += LENGTH_SZ; |
wolfSSL | 0:9d17e4342598 | 9400 | |
wolfSSL | 0:9d17e4342598 | 9401 | /* do signature */ |
wolfSSL | 0:9d17e4342598 | 9402 | { |
wolfSSL | 0:9d17e4342598 | 9403 | #ifndef NO_OLD_TLS |
wolfSSL | 0:9d17e4342598 | 9404 | Md5 md5; |
wolfSSL | 0:9d17e4342598 | 9405 | Sha sha; |
wolfSSL | 0:9d17e4342598 | 9406 | #endif |
wolfSSL | 0:9d17e4342598 | 9407 | byte hash[FINISHED_SZ]; |
wolfSSL | 0:9d17e4342598 | 9408 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 9409 | Sha256 sha256; |
wolfSSL | 0:9d17e4342598 | 9410 | byte hash256[SHA256_DIGEST_SIZE]; |
wolfSSL | 0:9d17e4342598 | 9411 | #endif |
wolfSSL | 0:9d17e4342598 | 9412 | #ifdef CYASSL_SHA384 |
wolfSSL | 0:9d17e4342598 | 9413 | Sha384 sha384; |
wolfSSL | 0:9d17e4342598 | 9414 | byte hash384[SHA384_DIGEST_SIZE]; |
wolfSSL | 0:9d17e4342598 | 9415 | #endif |
wolfSSL | 0:9d17e4342598 | 9416 | |
wolfSSL | 0:9d17e4342598 | 9417 | #ifndef NO_OLD_TLS |
wolfSSL | 0:9d17e4342598 | 9418 | /* md5 */ |
wolfSSL | 0:9d17e4342598 | 9419 | InitMd5(&md5); |
wolfSSL | 0:9d17e4342598 | 9420 | Md5Update(&md5, ssl->arrays->clientRandom, RAN_LEN); |
wolfSSL | 0:9d17e4342598 | 9421 | Md5Update(&md5, ssl->arrays->serverRandom, RAN_LEN); |
wolfSSL | 0:9d17e4342598 | 9422 | Md5Update(&md5, output + preSigIdx, preSigSz); |
wolfSSL | 0:9d17e4342598 | 9423 | Md5Final(&md5, hash); |
wolfSSL | 0:9d17e4342598 | 9424 | |
wolfSSL | 0:9d17e4342598 | 9425 | /* sha */ |
wolfSSL | 0:9d17e4342598 | 9426 | ret = InitSha(&sha); |
wolfSSL | 0:9d17e4342598 | 9427 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 9428 | return ret; |
wolfSSL | 0:9d17e4342598 | 9429 | ShaUpdate(&sha, ssl->arrays->clientRandom, RAN_LEN); |
wolfSSL | 0:9d17e4342598 | 9430 | ShaUpdate(&sha, ssl->arrays->serverRandom, RAN_LEN); |
wolfSSL | 0:9d17e4342598 | 9431 | ShaUpdate(&sha, output + preSigIdx, preSigSz); |
wolfSSL | 0:9d17e4342598 | 9432 | ShaFinal(&sha, &hash[MD5_DIGEST_SIZE]); |
wolfSSL | 0:9d17e4342598 | 9433 | #endif |
wolfSSL | 0:9d17e4342598 | 9434 | |
wolfSSL | 0:9d17e4342598 | 9435 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 9436 | ret = InitSha256(&sha256); |
wolfSSL | 0:9d17e4342598 | 9437 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 9438 | return ret; |
wolfSSL | 0:9d17e4342598 | 9439 | Sha256Update(&sha256, ssl->arrays->clientRandom, RAN_LEN); |
wolfSSL | 0:9d17e4342598 | 9440 | Sha256Update(&sha256, ssl->arrays->serverRandom, RAN_LEN); |
wolfSSL | 0:9d17e4342598 | 9441 | Sha256Update(&sha256, output + preSigIdx, preSigSz); |
wolfSSL | 0:9d17e4342598 | 9442 | Sha256Final(&sha256, hash256); |
wolfSSL | 0:9d17e4342598 | 9443 | #endif |
wolfSSL | 0:9d17e4342598 | 9444 | |
wolfSSL | 0:9d17e4342598 | 9445 | #ifdef CYASSL_SHA384 |
wolfSSL | 0:9d17e4342598 | 9446 | ret = InitSha384(&sha384); |
wolfSSL | 0:9d17e4342598 | 9447 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 9448 | return ret; |
wolfSSL | 0:9d17e4342598 | 9449 | Sha384Update(&sha384, ssl->arrays->clientRandom, RAN_LEN); |
wolfSSL | 0:9d17e4342598 | 9450 | Sha384Update(&sha384, ssl->arrays->serverRandom, RAN_LEN); |
wolfSSL | 0:9d17e4342598 | 9451 | Sha384Update(&sha384, output + preSigIdx, preSigSz); |
wolfSSL | 0:9d17e4342598 | 9452 | Sha384Final(&sha384, hash384); |
wolfSSL | 0:9d17e4342598 | 9453 | #endif |
wolfSSL | 0:9d17e4342598 | 9454 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 9455 | if (ssl->suites->sigAlgo == rsa_sa_algo) { |
wolfSSL | 0:9d17e4342598 | 9456 | byte* signBuffer = hash; |
wolfSSL | 0:9d17e4342598 | 9457 | word32 signSz = sizeof(hash); |
wolfSSL | 0:9d17e4342598 | 9458 | byte encodedSig[MAX_ENCODED_SIG_SZ]; |
wolfSSL | 0:9d17e4342598 | 9459 | byte doUserRsa = 0; |
wolfSSL | 0:9d17e4342598 | 9460 | |
wolfSSL | 0:9d17e4342598 | 9461 | #ifdef HAVE_PK_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 9462 | if (ssl->ctx->RsaSignCb) |
wolfSSL | 0:9d17e4342598 | 9463 | doUserRsa = 1; |
wolfSSL | 0:9d17e4342598 | 9464 | #endif /*HAVE_PK_CALLBACKS */ |
wolfSSL | 0:9d17e4342598 | 9465 | |
wolfSSL | 0:9d17e4342598 | 9466 | if (IsAtLeastTLSv1_2(ssl)) { |
wolfSSL | 0:9d17e4342598 | 9467 | byte* digest = &hash[MD5_DIGEST_SIZE]; |
wolfSSL | 0:9d17e4342598 | 9468 | int typeH = SHAh; |
wolfSSL | 0:9d17e4342598 | 9469 | int digestSz = SHA_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 9470 | |
wolfSSL | 0:9d17e4342598 | 9471 | if (ssl->suites->hashAlgo == sha256_mac) { |
wolfSSL | 0:9d17e4342598 | 9472 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 9473 | digest = hash256; |
wolfSSL | 0:9d17e4342598 | 9474 | typeH = SHA256h; |
wolfSSL | 0:9d17e4342598 | 9475 | digestSz = SHA256_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 9476 | #endif |
wolfSSL | 0:9d17e4342598 | 9477 | } |
wolfSSL | 0:9d17e4342598 | 9478 | else if (ssl->suites->hashAlgo == sha384_mac) { |
wolfSSL | 0:9d17e4342598 | 9479 | #ifdef CYASSL_SHA384 |
wolfSSL | 0:9d17e4342598 | 9480 | digest = hash384; |
wolfSSL | 0:9d17e4342598 | 9481 | typeH = SHA384h; |
wolfSSL | 0:9d17e4342598 | 9482 | digestSz = SHA384_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 9483 | #endif |
wolfSSL | 0:9d17e4342598 | 9484 | } |
wolfSSL | 0:9d17e4342598 | 9485 | |
wolfSSL | 0:9d17e4342598 | 9486 | signSz = EncodeSignature(encodedSig, digest, digestSz, |
wolfSSL | 0:9d17e4342598 | 9487 | typeH); |
wolfSSL | 0:9d17e4342598 | 9488 | signBuffer = encodedSig; |
wolfSSL | 0:9d17e4342598 | 9489 | } |
wolfSSL | 0:9d17e4342598 | 9490 | if (doUserRsa) { |
wolfSSL | 0:9d17e4342598 | 9491 | #ifdef HAVE_PK_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 9492 | word32 ioLen = sigSz; |
wolfSSL | 0:9d17e4342598 | 9493 | ret = ssl->ctx->RsaSignCb(ssl, signBuffer, signSz, |
wolfSSL | 0:9d17e4342598 | 9494 | output + idx, |
wolfSSL | 0:9d17e4342598 | 9495 | &ioLen, |
wolfSSL | 0:9d17e4342598 | 9496 | ssl->buffers.key.buffer, |
wolfSSL | 0:9d17e4342598 | 9497 | ssl->buffers.key.length, |
wolfSSL | 0:9d17e4342598 | 9498 | ssl->RsaSignCtx); |
wolfSSL | 0:9d17e4342598 | 9499 | #endif /*HAVE_PK_CALLBACKS */ |
wolfSSL | 0:9d17e4342598 | 9500 | } |
wolfSSL | 0:9d17e4342598 | 9501 | else { |
wolfSSL | 0:9d17e4342598 | 9502 | ret = RsaSSL_Sign(signBuffer, signSz, output + idx, |
wolfSSL | 0:9d17e4342598 | 9503 | sigSz, &rsaKey, ssl->rng); |
wolfSSL | 0:9d17e4342598 | 9504 | } |
wolfSSL | 0:9d17e4342598 | 9505 | FreeRsaKey(&rsaKey); |
wolfSSL | 0:9d17e4342598 | 9506 | if (ret < 0) |
wolfSSL | 0:9d17e4342598 | 9507 | return ret; |
wolfSSL | 0:9d17e4342598 | 9508 | } |
wolfSSL | 0:9d17e4342598 | 9509 | #endif |
wolfSSL | 0:9d17e4342598 | 9510 | } |
wolfSSL | 0:9d17e4342598 | 9511 | |
wolfSSL | 0:9d17e4342598 | 9512 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 9513 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 9514 | if ((ret = DtlsPoolSave(ssl, output, sendSz)) != 0) |
wolfSSL | 0:9d17e4342598 | 9515 | return ret; |
wolfSSL | 0:9d17e4342598 | 9516 | } |
wolfSSL | 0:9d17e4342598 | 9517 | #endif |
wolfSSL | 0:9d17e4342598 | 9518 | HashOutput(ssl, output, sendSz, 0); |
wolfSSL | 0:9d17e4342598 | 9519 | |
wolfSSL | 0:9d17e4342598 | 9520 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 9521 | if (ssl->hsInfoOn) |
wolfSSL | 0:9d17e4342598 | 9522 | AddPacketName("ServerKeyExchange", &ssl->handShakeInfo); |
wolfSSL | 0:9d17e4342598 | 9523 | if (ssl->toInfoOn) |
wolfSSL | 0:9d17e4342598 | 9524 | AddPacketInfo("ServerKeyExchange", &ssl->timeoutInfo, |
wolfSSL | 0:9d17e4342598 | 9525 | output, sendSz, ssl->heap); |
wolfSSL | 0:9d17e4342598 | 9526 | #endif |
wolfSSL | 0:9d17e4342598 | 9527 | |
wolfSSL | 0:9d17e4342598 | 9528 | ssl->buffers.outputBuffer.length += sendSz; |
wolfSSL | 0:9d17e4342598 | 9529 | if (ssl->options.groupMessages) |
wolfSSL | 0:9d17e4342598 | 9530 | ret = 0; |
wolfSSL | 0:9d17e4342598 | 9531 | else |
wolfSSL | 0:9d17e4342598 | 9532 | ret = SendBuffered(ssl); |
wolfSSL | 0:9d17e4342598 | 9533 | ssl->options.serverState = SERVER_KEYEXCHANGE_COMPLETE; |
wolfSSL | 0:9d17e4342598 | 9534 | } |
wolfSSL | 0:9d17e4342598 | 9535 | #endif /* OPENSSL_EXTRA */ |
wolfSSL | 0:9d17e4342598 | 9536 | |
wolfSSL | 0:9d17e4342598 | 9537 | return ret; |
wolfSSL | 0:9d17e4342598 | 9538 | } |
wolfSSL | 0:9d17e4342598 | 9539 | |
wolfSSL | 0:9d17e4342598 | 9540 | |
wolfSSL | 0:9d17e4342598 | 9541 | /* cipher requirements */ |
wolfSSL | 0:9d17e4342598 | 9542 | enum { |
wolfSSL | 0:9d17e4342598 | 9543 | REQUIRES_RSA, |
wolfSSL | 0:9d17e4342598 | 9544 | REQUIRES_DHE, |
wolfSSL | 0:9d17e4342598 | 9545 | REQUIRES_ECC_DSA, |
wolfSSL | 0:9d17e4342598 | 9546 | REQUIRES_ECC_STATIC, |
wolfSSL | 0:9d17e4342598 | 9547 | REQUIRES_PSK, |
wolfSSL | 0:9d17e4342598 | 9548 | REQUIRES_NTRU, |
wolfSSL | 0:9d17e4342598 | 9549 | REQUIRES_RSA_SIG |
wolfSSL | 0:9d17e4342598 | 9550 | }; |
wolfSSL | 0:9d17e4342598 | 9551 | |
wolfSSL | 0:9d17e4342598 | 9552 | |
wolfSSL | 0:9d17e4342598 | 9553 | |
wolfSSL | 0:9d17e4342598 | 9554 | /* Does this cipher suite (first, second) have the requirement |
wolfSSL | 0:9d17e4342598 | 9555 | an ephemeral key exchange will still require the key for signing |
wolfSSL | 0:9d17e4342598 | 9556 | the key exchange so ECHDE_RSA requires an rsa key thus rsa_kea */ |
wolfSSL | 0:9d17e4342598 | 9557 | static int CipherRequires(byte first, byte second, int requirement) |
wolfSSL | 0:9d17e4342598 | 9558 | { |
wolfSSL | 0:9d17e4342598 | 9559 | /* ECC extensions */ |
wolfSSL | 0:9d17e4342598 | 9560 | if (first == ECC_BYTE) { |
wolfSSL | 0:9d17e4342598 | 9561 | |
wolfSSL | 0:9d17e4342598 | 9562 | switch (second) { |
wolfSSL | 0:9d17e4342598 | 9563 | |
wolfSSL | 0:9d17e4342598 | 9564 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 9565 | case TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA : |
wolfSSL | 0:9d17e4342598 | 9566 | if (requirement == REQUIRES_RSA) |
wolfSSL | 0:9d17e4342598 | 9567 | return 1; |
wolfSSL | 0:9d17e4342598 | 9568 | break; |
wolfSSL | 0:9d17e4342598 | 9569 | |
wolfSSL | 0:9d17e4342598 | 9570 | case TLS_ECDH_RSA_WITH_AES_128_CBC_SHA : |
wolfSSL | 0:9d17e4342598 | 9571 | if (requirement == REQUIRES_ECC_STATIC) |
wolfSSL | 0:9d17e4342598 | 9572 | return 1; |
wolfSSL | 0:9d17e4342598 | 9573 | if (requirement == REQUIRES_RSA_SIG) |
wolfSSL | 0:9d17e4342598 | 9574 | return 1; |
wolfSSL | 0:9d17e4342598 | 9575 | break; |
wolfSSL | 0:9d17e4342598 | 9576 | |
wolfSSL | 0:9d17e4342598 | 9577 | #ifndef NO_DES3 |
wolfSSL | 0:9d17e4342598 | 9578 | case TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA : |
wolfSSL | 0:9d17e4342598 | 9579 | if (requirement == REQUIRES_RSA) |
wolfSSL | 0:9d17e4342598 | 9580 | return 1; |
wolfSSL | 0:9d17e4342598 | 9581 | break; |
wolfSSL | 0:9d17e4342598 | 9582 | |
wolfSSL | 0:9d17e4342598 | 9583 | case TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA : |
wolfSSL | 0:9d17e4342598 | 9584 | if (requirement == REQUIRES_ECC_STATIC) |
wolfSSL | 0:9d17e4342598 | 9585 | return 1; |
wolfSSL | 0:9d17e4342598 | 9586 | if (requirement == REQUIRES_RSA_SIG) |
wolfSSL | 0:9d17e4342598 | 9587 | return 1; |
wolfSSL | 0:9d17e4342598 | 9588 | break; |
wolfSSL | 0:9d17e4342598 | 9589 | #endif |
wolfSSL | 0:9d17e4342598 | 9590 | |
wolfSSL | 0:9d17e4342598 | 9591 | #ifndef NO_RC4 |
wolfSSL | 0:9d17e4342598 | 9592 | case TLS_ECDHE_RSA_WITH_RC4_128_SHA : |
wolfSSL | 0:9d17e4342598 | 9593 | if (requirement == REQUIRES_RSA) |
wolfSSL | 0:9d17e4342598 | 9594 | return 1; |
wolfSSL | 0:9d17e4342598 | 9595 | break; |
wolfSSL | 0:9d17e4342598 | 9596 | |
wolfSSL | 0:9d17e4342598 | 9597 | case TLS_ECDH_RSA_WITH_RC4_128_SHA : |
wolfSSL | 0:9d17e4342598 | 9598 | if (requirement == REQUIRES_ECC_STATIC) |
wolfSSL | 0:9d17e4342598 | 9599 | return 1; |
wolfSSL | 0:9d17e4342598 | 9600 | if (requirement == REQUIRES_RSA_SIG) |
wolfSSL | 0:9d17e4342598 | 9601 | return 1; |
wolfSSL | 0:9d17e4342598 | 9602 | break; |
wolfSSL | 0:9d17e4342598 | 9603 | #endif |
wolfSSL | 0:9d17e4342598 | 9604 | #endif /* NO_RSA */ |
wolfSSL | 0:9d17e4342598 | 9605 | |
wolfSSL | 0:9d17e4342598 | 9606 | #ifndef NO_DES3 |
wolfSSL | 0:9d17e4342598 | 9607 | case TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA : |
wolfSSL | 0:9d17e4342598 | 9608 | if (requirement == REQUIRES_ECC_DSA) |
wolfSSL | 0:9d17e4342598 | 9609 | return 1; |
wolfSSL | 0:9d17e4342598 | 9610 | break; |
wolfSSL | 0:9d17e4342598 | 9611 | |
wolfSSL | 0:9d17e4342598 | 9612 | case TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA : |
wolfSSL | 0:9d17e4342598 | 9613 | if (requirement == REQUIRES_ECC_STATIC) |
wolfSSL | 0:9d17e4342598 | 9614 | return 1; |
wolfSSL | 0:9d17e4342598 | 9615 | break; |
wolfSSL | 0:9d17e4342598 | 9616 | #endif |
wolfSSL | 0:9d17e4342598 | 9617 | #ifndef NO_RC4 |
wolfSSL | 0:9d17e4342598 | 9618 | case TLS_ECDHE_ECDSA_WITH_RC4_128_SHA : |
wolfSSL | 0:9d17e4342598 | 9619 | if (requirement == REQUIRES_ECC_DSA) |
wolfSSL | 0:9d17e4342598 | 9620 | return 1; |
wolfSSL | 0:9d17e4342598 | 9621 | break; |
wolfSSL | 0:9d17e4342598 | 9622 | |
wolfSSL | 0:9d17e4342598 | 9623 | case TLS_ECDH_ECDSA_WITH_RC4_128_SHA : |
wolfSSL | 0:9d17e4342598 | 9624 | if (requirement == REQUIRES_ECC_STATIC) |
wolfSSL | 0:9d17e4342598 | 9625 | return 1; |
wolfSSL | 0:9d17e4342598 | 9626 | break; |
wolfSSL | 0:9d17e4342598 | 9627 | #endif |
wolfSSL | 0:9d17e4342598 | 9628 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 9629 | case TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA : |
wolfSSL | 0:9d17e4342598 | 9630 | if (requirement == REQUIRES_RSA) |
wolfSSL | 0:9d17e4342598 | 9631 | return 1; |
wolfSSL | 0:9d17e4342598 | 9632 | break; |
wolfSSL | 0:9d17e4342598 | 9633 | |
wolfSSL | 0:9d17e4342598 | 9634 | case TLS_ECDH_RSA_WITH_AES_256_CBC_SHA : |
wolfSSL | 0:9d17e4342598 | 9635 | if (requirement == REQUIRES_ECC_STATIC) |
wolfSSL | 0:9d17e4342598 | 9636 | return 1; |
wolfSSL | 0:9d17e4342598 | 9637 | if (requirement == REQUIRES_RSA_SIG) |
wolfSSL | 0:9d17e4342598 | 9638 | return 1; |
wolfSSL | 0:9d17e4342598 | 9639 | break; |
wolfSSL | 0:9d17e4342598 | 9640 | #endif |
wolfSSL | 0:9d17e4342598 | 9641 | |
wolfSSL | 0:9d17e4342598 | 9642 | case TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA : |
wolfSSL | 0:9d17e4342598 | 9643 | if (requirement == REQUIRES_ECC_DSA) |
wolfSSL | 0:9d17e4342598 | 9644 | return 1; |
wolfSSL | 0:9d17e4342598 | 9645 | break; |
wolfSSL | 0:9d17e4342598 | 9646 | |
wolfSSL | 0:9d17e4342598 | 9647 | case TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA : |
wolfSSL | 0:9d17e4342598 | 9648 | if (requirement == REQUIRES_ECC_STATIC) |
wolfSSL | 0:9d17e4342598 | 9649 | return 1; |
wolfSSL | 0:9d17e4342598 | 9650 | break; |
wolfSSL | 0:9d17e4342598 | 9651 | |
wolfSSL | 0:9d17e4342598 | 9652 | case TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA : |
wolfSSL | 0:9d17e4342598 | 9653 | if (requirement == REQUIRES_ECC_DSA) |
wolfSSL | 0:9d17e4342598 | 9654 | return 1; |
wolfSSL | 0:9d17e4342598 | 9655 | break; |
wolfSSL | 0:9d17e4342598 | 9656 | |
wolfSSL | 0:9d17e4342598 | 9657 | case TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA : |
wolfSSL | 0:9d17e4342598 | 9658 | if (requirement == REQUIRES_ECC_STATIC) |
wolfSSL | 0:9d17e4342598 | 9659 | return 1; |
wolfSSL | 0:9d17e4342598 | 9660 | break; |
wolfSSL | 0:9d17e4342598 | 9661 | |
wolfSSL | 0:9d17e4342598 | 9662 | case TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 : |
wolfSSL | 0:9d17e4342598 | 9663 | if (requirement == REQUIRES_ECC_DSA) |
wolfSSL | 0:9d17e4342598 | 9664 | return 1; |
wolfSSL | 0:9d17e4342598 | 9665 | break; |
wolfSSL | 0:9d17e4342598 | 9666 | |
wolfSSL | 0:9d17e4342598 | 9667 | case TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 : |
wolfSSL | 0:9d17e4342598 | 9668 | if (requirement == REQUIRES_ECC_DSA) |
wolfSSL | 0:9d17e4342598 | 9669 | return 1; |
wolfSSL | 0:9d17e4342598 | 9670 | break; |
wolfSSL | 0:9d17e4342598 | 9671 | |
wolfSSL | 0:9d17e4342598 | 9672 | case TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 : |
wolfSSL | 0:9d17e4342598 | 9673 | if (requirement == REQUIRES_ECC_STATIC) |
wolfSSL | 0:9d17e4342598 | 9674 | return 1; |
wolfSSL | 0:9d17e4342598 | 9675 | break; |
wolfSSL | 0:9d17e4342598 | 9676 | |
wolfSSL | 0:9d17e4342598 | 9677 | case TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 : |
wolfSSL | 0:9d17e4342598 | 9678 | if (requirement == REQUIRES_ECC_STATIC) |
wolfSSL | 0:9d17e4342598 | 9679 | return 1; |
wolfSSL | 0:9d17e4342598 | 9680 | break; |
wolfSSL | 0:9d17e4342598 | 9681 | |
wolfSSL | 0:9d17e4342598 | 9682 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 9683 | case TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 : |
wolfSSL | 0:9d17e4342598 | 9684 | if (requirement == REQUIRES_RSA) |
wolfSSL | 0:9d17e4342598 | 9685 | return 1; |
wolfSSL | 0:9d17e4342598 | 9686 | break; |
wolfSSL | 0:9d17e4342598 | 9687 | |
wolfSSL | 0:9d17e4342598 | 9688 | case TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 : |
wolfSSL | 0:9d17e4342598 | 9689 | if (requirement == REQUIRES_RSA) |
wolfSSL | 0:9d17e4342598 | 9690 | return 1; |
wolfSSL | 0:9d17e4342598 | 9691 | break; |
wolfSSL | 0:9d17e4342598 | 9692 | |
wolfSSL | 0:9d17e4342598 | 9693 | case TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 : |
wolfSSL | 0:9d17e4342598 | 9694 | if (requirement == REQUIRES_ECC_STATIC) |
wolfSSL | 0:9d17e4342598 | 9695 | return 1; |
wolfSSL | 0:9d17e4342598 | 9696 | if (requirement == REQUIRES_RSA_SIG) |
wolfSSL | 0:9d17e4342598 | 9697 | return 1; |
wolfSSL | 0:9d17e4342598 | 9698 | break; |
wolfSSL | 0:9d17e4342598 | 9699 | |
wolfSSL | 0:9d17e4342598 | 9700 | case TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 : |
wolfSSL | 0:9d17e4342598 | 9701 | if (requirement == REQUIRES_ECC_STATIC) |
wolfSSL | 0:9d17e4342598 | 9702 | return 1; |
wolfSSL | 0:9d17e4342598 | 9703 | if (requirement == REQUIRES_RSA_SIG) |
wolfSSL | 0:9d17e4342598 | 9704 | return 1; |
wolfSSL | 0:9d17e4342598 | 9705 | break; |
wolfSSL | 0:9d17e4342598 | 9706 | |
wolfSSL | 0:9d17e4342598 | 9707 | case TLS_RSA_WITH_AES_128_CCM_8 : |
wolfSSL | 0:9d17e4342598 | 9708 | case TLS_RSA_WITH_AES_256_CCM_8 : |
wolfSSL | 0:9d17e4342598 | 9709 | if (requirement == REQUIRES_RSA) |
wolfSSL | 0:9d17e4342598 | 9710 | return 1; |
wolfSSL | 0:9d17e4342598 | 9711 | if (requirement == REQUIRES_RSA_SIG) |
wolfSSL | 0:9d17e4342598 | 9712 | return 1; |
wolfSSL | 0:9d17e4342598 | 9713 | break; |
wolfSSL | 0:9d17e4342598 | 9714 | |
wolfSSL | 0:9d17e4342598 | 9715 | case TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 : |
wolfSSL | 0:9d17e4342598 | 9716 | case TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 : |
wolfSSL | 0:9d17e4342598 | 9717 | if (requirement == REQUIRES_RSA) |
wolfSSL | 0:9d17e4342598 | 9718 | return 1; |
wolfSSL | 0:9d17e4342598 | 9719 | if (requirement == REQUIRES_RSA_SIG) |
wolfSSL | 0:9d17e4342598 | 9720 | return 1; |
wolfSSL | 0:9d17e4342598 | 9721 | break; |
wolfSSL | 0:9d17e4342598 | 9722 | |
wolfSSL | 0:9d17e4342598 | 9723 | case TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 : |
wolfSSL | 0:9d17e4342598 | 9724 | case TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 : |
wolfSSL | 0:9d17e4342598 | 9725 | if (requirement == REQUIRES_RSA_SIG) |
wolfSSL | 0:9d17e4342598 | 9726 | return 1; |
wolfSSL | 0:9d17e4342598 | 9727 | if (requirement == REQUIRES_ECC_STATIC) |
wolfSSL | 0:9d17e4342598 | 9728 | return 1; |
wolfSSL | 0:9d17e4342598 | 9729 | break; |
wolfSSL | 0:9d17e4342598 | 9730 | #endif |
wolfSSL | 0:9d17e4342598 | 9731 | |
wolfSSL | 0:9d17e4342598 | 9732 | case TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 : |
wolfSSL | 0:9d17e4342598 | 9733 | case TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 : |
wolfSSL | 0:9d17e4342598 | 9734 | if (requirement == REQUIRES_ECC_DSA) |
wolfSSL | 0:9d17e4342598 | 9735 | return 1; |
wolfSSL | 0:9d17e4342598 | 9736 | break; |
wolfSSL | 0:9d17e4342598 | 9737 | |
wolfSSL | 0:9d17e4342598 | 9738 | case TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 : |
wolfSSL | 0:9d17e4342598 | 9739 | case TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 : |
wolfSSL | 0:9d17e4342598 | 9740 | if (requirement == REQUIRES_ECC_DSA) |
wolfSSL | 0:9d17e4342598 | 9741 | return 1; |
wolfSSL | 0:9d17e4342598 | 9742 | break; |
wolfSSL | 0:9d17e4342598 | 9743 | |
wolfSSL | 0:9d17e4342598 | 9744 | case TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 : |
wolfSSL | 0:9d17e4342598 | 9745 | case TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 : |
wolfSSL | 0:9d17e4342598 | 9746 | if (requirement == REQUIRES_ECC_DSA) |
wolfSSL | 0:9d17e4342598 | 9747 | return 1; |
wolfSSL | 0:9d17e4342598 | 9748 | if (requirement == REQUIRES_ECC_STATIC) |
wolfSSL | 0:9d17e4342598 | 9749 | return 1; |
wolfSSL | 0:9d17e4342598 | 9750 | break; |
wolfSSL | 0:9d17e4342598 | 9751 | |
wolfSSL | 0:9d17e4342598 | 9752 | default: |
wolfSSL | 0:9d17e4342598 | 9753 | CYASSL_MSG("Unsupported cipher suite, CipherRequires ECC"); |
wolfSSL | 0:9d17e4342598 | 9754 | return 0; |
wolfSSL | 0:9d17e4342598 | 9755 | } /* switch */ |
wolfSSL | 0:9d17e4342598 | 9756 | } /* if */ |
wolfSSL | 0:9d17e4342598 | 9757 | if (first != ECC_BYTE) { /* normal suites */ |
wolfSSL | 0:9d17e4342598 | 9758 | switch (second) { |
wolfSSL | 0:9d17e4342598 | 9759 | |
wolfSSL | 0:9d17e4342598 | 9760 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 9761 | case SSL_RSA_WITH_RC4_128_SHA : |
wolfSSL | 0:9d17e4342598 | 9762 | if (requirement == REQUIRES_RSA) |
wolfSSL | 0:9d17e4342598 | 9763 | return 1; |
wolfSSL | 0:9d17e4342598 | 9764 | break; |
wolfSSL | 0:9d17e4342598 | 9765 | |
wolfSSL | 0:9d17e4342598 | 9766 | case TLS_NTRU_RSA_WITH_RC4_128_SHA : |
wolfSSL | 0:9d17e4342598 | 9767 | if (requirement == REQUIRES_NTRU) |
wolfSSL | 0:9d17e4342598 | 9768 | return 1; |
wolfSSL | 0:9d17e4342598 | 9769 | break; |
wolfSSL | 0:9d17e4342598 | 9770 | |
wolfSSL | 0:9d17e4342598 | 9771 | case SSL_RSA_WITH_RC4_128_MD5 : |
wolfSSL | 0:9d17e4342598 | 9772 | if (requirement == REQUIRES_RSA) |
wolfSSL | 0:9d17e4342598 | 9773 | return 1; |
wolfSSL | 0:9d17e4342598 | 9774 | break; |
wolfSSL | 0:9d17e4342598 | 9775 | |
wolfSSL | 0:9d17e4342598 | 9776 | case SSL_RSA_WITH_3DES_EDE_CBC_SHA : |
wolfSSL | 0:9d17e4342598 | 9777 | if (requirement == REQUIRES_RSA) |
wolfSSL | 0:9d17e4342598 | 9778 | return 1; |
wolfSSL | 0:9d17e4342598 | 9779 | break; |
wolfSSL | 0:9d17e4342598 | 9780 | |
wolfSSL | 0:9d17e4342598 | 9781 | case TLS_NTRU_RSA_WITH_3DES_EDE_CBC_SHA : |
wolfSSL | 0:9d17e4342598 | 9782 | if (requirement == REQUIRES_NTRU) |
wolfSSL | 0:9d17e4342598 | 9783 | return 1; |
wolfSSL | 0:9d17e4342598 | 9784 | break; |
wolfSSL | 0:9d17e4342598 | 9785 | |
wolfSSL | 0:9d17e4342598 | 9786 | case TLS_RSA_WITH_AES_128_CBC_SHA : |
wolfSSL | 0:9d17e4342598 | 9787 | if (requirement == REQUIRES_RSA) |
wolfSSL | 0:9d17e4342598 | 9788 | return 1; |
wolfSSL | 0:9d17e4342598 | 9789 | break; |
wolfSSL | 0:9d17e4342598 | 9790 | |
wolfSSL | 0:9d17e4342598 | 9791 | case TLS_RSA_WITH_AES_128_CBC_SHA256 : |
wolfSSL | 0:9d17e4342598 | 9792 | if (requirement == REQUIRES_RSA) |
wolfSSL | 0:9d17e4342598 | 9793 | return 1; |
wolfSSL | 0:9d17e4342598 | 9794 | break; |
wolfSSL | 0:9d17e4342598 | 9795 | |
wolfSSL | 0:9d17e4342598 | 9796 | case TLS_NTRU_RSA_WITH_AES_128_CBC_SHA : |
wolfSSL | 0:9d17e4342598 | 9797 | if (requirement == REQUIRES_NTRU) |
wolfSSL | 0:9d17e4342598 | 9798 | return 1; |
wolfSSL | 0:9d17e4342598 | 9799 | break; |
wolfSSL | 0:9d17e4342598 | 9800 | |
wolfSSL | 0:9d17e4342598 | 9801 | case TLS_RSA_WITH_AES_256_CBC_SHA : |
wolfSSL | 0:9d17e4342598 | 9802 | if (requirement == REQUIRES_RSA) |
wolfSSL | 0:9d17e4342598 | 9803 | return 1; |
wolfSSL | 0:9d17e4342598 | 9804 | break; |
wolfSSL | 0:9d17e4342598 | 9805 | |
wolfSSL | 0:9d17e4342598 | 9806 | case TLS_RSA_WITH_AES_256_CBC_SHA256 : |
wolfSSL | 0:9d17e4342598 | 9807 | if (requirement == REQUIRES_RSA) |
wolfSSL | 0:9d17e4342598 | 9808 | return 1; |
wolfSSL | 0:9d17e4342598 | 9809 | break; |
wolfSSL | 0:9d17e4342598 | 9810 | |
wolfSSL | 0:9d17e4342598 | 9811 | case TLS_RSA_WITH_NULL_SHA : |
wolfSSL | 0:9d17e4342598 | 9812 | case TLS_RSA_WITH_NULL_SHA256 : |
wolfSSL | 0:9d17e4342598 | 9813 | if (requirement == REQUIRES_RSA) |
wolfSSL | 0:9d17e4342598 | 9814 | return 1; |
wolfSSL | 0:9d17e4342598 | 9815 | break; |
wolfSSL | 0:9d17e4342598 | 9816 | |
wolfSSL | 0:9d17e4342598 | 9817 | case TLS_NTRU_RSA_WITH_AES_256_CBC_SHA : |
wolfSSL | 0:9d17e4342598 | 9818 | if (requirement == REQUIRES_NTRU) |
wolfSSL | 0:9d17e4342598 | 9819 | return 1; |
wolfSSL | 0:9d17e4342598 | 9820 | break; |
wolfSSL | 0:9d17e4342598 | 9821 | #endif |
wolfSSL | 0:9d17e4342598 | 9822 | |
wolfSSL | 0:9d17e4342598 | 9823 | case TLS_PSK_WITH_AES_128_CBC_SHA256 : |
wolfSSL | 0:9d17e4342598 | 9824 | if (requirement == REQUIRES_PSK) |
wolfSSL | 0:9d17e4342598 | 9825 | return 1; |
wolfSSL | 0:9d17e4342598 | 9826 | break; |
wolfSSL | 0:9d17e4342598 | 9827 | |
wolfSSL | 0:9d17e4342598 | 9828 | case TLS_PSK_WITH_AES_128_CBC_SHA : |
wolfSSL | 0:9d17e4342598 | 9829 | if (requirement == REQUIRES_PSK) |
wolfSSL | 0:9d17e4342598 | 9830 | return 1; |
wolfSSL | 0:9d17e4342598 | 9831 | break; |
wolfSSL | 0:9d17e4342598 | 9832 | |
wolfSSL | 0:9d17e4342598 | 9833 | case TLS_PSK_WITH_AES_256_CBC_SHA : |
wolfSSL | 0:9d17e4342598 | 9834 | if (requirement == REQUIRES_PSK) |
wolfSSL | 0:9d17e4342598 | 9835 | return 1; |
wolfSSL | 0:9d17e4342598 | 9836 | break; |
wolfSSL | 0:9d17e4342598 | 9837 | |
wolfSSL | 0:9d17e4342598 | 9838 | case TLS_PSK_WITH_NULL_SHA256 : |
wolfSSL | 0:9d17e4342598 | 9839 | if (requirement == REQUIRES_PSK) |
wolfSSL | 0:9d17e4342598 | 9840 | return 1; |
wolfSSL | 0:9d17e4342598 | 9841 | break; |
wolfSSL | 0:9d17e4342598 | 9842 | |
wolfSSL | 0:9d17e4342598 | 9843 | case TLS_PSK_WITH_NULL_SHA : |
wolfSSL | 0:9d17e4342598 | 9844 | if (requirement == REQUIRES_PSK) |
wolfSSL | 0:9d17e4342598 | 9845 | return 1; |
wolfSSL | 0:9d17e4342598 | 9846 | break; |
wolfSSL | 0:9d17e4342598 | 9847 | |
wolfSSL | 0:9d17e4342598 | 9848 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 9849 | case TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 : |
wolfSSL | 0:9d17e4342598 | 9850 | if (requirement == REQUIRES_RSA) |
wolfSSL | 0:9d17e4342598 | 9851 | return 1; |
wolfSSL | 0:9d17e4342598 | 9852 | if (requirement == REQUIRES_DHE) |
wolfSSL | 0:9d17e4342598 | 9853 | return 1; |
wolfSSL | 0:9d17e4342598 | 9854 | break; |
wolfSSL | 0:9d17e4342598 | 9855 | |
wolfSSL | 0:9d17e4342598 | 9856 | case TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 : |
wolfSSL | 0:9d17e4342598 | 9857 | if (requirement == REQUIRES_RSA) |
wolfSSL | 0:9d17e4342598 | 9858 | return 1; |
wolfSSL | 0:9d17e4342598 | 9859 | if (requirement == REQUIRES_DHE) |
wolfSSL | 0:9d17e4342598 | 9860 | return 1; |
wolfSSL | 0:9d17e4342598 | 9861 | break; |
wolfSSL | 0:9d17e4342598 | 9862 | |
wolfSSL | 0:9d17e4342598 | 9863 | case TLS_DHE_RSA_WITH_AES_128_CBC_SHA : |
wolfSSL | 0:9d17e4342598 | 9864 | if (requirement == REQUIRES_RSA) |
wolfSSL | 0:9d17e4342598 | 9865 | return 1; |
wolfSSL | 0:9d17e4342598 | 9866 | if (requirement == REQUIRES_DHE) |
wolfSSL | 0:9d17e4342598 | 9867 | return 1; |
wolfSSL | 0:9d17e4342598 | 9868 | break; |
wolfSSL | 0:9d17e4342598 | 9869 | |
wolfSSL | 0:9d17e4342598 | 9870 | case TLS_DHE_RSA_WITH_AES_256_CBC_SHA : |
wolfSSL | 0:9d17e4342598 | 9871 | if (requirement == REQUIRES_RSA) |
wolfSSL | 0:9d17e4342598 | 9872 | return 1; |
wolfSSL | 0:9d17e4342598 | 9873 | if (requirement == REQUIRES_DHE) |
wolfSSL | 0:9d17e4342598 | 9874 | return 1; |
wolfSSL | 0:9d17e4342598 | 9875 | break; |
wolfSSL | 0:9d17e4342598 | 9876 | |
wolfSSL | 0:9d17e4342598 | 9877 | case TLS_RSA_WITH_HC_128_MD5 : |
wolfSSL | 0:9d17e4342598 | 9878 | if (requirement == REQUIRES_RSA) |
wolfSSL | 0:9d17e4342598 | 9879 | return 1; |
wolfSSL | 0:9d17e4342598 | 9880 | break; |
wolfSSL | 0:9d17e4342598 | 9881 | |
wolfSSL | 0:9d17e4342598 | 9882 | case TLS_RSA_WITH_HC_128_SHA : |
wolfSSL | 0:9d17e4342598 | 9883 | if (requirement == REQUIRES_RSA) |
wolfSSL | 0:9d17e4342598 | 9884 | return 1; |
wolfSSL | 0:9d17e4342598 | 9885 | break; |
wolfSSL | 0:9d17e4342598 | 9886 | |
wolfSSL | 0:9d17e4342598 | 9887 | case TLS_RSA_WITH_HC_128_B2B256: |
wolfSSL | 0:9d17e4342598 | 9888 | if (requirement == REQUIRES_RSA) |
wolfSSL | 0:9d17e4342598 | 9889 | return 1; |
wolfSSL | 0:9d17e4342598 | 9890 | break; |
wolfSSL | 0:9d17e4342598 | 9891 | |
wolfSSL | 0:9d17e4342598 | 9892 | case TLS_RSA_WITH_AES_128_CBC_B2B256: |
wolfSSL | 0:9d17e4342598 | 9893 | case TLS_RSA_WITH_AES_256_CBC_B2B256: |
wolfSSL | 0:9d17e4342598 | 9894 | if (requirement == REQUIRES_RSA) |
wolfSSL | 0:9d17e4342598 | 9895 | return 1; |
wolfSSL | 0:9d17e4342598 | 9896 | break; |
wolfSSL | 0:9d17e4342598 | 9897 | |
wolfSSL | 0:9d17e4342598 | 9898 | case TLS_RSA_WITH_RABBIT_SHA : |
wolfSSL | 0:9d17e4342598 | 9899 | if (requirement == REQUIRES_RSA) |
wolfSSL | 0:9d17e4342598 | 9900 | return 1; |
wolfSSL | 0:9d17e4342598 | 9901 | break; |
wolfSSL | 0:9d17e4342598 | 9902 | |
wolfSSL | 0:9d17e4342598 | 9903 | case TLS_RSA_WITH_AES_128_GCM_SHA256 : |
wolfSSL | 0:9d17e4342598 | 9904 | case TLS_RSA_WITH_AES_256_GCM_SHA384 : |
wolfSSL | 0:9d17e4342598 | 9905 | if (requirement == REQUIRES_RSA) |
wolfSSL | 0:9d17e4342598 | 9906 | return 1; |
wolfSSL | 0:9d17e4342598 | 9907 | break; |
wolfSSL | 0:9d17e4342598 | 9908 | |
wolfSSL | 0:9d17e4342598 | 9909 | case TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 : |
wolfSSL | 0:9d17e4342598 | 9910 | case TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 : |
wolfSSL | 0:9d17e4342598 | 9911 | if (requirement == REQUIRES_RSA) |
wolfSSL | 0:9d17e4342598 | 9912 | return 1; |
wolfSSL | 0:9d17e4342598 | 9913 | if (requirement == REQUIRES_DHE) |
wolfSSL | 0:9d17e4342598 | 9914 | return 1; |
wolfSSL | 0:9d17e4342598 | 9915 | break; |
wolfSSL | 0:9d17e4342598 | 9916 | |
wolfSSL | 0:9d17e4342598 | 9917 | case TLS_RSA_WITH_CAMELLIA_128_CBC_SHA : |
wolfSSL | 0:9d17e4342598 | 9918 | case TLS_RSA_WITH_CAMELLIA_256_CBC_SHA : |
wolfSSL | 0:9d17e4342598 | 9919 | case TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 : |
wolfSSL | 0:9d17e4342598 | 9920 | case TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 : |
wolfSSL | 0:9d17e4342598 | 9921 | if (requirement == REQUIRES_RSA) |
wolfSSL | 0:9d17e4342598 | 9922 | return 1; |
wolfSSL | 0:9d17e4342598 | 9923 | break; |
wolfSSL | 0:9d17e4342598 | 9924 | |
wolfSSL | 0:9d17e4342598 | 9925 | case TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA : |
wolfSSL | 0:9d17e4342598 | 9926 | case TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA : |
wolfSSL | 0:9d17e4342598 | 9927 | case TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 : |
wolfSSL | 0:9d17e4342598 | 9928 | case TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 : |
wolfSSL | 0:9d17e4342598 | 9929 | if (requirement == REQUIRES_RSA) |
wolfSSL | 0:9d17e4342598 | 9930 | return 1; |
wolfSSL | 0:9d17e4342598 | 9931 | if (requirement == REQUIRES_RSA_SIG) |
wolfSSL | 0:9d17e4342598 | 9932 | return 1; |
wolfSSL | 0:9d17e4342598 | 9933 | if (requirement == REQUIRES_DHE) |
wolfSSL | 0:9d17e4342598 | 9934 | return 1; |
wolfSSL | 0:9d17e4342598 | 9935 | break; |
wolfSSL | 0:9d17e4342598 | 9936 | #endif |
wolfSSL | 0:9d17e4342598 | 9937 | |
wolfSSL | 0:9d17e4342598 | 9938 | default: |
wolfSSL | 0:9d17e4342598 | 9939 | CYASSL_MSG("Unsupported cipher suite, CipherRequires"); |
wolfSSL | 0:9d17e4342598 | 9940 | return 0; |
wolfSSL | 0:9d17e4342598 | 9941 | } /* switch */ |
wolfSSL | 0:9d17e4342598 | 9942 | } /* if ECC / Normal suites else */ |
wolfSSL | 0:9d17e4342598 | 9943 | |
wolfSSL | 0:9d17e4342598 | 9944 | return 0; |
wolfSSL | 0:9d17e4342598 | 9945 | } |
wolfSSL | 0:9d17e4342598 | 9946 | |
wolfSSL | 0:9d17e4342598 | 9947 | |
wolfSSL | 0:9d17e4342598 | 9948 | |
wolfSSL | 0:9d17e4342598 | 9949 | |
wolfSSL | 0:9d17e4342598 | 9950 | |
wolfSSL | 0:9d17e4342598 | 9951 | /* Make sure cert/key are valid for this suite, true on success */ |
wolfSSL | 0:9d17e4342598 | 9952 | static int VerifySuite(CYASSL* ssl, word16 idx) |
wolfSSL | 0:9d17e4342598 | 9953 | { |
wolfSSL | 0:9d17e4342598 | 9954 | int haveRSA = !ssl->options.haveStaticECC; |
wolfSSL | 0:9d17e4342598 | 9955 | int havePSK = 0; |
wolfSSL | 0:9d17e4342598 | 9956 | byte first; |
wolfSSL | 0:9d17e4342598 | 9957 | byte second; |
wolfSSL | 0:9d17e4342598 | 9958 | |
wolfSSL | 0:9d17e4342598 | 9959 | CYASSL_ENTER("VerifySuite"); |
wolfSSL | 0:9d17e4342598 | 9960 | |
wolfSSL | 0:9d17e4342598 | 9961 | if (ssl->suites == NULL) { |
wolfSSL | 0:9d17e4342598 | 9962 | CYASSL_MSG("Suites pointer error"); |
wolfSSL | 0:9d17e4342598 | 9963 | return 0; |
wolfSSL | 0:9d17e4342598 | 9964 | } |
wolfSSL | 0:9d17e4342598 | 9965 | |
wolfSSL | 0:9d17e4342598 | 9966 | first = ssl->suites->suites[idx]; |
wolfSSL | 0:9d17e4342598 | 9967 | second = ssl->suites->suites[idx+1]; |
wolfSSL | 0:9d17e4342598 | 9968 | |
wolfSSL | 0:9d17e4342598 | 9969 | #ifndef NO_PSK |
wolfSSL | 0:9d17e4342598 | 9970 | havePSK = ssl->options.havePSK; |
wolfSSL | 0:9d17e4342598 | 9971 | #endif |
wolfSSL | 0:9d17e4342598 | 9972 | |
wolfSSL | 0:9d17e4342598 | 9973 | if (ssl->options.haveNTRU) |
wolfSSL | 0:9d17e4342598 | 9974 | haveRSA = 0; |
wolfSSL | 0:9d17e4342598 | 9975 | |
wolfSSL | 0:9d17e4342598 | 9976 | if (CipherRequires(first, second, REQUIRES_RSA)) { |
wolfSSL | 0:9d17e4342598 | 9977 | CYASSL_MSG("Requires RSA"); |
wolfSSL | 0:9d17e4342598 | 9978 | if (haveRSA == 0) { |
wolfSSL | 0:9d17e4342598 | 9979 | CYASSL_MSG("Don't have RSA"); |
wolfSSL | 0:9d17e4342598 | 9980 | return 0; |
wolfSSL | 0:9d17e4342598 | 9981 | } |
wolfSSL | 0:9d17e4342598 | 9982 | } |
wolfSSL | 0:9d17e4342598 | 9983 | |
wolfSSL | 0:9d17e4342598 | 9984 | if (CipherRequires(first, second, REQUIRES_DHE)) { |
wolfSSL | 0:9d17e4342598 | 9985 | CYASSL_MSG("Requires DHE"); |
wolfSSL | 0:9d17e4342598 | 9986 | if (ssl->options.haveDH == 0) { |
wolfSSL | 0:9d17e4342598 | 9987 | CYASSL_MSG("Don't have DHE"); |
wolfSSL | 0:9d17e4342598 | 9988 | return 0; |
wolfSSL | 0:9d17e4342598 | 9989 | } |
wolfSSL | 0:9d17e4342598 | 9990 | } |
wolfSSL | 0:9d17e4342598 | 9991 | |
wolfSSL | 0:9d17e4342598 | 9992 | if (CipherRequires(first, second, REQUIRES_ECC_DSA)) { |
wolfSSL | 0:9d17e4342598 | 9993 | CYASSL_MSG("Requires ECCDSA"); |
wolfSSL | 0:9d17e4342598 | 9994 | if (ssl->options.haveECDSAsig == 0) { |
wolfSSL | 0:9d17e4342598 | 9995 | CYASSL_MSG("Don't have ECCDSA"); |
wolfSSL | 0:9d17e4342598 | 9996 | return 0; |
wolfSSL | 0:9d17e4342598 | 9997 | } |
wolfSSL | 0:9d17e4342598 | 9998 | } |
wolfSSL | 0:9d17e4342598 | 9999 | |
wolfSSL | 0:9d17e4342598 | 10000 | if (CipherRequires(first, second, REQUIRES_ECC_STATIC)) { |
wolfSSL | 0:9d17e4342598 | 10001 | CYASSL_MSG("Requires static ECC"); |
wolfSSL | 0:9d17e4342598 | 10002 | if (ssl->options.haveStaticECC == 0) { |
wolfSSL | 0:9d17e4342598 | 10003 | CYASSL_MSG("Don't have static ECC"); |
wolfSSL | 0:9d17e4342598 | 10004 | return 0; |
wolfSSL | 0:9d17e4342598 | 10005 | } |
wolfSSL | 0:9d17e4342598 | 10006 | } |
wolfSSL | 0:9d17e4342598 | 10007 | |
wolfSSL | 0:9d17e4342598 | 10008 | if (CipherRequires(first, second, REQUIRES_PSK)) { |
wolfSSL | 0:9d17e4342598 | 10009 | CYASSL_MSG("Requires PSK"); |
wolfSSL | 0:9d17e4342598 | 10010 | if (havePSK == 0) { |
wolfSSL | 0:9d17e4342598 | 10011 | CYASSL_MSG("Don't have PSK"); |
wolfSSL | 0:9d17e4342598 | 10012 | return 0; |
wolfSSL | 0:9d17e4342598 | 10013 | } |
wolfSSL | 0:9d17e4342598 | 10014 | } |
wolfSSL | 0:9d17e4342598 | 10015 | |
wolfSSL | 0:9d17e4342598 | 10016 | if (CipherRequires(first, second, REQUIRES_NTRU)) { |
wolfSSL | 0:9d17e4342598 | 10017 | CYASSL_MSG("Requires NTRU"); |
wolfSSL | 0:9d17e4342598 | 10018 | if (ssl->options.haveNTRU == 0) { |
wolfSSL | 0:9d17e4342598 | 10019 | CYASSL_MSG("Don't have NTRU"); |
wolfSSL | 0:9d17e4342598 | 10020 | return 0; |
wolfSSL | 0:9d17e4342598 | 10021 | } |
wolfSSL | 0:9d17e4342598 | 10022 | } |
wolfSSL | 0:9d17e4342598 | 10023 | |
wolfSSL | 0:9d17e4342598 | 10024 | if (CipherRequires(first, second, REQUIRES_RSA_SIG)) { |
wolfSSL | 0:9d17e4342598 | 10025 | CYASSL_MSG("Requires RSA Signature"); |
wolfSSL | 0:9d17e4342598 | 10026 | if (ssl->options.side == CYASSL_SERVER_END && |
wolfSSL | 0:9d17e4342598 | 10027 | ssl->options.haveECDSAsig == 1) { |
wolfSSL | 0:9d17e4342598 | 10028 | CYASSL_MSG("Don't have RSA Signature"); |
wolfSSL | 0:9d17e4342598 | 10029 | return 0; |
wolfSSL | 0:9d17e4342598 | 10030 | } |
wolfSSL | 0:9d17e4342598 | 10031 | } |
wolfSSL | 0:9d17e4342598 | 10032 | |
wolfSSL | 0:9d17e4342598 | 10033 | #ifdef HAVE_SUPPORTED_CURVES |
wolfSSL | 0:9d17e4342598 | 10034 | if (!TLSX_ValidateEllipticCurves(ssl, first, second)) { |
wolfSSL | 0:9d17e4342598 | 10035 | CYASSL_MSG("Don't have matching curves"); |
wolfSSL | 0:9d17e4342598 | 10036 | return 0; |
wolfSSL | 0:9d17e4342598 | 10037 | } |
wolfSSL | 0:9d17e4342598 | 10038 | #endif |
wolfSSL | 0:9d17e4342598 | 10039 | |
wolfSSL | 0:9d17e4342598 | 10040 | /* ECCDHE is always supported if ECC on */ |
wolfSSL | 0:9d17e4342598 | 10041 | |
wolfSSL | 0:9d17e4342598 | 10042 | return 1; |
wolfSSL | 0:9d17e4342598 | 10043 | } |
wolfSSL | 0:9d17e4342598 | 10044 | |
wolfSSL | 0:9d17e4342598 | 10045 | |
wolfSSL | 0:9d17e4342598 | 10046 | static int MatchSuite(CYASSL* ssl, Suites* peerSuites) |
wolfSSL | 0:9d17e4342598 | 10047 | { |
wolfSSL | 0:9d17e4342598 | 10048 | word16 i, j; |
wolfSSL | 0:9d17e4342598 | 10049 | |
wolfSSL | 0:9d17e4342598 | 10050 | CYASSL_ENTER("MatchSuite"); |
wolfSSL | 0:9d17e4342598 | 10051 | |
wolfSSL | 0:9d17e4342598 | 10052 | /* & 0x1 equivalent % 2 */ |
wolfSSL | 0:9d17e4342598 | 10053 | if (peerSuites->suiteSz == 0 || peerSuites->suiteSz & 0x1) |
wolfSSL | 0:9d17e4342598 | 10054 | return MATCH_SUITE_ERROR; |
wolfSSL | 0:9d17e4342598 | 10055 | |
wolfSSL | 0:9d17e4342598 | 10056 | if (ssl->suites == NULL) |
wolfSSL | 0:9d17e4342598 | 10057 | return SUITES_ERROR; |
wolfSSL | 0:9d17e4342598 | 10058 | /* start with best, if a match we are good */ |
wolfSSL | 0:9d17e4342598 | 10059 | for (i = 0; i < ssl->suites->suiteSz; i += 2) |
wolfSSL | 0:9d17e4342598 | 10060 | for (j = 0; j < peerSuites->suiteSz; j += 2) |
wolfSSL | 0:9d17e4342598 | 10061 | if (ssl->suites->suites[i] == peerSuites->suites[j] && |
wolfSSL | 0:9d17e4342598 | 10062 | ssl->suites->suites[i+1] == peerSuites->suites[j+1] ) { |
wolfSSL | 0:9d17e4342598 | 10063 | |
wolfSSL | 0:9d17e4342598 | 10064 | if (VerifySuite(ssl, i)) { |
wolfSSL | 0:9d17e4342598 | 10065 | int result; |
wolfSSL | 0:9d17e4342598 | 10066 | CYASSL_MSG("Verified suite validity"); |
wolfSSL | 0:9d17e4342598 | 10067 | ssl->options.cipherSuite0 = ssl->suites->suites[i]; |
wolfSSL | 0:9d17e4342598 | 10068 | ssl->options.cipherSuite = ssl->suites->suites[i+1]; |
wolfSSL | 0:9d17e4342598 | 10069 | result = SetCipherSpecs(ssl); |
wolfSSL | 0:9d17e4342598 | 10070 | if (result == 0) |
wolfSSL | 0:9d17e4342598 | 10071 | PickHashSigAlgo(ssl, peerSuites->hashSigAlgo, |
wolfSSL | 0:9d17e4342598 | 10072 | peerSuites->hashSigAlgoSz); |
wolfSSL | 0:9d17e4342598 | 10073 | return result; |
wolfSSL | 0:9d17e4342598 | 10074 | } |
wolfSSL | 0:9d17e4342598 | 10075 | else { |
wolfSSL | 0:9d17e4342598 | 10076 | CYASSL_MSG("Could not verify suite validity, continue"); |
wolfSSL | 0:9d17e4342598 | 10077 | } |
wolfSSL | 0:9d17e4342598 | 10078 | } |
wolfSSL | 0:9d17e4342598 | 10079 | |
wolfSSL | 0:9d17e4342598 | 10080 | return MATCH_SUITE_ERROR; |
wolfSSL | 0:9d17e4342598 | 10081 | } |
wolfSSL | 0:9d17e4342598 | 10082 | |
wolfSSL | 0:9d17e4342598 | 10083 | |
wolfSSL | 0:9d17e4342598 | 10084 | /* process old style client hello, deprecate? */ |
wolfSSL | 0:9d17e4342598 | 10085 | int ProcessOldClientHello(CYASSL* ssl, const byte* input, word32* inOutIdx, |
wolfSSL | 0:9d17e4342598 | 10086 | word32 inSz, word16 sz) |
wolfSSL | 0:9d17e4342598 | 10087 | { |
wolfSSL | 0:9d17e4342598 | 10088 | word32 idx = *inOutIdx; |
wolfSSL | 0:9d17e4342598 | 10089 | word16 sessionSz; |
wolfSSL | 0:9d17e4342598 | 10090 | word16 randomSz; |
wolfSSL | 0:9d17e4342598 | 10091 | word16 i, j; |
wolfSSL | 0:9d17e4342598 | 10092 | ProtocolVersion pv; |
wolfSSL | 0:9d17e4342598 | 10093 | Suites clSuites; |
wolfSSL | 0:9d17e4342598 | 10094 | |
wolfSSL | 0:9d17e4342598 | 10095 | (void)inSz; |
wolfSSL | 0:9d17e4342598 | 10096 | CYASSL_MSG("Got old format client hello"); |
wolfSSL | 0:9d17e4342598 | 10097 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 10098 | if (ssl->hsInfoOn) |
wolfSSL | 0:9d17e4342598 | 10099 | AddPacketName("ClientHello", &ssl->handShakeInfo); |
wolfSSL | 0:9d17e4342598 | 10100 | if (ssl->toInfoOn) |
wolfSSL | 0:9d17e4342598 | 10101 | AddLateName("ClientHello", &ssl->timeoutInfo); |
wolfSSL | 0:9d17e4342598 | 10102 | #endif |
wolfSSL | 0:9d17e4342598 | 10103 | |
wolfSSL | 0:9d17e4342598 | 10104 | /* manually hash input since different format */ |
wolfSSL | 0:9d17e4342598 | 10105 | #ifndef NO_OLD_TLS |
wolfSSL | 0:9d17e4342598 | 10106 | #ifndef NO_MD5 |
wolfSSL | 0:9d17e4342598 | 10107 | Md5Update(&ssl->hashMd5, input + idx, sz); |
wolfSSL | 0:9d17e4342598 | 10108 | #endif |
wolfSSL | 0:9d17e4342598 | 10109 | #ifndef NO_SHA |
wolfSSL | 0:9d17e4342598 | 10110 | ShaUpdate(&ssl->hashSha, input + idx, sz); |
wolfSSL | 0:9d17e4342598 | 10111 | #endif |
wolfSSL | 0:9d17e4342598 | 10112 | #endif |
wolfSSL | 0:9d17e4342598 | 10113 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 10114 | if (IsAtLeastTLSv1_2(ssl)) |
wolfSSL | 0:9d17e4342598 | 10115 | Sha256Update(&ssl->hashSha256, input + idx, sz); |
wolfSSL | 0:9d17e4342598 | 10116 | #endif |
wolfSSL | 0:9d17e4342598 | 10117 | |
wolfSSL | 0:9d17e4342598 | 10118 | /* does this value mean client_hello? */ |
wolfSSL | 0:9d17e4342598 | 10119 | idx++; |
wolfSSL | 0:9d17e4342598 | 10120 | |
wolfSSL | 0:9d17e4342598 | 10121 | /* version */ |
wolfSSL | 0:9d17e4342598 | 10122 | pv.major = input[idx++]; |
wolfSSL | 0:9d17e4342598 | 10123 | pv.minor = input[idx++]; |
wolfSSL | 0:9d17e4342598 | 10124 | ssl->chVersion = pv; /* store */ |
wolfSSL | 0:9d17e4342598 | 10125 | |
wolfSSL | 0:9d17e4342598 | 10126 | if (ssl->version.minor > pv.minor) { |
wolfSSL | 0:9d17e4342598 | 10127 | byte haveRSA = 0; |
wolfSSL | 0:9d17e4342598 | 10128 | byte havePSK = 0; |
wolfSSL | 0:9d17e4342598 | 10129 | if (!ssl->options.downgrade) { |
wolfSSL | 0:9d17e4342598 | 10130 | CYASSL_MSG("Client trying to connect with lesser version"); |
wolfSSL | 0:9d17e4342598 | 10131 | return VERSION_ERROR; |
wolfSSL | 0:9d17e4342598 | 10132 | } |
wolfSSL | 0:9d17e4342598 | 10133 | if (pv.minor == SSLv3_MINOR) { |
wolfSSL | 0:9d17e4342598 | 10134 | /* turn off tls */ |
wolfSSL | 0:9d17e4342598 | 10135 | CYASSL_MSG(" downgrading to SSLv3"); |
wolfSSL | 0:9d17e4342598 | 10136 | ssl->options.tls = 0; |
wolfSSL | 0:9d17e4342598 | 10137 | ssl->options.tls1_1 = 0; |
wolfSSL | 0:9d17e4342598 | 10138 | ssl->version.minor = SSLv3_MINOR; |
wolfSSL | 0:9d17e4342598 | 10139 | } |
wolfSSL | 0:9d17e4342598 | 10140 | else if (pv.minor == TLSv1_MINOR) { |
wolfSSL | 0:9d17e4342598 | 10141 | CYASSL_MSG(" downgrading to TLSv1"); |
wolfSSL | 0:9d17e4342598 | 10142 | /* turn off tls 1.1+ */ |
wolfSSL | 0:9d17e4342598 | 10143 | ssl->options.tls1_1 = 0; |
wolfSSL | 0:9d17e4342598 | 10144 | ssl->version.minor = TLSv1_MINOR; |
wolfSSL | 0:9d17e4342598 | 10145 | } |
wolfSSL | 0:9d17e4342598 | 10146 | else if (pv.minor == TLSv1_1_MINOR) { |
wolfSSL | 0:9d17e4342598 | 10147 | CYASSL_MSG(" downgrading to TLSv1.1"); |
wolfSSL | 0:9d17e4342598 | 10148 | ssl->version.minor = TLSv1_1_MINOR; |
wolfSSL | 0:9d17e4342598 | 10149 | } |
wolfSSL | 0:9d17e4342598 | 10150 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 10151 | haveRSA = 1; |
wolfSSL | 0:9d17e4342598 | 10152 | #endif |
wolfSSL | 0:9d17e4342598 | 10153 | #ifndef NO_PSK |
wolfSSL | 0:9d17e4342598 | 10154 | havePSK = ssl->options.havePSK; |
wolfSSL | 0:9d17e4342598 | 10155 | #endif |
wolfSSL | 0:9d17e4342598 | 10156 | |
wolfSSL | 0:9d17e4342598 | 10157 | InitSuites(ssl->suites, ssl->version, haveRSA, havePSK, |
wolfSSL | 0:9d17e4342598 | 10158 | ssl->options.haveDH, ssl->options.haveNTRU, |
wolfSSL | 0:9d17e4342598 | 10159 | ssl->options.haveECDSAsig, ssl->options.haveStaticECC, |
wolfSSL | 0:9d17e4342598 | 10160 | ssl->options.side); |
wolfSSL | 0:9d17e4342598 | 10161 | } |
wolfSSL | 0:9d17e4342598 | 10162 | |
wolfSSL | 0:9d17e4342598 | 10163 | /* suite size */ |
wolfSSL | 0:9d17e4342598 | 10164 | ato16(&input[idx], &clSuites.suiteSz); |
wolfSSL | 0:9d17e4342598 | 10165 | idx += 2; |
wolfSSL | 0:9d17e4342598 | 10166 | |
wolfSSL | 0:9d17e4342598 | 10167 | if (clSuites.suiteSz > MAX_SUITE_SZ) |
wolfSSL | 0:9d17e4342598 | 10168 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 10169 | clSuites.hashSigAlgoSz = 0; |
wolfSSL | 0:9d17e4342598 | 10170 | |
wolfSSL | 0:9d17e4342598 | 10171 | /* session size */ |
wolfSSL | 0:9d17e4342598 | 10172 | ato16(&input[idx], &sessionSz); |
wolfSSL | 0:9d17e4342598 | 10173 | idx += 2; |
wolfSSL | 0:9d17e4342598 | 10174 | |
wolfSSL | 0:9d17e4342598 | 10175 | if (sessionSz > ID_LEN) |
wolfSSL | 0:9d17e4342598 | 10176 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 10177 | |
wolfSSL | 0:9d17e4342598 | 10178 | /* random size */ |
wolfSSL | 0:9d17e4342598 | 10179 | ato16(&input[idx], &randomSz); |
wolfSSL | 0:9d17e4342598 | 10180 | idx += 2; |
wolfSSL | 0:9d17e4342598 | 10181 | |
wolfSSL | 0:9d17e4342598 | 10182 | if (randomSz > RAN_LEN) |
wolfSSL | 0:9d17e4342598 | 10183 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 10184 | |
wolfSSL | 0:9d17e4342598 | 10185 | /* suites */ |
wolfSSL | 0:9d17e4342598 | 10186 | for (i = 0, j = 0; i < clSuites.suiteSz; i += 3) { |
wolfSSL | 0:9d17e4342598 | 10187 | byte first = input[idx++]; |
wolfSSL | 0:9d17e4342598 | 10188 | if (!first) { /* implicit: skip sslv2 type */ |
wolfSSL | 0:9d17e4342598 | 10189 | XMEMCPY(&clSuites.suites[j], &input[idx], 2); |
wolfSSL | 0:9d17e4342598 | 10190 | j += 2; |
wolfSSL | 0:9d17e4342598 | 10191 | } |
wolfSSL | 0:9d17e4342598 | 10192 | idx += 2; |
wolfSSL | 0:9d17e4342598 | 10193 | } |
wolfSSL | 0:9d17e4342598 | 10194 | clSuites.suiteSz = j; |
wolfSSL | 0:9d17e4342598 | 10195 | |
wolfSSL | 0:9d17e4342598 | 10196 | /* session id */ |
wolfSSL | 0:9d17e4342598 | 10197 | if (sessionSz) { |
wolfSSL | 0:9d17e4342598 | 10198 | XMEMCPY(ssl->arrays->sessionID, input + idx, sessionSz); |
wolfSSL | 0:9d17e4342598 | 10199 | idx += sessionSz; |
wolfSSL | 0:9d17e4342598 | 10200 | ssl->options.resuming = 1; |
wolfSSL | 0:9d17e4342598 | 10201 | } |
wolfSSL | 0:9d17e4342598 | 10202 | |
wolfSSL | 0:9d17e4342598 | 10203 | /* random */ |
wolfSSL | 0:9d17e4342598 | 10204 | if (randomSz < RAN_LEN) |
wolfSSL | 0:9d17e4342598 | 10205 | XMEMSET(ssl->arrays->clientRandom, 0, RAN_LEN - randomSz); |
wolfSSL | 0:9d17e4342598 | 10206 | XMEMCPY(&ssl->arrays->clientRandom[RAN_LEN - randomSz], input + idx, |
wolfSSL | 0:9d17e4342598 | 10207 | randomSz); |
wolfSSL | 0:9d17e4342598 | 10208 | idx += randomSz; |
wolfSSL | 0:9d17e4342598 | 10209 | |
wolfSSL | 0:9d17e4342598 | 10210 | if (ssl->options.usingCompression) |
wolfSSL | 0:9d17e4342598 | 10211 | ssl->options.usingCompression = 0; /* turn off */ |
wolfSSL | 0:9d17e4342598 | 10212 | |
wolfSSL | 0:9d17e4342598 | 10213 | ssl->options.clientState = CLIENT_HELLO_COMPLETE; |
wolfSSL | 0:9d17e4342598 | 10214 | *inOutIdx = idx; |
wolfSSL | 0:9d17e4342598 | 10215 | |
wolfSSL | 0:9d17e4342598 | 10216 | ssl->options.haveSessionId = 1; |
wolfSSL | 0:9d17e4342598 | 10217 | /* DoClientHello uses same resume code */ |
wolfSSL | 0:9d17e4342598 | 10218 | if (ssl->options.resuming) { /* let's try */ |
wolfSSL | 0:9d17e4342598 | 10219 | int ret = -1; |
wolfSSL | 0:9d17e4342598 | 10220 | CYASSL_SESSION* session = GetSession(ssl,ssl->arrays->masterSecret); |
wolfSSL | 0:9d17e4342598 | 10221 | if (!session) { |
wolfSSL | 0:9d17e4342598 | 10222 | CYASSL_MSG("Session lookup for resume failed"); |
wolfSSL | 0:9d17e4342598 | 10223 | ssl->options.resuming = 0; |
wolfSSL | 0:9d17e4342598 | 10224 | } else { |
wolfSSL | 0:9d17e4342598 | 10225 | if (MatchSuite(ssl, &clSuites) < 0) { |
wolfSSL | 0:9d17e4342598 | 10226 | CYASSL_MSG("Unsupported cipher suite, OldClientHello"); |
wolfSSL | 0:9d17e4342598 | 10227 | return UNSUPPORTED_SUITE; |
wolfSSL | 0:9d17e4342598 | 10228 | } |
wolfSSL | 0:9d17e4342598 | 10229 | #ifdef SESSION_CERTS |
wolfSSL | 0:9d17e4342598 | 10230 | ssl->session = *session; /* restore session certs. */ |
wolfSSL | 0:9d17e4342598 | 10231 | #endif |
wolfSSL | 0:9d17e4342598 | 10232 | RNG_GenerateBlock(ssl->rng, ssl->arrays->serverRandom, RAN_LEN); |
wolfSSL | 0:9d17e4342598 | 10233 | #ifdef NO_OLD_TLS |
wolfSSL | 0:9d17e4342598 | 10234 | ret = DeriveTlsKeys(ssl); |
wolfSSL | 0:9d17e4342598 | 10235 | #else |
wolfSSL | 0:9d17e4342598 | 10236 | #ifndef NO_TLS |
wolfSSL | 0:9d17e4342598 | 10237 | if (ssl->options.tls) |
wolfSSL | 0:9d17e4342598 | 10238 | ret = DeriveTlsKeys(ssl); |
wolfSSL | 0:9d17e4342598 | 10239 | #endif |
wolfSSL | 0:9d17e4342598 | 10240 | if (!ssl->options.tls) |
wolfSSL | 0:9d17e4342598 | 10241 | ret = DeriveKeys(ssl); |
wolfSSL | 0:9d17e4342598 | 10242 | #endif |
wolfSSL | 0:9d17e4342598 | 10243 | ssl->options.clientState = CLIENT_KEYEXCHANGE_COMPLETE; |
wolfSSL | 0:9d17e4342598 | 10244 | |
wolfSSL | 0:9d17e4342598 | 10245 | return ret; |
wolfSSL | 0:9d17e4342598 | 10246 | } |
wolfSSL | 0:9d17e4342598 | 10247 | } |
wolfSSL | 0:9d17e4342598 | 10248 | |
wolfSSL | 0:9d17e4342598 | 10249 | return MatchSuite(ssl, &clSuites); |
wolfSSL | 0:9d17e4342598 | 10250 | } |
wolfSSL | 0:9d17e4342598 | 10251 | |
wolfSSL | 0:9d17e4342598 | 10252 | |
wolfSSL | 0:9d17e4342598 | 10253 | static int DoClientHello(CYASSL* ssl, const byte* input, word32* inOutIdx, |
wolfSSL | 0:9d17e4342598 | 10254 | word32 helloSz) |
wolfSSL | 0:9d17e4342598 | 10255 | { |
wolfSSL | 0:9d17e4342598 | 10256 | byte b; |
wolfSSL | 0:9d17e4342598 | 10257 | ProtocolVersion pv; |
wolfSSL | 0:9d17e4342598 | 10258 | Suites clSuites; |
wolfSSL | 0:9d17e4342598 | 10259 | word32 i = *inOutIdx; |
wolfSSL | 0:9d17e4342598 | 10260 | word32 begin = i; |
wolfSSL | 0:9d17e4342598 | 10261 | |
wolfSSL | 0:9d17e4342598 | 10262 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 10263 | if (ssl->hsInfoOn) AddPacketName("ClientHello", &ssl->handShakeInfo); |
wolfSSL | 0:9d17e4342598 | 10264 | if (ssl->toInfoOn) AddLateName("ClientHello", &ssl->timeoutInfo); |
wolfSSL | 0:9d17e4342598 | 10265 | #endif |
wolfSSL | 0:9d17e4342598 | 10266 | |
wolfSSL | 0:9d17e4342598 | 10267 | /* protocol version, random and session id length check */ |
wolfSSL | 0:9d17e4342598 | 10268 | if ((i - begin) + OPAQUE16_LEN + RAN_LEN + OPAQUE8_LEN > helloSz) |
wolfSSL | 0:9d17e4342598 | 10269 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 10270 | |
wolfSSL | 0:9d17e4342598 | 10271 | /* protocol version */ |
wolfSSL | 0:9d17e4342598 | 10272 | XMEMCPY(&pv, input + i, OPAQUE16_LEN); |
wolfSSL | 0:9d17e4342598 | 10273 | ssl->chVersion = pv; /* store */ |
wolfSSL | 0:9d17e4342598 | 10274 | i += OPAQUE16_LEN; |
wolfSSL | 0:9d17e4342598 | 10275 | |
wolfSSL | 0:9d17e4342598 | 10276 | if (ssl->version.minor > pv.minor) { |
wolfSSL | 0:9d17e4342598 | 10277 | byte haveRSA = 0; |
wolfSSL | 0:9d17e4342598 | 10278 | byte havePSK = 0; |
wolfSSL | 0:9d17e4342598 | 10279 | |
wolfSSL | 0:9d17e4342598 | 10280 | if (!ssl->options.downgrade) { |
wolfSSL | 0:9d17e4342598 | 10281 | CYASSL_MSG("Client trying to connect with lesser version"); |
wolfSSL | 0:9d17e4342598 | 10282 | return VERSION_ERROR; |
wolfSSL | 0:9d17e4342598 | 10283 | } |
wolfSSL | 0:9d17e4342598 | 10284 | |
wolfSSL | 0:9d17e4342598 | 10285 | if (pv.minor == SSLv3_MINOR) { |
wolfSSL | 0:9d17e4342598 | 10286 | /* turn off tls */ |
wolfSSL | 0:9d17e4342598 | 10287 | CYASSL_MSG(" downgrading to SSLv3"); |
wolfSSL | 0:9d17e4342598 | 10288 | ssl->options.tls = 0; |
wolfSSL | 0:9d17e4342598 | 10289 | ssl->options.tls1_1 = 0; |
wolfSSL | 0:9d17e4342598 | 10290 | ssl->version.minor = SSLv3_MINOR; |
wolfSSL | 0:9d17e4342598 | 10291 | } |
wolfSSL | 0:9d17e4342598 | 10292 | else if (pv.minor == TLSv1_MINOR) { |
wolfSSL | 0:9d17e4342598 | 10293 | /* turn off tls 1.1+ */ |
wolfSSL | 0:9d17e4342598 | 10294 | CYASSL_MSG(" downgrading to TLSv1"); |
wolfSSL | 0:9d17e4342598 | 10295 | ssl->options.tls1_1 = 0; |
wolfSSL | 0:9d17e4342598 | 10296 | ssl->version.minor = TLSv1_MINOR; |
wolfSSL | 0:9d17e4342598 | 10297 | } |
wolfSSL | 0:9d17e4342598 | 10298 | else if (pv.minor == TLSv1_1_MINOR) { |
wolfSSL | 0:9d17e4342598 | 10299 | CYASSL_MSG(" downgrading to TLSv1.1"); |
wolfSSL | 0:9d17e4342598 | 10300 | ssl->version.minor = TLSv1_1_MINOR; |
wolfSSL | 0:9d17e4342598 | 10301 | } |
wolfSSL | 0:9d17e4342598 | 10302 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 10303 | haveRSA = 1; |
wolfSSL | 0:9d17e4342598 | 10304 | #endif |
wolfSSL | 0:9d17e4342598 | 10305 | #ifndef NO_PSK |
wolfSSL | 0:9d17e4342598 | 10306 | havePSK = ssl->options.havePSK; |
wolfSSL | 0:9d17e4342598 | 10307 | #endif |
wolfSSL | 0:9d17e4342598 | 10308 | InitSuites(ssl->suites, ssl->version, haveRSA, havePSK, |
wolfSSL | 0:9d17e4342598 | 10309 | ssl->options.haveDH, ssl->options.haveNTRU, |
wolfSSL | 0:9d17e4342598 | 10310 | ssl->options.haveECDSAsig, ssl->options.haveStaticECC, |
wolfSSL | 0:9d17e4342598 | 10311 | ssl->options.side); |
wolfSSL | 0:9d17e4342598 | 10312 | } |
wolfSSL | 0:9d17e4342598 | 10313 | |
wolfSSL | 0:9d17e4342598 | 10314 | /* random */ |
wolfSSL | 0:9d17e4342598 | 10315 | XMEMCPY(ssl->arrays->clientRandom, input + i, RAN_LEN); |
wolfSSL | 0:9d17e4342598 | 10316 | i += RAN_LEN; |
wolfSSL | 0:9d17e4342598 | 10317 | |
wolfSSL | 0:9d17e4342598 | 10318 | #ifdef SHOW_SECRETS |
wolfSSL | 0:9d17e4342598 | 10319 | { |
wolfSSL | 0:9d17e4342598 | 10320 | int j; |
wolfSSL | 0:9d17e4342598 | 10321 | printf("client random: "); |
wolfSSL | 0:9d17e4342598 | 10322 | for (j = 0; j < RAN_LEN; j++) |
wolfSSL | 0:9d17e4342598 | 10323 | printf("%02x", ssl->arrays->clientRandom[j]); |
wolfSSL | 0:9d17e4342598 | 10324 | printf("\n"); |
wolfSSL | 0:9d17e4342598 | 10325 | } |
wolfSSL | 0:9d17e4342598 | 10326 | #endif |
wolfSSL | 0:9d17e4342598 | 10327 | |
wolfSSL | 0:9d17e4342598 | 10328 | /* session id */ |
wolfSSL | 0:9d17e4342598 | 10329 | b = input[i++]; |
wolfSSL | 0:9d17e4342598 | 10330 | |
wolfSSL | 0:9d17e4342598 | 10331 | if (b == ID_LEN) { |
wolfSSL | 0:9d17e4342598 | 10332 | if ((i - begin) + ID_LEN > helloSz) |
wolfSSL | 0:9d17e4342598 | 10333 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 10334 | |
wolfSSL | 0:9d17e4342598 | 10335 | XMEMCPY(ssl->arrays->sessionID, input + i, ID_LEN); |
wolfSSL | 0:9d17e4342598 | 10336 | i += ID_LEN; |
wolfSSL | 0:9d17e4342598 | 10337 | ssl->options.resuming = 1; /* client wants to resume */ |
wolfSSL | 0:9d17e4342598 | 10338 | CYASSL_MSG("Client wants to resume session"); |
wolfSSL | 0:9d17e4342598 | 10339 | } |
wolfSSL | 0:9d17e4342598 | 10340 | else if (b) { |
wolfSSL | 0:9d17e4342598 | 10341 | CYASSL_MSG("Invalid session ID size"); |
wolfSSL | 0:9d17e4342598 | 10342 | return BUFFER_ERROR; /* session ID nor 0 neither 32 bytes long */ |
wolfSSL | 0:9d17e4342598 | 10343 | } |
wolfSSL | 0:9d17e4342598 | 10344 | |
wolfSSL | 0:9d17e4342598 | 10345 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 10346 | /* cookie */ |
wolfSSL | 0:9d17e4342598 | 10347 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 10348 | |
wolfSSL | 0:9d17e4342598 | 10349 | if ((i - begin) + OPAQUE8_LEN > helloSz) |
wolfSSL | 0:9d17e4342598 | 10350 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 10351 | |
wolfSSL | 0:9d17e4342598 | 10352 | b = input[i++]; |
wolfSSL | 0:9d17e4342598 | 10353 | |
wolfSSL | 0:9d17e4342598 | 10354 | if (b) { |
wolfSSL | 0:9d17e4342598 | 10355 | byte cookie[MAX_COOKIE_LEN]; |
wolfSSL | 0:9d17e4342598 | 10356 | |
wolfSSL | 0:9d17e4342598 | 10357 | if (b > MAX_COOKIE_LEN) |
wolfSSL | 0:9d17e4342598 | 10358 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 10359 | |
wolfSSL | 0:9d17e4342598 | 10360 | if ((i - begin) + b > helloSz) |
wolfSSL | 0:9d17e4342598 | 10361 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 10362 | |
wolfSSL | 0:9d17e4342598 | 10363 | if (ssl->ctx->CBIOCookie == NULL) { |
wolfSSL | 0:9d17e4342598 | 10364 | CYASSL_MSG("Your Cookie callback is null, please set"); |
wolfSSL | 0:9d17e4342598 | 10365 | return COOKIE_ERROR; |
wolfSSL | 0:9d17e4342598 | 10366 | } |
wolfSSL | 0:9d17e4342598 | 10367 | |
wolfSSL | 0:9d17e4342598 | 10368 | if ((ssl->ctx->CBIOCookie(ssl, cookie, COOKIE_SZ, |
wolfSSL | 0:9d17e4342598 | 10369 | ssl->IOCB_CookieCtx) != COOKIE_SZ) |
wolfSSL | 0:9d17e4342598 | 10370 | || (b != COOKIE_SZ) |
wolfSSL | 0:9d17e4342598 | 10371 | || (XMEMCMP(cookie, input + i, b) != 0)) { |
wolfSSL | 0:9d17e4342598 | 10372 | return COOKIE_ERROR; |
wolfSSL | 0:9d17e4342598 | 10373 | } |
wolfSSL | 0:9d17e4342598 | 10374 | |
wolfSSL | 0:9d17e4342598 | 10375 | i += b; |
wolfSSL | 0:9d17e4342598 | 10376 | } |
wolfSSL | 0:9d17e4342598 | 10377 | } |
wolfSSL | 0:9d17e4342598 | 10378 | #endif |
wolfSSL | 0:9d17e4342598 | 10379 | |
wolfSSL | 0:9d17e4342598 | 10380 | /* suites */ |
wolfSSL | 0:9d17e4342598 | 10381 | if ((i - begin) + OPAQUE16_LEN > helloSz) |
wolfSSL | 0:9d17e4342598 | 10382 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 10383 | |
wolfSSL | 0:9d17e4342598 | 10384 | ato16(&input[i], &clSuites.suiteSz); |
wolfSSL | 0:9d17e4342598 | 10385 | i += OPAQUE16_LEN; |
wolfSSL | 0:9d17e4342598 | 10386 | |
wolfSSL | 0:9d17e4342598 | 10387 | /* suites and compression length check */ |
wolfSSL | 0:9d17e4342598 | 10388 | if ((i - begin) + clSuites.suiteSz + OPAQUE8_LEN > helloSz) |
wolfSSL | 0:9d17e4342598 | 10389 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 10390 | |
wolfSSL | 0:9d17e4342598 | 10391 | if (clSuites.suiteSz > MAX_SUITE_SZ) |
wolfSSL | 0:9d17e4342598 | 10392 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 10393 | |
wolfSSL | 0:9d17e4342598 | 10394 | XMEMCPY(clSuites.suites, input + i, clSuites.suiteSz); |
wolfSSL | 0:9d17e4342598 | 10395 | i += clSuites.suiteSz; |
wolfSSL | 0:9d17e4342598 | 10396 | clSuites.hashSigAlgoSz = 0; |
wolfSSL | 0:9d17e4342598 | 10397 | |
wolfSSL | 0:9d17e4342598 | 10398 | /* compression length */ |
wolfSSL | 0:9d17e4342598 | 10399 | b = input[i++]; |
wolfSSL | 0:9d17e4342598 | 10400 | |
wolfSSL | 0:9d17e4342598 | 10401 | if ((i - begin) + b > helloSz) |
wolfSSL | 0:9d17e4342598 | 10402 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 10403 | |
wolfSSL | 0:9d17e4342598 | 10404 | if (ssl->options.usingCompression) { |
wolfSSL | 0:9d17e4342598 | 10405 | int match = 0; |
wolfSSL | 0:9d17e4342598 | 10406 | |
wolfSSL | 0:9d17e4342598 | 10407 | while (b--) { |
wolfSSL | 0:9d17e4342598 | 10408 | byte comp = input[i++]; |
wolfSSL | 0:9d17e4342598 | 10409 | |
wolfSSL | 0:9d17e4342598 | 10410 | if (comp == ZLIB_COMPRESSION) |
wolfSSL | 0:9d17e4342598 | 10411 | match = 1; |
wolfSSL | 0:9d17e4342598 | 10412 | } |
wolfSSL | 0:9d17e4342598 | 10413 | |
wolfSSL | 0:9d17e4342598 | 10414 | if (!match) { |
wolfSSL | 0:9d17e4342598 | 10415 | CYASSL_MSG("Not matching compression, turning off"); |
wolfSSL | 0:9d17e4342598 | 10416 | ssl->options.usingCompression = 0; /* turn off */ |
wolfSSL | 0:9d17e4342598 | 10417 | } |
wolfSSL | 0:9d17e4342598 | 10418 | } |
wolfSSL | 0:9d17e4342598 | 10419 | else |
wolfSSL | 0:9d17e4342598 | 10420 | i += b; /* ignore, since we're not on */ |
wolfSSL | 0:9d17e4342598 | 10421 | |
wolfSSL | 0:9d17e4342598 | 10422 | *inOutIdx = i; |
wolfSSL | 0:9d17e4342598 | 10423 | |
wolfSSL | 0:9d17e4342598 | 10424 | /* tls extensions */ |
wolfSSL | 0:9d17e4342598 | 10425 | if ((i - begin) < helloSz) { |
wolfSSL | 0:9d17e4342598 | 10426 | #ifdef HAVE_TLS_EXTENSIONS |
wolfSSL | 0:9d17e4342598 | 10427 | if (IsTLS(ssl)) { |
wolfSSL | 0:9d17e4342598 | 10428 | int ret = 0; |
wolfSSL | 0:9d17e4342598 | 10429 | #else |
wolfSSL | 0:9d17e4342598 | 10430 | if (IsAtLeastTLSv1_2(ssl)) { |
wolfSSL | 0:9d17e4342598 | 10431 | #endif |
wolfSSL | 0:9d17e4342598 | 10432 | /* Process the hello extension. Skip unsupported. */ |
wolfSSL | 0:9d17e4342598 | 10433 | word16 totalExtSz; |
wolfSSL | 0:9d17e4342598 | 10434 | |
wolfSSL | 0:9d17e4342598 | 10435 | if ((i - begin) + OPAQUE16_LEN > helloSz) |
wolfSSL | 0:9d17e4342598 | 10436 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 10437 | |
wolfSSL | 0:9d17e4342598 | 10438 | ato16(&input[i], &totalExtSz); |
wolfSSL | 0:9d17e4342598 | 10439 | i += OPAQUE16_LEN; |
wolfSSL | 0:9d17e4342598 | 10440 | |
wolfSSL | 0:9d17e4342598 | 10441 | if ((i - begin) + totalExtSz > helloSz) |
wolfSSL | 0:9d17e4342598 | 10442 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 10443 | |
wolfSSL | 0:9d17e4342598 | 10444 | #ifdef HAVE_TLS_EXTENSIONS |
wolfSSL | 0:9d17e4342598 | 10445 | if ((ret = TLSX_Parse(ssl, (byte *) input + i, |
wolfSSL | 0:9d17e4342598 | 10446 | totalExtSz, 1, &clSuites))) |
wolfSSL | 0:9d17e4342598 | 10447 | return ret; |
wolfSSL | 0:9d17e4342598 | 10448 | |
wolfSSL | 0:9d17e4342598 | 10449 | i += totalExtSz; |
wolfSSL | 0:9d17e4342598 | 10450 | #else |
wolfSSL | 0:9d17e4342598 | 10451 | while (totalExtSz) { |
wolfSSL | 0:9d17e4342598 | 10452 | word16 extId, extSz; |
wolfSSL | 0:9d17e4342598 | 10453 | |
wolfSSL | 0:9d17e4342598 | 10454 | if (OPAQUE16_LEN + OPAQUE16_LEN > totalExtSz) |
wolfSSL | 0:9d17e4342598 | 10455 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 10456 | |
wolfSSL | 0:9d17e4342598 | 10457 | ato16(&input[i], &extId); |
wolfSSL | 0:9d17e4342598 | 10458 | i += OPAQUE16_LEN; |
wolfSSL | 0:9d17e4342598 | 10459 | ato16(&input[i], &extSz); |
wolfSSL | 0:9d17e4342598 | 10460 | i += OPAQUE16_LEN; |
wolfSSL | 0:9d17e4342598 | 10461 | |
wolfSSL | 0:9d17e4342598 | 10462 | if (OPAQUE16_LEN + OPAQUE16_LEN + extSz > totalExtSz) |
wolfSSL | 0:9d17e4342598 | 10463 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 10464 | |
wolfSSL | 0:9d17e4342598 | 10465 | if (extId == HELLO_EXT_SIG_ALGO) { |
wolfSSL | 0:9d17e4342598 | 10466 | ato16(&input[i], &clSuites.hashSigAlgoSz); |
wolfSSL | 0:9d17e4342598 | 10467 | i += OPAQUE16_LEN; |
wolfSSL | 0:9d17e4342598 | 10468 | |
wolfSSL | 0:9d17e4342598 | 10469 | if (OPAQUE16_LEN + clSuites.hashSigAlgoSz > extSz) |
wolfSSL | 0:9d17e4342598 | 10470 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 10471 | |
wolfSSL | 0:9d17e4342598 | 10472 | XMEMCPY(clSuites.hashSigAlgo, &input[i], |
wolfSSL | 0:9d17e4342598 | 10473 | min(clSuites.hashSigAlgoSz, HELLO_EXT_SIGALGO_MAX)); |
wolfSSL | 0:9d17e4342598 | 10474 | i += clSuites.hashSigAlgoSz; |
wolfSSL | 0:9d17e4342598 | 10475 | } |
wolfSSL | 0:9d17e4342598 | 10476 | else |
wolfSSL | 0:9d17e4342598 | 10477 | i += extSz; |
wolfSSL | 0:9d17e4342598 | 10478 | |
wolfSSL | 0:9d17e4342598 | 10479 | totalExtSz -= OPAQUE16_LEN + OPAQUE16_LEN + extSz; |
wolfSSL | 0:9d17e4342598 | 10480 | } |
wolfSSL | 0:9d17e4342598 | 10481 | #endif |
wolfSSL | 0:9d17e4342598 | 10482 | *inOutIdx = i; |
wolfSSL | 0:9d17e4342598 | 10483 | } |
wolfSSL | 0:9d17e4342598 | 10484 | else |
wolfSSL | 0:9d17e4342598 | 10485 | *inOutIdx = begin + helloSz; /* skip extensions */ |
wolfSSL | 0:9d17e4342598 | 10486 | } |
wolfSSL | 0:9d17e4342598 | 10487 | |
wolfSSL | 0:9d17e4342598 | 10488 | ssl->options.clientState = CLIENT_HELLO_COMPLETE; |
wolfSSL | 0:9d17e4342598 | 10489 | ssl->options.haveSessionId = 1; |
wolfSSL | 0:9d17e4342598 | 10490 | |
wolfSSL | 0:9d17e4342598 | 10491 | /* ProcessOld uses same resume code */ |
wolfSSL | 0:9d17e4342598 | 10492 | if (ssl->options.resuming && (!ssl->options.dtls || |
wolfSSL | 0:9d17e4342598 | 10493 | ssl->options.acceptState == HELLO_VERIFY_SENT)) { /* let's try */ |
wolfSSL | 0:9d17e4342598 | 10494 | int ret = -1; |
wolfSSL | 0:9d17e4342598 | 10495 | CYASSL_SESSION* session = GetSession(ssl,ssl->arrays->masterSecret); |
wolfSSL | 0:9d17e4342598 | 10496 | |
wolfSSL | 0:9d17e4342598 | 10497 | if (!session) { |
wolfSSL | 0:9d17e4342598 | 10498 | CYASSL_MSG("Session lookup for resume failed"); |
wolfSSL | 0:9d17e4342598 | 10499 | ssl->options.resuming = 0; |
wolfSSL | 0:9d17e4342598 | 10500 | } |
wolfSSL | 0:9d17e4342598 | 10501 | else { |
wolfSSL | 0:9d17e4342598 | 10502 | if (MatchSuite(ssl, &clSuites) < 0) { |
wolfSSL | 0:9d17e4342598 | 10503 | CYASSL_MSG("Unsupported cipher suite, ClientHello"); |
wolfSSL | 0:9d17e4342598 | 10504 | return UNSUPPORTED_SUITE; |
wolfSSL | 0:9d17e4342598 | 10505 | } |
wolfSSL | 0:9d17e4342598 | 10506 | #ifdef SESSION_CERTS |
wolfSSL | 0:9d17e4342598 | 10507 | ssl->session = *session; /* restore session certs. */ |
wolfSSL | 0:9d17e4342598 | 10508 | #endif |
wolfSSL | 0:9d17e4342598 | 10509 | RNG_GenerateBlock(ssl->rng, ssl->arrays->serverRandom, RAN_LEN); |
wolfSSL | 0:9d17e4342598 | 10510 | #ifdef NO_OLD_TLS |
wolfSSL | 0:9d17e4342598 | 10511 | ret = DeriveTlsKeys(ssl); |
wolfSSL | 0:9d17e4342598 | 10512 | #else |
wolfSSL | 0:9d17e4342598 | 10513 | #ifndef NO_TLS |
wolfSSL | 0:9d17e4342598 | 10514 | if (ssl->options.tls) |
wolfSSL | 0:9d17e4342598 | 10515 | ret = DeriveTlsKeys(ssl); |
wolfSSL | 0:9d17e4342598 | 10516 | #endif |
wolfSSL | 0:9d17e4342598 | 10517 | if (!ssl->options.tls) |
wolfSSL | 0:9d17e4342598 | 10518 | ret = DeriveKeys(ssl); |
wolfSSL | 0:9d17e4342598 | 10519 | #endif |
wolfSSL | 0:9d17e4342598 | 10520 | ssl->options.clientState = CLIENT_KEYEXCHANGE_COMPLETE; |
wolfSSL | 0:9d17e4342598 | 10521 | |
wolfSSL | 0:9d17e4342598 | 10522 | return ret; |
wolfSSL | 0:9d17e4342598 | 10523 | } |
wolfSSL | 0:9d17e4342598 | 10524 | } |
wolfSSL | 0:9d17e4342598 | 10525 | return MatchSuite(ssl, &clSuites); |
wolfSSL | 0:9d17e4342598 | 10526 | } |
wolfSSL | 0:9d17e4342598 | 10527 | |
wolfSSL | 0:9d17e4342598 | 10528 | #if !defined(NO_RSA) || defined(HAVE_ECC) |
wolfSSL | 0:9d17e4342598 | 10529 | static int DoCertificateVerify(CYASSL* ssl, byte* input, word32* inOutIdx, |
wolfSSL | 0:9d17e4342598 | 10530 | word32 size) |
wolfSSL | 0:9d17e4342598 | 10531 | { |
wolfSSL | 0:9d17e4342598 | 10532 | word16 sz = 0; |
wolfSSL | 0:9d17e4342598 | 10533 | int ret = VERIFY_CERT_ERROR; /* start in error state */ |
wolfSSL | 0:9d17e4342598 | 10534 | byte hashAlgo = sha_mac; |
wolfSSL | 0:9d17e4342598 | 10535 | byte sigAlgo = anonymous_sa_algo; |
wolfSSL | 0:9d17e4342598 | 10536 | word32 begin = *inOutIdx; |
wolfSSL | 0:9d17e4342598 | 10537 | |
wolfSSL | 0:9d17e4342598 | 10538 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 10539 | if (ssl->hsInfoOn) |
wolfSSL | 0:9d17e4342598 | 10540 | AddPacketName("CertificateVerify", &ssl->handShakeInfo); |
wolfSSL | 0:9d17e4342598 | 10541 | if (ssl->toInfoOn) |
wolfSSL | 0:9d17e4342598 | 10542 | AddLateName("CertificateVerify", &ssl->timeoutInfo); |
wolfSSL | 0:9d17e4342598 | 10543 | #endif |
wolfSSL | 0:9d17e4342598 | 10544 | |
wolfSSL | 0:9d17e4342598 | 10545 | |
wolfSSL | 0:9d17e4342598 | 10546 | if (IsAtLeastTLSv1_2(ssl)) { |
wolfSSL | 0:9d17e4342598 | 10547 | if ((*inOutIdx - begin) + ENUM_LEN + ENUM_LEN > size) |
wolfSSL | 0:9d17e4342598 | 10548 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 10549 | |
wolfSSL | 0:9d17e4342598 | 10550 | hashAlgo = input[(*inOutIdx)++]; |
wolfSSL | 0:9d17e4342598 | 10551 | sigAlgo = input[(*inOutIdx)++]; |
wolfSSL | 0:9d17e4342598 | 10552 | } |
wolfSSL | 0:9d17e4342598 | 10553 | |
wolfSSL | 0:9d17e4342598 | 10554 | if ((*inOutIdx - begin) + OPAQUE16_LEN > size) |
wolfSSL | 0:9d17e4342598 | 10555 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 10556 | |
wolfSSL | 0:9d17e4342598 | 10557 | ato16(input + *inOutIdx, &sz); |
wolfSSL | 0:9d17e4342598 | 10558 | *inOutIdx += OPAQUE16_LEN; |
wolfSSL | 0:9d17e4342598 | 10559 | |
wolfSSL | 0:9d17e4342598 | 10560 | if ((*inOutIdx - begin) + sz > size || sz > ENCRYPT_LEN) |
wolfSSL | 0:9d17e4342598 | 10561 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 10562 | |
wolfSSL | 0:9d17e4342598 | 10563 | /* RSA */ |
wolfSSL | 0:9d17e4342598 | 10564 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 10565 | if (ssl->peerRsaKeyPresent != 0) { |
wolfSSL | 0:9d17e4342598 | 10566 | byte* out = NULL; |
wolfSSL | 0:9d17e4342598 | 10567 | int outLen = 0; |
wolfSSL | 0:9d17e4342598 | 10568 | byte doUserRsa = 0; |
wolfSSL | 0:9d17e4342598 | 10569 | |
wolfSSL | 0:9d17e4342598 | 10570 | #ifdef HAVE_PK_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 10571 | if (ssl->ctx->RsaVerifyCb) |
wolfSSL | 0:9d17e4342598 | 10572 | doUserRsa = 1; |
wolfSSL | 0:9d17e4342598 | 10573 | #endif /*HAVE_PK_CALLBACKS */ |
wolfSSL | 0:9d17e4342598 | 10574 | |
wolfSSL | 0:9d17e4342598 | 10575 | CYASSL_MSG("Doing RSA peer cert verify"); |
wolfSSL | 0:9d17e4342598 | 10576 | |
wolfSSL | 0:9d17e4342598 | 10577 | if (doUserRsa) { |
wolfSSL | 0:9d17e4342598 | 10578 | #ifdef HAVE_PK_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 10579 | outLen = ssl->ctx->RsaVerifyCb(ssl, input + *inOutIdx, sz, |
wolfSSL | 0:9d17e4342598 | 10580 | &out, |
wolfSSL | 0:9d17e4342598 | 10581 | ssl->buffers.peerRsaKey.buffer, |
wolfSSL | 0:9d17e4342598 | 10582 | ssl->buffers.peerRsaKey.length, |
wolfSSL | 0:9d17e4342598 | 10583 | ssl->RsaVerifyCtx); |
wolfSSL | 0:9d17e4342598 | 10584 | #endif /*HAVE_PK_CALLBACKS */ |
wolfSSL | 0:9d17e4342598 | 10585 | } |
wolfSSL | 0:9d17e4342598 | 10586 | else { |
wolfSSL | 0:9d17e4342598 | 10587 | outLen = RsaSSL_VerifyInline(input + *inOutIdx, sz, &out, |
wolfSSL | 0:9d17e4342598 | 10588 | ssl->peerRsaKey); |
wolfSSL | 0:9d17e4342598 | 10589 | } |
wolfSSL | 0:9d17e4342598 | 10590 | |
wolfSSL | 0:9d17e4342598 | 10591 | if (IsAtLeastTLSv1_2(ssl)) { |
wolfSSL | 0:9d17e4342598 | 10592 | byte encodedSig[MAX_ENCODED_SIG_SZ]; |
wolfSSL | 0:9d17e4342598 | 10593 | word32 sigSz; |
wolfSSL | 0:9d17e4342598 | 10594 | byte* digest = ssl->certHashes.sha; |
wolfSSL | 0:9d17e4342598 | 10595 | int typeH = SHAh; |
wolfSSL | 0:9d17e4342598 | 10596 | int digestSz = SHA_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 10597 | |
wolfSSL | 0:9d17e4342598 | 10598 | if (sigAlgo != rsa_sa_algo) { |
wolfSSL | 0:9d17e4342598 | 10599 | CYASSL_MSG("Oops, peer sent RSA key but not in verify"); |
wolfSSL | 0:9d17e4342598 | 10600 | } |
wolfSSL | 0:9d17e4342598 | 10601 | |
wolfSSL | 0:9d17e4342598 | 10602 | if (hashAlgo == sha256_mac) { |
wolfSSL | 0:9d17e4342598 | 10603 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 10604 | digest = ssl->certHashes.sha256; |
wolfSSL | 0:9d17e4342598 | 10605 | typeH = SHA256h; |
wolfSSL | 0:9d17e4342598 | 10606 | digestSz = SHA256_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 10607 | #endif |
wolfSSL | 0:9d17e4342598 | 10608 | } |
wolfSSL | 0:9d17e4342598 | 10609 | else if (hashAlgo == sha384_mac) { |
wolfSSL | 0:9d17e4342598 | 10610 | #ifdef CYASSL_SHA384 |
wolfSSL | 0:9d17e4342598 | 10611 | digest = ssl->certHashes.sha384; |
wolfSSL | 0:9d17e4342598 | 10612 | typeH = SHA384h; |
wolfSSL | 0:9d17e4342598 | 10613 | digestSz = SHA384_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 10614 | #endif |
wolfSSL | 0:9d17e4342598 | 10615 | } |
wolfSSL | 0:9d17e4342598 | 10616 | |
wolfSSL | 0:9d17e4342598 | 10617 | sigSz = EncodeSignature(encodedSig, digest, digestSz, typeH); |
wolfSSL | 0:9d17e4342598 | 10618 | |
wolfSSL | 0:9d17e4342598 | 10619 | if (outLen == (int)sigSz && out && XMEMCMP(out, encodedSig, |
wolfSSL | 0:9d17e4342598 | 10620 | min(sigSz, MAX_ENCODED_SIG_SZ)) == 0) |
wolfSSL | 0:9d17e4342598 | 10621 | ret = 0; /* verified */ |
wolfSSL | 0:9d17e4342598 | 10622 | } |
wolfSSL | 0:9d17e4342598 | 10623 | else { |
wolfSSL | 0:9d17e4342598 | 10624 | if (outLen == FINISHED_SZ && out && XMEMCMP(out, |
wolfSSL | 0:9d17e4342598 | 10625 | &ssl->certHashes, FINISHED_SZ) == 0) |
wolfSSL | 0:9d17e4342598 | 10626 | ret = 0; /* verified */ |
wolfSSL | 0:9d17e4342598 | 10627 | } |
wolfSSL | 0:9d17e4342598 | 10628 | } |
wolfSSL | 0:9d17e4342598 | 10629 | #endif |
wolfSSL | 0:9d17e4342598 | 10630 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 10631 | if (ssl->peerEccDsaKeyPresent) { |
wolfSSL | 0:9d17e4342598 | 10632 | int verify = 0; |
wolfSSL | 0:9d17e4342598 | 10633 | int err = -1; |
wolfSSL | 0:9d17e4342598 | 10634 | byte* digest = ssl->certHashes.sha; |
wolfSSL | 0:9d17e4342598 | 10635 | word32 digestSz = SHA_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 10636 | byte doUserEcc = 0; |
wolfSSL | 0:9d17e4342598 | 10637 | |
wolfSSL | 0:9d17e4342598 | 10638 | #ifdef HAVE_PK_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 10639 | if (ssl->ctx->EccVerifyCb) |
wolfSSL | 0:9d17e4342598 | 10640 | doUserEcc = 1; |
wolfSSL | 0:9d17e4342598 | 10641 | #endif |
wolfSSL | 0:9d17e4342598 | 10642 | |
wolfSSL | 0:9d17e4342598 | 10643 | CYASSL_MSG("Doing ECC peer cert verify"); |
wolfSSL | 0:9d17e4342598 | 10644 | |
wolfSSL | 0:9d17e4342598 | 10645 | if (IsAtLeastTLSv1_2(ssl)) { |
wolfSSL | 0:9d17e4342598 | 10646 | if (sigAlgo != ecc_dsa_sa_algo) { |
wolfSSL | 0:9d17e4342598 | 10647 | CYASSL_MSG("Oops, peer sent ECC key but not in verify"); |
wolfSSL | 0:9d17e4342598 | 10648 | } |
wolfSSL | 0:9d17e4342598 | 10649 | |
wolfSSL | 0:9d17e4342598 | 10650 | if (hashAlgo == sha256_mac) { |
wolfSSL | 0:9d17e4342598 | 10651 | #ifndef NO_SHA256 |
wolfSSL | 0:9d17e4342598 | 10652 | digest = ssl->certHashes.sha256; |
wolfSSL | 0:9d17e4342598 | 10653 | digestSz = SHA256_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 10654 | #endif |
wolfSSL | 0:9d17e4342598 | 10655 | } |
wolfSSL | 0:9d17e4342598 | 10656 | else if (hashAlgo == sha384_mac) { |
wolfSSL | 0:9d17e4342598 | 10657 | #ifdef CYASSL_SHA384 |
wolfSSL | 0:9d17e4342598 | 10658 | digest = ssl->certHashes.sha384; |
wolfSSL | 0:9d17e4342598 | 10659 | digestSz = SHA384_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 10660 | #endif |
wolfSSL | 0:9d17e4342598 | 10661 | } |
wolfSSL | 0:9d17e4342598 | 10662 | } |
wolfSSL | 0:9d17e4342598 | 10663 | |
wolfSSL | 0:9d17e4342598 | 10664 | if (doUserEcc) { |
wolfSSL | 0:9d17e4342598 | 10665 | #ifdef HAVE_PK_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 10666 | ret = ssl->ctx->EccVerifyCb(ssl, input + *inOutIdx, sz, digest, |
wolfSSL | 0:9d17e4342598 | 10667 | digestSz, |
wolfSSL | 0:9d17e4342598 | 10668 | ssl->buffers.peerEccDsaKey.buffer, |
wolfSSL | 0:9d17e4342598 | 10669 | ssl->buffers.peerEccDsaKey.length, |
wolfSSL | 0:9d17e4342598 | 10670 | &verify, ssl->EccVerifyCtx); |
wolfSSL | 0:9d17e4342598 | 10671 | #endif |
wolfSSL | 0:9d17e4342598 | 10672 | } |
wolfSSL | 0:9d17e4342598 | 10673 | else { |
wolfSSL | 0:9d17e4342598 | 10674 | err = ecc_verify_hash(input + *inOutIdx, sz, digest, digestSz, |
wolfSSL | 0:9d17e4342598 | 10675 | &verify, ssl->peerEccDsaKey); |
wolfSSL | 0:9d17e4342598 | 10676 | } |
wolfSSL | 0:9d17e4342598 | 10677 | |
wolfSSL | 0:9d17e4342598 | 10678 | if (err == 0 && verify == 1) |
wolfSSL | 0:9d17e4342598 | 10679 | ret = 0; /* verified */ |
wolfSSL | 0:9d17e4342598 | 10680 | } |
wolfSSL | 0:9d17e4342598 | 10681 | #endif |
wolfSSL | 0:9d17e4342598 | 10682 | *inOutIdx += sz; |
wolfSSL | 0:9d17e4342598 | 10683 | |
wolfSSL | 0:9d17e4342598 | 10684 | if (ret == 0) |
wolfSSL | 0:9d17e4342598 | 10685 | ssl->options.havePeerVerify = 1; |
wolfSSL | 0:9d17e4342598 | 10686 | |
wolfSSL | 0:9d17e4342598 | 10687 | return ret; |
wolfSSL | 0:9d17e4342598 | 10688 | } |
wolfSSL | 0:9d17e4342598 | 10689 | #endif /* !NO_RSA || HAVE_ECC */ |
wolfSSL | 0:9d17e4342598 | 10690 | |
wolfSSL | 0:9d17e4342598 | 10691 | int SendServerHelloDone(CYASSL* ssl) |
wolfSSL | 0:9d17e4342598 | 10692 | { |
wolfSSL | 0:9d17e4342598 | 10693 | byte *output; |
wolfSSL | 0:9d17e4342598 | 10694 | int sendSz = RECORD_HEADER_SZ + HANDSHAKE_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 10695 | int ret; |
wolfSSL | 0:9d17e4342598 | 10696 | |
wolfSSL | 0:9d17e4342598 | 10697 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 10698 | if (ssl->options.dtls) |
wolfSSL | 0:9d17e4342598 | 10699 | sendSz += DTLS_RECORD_EXTRA + DTLS_HANDSHAKE_EXTRA; |
wolfSSL | 0:9d17e4342598 | 10700 | #endif |
wolfSSL | 0:9d17e4342598 | 10701 | /* check for available size */ |
wolfSSL | 0:9d17e4342598 | 10702 | if ((ret = CheckAvailableSize(ssl, sendSz)) != 0) |
wolfSSL | 0:9d17e4342598 | 10703 | return ret; |
wolfSSL | 0:9d17e4342598 | 10704 | |
wolfSSL | 0:9d17e4342598 | 10705 | /* get ouput buffer */ |
wolfSSL | 0:9d17e4342598 | 10706 | output = ssl->buffers.outputBuffer.buffer + |
wolfSSL | 0:9d17e4342598 | 10707 | ssl->buffers.outputBuffer.length; |
wolfSSL | 0:9d17e4342598 | 10708 | |
wolfSSL | 0:9d17e4342598 | 10709 | AddHeaders(output, 0, server_hello_done, ssl); |
wolfSSL | 0:9d17e4342598 | 10710 | |
wolfSSL | 0:9d17e4342598 | 10711 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 10712 | if (ssl->options.dtls) { |
wolfSSL | 0:9d17e4342598 | 10713 | if ((ret = DtlsPoolSave(ssl, output, sendSz)) != 0) |
wolfSSL | 0:9d17e4342598 | 10714 | return 0; |
wolfSSL | 0:9d17e4342598 | 10715 | } |
wolfSSL | 0:9d17e4342598 | 10716 | #endif |
wolfSSL | 0:9d17e4342598 | 10717 | HashOutput(ssl, output, sendSz, 0); |
wolfSSL | 0:9d17e4342598 | 10718 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 10719 | if (ssl->hsInfoOn) |
wolfSSL | 0:9d17e4342598 | 10720 | AddPacketName("ServerHelloDone", &ssl->handShakeInfo); |
wolfSSL | 0:9d17e4342598 | 10721 | if (ssl->toInfoOn) |
wolfSSL | 0:9d17e4342598 | 10722 | AddPacketInfo("ServerHelloDone", &ssl->timeoutInfo, output, sendSz, |
wolfSSL | 0:9d17e4342598 | 10723 | ssl->heap); |
wolfSSL | 0:9d17e4342598 | 10724 | #endif |
wolfSSL | 0:9d17e4342598 | 10725 | ssl->options.serverState = SERVER_HELLODONE_COMPLETE; |
wolfSSL | 0:9d17e4342598 | 10726 | |
wolfSSL | 0:9d17e4342598 | 10727 | ssl->buffers.outputBuffer.length += sendSz; |
wolfSSL | 0:9d17e4342598 | 10728 | |
wolfSSL | 0:9d17e4342598 | 10729 | return SendBuffered(ssl); |
wolfSSL | 0:9d17e4342598 | 10730 | } |
wolfSSL | 0:9d17e4342598 | 10731 | |
wolfSSL | 0:9d17e4342598 | 10732 | #ifdef CYASSL_DTLS |
wolfSSL | 0:9d17e4342598 | 10733 | int SendHelloVerifyRequest(CYASSL* ssl) |
wolfSSL | 0:9d17e4342598 | 10734 | { |
wolfSSL | 0:9d17e4342598 | 10735 | byte* output; |
wolfSSL | 0:9d17e4342598 | 10736 | byte cookieSz = COOKIE_SZ; |
wolfSSL | 0:9d17e4342598 | 10737 | int length = VERSION_SZ + ENUM_LEN + cookieSz; |
wolfSSL | 0:9d17e4342598 | 10738 | int idx = DTLS_RECORD_HEADER_SZ + DTLS_HANDSHAKE_HEADER_SZ; |
wolfSSL | 0:9d17e4342598 | 10739 | int sendSz = length + idx; |
wolfSSL | 0:9d17e4342598 | 10740 | int ret; |
wolfSSL | 0:9d17e4342598 | 10741 | |
wolfSSL | 0:9d17e4342598 | 10742 | /* check for available size */ |
wolfSSL | 0:9d17e4342598 | 10743 | if ((ret = CheckAvailableSize(ssl, sendSz)) != 0) |
wolfSSL | 0:9d17e4342598 | 10744 | return ret; |
wolfSSL | 0:9d17e4342598 | 10745 | |
wolfSSL | 0:9d17e4342598 | 10746 | /* get ouput buffer */ |
wolfSSL | 0:9d17e4342598 | 10747 | output = ssl->buffers.outputBuffer.buffer + |
wolfSSL | 0:9d17e4342598 | 10748 | ssl->buffers.outputBuffer.length; |
wolfSSL | 0:9d17e4342598 | 10749 | |
wolfSSL | 0:9d17e4342598 | 10750 | AddHeaders(output, length, hello_verify_request, ssl); |
wolfSSL | 0:9d17e4342598 | 10751 | |
wolfSSL | 0:9d17e4342598 | 10752 | output[idx++] = ssl->chVersion.major; |
wolfSSL | 0:9d17e4342598 | 10753 | output[idx++] = ssl->chVersion.minor; |
wolfSSL | 0:9d17e4342598 | 10754 | |
wolfSSL | 0:9d17e4342598 | 10755 | output[idx++] = cookieSz; |
wolfSSL | 0:9d17e4342598 | 10756 | if (ssl->ctx->CBIOCookie == NULL) { |
wolfSSL | 0:9d17e4342598 | 10757 | CYASSL_MSG("Your Cookie callback is null, please set"); |
wolfSSL | 0:9d17e4342598 | 10758 | return COOKIE_ERROR; |
wolfSSL | 0:9d17e4342598 | 10759 | } |
wolfSSL | 0:9d17e4342598 | 10760 | if ((ret = ssl->ctx->CBIOCookie(ssl, output + idx, cookieSz, |
wolfSSL | 0:9d17e4342598 | 10761 | ssl->IOCB_CookieCtx)) < 0) |
wolfSSL | 0:9d17e4342598 | 10762 | return ret; |
wolfSSL | 0:9d17e4342598 | 10763 | |
wolfSSL | 0:9d17e4342598 | 10764 | HashOutput(ssl, output, sendSz, 0); |
wolfSSL | 0:9d17e4342598 | 10765 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 10766 | if (ssl->hsInfoOn) |
wolfSSL | 0:9d17e4342598 | 10767 | AddPacketName("HelloVerifyRequest", &ssl->handShakeInfo); |
wolfSSL | 0:9d17e4342598 | 10768 | if (ssl->toInfoOn) |
wolfSSL | 0:9d17e4342598 | 10769 | AddPacketInfo("HelloVerifyRequest", &ssl->timeoutInfo, output, |
wolfSSL | 0:9d17e4342598 | 10770 | sendSz, ssl->heap); |
wolfSSL | 0:9d17e4342598 | 10771 | #endif |
wolfSSL | 0:9d17e4342598 | 10772 | ssl->options.serverState = SERVER_HELLOVERIFYREQUEST_COMPLETE; |
wolfSSL | 0:9d17e4342598 | 10773 | |
wolfSSL | 0:9d17e4342598 | 10774 | ssl->buffers.outputBuffer.length += sendSz; |
wolfSSL | 0:9d17e4342598 | 10775 | |
wolfSSL | 0:9d17e4342598 | 10776 | return SendBuffered(ssl); |
wolfSSL | 0:9d17e4342598 | 10777 | } |
wolfSSL | 0:9d17e4342598 | 10778 | #endif |
wolfSSL | 0:9d17e4342598 | 10779 | |
wolfSSL | 0:9d17e4342598 | 10780 | static int DoClientKeyExchange(CYASSL* ssl, byte* input, word32* inOutIdx, |
wolfSSL | 0:9d17e4342598 | 10781 | word32 size) |
wolfSSL | 0:9d17e4342598 | 10782 | { |
wolfSSL | 0:9d17e4342598 | 10783 | int ret = 0; |
wolfSSL | 0:9d17e4342598 | 10784 | word32 length = 0; |
wolfSSL | 0:9d17e4342598 | 10785 | byte* out = NULL; |
wolfSSL | 0:9d17e4342598 | 10786 | word32 begin = *inOutIdx; |
wolfSSL | 0:9d17e4342598 | 10787 | |
wolfSSL | 0:9d17e4342598 | 10788 | (void)length; /* shut up compiler warnings */ |
wolfSSL | 0:9d17e4342598 | 10789 | (void)out; |
wolfSSL | 0:9d17e4342598 | 10790 | (void)input; |
wolfSSL | 0:9d17e4342598 | 10791 | (void)size; |
wolfSSL | 0:9d17e4342598 | 10792 | |
wolfSSL | 0:9d17e4342598 | 10793 | if (ssl->options.side != CYASSL_SERVER_END) { |
wolfSSL | 0:9d17e4342598 | 10794 | CYASSL_MSG("Client received client keyexchange, attack?"); |
wolfSSL | 0:9d17e4342598 | 10795 | CYASSL_ERROR(ssl->error = SIDE_ERROR); |
wolfSSL | 0:9d17e4342598 | 10796 | return SSL_FATAL_ERROR; |
wolfSSL | 0:9d17e4342598 | 10797 | } |
wolfSSL | 0:9d17e4342598 | 10798 | |
wolfSSL | 0:9d17e4342598 | 10799 | if (ssl->options.clientState < CLIENT_HELLO_COMPLETE) { |
wolfSSL | 0:9d17e4342598 | 10800 | CYASSL_MSG("Client sending keyexchange at wrong time"); |
wolfSSL | 0:9d17e4342598 | 10801 | SendAlert(ssl, alert_fatal, unexpected_message); |
wolfSSL | 0:9d17e4342598 | 10802 | return OUT_OF_ORDER_E; |
wolfSSL | 0:9d17e4342598 | 10803 | } |
wolfSSL | 0:9d17e4342598 | 10804 | |
wolfSSL | 0:9d17e4342598 | 10805 | #ifndef NO_CERTS |
wolfSSL | 0:9d17e4342598 | 10806 | if (ssl->options.verifyPeer && ssl->options.failNoCert) |
wolfSSL | 0:9d17e4342598 | 10807 | if (!ssl->options.havePeerCert) { |
wolfSSL | 0:9d17e4342598 | 10808 | CYASSL_MSG("client didn't present peer cert"); |
wolfSSL | 0:9d17e4342598 | 10809 | return NO_PEER_CERT; |
wolfSSL | 0:9d17e4342598 | 10810 | } |
wolfSSL | 0:9d17e4342598 | 10811 | #endif |
wolfSSL | 0:9d17e4342598 | 10812 | |
wolfSSL | 0:9d17e4342598 | 10813 | #ifdef CYASSL_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 10814 | if (ssl->hsInfoOn) |
wolfSSL | 0:9d17e4342598 | 10815 | AddPacketName("ClientKeyExchange", &ssl->handShakeInfo); |
wolfSSL | 0:9d17e4342598 | 10816 | if (ssl->toInfoOn) |
wolfSSL | 0:9d17e4342598 | 10817 | AddLateName("ClientKeyExchange", &ssl->timeoutInfo); |
wolfSSL | 0:9d17e4342598 | 10818 | #endif |
wolfSSL | 0:9d17e4342598 | 10819 | |
wolfSSL | 0:9d17e4342598 | 10820 | switch (ssl->specs.kea) { |
wolfSSL | 0:9d17e4342598 | 10821 | #ifndef NO_RSA |
wolfSSL | 0:9d17e4342598 | 10822 | case rsa_kea: |
wolfSSL | 0:9d17e4342598 | 10823 | { |
wolfSSL | 0:9d17e4342598 | 10824 | word32 idx = 0; |
wolfSSL | 0:9d17e4342598 | 10825 | RsaKey key; |
wolfSSL | 0:9d17e4342598 | 10826 | byte doUserRsa = 0; |
wolfSSL | 0:9d17e4342598 | 10827 | |
wolfSSL | 0:9d17e4342598 | 10828 | #ifdef HAVE_PK_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 10829 | if (ssl->ctx->RsaDecCb) |
wolfSSL | 0:9d17e4342598 | 10830 | doUserRsa = 1; |
wolfSSL | 0:9d17e4342598 | 10831 | #endif |
wolfSSL | 0:9d17e4342598 | 10832 | |
wolfSSL | 0:9d17e4342598 | 10833 | ret = InitRsaKey(&key, ssl->heap); |
wolfSSL | 0:9d17e4342598 | 10834 | if (ret != 0) return ret; |
wolfSSL | 0:9d17e4342598 | 10835 | |
wolfSSL | 0:9d17e4342598 | 10836 | if (ssl->buffers.key.buffer) |
wolfSSL | 0:9d17e4342598 | 10837 | ret = RsaPrivateKeyDecode(ssl->buffers.key.buffer, &idx, |
wolfSSL | 0:9d17e4342598 | 10838 | &key, ssl->buffers.key.length); |
wolfSSL | 0:9d17e4342598 | 10839 | else |
wolfSSL | 0:9d17e4342598 | 10840 | return NO_PRIVATE_KEY; |
wolfSSL | 0:9d17e4342598 | 10841 | |
wolfSSL | 0:9d17e4342598 | 10842 | if (ret == 0) { |
wolfSSL | 0:9d17e4342598 | 10843 | length = RsaEncryptSize(&key); |
wolfSSL | 0:9d17e4342598 | 10844 | ssl->arrays->preMasterSz = SECRET_LEN; |
wolfSSL | 0:9d17e4342598 | 10845 | |
wolfSSL | 0:9d17e4342598 | 10846 | if (ssl->options.tls) { |
wolfSSL | 0:9d17e4342598 | 10847 | word16 check; |
wolfSSL | 0:9d17e4342598 | 10848 | |
wolfSSL | 0:9d17e4342598 | 10849 | if ((*inOutIdx - begin) + OPAQUE16_LEN > size) |
wolfSSL | 0:9d17e4342598 | 10850 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 10851 | |
wolfSSL | 0:9d17e4342598 | 10852 | ato16(input + *inOutIdx, &check); |
wolfSSL | 0:9d17e4342598 | 10853 | *inOutIdx += OPAQUE16_LEN; |
wolfSSL | 0:9d17e4342598 | 10854 | |
wolfSSL | 0:9d17e4342598 | 10855 | if ((word32) check != length) { |
wolfSSL | 0:9d17e4342598 | 10856 | CYASSL_MSG("RSA explicit size doesn't match"); |
wolfSSL | 0:9d17e4342598 | 10857 | FreeRsaKey(&key); |
wolfSSL | 0:9d17e4342598 | 10858 | return RSA_PRIVATE_ERROR; |
wolfSSL | 0:9d17e4342598 | 10859 | } |
wolfSSL | 0:9d17e4342598 | 10860 | } |
wolfSSL | 0:9d17e4342598 | 10861 | |
wolfSSL | 0:9d17e4342598 | 10862 | if ((*inOutIdx - begin) + length > size) { |
wolfSSL | 0:9d17e4342598 | 10863 | CYASSL_MSG("RSA message too big"); |
wolfSSL | 0:9d17e4342598 | 10864 | FreeRsaKey(&key); |
wolfSSL | 0:9d17e4342598 | 10865 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 10866 | } |
wolfSSL | 0:9d17e4342598 | 10867 | |
wolfSSL | 0:9d17e4342598 | 10868 | if (doUserRsa) { |
wolfSSL | 0:9d17e4342598 | 10869 | #ifdef HAVE_PK_CALLBACKS |
wolfSSL | 0:9d17e4342598 | 10870 | ret = ssl->ctx->RsaDecCb(ssl, |
wolfSSL | 0:9d17e4342598 | 10871 | input + *inOutIdx, length, &out, |
wolfSSL | 0:9d17e4342598 | 10872 | ssl->buffers.key.buffer, |
wolfSSL | 0:9d17e4342598 | 10873 | ssl->buffers.key.length, |
wolfSSL | 0:9d17e4342598 | 10874 | ssl->RsaDecCtx); |
wolfSSL | 0:9d17e4342598 | 10875 | #endif |
wolfSSL | 0:9d17e4342598 | 10876 | } |
wolfSSL | 0:9d17e4342598 | 10877 | else { |
wolfSSL | 0:9d17e4342598 | 10878 | ret = RsaPrivateDecryptInline(input + *inOutIdx, length, |
wolfSSL | 0:9d17e4342598 | 10879 | &out, &key); |
wolfSSL | 0:9d17e4342598 | 10880 | } |
wolfSSL | 0:9d17e4342598 | 10881 | |
wolfSSL | 0:9d17e4342598 | 10882 | *inOutIdx += length; |
wolfSSL | 0:9d17e4342598 | 10883 | |
wolfSSL | 0:9d17e4342598 | 10884 | if (ret == SECRET_LEN) { |
wolfSSL | 0:9d17e4342598 | 10885 | XMEMCPY(ssl->arrays->preMasterSecret, out, SECRET_LEN); |
wolfSSL | 0:9d17e4342598 | 10886 | if (ssl->arrays->preMasterSecret[0] != |
wolfSSL | 0:9d17e4342598 | 10887 | ssl->chVersion.major |
wolfSSL | 0:9d17e4342598 | 10888 | || ssl->arrays->preMasterSecret[1] != |
wolfSSL | 0:9d17e4342598 | 10889 | ssl->chVersion.minor) |
wolfSSL | 0:9d17e4342598 | 10890 | ret = PMS_VERSION_ERROR; |
wolfSSL | 0:9d17e4342598 | 10891 | else |
wolfSSL | 0:9d17e4342598 | 10892 | ret = MakeMasterSecret(ssl); |
wolfSSL | 0:9d17e4342598 | 10893 | } |
wolfSSL | 0:9d17e4342598 | 10894 | else { |
wolfSSL | 0:9d17e4342598 | 10895 | ret = RSA_PRIVATE_ERROR; |
wolfSSL | 0:9d17e4342598 | 10896 | } |
wolfSSL | 0:9d17e4342598 | 10897 | } |
wolfSSL | 0:9d17e4342598 | 10898 | |
wolfSSL | 0:9d17e4342598 | 10899 | FreeRsaKey(&key); |
wolfSSL | 0:9d17e4342598 | 10900 | } |
wolfSSL | 0:9d17e4342598 | 10901 | break; |
wolfSSL | 0:9d17e4342598 | 10902 | #endif |
wolfSSL | 0:9d17e4342598 | 10903 | #ifndef NO_PSK |
wolfSSL | 0:9d17e4342598 | 10904 | case psk_kea: |
wolfSSL | 0:9d17e4342598 | 10905 | { |
wolfSSL | 0:9d17e4342598 | 10906 | byte* pms = ssl->arrays->preMasterSecret; |
wolfSSL | 0:9d17e4342598 | 10907 | word16 ci_sz; |
wolfSSL | 0:9d17e4342598 | 10908 | |
wolfSSL | 0:9d17e4342598 | 10909 | if ((*inOutIdx - begin) + OPAQUE16_LEN > size) |
wolfSSL | 0:9d17e4342598 | 10910 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 10911 | |
wolfSSL | 0:9d17e4342598 | 10912 | ato16(input + *inOutIdx, &ci_sz); |
wolfSSL | 0:9d17e4342598 | 10913 | *inOutIdx += OPAQUE16_LEN; |
wolfSSL | 0:9d17e4342598 | 10914 | |
wolfSSL | 0:9d17e4342598 | 10915 | if (ci_sz > MAX_PSK_ID_LEN) |
wolfSSL | 0:9d17e4342598 | 10916 | return CLIENT_ID_ERROR; |
wolfSSL | 0:9d17e4342598 | 10917 | |
wolfSSL | 0:9d17e4342598 | 10918 | if ((*inOutIdx - begin) + ci_sz > size) |
wolfSSL | 0:9d17e4342598 | 10919 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 10920 | |
wolfSSL | 0:9d17e4342598 | 10921 | XMEMCPY(ssl->arrays->client_identity, input + *inOutIdx, ci_sz); |
wolfSSL | 0:9d17e4342598 | 10922 | *inOutIdx += ci_sz; |
wolfSSL | 0:9d17e4342598 | 10923 | |
wolfSSL | 0:9d17e4342598 | 10924 | ssl->arrays->client_identity[min(ci_sz, MAX_PSK_ID_LEN-1)] = 0; |
wolfSSL | 0:9d17e4342598 | 10925 | ssl->arrays->psk_keySz = ssl->options.server_psk_cb(ssl, |
wolfSSL | 0:9d17e4342598 | 10926 | ssl->arrays->client_identity, ssl->arrays->psk_key, |
wolfSSL | 0:9d17e4342598 | 10927 | MAX_PSK_KEY_LEN); |
wolfSSL | 0:9d17e4342598 | 10928 | |
wolfSSL | 0:9d17e4342598 | 10929 | if (ssl->arrays->psk_keySz == 0 || |
wolfSSL | 0:9d17e4342598 | 10930 | ssl->arrays->psk_keySz > MAX_PSK_KEY_LEN) |
wolfSSL | 0:9d17e4342598 | 10931 | return PSK_KEY_ERROR; |
wolfSSL | 0:9d17e4342598 | 10932 | |
wolfSSL | 0:9d17e4342598 | 10933 | /* make psk pre master secret */ |
wolfSSL | 0:9d17e4342598 | 10934 | /* length of key + length 0s + length of key + key */ |
wolfSSL | 0:9d17e4342598 | 10935 | c16toa((word16) ssl->arrays->psk_keySz, pms); |
wolfSSL | 0:9d17e4342598 | 10936 | pms += OPAQUE16_LEN; |
wolfSSL | 0:9d17e4342598 | 10937 | |
wolfSSL | 0:9d17e4342598 | 10938 | XMEMSET(pms, 0, ssl->arrays->psk_keySz); |
wolfSSL | 0:9d17e4342598 | 10939 | pms += ssl->arrays->psk_keySz; |
wolfSSL | 0:9d17e4342598 | 10940 | |
wolfSSL | 0:9d17e4342598 | 10941 | c16toa((word16) ssl->arrays->psk_keySz, pms); |
wolfSSL | 0:9d17e4342598 | 10942 | pms += OPAQUE16_LEN; |
wolfSSL | 0:9d17e4342598 | 10943 | |
wolfSSL | 0:9d17e4342598 | 10944 | XMEMCPY(pms, ssl->arrays->psk_key, ssl->arrays->psk_keySz); |
wolfSSL | 0:9d17e4342598 | 10945 | ssl->arrays->preMasterSz = ssl->arrays->psk_keySz * 2 + 4; |
wolfSSL | 0:9d17e4342598 | 10946 | |
wolfSSL | 0:9d17e4342598 | 10947 | ret = MakeMasterSecret(ssl); |
wolfSSL | 0:9d17e4342598 | 10948 | |
wolfSSL | 0:9d17e4342598 | 10949 | /* No further need for PSK */ |
wolfSSL | 0:9d17e4342598 | 10950 | XMEMSET(ssl->arrays->psk_key, 0, ssl->arrays->psk_keySz); |
wolfSSL | 0:9d17e4342598 | 10951 | ssl->arrays->psk_keySz = 0; |
wolfSSL | 0:9d17e4342598 | 10952 | } |
wolfSSL | 0:9d17e4342598 | 10953 | break; |
wolfSSL | 0:9d17e4342598 | 10954 | #endif /* NO_PSK */ |
wolfSSL | 0:9d17e4342598 | 10955 | #ifdef HAVE_NTRU |
wolfSSL | 0:9d17e4342598 | 10956 | case ntru_kea: |
wolfSSL | 0:9d17e4342598 | 10957 | { |
wolfSSL | 0:9d17e4342598 | 10958 | word16 cipherLen; |
wolfSSL | 0:9d17e4342598 | 10959 | word16 plainLen = sizeof(ssl->arrays->preMasterSecret); |
wolfSSL | 0:9d17e4342598 | 10960 | |
wolfSSL | 0:9d17e4342598 | 10961 | if (!ssl->buffers.key.buffer) |
wolfSSL | 0:9d17e4342598 | 10962 | return NO_PRIVATE_KEY; |
wolfSSL | 0:9d17e4342598 | 10963 | |
wolfSSL | 0:9d17e4342598 | 10964 | if ((*inOutIdx - begin) + OPAQUE16_LEN > size) |
wolfSSL | 0:9d17e4342598 | 10965 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 10966 | |
wolfSSL | 0:9d17e4342598 | 10967 | ato16(input + *inOutIdx, &cipherLen); |
wolfSSL | 0:9d17e4342598 | 10968 | *inOutIdx += OPAQUE16_LEN; |
wolfSSL | 0:9d17e4342598 | 10969 | |
wolfSSL | 0:9d17e4342598 | 10970 | if (cipherLen > MAX_NTRU_ENCRYPT_SZ) |
wolfSSL | 0:9d17e4342598 | 10971 | return NTRU_KEY_ERROR; |
wolfSSL | 0:9d17e4342598 | 10972 | |
wolfSSL | 0:9d17e4342598 | 10973 | if ((*inOutIdx - begin) + cipherLen > size) |
wolfSSL | 0:9d17e4342598 | 10974 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 10975 | |
wolfSSL | 0:9d17e4342598 | 10976 | if (NTRU_OK != crypto_ntru_decrypt( |
wolfSSL | 0:9d17e4342598 | 10977 | (word16) ssl->buffers.key.length, |
wolfSSL | 0:9d17e4342598 | 10978 | ssl->buffers.key.buffer, cipherLen, |
wolfSSL | 0:9d17e4342598 | 10979 | input + *inOutIdx, &plainLen, |
wolfSSL | 0:9d17e4342598 | 10980 | ssl->arrays->preMasterSecret)) |
wolfSSL | 0:9d17e4342598 | 10981 | return NTRU_DECRYPT_ERROR; |
wolfSSL | 0:9d17e4342598 | 10982 | |
wolfSSL | 0:9d17e4342598 | 10983 | if (plainLen != SECRET_LEN) |
wolfSSL | 0:9d17e4342598 | 10984 | return NTRU_DECRYPT_ERROR; |
wolfSSL | 0:9d17e4342598 | 10985 | |
wolfSSL | 0:9d17e4342598 | 10986 | *inOutIdx += cipherLen; |
wolfSSL | 0:9d17e4342598 | 10987 | |
wolfSSL | 0:9d17e4342598 | 10988 | ssl->arrays->preMasterSz = plainLen; |
wolfSSL | 0:9d17e4342598 | 10989 | ret = MakeMasterSecret(ssl); |
wolfSSL | 0:9d17e4342598 | 10990 | } |
wolfSSL | 0:9d17e4342598 | 10991 | break; |
wolfSSL | 0:9d17e4342598 | 10992 | #endif /* HAVE_NTRU */ |
wolfSSL | 0:9d17e4342598 | 10993 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 10994 | case ecc_diffie_hellman_kea: |
wolfSSL | 0:9d17e4342598 | 10995 | { |
wolfSSL | 0:9d17e4342598 | 10996 | if ((*inOutIdx - begin) + OPAQUE8_LEN > size) |
wolfSSL | 0:9d17e4342598 | 10997 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 10998 | |
wolfSSL | 0:9d17e4342598 | 10999 | length = input[(*inOutIdx)++]; |
wolfSSL | 0:9d17e4342598 | 11000 | |
wolfSSL | 0:9d17e4342598 | 11001 | if ((*inOutIdx - begin) + length > size) |
wolfSSL | 0:9d17e4342598 | 11002 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 11003 | |
wolfSSL | 0:9d17e4342598 | 11004 | if (ecc_import_x963(input + *inOutIdx, length, ssl->peerEccKey)) |
wolfSSL | 0:9d17e4342598 | 11005 | return ECC_PEERKEY_ERROR; |
wolfSSL | 0:9d17e4342598 | 11006 | |
wolfSSL | 0:9d17e4342598 | 11007 | *inOutIdx += length; |
wolfSSL | 0:9d17e4342598 | 11008 | ssl->peerEccKeyPresent = 1; |
wolfSSL | 0:9d17e4342598 | 11009 | |
wolfSSL | 0:9d17e4342598 | 11010 | length = sizeof(ssl->arrays->preMasterSecret); |
wolfSSL | 0:9d17e4342598 | 11011 | |
wolfSSL | 0:9d17e4342598 | 11012 | if (ssl->specs.static_ecdh) { |
wolfSSL | 0:9d17e4342598 | 11013 | ecc_key staticKey; |
wolfSSL | 0:9d17e4342598 | 11014 | word32 i = 0; |
wolfSSL | 0:9d17e4342598 | 11015 | |
wolfSSL | 0:9d17e4342598 | 11016 | ecc_init(&staticKey); |
wolfSSL | 0:9d17e4342598 | 11017 | ret = EccPrivateKeyDecode(ssl->buffers.key.buffer, &i, |
wolfSSL | 0:9d17e4342598 | 11018 | &staticKey, ssl->buffers.key.length); |
wolfSSL | 0:9d17e4342598 | 11019 | |
wolfSSL | 0:9d17e4342598 | 11020 | if (ret == 0) |
wolfSSL | 0:9d17e4342598 | 11021 | ret = ecc_shared_secret(&staticKey, ssl->peerEccKey, |
wolfSSL | 0:9d17e4342598 | 11022 | ssl->arrays->preMasterSecret, &length); |
wolfSSL | 0:9d17e4342598 | 11023 | |
wolfSSL | 0:9d17e4342598 | 11024 | ecc_free(&staticKey); |
wolfSSL | 0:9d17e4342598 | 11025 | } |
wolfSSL | 0:9d17e4342598 | 11026 | else |
wolfSSL | 0:9d17e4342598 | 11027 | ret = ecc_shared_secret(ssl->eccTempKey, ssl->peerEccKey, |
wolfSSL | 0:9d17e4342598 | 11028 | ssl->arrays->preMasterSecret, &length); |
wolfSSL | 0:9d17e4342598 | 11029 | |
wolfSSL | 0:9d17e4342598 | 11030 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 11031 | return ECC_SHARED_ERROR; |
wolfSSL | 0:9d17e4342598 | 11032 | |
wolfSSL | 0:9d17e4342598 | 11033 | ssl->arrays->preMasterSz = length; |
wolfSSL | 0:9d17e4342598 | 11034 | ret = MakeMasterSecret(ssl); |
wolfSSL | 0:9d17e4342598 | 11035 | } |
wolfSSL | 0:9d17e4342598 | 11036 | break; |
wolfSSL | 0:9d17e4342598 | 11037 | #endif /* HAVE_ECC */ |
wolfSSL | 0:9d17e4342598 | 11038 | #ifdef OPENSSL_EXTRA |
wolfSSL | 0:9d17e4342598 | 11039 | case diffie_hellman_kea: |
wolfSSL | 0:9d17e4342598 | 11040 | { |
wolfSSL | 0:9d17e4342598 | 11041 | word16 clientPubSz; |
wolfSSL | 0:9d17e4342598 | 11042 | DhKey dhKey; |
wolfSSL | 0:9d17e4342598 | 11043 | |
wolfSSL | 0:9d17e4342598 | 11044 | if ((*inOutIdx - begin) + OPAQUE16_LEN > size) |
wolfSSL | 0:9d17e4342598 | 11045 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 11046 | |
wolfSSL | 0:9d17e4342598 | 11047 | ato16(input + *inOutIdx, &clientPubSz); |
wolfSSL | 0:9d17e4342598 | 11048 | *inOutIdx += OPAQUE16_LEN; |
wolfSSL | 0:9d17e4342598 | 11049 | |
wolfSSL | 0:9d17e4342598 | 11050 | if ((*inOutIdx - begin) + clientPubSz > size) |
wolfSSL | 0:9d17e4342598 | 11051 | return BUFFER_ERROR; |
wolfSSL | 0:9d17e4342598 | 11052 | |
wolfSSL | 0:9d17e4342598 | 11053 | InitDhKey(&dhKey); |
wolfSSL | 0:9d17e4342598 | 11054 | ret = DhSetKey(&dhKey, ssl->buffers.serverDH_P.buffer, |
wolfSSL | 0:9d17e4342598 | 11055 | ssl->buffers.serverDH_P.length, |
wolfSSL | 0:9d17e4342598 | 11056 | ssl->buffers.serverDH_G.buffer, |
wolfSSL | 0:9d17e4342598 | 11057 | ssl->buffers.serverDH_G.length); |
wolfSSL | 0:9d17e4342598 | 11058 | if (ret == 0) |
wolfSSL | 0:9d17e4342598 | 11059 | ret = DhAgree(&dhKey, ssl->arrays->preMasterSecret, |
wolfSSL | 0:9d17e4342598 | 11060 | &ssl->arrays->preMasterSz, |
wolfSSL | 0:9d17e4342598 | 11061 | ssl->buffers.serverDH_Priv.buffer, |
wolfSSL | 0:9d17e4342598 | 11062 | ssl->buffers.serverDH_Priv.length, |
wolfSSL | 0:9d17e4342598 | 11063 | input + *inOutIdx, clientPubSz); |
wolfSSL | 0:9d17e4342598 | 11064 | FreeDhKey(&dhKey); |
wolfSSL | 0:9d17e4342598 | 11065 | |
wolfSSL | 0:9d17e4342598 | 11066 | *inOutIdx += clientPubSz; |
wolfSSL | 0:9d17e4342598 | 11067 | |
wolfSSL | 0:9d17e4342598 | 11068 | if (ret == 0) |
wolfSSL | 0:9d17e4342598 | 11069 | ret = MakeMasterSecret(ssl); |
wolfSSL | 0:9d17e4342598 | 11070 | } |
wolfSSL | 0:9d17e4342598 | 11071 | break; |
wolfSSL | 0:9d17e4342598 | 11072 | #endif /* OPENSSL_EXTRA */ |
wolfSSL | 0:9d17e4342598 | 11073 | default: |
wolfSSL | 0:9d17e4342598 | 11074 | { |
wolfSSL | 0:9d17e4342598 | 11075 | CYASSL_MSG("Bad kea type"); |
wolfSSL | 0:9d17e4342598 | 11076 | ret = BAD_KEA_TYPE_E; |
wolfSSL | 0:9d17e4342598 | 11077 | } |
wolfSSL | 0:9d17e4342598 | 11078 | break; |
wolfSSL | 0:9d17e4342598 | 11079 | } |
wolfSSL | 0:9d17e4342598 | 11080 | |
wolfSSL | 0:9d17e4342598 | 11081 | /* No further need for PMS */ |
wolfSSL | 0:9d17e4342598 | 11082 | XMEMSET(ssl->arrays->preMasterSecret, 0, ssl->arrays->preMasterSz); |
wolfSSL | 0:9d17e4342598 | 11083 | ssl->arrays->preMasterSz = 0; |
wolfSSL | 0:9d17e4342598 | 11084 | |
wolfSSL | 0:9d17e4342598 | 11085 | if (ret == 0) { |
wolfSSL | 0:9d17e4342598 | 11086 | ssl->options.clientState = CLIENT_KEYEXCHANGE_COMPLETE; |
wolfSSL | 0:9d17e4342598 | 11087 | #ifndef NO_CERTS |
wolfSSL | 0:9d17e4342598 | 11088 | if (ssl->options.verifyPeer) |
wolfSSL | 0:9d17e4342598 | 11089 | BuildCertHashes(ssl, &ssl->certHashes); |
wolfSSL | 0:9d17e4342598 | 11090 | #endif |
wolfSSL | 0:9d17e4342598 | 11091 | } |
wolfSSL | 0:9d17e4342598 | 11092 | |
wolfSSL | 0:9d17e4342598 | 11093 | return ret; |
wolfSSL | 0:9d17e4342598 | 11094 | } |
wolfSSL | 0:9d17e4342598 | 11095 | |
wolfSSL | 0:9d17e4342598 | 11096 | #endif /* NO_CYASSL_SERVER */ |