0000: 2f 2a 0a 20 2a 20 43 6f 70 79 72 69 67 68 74 20 /*. * Copyright
0010: 28 43 29 20 31 39 39 37 2d 32 30 30 30 20 4d 61 (C) 1997-2000 Ma
0020: 74 74 20 4e 65 77 6d 61 6e 20 3c 6d 61 74 74 40 tt Newman <matt@
0030: 6e 6f 76 61 64 69 67 6d 2e 63 6f 6d 3e 0a 20 2a novadigm.com>. *
0040: 0a 20 2a 20 54 4c 53 20 28 61 6b 61 20 53 53 4c . * TLS (aka SSL
0050: 29 20 43 68 61 6e 6e 65 6c 20 2d 20 63 61 6e 20 ) Channel - can
0060: 62 65 20 6c 61 79 65 72 65 64 20 6f 6e 20 61 6e be layered on an
0070: 79 20 62 69 2d 64 69 72 65 63 74 69 6f 6e 61 6c y bi-directional
0080: 0a 20 2a 20 54 63 6c 5f 43 68 61 6e 6e 65 6c 20 . * Tcl_Channel
0090: 28 4e 6f 74 65 3a 20 52 65 71 75 69 72 65 73 20 (Note: Requires
00a0: 54 72 66 20 43 6f 72 65 20 50 61 74 63 68 29 0a Trf Core Patch).
00b0: 20 2a 0a 20 2a 20 54 68 69 73 20 77 61 73 20 62 *. * This was b
00c0: 75 69 6c 74 20 66 72 6f 6d 20 73 63 72 61 74 63 uilt from scratc
00d0: 68 20 62 61 73 65 64 20 75 70 6f 6e 20 6f 62 73 h based upon obs
00e0: 65 72 76 61 74 69 6f 6e 20 6f 66 20 4f 70 65 6e ervation of Open
00f0: 53 53 4c 20 30 2e 39 2e 32 42 0a 20 2a 0a 20 2a SSL 0.9.2B. *. *
0100: 20 41 64 64 69 74 69 6f 6e 20 63 72 65 64 69 74 Addition credit
0110: 20 69 73 20 64 75 65 20 66 6f 72 20 41 6e 64 72 is due for Andr
0120: 65 61 73 20 4b 75 70 72 69 65 73 20 28 61 2e 6b eas Kupries (a.k
0130: 75 70 72 69 65 73 40 77 65 73 74 65 6e 64 2e 63 upries@westend.c
0140: 6f 6d 29 2c 20 66 6f 72 0a 20 2a 20 70 72 6f 76 om), for. * prov
0150: 69 64 69 6e 67 20 74 68 65 20 54 63 6c 5f 52 65 iding the Tcl_Re
0160: 70 6c 61 63 65 43 68 61 6e 6e 65 6c 20 6d 65 63 placeChannel mec
0170: 68 61 6e 69 73 6d 20 61 6e 64 20 77 6f 72 6b 69 hanism and worki
0180: 6e 67 20 63 6c 6f 73 65 6c 79 20 77 69 74 68 20 ng closely with
0190: 6d 65 0a 20 2a 20 74 6f 20 65 6e 68 61 6e 63 65 me. * to enhance
01a0: 20 69 74 20 74 6f 20 73 75 70 70 6f 72 74 20 66 it to support f
01b0: 75 6c 6c 20 66 69 6c 65 65 76 65 6e 74 20 73 65 ull fileevent se
01c0: 6d 61 6e 74 69 63 73 2e 0a 20 2a 0a 20 2a 20 41 mantics.. *. * A
01d0: 6c 73 6f 20 77 6f 72 6b 20 64 6f 6e 65 20 62 79 lso work done by
01e0: 20 74 68 65 20 66 6f 6c 6c 6f 77 20 70 65 6f 70 the follow peop
01f0: 6c 65 20 70 72 6f 76 69 64 65 64 20 74 68 65 20 le provided the
0200: 69 6d 70 65 74 75 73 20 74 6f 20 64 6f 20 74 68 impetus to do th
0210: 69 73 20 22 72 69 67 68 74 22 3a 2d 0a 20 2a 09 is "right":-. *.
0220: 74 63 6c 53 53 4c 20 28 43 6f 6c 69 6e 20 4d 63 tclSSL (Colin Mc
0230: 43 6f 72 6d 61 63 6b 2c 20 53 68 61 72 65 64 20 Cormack, Shared
0240: 54 65 63 68 6e 6f 6c 6f 67 79 29 0a 20 2a 09 53 Technology). *.S
0250: 53 4c 74 63 6c 20 28 50 65 74 65 72 20 41 6e 74 SLtcl (Peter Ant
0260: 6d 61 6e 29 0a 20 2a 0a 20 2a 2f 0a 23 69 66 6e man). *. */.#ifn
0270: 64 65 66 20 5f 54 4c 53 49 4e 54 5f 48 0a 23 64 def _TLSINT_H.#d
0280: 65 66 69 6e 65 20 5f 54 4c 53 49 4e 54 5f 48 0a efine _TLSINT_H.
0290: 0a 23 69 6e 63 6c 75 64 65 20 22 74 6c 73 2e 68 .#include "tls.h
02a0: 22 0a 23 69 6e 63 6c 75 64 65 20 3c 65 72 72 6e ".#include <errn
02b0: 6f 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 73 o.h>.#include <s
02c0: 74 72 69 6e 67 2e 68 3e 0a 23 69 6e 63 6c 75 64 tring.h>.#includ
02d0: 65 20 3c 73 74 64 69 6e 74 2e 68 3e 0a 0a 23 69 e <stdint.h>..#i
02e0: 66 64 65 66 20 5f 57 49 4e 33 32 0a 23 64 65 66 fdef _WIN32.#def
02f0: 69 6e 65 20 57 49 4e 33 32 5f 4c 45 41 4e 5f 41 ine WIN32_LEAN_A
0300: 4e 44 5f 4d 45 41 4e 0a 23 69 6e 63 6c 75 64 65 ND_MEAN.#include
0310: 20 3c 77 69 6e 64 6f 77 73 2e 68 3e 0a 23 69 6e <windows.h>.#in
0320: 63 6c 75 64 65 20 3c 77 69 6e 63 72 79 70 74 2e clude <wincrypt.
0330: 68 3e 20 2f 2a 20 4f 70 65 6e 53 53 4c 20 6e 65 h> /* OpenSSL ne
0340: 65 64 73 20 74 68 69 73 20 6f 6e 20 57 69 6e 64 eds this on Wind
0350: 6f 77 73 20 2a 2f 0a 23 65 6e 64 69 66 0a 0a 23 ows */.#endif..#
0360: 69 66 64 65 66 20 4e 4f 5f 50 41 54 45 4e 54 53 ifdef NO_PATENTS
0370: 0a 23 20 20 64 65 66 69 6e 65 20 4e 4f 5f 49 44 .# define NO_ID
0380: 45 41 0a 23 20 20 64 65 66 69 6e 65 20 4e 4f 5f EA.# define NO_
0390: 52 43 32 0a 23 20 20 64 65 66 69 6e 65 20 4e 4f RC2.# define NO
03a0: 5f 52 43 34 0a 23 20 20 64 65 66 69 6e 65 20 4e _RC4.# define N
03b0: 4f 5f 52 43 35 0a 23 20 20 64 65 66 69 6e 65 20 O_RC5.# define
03c0: 4e 4f 5f 52 53 41 0a 23 65 6e 64 69 66 0a 0a 23 NO_RSA.#endif..#
03d0: 69 6e 63 6c 75 64 65 20 3c 6f 70 65 6e 73 73 6c include <openssl
03e0: 2f 73 73 6c 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 /ssl.h>.#include
03f0: 20 3c 6f 70 65 6e 73 73 6c 2f 65 72 72 2e 68 3e <openssl/err.h>
0400: 0a 23 69 6e 63 6c 75 64 65 20 3c 6f 70 65 6e 73 .#include <opens
0410: 73 6c 2f 72 61 6e 64 2e 68 3e 0a 23 69 6e 63 6c sl/rand.h>.#incl
0420: 75 64 65 20 3c 6f 70 65 6e 73 73 6c 2f 6f 70 65 ude <openssl/ope
0430: 6e 73 73 6c 76 2e 68 3e 0a 0a 2f 2a 0a 20 2a 20 nsslv.h>../*. *
0440: 44 65 74 65 72 6d 69 6e 65 20 69 66 20 77 65 20 Determine if we
0450: 73 68 6f 75 6c 64 20 75 73 65 20 74 68 65 20 70 should use the p
0460: 72 65 2d 4f 70 65 6e 53 53 4c 20 31 2e 31 2e 30 re-OpenSSL 1.1.0
0470: 20 41 50 49 0a 20 2a 2f 0a 23 75 6e 64 65 66 20 API. */.#undef
0480: 54 43 4c 54 4c 53 5f 4f 50 45 4e 53 53 4c 5f 50 TCLTLS_OPENSSL_P
0490: 52 45 5f 31 5f 31 0a 23 69 66 20 64 65 66 69 6e RE_1_1.#if defin
04a0: 65 64 28 4c 49 42 52 45 53 53 4c 5f 56 45 52 53 ed(LIBRESSL_VERS
04b0: 49 4f 4e 5f 4e 55 4d 42 45 52 29 0a 23 20 20 64 ION_NUMBER).# d
04c0: 65 66 69 6e 65 20 54 43 4c 54 4c 53 5f 4f 50 45 efine TCLTLS_OPE
04d0: 4e 53 53 4c 5f 50 52 45 5f 31 5f 31 5f 41 50 49 NSSL_PRE_1_1_API
04e0: 20 31 0a 23 65 6e 64 69 66 0a 0a 23 69 66 6e 64 1.#endif..#ifnd
04f0: 65 66 20 45 43 4f 4e 4e 41 42 4f 52 54 45 44 0a ef ECONNABORTED.
0500: 23 64 65 66 69 6e 65 20 45 43 4f 4e 4e 41 42 4f #define ECONNABO
0510: 52 54 45 44 09 31 33 30 09 2f 2a 20 53 6f 66 74 RTED.130./* Soft
0520: 77 61 72 65 20 63 61 75 73 65 64 20 63 6f 6e 6e ware caused conn
0530: 65 63 74 69 6f 6e 20 61 62 6f 72 74 20 2a 2f 0a ection abort */.
0540: 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 45 #endif.#ifndef E
0550: 43 4f 4e 4e 52 45 53 45 54 0a 23 64 65 66 69 6e CONNRESET.#defin
0560: 65 20 45 43 4f 4e 4e 52 45 53 45 54 09 31 33 31 e ECONNRESET.131
0570: 09 2f 2a 20 43 6f 6e 6e 65 63 74 69 6f 6e 20 72 ./* Connection r
0580: 65 73 65 74 20 62 79 20 70 65 65 72 20 2a 2f 0a eset by peer */.
0590: 23 65 6e 64 69 66 0a 0a 23 69 66 64 65 66 20 54 #endif..#ifdef T
05a0: 43 4c 45 58 54 5f 54 43 4c 54 4c 53 5f 44 45 42 CLEXT_TCLTLS_DEB
05b0: 55 47 0a 23 69 6e 63 6c 75 64 65 20 3c 63 74 79 UG.#include <cty
05c0: 70 65 2e 68 3e 0a 23 64 65 66 69 6e 65 20 64 70 pe.h>.#define dp
05d0: 72 69 6e 74 66 28 2e 2e 2e 29 20 7b 20 5c 0a 09 rintf(...) { \..
05e0: 63 68 61 72 20 64 70 72 69 6e 74 66 42 75 66 66 char dprintfBuff
05f0: 65 72 5b 38 31 39 32 5d 2c 20 2a 64 70 72 69 6e er[8192], *dprin
0600: 74 66 42 75 66 66 65 72 5f 70 3b 20 5c 0a 09 64 tfBuffer_p; \..d
0610: 70 72 69 6e 74 66 42 75 66 66 65 72 5f 70 20 3d printfBuffer_p =
0620: 20 26 64 70 72 69 6e 74 66 42 75 66 66 65 72 5b &dprintfBuffer[
0630: 30 5d 3b 20 5c 0a 09 64 70 72 69 6e 74 66 42 75 0]; \..dprintfBu
0640: 66 66 65 72 5f 70 20 2b 3d 20 73 70 72 69 6e 74 ffer_p += sprint
0650: 66 28 64 70 72 69 6e 74 66 42 75 66 66 65 72 5f f(dprintfBuffer_
0660: 70 2c 20 22 25 73 3a 25 69 3a 25 73 28 29 3a 22 p, "%s:%i:%s():"
0670: 2c 20 5f 5f 46 49 4c 45 5f 5f 2c 20 5f 5f 4c 49 , __FILE__, __LI
0680: 4e 45 5f 5f 2c 20 5f 5f 66 75 6e 63 5f 5f 29 3b NE__, __func__);
0690: 20 5c 0a 09 64 70 72 69 6e 74 66 42 75 66 66 65 \..dprintfBuffe
06a0: 72 5f 70 20 2b 3d 20 73 70 72 69 6e 74 66 28 64 r_p += sprintf(d
06b0: 70 72 69 6e 74 66 42 75 66 66 65 72 5f 70 2c 20 printfBuffer_p,
06c0: 5f 5f 56 41 5f 41 52 47 53 5f 5f 29 3b 20 5c 0a __VA_ARGS__); \.
06d0: 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c .fprintf(stderr,
06e0: 20 22 25 73 5c 6e 22 2c 20 64 70 72 69 6e 74 66 "%s\n", dprintf
06f0: 42 75 66 66 65 72 29 3b 20 5c 0a 7d 0a 23 64 65 Buffer); \.}.#de
0700: 66 69 6e 65 20 64 70 72 69 6e 74 42 75 66 66 65 fine dprintBuffe
0710: 72 28 62 75 66 66 65 72 4e 61 6d 65 2c 20 62 75 r(bufferName, bu
0720: 66 66 65 72 4c 65 6e 67 74 68 29 20 7b 20 5c 0a fferLength) { \.
0730: 09 69 6e 74 20 64 70 72 69 6e 74 42 75 66 66 65 .int dprintBuffe
0740: 72 49 64 78 3b 20 5c 0a 09 75 6e 73 69 67 6e 65 rIdx; \..unsigne
0750: 64 20 63 68 61 72 20 64 70 72 69 6e 74 42 75 66 d char dprintBuf
0760: 66 65 72 43 68 61 72 3b 20 5c 0a 09 66 70 72 69 ferChar; \..fpri
0770: 6e 74 66 28 73 74 64 65 72 72 2c 20 22 25 73 3a ntf(stderr, "%s:
0780: 25 69 3a 25 73 28 29 3a 25 73 5b 25 6c 6c 75 5d %i:%s():%s[%llu]
0790: 3d 7b 22 2c 20 5f 5f 46 49 4c 45 5f 5f 2c 20 5f ={", __FILE__, _
07a0: 5f 4c 49 4e 45 5f 5f 2c 20 5f 5f 66 75 6e 63 5f _LINE__, __func_
07b0: 5f 2c 20 23 62 75 66 66 65 72 4e 61 6d 65 2c 20 _, #bufferName,
07c0: 28 75 6e 73 69 67 6e 65 64 20 6c 6f 6e 67 20 6c (unsigned long l
07d0: 6f 6e 67 29 20 62 75 66 66 65 72 4c 65 6e 67 74 ong) bufferLengt
07e0: 68 29 3b 20 5c 0a 09 66 6f 72 20 28 64 70 72 69 h); \..for (dpri
07f0: 6e 74 42 75 66 66 65 72 49 64 78 20 3d 20 30 3b ntBufferIdx = 0;
0800: 20 64 70 72 69 6e 74 42 75 66 66 65 72 49 64 78 dprintBufferIdx
0810: 20 3c 20 62 75 66 66 65 72 4c 65 6e 67 74 68 3b < bufferLength;
0820: 20 64 70 72 69 6e 74 42 75 66 66 65 72 49 64 78 dprintBufferIdx
0830: 2b 2b 29 20 7b 20 5c 0a 09 09 64 70 72 69 6e 74 ++) { \...dprint
0840: 42 75 66 66 65 72 43 68 61 72 20 3d 20 62 75 66 BufferChar = buf
0850: 66 65 72 4e 61 6d 65 5b 64 70 72 69 6e 74 42 75 ferName[dprintBu
0860: 66 66 65 72 49 64 78 5d 3b 20 5c 0a 09 09 69 66 fferIdx]; \...if
0870: 20 28 69 73 61 6c 70 68 61 28 64 70 72 69 6e 74 (isalpha(dprint
0880: 42 75 66 66 65 72 43 68 61 72 29 20 7c 7c 20 69 BufferChar) || i
0890: 73 64 69 67 69 74 28 64 70 72 69 6e 74 42 75 66 sdigit(dprintBuf
08a0: 66 65 72 43 68 61 72 29 29 20 7b 20 5c 0a 09 09 ferChar)) { \...
08b0: 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c .fprintf(stderr,
08c0: 20 22 27 25 63 27 20 22 2c 20 64 70 72 69 6e 74 "'%c' ", dprint
08d0: 42 75 66 66 65 72 43 68 61 72 29 3b 20 5c 0a 09 BufferChar); \..
08e0: 09 7d 20 65 6c 73 65 20 7b 20 5c 0a 09 09 09 66 .} else { \....f
08f0: 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 printf(stderr, "
0900: 25 30 32 78 20 22 2c 20 28 75 6e 73 69 67 6e 65 %02x ", (unsigne
0910: 64 20 69 6e 74 29 20 64 70 72 69 6e 74 42 75 66 d int) dprintBuf
0920: 66 65 72 43 68 61 72 29 3b 20 5c 0a 09 09 7d 3b ferChar); \...};
0930: 20 5c 0a 09 7d 3b 20 5c 0a 09 66 70 72 69 6e 74 \..}; \..fprint
0940: 66 28 73 74 64 65 72 72 2c 20 22 7d 5c 6e 22 29 f(stderr, "}\n")
0950: 3b 20 5c 0a 7d 0a 23 64 65 66 69 6e 65 20 64 70 ; \.}.#define dp
0960: 72 69 6e 74 46 6c 61 67 73 28 73 74 61 74 65 50 rintFlags(stateP
0970: 74 72 29 20 7b 20 5c 0a 09 63 68 61 72 20 64 70 tr) { \..char dp
0980: 72 69 6e 74 66 42 75 66 66 65 72 5b 38 31 39 32 rintfBuffer[8192
0990: 5d 2c 20 2a 64 70 72 69 6e 74 66 42 75 66 66 65 ], *dprintfBuffe
09a0: 72 5f 70 3b 20 5c 0a 09 64 70 72 69 6e 74 66 42 r_p; \..dprintfB
09b0: 75 66 66 65 72 5f 70 20 3d 20 26 64 70 72 69 6e uffer_p = &dprin
09c0: 74 66 42 75 66 66 65 72 5b 30 5d 3b 20 5c 0a 09 tfBuffer[0]; \..
09d0: 64 70 72 69 6e 74 66 42 75 66 66 65 72 5f 70 20 dprintfBuffer_p
09e0: 2b 3d 20 73 70 72 69 6e 74 66 28 64 70 72 69 6e += sprintf(dprin
09f0: 74 66 42 75 66 66 65 72 5f 70 2c 20 22 25 73 3a tfBuffer_p, "%s:
0a00: 25 69 3a 25 73 28 29 3a 25 73 2d 3e 66 6c 61 67 %i:%s():%s->flag
0a10: 73 3d 30 22 2c 20 5f 5f 46 49 4c 45 5f 5f 2c 20 s=0", __FILE__,
0a20: 5f 5f 4c 49 4e 45 5f 5f 2c 20 5f 5f 66 75 6e 63 __LINE__, __func
0a30: 5f 5f 2c 20 23 73 74 61 74 65 50 74 72 29 3b 20 __, #statePtr);
0a40: 5c 0a 09 69 66 20 28 28 28 73 74 61 74 65 50 74 \..if (((statePt
0a50: 72 29 2d 3e 66 6c 61 67 73 20 26 20 54 4c 53 5f r)->flags & TLS_
0a60: 54 43 4c 5f 41 53 59 4e 43 29 20 3d 3d 20 54 4c TCL_ASYNC) == TL
0a70: 53 5f 54 43 4c 5f 41 53 59 4e 43 29 20 7b 20 64 S_TCL_ASYNC) { d
0a80: 70 72 69 6e 74 66 42 75 66 66 65 72 5f 70 20 2b printfBuffer_p +
0a90: 3d 20 73 70 72 69 6e 74 66 28 64 70 72 69 6e 74 = sprintf(dprint
0aa0: 66 42 75 66 66 65 72 5f 70 2c 20 22 7c 54 4c 53 fBuffer_p, "|TLS
0ab0: 5f 54 43 4c 5f 41 53 59 4e 43 22 29 3b 20 7d 3b _TCL_ASYNC"); };
0ac0: 20 5c 0a 09 69 66 20 28 28 28 73 74 61 74 65 50 \..if (((stateP
0ad0: 74 72 29 2d 3e 66 6c 61 67 73 20 26 20 54 4c 53 tr)->flags & TLS
0ae0: 5f 54 43 4c 5f 53 45 52 56 45 52 29 20 3d 3d 20 _TCL_SERVER) ==
0af0: 54 4c 53 5f 54 43 4c 5f 53 45 52 56 45 52 29 20 TLS_TCL_SERVER)
0b00: 7b 20 64 70 72 69 6e 74 66 42 75 66 66 65 72 5f { dprintfBuffer_
0b10: 70 20 2b 3d 20 73 70 72 69 6e 74 66 28 64 70 72 p += sprintf(dpr
0b20: 69 6e 74 66 42 75 66 66 65 72 5f 70 2c 20 22 7c intfBuffer_p, "|
0b30: 54 4c 53 5f 54 43 4c 5f 53 45 52 56 45 52 22 29 TLS_TCL_SERVER")
0b40: 3b 20 7d 3b 20 5c 0a 09 69 66 20 28 28 28 73 74 ; }; \..if (((st
0b50: 61 74 65 50 74 72 29 2d 3e 66 6c 61 67 73 20 26 atePtr)->flags &
0b60: 20 54 4c 53 5f 54 43 4c 5f 49 4e 49 54 29 20 3d TLS_TCL_INIT) =
0b70: 3d 20 54 4c 53 5f 54 43 4c 5f 49 4e 49 54 29 20 = TLS_TCL_INIT)
0b80: 7b 20 64 70 72 69 6e 74 66 42 75 66 66 65 72 5f { dprintfBuffer_
0b90: 70 20 2b 3d 20 73 70 72 69 6e 74 66 28 64 70 72 p += sprintf(dpr
0ba0: 69 6e 74 66 42 75 66 66 65 72 5f 70 2c 20 22 7c intfBuffer_p, "|
0bb0: 54 4c 53 5f 54 43 4c 5f 49 4e 49 54 22 29 3b 20 TLS_TCL_INIT");
0bc0: 7d 3b 20 5c 0a 09 69 66 20 28 28 28 73 74 61 74 }; \..if (((stat
0bd0: 65 50 74 72 29 2d 3e 66 6c 61 67 73 20 26 20 54 ePtr)->flags & T
0be0: 4c 53 5f 54 43 4c 5f 44 45 42 55 47 29 20 3d 3d LS_TCL_DEBUG) ==
0bf0: 20 54 4c 53 5f 54 43 4c 5f 44 45 42 55 47 29 20 TLS_TCL_DEBUG)
0c00: 7b 20 64 70 72 69 6e 74 66 42 75 66 66 65 72 5f { dprintfBuffer_
0c10: 70 20 2b 3d 20 73 70 72 69 6e 74 66 28 64 70 72 p += sprintf(dpr
0c20: 69 6e 74 66 42 75 66 66 65 72 5f 70 2c 20 22 7c intfBuffer_p, "|
0c30: 54 4c 53 5f 54 43 4c 5f 44 45 42 55 47 22 29 3b TLS_TCL_DEBUG");
0c40: 20 7d 3b 20 5c 0a 09 69 66 20 28 28 28 73 74 61 }; \..if (((sta
0c50: 74 65 50 74 72 29 2d 3e 66 6c 61 67 73 20 26 20 tePtr)->flags &
0c60: 54 4c 53 5f 54 43 4c 5f 43 41 4c 4c 42 41 43 4b TLS_TCL_CALLBACK
0c70: 29 20 3d 3d 20 54 4c 53 5f 54 43 4c 5f 43 41 4c ) == TLS_TCL_CAL
0c80: 4c 42 41 43 4b 29 20 7b 20 64 70 72 69 6e 74 66 LBACK) { dprintf
0c90: 42 75 66 66 65 72 5f 70 20 2b 3d 20 73 70 72 69 Buffer_p += spri
0ca0: 6e 74 66 28 64 70 72 69 6e 74 66 42 75 66 66 65 ntf(dprintfBuffe
0cb0: 72 5f 70 2c 20 22 7c 54 4c 53 5f 54 43 4c 5f 43 r_p, "|TLS_TCL_C
0cc0: 41 4c 4c 42 41 43 4b 22 29 3b 20 7d 3b 20 5c 0a ALLBACK"); }; \.
0cd0: 09 69 66 20 28 28 28 73 74 61 74 65 50 74 72 29 .if (((statePtr)
0ce0: 2d 3e 66 6c 61 67 73 20 26 20 54 4c 53 5f 54 43 ->flags & TLS_TC
0cf0: 4c 5f 48 41 4e 44 53 48 41 4b 45 5f 46 41 49 4c L_HANDSHAKE_FAIL
0d00: 45 44 29 20 3d 3d 20 54 4c 53 5f 54 43 4c 5f 48 ED) == TLS_TCL_H
0d10: 41 4e 44 53 48 41 4b 45 5f 46 41 49 4c 45 44 29 ANDSHAKE_FAILED)
0d20: 20 7b 20 64 70 72 69 6e 74 66 42 75 66 66 65 72 { dprintfBuffer
0d30: 5f 70 20 2b 3d 20 73 70 72 69 6e 74 66 28 64 70 _p += sprintf(dp
0d40: 72 69 6e 74 66 42 75 66 66 65 72 5f 70 2c 20 22 rintfBuffer_p, "
0d50: 7c 54 4c 53 5f 54 43 4c 5f 48 41 4e 44 53 48 41 |TLS_TCL_HANDSHA
0d60: 4b 45 5f 46 41 49 4c 45 44 22 29 3b 20 7d 3b 20 KE_FAILED"); };
0d70: 5c 0a 09 69 66 20 28 28 28 73 74 61 74 65 50 74 \..if (((statePt
0d80: 72 29 2d 3e 66 6c 61 67 73 20 26 20 54 4c 53 5f r)->flags & TLS_
0d90: 54 43 4c 5f 46 41 53 54 50 41 54 48 29 20 3d 3d TCL_FASTPATH) ==
0da0: 20 54 4c 53 5f 54 43 4c 5f 46 41 53 54 50 41 54 TLS_TCL_FASTPAT
0db0: 48 29 20 7b 20 64 70 72 69 6e 74 66 42 75 66 66 H) { dprintfBuff
0dc0: 65 72 5f 70 20 2b 3d 20 73 70 72 69 6e 74 66 28 er_p += sprintf(
0dd0: 64 70 72 69 6e 74 66 42 75 66 66 65 72 5f 70 2c dprintfBuffer_p,
0de0: 20 22 7c 54 4c 53 5f 54 43 4c 5f 46 41 53 54 50 "|TLS_TCL_FASTP
0df0: 41 54 48 22 29 3b 20 7d 3b 20 5c 0a 09 66 70 72 ATH"); }; \..fpr
0e00: 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 25 73 intf(stderr, "%s
0e10: 5c 6e 22 2c 20 64 70 72 69 6e 74 66 42 75 66 66 \n", dprintfBuff
0e20: 65 72 29 3b 20 5c 0a 7d 0a 23 65 6c 73 65 0a 23 er); \.}.#else.#
0e30: 64 65 66 69 6e 65 20 64 70 72 69 6e 74 66 28 2e define dprintf(.
0e40: 2e 2e 29 20 69 66 20 28 30 29 20 7b 20 66 70 72 ..) if (0) { fpr
0e50: 69 6e 74 66 28 73 74 64 65 72 72 2c 20 5f 5f 56 intf(stderr, __V
0e60: 41 5f 41 52 47 53 5f 5f 29 3b 20 7d 0a 23 64 65 A_ARGS__); }.#de
0e70: 66 69 6e 65 20 64 70 72 69 6e 74 42 75 66 66 65 fine dprintBuffe
0e80: 72 28 62 75 66 66 65 72 4e 61 6d 65 2c 20 62 75 r(bufferName, bu
0e90: 66 66 65 72 4c 65 6e 67 74 68 29 20 2f 2a 2a 2f fferLength) /**/
0ea0: 0a 23 64 65 66 69 6e 65 20 64 70 72 69 6e 74 46 .#define dprintF
0eb0: 6c 61 67 73 28 73 74 61 74 65 50 74 72 29 20 2f lags(statePtr) /
0ec0: 2a 2a 2f 0a 23 65 6e 64 69 66 0a 0a 23 64 65 66 **/.#endif..#def
0ed0: 69 6e 65 20 54 43 4c 54 4c 53 5f 53 53 4c 5f 45 ine TCLTLS_SSL_E
0ee0: 52 52 4f 52 28 73 73 6c 2c 65 72 72 29 20 28 28 RROR(ssl,err) ((
0ef0: 63 68 61 72 2a 29 45 52 52 5f 72 65 61 73 6f 6e char*)ERR_reason
0f00: 5f 65 72 72 6f 72 5f 73 74 72 69 6e 67 28 28 75 _error_string((u
0f10: 6e 73 69 67 6e 65 64 20 6c 6f 6e 67 29 53 53 4c nsigned long)SSL
0f20: 5f 67 65 74 5f 65 72 72 6f 72 28 28 73 73 6c 29 _get_error((ssl)
0f30: 2c 28 65 72 72 29 29 29 29 0a 2f 2a 0a 20 2a 20 ,(err))))./*. *
0f40: 4f 70 65 6e 53 53 4c 20 42 49 4f 20 52 6f 75 74 OpenSSL BIO Rout
0f50: 69 6e 65 73 0a 20 2a 2f 0a 23 64 65 66 69 6e 65 ines. */.#define
0f60: 20 42 49 4f 5f 54 59 50 45 5f 54 43 4c 09 28 31 BIO_TYPE_TCL.(1
0f70: 39 7c 30 78 30 34 30 30 29 0a 0a 2f 2a 0a 20 2a 9|0x0400)../*. *
0f80: 20 44 65 66 69 6e 65 73 20 66 6f 72 20 53 74 61 Defines for Sta
0f90: 74 65 2e 66 6c 61 67 73 0a 20 2a 2f 0a 23 64 65 te.flags. */.#de
0fa0: 66 69 6e 65 20 54 4c 53 5f 54 43 4c 5f 41 53 59 fine TLS_TCL_ASY
0fb0: 4e 43 09 09 28 31 3c 3c 30 29 09 2f 2a 20 6e 6f NC..(1<<0)./* no
0fc0: 6e 2d 62 6c 6f 63 6b 69 6e 67 20 6d 6f 64 65 20 n-blocking mode
0fd0: 2a 2f 0a 23 64 65 66 69 6e 65 20 54 4c 53 5f 54 */.#define TLS_T
0fe0: 43 4c 5f 53 45 52 56 45 52 09 09 28 31 3c 3c 31 CL_SERVER..(1<<1
0ff0: 29 09 2f 2a 20 53 65 72 76 65 72 2d 53 69 64 65 )./* Server-Side
1000: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 54 4c 53 5f */.#define TLS_
1010: 54 43 4c 5f 49 4e 49 54 09 09 28 31 3c 3c 32 29 TCL_INIT..(1<<2)
1020: 09 2f 2a 20 49 6e 69 74 69 61 6c 69 7a 69 6e 67 ./* Initializing
1030: 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 2a 2f 0a 23 connection */.#
1040: 64 65 66 69 6e 65 20 54 4c 53 5f 54 43 4c 5f 44 define TLS_TCL_D
1050: 45 42 55 47 09 09 28 31 3c 3c 33 29 09 2f 2a 20 EBUG..(1<<3)./*
1060: 53 68 6f 77 20 64 65 62 75 67 20 74 72 61 63 69 Show debug traci
1070: 6e 67 20 2a 2f 0a 23 64 65 66 69 6e 65 20 54 4c ng */.#define TL
1080: 53 5f 54 43 4c 5f 43 41 4c 4c 42 41 43 4b 09 28 S_TCL_CALLBACK.(
1090: 31 3c 3c 34 29 09 2f 2a 20 49 6e 20 61 20 63 61 1<<4)./* In a ca
10a0: 6c 6c 62 61 63 6b 2c 20 70 72 65 76 65 6e 74 20 llback, prevent
10b0: 75 70 64 61 74 65 0a 09 09 09 09 09 20 2a 20 6c update...... * l
10c0: 6f 6f 70 69 6e 67 20 70 72 6f 62 6c 65 6d 2e 20 ooping problem.
10d0: 5b 42 75 67 20 31 36 35 32 33 38 30 5d 20 2a 2f [Bug 1652380] */
10e0: 0a 23 64 65 66 69 6e 65 20 54 4c 53 5f 54 43 4c .#define TLS_TCL
10f0: 5f 48 41 4e 44 53 48 41 4b 45 5f 46 41 49 4c 45 _HANDSHAKE_FAILE
1100: 44 20 28 31 3c 3c 35 29 20 2f 2a 20 53 65 74 20 D (1<<5) /* Set
1110: 6f 6e 20 68 61 6e 64 73 68 61 6b 65 20 66 61 69 on handshake fai
1120: 6c 75 72 65 73 20 61 6e 64 20 6f 6e 63 65 20 73 lures and once s
1130: 65 74 2c 20 61 6c 6c 0a 20 20 20 20 20 20 20 20 et, all.
1140: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1150: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1160: 20 2a 20 66 75 72 74 68 65 72 20 49 2f 4f 20 77 * further I/O w
1170: 69 6c 6c 20 72 65 73 75 6c 74 20 69 6e 20 45 43 ill result in EC
1180: 4f 4e 4e 41 42 4f 52 54 45 44 20 65 72 72 6f 72 ONNABORTED error
1190: 73 2e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 54 4c s. */.#define TL
11a0: 53 5f 54 43 4c 5f 46 41 53 54 50 41 54 48 20 09 S_TCL_FASTPATH .
11b0: 28 31 3c 3c 36 29 09 2f 2a 20 54 68 65 20 70 61 (1<<6)./* The pa
11c0: 72 65 6e 74 20 63 68 61 6e 6e 65 6c 20 69 73 20 rent channel is
11d0: 62 65 69 6e 67 20 75 73 65 64 20 64 69 72 65 63 being used direc
11e0: 74 6c 79 20 62 79 20 74 68 65 20 53 53 4c 20 6c tly by the SSL l
11f0: 69 62 72 61 72 79 20 2a 2f 0a 23 64 65 66 69 6e ibrary */.#defin
1200: 65 20 54 4c 53 5f 54 43 4c 5f 44 45 4c 41 59 20 e TLS_TCL_DELAY
1210: 28 35 29 0a 0a 2f 2a 0a 20 2a 20 54 68 69 73 20 (5)../*. * This
1220: 73 74 72 75 63 74 75 72 65 20 64 65 73 63 72 69 structure descri
1230: 62 65 73 20 74 68 65 20 70 65 72 2d 69 6e 73 74 bes the per-inst
1240: 61 6e 63 65 20 73 74 61 74 65 20 6f 66 20 61 6e ance state of an
1250: 20 53 53 4c 20 63 68 61 6e 6e 65 6c 2e 0a 20 2a SSL channel.. *
1260: 0a 20 2a 20 54 68 65 20 53 53 4c 20 70 72 6f 63 . * The SSL proc
1270: 65 73 73 69 6e 67 20 63 6f 6e 74 65 78 74 20 69 essing context i
1280: 73 20 6d 61 69 6e 74 61 69 6e 65 64 20 68 65 72 s maintained her
1290: 65 2c 20 69 6e 20 74 68 65 20 43 6c 69 65 6e 74 e, in the Client
12a0: 44 61 74 61 0a 20 2a 2f 0a 74 79 70 65 64 65 66 Data. */.typedef
12b0: 20 73 74 72 75 63 74 20 53 74 61 74 65 20 7b 0a struct State {.
12c0: 09 54 63 6c 5f 43 68 61 6e 6e 65 6c 20 73 65 6c .Tcl_Channel sel
12d0: 66 3b 09 2f 2a 20 74 68 69 73 20 73 6f 63 6b 65 f;./* this socke
12e0: 74 20 63 68 61 6e 6e 65 6c 20 2a 2f 0a 09 54 63 t channel */..Tc
12f0: 6c 5f 54 69 6d 65 72 54 6f 6b 65 6e 20 74 69 6d l_TimerToken tim
1300: 65 72 3b 0a 0a 09 69 6e 74 20 66 6c 61 67 73 3b er;...int flags;
1310: 09 09 2f 2a 20 73 65 65 20 53 74 61 74 65 2e 66 ../* see State.f
1320: 6c 61 67 73 20 61 62 6f 76 65 20 20 2a 2f 0a 09 lags above */..
1330: 69 6e 74 20 77 61 74 63 68 4d 61 73 6b 3b 09 09 int watchMask;..
1340: 2f 2a 20 63 75 72 72 65 6e 74 20 57 61 74 63 68 /* current Watch
1350: 50 72 6f 63 20 6d 61 73 6b 20 2a 2f 0a 09 69 6e Proc mask */..in
1360: 74 20 6d 6f 64 65 3b 09 09 2f 2a 20 63 75 72 72 t mode;../* curr
1370: 65 6e 74 20 6d 6f 64 65 20 6f 66 20 70 61 72 65 ent mode of pare
1380: 6e 74 20 63 68 61 6e 6e 65 6c 20 2a 2f 0a 0a 09 nt channel */...
1390: 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 Tcl_Interp *inte
13a0: 72 70 3b 09 2f 2a 20 69 6e 74 65 72 70 72 65 74 rp;./* interpret
13b0: 65 72 20 69 6e 20 77 68 69 63 68 20 74 68 69 73 er in which this
13c0: 20 72 65 73 69 64 65 73 20 2a 2f 0a 09 54 63 6c resides */..Tcl
13d0: 5f 4f 62 6a 20 2a 63 61 6c 6c 62 61 63 6b 3b 09 _Obj *callback;.
13e0: 2f 2a 20 73 63 72 69 70 74 20 63 61 6c 6c 65 64 /* script called
13f0: 20 66 6f 72 20 74 72 61 63 69 6e 67 2c 20 69 6e for tracing, in
1400: 66 6f 2c 20 61 6e 64 20 65 72 72 6f 72 73 20 2a fo, and errors *
1410: 2f 0a 09 54 63 6c 5f 4f 62 6a 20 2a 70 61 73 73 /..Tcl_Obj *pass
1420: 77 6f 72 64 3b 09 2f 2a 20 73 63 72 69 70 74 20 word;./* script
1430: 63 61 6c 6c 65 64 20 66 6f 72 20 63 65 72 74 69 called for certi
1440: 66 69 63 61 74 65 20 70 61 73 73 77 6f 72 64 20 ficate password
1450: 2a 2f 0a 0a 09 69 6e 74 20 76 66 6c 61 67 73 3b */...int vflags;
1460: 09 09 2f 2a 20 76 65 72 69 66 79 20 66 6c 61 67 ../* verify flag
1470: 73 20 2a 2f 0a 09 53 53 4c 20 2a 73 73 6c 3b 09 s */..SSL *ssl;.
1480: 09 2f 2a 20 53 74 72 75 63 74 20 66 6f 72 20 53 ./* Struct for S
1490: 53 4c 20 70 72 6f 63 65 73 73 69 6e 67 20 2a 2f SL processing */
14a0: 0a 09 53 53 4c 5f 43 54 58 20 2a 63 74 78 3b 09 ..SSL_CTX *ctx;.
14b0: 09 2f 2a 20 53 53 4c 20 43 6f 6e 74 65 78 74 20 ./* SSL Context
14c0: 2a 2f 0a 09 42 49 4f 20 2a 62 69 6f 3b 09 09 2f */..BIO *bio;../
14d0: 2a 20 53 74 72 75 63 74 20 66 6f 72 20 53 53 4c * Struct for SSL
14e0: 20 70 72 6f 63 65 73 73 69 6e 67 20 2a 2f 0a 09 processing */..
14f0: 42 49 4f 20 2a 70 5f 62 69 6f 3b 09 09 2f 2a 20 BIO *p_bio;../*
1500: 50 61 72 65 6e 74 20 42 49 4f 20 28 74 68 61 74 Parent BIO (that
1510: 20 69 73 20 6c 61 79 65 72 65 64 20 6f 6e 20 54 is layered on T
1520: 63 6c 5f 43 68 61 6e 6e 65 6c 29 20 2a 2f 0a 0a cl_Channel) */..
1530: 09 63 6f 6e 73 74 20 63 68 61 72 20 2a 65 72 72 .const char *err
1540: 3b 0a 7d 20 53 74 61 74 65 3b 0a 0a 23 69 66 64 ;.} State;..#ifd
1550: 65 66 20 55 53 45 5f 54 43 4c 5f 53 54 55 42 53 ef USE_TCL_STUBS
1560: 0a 23 69 66 6e 64 65 66 20 54 63 6c 5f 53 74 61 .#ifndef Tcl_Sta
1570: 63 6b 43 68 61 6e 6e 65 6c 0a 23 65 72 72 6f 72 ckChannel.#error
1580: 20 22 55 6e 61 62 6c 65 20 74 6f 20 63 6f 6d 70 "Unable to comp
1590: 69 6c 65 20 6f 6e 20 74 68 69 73 20 76 65 72 73 ile on this vers
15a0: 69 6f 6e 20 6f 66 20 54 63 6c 22 0a 23 65 6e 64 ion of Tcl".#end
15b0: 69 66 20 2f 2a 20 54 63 6c 5f 47 65 74 53 74 61 if /* Tcl_GetSta
15c0: 63 6b 65 64 43 68 61 6e 6e 65 6c 20 2a 2f 0a 23 ckedChannel */.#
15d0: 65 6e 64 69 66 20 2f 2a 20 55 53 45 5f 54 43 4c endif /* USE_TCL
15e0: 5f 53 54 55 42 53 20 2a 2f 0a 0a 23 69 66 6e 64 _STUBS */..#ifnd
15f0: 65 66 20 4a 4f 49 4e 0a 23 20 20 64 65 66 69 6e ef JOIN.# defin
1600: 65 20 4a 4f 49 4e 28 61 2c 62 29 20 4a 4f 49 4e e JOIN(a,b) JOIN
1610: 31 28 61 2c 62 29 0a 23 20 20 64 65 66 69 6e 65 1(a,b).# define
1620: 20 4a 4f 49 4e 31 28 61 2c 62 29 20 61 23 23 62 JOIN1(a,b) a##b
1630: 0a 23 65 6e 64 69 66 0a 0a 23 69 66 6e 64 65 66 .#endif..#ifndef
1640: 20 54 43 4c 5f 55 4e 55 53 45 44 0a 23 20 69 66 TCL_UNUSED.# if
1650: 20 64 65 66 69 6e 65 64 28 5f 5f 63 70 6c 75 73 defined(__cplus
1660: 70 6c 75 73 29 0a 23 20 20 20 64 65 66 69 6e 65 plus).# define
1670: 20 54 43 4c 5f 55 4e 55 53 45 44 28 54 29 20 54 TCL_UNUSED(T) T
1680: 0a 23 20 65 6c 69 66 20 64 65 66 69 6e 65 64 28 .# elif defined(
1690: 5f 5f 47 4e 55 43 5f 5f 29 20 26 26 20 28 5f 5f __GNUC__) && (__
16a0: 47 4e 55 43 5f 5f 20 3e 20 32 29 0a 23 20 20 20 GNUC__ > 2).#
16b0: 64 65 66 69 6e 65 20 54 43 4c 5f 55 4e 55 53 45 define TCL_UNUSE
16c0: 44 28 54 29 20 54 20 4a 4f 49 4e 28 64 75 6d 6d D(T) T JOIN(dumm
16d0: 79 2c 20 5f 5f 4c 49 4e 45 5f 5f 29 20 5f 5f 61 y, __LINE__) __a
16e0: 74 74 72 69 62 75 74 65 5f 5f 28 28 75 6e 75 73 ttribute__((unus
16f0: 65 64 29 29 0a 23 20 65 6c 73 65 0a 23 20 20 20 ed)).# else.#
1700: 64 65 66 69 6e 65 20 54 43 4c 5f 55 4e 55 53 45 define TCL_UNUSE
1710: 44 28 54 29 20 54 20 4a 4f 49 4e 28 64 75 6d 6d D(T) T JOIN(dumm
1720: 79 2c 20 5f 5f 4c 49 4e 45 5f 5f 29 0a 23 20 65 y, __LINE__).# e
1730: 6e 64 69 66 0a 23 65 6e 64 69 66 0a 0a 23 69 66 ndif.#endif..#if
1740: 20 28 54 43 4c 5f 4d 41 4a 4f 52 5f 56 45 52 53 (TCL_MAJOR_VERS
1750: 49 4f 4e 20 3c 20 39 29 20 26 26 20 64 65 66 69 ION < 9) && defi
1760: 6e 65 64 28 54 43 4c 5f 4d 49 4e 4f 52 5f 56 45 ned(TCL_MINOR_VE
1770: 52 53 49 4f 4e 29 20 26 26 20 28 54 43 4c 5f 4d RSION) && (TCL_M
1780: 49 4e 4f 52 5f 56 45 52 53 49 4f 4e 20 3c 20 37 INOR_VERSION < 7
1790: 29 20 26 26 20 21 64 65 66 69 6e 65 64 28 54 63 ) && !defined(Tc
17a0: 6c 5f 53 69 7a 65 29 0a 23 20 20 20 64 65 66 69 l_Size).# defi
17b0: 6e 65 20 54 63 6c 5f 53 69 7a 65 20 69 6e 74 0a ne Tcl_Size int.
17c0: 23 20 20 20 64 65 66 69 6e 65 20 54 43 4c 5f 53 # define TCL_S
17d0: 49 5a 45 5f 4d 4f 44 49 46 49 45 52 20 22 22 0a IZE_MODIFIER "".
17e0: 23 65 6e 64 69 66 0a 0a 2f 2a 0a 20 2a 20 46 6f #endif../*. * Fo
17f0: 72 77 61 72 64 20 64 65 63 6c 61 72 61 74 69 6f rward declaratio
1800: 6e 73 0a 20 2a 2f 0a 63 6f 6e 73 74 20 54 63 6c ns. */.const Tcl
1810: 5f 43 68 61 6e 6e 65 6c 54 79 70 65 20 2a 54 6c _ChannelType *Tl
1820: 73 5f 43 68 61 6e 6e 65 6c 54 79 70 65 28 76 6f s_ChannelType(vo
1830: 69 64 29 3b 0a 54 63 6c 5f 43 68 61 6e 6e 65 6c id);.Tcl_Channel
1840: 20 20 20 20 20 54 6c 73 5f 47 65 74 50 61 72 65 Tls_GetPare
1850: 6e 74 28 53 74 61 74 65 20 2a 73 74 61 74 65 50 nt(State *stateP
1860: 74 72 2c 20 69 6e 74 20 6d 61 73 6b 46 6c 61 67 tr, int maskFlag
1870: 73 29 3b 0a 0a 54 63 6c 5f 4f 62 6a 20 20 20 20 s);..Tcl_Obj
1880: 20 20 20 20 2a 54 6c 73 5f 4e 65 77 58 35 30 39 *Tls_NewX509
1890: 4f 62 6a 28 54 63 6c 5f 49 6e 74 65 72 70 20 2a Obj(Tcl_Interp *
18a0: 69 6e 74 65 72 70 2c 20 58 35 30 39 20 2a 63 65 interp, X509 *ce
18b0: 72 74 29 3b 0a 76 6f 69 64 20 20 20 20 20 20 20 rt);.void
18c0: 20 20 20 20 20 54 6c 73 5f 45 72 72 6f 72 28 53 Tls_Error(S
18d0: 74 61 74 65 20 2a 73 74 61 74 65 50 74 72 2c 20 tate *statePtr,
18e0: 63 68 61 72 20 2a 6d 73 67 29 3b 0a 23 69 66 20 char *msg);.#if
18f0: 54 43 4c 5f 4d 41 4a 4f 52 5f 56 45 52 53 49 4f TCL_MAJOR_VERSIO
1900: 4e 20 3e 20 38 0a 76 6f 69 64 20 20 20 20 20 20 N > 8.void
1910: 20 20 20 20 20 20 54 6c 73 5f 46 72 65 65 28 76 Tls_Free(v
1920: 6f 69 64 20 2a 62 6c 6f 63 6b 50 74 72 29 3b 0a oid *blockPtr);.
1930: 23 65 6c 73 65 0a 76 6f 69 64 20 20 20 20 20 20 #else.void
1940: 20 20 20 20 20 20 54 6c 73 5f 46 72 65 65 28 63 Tls_Free(c
1950: 68 61 72 20 2a 62 6c 6f 63 6b 50 74 72 29 3b 0a har *blockPtr);.
1960: 23 65 6e 64 69 66 0a 76 6f 69 64 20 20 20 20 20 #endif.void
1970: 20 20 20 20 20 20 20 54 6c 73 5f 43 6c 65 61 6e Tls_Clean
1980: 28 53 74 61 74 65 20 2a 73 74 61 74 65 50 74 72 (State *statePtr
1990: 29 3b 0a 69 6e 74 20 20 20 20 20 20 20 20 20 20 );.int
19a0: 20 20 20 54 6c 73 5f 57 61 69 74 46 6f 72 43 6f Tls_WaitForCo
19b0: 6e 6e 65 63 74 28 53 74 61 74 65 20 2a 73 74 61 nnect(State *sta
19c0: 74 65 50 74 72 2c 20 69 6e 74 20 2a 65 72 72 6f tePtr, int *erro
19d0: 72 43 6f 64 65 50 74 72 2c 20 69 6e 74 20 68 61 rCodePtr, int ha
19e0: 6e 64 73 68 61 6b 65 46 61 69 6c 75 72 65 49 73 ndshakeFailureIs
19f0: 50 65 72 6d 61 6e 65 6e 74 29 3b 0a 0a 42 49 4f Permanent);..BIO
1a00: 20 20 20 20 20 20 20 20 20 20 20 20 2a 42 49 4f *BIO
1a10: 5f 6e 65 77 5f 74 63 6c 28 53 74 61 74 65 2a 20 _new_tcl(State*
1a20: 73 74 61 74 65 50 74 72 2c 20 69 6e 74 20 66 6c statePtr, int fl
1a30: 61 67 73 29 3b 0a 0a 23 64 65 66 69 6e 65 20 50 ags);..#define P
1a40: 54 52 32 49 4e 54 28 78 29 20 28 28 69 6e 74 29 TR2INT(x) ((int)
1a50: 20 28 28 69 6e 74 70 74 72 5f 74 29 20 28 78 29 ((intptr_t) (x)
1a60: 29 29 0a 0a 23 65 6e 64 69 66 20 2f 2a 20 5f 54 ))..#endif /* _T
1a70: 4c 53 49 4e 54 5f 48 20 2a 2f 0a LSINT_H */.