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 5f 57 49 4e 33 32 5f 5f 0a 23 fdef __WIN32__.#
02f0: 64 65 66 69 6e 65 20 57 49 4e 33 32 5f 4c 45 41 define WIN32_LEA
0300: 4e 5f 41 4e 44 5f 4d 45 41 4e 0a 23 69 6e 63 6c N_AND_MEAN.#incl
0310: 75 64 65 20 3c 77 69 6e 64 6f 77 73 2e 68 3e 0a ude <windows.h>.
0320: 23 69 6e 63 6c 75 64 65 20 3c 77 69 6e 63 72 79 #include <wincry
0330: 70 74 2e 68 3e 20 2f 2a 20 4f 70 65 6e 53 53 4c pt.h> /* OpenSSL
0340: 20 6e 65 65 64 73 20 74 68 69 73 20 6f 6e 20 57 needs this on W
0350: 69 6e 64 6f 77 73 20 2a 2f 0a 23 65 6e 64 69 66 indows */.#endif
0360: 0a 0a 23 69 66 64 65 66 20 4e 4f 5f 50 41 54 45 ..#ifdef NO_PATE
0370: 4e 54 53 0a 23 20 20 64 65 66 69 6e 65 20 4e 4f NTS.# define NO
0380: 5f 49 44 45 41 0a 23 20 20 64 65 66 69 6e 65 20 _IDEA.# define
0390: 4e 4f 5f 52 43 32 0a 23 20 20 64 65 66 69 6e 65 NO_RC2.# define
03a0: 20 4e 4f 5f 52 43 34 0a 23 20 20 64 65 66 69 6e NO_RC4.# defin
03b0: 65 20 4e 4f 5f 52 43 35 0a 23 20 20 64 65 66 69 e NO_RC5.# defi
03c0: 6e 65 20 4e 4f 5f 52 53 41 0a 23 20 20 69 66 6e ne NO_RSA.# ifn
03d0: 64 65 66 20 4e 4f 5f 53 53 4c 32 0a 23 20 20 20 def NO_SSL2.#
03e0: 20 64 65 66 69 6e 65 20 4e 4f 5f 53 53 4c 32 0a define NO_SSL2.
03f0: 23 20 20 65 6e 64 69 66 0a 23 65 6e 64 69 66 0a # endif.#endif.
0400: 0a 23 69 6e 63 6c 75 64 65 20 3c 6f 70 65 6e 73 .#include <opens
0410: 73 6c 2f 73 73 6c 2e 68 3e 0a 23 69 6e 63 6c 75 sl/ssl.h>.#inclu
0420: 64 65 20 3c 6f 70 65 6e 73 73 6c 2f 65 72 72 2e de <openssl/err.
0430: 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 6f 70 65 h>.#include <ope
0440: 6e 73 73 6c 2f 72 61 6e 64 2e 68 3e 0a 23 69 6e nssl/rand.h>.#in
0450: 63 6c 75 64 65 20 3c 6f 70 65 6e 73 73 6c 2f 6f clude <openssl/o
0460: 70 65 6e 73 73 6c 76 2e 68 3e 0a 0a 2f 2a 0a 20 pensslv.h>../*.
0470: 2a 20 44 65 74 65 72 6d 69 6e 65 20 69 66 20 77 * Determine if w
0480: 65 20 73 68 6f 75 6c 64 20 75 73 65 20 74 68 65 e should use the
0490: 20 70 72 65 2d 4f 70 65 6e 53 53 4c 20 31 2e 31 pre-OpenSSL 1.1
04a0: 2e 30 20 41 50 49 0a 20 2a 2f 0a 23 75 6e 64 65 .0 API. */.#unde
04b0: 66 20 54 43 4c 54 4c 53 5f 4f 50 45 4e 53 53 4c f TCLTLS_OPENSSL
04c0: 5f 50 52 45 5f 31 5f 31 0a 23 69 66 20 28 64 65 _PRE_1_1.#if (de
04d0: 66 69 6e 65 64 28 4c 49 42 52 45 53 53 4c 5f 56 fined(LIBRESSL_V
04e0: 45 52 53 49 4f 4e 5f 4e 55 4d 42 45 52 29 29 20 ERSION_NUMBER))
04f0: 7c 7c 20 4f 50 45 4e 53 53 4c 5f 56 45 52 53 49 || OPENSSL_VERSI
0500: 4f 4e 5f 4e 55 4d 42 45 52 20 3c 20 30 78 31 30 ON_NUMBER < 0x10
0510: 31 30 30 30 30 30 4c 0a 23 20 20 64 65 66 69 6e 100000L.# defin
0520: 65 20 54 43 4c 54 4c 53 5f 4f 50 45 4e 53 53 4c e TCLTLS_OPENSSL
0530: 5f 50 52 45 5f 31 5f 31 5f 41 50 49 20 31 0a 23 _PRE_1_1_API 1.#
0540: 65 6e 64 69 66 0a 0a 23 69 66 6e 64 65 66 20 45 endif..#ifndef E
0550: 43 4f 4e 4e 41 42 4f 52 54 45 44 0a 23 64 65 66 CONNABORTED.#def
0560: 69 6e 65 20 45 43 4f 4e 4e 41 42 4f 52 54 45 44 ine ECONNABORTED
0570: 09 31 33 30 09 2f 2a 20 53 6f 66 74 77 61 72 65 .130./* Software
0580: 20 63 61 75 73 65 64 20 63 6f 6e 6e 65 63 74 69 caused connecti
0590: 6f 6e 20 61 62 6f 72 74 20 2a 2f 0a 23 65 6e 64 on abort */.#end
05a0: 69 66 0a 23 69 66 6e 64 65 66 20 45 43 4f 4e 4e if.#ifndef ECONN
05b0: 52 45 53 45 54 0a 23 64 65 66 69 6e 65 20 45 43 RESET.#define EC
05c0: 4f 4e 4e 52 45 53 45 54 09 31 33 31 09 2f 2a 20 ONNRESET.131./*
05d0: 43 6f 6e 6e 65 63 74 69 6f 6e 20 72 65 73 65 74 Connection reset
05e0: 20 62 79 20 70 65 65 72 20 2a 2f 0a 23 65 6e 64 by peer */.#end
05f0: 69 66 0a 0a 23 69 66 64 65 66 20 54 43 4c 45 58 if..#ifdef TCLEX
0600: 54 5f 54 43 4c 54 4c 53 5f 44 45 42 55 47 0a 23 T_TCLTLS_DEBUG.#
0610: 69 6e 63 6c 75 64 65 20 3c 63 74 79 70 65 2e 68 include <ctype.h
0620: 3e 0a 23 64 65 66 69 6e 65 20 64 70 72 69 6e 74 >.#define dprint
0630: 66 28 2e 2e 2e 29 20 7b 20 5c 0a 20 20 20 20 20 f(...) { \.
0640: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0650: 20 20 63 68 61 72 20 64 70 72 69 6e 74 66 42 75 char dprintfBu
0660: 66 66 65 72 5b 38 31 39 32 5d 2c 20 2a 64 70 72 ffer[8192], *dpr
0670: 69 6e 74 66 42 75 66 66 65 72 5f 70 3b 20 5c 0a intfBuffer_p; \.
0680: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0690: 20 20 20 20 20 20 20 64 70 72 69 6e 74 66 42 75 dprintfBu
06a0: 66 66 65 72 5f 70 20 3d 20 26 64 70 72 69 6e 74 ffer_p = &dprint
06b0: 66 42 75 66 66 65 72 5b 30 5d 3b 20 5c 0a 20 20 fBuffer[0]; \.
06c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
06d0: 20 20 20 20 20 64 70 72 69 6e 74 66 42 75 66 66 dprintfBuff
06e0: 65 72 5f 70 20 2b 3d 20 73 70 72 69 6e 74 66 28 er_p += sprintf(
06f0: 64 70 72 69 6e 74 66 42 75 66 66 65 72 5f 70 2c dprintfBuffer_p,
0700: 20 22 25 73 3a 25 69 3a 25 73 28 29 3a 22 2c 20 "%s:%i:%s():",
0710: 5f 5f 46 49 4c 45 5f 5f 2c 20 5f 5f 4c 49 4e 45 __FILE__, __LINE
0720: 5f 5f 2c 20 5f 5f 66 75 6e 63 5f 5f 29 3b 20 5c __, __func__); \
0730: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
0740: 20 20 20 20 20 20 20 20 64 70 72 69 6e 74 66 42 dprintfB
0750: 75 66 66 65 72 5f 70 20 2b 3d 20 73 70 72 69 6e uffer_p += sprin
0760: 74 66 28 64 70 72 69 6e 74 66 42 75 66 66 65 72 tf(dprintfBuffer
0770: 5f 70 2c 20 5f 5f 56 41 5f 41 52 47 53 5f 5f 29 _p, __VA_ARGS__)
0780: 3b 20 5c 0a 20 20 20 20 20 20 20 20 20 20 20 20 ; \.
0790: 20 20 20 20 20 20 20 20 20 20 20 66 70 72 69 6e fprin
07a0: 74 66 28 73 74 64 65 72 72 2c 20 22 25 73 5c 6e tf(stderr, "%s\n
07b0: 22 2c 20 64 70 72 69 6e 74 66 42 75 66 66 65 72 ", dprintfBuffer
07c0: 29 3b 20 5c 0a 20 20 20 20 20 20 20 20 20 20 20 ); \.
07d0: 20 20 20 20 20 20 20 20 20 20 7d 0a 23 64 65 66 }.#def
07e0: 69 6e 65 20 64 70 72 69 6e 74 42 75 66 66 65 72 ine dprintBuffer
07f0: 28 62 75 66 66 65 72 4e 61 6d 65 2c 20 62 75 66 (bufferName, buf
0800: 66 65 72 4c 65 6e 67 74 68 29 20 7b 20 5c 0a 20 ferLength) { \.
0810: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0820: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0830: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0840: 69 6e 74 20 64 70 72 69 6e 74 42 75 66 66 65 72 int dprintBuffer
0850: 49 64 78 3b 20 5c 0a 20 20 20 20 20 20 20 20 20 Idx; \.
0860: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0870: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0880: 20 20 20 20 20 20 20 20 75 6e 73 69 67 6e 65 64 unsigned
0890: 20 63 68 61 72 20 64 70 72 69 6e 74 42 75 66 66 char dprintBuff
08a0: 65 72 43 68 61 72 3b 20 5c 0a 20 20 20 20 20 20 erChar; \.
08b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
08c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
08d0: 20 20 20 20 20 20 20 20 20 20 20 66 70 72 69 6e fprin
08e0: 74 66 28 73 74 64 65 72 72 2c 20 22 25 73 3a 25 tf(stderr, "%s:%
08f0: 69 3a 25 73 28 29 3a 25 73 5b 25 6c 6c 75 5d 3d i:%s():%s[%llu]=
0900: 7b 22 2c 20 5f 5f 46 49 4c 45 5f 5f 2c 20 5f 5f {", __FILE__, __
0910: 4c 49 4e 45 5f 5f 2c 20 5f 5f 66 75 6e 63 5f 5f LINE__, __func__
0920: 2c 20 23 62 75 66 66 65 72 4e 61 6d 65 2c 20 28 , #bufferName, (
0930: 75 6e 73 69 67 6e 65 64 20 6c 6f 6e 67 20 6c 6f unsigned long lo
0940: 6e 67 29 20 62 75 66 66 65 72 4c 65 6e 67 74 68 ng) bufferLength
0950: 29 3b 20 5c 0a 20 20 20 20 20 20 20 20 20 20 20 ); \.
0960: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0970: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0980: 20 20 20 20 20 20 66 6f 72 20 28 64 70 72 69 6e for (dprin
0990: 74 42 75 66 66 65 72 49 64 78 20 3d 20 30 3b 20 tBufferIdx = 0;
09a0: 64 70 72 69 6e 74 42 75 66 66 65 72 49 64 78 20 dprintBufferIdx
09b0: 3c 20 62 75 66 66 65 72 4c 65 6e 67 74 68 3b 20 < bufferLength;
09c0: 64 70 72 69 6e 74 42 75 66 66 65 72 49 64 78 2b dprintBufferIdx+
09d0: 2b 29 20 7b 20 5c 0a 20 20 20 20 20 20 20 20 20 +) { \.
09e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
09f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0a00: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0a10: 64 70 72 69 6e 74 42 75 66 66 65 72 43 68 61 72 dprintBufferChar
0a20: 20 3d 20 62 75 66 66 65 72 4e 61 6d 65 5b 64 70 = bufferName[dp
0a30: 72 69 6e 74 42 75 66 66 65 72 49 64 78 5d 3b 20 rintBufferIdx];
0a40: 5c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 \.
0a50: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0a60: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0a70: 20 20 20 20 20 20 20 20 20 20 20 69 66 20 28 69 if (i
0a80: 73 61 6c 70 68 61 28 64 70 72 69 6e 74 42 75 66 salpha(dprintBuf
0a90: 66 65 72 43 68 61 72 29 20 7c 7c 20 69 73 64 69 ferChar) || isdi
0aa0: 67 69 74 28 64 70 72 69 6e 74 42 75 66 66 65 72 git(dprintBuffer
0ab0: 43 68 61 72 29 29 20 7b 20 5c 0a 20 20 20 20 20 Char)) { \.
0ac0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0ad0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0ae0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0af0: 20 20 20 20 20 20 20 20 20 20 20 20 66 70 72 69 fpri
0b00: 6e 74 66 28 73 74 64 65 72 72 2c 20 22 27 25 63 ntf(stderr, "'%c
0b10: 27 20 22 2c 20 64 70 72 69 6e 74 42 75 66 66 65 ' ", dprintBuffe
0b20: 72 43 68 61 72 29 3b 20 5c 0a 20 20 20 20 20 20 rChar); \.
0b30: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0b40: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0b50: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0b60: 20 20 20 7d 20 65 6c 73 65 20 7b 20 5c 0a 20 20 } else { \.
0b70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0b80: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0b90: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0ba0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 66 f
0bb0: 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 printf(stderr, "
0bc0: 25 30 32 78 20 22 2c 20 28 75 6e 73 69 67 6e 65 %02x ", (unsigne
0bd0: 64 20 69 6e 74 29 20 64 70 72 69 6e 74 42 75 66 d int) dprintBuf
0be0: 66 65 72 43 68 61 72 29 3b 20 5c 0a 20 20 20 20 ferChar); \.
0bf0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0c00: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0c10: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0c20: 20 20 20 20 20 7d 3b 20 5c 0a 20 20 20 20 20 20 }; \.
0c30: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0c40: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0c50: 20 20 20 20 20 20 20 20 20 20 20 7d 3b 20 5c 0a }; \.
0c60: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0c70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0c80: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0c90: 20 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c fprintf(stderr,
0ca0: 20 22 7d 5c 6e 22 29 3b 20 5c 0a 20 20 20 20 20 "}\n"); \.
0cb0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0cc0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0cd0: 20 20 20 20 20 20 20 20 20 20 7d 0a 23 64 65 66 }.#def
0ce0: 69 6e 65 20 64 70 72 69 6e 74 46 6c 61 67 73 28 ine dprintFlags(
0cf0: 73 74 61 74 65 50 74 72 29 20 7b 20 5c 0a 20 20 statePtr) { \.
0d00: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0d10: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 63 68 ch
0d20: 61 72 20 64 70 72 69 6e 74 66 42 75 66 66 65 72 ar dprintfBuffer
0d30: 5b 38 31 39 32 5d 2c 20 2a 64 70 72 69 6e 74 66 [8192], *dprintf
0d40: 42 75 66 66 65 72 5f 70 3b 20 5c 0a 20 20 20 20 Buffer_p; \.
0d50: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0d60: 20 20 20 20 20 20 20 20 20 20 20 20 64 70 72 69 dpri
0d70: 6e 74 66 42 75 66 66 65 72 5f 70 20 3d 20 26 64 ntfBuffer_p = &d
0d80: 70 72 69 6e 74 66 42 75 66 66 65 72 5b 30 5d 3b printfBuffer[0];
0d90: 20 5c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 \.
0da0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0db0: 20 20 20 64 70 72 69 6e 74 66 42 75 66 66 65 72 dprintfBuffer
0dc0: 5f 70 20 2b 3d 20 73 70 72 69 6e 74 66 28 64 70 _p += sprintf(dp
0dd0: 72 69 6e 74 66 42 75 66 66 65 72 5f 70 2c 20 22 rintfBuffer_p, "
0de0: 25 73 3a 25 69 3a 25 73 28 29 3a 25 73 2d 3e 66 %s:%i:%s():%s->f
0df0: 6c 61 67 73 3d 30 22 2c 20 5f 5f 46 49 4c 45 5f lags=0", __FILE_
0e00: 5f 2c 20 5f 5f 4c 49 4e 45 5f 5f 2c 20 5f 5f 66 _, __LINE__, __f
0e10: 75 6e 63 5f 5f 2c 20 23 73 74 61 74 65 50 74 72 unc__, #statePtr
0e20: 29 3b 20 5c 0a 20 20 20 20 20 20 20 20 20 20 20 ); \.
0e30: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0e40: 20 20 20 20 20 69 66 20 28 28 28 73 74 61 74 65 if (((state
0e50: 50 74 72 29 2d 3e 66 6c 61 67 73 20 26 20 54 4c Ptr)->flags & TL
0e60: 53 5f 54 43 4c 5f 41 53 59 4e 43 29 20 3d 3d 20 S_TCL_ASYNC) ==
0e70: 54 4c 53 5f 54 43 4c 5f 41 53 59 4e 43 29 20 7b TLS_TCL_ASYNC) {
0e80: 20 64 70 72 69 6e 74 66 42 75 66 66 65 72 5f 70 dprintfBuffer_p
0e90: 20 2b 3d 20 73 70 72 69 6e 74 66 28 64 70 72 69 += sprintf(dpri
0ea0: 6e 74 66 42 75 66 66 65 72 5f 70 2c 20 22 7c 54 ntfBuffer_p, "|T
0eb0: 4c 53 5f 54 43 4c 5f 41 53 59 4e 43 22 29 3b 20 LS_TCL_ASYNC");
0ec0: 7d 3b 20 5c 0a 20 20 20 20 20 20 20 20 20 20 20 }; \.
0ed0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0ee0: 20 20 20 20 20 69 66 20 28 28 28 73 74 61 74 65 if (((state
0ef0: 50 74 72 29 2d 3e 66 6c 61 67 73 20 26 20 54 4c Ptr)->flags & TL
0f00: 53 5f 54 43 4c 5f 53 45 52 56 45 52 29 20 3d 3d S_TCL_SERVER) ==
0f10: 20 54 4c 53 5f 54 43 4c 5f 53 45 52 56 45 52 29 TLS_TCL_SERVER)
0f20: 20 7b 20 64 70 72 69 6e 74 66 42 75 66 66 65 72 { dprintfBuffer
0f30: 5f 70 20 2b 3d 20 73 70 72 69 6e 74 66 28 64 70 _p += sprintf(dp
0f40: 72 69 6e 74 66 42 75 66 66 65 72 5f 70 2c 20 22 rintfBuffer_p, "
0f50: 7c 54 4c 53 5f 54 43 4c 5f 53 45 52 56 45 52 22 |TLS_TCL_SERVER"
0f60: 29 3b 20 7d 3b 20 5c 0a 20 20 20 20 20 20 20 20 ); }; \.
0f70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0f80: 20 20 20 20 20 20 20 20 69 66 20 28 28 28 73 74 if (((st
0f90: 61 74 65 50 74 72 29 2d 3e 66 6c 61 67 73 20 26 atePtr)->flags &
0fa0: 20 54 4c 53 5f 54 43 4c 5f 49 4e 49 54 29 20 3d TLS_TCL_INIT) =
0fb0: 3d 20 54 4c 53 5f 54 43 4c 5f 49 4e 49 54 29 20 = TLS_TCL_INIT)
0fc0: 7b 20 64 70 72 69 6e 74 66 42 75 66 66 65 72 5f { dprintfBuffer_
0fd0: 70 20 2b 3d 20 73 70 72 69 6e 74 66 28 64 70 72 p += sprintf(dpr
0fe0: 69 6e 74 66 42 75 66 66 65 72 5f 70 2c 20 22 7c intfBuffer_p, "|
0ff0: 54 4c 53 5f 54 43 4c 5f 49 4e 49 54 22 29 3b 20 TLS_TCL_INIT");
1000: 7d 3b 20 5c 0a 20 20 20 20 20 20 20 20 20 20 20 }; \.
1010: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1020: 20 20 20 20 20 69 66 20 28 28 28 73 74 61 74 65 if (((state
1030: 50 74 72 29 2d 3e 66 6c 61 67 73 20 26 20 54 4c Ptr)->flags & TL
1040: 53 5f 54 43 4c 5f 44 45 42 55 47 29 20 3d 3d 20 S_TCL_DEBUG) ==
1050: 54 4c 53 5f 54 43 4c 5f 44 45 42 55 47 29 20 7b TLS_TCL_DEBUG) {
1060: 20 64 70 72 69 6e 74 66 42 75 66 66 65 72 5f 70 dprintfBuffer_p
1070: 20 2b 3d 20 73 70 72 69 6e 74 66 28 64 70 72 69 += sprintf(dpri
1080: 6e 74 66 42 75 66 66 65 72 5f 70 2c 20 22 7c 54 ntfBuffer_p, "|T
1090: 4c 53 5f 54 43 4c 5f 44 45 42 55 47 22 29 3b 20 LS_TCL_DEBUG");
10a0: 7d 3b 20 5c 0a 20 20 20 20 20 20 20 20 20 20 20 }; \.
10b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
10c0: 20 20 20 20 20 69 66 20 28 28 28 73 74 61 74 65 if (((state
10d0: 50 74 72 29 2d 3e 66 6c 61 67 73 20 26 20 54 4c Ptr)->flags & TL
10e0: 53 5f 54 43 4c 5f 43 41 4c 4c 42 41 43 4b 29 20 S_TCL_CALLBACK)
10f0: 3d 3d 20 54 4c 53 5f 54 43 4c 5f 43 41 4c 4c 42 == TLS_TCL_CALLB
1100: 41 43 4b 29 20 7b 20 64 70 72 69 6e 74 66 42 75 ACK) { dprintfBu
1110: 66 66 65 72 5f 70 20 2b 3d 20 73 70 72 69 6e 74 ffer_p += sprint
1120: 66 28 64 70 72 69 6e 74 66 42 75 66 66 65 72 5f f(dprintfBuffer_
1130: 70 2c 20 22 7c 54 4c 53 5f 54 43 4c 5f 43 41 4c p, "|TLS_TCL_CAL
1140: 4c 42 41 43 4b 22 29 3b 20 7d 3b 20 5c 0a 20 20 LBACK"); }; \.
1150: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1160: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69 66 if
1170: 20 28 28 28 73 74 61 74 65 50 74 72 29 2d 3e 66 (((statePtr)->f
1180: 6c 61 67 73 20 26 20 54 4c 53 5f 54 43 4c 5f 48 lags & TLS_TCL_H
1190: 41 4e 44 53 48 41 4b 45 5f 46 41 49 4c 45 44 29 ANDSHAKE_FAILED)
11a0: 20 3d 3d 20 54 4c 53 5f 54 43 4c 5f 48 41 4e 44 == TLS_TCL_HAND
11b0: 53 48 41 4b 45 5f 46 41 49 4c 45 44 29 20 7b 20 SHAKE_FAILED) {
11c0: 64 70 72 69 6e 74 66 42 75 66 66 65 72 5f 70 20 dprintfBuffer_p
11d0: 2b 3d 20 73 70 72 69 6e 74 66 28 64 70 72 69 6e += sprintf(dprin
11e0: 74 66 42 75 66 66 65 72 5f 70 2c 20 22 7c 54 4c tfBuffer_p, "|TL
11f0: 53 5f 54 43 4c 5f 48 41 4e 44 53 48 41 4b 45 5f S_TCL_HANDSHAKE_
1200: 46 41 49 4c 45 44 22 29 3b 20 7d 3b 20 5c 0a 20 FAILED"); }; \.
1210: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1220: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69 i
1230: 66 20 28 28 28 73 74 61 74 65 50 74 72 29 2d 3e f (((statePtr)->
1240: 66 6c 61 67 73 20 26 20 54 4c 53 5f 54 43 4c 5f flags & TLS_TCL_
1250: 46 41 53 54 50 41 54 48 29 20 3d 3d 20 54 4c 53 FASTPATH) == TLS
1260: 5f 54 43 4c 5f 46 41 53 54 50 41 54 48 29 20 7b _TCL_FASTPATH) {
1270: 20 64 70 72 69 6e 74 66 42 75 66 66 65 72 5f 70 dprintfBuffer_p
1280: 20 2b 3d 20 73 70 72 69 6e 74 66 28 64 70 72 69 += sprintf(dpri
1290: 6e 74 66 42 75 66 66 65 72 5f 70 2c 20 22 7c 54 ntfBuffer_p, "|T
12a0: 4c 53 5f 54 43 4c 5f 46 41 53 54 50 41 54 48 22 LS_TCL_FASTPATH"
12b0: 29 3b 20 7d 3b 20 5c 0a 20 20 20 20 20 20 20 20 ); }; \.
12c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
12d0: 20 20 20 20 20 20 20 20 66 70 72 69 6e 74 66 28 fprintf(
12e0: 73 74 64 65 72 72 2c 20 22 25 73 5c 6e 22 2c 20 stderr, "%s\n",
12f0: 64 70 72 69 6e 74 66 42 75 66 66 65 72 29 3b 20 dprintfBuffer);
1300: 5c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 \.
1310: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1320: 7d 0a 23 65 6c 73 65 0a 23 64 65 66 69 6e 65 20 }.#else.#define
1330: 64 70 72 69 6e 74 66 28 2e 2e 2e 29 20 69 66 20 dprintf(...) if
1340: 28 30 29 20 7b 20 66 70 72 69 6e 74 66 28 73 74 (0) { fprintf(st
1350: 64 65 72 72 2c 20 5f 5f 56 41 5f 41 52 47 53 5f derr, __VA_ARGS_
1360: 5f 29 3b 20 7d 0a 23 64 65 66 69 6e 65 20 64 70 _); }.#define dp
1370: 72 69 6e 74 42 75 66 66 65 72 28 62 75 66 66 65 rintBuffer(buffe
1380: 72 4e 61 6d 65 2c 20 62 75 66 66 65 72 4c 65 6e rName, bufferLen
1390: 67 74 68 29 20 2f 2a 2a 2f 0a 23 64 65 66 69 6e gth) /**/.#defin
13a0: 65 20 64 70 72 69 6e 74 46 6c 61 67 73 28 73 74 e dprintFlags(st
13b0: 61 74 65 50 74 72 29 20 2f 2a 2a 2f 0a 23 65 6e atePtr) /**/.#en
13c0: 64 69 66 0a 0a 23 64 65 66 69 6e 65 20 54 43 4c dif..#define TCL
13d0: 54 4c 53 5f 53 53 4c 5f 45 52 52 4f 52 28 73 73 TLS_SSL_ERROR(ss
13e0: 6c 2c 65 72 72 29 20 28 28 63 68 61 72 2a 29 45 l,err) ((char*)E
13f0: 52 52 5f 72 65 61 73 6f 6e 5f 65 72 72 6f 72 5f RR_reason_error_
1400: 73 74 72 69 6e 67 28 28 75 6e 73 69 67 6e 65 64 string((unsigned
1410: 20 6c 6f 6e 67 29 53 53 4c 5f 67 65 74 5f 65 72 long)SSL_get_er
1420: 72 6f 72 28 28 73 73 6c 29 2c 28 65 72 72 29 29 ror((ssl),(err))
1430: 29 29 0a 2f 2a 0a 20 2a 20 4f 70 65 6e 53 53 4c ))./*. * OpenSSL
1440: 20 42 49 4f 20 52 6f 75 74 69 6e 65 73 0a 20 2a BIO Routines. *
1450: 2f 0a 23 64 65 66 69 6e 65 20 42 49 4f 5f 54 59 /.#define BIO_TY
1460: 50 45 5f 54 43 4c 09 28 31 39 7c 30 78 30 34 30 PE_TCL.(19|0x040
1470: 30 29 0a 0a 2f 2a 0a 20 2a 20 44 65 66 69 6e 65 0)../*. * Define
1480: 73 20 66 6f 72 20 53 74 61 74 65 2e 66 6c 61 67 s for State.flag
1490: 73 0a 20 2a 2f 0a 23 64 65 66 69 6e 65 20 54 4c s. */.#define TL
14a0: 53 5f 54 43 4c 5f 41 53 59 4e 43 09 28 31 3c 3c S_TCL_ASYNC.(1<<
14b0: 30 29 09 2f 2a 20 6e 6f 6e 2d 62 6c 6f 63 6b 69 0)./* non-blocki
14c0: 6e 67 20 6d 6f 64 65 20 2a 2f 0a 23 64 65 66 69 ng mode */.#defi
14d0: 6e 65 20 54 4c 53 5f 54 43 4c 5f 53 45 52 56 45 ne TLS_TCL_SERVE
14e0: 52 09 28 31 3c 3c 31 29 09 2f 2a 20 53 65 72 76 R.(1<<1)./* Serv
14f0: 65 72 2d 53 69 64 65 20 2a 2f 0a 23 64 65 66 69 er-Side */.#defi
1500: 6e 65 20 54 4c 53 5f 54 43 4c 5f 49 4e 49 54 09 ne TLS_TCL_INIT.
1510: 28 31 3c 3c 32 29 09 2f 2a 20 49 6e 69 74 69 61 (1<<2)./* Initia
1520: 6c 69 7a 69 6e 67 20 63 6f 6e 6e 65 63 74 69 6f lizing connectio
1530: 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 54 4c 53 n */.#define TLS
1540: 5f 54 43 4c 5f 44 45 42 55 47 09 28 31 3c 3c 33 _TCL_DEBUG.(1<<3
1550: 29 09 2f 2a 20 53 68 6f 77 20 64 65 62 75 67 20 )./* Show debug
1560: 74 72 61 63 69 6e 67 20 2a 2f 0a 23 64 65 66 69 tracing */.#defi
1570: 6e 65 20 54 4c 53 5f 54 43 4c 5f 43 41 4c 4c 42 ne TLS_TCL_CALLB
1580: 41 43 4b 09 28 31 3c 3c 34 29 09 2f 2a 20 49 6e ACK.(1<<4)./* In
1590: 20 61 20 63 61 6c 6c 62 61 63 6b 2c 20 70 72 65 a callback, pre
15a0: 76 65 6e 74 20 75 70 64 61 74 65 0a 09 09 09 09 vent update.....
15b0: 09 20 2a 20 6c 6f 6f 70 69 6e 67 20 70 72 6f 62 . * looping prob
15c0: 6c 65 6d 2e 20 5b 42 75 67 20 31 36 35 32 33 38 lem. [Bug 165238
15d0: 30 5d 20 2a 2f 0a 23 64 65 66 69 6e 65 20 54 4c 0] */.#define TL
15e0: 53 5f 54 43 4c 5f 48 41 4e 44 53 48 41 4b 45 5f S_TCL_HANDSHAKE_
15f0: 46 41 49 4c 45 44 20 28 31 3c 3c 35 29 20 2f 2a FAILED (1<<5) /*
1600: 20 53 65 74 20 6f 6e 20 68 61 6e 64 73 68 61 6b Set on handshak
1610: 65 20 66 61 69 6c 75 72 65 73 20 61 6e 64 20 6f e failures and o
1620: 6e 63 65 0a 20 20 20 20 20 20 20 20 20 20 20 20 nce.
1630: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1640: 20 20 20 20 20 20 20 20 20 20 20 20 20 2a 20 73 * s
1650: 65 74 2c 20 61 6c 6c 20 66 75 72 74 68 65 72 20 et, all further
1660: 49 2f 4f 20 77 69 6c 6c 20 72 65 73 75 6c 74 0a I/O will result.
1670: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1680: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1690: 20 20 20 20 20 20 20 20 20 2a 20 69 6e 20 45 43 * in EC
16a0: 4f 4e 4e 41 42 4f 52 54 45 44 20 65 72 72 6f 72 ONNABORTED error
16b0: 73 2e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 54 4c s. */.#define TL
16c0: 53 5f 54 43 4c 5f 46 41 53 54 50 41 54 48 20 28 S_TCL_FASTPATH (
16d0: 31 3c 3c 36 29 20 20 20 20 20 20 20 20 20 2f 2a 1<<6) /*
16e0: 20 54 68 65 20 70 61 72 65 6e 74 20 63 68 61 6e The parent chan
16f0: 6e 65 6c 20 69 73 20 62 65 69 6e 67 20 75 73 65 nel is being use
1700: 64 20 64 69 72 65 63 74 6c 79 20 62 79 20 74 68 d directly by th
1710: 65 20 53 53 4c 20 6c 69 62 72 61 72 79 20 2a 2f e SSL library */
1720: 0a 23 64 65 66 69 6e 65 20 54 4c 53 5f 54 43 4c .#define TLS_TCL
1730: 5f 44 45 4c 41 59 20 28 35 29 0a 0a 2f 2a 0a 20 _DELAY (5)../*.
1740: 2a 20 54 68 69 73 20 73 74 72 75 63 74 75 72 65 * This structure
1750: 20 64 65 73 63 72 69 62 65 73 20 74 68 65 20 70 describes the p
1760: 65 72 2d 69 6e 73 74 61 6e 63 65 20 73 74 61 74 er-instance stat
1770: 65 0a 20 2a 20 6f 66 20 61 6e 20 73 73 6c 20 63 e. * of an ssl c
1780: 68 61 6e 6e 65 6c 2e 0a 20 2a 0a 20 2a 20 54 68 hannel.. *. * Th
1790: 65 20 53 53 4c 20 70 72 6f 63 65 73 73 69 6e 67 e SSL processing
17a0: 20 63 6f 6e 74 65 78 74 20 69 73 20 6d 61 69 6e context is main
17b0: 74 61 69 6e 65 64 20 68 65 72 65 2c 20 69 6e 20 tained here, in
17c0: 74 68 65 20 43 6c 69 65 6e 74 44 61 74 61 0a 20 the ClientData.
17d0: 2a 2f 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 */.typedef struc
17e0: 74 20 53 74 61 74 65 20 7b 0a 09 54 63 6c 5f 43 t State {..Tcl_C
17f0: 68 61 6e 6e 65 6c 20 73 65 6c 66 3b 20 20 20 20 hannel self;
1800: 20 20 20 2f 2a 20 74 68 69 73 20 73 6f 63 6b 65 /* this socke
1810: 74 20 63 68 61 6e 6e 65 6c 20 2a 2f 0a 09 54 63 t channel */..Tc
1820: 6c 5f 54 69 6d 65 72 54 6f 6b 65 6e 20 74 69 6d l_TimerToken tim
1830: 65 72 3b 0a 0a 09 69 6e 74 20 66 6c 61 67 73 3b er;...int flags;
1840: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
1850: 20 73 65 65 20 53 74 61 74 65 2e 66 6c 61 67 73 see State.flags
1860: 20 61 62 6f 76 65 20 20 2a 2f 0a 09 69 6e 74 20 above */..int
1870: 77 61 74 63 68 4d 61 73 6b 3b 20 20 20 20 20 20 watchMask;
1880: 20 20 20 20 2f 2a 20 63 75 72 72 65 6e 74 20 57 /* current W
1890: 61 74 63 68 50 72 6f 63 20 6d 61 73 6b 20 2a 2f atchProc mask */
18a0: 0a 09 69 6e 74 20 6d 6f 64 65 3b 20 20 20 20 20 ..int mode;
18b0: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 63 75 72 /* cur
18c0: 72 65 6e 74 20 6d 6f 64 65 20 6f 66 20 70 61 72 rent mode of par
18d0: 65 6e 74 20 63 68 61 6e 6e 65 6c 20 2a 2f 0a 0a ent channel */..
18e0: 09 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 .Tcl_Interp *int
18f0: 65 72 70 3b 20 20 20 20 20 2f 2a 20 69 6e 74 65 erp; /* inte
1900: 72 70 72 65 74 65 72 20 69 6e 20 77 68 69 63 68 rpreter in which
1910: 20 74 68 69 73 20 72 65 73 69 64 65 73 20 2a 2f this resides */
1920: 0a 09 54 63 6c 5f 4f 62 6a 20 2a 63 61 6c 6c 62 ..Tcl_Obj *callb
1930: 61 63 6b 3b 20 20 20 20 20 20 2f 2a 20 73 63 72 ack; /* scr
1940: 69 70 74 20 63 61 6c 6c 65 64 20 66 6f 72 20 74 ipt called for t
1950: 72 61 63 69 6e 67 2c 20 76 65 72 69 66 79 69 6e racing, verifyin
1960: 67 20 61 6e 64 20 65 72 72 6f 72 73 20 2a 2f 0a g and errors */.
1970: 09 54 63 6c 5f 4f 62 6a 20 2a 70 61 73 73 77 6f .Tcl_Obj *passwo
1980: 72 64 3b 20 20 20 20 20 20 2f 2a 20 73 63 72 69 rd; /* scri
1990: 70 74 20 63 61 6c 6c 65 64 20 66 6f 72 20 63 65 pt called for ce
19a0: 72 74 69 66 69 63 61 74 65 20 70 61 73 73 77 6f rtificate passwo
19b0: 72 64 20 2a 2f 0a 0a 09 69 6e 74 20 76 66 6c 61 rd */...int vfla
19c0: 67 73 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 gs;
19d0: 2f 2a 20 76 65 72 69 66 79 20 66 6c 61 67 73 20 /* verify flags
19e0: 2a 2f 0a 09 53 53 4c 20 2a 73 73 6c 3b 20 20 20 */..SSL *ssl;
19f0: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 53 /* S
1a00: 74 72 75 63 74 20 66 6f 72 20 53 53 4c 20 70 72 truct for SSL pr
1a10: 6f 63 65 73 73 69 6e 67 20 2a 2f 0a 09 53 53 4c ocessing */..SSL
1a20: 5f 43 54 58 20 2a 63 74 78 3b 20 20 20 20 20 20 _CTX *ctx;
1a30: 20 20 20 20 20 2f 2a 20 53 53 4c 20 43 6f 6e 74 /* SSL Cont
1a40: 65 78 74 20 2a 2f 0a 09 42 49 4f 20 2a 62 69 6f ext */..BIO *bio
1a50: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
1a60: 2f 2a 20 53 74 72 75 63 74 20 66 6f 72 20 53 53 /* Struct for SS
1a70: 4c 20 70 72 6f 63 65 73 73 69 6e 67 20 2a 2f 0a L processing */.
1a80: 09 42 49 4f 20 2a 70 5f 62 69 6f 3b 20 20 20 20 .BIO *p_bio;
1a90: 20 20 20 20 20 20 20 20 20 2f 2a 20 50 61 72 65 /* Pare
1aa0: 6e 74 20 42 49 4f 20 28 74 68 61 74 20 69 73 20 nt BIO (that is
1ab0: 6c 61 79 65 72 65 64 20 6f 6e 20 54 63 6c 5f 43 layered on Tcl_C
1ac0: 68 61 6e 6e 65 6c 29 20 2a 2f 0a 0a 09 63 6f 6e hannel) */...con
1ad0: 73 74 20 63 68 61 72 20 2a 65 72 72 3b 0a 7d 20 st char *err;.}
1ae0: 53 74 61 74 65 3b 0a 0a 23 69 66 64 65 66 20 55 State;..#ifdef U
1af0: 53 45 5f 54 43 4c 5f 53 54 55 42 53 0a 23 69 66 SE_TCL_STUBS.#if
1b00: 6e 64 65 66 20 54 63 6c 5f 53 74 61 63 6b 43 68 ndef Tcl_StackCh
1b10: 61 6e 6e 65 6c 0a 23 65 72 72 6f 72 20 22 55 6e annel.#error "Un
1b20: 61 62 6c 65 20 74 6f 20 63 6f 6d 70 69 6c 65 20 able to compile
1b30: 6f 6e 20 74 68 69 73 20 76 65 72 73 69 6f 6e 20 on this version
1b40: 6f 66 20 54 63 6c 22 0a 23 65 6e 64 69 66 20 2f of Tcl".#endif /
1b50: 2a 20 54 63 6c 5f 47 65 74 53 74 61 63 6b 65 64 * Tcl_GetStacked
1b60: 43 68 61 6e 6e 65 6c 20 2a 2f 0a 23 65 6e 64 69 Channel */.#endi
1b70: 66 20 2f 2a 20 55 53 45 5f 54 43 4c 5f 53 54 55 f /* USE_TCL_STU
1b80: 42 53 20 2a 2f 0a 0a 23 69 66 6e 64 65 66 20 4a BS */..#ifndef J
1b90: 4f 49 4e 0a 23 20 20 64 65 66 69 6e 65 20 4a 4f OIN.# define JO
1ba0: 49 4e 28 61 2c 62 29 20 4a 4f 49 4e 31 28 61 2c IN(a,b) JOIN1(a,
1bb0: 62 29 0a 23 20 20 64 65 66 69 6e 65 20 4a 4f 49 b).# define JOI
1bc0: 4e 31 28 61 2c 62 29 20 61 23 23 62 0a 23 65 6e N1(a,b) a##b.#en
1bd0: 64 69 66 0a 0a 23 69 66 6e 64 65 66 20 54 43 4c dif..#ifndef TCL
1be0: 5f 55 4e 55 53 45 44 0a 23 20 69 66 20 64 65 66 _UNUSED.# if def
1bf0: 69 6e 65 64 28 5f 5f 63 70 6c 75 73 70 6c 75 73 ined(__cplusplus
1c00: 29 0a 23 20 20 20 64 65 66 69 6e 65 20 54 43 4c ).# define TCL
1c10: 5f 55 4e 55 53 45 44 28 54 29 20 54 0a 23 20 65 _UNUSED(T) T.# e
1c20: 6c 69 66 20 64 65 66 69 6e 65 64 28 5f 5f 47 4e lif defined(__GN
1c30: 55 43 5f 5f 29 20 26 26 20 28 5f 5f 47 4e 55 43 UC__) && (__GNUC
1c40: 5f 5f 20 3e 20 32 29 0a 23 20 20 20 64 65 66 69 __ > 2).# defi
1c50: 6e 65 20 54 43 4c 5f 55 4e 55 53 45 44 28 54 29 ne TCL_UNUSED(T)
1c60: 20 54 20 4a 4f 49 4e 28 64 75 6d 6d 79 2c 20 5f T JOIN(dummy, _
1c70: 5f 4c 49 4e 45 5f 5f 29 20 5f 5f 61 74 74 72 69 _LINE__) __attri
1c80: 62 75 74 65 5f 5f 28 28 75 6e 75 73 65 64 29 29 bute__((unused))
1c90: 0a 23 20 65 6c 73 65 0a 23 20 20 20 64 65 66 69 .# else.# defi
1ca0: 6e 65 20 54 43 4c 5f 55 4e 55 53 45 44 28 54 29 ne TCL_UNUSED(T)
1cb0: 20 54 20 4a 4f 49 4e 28 64 75 6d 6d 79 2c 20 5f T JOIN(dummy, _
1cc0: 5f 4c 49 4e 45 5f 5f 29 0a 23 20 65 6e 64 69 66 _LINE__).# endif
1cd0: 0a 23 65 6e 64 69 66 0a 0a 23 69 66 20 28 54 43 .#endif..#if (TC
1ce0: 4c 5f 4d 41 4a 4f 52 5f 56 45 52 53 49 4f 4e 20 L_MAJOR_VERSION
1cf0: 3c 20 39 29 20 26 26 20 64 65 66 69 6e 65 64 28 < 9) && defined(
1d00: 54 43 4c 5f 4d 49 4e 4f 52 5f 56 45 52 53 49 4f TCL_MINOR_VERSIO
1d10: 4e 29 20 26 26 20 28 54 43 4c 5f 4d 49 4e 4f 52 N) && (TCL_MINOR
1d20: 5f 56 45 52 53 49 4f 4e 20 3c 20 37 29 20 26 26 _VERSION < 7) &&
1d30: 20 21 64 65 66 69 6e 65 64 28 54 63 6c 5f 53 69 !defined(Tcl_Si
1d40: 7a 65 29 0a 23 20 20 20 64 65 66 69 6e 65 20 54 ze).# define T
1d50: 63 6c 5f 53 69 7a 65 20 69 6e 74 0a 23 65 6e 64 cl_Size int.#end
1d60: 69 66 0a 0a 2f 2a 0a 20 2a 20 46 6f 72 77 61 72 if../*. * Forwar
1d70: 64 20 64 65 63 6c 61 72 61 74 69 6f 6e 73 0a 20 d declarations.
1d80: 2a 2f 0a 63 6f 6e 73 74 20 54 63 6c 5f 43 68 61 */.const Tcl_Cha
1d90: 6e 6e 65 6c 54 79 70 65 20 2a 54 6c 73 5f 43 68 nnelType *Tls_Ch
1da0: 61 6e 6e 65 6c 54 79 70 65 28 76 6f 69 64 29 3b annelType(void);
1db0: 0a 54 63 6c 5f 43 68 61 6e 6e 65 6c 20 20 20 20 .Tcl_Channel
1dc0: 20 54 6c 73 5f 47 65 74 50 61 72 65 6e 74 28 53 Tls_GetParent(S
1dd0: 74 61 74 65 20 2a 73 74 61 74 65 50 74 72 2c 20 tate *statePtr,
1de0: 69 6e 74 20 6d 61 73 6b 46 6c 61 67 73 29 3b 0a int maskFlags);.
1df0: 0a 54 63 6c 5f 4f 62 6a 20 20 20 20 20 20 20 20 .Tcl_Obj
1e00: 20 2a 54 6c 73 5f 4e 65 77 58 35 30 39 4f 62 6a *Tls_NewX509Obj
1e10: 28 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 (Tcl_Interp *int
1e20: 65 72 70 2c 20 58 35 30 39 20 2a 63 65 72 74 29 erp, X509 *cert)
1e30: 3b 0a 76 6f 69 64 20 20 20 20 20 20 20 20 20 20 ;.void
1e40: 20 20 54 6c 73 5f 45 72 72 6f 72 28 53 74 61 74 Tls_Error(Stat
1e50: 65 20 2a 73 74 61 74 65 50 74 72 2c 20 63 68 61 e *statePtr, cha
1e60: 72 20 2a 6d 73 67 29 3b 0a 23 69 66 20 54 43 4c r *msg);.#if TCL
1e70: 5f 4d 41 4a 4f 52 5f 56 45 52 53 49 4f 4e 20 3e _MAJOR_VERSION >
1e80: 20 38 0a 76 6f 69 64 20 20 20 20 20 20 20 20 20 8.void
1e90: 20 20 20 54 6c 73 5f 46 72 65 65 28 76 6f 69 64 Tls_Free(void
1ea0: 20 2a 62 6c 6f 63 6b 50 74 72 29 3b 0a 23 65 6c *blockPtr);.#el
1eb0: 73 65 0a 76 6f 69 64 20 20 20 20 20 20 20 20 20 se.void
1ec0: 20 20 20 54 6c 73 5f 46 72 65 65 28 63 68 61 72 Tls_Free(char
1ed0: 20 2a 62 6c 6f 63 6b 50 74 72 29 3b 0a 23 65 6e *blockPtr);.#en
1ee0: 64 69 66 0a 76 6f 69 64 20 20 20 20 20 20 20 20 dif.void
1ef0: 20 20 20 20 54 6c 73 5f 43 6c 65 61 6e 28 53 74 Tls_Clean(St
1f00: 61 74 65 20 2a 73 74 61 74 65 50 74 72 29 3b 0a ate *statePtr);.
1f10: 69 6e 74 20 20 20 20 20 20 20 20 20 20 20 20 20 int
1f20: 54 6c 73 5f 57 61 69 74 46 6f 72 43 6f 6e 6e 65 Tls_WaitForConne
1f30: 63 74 28 53 74 61 74 65 20 2a 73 74 61 74 65 50 ct(State *stateP
1f40: 74 72 2c 20 69 6e 74 20 2a 65 72 72 6f 72 43 6f tr, int *errorCo
1f50: 64 65 50 74 72 2c 20 69 6e 74 20 68 61 6e 64 73 dePtr, int hands
1f60: 68 61 6b 65 46 61 69 6c 75 72 65 49 73 50 65 72 hakeFailureIsPer
1f70: 6d 61 6e 65 6e 74 29 3b 0a 0a 42 49 4f 20 20 20 manent);..BIO
1f80: 20 20 20 20 20 20 20 20 20 20 2a 42 49 4f 5f 6e *BIO_n
1f90: 65 77 5f 74 63 6c 28 53 74 61 74 65 2a 20 73 74 ew_tcl(State* st
1fa0: 61 74 65 50 74 72 2c 20 69 6e 74 20 66 6c 61 67 atePtr, int flag
1fb0: 73 29 3b 0a 0a 23 64 65 66 69 6e 65 20 50 54 52 s);..#define PTR
1fc0: 32 49 4e 54 28 78 29 20 28 28 69 6e 74 29 20 28 2INT(x) ((int) (
1fd0: 28 69 6e 74 70 74 72 5f 74 29 20 28 78 29 29 29 (intptr_t) (x)))
1fe0: 0a 0a 23 65 6e 64 69 66 20 2f 2a 20 5f 54 4c 53 ..#endif /* _TLS
1ff0: 49 4e 54 5f 48 20 2a 2f 0a INT_H */.