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 4f 50 45 4e 53 53 4c 5f 48 45 41 fdef OPENSSL_HEA
02f0: 44 45 52 5f 50 52 45 46 49 58 0a 23 20 20 64 65 DER_PREFIX.# de
0300: 66 69 6e 65 20 4f 50 45 4e 53 53 4c 5f 48 45 41 fine OPENSSL_HEA
0310: 44 45 52 28 68 65 61 64 65 72 29 20 3c 4f 50 45 DER(header) <OPE
0320: 4e 53 53 4c 5f 48 45 41 44 45 52 5f 50 52 45 46 NSSL_HEADER_PREF
0330: 49 58 2f 68 65 61 64 65 72 3e 0a 23 65 6c 73 65 IX/header>.#else
0340: 0a 23 20 20 64 65 66 69 6e 65 20 4f 50 45 4e 53 .# define OPENS
0350: 53 4c 5f 48 45 41 44 45 52 28 68 65 61 64 65 72 SL_HEADER(header
0360: 29 20 3c 68 65 61 64 65 72 3e 0a 23 65 6e 64 69 ) <header>.#endi
0370: 66 0a 0a 23 69 66 64 65 66 20 5f 5f 57 49 4e 33 f..#ifdef __WIN3
0380: 32 5f 5f 0a 23 64 65 66 69 6e 65 20 57 49 4e 33 2__.#define WIN3
0390: 32 5f 4c 45 41 4e 5f 41 4e 44 5f 4d 45 41 4e 0a 2_LEAN_AND_MEAN.
03a0: 23 69 6e 63 6c 75 64 65 20 3c 77 69 6e 64 6f 77 #include <window
03b0: 73 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 77 s.h>.#include <w
03c0: 69 6e 63 72 79 70 74 2e 68 3e 20 2f 2a 20 4f 70 incrypt.h> /* Op
03d0: 65 6e 53 53 4c 20 6e 65 65 64 73 20 74 68 69 73 enSSL needs this
03e0: 20 6f 6e 20 57 69 6e 64 6f 77 73 20 2a 2f 0a 23 on Windows */.#
03f0: 65 6e 64 69 66 0a 0a 2f 2a 20 48 61 6e 64 6c 65 endif../* Handle
0400: 20 74 63 6c 38 2e 33 2d 3e 74 63 6c 38 2e 34 20 tcl8.3->tcl8.4
0410: 43 4f 4e 53 54 20 63 68 61 6e 67 65 73 20 2a 2f CONST changes */
0420: 0a 23 69 66 6e 64 65 66 20 43 4f 4e 53 54 38 34 .#ifndef CONST84
0430: 0a 23 64 65 66 69 6e 65 20 43 4f 4e 53 54 38 34 .#define CONST84
0440: 0a 23 65 6e 64 69 66 0a 0a 23 69 66 64 65 66 20 .#endif..#ifdef
0450: 4e 4f 5f 50 41 54 45 4e 54 53 0a 23 20 20 64 65 NO_PATENTS.# de
0460: 66 69 6e 65 20 4e 4f 5f 49 44 45 41 0a 23 20 20 fine NO_IDEA.#
0470: 64 65 66 69 6e 65 20 4e 4f 5f 52 43 32 0a 23 20 define NO_RC2.#
0480: 20 64 65 66 69 6e 65 20 4e 4f 5f 52 43 34 0a 23 define NO_RC4.#
0490: 20 20 64 65 66 69 6e 65 20 4e 4f 5f 52 43 35 0a define NO_RC5.
04a0: 23 20 20 64 65 66 69 6e 65 20 4e 4f 5f 52 53 41 # define NO_RSA
04b0: 0a 23 20 20 69 66 6e 64 65 66 20 4e 4f 5f 53 53 .# ifndef NO_SS
04c0: 4c 32 0a 23 20 20 20 20 64 65 66 69 6e 65 20 4e L2.# define N
04d0: 4f 5f 53 53 4c 32 0a 23 20 20 65 6e 64 69 66 0a O_SSL2.# endif.
04e0: 23 65 6e 64 69 66 0a 0a 23 69 6e 63 6c 75 64 65 #endif..#include
04f0: 20 4f 50 45 4e 53 53 4c 5f 48 45 41 44 45 52 28 OPENSSL_HEADER(
0500: 6f 70 65 6e 73 73 6c 2f 73 73 6c 2e 68 29 0a 23 openssl/ssl.h).#
0510: 69 6e 63 6c 75 64 65 20 4f 50 45 4e 53 53 4c 5f include OPENSSL_
0520: 48 45 41 44 45 52 28 6f 70 65 6e 73 73 6c 2f 65 HEADER(openssl/e
0530: 72 72 2e 68 29 0a 23 69 6e 63 6c 75 64 65 20 4f rr.h).#include O
0540: 50 45 4e 53 53 4c 5f 48 45 41 44 45 52 28 6f 70 PENSSL_HEADER(op
0550: 65 6e 73 73 6c 2f 72 61 6e 64 2e 68 29 0a 23 69 enssl/rand.h).#i
0560: 6e 63 6c 75 64 65 20 4f 50 45 4e 53 53 4c 5f 48 nclude OPENSSL_H
0570: 45 41 44 45 52 28 6f 70 65 6e 73 73 6c 2f 6f 70 EADER(openssl/op
0580: 65 6e 73 73 6c 76 2e 68 29 0a 0a 2f 2a 0a 20 2a ensslv.h)../*. *
0590: 20 44 65 74 65 72 6d 69 6e 65 20 69 66 20 77 65 Determine if we
05a0: 20 73 68 6f 75 6c 64 20 75 73 65 20 74 68 65 20 should use the
05b0: 70 72 65 2d 4f 70 65 6e 53 53 4c 20 31 2e 31 2e pre-OpenSSL 1.1.
05c0: 30 20 41 50 49 0a 20 2a 2f 0a 23 75 6e 64 65 66 0 API. */.#undef
05d0: 20 54 43 4c 54 4c 53 5f 4f 50 45 4e 53 53 4c 5f TCLTLS_OPENSSL_
05e0: 50 52 45 5f 31 5f 31 0a 23 69 66 20 28 64 65 66 PRE_1_1.#if (def
05f0: 69 6e 65 64 28 4c 49 42 52 45 53 53 4c 5f 56 45 ined(LIBRESSL_VE
0600: 52 53 49 4f 4e 5f 4e 55 4d 42 45 52 29 29 20 7c RSION_NUMBER)) |
0610: 7c 20 4f 50 45 4e 53 53 4c 5f 56 45 52 53 49 4f | OPENSSL_VERSIO
0620: 4e 5f 4e 55 4d 42 45 52 20 3c 20 30 78 31 30 31 N_NUMBER < 0x101
0630: 30 30 30 30 30 4c 0a 23 20 20 64 65 66 69 6e 65 00000L.# define
0640: 20 54 43 4c 54 4c 53 5f 4f 50 45 4e 53 53 4c 5f TCLTLS_OPENSSL_
0650: 50 52 45 5f 31 5f 31 5f 41 50 49 20 31 0a 23 65 PRE_1_1_API 1.#e
0660: 6e 64 69 66 0a 0a 23 69 66 6e 64 65 66 20 45 43 ndif..#ifndef EC
0670: 4f 4e 4e 41 42 4f 52 54 45 44 0a 23 64 65 66 69 ONNABORTED.#defi
0680: 6e 65 20 45 43 4f 4e 4e 41 42 4f 52 54 45 44 09 ne ECONNABORTED.
0690: 31 33 30 09 2f 2a 20 53 6f 66 74 77 61 72 65 20 130./* Software
06a0: 63 61 75 73 65 64 20 63 6f 6e 6e 65 63 74 69 6f caused connectio
06b0: 6e 20 61 62 6f 72 74 20 2a 2f 0a 23 65 6e 64 69 n abort */.#endi
06c0: 66 0a 23 69 66 6e 64 65 66 20 45 43 4f 4e 4e 52 f.#ifndef ECONNR
06d0: 45 53 45 54 0a 23 64 65 66 69 6e 65 20 45 43 4f ESET.#define ECO
06e0: 4e 4e 52 45 53 45 54 09 31 33 31 09 2f 2a 20 43 NNRESET.131./* C
06f0: 6f 6e 6e 65 63 74 69 6f 6e 20 72 65 73 65 74 20 onnection reset
0700: 62 79 20 70 65 65 72 20 2a 2f 0a 23 65 6e 64 69 by peer */.#endi
0710: 66 0a 0a 23 69 66 64 65 66 20 54 43 4c 45 58 54 f..#ifdef TCLEXT
0720: 5f 54 43 4c 54 4c 53 5f 44 45 42 55 47 0a 23 69 _TCLTLS_DEBUG.#i
0730: 6e 63 6c 75 64 65 20 3c 63 74 79 70 65 2e 68 3e nclude <ctype.h>
0740: 0a 23 64 65 66 69 6e 65 20 64 70 72 69 6e 74 66 .#define dprintf
0750: 28 2e 2e 2e 29 20 7b 20 5c 0a 20 20 20 20 20 20 (...) { \.
0760: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0770: 20 63 68 61 72 20 64 70 72 69 6e 74 66 42 75 66 char dprintfBuf
0780: 66 65 72 5b 38 31 39 32 5d 2c 20 2a 64 70 72 69 fer[8192], *dpri
0790: 6e 74 66 42 75 66 66 65 72 5f 70 3b 20 5c 0a 20 ntfBuffer_p; \.
07a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
07b0: 20 20 20 20 20 20 64 70 72 69 6e 74 66 42 75 66 dprintfBuf
07c0: 66 65 72 5f 70 20 3d 20 26 64 70 72 69 6e 74 66 fer_p = &dprintf
07d0: 42 75 66 66 65 72 5b 30 5d 3b 20 5c 0a 20 20 20 Buffer[0]; \.
07e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
07f0: 20 20 20 20 64 70 72 69 6e 74 66 42 75 66 66 65 dprintfBuffe
0800: 72 5f 70 20 2b 3d 20 73 70 72 69 6e 74 66 28 64 r_p += sprintf(d
0810: 70 72 69 6e 74 66 42 75 66 66 65 72 5f 70 2c 20 printfBuffer_p,
0820: 22 25 73 3a 25 69 3a 25 73 28 29 3a 22 2c 20 5f "%s:%i:%s():", _
0830: 5f 46 49 4c 45 5f 5f 2c 20 5f 5f 4c 49 4e 45 5f _FILE__, __LINE_
0840: 5f 2c 20 5f 5f 66 75 6e 63 5f 5f 29 3b 20 5c 0a _, __func__); \.
0850: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0860: 20 20 20 20 20 20 20 64 70 72 69 6e 74 66 42 75 dprintfBu
0870: 66 66 65 72 5f 70 20 2b 3d 20 73 70 72 69 6e 74 ffer_p += sprint
0880: 66 28 64 70 72 69 6e 74 66 42 75 66 66 65 72 5f f(dprintfBuffer_
0890: 70 2c 20 5f 5f 56 41 5f 41 52 47 53 5f 5f 29 3b p, __VA_ARGS__);
08a0: 20 5c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 \.
08b0: 20 20 20 20 20 20 20 20 20 20 66 70 72 69 6e 74 fprint
08c0: 66 28 73 74 64 65 72 72 2c 20 22 25 73 5c 6e 22 f(stderr, "%s\n"
08d0: 2c 20 64 70 72 69 6e 74 66 42 75 66 66 65 72 29 , dprintfBuffer)
08e0: 3b 20 5c 0a 20 20 20 20 20 20 20 20 20 20 20 20 ; \.
08f0: 20 20 20 20 20 20 20 20 20 7d 0a 23 64 65 66 69 }.#defi
0900: 6e 65 20 64 70 72 69 6e 74 42 75 66 66 65 72 28 ne dprintBuffer(
0910: 62 75 66 66 65 72 4e 61 6d 65 2c 20 62 75 66 66 bufferName, buff
0920: 65 72 4c 65 6e 67 74 68 29 20 7b 20 5c 0a 20 20 erLength) { \.
0930: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0940: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0950: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69 i
0960: 6e 74 20 64 70 72 69 6e 74 42 75 66 66 65 72 49 nt dprintBufferI
0970: 64 78 3b 20 5c 0a 20 20 20 20 20 20 20 20 20 20 dx; \.
0980: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0990: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
09a0: 20 20 20 20 20 20 20 75 6e 73 69 67 6e 65 64 20 unsigned
09b0: 63 68 61 72 20 64 70 72 69 6e 74 42 75 66 66 65 char dprintBuffe
09c0: 72 43 68 61 72 3b 20 5c 0a 20 20 20 20 20 20 20 rChar; \.
09d0: 20 20 20 20 20 20 20 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 66 70 72 69 6e 74 fprint
0a00: 66 28 73 74 64 65 72 72 2c 20 22 25 73 3a 25 69 f(stderr, "%s:%i
0a10: 3a 25 73 28 29 3a 25 73 5b 25 6c 6c 75 5d 3d 7b :%s():%s[%llu]={
0a20: 22 2c 20 5f 5f 46 49 4c 45 5f 5f 2c 20 5f 5f 4c ", __FILE__, __L
0a30: 49 4e 45 5f 5f 2c 20 5f 5f 66 75 6e 63 5f 5f 2c INE__, __func__,
0a40: 20 23 62 75 66 66 65 72 4e 61 6d 65 2c 20 28 75 #bufferName, (u
0a50: 6e 73 69 67 6e 65 64 20 6c 6f 6e 67 20 6c 6f 6e nsigned long lon
0a60: 67 29 20 62 75 66 66 65 72 4c 65 6e 67 74 68 29 g) bufferLength)
0a70: 3b 20 5c 0a 20 20 20 20 20 20 20 20 20 20 20 20 ; \.
0a80: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0a90: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0aa0: 20 20 20 20 20 66 6f 72 20 28 64 70 72 69 6e 74 for (dprint
0ab0: 42 75 66 66 65 72 49 64 78 20 3d 20 30 3b 20 64 BufferIdx = 0; d
0ac0: 70 72 69 6e 74 42 75 66 66 65 72 49 64 78 20 3c printBufferIdx <
0ad0: 20 62 75 66 66 65 72 4c 65 6e 67 74 68 3b 20 64 bufferLength; d
0ae0: 70 72 69 6e 74 42 75 66 66 65 72 49 64 78 2b 2b printBufferIdx++
0af0: 29 20 7b 20 5c 0a 20 20 20 20 20 20 20 20 20 20 ) { \.
0b00: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0b10: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0b20: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 64 d
0b30: 70 72 69 6e 74 42 75 66 66 65 72 43 68 61 72 20 printBufferChar
0b40: 3d 20 62 75 66 66 65 72 4e 61 6d 65 5b 64 70 72 = bufferName[dpr
0b50: 69 6e 74 42 75 66 66 65 72 49 64 78 5d 3b 20 5c intBufferIdx]; \
0b60: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
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 69 66 20 28 69 73 if (is
0ba0: 61 6c 70 68 61 28 64 70 72 69 6e 74 42 75 66 66 alpha(dprintBuff
0bb0: 65 72 43 68 61 72 29 20 7c 7c 20 69 73 64 69 67 erChar) || isdig
0bc0: 69 74 28 64 70 72 69 6e 74 42 75 66 66 65 72 43 it(dprintBufferC
0bd0: 68 61 72 29 29 20 7b 20 5c 0a 20 20 20 20 20 20 har)) { \.
0be0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
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 66 70 72 69 6e fprin
0c20: 74 66 28 73 74 64 65 72 72 2c 20 22 27 25 63 27 tf(stderr, "'%c'
0c30: 20 22 2c 20 64 70 72 69 6e 74 42 75 66 66 65 72 ", dprintBuffer
0c40: 43 68 61 72 29 3b 20 5c 0a 20 20 20 20 20 20 20 Char); \.
0c50: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
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 7d 20 65 6c 73 65 20 7b 20 5c 0a 20 20 20 } else { \.
0c90: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0ca0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
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 66 70 fp
0cd0: 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 25 rintf(stderr, "%
0ce0: 30 32 78 20 22 2c 20 28 75 6e 73 69 67 6e 65 64 02x ", (unsigned
0cf0: 20 69 6e 74 29 20 64 70 72 69 6e 74 42 75 66 66 int) dprintBuff
0d00: 65 72 43 68 61 72 29 3b 20 5c 0a 20 20 20 20 20 erChar); \.
0d10: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0d20: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0d30: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0d40: 20 20 20 20 7d 3b 20 5c 0a 20 20 20 20 20 20 20 }; \.
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 20 20 20 20
0d70: 20 20 20 20 20 20 20 20 20 20 7d 3b 20 5c 0a 20 }; \.
0d80: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0d90: 20 20 20 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: 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 fprintf(stderr,
0dc0: 22 7d 5c 6e 22 29 3b 20 5c 0a 20 20 20 20 20 20 "}\n"); \.
0dd0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0de0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0df0: 20 20 20 20 20 20 20 20 20 7d 0a 23 64 65 66 69 }.#defi
0e00: 6e 65 20 64 70 72 69 6e 74 46 6c 61 67 73 28 73 ne dprintFlags(s
0e10: 74 61 74 65 50 74 72 29 20 7b 20 5c 0a 20 20 20 tatePtr) { \.
0e20: 20 20 20 20 20 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 63 68 61 cha
0e40: 72 20 64 70 72 69 6e 74 66 42 75 66 66 65 72 5b r dprintfBuffer[
0e50: 38 31 39 32 5d 2c 20 2a 64 70 72 69 6e 74 66 42 8192], *dprintfB
0e60: 75 66 66 65 72 5f 70 3b 20 5c 0a 20 20 20 20 20 uffer_p; \.
0e70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0e80: 20 20 20 20 20 20 20 20 20 20 20 64 70 72 69 6e dprin
0e90: 74 66 42 75 66 66 65 72 5f 70 20 3d 20 26 64 70 tfBuffer_p = &dp
0ea0: 72 69 6e 74 66 42 75 66 66 65 72 5b 30 5d 3b 20 rintfBuffer[0];
0eb0: 5c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 \.
0ec0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0ed0: 20 20 64 70 72 69 6e 74 66 42 75 66 66 65 72 5f dprintfBuffer_
0ee0: 70 20 2b 3d 20 73 70 72 69 6e 74 66 28 64 70 72 p += sprintf(dpr
0ef0: 69 6e 74 66 42 75 66 66 65 72 5f 70 2c 20 22 25 intfBuffer_p, "%
0f00: 73 3a 25 69 3a 25 73 28 29 3a 25 73 2d 3e 66 6c s:%i:%s():%s->fl
0f10: 61 67 73 3d 30 22 2c 20 5f 5f 46 49 4c 45 5f 5f ags=0", __FILE__
0f20: 2c 20 5f 5f 4c 49 4e 45 5f 5f 2c 20 5f 5f 66 75 , __LINE__, __fu
0f30: 6e 63 5f 5f 2c 20 23 73 74 61 74 65 50 74 72 29 nc__, #statePtr)
0f40: 3b 20 5c 0a 20 20 20 20 20 20 20 20 20 20 20 20 ; \.
0f50: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0f60: 20 20 20 20 69 66 20 28 28 28 73 74 61 74 65 50 if (((stateP
0f70: 74 72 29 2d 3e 66 6c 61 67 73 20 26 20 54 4c 53 tr)->flags & TLS
0f80: 5f 54 43 4c 5f 41 53 59 4e 43 29 20 3d 3d 20 54 _TCL_ASYNC) == T
0f90: 4c 53 5f 54 43 4c 5f 41 53 59 4e 43 29 20 7b 20 LS_TCL_ASYNC) {
0fa0: 64 70 72 69 6e 74 66 42 75 66 66 65 72 5f 70 20 dprintfBuffer_p
0fb0: 2b 3d 20 73 70 72 69 6e 74 66 28 64 70 72 69 6e += sprintf(dprin
0fc0: 74 66 42 75 66 66 65 72 5f 70 2c 20 22 7c 54 4c tfBuffer_p, "|TL
0fd0: 53 5f 54 43 4c 5f 41 53 59 4e 43 22 29 3b 20 7d S_TCL_ASYNC"); }
0fe0: 3b 20 5c 0a 20 20 20 20 20 20 20 20 20 20 20 20 ; \.
0ff0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1000: 20 20 20 20 69 66 20 28 28 28 73 74 61 74 65 50 if (((stateP
1010: 74 72 29 2d 3e 66 6c 61 67 73 20 26 20 54 4c 53 tr)->flags & TLS
1020: 5f 54 43 4c 5f 53 45 52 56 45 52 29 20 3d 3d 20 _TCL_SERVER) ==
1030: 54 4c 53 5f 54 43 4c 5f 53 45 52 56 45 52 29 20 TLS_TCL_SERVER)
1040: 7b 20 64 70 72 69 6e 74 66 42 75 66 66 65 72 5f { dprintfBuffer_
1050: 70 20 2b 3d 20 73 70 72 69 6e 74 66 28 64 70 72 p += sprintf(dpr
1060: 69 6e 74 66 42 75 66 66 65 72 5f 70 2c 20 22 7c intfBuffer_p, "|
1070: 54 4c 53 5f 54 43 4c 5f 53 45 52 56 45 52 22 29 TLS_TCL_SERVER")
1080: 3b 20 7d 3b 20 5c 0a 20 20 20 20 20 20 20 20 20 ; }; \.
1090: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
10a0: 20 20 20 20 20 20 20 69 66 20 28 28 28 73 74 61 if (((sta
10b0: 74 65 50 74 72 29 2d 3e 66 6c 61 67 73 20 26 20 tePtr)->flags &
10c0: 54 4c 53 5f 54 43 4c 5f 49 4e 49 54 29 20 3d 3d TLS_TCL_INIT) ==
10d0: 20 54 4c 53 5f 54 43 4c 5f 49 4e 49 54 29 20 7b TLS_TCL_INIT) {
10e0: 20 64 70 72 69 6e 74 66 42 75 66 66 65 72 5f 70 dprintfBuffer_p
10f0: 20 2b 3d 20 73 70 72 69 6e 74 66 28 64 70 72 69 += sprintf(dpri
1100: 6e 74 66 42 75 66 66 65 72 5f 70 2c 20 22 7c 54 ntfBuffer_p, "|T
1110: 4c 53 5f 54 43 4c 5f 49 4e 49 54 22 29 3b 20 7d LS_TCL_INIT"); }
1120: 3b 20 5c 0a 20 20 20 20 20 20 20 20 20 20 20 20 ; \.
1130: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1140: 20 20 20 20 69 66 20 28 28 28 73 74 61 74 65 50 if (((stateP
1150: 74 72 29 2d 3e 66 6c 61 67 73 20 26 20 54 4c 53 tr)->flags & TLS
1160: 5f 54 43 4c 5f 44 45 42 55 47 29 20 3d 3d 20 54 _TCL_DEBUG) == T
1170: 4c 53 5f 54 43 4c 5f 44 45 42 55 47 29 20 7b 20 LS_TCL_DEBUG) {
1180: 64 70 72 69 6e 74 66 42 75 66 66 65 72 5f 70 20 dprintfBuffer_p
1190: 2b 3d 20 73 70 72 69 6e 74 66 28 64 70 72 69 6e += sprintf(dprin
11a0: 74 66 42 75 66 66 65 72 5f 70 2c 20 22 7c 54 4c tfBuffer_p, "|TL
11b0: 53 5f 54 43 4c 5f 44 45 42 55 47 22 29 3b 20 7d S_TCL_DEBUG"); }
11c0: 3b 20 5c 0a 20 20 20 20 20 20 20 20 20 20 20 20 ; \.
11d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
11e0: 20 20 20 20 69 66 20 28 28 28 73 74 61 74 65 50 if (((stateP
11f0: 74 72 29 2d 3e 66 6c 61 67 73 20 26 20 54 4c 53 tr)->flags & TLS
1200: 5f 54 43 4c 5f 43 41 4c 4c 42 41 43 4b 29 20 3d _TCL_CALLBACK) =
1210: 3d 20 54 4c 53 5f 54 43 4c 5f 43 41 4c 4c 42 41 = TLS_TCL_CALLBA
1220: 43 4b 29 20 7b 20 64 70 72 69 6e 74 66 42 75 66 CK) { dprintfBuf
1230: 66 65 72 5f 70 20 2b 3d 20 73 70 72 69 6e 74 66 fer_p += sprintf
1240: 28 64 70 72 69 6e 74 66 42 75 66 66 65 72 5f 70 (dprintfBuffer_p
1250: 2c 20 22 7c 54 4c 53 5f 54 43 4c 5f 43 41 4c 4c , "|TLS_TCL_CALL
1260: 42 41 43 4b 22 29 3b 20 7d 3b 20 5c 0a 20 20 20 BACK"); }; \.
1270: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1280: 20 20 20 20 20 20 20 20 20 20 20 20 20 69 66 20 if
1290: 28 28 28 73 74 61 74 65 50 74 72 29 2d 3e 66 6c (((statePtr)->fl
12a0: 61 67 73 20 26 20 54 4c 53 5f 54 43 4c 5f 48 41 ags & TLS_TCL_HA
12b0: 4e 44 53 48 41 4b 45 5f 46 41 49 4c 45 44 29 20 NDSHAKE_FAILED)
12c0: 3d 3d 20 54 4c 53 5f 54 43 4c 5f 48 41 4e 44 53 == TLS_TCL_HANDS
12d0: 48 41 4b 45 5f 46 41 49 4c 45 44 29 20 7b 20 64 HAKE_FAILED) { d
12e0: 70 72 69 6e 74 66 42 75 66 66 65 72 5f 70 20 2b printfBuffer_p +
12f0: 3d 20 73 70 72 69 6e 74 66 28 64 70 72 69 6e 74 = sprintf(dprint
1300: 66 42 75 66 66 65 72 5f 70 2c 20 22 7c 54 4c 53 fBuffer_p, "|TLS
1310: 5f 54 43 4c 5f 48 41 4e 44 53 48 41 4b 45 5f 46 _TCL_HANDSHAKE_F
1320: 41 49 4c 45 44 22 29 3b 20 7d 3b 20 5c 0a 20 20 AILED"); }; \.
1330: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1340: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69 66 if
1350: 20 28 28 28 73 74 61 74 65 50 74 72 29 2d 3e 66 (((statePtr)->f
1360: 6c 61 67 73 20 26 20 54 4c 53 5f 54 43 4c 5f 46 lags & TLS_TCL_F
1370: 41 53 54 50 41 54 48 29 20 3d 3d 20 54 4c 53 5f ASTPATH) == TLS_
1380: 54 43 4c 5f 46 41 53 54 50 41 54 48 29 20 7b 20 TCL_FASTPATH) {
1390: 64 70 72 69 6e 74 66 42 75 66 66 65 72 5f 70 20 dprintfBuffer_p
13a0: 2b 3d 20 73 70 72 69 6e 74 66 28 64 70 72 69 6e += sprintf(dprin
13b0: 74 66 42 75 66 66 65 72 5f 70 2c 20 22 7c 54 4c tfBuffer_p, "|TL
13c0: 53 5f 54 43 4c 5f 46 41 53 54 50 41 54 48 22 29 S_TCL_FASTPATH")
13d0: 3b 20 7d 3b 20 5c 0a 20 20 20 20 20 20 20 20 20 ; }; \.
13e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
13f0: 20 20 20 20 20 20 20 66 70 72 69 6e 74 66 28 73 fprintf(s
1400: 74 64 65 72 72 2c 20 22 25 73 5c 6e 22 2c 20 64 tderr, "%s\n", d
1410: 70 72 69 6e 74 66 42 75 66 66 65 72 29 3b 20 5c printfBuffer); \
1420: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
1430: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7d }
1440: 0a 23 65 6c 73 65 0a 23 64 65 66 69 6e 65 20 64 .#else.#define d
1450: 70 72 69 6e 74 66 28 2e 2e 2e 29 20 69 66 20 28 printf(...) if (
1460: 30 29 20 7b 20 66 70 72 69 6e 74 66 28 73 74 64 0) { fprintf(std
1470: 65 72 72 2c 20 5f 5f 56 41 5f 41 52 47 53 5f 5f err, __VA_ARGS__
1480: 29 3b 20 7d 0a 23 64 65 66 69 6e 65 20 64 70 72 ); }.#define dpr
1490: 69 6e 74 42 75 66 66 65 72 28 62 75 66 66 65 72 intBuffer(buffer
14a0: 4e 61 6d 65 2c 20 62 75 66 66 65 72 4c 65 6e 67 Name, bufferLeng
14b0: 74 68 29 20 2f 2a 2a 2f 0a 23 64 65 66 69 6e 65 th) /**/.#define
14c0: 20 64 70 72 69 6e 74 46 6c 61 67 73 28 73 74 61 dprintFlags(sta
14d0: 74 65 50 74 72 29 20 2f 2a 2a 2f 0a 23 65 6e 64 tePtr) /**/.#end
14e0: 69 66 0a 0a 23 64 65 66 69 6e 65 20 54 43 4c 54 if..#define TCLT
14f0: 4c 53 5f 53 53 4c 5f 45 52 52 4f 52 28 73 73 6c LS_SSL_ERROR(ssl
1500: 2c 65 72 72 29 20 28 28 63 68 61 72 2a 29 45 52 ,err) ((char*)ER
1510: 52 5f 72 65 61 73 6f 6e 5f 65 72 72 6f 72 5f 73 R_reason_error_s
1520: 74 72 69 6e 67 28 28 75 6e 73 69 67 6e 65 64 20 tring((unsigned
1530: 6c 6f 6e 67 29 53 53 4c 5f 67 65 74 5f 65 72 72 long)SSL_get_err
1540: 6f 72 28 28 73 73 6c 29 2c 28 65 72 72 29 29 29 or((ssl),(err)))
1550: 29 0a 2f 2a 0a 20 2a 20 4f 70 65 6e 53 53 4c 20 )./*. * OpenSSL
1560: 42 49 4f 20 52 6f 75 74 69 6e 65 73 0a 20 2a 2f BIO Routines. */
1570: 0a 23 64 65 66 69 6e 65 20 42 49 4f 5f 54 59 50 .#define BIO_TYP
1580: 45 5f 54 43 4c 09 28 31 39 7c 30 78 30 34 30 30 E_TCL.(19|0x0400
1590: 29 0a 0a 2f 2a 0a 20 2a 20 44 65 66 69 6e 65 73 )../*. * Defines
15a0: 20 66 6f 72 20 53 74 61 74 65 2e 66 6c 61 67 73 for State.flags
15b0: 0a 20 2a 2f 0a 23 64 65 66 69 6e 65 20 54 4c 53 . */.#define TLS
15c0: 5f 54 43 4c 5f 41 53 59 4e 43 09 28 31 3c 3c 30 _TCL_ASYNC.(1<<0
15d0: 29 09 2f 2a 20 6e 6f 6e 2d 62 6c 6f 63 6b 69 6e )./* non-blockin
15e0: 67 20 6d 6f 64 65 20 2a 2f 0a 23 64 65 66 69 6e g mode */.#defin
15f0: 65 20 54 4c 53 5f 54 43 4c 5f 53 45 52 56 45 52 e TLS_TCL_SERVER
1600: 09 28 31 3c 3c 31 29 09 2f 2a 20 53 65 72 76 65 .(1<<1)./* Serve
1610: 72 2d 53 69 64 65 20 2a 2f 0a 23 64 65 66 69 6e r-Side */.#defin
1620: 65 20 54 4c 53 5f 54 43 4c 5f 49 4e 49 54 09 28 e TLS_TCL_INIT.(
1630: 31 3c 3c 32 29 09 2f 2a 20 49 6e 69 74 69 61 6c 1<<2)./* Initial
1640: 69 7a 69 6e 67 20 63 6f 6e 6e 65 63 74 69 6f 6e izing connection
1650: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 54 4c 53 5f */.#define TLS_
1660: 54 43 4c 5f 44 45 42 55 47 09 28 31 3c 3c 33 29 TCL_DEBUG.(1<<3)
1670: 09 2f 2a 20 53 68 6f 77 20 64 65 62 75 67 20 74 ./* Show debug t
1680: 72 61 63 69 6e 67 20 2a 2f 0a 23 64 65 66 69 6e racing */.#defin
1690: 65 20 54 4c 53 5f 54 43 4c 5f 43 41 4c 4c 42 41 e TLS_TCL_CALLBA
16a0: 43 4b 09 28 31 3c 3c 34 29 09 2f 2a 20 49 6e 20 CK.(1<<4)./* In
16b0: 61 20 63 61 6c 6c 62 61 63 6b 2c 20 70 72 65 76 a callback, prev
16c0: 65 6e 74 20 75 70 64 61 74 65 0a 09 09 09 09 09 ent update......
16d0: 20 2a 20 6c 6f 6f 70 69 6e 67 20 70 72 6f 62 6c * looping probl
16e0: 65 6d 2e 20 5b 42 75 67 20 31 36 35 32 33 38 30 em. [Bug 1652380
16f0: 5d 20 2a 2f 0a 23 64 65 66 69 6e 65 20 54 4c 53 ] */.#define TLS
1700: 5f 54 43 4c 5f 48 41 4e 44 53 48 41 4b 45 5f 46 _TCL_HANDSHAKE_F
1710: 41 49 4c 45 44 20 28 31 3c 3c 35 29 20 2f 2a 20 AILED (1<<5) /*
1720: 53 65 74 20 6f 6e 20 68 61 6e 64 73 68 61 6b 65 Set on handshake
1730: 20 66 61 69 6c 75 72 65 73 20 61 6e 64 20 6f 6e failures and on
1740: 63 65 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 ce.
1750: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1760: 20 20 20 20 20 20 20 20 20 20 20 20 2a 20 73 65 * se
1770: 74 2c 20 61 6c 6c 20 66 75 72 74 68 65 72 20 49 t, all further I
1780: 2f 4f 20 77 69 6c 6c 20 72 65 73 75 6c 74 0a 20 /O will result.
1790: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
17a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
17b0: 20 20 20 20 20 20 20 20 2a 20 69 6e 20 45 43 4f * in ECO
17c0: 4e 4e 41 42 4f 52 54 45 44 20 65 72 72 6f 72 73 NNABORTED errors
17d0: 2e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 54 4c 53 . */.#define TLS
17e0: 5f 54 43 4c 5f 46 41 53 54 50 41 54 48 20 28 31 _TCL_FASTPATH (1
17f0: 3c 3c 36 29 20 20 20 20 20 20 20 20 20 2f 2a 20 <<6) /*
1800: 54 68 65 20 70 61 72 65 6e 74 20 63 68 61 6e 6e The parent chann
1810: 65 6c 20 69 73 20 62 65 69 6e 67 20 75 73 65 64 el is being used
1820: 20 64 69 72 65 63 74 6c 79 20 62 79 20 74 68 65 directly by the
1830: 20 53 53 4c 20 6c 69 62 72 61 72 79 20 2a 2f 0a SSL library */.
1840: 23 64 65 66 69 6e 65 20 54 4c 53 5f 54 43 4c 5f #define TLS_TCL_
1850: 44 45 4c 41 59 20 28 35 29 0a 0a 2f 2a 0a 20 2a DELAY (5)../*. *
1860: 20 54 68 69 73 20 73 74 72 75 63 74 75 72 65 20 This structure
1870: 64 65 73 63 72 69 62 65 73 20 74 68 65 20 70 65 describes the pe
1880: 72 2d 69 6e 73 74 61 6e 63 65 20 73 74 61 74 65 r-instance state
1890: 0a 20 2a 20 6f 66 20 61 6e 20 73 73 6c 20 63 68 . * of an ssl ch
18a0: 61 6e 6e 65 6c 2e 0a 20 2a 0a 20 2a 20 54 68 65 annel.. *. * The
18b0: 20 53 53 4c 20 70 72 6f 63 65 73 73 69 6e 67 20 SSL processing
18c0: 63 6f 6e 74 65 78 74 20 69 73 20 6d 61 69 6e 74 context is maint
18d0: 61 69 6e 65 64 20 68 65 72 65 2c 20 69 6e 20 74 ained here, in t
18e0: 68 65 20 43 6c 69 65 6e 74 44 61 74 61 0a 20 2a he ClientData. *
18f0: 2f 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 /.typedef struct
1900: 20 53 74 61 74 65 20 7b 0a 09 54 63 6c 5f 43 68 State {..Tcl_Ch
1910: 61 6e 6e 65 6c 20 73 65 6c 66 3b 20 20 20 20 20 annel self;
1920: 20 20 2f 2a 20 74 68 69 73 20 73 6f 63 6b 65 74 /* this socket
1930: 20 63 68 61 6e 6e 65 6c 20 2a 2f 0a 09 54 63 6c channel */..Tcl
1940: 5f 54 69 6d 65 72 54 6f 6b 65 6e 20 74 69 6d 65 _TimerToken time
1950: 72 3b 0a 0a 09 69 6e 74 20 66 6c 61 67 73 3b 20 r;...int flags;
1960: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
1970: 73 65 65 20 53 74 61 74 65 2e 66 6c 61 67 73 20 see State.flags
1980: 61 62 6f 76 65 20 20 2a 2f 0a 09 69 6e 74 20 77 above */..int w
1990: 61 74 63 68 4d 61 73 6b 3b 20 20 20 20 20 20 20 atchMask;
19a0: 20 20 20 2f 2a 20 63 75 72 72 65 6e 74 20 57 61 /* current Wa
19b0: 74 63 68 50 72 6f 63 20 6d 61 73 6b 20 2a 2f 0a tchProc mask */.
19c0: 09 69 6e 74 20 6d 6f 64 65 3b 20 20 20 20 20 20 .int mode;
19d0: 20 20 20 20 20 20 20 20 20 2f 2a 20 63 75 72 72 /* curr
19e0: 65 6e 74 20 6d 6f 64 65 20 6f 66 20 70 61 72 65 ent mode of pare
19f0: 6e 74 20 63 68 61 6e 6e 65 6c 20 2a 2f 0a 0a 09 nt channel */...
1a00: 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 Tcl_Interp *inte
1a10: 72 70 3b 20 20 20 20 20 2f 2a 20 69 6e 74 65 72 rp; /* inter
1a20: 70 72 65 74 65 72 20 69 6e 20 77 68 69 63 68 20 preter in which
1a30: 74 68 69 73 20 72 65 73 69 64 65 73 20 2a 2f 0a this resides */.
1a40: 09 54 63 6c 5f 4f 62 6a 20 2a 63 61 6c 6c 62 61 .Tcl_Obj *callba
1a50: 63 6b 3b 20 20 20 20 20 20 2f 2a 20 73 63 72 69 ck; /* scri
1a60: 70 74 20 63 61 6c 6c 65 64 20 66 6f 72 20 74 72 pt called for tr
1a70: 61 63 69 6e 67 2c 20 76 65 72 69 66 79 69 6e 67 acing, verifying
1a80: 20 61 6e 64 20 65 72 72 6f 72 73 20 2a 2f 0a 09 and errors */..
1a90: 54 63 6c 5f 4f 62 6a 20 2a 70 61 73 73 77 6f 72 Tcl_Obj *passwor
1aa0: 64 3b 20 20 20 20 20 20 2f 2a 20 73 63 72 69 70 d; /* scrip
1ab0: 74 20 63 61 6c 6c 65 64 20 66 6f 72 20 63 65 72 t called for cer
1ac0: 74 69 66 69 63 61 74 65 20 70 61 73 73 77 6f 72 tificate passwor
1ad0: 64 20 2a 2f 20 0a 0a 09 69 6e 74 20 76 66 6c 61 d */ ...int vfla
1ae0: 67 73 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 gs;
1af0: 2f 2a 20 76 65 72 69 66 79 20 66 6c 61 67 73 20 /* verify flags
1b00: 2a 2f 0a 09 53 53 4c 20 2a 73 73 6c 3b 20 20 20 */..SSL *ssl;
1b10: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 53 /* S
1b20: 74 72 75 63 74 20 66 6f 72 20 53 53 4c 20 70 72 truct for SSL pr
1b30: 6f 63 65 73 73 69 6e 67 20 2a 2f 0a 09 53 53 4c ocessing */..SSL
1b40: 5f 43 54 58 20 2a 63 74 78 3b 20 20 20 20 20 20 _CTX *ctx;
1b50: 20 20 20 20 20 2f 2a 20 53 53 4c 20 43 6f 6e 74 /* SSL Cont
1b60: 65 78 74 20 2a 2f 0a 09 42 49 4f 20 2a 62 69 6f ext */..BIO *bio
1b70: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
1b80: 2f 2a 20 53 74 72 75 63 74 20 66 6f 72 20 53 53 /* Struct for SS
1b90: 4c 20 70 72 6f 63 65 73 73 69 6e 67 20 2a 2f 0a L processing */.
1ba0: 09 42 49 4f 20 2a 70 5f 62 69 6f 3b 20 20 20 20 .BIO *p_bio;
1bb0: 20 20 20 20 20 20 20 20 20 2f 2a 20 50 61 72 65 /* Pare
1bc0: 6e 74 20 42 49 4f 20 28 74 68 61 74 20 69 73 20 nt BIO (that is
1bd0: 6c 61 79 65 72 65 64 20 6f 6e 20 54 63 6c 5f 43 layered on Tcl_C
1be0: 68 61 6e 6e 65 6c 29 20 2a 2f 0a 0a 09 63 68 61 hannel) */...cha
1bf0: 72 20 2a 65 72 72 3b 0a 7d 20 53 74 61 74 65 3b r *err;.} State;
1c00: 0a 0a 23 69 66 64 65 66 20 55 53 45 5f 54 43 4c ..#ifdef USE_TCL
1c10: 5f 53 54 55 42 53 0a 23 69 66 6e 64 65 66 20 54 _STUBS.#ifndef T
1c20: 63 6c 5f 53 74 61 63 6b 43 68 61 6e 6e 65 6c 0a cl_StackChannel.
1c30: 23 65 72 72 6f 72 20 22 55 6e 61 62 6c 65 20 74 #error "Unable t
1c40: 6f 20 63 6f 6d 70 69 6c 65 20 6f 6e 20 74 68 69 o compile on thi
1c50: 73 20 76 65 72 73 69 6f 6e 20 6f 66 20 54 63 6c s version of Tcl
1c60: 22 0a 23 65 6e 64 69 66 20 2f 2a 20 54 63 6c 5f ".#endif /* Tcl_
1c70: 47 65 74 53 74 61 63 6b 65 64 43 68 61 6e 6e 65 GetStackedChanne
1c80: 6c 20 2a 2f 0a 23 65 6e 64 69 66 20 2f 2a 20 55 l */.#endif /* U
1c90: 53 45 5f 54 43 4c 5f 53 54 55 42 53 20 2a 2f 0a SE_TCL_STUBS */.
1ca0: 0a 2f 2a 0a 20 2a 20 46 6f 72 77 61 72 64 20 64 ./*. * Forward d
1cb0: 65 63 6c 61 72 61 74 69 6f 6e 73 0a 20 2a 2f 0a eclarations. */.
1cc0: 54 63 6c 5f 43 68 61 6e 6e 65 6c 54 79 70 65 20 Tcl_ChannelType
1cd0: 2a 54 6c 73 5f 43 68 61 6e 6e 65 6c 54 79 70 65 *Tls_ChannelType
1ce0: 28 76 6f 69 64 29 3b 0a 54 63 6c 5f 43 68 61 6e (void);.Tcl_Chan
1cf0: 6e 65 6c 20 20 20 20 20 54 6c 73 5f 47 65 74 50 nel Tls_GetP
1d00: 61 72 65 6e 74 28 53 74 61 74 65 20 2a 73 74 61 arent(State *sta
1d10: 74 65 50 74 72 2c 20 69 6e 74 20 6d 61 73 6b 46 tePtr, int maskF
1d20: 6c 61 67 73 29 3b 0a 0a 54 63 6c 5f 4f 62 6a 20 lags);..Tcl_Obj
1d30: 20 20 20 20 20 20 20 20 2a 54 6c 73 5f 4e 65 77 *Tls_New
1d40: 58 35 30 39 4f 62 6a 28 54 63 6c 5f 49 6e 74 65 X509Obj(Tcl_Inte
1d50: 72 70 20 2a 69 6e 74 65 72 70 2c 20 58 35 30 39 rp *interp, X509
1d60: 20 2a 63 65 72 74 29 3b 0a 76 6f 69 64 20 20 20 *cert);.void
1d70: 20 20 20 20 20 20 20 20 20 54 6c 73 5f 45 72 72 Tls_Err
1d80: 6f 72 28 53 74 61 74 65 20 2a 73 74 61 74 65 50 or(State *stateP
1d90: 74 72 2c 20 63 68 61 72 20 2a 6d 73 67 29 3b 0a tr, char *msg);.
1da0: 76 6f 69 64 20 20 20 20 20 20 20 20 20 20 20 20 void
1db0: 54 6c 73 5f 46 72 65 65 28 63 68 61 72 20 2a 62 Tls_Free(char *b
1dc0: 6c 6f 63 6b 50 74 72 29 3b 0a 76 6f 69 64 20 20 lockPtr);.void
1dd0: 20 20 20 20 20 20 20 20 20 20 54 6c 73 5f 43 6c Tls_Cl
1de0: 65 61 6e 28 53 74 61 74 65 20 2a 73 74 61 74 65 ean(State *state
1df0: 50 74 72 29 3b 0a 69 6e 74 20 20 20 20 20 20 20 Ptr);.int
1e00: 20 20 20 20 20 20 54 6c 73 5f 57 61 69 74 46 6f Tls_WaitFo
1e10: 72 43 6f 6e 6e 65 63 74 28 53 74 61 74 65 20 2a rConnect(State *
1e20: 73 74 61 74 65 50 74 72 2c 20 69 6e 74 20 2a 65 statePtr, int *e
1e30: 72 72 6f 72 43 6f 64 65 50 74 72 2c 20 69 6e 74 rrorCodePtr, int
1e40: 20 68 61 6e 64 73 68 61 6b 65 46 61 69 6c 75 72 handshakeFailur
1e50: 65 49 73 50 65 72 6d 61 6e 65 6e 74 29 3b 0a 0a eIsPermanent);..
1e60: 42 49 4f 20 20 20 20 20 20 20 20 20 20 20 20 20 BIO
1e70: 2a 42 49 4f 5f 6e 65 77 5f 74 63 6c 28 53 74 61 *BIO_new_tcl(Sta
1e80: 74 65 2a 20 73 74 61 74 65 50 74 72 2c 20 69 6e te* statePtr, in
1e90: 74 20 66 6c 61 67 73 29 3b 0a 0a 23 64 65 66 69 t flags);..#defi
1ea0: 6e 65 20 50 54 52 32 49 4e 54 28 78 29 20 28 28 ne PTR2INT(x) ((
1eb0: 69 6e 74 29 20 28 28 69 6e 74 70 74 72 5f 74 29 int) ((intptr_t)
1ec0: 20 28 78 29 29 29 0a 0a 23 65 6e 64 69 66 20 2f (x)))..#endif /
1ed0: 2a 20 5f 54 4c 53 49 4e 54 5f 48 20 2a 2f 0a * _TLSINT_H */.