Hex Artifact Content

Artifact cf94bc9b5ce47aca07a391e6d9d9a5eed3c217f6:


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 53 4c 49 4e 54 5f 48 0a 23 64  def _TSLINT_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 0a 23 69 66 64 65 66  tring.h>..#ifdef
02d0: 20 5f 5f 57 49 4e 33 32 5f 5f 0a 23 64 65 66 69   __WIN32__.#defi
02e0: 6e 65 20 57 49 4e 33 32 5f 4c 45 41 4e 5f 41 4e  ne WIN32_LEAN_AN
02f0: 44 5f 4d 45 41 4e 0a 23 69 6e 63 6c 75 64 65 20  D_MEAN.#include 
0300: 3c 77 69 6e 64 6f 77 73 2e 68 3e 0a 23 69 6e 63  <windows.h>.#inc
0310: 6c 75 64 65 20 3c 77 69 6e 63 72 79 70 74 2e 68  lude <wincrypt.h
0320: 3e 20 2f 2a 20 4f 70 65 6e 53 53 4c 20 6e 65 65  > /* OpenSSL nee
0330: 64 73 20 74 68 69 73 20 6f 6e 20 57 69 6e 64 6f  ds this on Windo
0340: 77 73 20 2a 2f 0a 23 65 6e 64 69 66 0a 0a 2f 2a  ws */.#endif../*
0350: 20 48 61 6e 64 6c 65 20 74 63 6c 38 2e 33 2d 3e   Handle tcl8.3->
0360: 74 63 6c 38 2e 34 20 43 4f 4e 53 54 20 63 68 61  tcl8.4 CONST cha
0370: 6e 67 65 73 20 2a 2f 0a 23 69 66 6e 64 65 66 20  nges */.#ifndef 
0380: 43 4f 4e 53 54 38 34 0a 23 64 65 66 69 6e 65 20  CONST84.#define 
0390: 43 4f 4e 53 54 38 34 0a 23 65 6e 64 69 66 0a 0a  CONST84.#endif..
03a0: 23 69 66 64 65 66 20 4e 4f 5f 50 41 54 45 4e 54  #ifdef NO_PATENT
03b0: 53 0a 23 64 65 66 69 6e 65 20 4e 4f 5f 49 44 45  S.#define NO_IDE
03c0: 41 0a 23 64 65 66 69 6e 65 20 4e 4f 5f 52 43 32  A.#define NO_RC2
03d0: 0a 23 64 65 66 69 6e 65 20 4e 4f 5f 52 43 34 0a  .#define NO_RC4.
03e0: 23 64 65 66 69 6e 65 20 4e 4f 5f 52 43 35 0a 23  #define NO_RC5.#
03f0: 64 65 66 69 6e 65 20 4e 4f 5f 52 53 41 0a 23 64  define NO_RSA.#d
0400: 65 66 69 6e 65 20 4e 4f 5f 53 53 4c 32 0a 23 65  efine NO_SSL2.#e
0410: 6e 64 69 66 0a 0a 23 69 66 64 65 66 20 42 53 41  ndif..#ifdef BSA
0420: 46 45 0a 23 69 6e 63 6c 75 64 65 20 3c 73 73 6c  FE.#include <ssl
0430: 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 65 72  .h>.#include <er
0440: 72 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 72  r.h>.#include <r
0450: 61 6e 64 2e 68 3e 0a 23 65 6c 73 65 0a 23 69 6e  and.h>.#else.#in
0460: 63 6c 75 64 65 20 3c 6f 70 65 6e 73 73 6c 2f 73  clude <openssl/s
0470: 73 6c 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c  sl.h>.#include <
0480: 6f 70 65 6e 73 73 6c 2f 65 72 72 2e 68 3e 0a 23  openssl/err.h>.#
0490: 69 6e 63 6c 75 64 65 20 3c 6f 70 65 6e 73 73 6c  include <openssl
04a0: 2f 72 61 6e 64 2e 68 3e 0a 23 65 6e 64 69 66 0a  /rand.h>.#endif.
04b0: 0a 23 69 66 6e 64 65 66 20 53 53 4c 5f 4f 50 5f  .#ifndef SSL_OP_
04c0: 4e 4f 5f 54 4c 53 76 31 5f 31 0a 23 64 65 66 69  NO_TLSv1_1.#defi
04d0: 6e 65 20 4e 4f 5f 54 4c 53 31 5f 31 0a 23 65 6e  ne NO_TLS1_1.#en
04e0: 64 69 66 0a 0a 23 69 66 6e 64 65 66 20 53 53 4c  dif..#ifndef SSL
04f0: 5f 4f 50 5f 4e 4f 5f 54 4c 53 76 31 5f 32 0a 23  _OP_NO_TLSv1_2.#
0500: 64 65 66 69 6e 65 20 4e 4f 5f 54 4c 53 31 5f 32  define NO_TLS1_2
0510: 0a 23 65 6e 64 69 66 0a 0a 23 69 66 64 65 66 20  .#endif..#ifdef 
0520: 54 43 4c 5f 53 54 4f 52 41 47 45 5f 43 4c 41 53  TCL_STORAGE_CLAS
0530: 53 0a 23 20 75 6e 64 65 66 20 54 43 4c 5f 53 54  S.# undef TCL_ST
0540: 4f 52 41 47 45 5f 43 4c 41 53 53 0a 23 65 6e 64  ORAGE_CLASS.#end
0550: 69 66 0a 23 69 66 64 65 66 20 42 55 49 4c 44 5f  if.#ifdef BUILD_
0560: 74 6c 73 0a 23 20 64 65 66 69 6e 65 20 54 43 4c  tls.# define TCL
0570: 5f 53 54 4f 52 41 47 45 5f 43 4c 41 53 53 20 44  _STORAGE_CLASS D
0580: 4c 4c 45 58 50 4f 52 54 0a 23 65 6c 73 65 0a 23  LLEXPORT.#else.#
0590: 20 64 65 66 69 6e 65 20 54 43 4c 5f 53 54 4f 52   define TCL_STOR
05a0: 41 47 45 5f 43 4c 41 53 53 20 44 4c 4c 49 4d 50  AGE_CLASS DLLIMP
05b0: 4f 52 54 0a 23 65 6e 64 69 66 0a 20 0a 23 69 66  ORT.#endif. .#if
05c0: 6e 64 65 66 20 45 43 4f 4e 4e 41 42 4f 52 54 45  ndef ECONNABORTE
05d0: 44 0a 23 64 65 66 69 6e 65 20 45 43 4f 4e 4e 41  D.#define ECONNA
05e0: 42 4f 52 54 45 44 09 31 33 30 09 2f 2a 20 53 6f  BORTED.130./* So
05f0: 66 74 77 61 72 65 20 63 61 75 73 65 64 20 63 6f  ftware caused co
0600: 6e 6e 65 63 74 69 6f 6e 20 61 62 6f 72 74 20 2a  nnection abort *
0610: 2f 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66  /.#endif.#ifndef
0620: 20 45 43 4f 4e 4e 52 45 53 45 54 0a 23 64 65 66   ECONNRESET.#def
0630: 69 6e 65 20 45 43 4f 4e 4e 52 45 53 45 54 09 31  ine ECONNRESET.1
0640: 33 31 09 2f 2a 20 43 6f 6e 6e 65 63 74 69 6f 6e  31./* Connection
0650: 20 72 65 73 65 74 20 62 79 20 70 65 65 72 20 2a   reset by peer *
0660: 2f 0a 23 65 6e 64 69 66 0a 0a 23 69 66 64 65 66  /.#endif..#ifdef
0670: 20 54 43 4c 45 58 54 5f 54 43 4c 54 4c 53 5f 44   TCLEXT_TCLTLS_D
0680: 45 42 55 47 0a 23 64 65 66 69 6e 65 20 64 70 72  EBUG.#define dpr
0690: 69 6e 74 66 28 2e 2e 2e 29 20 7b 20 66 70 72 69  intf(...) { fpri
06a0: 6e 74 66 28 73 74 64 65 72 72 2c 20 22 25 73 3a  ntf(stderr, "%s:
06b0: 25 69 3a 22 2c 20 5f 5f 66 75 6e 63 5f 5f 2c 20  %i:", __func__, 
06c0: 5f 5f 4c 49 4e 45 5f 5f 29 3b 20 66 70 72 69 6e  __LINE__); fprin
06d0: 74 66 28 73 74 64 65 72 72 2c 20 5f 5f 56 41 5f  tf(stderr, __VA_
06e0: 41 52 47 53 5f 5f 29 3b 20 66 70 72 69 6e 74 66  ARGS__); fprintf
06f0: 28 73 74 64 65 72 72 2c 20 22 5c 6e 22 29 3b 20  (stderr, "\n"); 
0700: 7d 0a 23 65 6c 73 65 0a 23 64 65 66 69 6e 65 20  }.#else.#define 
0710: 64 70 72 69 6e 74 66 28 2e 2e 2e 29 20 69 66 20  dprintf(...) if 
0720: 28 30 29 20 7b 20 66 70 72 69 6e 74 66 28 73 74  (0) { fprintf(st
0730: 64 65 72 72 2c 20 5f 5f 56 41 5f 41 52 47 53 5f  derr, __VA_ARGS_
0740: 5f 29 3b 20 7d 0a 23 65 6e 64 69 66 0a 0a 23 64  _); }.#endif..#d
0750: 65 66 69 6e 65 20 53 53 4c 5f 45 52 52 4f 52 28  efine SSL_ERROR(
0760: 73 73 6c 2c 65 72 72 29 09 5c 0a 20 20 20 20 28  ssl,err).\.    (
0770: 28 63 68 61 72 2a 29 45 52 52 5f 72 65 61 73 6f  (char*)ERR_reaso
0780: 6e 5f 65 72 72 6f 72 5f 73 74 72 69 6e 67 28 28  n_error_string((
0790: 75 6e 73 69 67 6e 65 64 20 6c 6f 6e 67 29 53 53  unsigned long)SS
07a0: 4c 5f 67 65 74 5f 65 72 72 6f 72 28 28 73 73 6c  L_get_error((ssl
07b0: 29 2c 28 65 72 72 29 29 29 29 0a 2f 2a 0a 20 2a  ),(err))))./*. *
07c0: 20 4f 70 65 6e 53 53 4c 20 42 49 4f 20 52 6f 75   OpenSSL BIO Rou
07d0: 74 69 6e 65 73 0a 20 2a 2f 0a 23 64 65 66 69 6e  tines. */.#defin
07e0: 65 20 42 49 4f 5f 54 59 50 45 5f 54 43 4c 09 28  e BIO_TYPE_TCL.(
07f0: 31 39 7c 30 78 30 34 30 30 29 0a 0a 2f 2a 0a 20  19|0x0400)../*. 
0800: 2a 20 44 65 66 69 6e 65 73 20 66 6f 72 20 53 74  * Defines for St
0810: 61 74 65 2e 66 6c 61 67 73 0a 20 2a 2f 0a 23 64  ate.flags. */.#d
0820: 65 66 69 6e 65 20 54 4c 53 5f 54 43 4c 5f 41 53  efine TLS_TCL_AS
0830: 59 4e 43 09 28 31 3c 3c 30 29 09 2f 2a 20 6e 6f  YNC.(1<<0)./* no
0840: 6e 2d 62 6c 6f 63 6b 69 6e 67 20 6d 6f 64 65 20  n-blocking mode 
0850: 2a 2f 0a 23 64 65 66 69 6e 65 20 54 4c 53 5f 54  */.#define TLS_T
0860: 43 4c 5f 53 45 52 56 45 52 09 28 31 3c 3c 31 29  CL_SERVER.(1<<1)
0870: 09 2f 2a 20 53 65 72 76 65 72 2d 53 69 64 65 20  ./* Server-Side 
0880: 2a 2f 0a 23 64 65 66 69 6e 65 20 54 4c 53 5f 54  */.#define TLS_T
0890: 43 4c 5f 49 4e 49 54 09 28 31 3c 3c 32 29 09 2f  CL_INIT.(1<<2)./
08a0: 2a 20 49 6e 69 74 69 61 6c 69 7a 69 6e 67 20 63  * Initializing c
08b0: 6f 6e 6e 65 63 74 69 6f 6e 20 2a 2f 0a 23 64 65  onnection */.#de
08c0: 66 69 6e 65 20 54 4c 53 5f 54 43 4c 5f 44 45 42  fine TLS_TCL_DEB
08d0: 55 47 09 28 31 3c 3c 33 29 09 2f 2a 20 53 68 6f  UG.(1<<3)./* Sho
08e0: 77 20 64 65 62 75 67 20 74 72 61 63 69 6e 67 20  w debug tracing 
08f0: 2a 2f 0a 23 64 65 66 69 6e 65 20 54 4c 53 5f 54  */.#define TLS_T
0900: 43 4c 5f 43 41 4c 4c 42 41 43 4b 09 28 31 3c 3c  CL_CALLBACK.(1<<
0910: 34 29 09 2f 2a 20 49 6e 20 61 20 63 61 6c 6c 62  4)./* In a callb
0920: 61 63 6b 2c 20 70 72 65 76 65 6e 74 20 75 70 64  ack, prevent upd
0930: 61 74 65 0a 09 09 09 09 09 20 2a 20 6c 6f 6f 70  ate...... * loop
0940: 69 6e 67 20 70 72 6f 62 6c 65 6d 2e 20 5b 42 75  ing problem. [Bu
0950: 67 20 31 36 35 32 33 38 30 5d 20 2a 2f 0a 23 64  g 1652380] */.#d
0960: 65 66 69 6e 65 20 54 4c 53 5f 54 43 4c 5f 48 41  efine TLS_TCL_HA
0970: 4e 44 53 48 41 4b 45 5f 46 41 49 4c 45 44 20 28  NDSHAKE_FAILED (
0980: 31 3c 3c 35 29 20 2f 2a 20 53 65 74 20 6f 6e 20  1<<5) /* Set on 
0990: 68 61 6e 64 73 68 61 6b 65 20 66 61 69 6c 75 72  handshake failur
09a0: 65 73 20 61 6e 64 20 6f 6e 63 65 0a 20 20 20 20  es and once.    
09b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
09c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
09d0: 20 20 20 20 20 2a 20 73 65 74 2c 20 61 6c 6c 20       * set, all 
09e0: 66 75 72 74 68 65 72 20 49 2f 4f 20 77 69 6c 6c  further I/O will
09f0: 20 72 65 73 75 6c 74 0a 20 20 20 20 20 20 20 20   result.        
0a00: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0a10: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0a20: 20 2a 20 69 6e 20 45 43 4f 4e 4e 41 42 4f 52 54   * in ECONNABORT
0a30: 45 44 20 65 72 72 6f 72 73 2e 20 2a 2f 0a 0a 23  ED errors. */..#
0a40: 64 65 66 69 6e 65 20 54 4c 53 5f 54 43 4c 5f 44  define TLS_TCL_D
0a50: 45 4c 41 59 20 28 35 29 0a 0a 2f 2a 0a 20 2a 20  ELAY (5)../*. * 
0a60: 54 68 69 73 20 73 74 72 75 63 74 75 72 65 20 64  This structure d
0a70: 65 73 63 72 69 62 65 73 20 74 68 65 20 70 65 72  escribes the per
0a80: 2d 69 6e 73 74 61 6e 63 65 20 73 74 61 74 65 0a  -instance state.
0a90: 20 2a 20 6f 66 20 61 6e 20 73 73 6c 20 63 68 61   * of an ssl cha
0aa0: 6e 6e 65 6c 2e 0a 20 2a 0a 20 2a 20 54 68 65 20  nnel.. *. * The 
0ab0: 53 53 4c 20 70 72 6f 63 65 73 73 69 6e 67 20 63  SSL processing c
0ac0: 6f 6e 74 65 78 74 20 69 73 20 6d 61 69 6e 74 61  ontext is mainta
0ad0: 69 6e 65 64 20 68 65 72 65 2c 20 69 6e 20 74 68  ined here, in th
0ae0: 65 20 43 6c 69 65 6e 74 44 61 74 61 0a 20 2a 2f  e ClientData. */
0af0: 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20  .typedef struct 
0b00: 53 74 61 74 65 20 7b 0a 20 20 20 20 54 63 6c 5f  State {.    Tcl_
0b10: 43 68 61 6e 6e 65 6c 20 73 65 6c 66 3b 09 2f 2a  Channel self;./*
0b20: 20 74 68 69 73 20 73 6f 63 6b 65 74 20 63 68 61   this socket cha
0b30: 6e 6e 65 6c 20 2a 2f 0a 20 20 20 20 54 63 6c 5f  nnel */.    Tcl_
0b40: 54 69 6d 65 72 54 6f 6b 65 6e 20 74 69 6d 65 72  TimerToken timer
0b50: 3b 0a 0a 20 20 20 20 69 6e 74 20 66 6c 61 67 73  ;..    int flags
0b60: 3b 09 09 2f 2a 20 73 65 65 20 53 74 61 74 65 2e  ;../* see State.
0b70: 66 6c 61 67 73 20 61 62 6f 76 65 20 20 2a 2f 0a  flags above  */.
0b80: 20 20 20 20 69 6e 74 20 77 61 74 63 68 4d 61 73      int watchMas
0b90: 6b 3b 09 2f 2a 20 63 75 72 72 65 6e 74 20 57 61  k;./* current Wa
0ba0: 74 63 68 50 72 6f 63 20 6d 61 73 6b 20 2a 2f 0a  tchProc mask */.
0bb0: 20 20 20 20 69 6e 74 20 6d 6f 64 65 3b 09 09 2f      int mode;../
0bc0: 2a 20 63 75 72 72 65 6e 74 20 6d 6f 64 65 20 6f  * current mode o
0bd0: 66 20 70 61 72 65 6e 74 20 63 68 61 6e 6e 65 6c  f parent channel
0be0: 20 2a 2f 0a 0a 20 20 20 20 54 63 6c 5f 49 6e 74   */..    Tcl_Int
0bf0: 65 72 70 20 2a 69 6e 74 65 72 70 3b 09 2f 2a 20  erp *interp;./* 
0c00: 69 6e 74 65 72 70 72 65 74 65 72 20 69 6e 20 77  interpreter in w
0c10: 68 69 63 68 20 74 68 69 73 20 72 65 73 69 64 65  hich this reside
0c20: 73 20 2a 2f 0a 20 20 20 20 54 63 6c 5f 4f 62 6a  s */.    Tcl_Obj
0c30: 20 2a 63 61 6c 6c 62 61 63 6b 3b 09 2f 2a 20 73   *callback;./* s
0c40: 63 72 69 70 74 20 63 61 6c 6c 65 64 20 66 6f 72  cript called for
0c50: 20 74 72 61 63 69 6e 67 2c 20 76 65 72 69 66 79   tracing, verify
0c60: 69 6e 67 20 61 6e 64 20 65 72 72 6f 72 73 20 2a  ing and errors *
0c70: 2f 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 70  /.    Tcl_Obj *p
0c80: 61 73 73 77 6f 72 64 3b 09 2f 2a 20 73 63 72 69  assword;./* scri
0c90: 70 74 20 63 61 6c 6c 65 64 20 66 6f 72 20 63 65  pt called for ce
0ca0: 72 74 69 66 69 63 61 74 65 20 70 61 73 73 77 6f  rtificate passwo
0cb0: 72 64 20 2a 2f 20 0a 0a 20 20 20 20 69 6e 74 20  rd */ ..    int 
0cc0: 76 66 6c 61 67 73 3b 09 09 2f 2a 20 76 65 72 69  vflags;../* veri
0cd0: 66 79 20 66 6c 61 67 73 20 2a 2f 0a 20 20 20 20  fy flags */.    
0ce0: 53 53 4c 20 2a 73 73 6c 3b 09 09 2f 2a 20 53 74  SSL *ssl;../* St
0cf0: 72 75 63 74 20 66 6f 72 20 53 53 4c 20 70 72 6f  ruct for SSL pro
0d00: 63 65 73 73 69 6e 67 20 2a 2f 0a 20 20 20 20 53  cessing */.    S
0d10: 53 4c 5f 43 54 58 20 2a 63 74 78 3b 09 2f 2a 20  SL_CTX *ctx;./* 
0d20: 53 53 4c 20 43 6f 6e 74 65 78 74 20 2a 2f 0a 20  SSL Context */. 
0d30: 20 20 20 42 49 4f 20 2a 62 69 6f 3b 09 09 2f 2a     BIO *bio;../*
0d40: 20 53 74 72 75 63 74 20 66 6f 72 20 53 53 4c 20   Struct for SSL 
0d50: 70 72 6f 63 65 73 73 69 6e 67 20 2a 2f 0a 20 20  processing */.  
0d60: 20 20 42 49 4f 20 2a 70 5f 62 69 6f 3b 09 09 2f    BIO *p_bio;../
0d70: 2a 20 50 61 72 65 6e 74 20 42 49 4f 20 28 74 68  * Parent BIO (th
0d80: 61 74 20 69 73 20 6c 61 79 65 72 65 64 20 6f 6e  at is layered on
0d90: 20 54 63 6c 5f 43 68 61 6e 6e 65 6c 29 20 2a 2f   Tcl_Channel) */
0da0: 0a 0a 20 20 20 20 63 68 61 72 20 2a 65 72 72 3b  ..    char *err;
0db0: 0a 7d 20 53 74 61 74 65 3b 0a 0a 2f 2a 0a 20 2a  .} State;../*. *
0dc0: 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 64   The following d
0dd0: 65 66 69 6e 69 74 69 6f 6e 73 20 68 61 76 65 20  efinitions have 
0de0: 74 6f 20 62 65 20 75 73 61 62 6c 65 20 66 6f 72  to be usable for
0df0: 20 38 2e 32 2e 30 2d 38 2e 33 2e 31 20 61 6e 64   8.2.0-8.3.1 and
0e00: 20 38 2e 33 2e 32 2b 2e 0a 20 2a 20 54 68 65 20   8.3.2+.. * The 
0e10: 64 69 66 66 65 72 65 6e 63 65 73 20 62 65 74 77  differences betw
0e20: 65 65 6e 20 74 68 65 73 65 20 76 65 72 73 69 6f  een these versio
0e30: 6e 73 3a 0a 20 2a 0a 20 2a 20 38 2e 30 2d 38 2e  ns:. *. * 8.0-8.
0e40: 31 3a 09 54 68 65 72 65 20 69 73 20 6e 6f 20 73  1:.There is no s
0e50: 75 70 70 6f 72 74 20 66 6f 72 20 74 68 65 73 65  upport for these
0e60: 20 69 6e 20 54 4c 53 20 31 2e 34 20 28 67 65 74   in TLS 1.4 (get
0e70: 20 31 2e 33 29 2e 20 20 54 68 69 73 0a 20 2a 09   1.3).  This. *.
0e80: 09 77 61 73 20 74 68 65 20 76 65 72 73 69 6f 6e  .was the version
0e90: 20 77 69 74 68 20 74 68 65 20 6f 72 69 67 69 6e   with the origin
0ea0: 61 6c 20 70 61 74 63 68 2e 0a 20 2a 0a 20 2a 20  al patch.. *. * 
0eb0: 38 2e 32 2e 30 2d 09 43 68 61 6e 67 65 64 20 73  8.2.0-.Changed s
0ec0: 65 6d 61 6e 74 69 63 73 20 66 6f 72 20 54 63 6c  emantics for Tcl
0ed0: 5f 53 74 61 63 6b 43 68 61 6e 6e 65 6c 20 28 54  _StackChannel (T
0ee0: 63 6c 5f 52 65 70 6c 61 63 65 43 68 61 6e 6e 65  cl_ReplaceChanne
0ef0: 6c 29 2e 0a 20 2a 20 38 2e 33 2e 31 3a 09 43 68  l).. * 8.3.1:.Ch
0f00: 65 63 6b 20 61 74 20 72 75 6e 74 69 6d 65 20 74  eck at runtime t
0f10: 6f 20 73 77 69 74 63 68 20 74 68 65 20 62 65 68  o switch the beh
0f20: 61 76 69 6f 75 72 2e 20 54 68 65 20 70 61 74 63  aviour. The patc
0f30: 68 20 69 73 20 70 61 72 74 0a 20 2a 09 09 6f 66  h is part. *..of
0f40: 20 74 68 65 20 63 6f 72 65 20 66 72 6f 6d 20 6e   the core from n
0f50: 6f 77 20 6f 6e 2e 0a 20 2a 0a 20 2a 20 38 2e 33  ow on.. *. * 8.3
0f60: 2e 32 2b 3a 09 53 74 61 63 6b 65 64 20 63 68 61  .2+:.Stacked cha
0f70: 6e 6e 65 6c 73 20 72 65 77 72 69 74 74 65 6e 20  nnels rewritten 
0f80: 66 6f 72 20 62 65 74 74 65 72 20 62 65 68 61 76  for better behav
0f90: 69 6f 75 72 20 69 6e 20 73 6f 6d 65 0a 20 2a 09  iour in some. *.
0fa0: 09 73 69 74 75 61 74 69 6f 6e 73 20 28 63 6c 6f  .situations (clo
0fb0: 73 69 6e 67 29 2e 20 53 6f 6d 65 20 6e 65 77 20  sing). Some new 
0fc0: 41 50 49 27 73 2c 20 73 65 6d 61 6e 74 69 63 20  API's, semantic 
0fd0: 63 68 61 6e 67 65 73 2e 0a 20 2a 0a 20 2a 20 54  changes.. *. * T
0fe0: 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 6d 61 67  he following mag
0ff0: 69 63 20 77 61 73 20 61 64 61 70 74 65 64 20 66  ic was adapted f
1000: 72 6f 6d 20 54 72 66 20 32 2e 31 20 28 4b 75 70  rom Trf 2.1 (Kup
1010: 72 69 65 73 29 2e 0a 20 2a 2f 0a 0a 23 64 65 66  ries).. */..#def
1020: 69 6e 65 20 54 4c 53 5f 43 48 41 4e 4e 45 4c 5f  ine TLS_CHANNEL_
1030: 56 45 52 53 49 4f 4e 5f 31 09 30 78 31 0a 23 64  VERSION_1.0x1.#d
1040: 65 66 69 6e 65 20 54 4c 53 5f 43 48 41 4e 4e 45  efine TLS_CHANNE
1050: 4c 5f 56 45 52 53 49 4f 4e 5f 32 09 30 78 32 0a  L_VERSION_2.0x2.
1060: 65 78 74 65 72 6e 20 69 6e 74 20 63 68 61 6e 6e  extern int chann
1070: 65 6c 54 79 70 65 56 65 72 73 69 6f 6e 3b 0a 0a  elTypeVersion;..
1080: 23 69 66 64 65 66 20 55 53 45 5f 54 43 4c 5f 53  #ifdef USE_TCL_S
1090: 54 55 42 53 0a 23 69 66 6e 64 65 66 20 54 63 6c  TUBS.#ifndef Tcl
10a0: 5f 53 74 61 63 6b 43 68 61 6e 6e 65 6c 0a 2f 2a  _StackChannel./*
10b0: 0a 20 2a 20 54 68 65 20 63 6f 72 65 20 77 65 20  . * The core we 
10c0: 61 72 65 20 63 6f 6d 70 69 6c 69 6e 67 20 61 67  are compiling ag
10d0: 61 69 6e 73 74 20 69 73 20 6e 6f 74 20 70 61 74  ainst is not pat
10e0: 63 68 65 64 2c 20 73 6f 20 73 75 70 70 6c 79 20  ched, so supply 
10f0: 74 68 65 0a 20 2a 20 6e 65 63 65 73 73 73 61 72  the. * necesssar
1100: 79 20 64 65 66 69 6e 69 74 69 6f 6e 73 20 68 65  y definitions he
1110: 72 65 20 62 79 20 6f 75 72 73 65 6c 76 65 73 2e  re by ourselves.
1120: 20 54 68 65 20 66 6f 72 6d 20 63 68 6f 73 65 6e   The form chosen
1130: 20 66 6f 72 0a 20 2a 20 74 68 65 20 70 72 6f 63   for. * the proc
1140: 65 64 75 72 65 20 6d 61 63 72 6f 73 20 28 72 65  edure macros (re
1150: 73 65 72 76 65 64 58 58 58 29 20 77 69 6c 6c 20  servedXXX) will 
1160: 6e 6f 74 69 66 79 20 75 73 20 69 66 20 74 68 65  notify us if the
1170: 20 63 6f 72 65 0a 20 2a 20 64 6f 65 73 20 6e 6f   core. * does no
1180: 74 20 68 61 76 65 20 74 68 65 73 65 20 72 65 73  t have these res
1190: 65 72 76 65 64 20 6c 6f 63 61 74 69 6f 6e 73 20  erved locations 
11a0: 61 6e 79 6d 6f 72 65 2e 0a 20 2a 0a 20 2a 20 21  anymore.. *. * !
11b0: 21 20 53 79 6e 63 68 72 6f 6e 69 7a 65 20 74 68  ! Synchronize th
11c0: 65 20 70 72 6f 63 65 64 75 72 65 20 69 6e 64 69  e procedure indi
11d0: 63 65 73 20 69 6e 20 74 68 65 69 72 20 64 65 66  ces in their def
11e0: 69 6e 69 74 69 6f 6e 73 20 77 69 74 68 0a 20 2a  initions with. *
11f0: 20 20 20 20 74 68 65 20 70 61 74 63 68 20 74 6f      the patch to
1200: 20 74 63 6c 2e 64 65 63 6c 73 2c 20 61 73 20 74   tcl.decls, as t
1210: 68 65 79 20 68 61 76 65 20 74 6f 20 62 65 20 74  hey have to be t
1220: 68 65 20 73 61 6d 65 2e 0a 20 2a 2f 0a 0a 2f 2a  he same.. */../*
1230: 20 32 38 31 20 2a 2f 0a 74 79 70 65 64 65 66 20   281 */.typedef 
1240: 54 63 6c 5f 43 68 61 6e 6e 65 6c 20 28 74 6c 73  Tcl_Channel (tls
1250: 5f 53 74 61 63 6b 43 68 61 6e 6e 65 6c 29 20 5f  _StackChannel) _
1260: 41 4e 53 49 5f 41 52 47 53 5f 28 28 54 63 6c 5f  ANSI_ARGS_((Tcl_
1270: 49 6e 74 65 72 70 2a 20 69 6e 74 65 72 70 2c 0a  Interp* interp,.
1280: 09 09 09 09 09 09 20 20 20 20 54 63 6c 5f 43 68  ......    Tcl_Ch
1290: 61 6e 6e 65 6c 54 79 70 65 2a 20 74 79 70 65 50  annelType* typeP
12a0: 74 72 2c 0a 09 09 09 09 09 09 20 20 20 20 43 6c  tr,.......    Cl
12b0: 69 65 6e 74 44 61 74 61 20 69 6e 73 74 61 6e 63  ientData instanc
12c0: 65 44 61 74 61 2c 0a 09 09 09 09 09 09 20 20 20  eData,.......   
12d0: 20 69 6e 74 20 6d 61 73 6b 2c 0a 09 09 09 09 09   int mask,......
12e0: 09 20 20 20 20 54 63 6c 5f 43 68 61 6e 6e 65 6c  .    Tcl_Channel
12f0: 20 70 72 65 76 43 68 61 6e 29 29 3b 0a 2f 2a 20   prevChan));./* 
1300: 32 38 32 20 2a 2f 0a 74 79 70 65 64 65 66 20 76  282 */.typedef v
1310: 6f 69 64 20 28 74 6c 73 5f 55 6e 73 74 61 63 6b  oid (tls_Unstack
1320: 43 68 61 6e 6e 65 6c 29 20 5f 41 4e 53 49 5f 41  Channel) _ANSI_A
1330: 52 47 53 5f 28 28 54 63 6c 5f 49 6e 74 65 72 70  RGS_((Tcl_Interp
1340: 2a 20 69 6e 74 65 72 70 2c 0a 09 09 09 09 09 20  * interp,...... 
1350: 20 20 20 20 20 20 54 63 6c 5f 43 68 61 6e 6e 65        Tcl_Channe
1360: 6c 20 63 68 61 6e 29 29 3b 0a 0a 23 64 65 66 69  l chan));..#defi
1370: 6e 65 20 54 63 6c 5f 53 74 61 63 6b 43 68 61 6e  ne Tcl_StackChan
1380: 6e 65 6c 20 20 20 20 20 28 28 74 6c 73 5f 53 74  nel     ((tls_St
1390: 61 63 6b 43 68 61 6e 6e 65 6c 2a 29 20 74 63 6c  ackChannel*) tcl
13a0: 53 74 75 62 73 50 74 72 2d 3e 72 65 73 65 72 76  StubsPtr->reserv
13b0: 65 64 32 38 31 29 0a 23 64 65 66 69 6e 65 20 54  ed281).#define T
13c0: 63 6c 5f 55 6e 73 74 61 63 6b 43 68 61 6e 6e 65  cl_UnstackChanne
13d0: 6c 20 28 28 74 6c 73 5f 55 6e 73 74 61 63 6b 43  l ((tls_UnstackC
13e0: 68 61 6e 6e 65 6c 2a 29 20 74 63 6c 53 74 75 62  hannel*) tclStub
13f0: 73 50 74 72 2d 3e 72 65 73 65 72 76 65 64 32 38  sPtr->reserved28
1400: 32 29 0a 0a 23 65 6e 64 69 66 20 2f 2a 20 54 63  2)..#endif /* Tc
1410: 6c 5f 53 74 61 63 6b 43 68 61 6e 6e 65 6c 20 2a  l_StackChannel *
1420: 2f 0a 0a 23 69 66 6e 64 65 66 20 54 63 6c 5f 47  /..#ifndef Tcl_G
1430: 65 74 53 74 61 63 6b 65 64 43 68 61 6e 6e 65 6c  etStackedChannel
1440: 0a 2f 2a 0a 20 2a 20 53 65 70 61 72 61 74 65 20  ./*. * Separate 
1450: 64 65 66 69 6e 69 74 69 6f 6e 2c 20 61 76 61 69  definition, avai
1460: 6c 61 62 6c 65 20 69 6e 20 38 2e 32 2c 20 62 75  lable in 8.2, bu
1470: 74 20 6e 6f 74 20 38 2e 31 20 61 6e 64 20 62 65  t not 8.1 and be
1480: 66 6f 72 65 20 21 0a 20 2a 2f 0a 0a 2f 2a 20 32  fore !. */../* 2
1490: 38 33 20 2a 2f 0a 74 79 70 65 64 65 66 20 54 63  83 */.typedef Tc
14a0: 6c 5f 43 68 61 6e 6e 65 6c 20 28 74 6c 73 5f 47  l_Channel (tls_G
14b0: 65 74 53 74 61 63 6b 65 64 43 68 61 6e 6e 65 6c  etStackedChannel
14c0: 29 20 5f 41 4e 53 49 5f 41 52 47 53 5f 28 28 54  ) _ANSI_ARGS_((T
14d0: 63 6c 5f 43 68 61 6e 6e 65 6c 20 63 68 61 6e 29  cl_Channel chan)
14e0: 29 3b 0a 0a 23 64 65 66 69 6e 65 20 54 63 6c 5f  );..#define Tcl_
14f0: 47 65 74 53 74 61 63 6b 65 64 43 68 61 6e 6e 65  GetStackedChanne
1500: 6c 20 28 28 74 6c 73 5f 47 65 74 53 74 61 63 6b  l ((tls_GetStack
1510: 65 64 43 68 61 6e 6e 65 6c 2a 29 20 74 63 6c 53  edChannel*) tclS
1520: 74 75 62 73 50 74 72 2d 3e 72 65 73 65 72 76 65  tubsPtr->reserve
1530: 64 32 38 33 29 0a 0a 23 65 6e 64 69 66 20 2f 2a  d283)..#endif /*
1540: 20 54 63 6c 5f 47 65 74 53 74 61 63 6b 65 64 43   Tcl_GetStackedC
1550: 68 61 6e 6e 65 6c 20 2a 2f 0a 0a 0a 23 69 66 6e  hannel */...#ifn
1560: 64 65 66 20 54 43 4c 5f 43 48 41 4e 4e 45 4c 5f  def TCL_CHANNEL_
1570: 56 45 52 53 49 4f 4e 5f 32 0a 2f 2a 0a 20 2a 20  VERSION_2./*. * 
1580: 43 6f 72 65 20 69 73 20 6f 6c 64 65 72 20 74 68  Core is older th
1590: 61 6e 20 38 2e 33 2e 32 2e 20 20 53 75 70 70 6c  an 8.3.2.  Suppl
15a0: 79 20 74 68 65 20 6d 69 73 73 69 6e 67 20 64 65  y the missing de
15b0: 66 69 6e 69 74 69 6f 6e 73 20 66 6f 72 0a 20 2a  finitions for. *
15c0: 20 74 68 65 20 6e 65 77 20 41 50 49 27 73 20 69   the new API's i
15d0: 6e 20 38 2e 33 2e 32 2e 0a 20 2a 2f 0a 23 64 65  n 8.3.2.. */.#de
15e0: 66 69 6e 65 20 45 4d 55 4c 41 54 45 5f 43 48 41  fine EMULATE_CHA
15f0: 4e 4e 45 4c 5f 56 45 52 53 49 4f 4e 5f 32 0a 0a  NNEL_VERSION_2..
1600: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 54  typedef struct T
1610: 6c 73 43 68 61 6e 6e 65 6c 54 79 70 65 56 65 72  lsChannelTypeVer
1620: 73 69 6f 6e 5f 2a 20 54 6c 73 43 68 61 6e 6e 65  sion_* TlsChanne
1630: 6c 54 79 70 65 56 65 72 73 69 6f 6e 3b 0a 23 64  lTypeVersion;.#d
1640: 65 66 69 6e 65 20 54 43 4c 5f 43 48 41 4e 4e 45  efine TCL_CHANNE
1650: 4c 5f 56 45 52 53 49 4f 4e 5f 32 09 28 28 54 6c  L_VERSION_2.((Tl
1660: 73 43 68 61 6e 6e 65 6c 54 79 70 65 56 65 72 73  sChannelTypeVers
1670: 69 6f 6e 29 20 30 78 32 29 0a 0a 74 79 70 65 64  ion) 0x2)..typed
1680: 65 66 20 69 6e 74 20 28 54 6c 73 44 72 69 76 65  ef int (TlsDrive
1690: 72 48 61 6e 64 6c 65 72 50 72 6f 63 29 20 5f 41  rHandlerProc) _A
16a0: 4e 53 49 5f 41 52 47 53 5f 28 28 43 6c 69 65 6e  NSI_ARGS_((Clien
16b0: 74 44 61 74 61 20 69 6e 73 74 61 6e 63 65 44 61  tData instanceDa
16c0: 74 61 2c 0a 09 09 09 09 09 69 6e 74 20 69 6e 74  ta,......int int
16d0: 65 72 65 73 74 4d 61 73 6b 29 29 3b 0a 2f 2a 20  erestMask));./* 
16e0: 33 39 34 20 2a 2f 0a 74 79 70 65 64 65 66 20 69  394 */.typedef i
16f0: 6e 74 20 28 74 6c 73 5f 52 65 61 64 52 61 77 29  nt (tls_ReadRaw)
1700: 20 20 5f 41 4e 53 49 5f 41 52 47 53 5f 28 28 54    _ANSI_ARGS_((T
1710: 63 6c 5f 43 68 61 6e 6e 65 6c 20 63 68 61 6e 2c  cl_Channel chan,
1720: 20 63 68 61 72 20 2a 64 73 74 2c 0a 09 09 09 09   char *dst,.....
1730: 09 69 6e 74 20 62 79 74 65 73 54 6f 52 65 61 64  .int bytesToRead
1740: 29 29 3b 0a 2f 2a 20 33 39 35 20 2a 2f 0a 74 79  ));./* 395 */.ty
1750: 70 65 64 65 66 20 69 6e 74 20 28 74 6c 73 5f 57  pedef int (tls_W
1760: 72 69 74 65 52 61 77 29 20 5f 41 4e 53 49 5f 41  riteRaw) _ANSI_A
1770: 52 47 53 5f 28 28 54 63 6c 5f 43 68 61 6e 6e 65  RGS_((Tcl_Channe
1780: 6c 20 63 68 61 6e 2c 20 63 68 61 72 20 2a 73 72  l chan, char *sr
1790: 63 2c 0a 09 09 09 09 09 69 6e 74 20 73 72 63 4c  c,......int srcL
17a0: 65 6e 29 29 3b 0a 2f 2a 20 33 39 37 20 2a 2f 0a  en));./* 397 */.
17b0: 74 79 70 65 64 65 66 20 69 6e 74 20 28 74 6c 73  typedef int (tls
17c0: 5f 47 65 74 54 6f 70 43 68 61 6e 6e 65 6c 29 20  _GetTopChannel) 
17d0: 5f 41 4e 53 49 5f 41 52 47 53 5f 28 28 54 63 6c  _ANSI_ARGS_((Tcl
17e0: 5f 43 68 61 6e 6e 65 6c 20 63 68 61 6e 29 29 3b  _Channel chan));
17f0: 0a 0a 2f 2a 0a 20 2a 20 47 65 6e 65 72 61 74 69  ../*. * Generati
1800: 6e 67 20 63 6f 64 65 20 66 6f 72 20 61 63 63 65  ng code for acce
1810: 73 73 69 6e 67 20 74 68 65 73 65 20 70 61 72 74  ssing these part
1820: 73 20 6f 66 20 74 68 65 20 73 74 75 62 20 74 61  s of the stub ta
1830: 62 6c 65 20 77 68 65 6e 0a 20 2a 20 63 6f 6d 70  ble when. * comp
1840: 69 6c 69 6e 67 20 61 67 61 69 6e 73 74 20 61 20  iling against a 
1850: 63 6f 72 65 20 6f 6c 64 65 72 20 74 68 61 6e 20  core older than 
1860: 38 2e 33 2e 32 20 69 73 20 61 20 68 61 73 73 6c  8.3.2 is a hassl
1870: 65 20 62 65 63 61 75 73 65 20 65 76 65 6e 0a 20  e because even. 
1880: 2a 20 74 68 65 20 27 72 65 73 65 72 76 65 64 58  * the 'reservedX
1890: 58 58 27 20 66 69 65 6c 64 73 20 6f 66 20 74 68  XX' fields of th
18a0: 65 20 73 74 72 75 63 74 75 72 65 20 61 72 65 20  e structure are 
18b0: 6e 6f 74 20 64 65 66 69 6e 65 64 20 79 65 74 2e  not defined yet.
18c0: 20 53 6f 0a 20 2a 20 77 65 20 68 61 76 65 20 74   So. * we have t
18d0: 6f 20 77 72 69 74 65 20 75 70 20 73 6f 6d 65 20  o write up some 
18e0: 6d 61 63 72 6f 73 20 68 69 64 69 6e 67 20 73 6f  macros hiding so
18f0: 6d 65 20 76 65 72 79 20 68 61 63 6b 69 73 68 20  me very hackish 
1900: 70 6f 69 6e 74 65 72 0a 20 2a 20 61 72 69 74 68  pointer. * arith
1910: 6d 65 74 69 63 73 20 74 6f 20 67 65 74 20 61 74  metics to get at
1920: 20 74 68 65 73 65 20 66 69 65 6c 64 73 2e 20 57   these fields. W
1930: 65 20 61 73 73 75 6d 65 20 74 68 61 74 20 70 6f  e assume that po
1940: 69 6e 74 65 72 20 74 6f 0a 20 2a 20 66 75 6e 63  inter to. * func
1950: 74 69 6f 6e 73 20 61 72 65 20 61 6c 77 61 79 73  tions are always
1960: 20 6f 66 20 74 68 65 20 73 61 6d 65 20 73 69 7a   of the same siz
1970: 65 2e 0a 20 2a 2f 0a 0a 23 64 65 66 69 6e 65 20  e.. */..#define 
1980: 53 54 55 42 5f 42 41 53 45 20 20 20 28 28 63 68  STUB_BASE   ((ch
1990: 61 72 2a 29 28 26 28 74 63 6c 53 74 75 62 73 50  ar*)(&(tclStubsP
19a0: 74 72 2d 3e 74 63 6c 5f 55 74 66 4e 63 61 73 65  tr->tcl_UtfNcase
19b0: 63 6d 70 29 29 29 20 2f 2a 20 66 69 65 6c 64 20  cmp))) /* field 
19c0: 33 37 30 20 2a 2f 0a 23 64 65 66 69 6e 65 20 70  370 */.#define p
19d0: 72 6f 63 50 74 72 53 69 7a 65 20 28 73 69 7a 65  rocPtrSize (size
19e0: 6f 66 20 28 54 63 6c 5f 44 72 69 76 65 72 42 6c  of (Tcl_DriverBl
19f0: 6f 63 6b 4d 6f 64 65 50 72 6f 63 20 2a 29 29 0a  ockModeProc *)).
1a00: 23 64 65 66 69 6e 65 20 49 44 58 28 6e 29 20 20  #define IDX(n)  
1a10: 20 20 20 20 28 28 28 6e 29 2d 33 37 30 29 20 2a      (((n)-370) *
1a20: 20 70 72 6f 63 50 74 72 53 69 7a 65 29 0a 23 64   procPtrSize).#d
1a30: 65 66 69 6e 65 20 53 4c 4f 54 28 6e 29 20 20 20  efine SLOT(n)   
1a40: 20 20 28 53 54 55 42 5f 42 41 53 45 20 2b 20 49    (STUB_BASE + I
1a50: 44 58 28 6e 29 29 0a 0a 23 64 65 66 69 6e 65 20  DX(n))..#define 
1a60: 54 63 6c 5f 52 65 61 64 52 61 77 09 09 28 2a 28  Tcl_ReadRaw..(*(
1a70: 28 74 6c 73 5f 52 65 61 64 52 61 77 2a 2a 29 09  (tls_ReadRaw**).
1a80: 28 53 4c 4f 54 28 33 39 34 29 29 29 29 0a 23 64  (SLOT(394)))).#d
1a90: 65 66 69 6e 65 20 54 63 6c 5f 57 72 69 74 65 52  efine Tcl_WriteR
1aa0: 61 77 09 09 28 2a 28 28 74 6c 73 5f 57 72 69 74  aw..(*((tls_Writ
1ab0: 65 52 61 77 2a 2a 29 09 28 53 4c 4f 54 28 33 39  eRaw**).(SLOT(39
1ac0: 35 29 29 29 29 0a 23 64 65 66 69 6e 65 20 54 63  5)))).#define Tc
1ad0: 6c 5f 47 65 74 54 6f 70 43 68 61 6e 6e 65 6c 09  l_GetTopChannel.
1ae0: 28 2a 28 28 74 6c 73 5f 47 65 74 54 6f 70 43 68  (*((tls_GetTopCh
1af0: 61 6e 6e 65 6c 2a 2a 29 28 53 4c 4f 54 28 33 39  annel**)(SLOT(39
1b00: 36 29 29 29 29 0a 0a 2f 2a 0a 20 2a 20 52 65 71  6))))../*. * Req
1b10: 75 69 72 65 64 2c 20 65 61 73 79 20 65 6d 75 6c  uired, easy emul
1b20: 61 74 69 6f 6e 2e 0a 20 2a 2f 0a 23 64 65 66 69  ation.. */.#defi
1b30: 6e 65 20 54 63 6c 5f 43 68 61 6e 6e 65 6c 47 65  ne Tcl_ChannelGe
1b40: 74 4f 70 74 69 6f 6e 50 72 6f 63 28 63 68 61 6e  tOptionProc(chan
1b50: 44 72 69 76 65 72 29 20 28 28 63 68 61 6e 44 72  Driver) ((chanDr
1b60: 69 76 65 72 29 2d 3e 67 65 74 4f 70 74 69 6f 6e  iver)->getOption
1b70: 50 72 6f 63 29 0a 0a 23 65 6e 64 69 66 20 2f 2a  Proc)..#endif /*
1b80: 20 54 43 4c 5f 43 48 41 4e 4e 45 4c 5f 56 45 52   TCL_CHANNEL_VER
1b90: 53 49 4f 4e 5f 32 20 2a 2f 0a 0a 23 65 6e 64 69  SION_2 */..#endi
1ba0: 66 20 2f 2a 20 55 53 45 5f 54 43 4c 5f 53 54 55  f /* USE_TCL_STU
1bb0: 42 53 20 2a 2f 0a 0a 2f 2a 0a 20 2a 20 46 6f 72  BS */../*. * For
1bc0: 77 61 72 64 20 64 65 63 6c 61 72 61 74 69 6f 6e  ward declaration
1bd0: 73 0a 20 2a 2f 0a 0a 45 58 54 45 52 4e 20 54 63  s. */..EXTERN Tc
1be0: 6c 5f 43 68 61 6e 6e 65 6c 54 79 70 65 20 2a 54  l_ChannelType *T
1bf0: 6c 73 5f 43 68 61 6e 6e 65 6c 54 79 70 65 20 5f  ls_ChannelType _
1c00: 41 4e 53 49 5f 41 52 47 53 5f 28 28 76 6f 69 64  ANSI_ARGS_((void
1c10: 29 29 3b 0a 45 58 54 45 52 4e 20 54 63 6c 5f 43  ));.EXTERN Tcl_C
1c20: 68 61 6e 6e 65 6c 09 54 6c 73 5f 47 65 74 50 61  hannel.Tls_GetPa
1c30: 72 65 6e 74 20 5f 41 4e 53 49 5f 41 52 47 53 5f  rent _ANSI_ARGS_
1c40: 28 28 53 74 61 74 65 20 2a 73 74 61 74 65 50 74  ((State *statePt
1c50: 72 29 29 3b 0a 0a 45 58 54 45 52 4e 20 54 63 6c  r));..EXTERN Tcl
1c60: 5f 4f 62 6a 2a 09 09 54 6c 73 5f 4e 65 77 58 35  _Obj*..Tls_NewX5
1c70: 30 39 4f 62 6a 20 5f 41 4e 53 49 5f 41 52 47 53  09Obj _ANSI_ARGS
1c80: 5f 20 28 28 20 54 63 6c 5f 49 6e 74 65 72 70 20  _ (( Tcl_Interp 
1c90: 2a 69 6e 74 65 72 70 2c 20 58 35 30 39 20 2a 63  *interp, X509 *c
1ca0: 65 72 74 29 29 3b 0a 45 58 54 45 52 4e 20 76 6f  ert));.EXTERN vo
1cb0: 69 64 09 09 54 6c 73 5f 45 72 72 6f 72 20 5f 41  id..Tls_Error _A
1cc0: 4e 53 49 5f 41 52 47 53 5f 20 28 28 53 74 61 74  NSI_ARGS_ ((Stat
1cd0: 65 20 2a 73 74 61 74 65 50 74 72 2c 20 63 68 61  e *statePtr, cha
1ce0: 72 20 2a 6d 73 67 29 29 3b 0a 45 58 54 45 52 4e  r *msg));.EXTERN
1cf0: 20 76 6f 69 64 09 09 54 6c 73 5f 46 72 65 65 20   void..Tls_Free 
1d00: 5f 41 4e 53 49 5f 41 52 47 53 5f 20 28 28 63 68  _ANSI_ARGS_ ((ch
1d10: 61 72 20 2a 62 6c 6f 63 6b 50 74 72 29 29 3b 0a  ar *blockPtr));.
1d20: 45 58 54 45 52 4e 20 76 6f 69 64 09 09 54 6c 73  EXTERN void..Tls
1d30: 5f 43 6c 65 61 6e 20 5f 41 4e 53 49 5f 41 52 47  _Clean _ANSI_ARG
1d40: 53 5f 20 28 28 53 74 61 74 65 20 2a 73 74 61 74  S_ ((State *stat
1d50: 65 50 74 72 29 29 3b 0a 45 58 54 45 52 4e 20 69  ePtr));.EXTERN i
1d60: 6e 74 09 09 54 6c 73 5f 57 61 69 74 46 6f 72 43  nt..Tls_WaitForC
1d70: 6f 6e 6e 65 63 74 20 5f 41 4e 53 49 5f 41 52 47  onnect _ANSI_ARG
1d80: 53 5f 28 28 20 53 74 61 74 65 20 2a 73 74 61 74  S_(( State *stat
1d90: 65 50 74 72 2c 0a 09 09 09 09 09 09 09 69 6e 74  ePtr,........int
1da0: 20 2a 65 72 72 6f 72 43 6f 64 65 50 74 72 29 29   *errorCodePtr))
1db0: 3b 0a 0a 45 58 54 45 52 4e 20 42 49 4f 5f 4d 45  ;..EXTERN BIO_ME
1dc0: 54 48 4f 44 20 2a 09 42 49 4f 5f 73 5f 74 63 6c  THOD *.BIO_s_tcl
1dd0: 20 5f 41 4e 53 49 5f 41 52 47 53 5f 28 28 76 6f   _ANSI_ARGS_((vo
1de0: 69 64 29 29 3b 0a 45 58 54 45 52 4e 20 42 49 4f  id));.EXTERN BIO
1df0: 20 2a 09 09 42 49 4f 5f 6e 65 77 5f 74 63 6c 20   *..BIO_new_tcl 
1e00: 5f 41 4e 53 49 5f 41 52 47 53 5f 28 28 53 74 61  _ANSI_ARGS_((Sta
1e10: 74 65 2a 20 73 74 61 74 65 50 74 72 2c 20 69 6e  te* statePtr, in
1e20: 74 20 66 6c 61 67 73 29 29 3b 0a 0a 23 65 6e 64  t flags));..#end
1e30: 69 66 20 2f 2a 20 5f 54 4c 53 49 4e 54 5f 48 20  if /* _TLSINT_H 
1e40: 2a 2f 0a                                         */.