Hex Artifact Content

Artifact 0876b611aa5a963212ce31853c978c4a1301bb11:


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 2f 2a 20 48 61 6e 64 6c 65 20 74 63 6c 38  ../* Handle tcl8
0370: 2e 33 2d 3e 74 63 6c 38 2e 34 20 43 4f 4e 53 54  .3->tcl8.4 CONST
0380: 20 63 68 61 6e 67 65 73 20 2a 2f 0a 23 69 66 6e   changes */.#ifn
0390: 64 65 66 20 43 4f 4e 53 54 38 34 0a 23 64 65 66  def CONST84.#def
03a0: 69 6e 65 20 43 4f 4e 53 54 38 34 0a 23 65 6e 64  ine CONST84.#end
03b0: 69 66 0a 0a 23 69 66 64 65 66 20 4e 4f 5f 50 41  if..#ifdef NO_PA
03c0: 54 45 4e 54 53 0a 23 20 20 64 65 66 69 6e 65 20  TENTS.#  define 
03d0: 4e 4f 5f 49 44 45 41 0a 23 20 20 64 65 66 69 6e  NO_IDEA.#  defin
03e0: 65 20 4e 4f 5f 52 43 32 0a 23 20 20 64 65 66 69  e NO_RC2.#  defi
03f0: 6e 65 20 4e 4f 5f 52 43 34 0a 23 20 20 64 65 66  ne NO_RC4.#  def
0400: 69 6e 65 20 4e 4f 5f 52 43 35 0a 23 20 20 64 65  ine NO_RC5.#  de
0410: 66 69 6e 65 20 4e 4f 5f 52 53 41 0a 23 20 20 69  fine NO_RSA.#  i
0420: 66 6e 64 65 66 20 4e 4f 5f 53 53 4c 32 0a 23 20  fndef NO_SSL2.# 
0430: 20 20 20 64 65 66 69 6e 65 20 4e 4f 5f 53 53 4c     define NO_SSL
0440: 32 0a 23 20 20 65 6e 64 69 66 0a 23 65 6e 64 69  2.#  endif.#endi
0450: 66 0a 0a 23 69 6e 63 6c 75 64 65 20 3c 6f 70 65  f..#include <ope
0460: 6e 73 73 6c 2f 73 73 6c 2e 68 3e 0a 23 69 6e 63  nssl/ssl.h>.#inc
0470: 6c 75 64 65 20 3c 6f 70 65 6e 73 73 6c 2f 65 72  lude <openssl/er
0480: 72 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 6f  r.h>.#include <o
0490: 70 65 6e 73 73 6c 2f 72 61 6e 64 2e 68 3e 0a 23  penssl/rand.h>.#
04a0: 69 6e 63 6c 75 64 65 20 3c 6f 70 65 6e 73 73 6c  include <openssl
04b0: 2f 6f 70 65 6e 73 73 6c 76 2e 68 3e 0a 0a 2f 2a  /opensslv.h>../*
04c0: 0a 20 2a 20 44 65 74 65 72 6d 69 6e 65 20 69 66  . * Determine if
04d0: 20 77 65 20 73 68 6f 75 6c 64 20 75 73 65 20 74   we should use t
04e0: 68 65 20 70 72 65 2d 4f 70 65 6e 53 53 4c 20 31  he pre-OpenSSL 1
04f0: 2e 31 2e 30 20 41 50 49 0a 20 2a 2f 0a 23 75 6e  .1.0 API. */.#un
0500: 64 65 66 20 54 43 4c 54 4c 53 5f 4f 50 45 4e 53  def TCLTLS_OPENS
0510: 53 4c 5f 50 52 45 5f 31 5f 31 0a 23 69 66 20 28  SL_PRE_1_1.#if (
0520: 64 65 66 69 6e 65 64 28 4c 49 42 52 45 53 53 4c  defined(LIBRESSL
0530: 5f 56 45 52 53 49 4f 4e 5f 4e 55 4d 42 45 52 29  _VERSION_NUMBER)
0540: 29 20 7c 7c 20 4f 50 45 4e 53 53 4c 5f 56 45 52  ) || OPENSSL_VER
0550: 53 49 4f 4e 5f 4e 55 4d 42 45 52 20 3c 20 30 78  SION_NUMBER < 0x
0560: 31 30 31 30 30 30 30 30 4c 0a 23 20 20 64 65 66  10100000L.#  def
0570: 69 6e 65 20 54 43 4c 54 4c 53 5f 4f 50 45 4e 53  ine TCLTLS_OPENS
0580: 53 4c 5f 50 52 45 5f 31 5f 31 5f 41 50 49 20 31  SL_PRE_1_1_API 1
0590: 0a 23 65 6e 64 69 66 0a 0a 23 69 66 6e 64 65 66  .#endif..#ifndef
05a0: 20 45 43 4f 4e 4e 41 42 4f 52 54 45 44 0a 23 64   ECONNABORTED.#d
05b0: 65 66 69 6e 65 20 45 43 4f 4e 4e 41 42 4f 52 54  efine ECONNABORT
05c0: 45 44 09 31 33 30 09 2f 2a 20 53 6f 66 74 77 61  ED.130./* Softwa
05d0: 72 65 20 63 61 75 73 65 64 20 63 6f 6e 6e 65 63  re caused connec
05e0: 74 69 6f 6e 20 61 62 6f 72 74 20 2a 2f 0a 23 65  tion abort */.#e
05f0: 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 45 43 4f  ndif.#ifndef ECO
0600: 4e 4e 52 45 53 45 54 0a 23 64 65 66 69 6e 65 20  NNRESET.#define 
0610: 45 43 4f 4e 4e 52 45 53 45 54 09 31 33 31 09 2f  ECONNRESET.131./
0620: 2a 20 43 6f 6e 6e 65 63 74 69 6f 6e 20 72 65 73  * Connection res
0630: 65 74 20 62 79 20 70 65 65 72 20 2a 2f 0a 23 65  et by peer */.#e
0640: 6e 64 69 66 0a 0a 23 69 66 64 65 66 20 54 43 4c  ndif..#ifdef TCL
0650: 45 58 54 5f 54 43 4c 54 4c 53 5f 44 45 42 55 47  EXT_TCLTLS_DEBUG
0660: 0a 23 69 6e 63 6c 75 64 65 20 3c 63 74 79 70 65  .#include <ctype
0670: 2e 68 3e 0a 23 64 65 66 69 6e 65 20 64 70 72 69  .h>.#define dpri
0680: 6e 74 66 28 2e 2e 2e 29 20 7b 20 5c 0a 20 20 20  ntf(...) { \.   
0690: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
06a0: 20 20 20 20 63 68 61 72 20 64 70 72 69 6e 74 66      char dprintf
06b0: 42 75 66 66 65 72 5b 38 31 39 32 5d 2c 20 2a 64  Buffer[8192], *d
06c0: 70 72 69 6e 74 66 42 75 66 66 65 72 5f 70 3b 20  printfBuffer_p; 
06d0: 5c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20  \.              
06e0: 20 20 20 20 20 20 20 20 20 64 70 72 69 6e 74 66           dprintf
06f0: 42 75 66 66 65 72 5f 70 20 3d 20 26 64 70 72 69  Buffer_p = &dpri
0700: 6e 74 66 42 75 66 66 65 72 5b 30 5d 3b 20 5c 0a  ntfBuffer[0]; \.
0710: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0720: 20 20 20 20 20 20 20 64 70 72 69 6e 74 66 42 75         dprintfBu
0730: 66 66 65 72 5f 70 20 2b 3d 20 73 70 72 69 6e 74  ffer_p += sprint
0740: 66 28 64 70 72 69 6e 74 66 42 75 66 66 65 72 5f  f(dprintfBuffer_
0750: 70 2c 20 22 25 73 3a 25 69 3a 25 73 28 29 3a 22  p, "%s:%i:%s():"
0760: 2c 20 5f 5f 46 49 4c 45 5f 5f 2c 20 5f 5f 4c 49  , __FILE__, __LI
0770: 4e 45 5f 5f 2c 20 5f 5f 66 75 6e 63 5f 5f 29 3b  NE__, __func__);
0780: 20 5c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20   \.             
0790: 20 20 20 20 20 20 20 20 20 20 64 70 72 69 6e 74            dprint
07a0: 66 42 75 66 66 65 72 5f 70 20 2b 3d 20 73 70 72  fBuffer_p += spr
07b0: 69 6e 74 66 28 64 70 72 69 6e 74 66 42 75 66 66  intf(dprintfBuff
07c0: 65 72 5f 70 2c 20 5f 5f 56 41 5f 41 52 47 53 5f  er_p, __VA_ARGS_
07d0: 5f 29 3b 20 5c 0a 20 20 20 20 20 20 20 20 20 20  _); \.          
07e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 66 70 72               fpr
07f0: 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 25 73  intf(stderr, "%s
0800: 5c 6e 22 2c 20 64 70 72 69 6e 74 66 42 75 66 66  \n", dprintfBuff
0810: 65 72 29 3b 20 5c 0a 20 20 20 20 20 20 20 20 20  er); \.         
0820: 20 20 20 20 20 20 20 20 20 20 20 20 7d 0a 23 64              }.#d
0830: 65 66 69 6e 65 20 64 70 72 69 6e 74 42 75 66 66  efine dprintBuff
0840: 65 72 28 62 75 66 66 65 72 4e 61 6d 65 2c 20 62  er(bufferName, b
0850: 75 66 66 65 72 4c 65 6e 67 74 68 29 20 7b 20 5c  ufferLength) { \
0860: 0a 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 20 20 20 20 20 20 20 20                  
0890: 20 20 69 6e 74 20 64 70 72 69 6e 74 42 75 66 66    int dprintBuff
08a0: 65 72 49 64 78 3b 20 5c 0a 20 20 20 20 20 20 20  erIdx; \.       
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 75 6e 73 69 67 6e            unsign
08e0: 65 64 20 63 68 61 72 20 64 70 72 69 6e 74 42 75  ed char dprintBu
08f0: 66 66 65 72 43 68 61 72 3b 20 5c 0a 20 20 20 20  fferChar; \.    
0900: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0910: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0920: 20 20 20 20 20 20 20 20 20 20 20 20 20 66 70 72               fpr
0930: 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 25 73  intf(stderr, "%s
0940: 3a 25 69 3a 25 73 28 29 3a 25 73 5b 25 6c 6c 75  :%i:%s():%s[%llu
0950: 5d 3d 7b 22 2c 20 5f 5f 46 49 4c 45 5f 5f 2c 20  ]={", __FILE__, 
0960: 5f 5f 4c 49 4e 45 5f 5f 2c 20 5f 5f 66 75 6e 63  __LINE__, __func
0970: 5f 5f 2c 20 23 62 75 66 66 65 72 4e 61 6d 65 2c  __, #bufferName,
0980: 20 28 75 6e 73 69 67 6e 65 64 20 6c 6f 6e 67 20   (unsigned long 
0990: 6c 6f 6e 67 29 20 62 75 66 66 65 72 4c 65 6e 67  long) bufferLeng
09a0: 74 68 29 3b 20 5c 0a 20 20 20 20 20 20 20 20 20  th); \.         
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 20 20 20 66 6f 72 20 28 64 70 72          for (dpr
09e0: 69 6e 74 42 75 66 66 65 72 49 64 78 20 3d 20 30  intBufferIdx = 0
09f0: 3b 20 64 70 72 69 6e 74 42 75 66 66 65 72 49 64  ; dprintBufferId
0a00: 78 20 3c 20 62 75 66 66 65 72 4c 65 6e 67 74 68  x < bufferLength
0a10: 3b 20 64 70 72 69 6e 74 42 75 66 66 65 72 49 64  ; dprintBufferId
0a20: 78 2b 2b 29 20 7b 20 5c 0a 20 20 20 20 20 20 20  x++) { \.       
0a30: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0a40: 20 20 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 64 70 72 69 6e 74 42 75 66 66 65 72 43 68    dprintBufferCh
0a70: 61 72 20 3d 20 62 75 66 66 65 72 4e 61 6d 65 5b  ar = bufferName[
0a80: 64 70 72 69 6e 74 42 75 66 66 65 72 49 64 78 5d  dprintBufferIdx]
0a90: 3b 20 5c 0a 20 20 20 20 20 20 20 20 20 20 20 20  ; \.            
0aa0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0ab0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0ac0: 20 20 20 20 20 20 20 20 20 20 20 20 20 69 66 20               if 
0ad0: 28 69 73 61 6c 70 68 61 28 64 70 72 69 6e 74 42  (isalpha(dprintB
0ae0: 75 66 66 65 72 43 68 61 72 29 20 7c 7c 20 69 73  ufferChar) || is
0af0: 64 69 67 69 74 28 64 70 72 69 6e 74 42 75 66 66  digit(dprintBuff
0b00: 65 72 43 68 61 72 29 29 20 7b 20 5c 0a 20 20 20  erChar)) { \.   
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 20                  
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 66 70                fp
0b50: 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 27  rintf(stderr, "'
0b60: 25 63 27 20 22 2c 20 64 70 72 69 6e 74 42 75 66  %c' ", dprintBuf
0b70: 66 65 72 43 68 61 72 29 3b 20 5c 0a 20 20 20 20  ferChar); \.    
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 20                  
0bb0: 20 20 20 20 20 7d 20 65 6c 73 65 20 7b 20 5c 0a       } else { \.
0bc0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0bd0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
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 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c   fprintf(stderr,
0c10: 20 22 25 30 32 78 20 22 2c 20 28 75 6e 73 69 67   "%02x ", (unsig
0c20: 6e 65 64 20 69 6e 74 29 20 64 70 72 69 6e 74 42  ned int) dprintB
0c30: 75 66 66 65 72 43 68 61 72 29 3b 20 5c 0a 20 20  ufferChar); \.  
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 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 7d 3b 20 5c 0a 20 20 20 20         }; \.    
0c80: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
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 7d 3b 20               }; 
0cb0: 5c 0a 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 20 20 20 20 20 20                  
0ce0: 20 20 20 66 70 72 69 6e 74 66 28 73 74 64 65 72     fprintf(stder
0cf0: 72 2c 20 22 7d 5c 6e 22 29 3b 20 5c 0a 20 20 20  r, "}\n"); \.   
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 20 20                  
0d20: 20 20 20 20 20 20 20 20 20 20 20 20 7d 0a 23 64              }.#d
0d30: 65 66 69 6e 65 20 64 70 72 69 6e 74 46 6c 61 67  efine dprintFlag
0d40: 73 28 73 74 61 74 65 50 74 72 29 20 7b 20 5c 0a  s(statePtr) { \.
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: 63 68 61 72 20 64 70 72 69 6e 74 66 42 75 66 66  char dprintfBuff
0d80: 65 72 5b 38 31 39 32 5d 2c 20 2a 64 70 72 69 6e  er[8192], *dprin
0d90: 74 66 42 75 66 66 65 72 5f 70 3b 20 5c 0a 20 20  tfBuffer_p; \.  
0da0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0db0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 64 70                dp
0dc0: 72 69 6e 74 66 42 75 66 66 65 72 5f 70 20 3d 20  rintfBuffer_p = 
0dd0: 26 64 70 72 69 6e 74 66 42 75 66 66 65 72 5b 30  &dprintfBuffer[0
0de0: 5d 3b 20 5c 0a 20 20 20 20 20 20 20 20 20 20 20  ]; \.           
0df0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0e00: 20 20 20 20 20 64 70 72 69 6e 74 66 42 75 66 66       dprintfBuff
0e10: 65 72 5f 70 20 2b 3d 20 73 70 72 69 6e 74 66 28  er_p += sprintf(
0e20: 64 70 72 69 6e 74 66 42 75 66 66 65 72 5f 70 2c  dprintfBuffer_p,
0e30: 20 22 25 73 3a 25 69 3a 25 73 28 29 3a 25 73 2d   "%s:%i:%s():%s-
0e40: 3e 66 6c 61 67 73 3d 30 22 2c 20 5f 5f 46 49 4c  >flags=0", __FIL
0e50: 45 5f 5f 2c 20 5f 5f 4c 49 4e 45 5f 5f 2c 20 5f  E__, __LINE__, _
0e60: 5f 66 75 6e 63 5f 5f 2c 20 23 73 74 61 74 65 50  _func__, #stateP
0e70: 74 72 29 3b 20 5c 0a 20 20 20 20 20 20 20 20 20  tr); \.         
0e80: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0e90: 20 20 20 20 20 20 20 69 66 20 28 28 28 73 74 61         if (((sta
0ea0: 74 65 50 74 72 29 2d 3e 66 6c 61 67 73 20 26 20  tePtr)->flags & 
0eb0: 54 4c 53 5f 54 43 4c 5f 41 53 59 4e 43 29 20 3d  TLS_TCL_ASYNC) =
0ec0: 3d 20 54 4c 53 5f 54 43 4c 5f 41 53 59 4e 43 29  = TLS_TCL_ASYNC)
0ed0: 20 7b 20 64 70 72 69 6e 74 66 42 75 66 66 65 72   { dprintfBuffer
0ee0: 5f 70 20 2b 3d 20 73 70 72 69 6e 74 66 28 64 70  _p += sprintf(dp
0ef0: 72 69 6e 74 66 42 75 66 66 65 72 5f 70 2c 20 22  rintfBuffer_p, "
0f00: 7c 54 4c 53 5f 54 43 4c 5f 41 53 59 4e 43 22 29  |TLS_TCL_ASYNC")
0f10: 3b 20 7d 3b 20 5c 0a 20 20 20 20 20 20 20 20 20  ; }; \.         
0f20: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0f30: 20 20 20 20 20 20 20 69 66 20 28 28 28 73 74 61         if (((sta
0f40: 74 65 50 74 72 29 2d 3e 66 6c 61 67 73 20 26 20  tePtr)->flags & 
0f50: 54 4c 53 5f 54 43 4c 5f 53 45 52 56 45 52 29 20  TLS_TCL_SERVER) 
0f60: 3d 3d 20 54 4c 53 5f 54 43 4c 5f 53 45 52 56 45  == TLS_TCL_SERVE
0f70: 52 29 20 7b 20 64 70 72 69 6e 74 66 42 75 66 66  R) { dprintfBuff
0f80: 65 72 5f 70 20 2b 3d 20 73 70 72 69 6e 74 66 28  er_p += sprintf(
0f90: 64 70 72 69 6e 74 66 42 75 66 66 65 72 5f 70 2c  dprintfBuffer_p,
0fa0: 20 22 7c 54 4c 53 5f 54 43 4c 5f 53 45 52 56 45   "|TLS_TCL_SERVE
0fb0: 52 22 29 3b 20 7d 3b 20 5c 0a 20 20 20 20 20 20  R"); }; \.      
0fc0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0fd0: 20 20 20 20 20 20 20 20 20 20 69 66 20 28 28 28            if (((
0fe0: 73 74 61 74 65 50 74 72 29 2d 3e 66 6c 61 67 73  statePtr)->flags
0ff0: 20 26 20 54 4c 53 5f 54 43 4c 5f 49 4e 49 54 29   & TLS_TCL_INIT)
1000: 20 3d 3d 20 54 4c 53 5f 54 43 4c 5f 49 4e 49 54   == TLS_TCL_INIT
1010: 29 20 7b 20 64 70 72 69 6e 74 66 42 75 66 66 65  ) { dprintfBuffe
1020: 72 5f 70 20 2b 3d 20 73 70 72 69 6e 74 66 28 64  r_p += sprintf(d
1030: 70 72 69 6e 74 66 42 75 66 66 65 72 5f 70 2c 20  printfBuffer_p, 
1040: 22 7c 54 4c 53 5f 54 43 4c 5f 49 4e 49 54 22 29  "|TLS_TCL_INIT")
1050: 3b 20 7d 3b 20 5c 0a 20 20 20 20 20 20 20 20 20  ; }; \.         
1060: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
1070: 20 20 20 20 20 20 20 69 66 20 28 28 28 73 74 61         if (((sta
1080: 74 65 50 74 72 29 2d 3e 66 6c 61 67 73 20 26 20  tePtr)->flags & 
1090: 54 4c 53 5f 54 43 4c 5f 44 45 42 55 47 29 20 3d  TLS_TCL_DEBUG) =
10a0: 3d 20 54 4c 53 5f 54 43 4c 5f 44 45 42 55 47 29  = TLS_TCL_DEBUG)
10b0: 20 7b 20 64 70 72 69 6e 74 66 42 75 66 66 65 72   { dprintfBuffer
10c0: 5f 70 20 2b 3d 20 73 70 72 69 6e 74 66 28 64 70  _p += sprintf(dp
10d0: 72 69 6e 74 66 42 75 66 66 65 72 5f 70 2c 20 22  rintfBuffer_p, "
10e0: 7c 54 4c 53 5f 54 43 4c 5f 44 45 42 55 47 22 29  |TLS_TCL_DEBUG")
10f0: 3b 20 7d 3b 20 5c 0a 20 20 20 20 20 20 20 20 20  ; }; \.         
1100: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
1110: 20 20 20 20 20 20 20 69 66 20 28 28 28 73 74 61         if (((sta
1120: 74 65 50 74 72 29 2d 3e 66 6c 61 67 73 20 26 20  tePtr)->flags & 
1130: 54 4c 53 5f 54 43 4c 5f 43 41 4c 4c 42 41 43 4b  TLS_TCL_CALLBACK
1140: 29 20 3d 3d 20 54 4c 53 5f 54 43 4c 5f 43 41 4c  ) == TLS_TCL_CAL
1150: 4c 42 41 43 4b 29 20 7b 20 64 70 72 69 6e 74 66  LBACK) { dprintf
1160: 42 75 66 66 65 72 5f 70 20 2b 3d 20 73 70 72 69  Buffer_p += spri
1170: 6e 74 66 28 64 70 72 69 6e 74 66 42 75 66 66 65  ntf(dprintfBuffe
1180: 72 5f 70 2c 20 22 7c 54 4c 53 5f 54 43 4c 5f 43  r_p, "|TLS_TCL_C
1190: 41 4c 4c 42 41 43 4b 22 29 3b 20 7d 3b 20 5c 0a  ALLBACK"); }; \.
11a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
11b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
11c0: 69 66 20 28 28 28 73 74 61 74 65 50 74 72 29 2d  if (((statePtr)-
11d0: 3e 66 6c 61 67 73 20 26 20 54 4c 53 5f 54 43 4c  >flags & TLS_TCL
11e0: 5f 48 41 4e 44 53 48 41 4b 45 5f 46 41 49 4c 45  _HANDSHAKE_FAILE
11f0: 44 29 20 3d 3d 20 54 4c 53 5f 54 43 4c 5f 48 41  D) == TLS_TCL_HA
1200: 4e 44 53 48 41 4b 45 5f 46 41 49 4c 45 44 29 20  NDSHAKE_FAILED) 
1210: 7b 20 64 70 72 69 6e 74 66 42 75 66 66 65 72 5f  { dprintfBuffer_
1220: 70 20 2b 3d 20 73 70 72 69 6e 74 66 28 64 70 72  p += sprintf(dpr
1230: 69 6e 74 66 42 75 66 66 65 72 5f 70 2c 20 22 7c  intfBuffer_p, "|
1240: 54 4c 53 5f 54 43 4c 5f 48 41 4e 44 53 48 41 4b  TLS_TCL_HANDSHAK
1250: 45 5f 46 41 49 4c 45 44 22 29 3b 20 7d 3b 20 5c  E_FAILED"); }; \
1260: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20  .               
1270: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
1280: 20 69 66 20 28 28 28 73 74 61 74 65 50 74 72 29   if (((statePtr)
1290: 2d 3e 66 6c 61 67 73 20 26 20 54 4c 53 5f 54 43  ->flags & TLS_TC
12a0: 4c 5f 46 41 53 54 50 41 54 48 29 20 3d 3d 20 54  L_FASTPATH) == T
12b0: 4c 53 5f 54 43 4c 5f 46 41 53 54 50 41 54 48 29  LS_TCL_FASTPATH)
12c0: 20 7b 20 64 70 72 69 6e 74 66 42 75 66 66 65 72   { dprintfBuffer
12d0: 5f 70 20 2b 3d 20 73 70 72 69 6e 74 66 28 64 70  _p += sprintf(dp
12e0: 72 69 6e 74 66 42 75 66 66 65 72 5f 70 2c 20 22  rintfBuffer_p, "
12f0: 7c 54 4c 53 5f 54 43 4c 5f 46 41 53 54 50 41 54  |TLS_TCL_FASTPAT
1300: 48 22 29 3b 20 7d 3b 20 5c 0a 20 20 20 20 20 20  H"); }; \.      
1310: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
1320: 20 20 20 20 20 20 20 20 20 20 66 70 72 69 6e 74            fprint
1330: 66 28 73 74 64 65 72 72 2c 20 22 25 73 5c 6e 22  f(stderr, "%s\n"
1340: 2c 20 64 70 72 69 6e 74 66 42 75 66 66 65 72 29  , dprintfBuffer)
1350: 3b 20 5c 0a 20 20 20 20 20 20 20 20 20 20 20 20  ; \.            
1360: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
1370: 20 20 7d 0a 23 65 6c 73 65 0a 23 64 65 66 69 6e    }.#else.#defin
1380: 65 20 64 70 72 69 6e 74 66 28 2e 2e 2e 29 20 69  e dprintf(...) i
1390: 66 20 28 30 29 20 7b 20 66 70 72 69 6e 74 66 28  f (0) { fprintf(
13a0: 73 74 64 65 72 72 2c 20 5f 5f 56 41 5f 41 52 47  stderr, __VA_ARG
13b0: 53 5f 5f 29 3b 20 7d 0a 23 64 65 66 69 6e 65 20  S__); }.#define 
13c0: 64 70 72 69 6e 74 42 75 66 66 65 72 28 62 75 66  dprintBuffer(buf
13d0: 66 65 72 4e 61 6d 65 2c 20 62 75 66 66 65 72 4c  ferName, bufferL
13e0: 65 6e 67 74 68 29 20 2f 2a 2a 2f 0a 23 64 65 66  ength) /**/.#def
13f0: 69 6e 65 20 64 70 72 69 6e 74 46 6c 61 67 73 28  ine dprintFlags(
1400: 73 74 61 74 65 50 74 72 29 20 2f 2a 2a 2f 0a 23  statePtr) /**/.#
1410: 65 6e 64 69 66 0a 0a 23 64 65 66 69 6e 65 20 54  endif..#define T
1420: 43 4c 54 4c 53 5f 53 53 4c 5f 45 52 52 4f 52 28  CLTLS_SSL_ERROR(
1430: 73 73 6c 2c 65 72 72 29 20 28 28 63 68 61 72 2a  ssl,err) ((char*
1440: 29 45 52 52 5f 72 65 61 73 6f 6e 5f 65 72 72 6f  )ERR_reason_erro
1450: 72 5f 73 74 72 69 6e 67 28 28 75 6e 73 69 67 6e  r_string((unsign
1460: 65 64 20 6c 6f 6e 67 29 53 53 4c 5f 67 65 74 5f  ed long)SSL_get_
1470: 65 72 72 6f 72 28 28 73 73 6c 29 2c 28 65 72 72  error((ssl),(err
1480: 29 29 29 29 0a 2f 2a 0a 20 2a 20 4f 70 65 6e 53  ))))./*. * OpenS
1490: 53 4c 20 42 49 4f 20 52 6f 75 74 69 6e 65 73 0a  SL BIO Routines.
14a0: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 42 49 4f 5f   */.#define BIO_
14b0: 54 59 50 45 5f 54 43 4c 09 28 31 39 7c 30 78 30  TYPE_TCL.(19|0x0
14c0: 34 30 30 29 0a 0a 2f 2a 0a 20 2a 20 44 65 66 69  400)../*. * Defi
14d0: 6e 65 73 20 66 6f 72 20 53 74 61 74 65 2e 66 6c  nes for State.fl
14e0: 61 67 73 0a 20 2a 2f 0a 23 64 65 66 69 6e 65 20  ags. */.#define 
14f0: 54 4c 53 5f 54 43 4c 5f 41 53 59 4e 43 09 28 31  TLS_TCL_ASYNC.(1
1500: 3c 3c 30 29 09 2f 2a 20 6e 6f 6e 2d 62 6c 6f 63  <<0)./* non-bloc
1510: 6b 69 6e 67 20 6d 6f 64 65 20 2a 2f 0a 23 64 65  king mode */.#de
1520: 66 69 6e 65 20 54 4c 53 5f 54 43 4c 5f 53 45 52  fine TLS_TCL_SER
1530: 56 45 52 09 28 31 3c 3c 31 29 09 2f 2a 20 53 65  VER.(1<<1)./* Se
1540: 72 76 65 72 2d 53 69 64 65 20 2a 2f 0a 23 64 65  rver-Side */.#de
1550: 66 69 6e 65 20 54 4c 53 5f 54 43 4c 5f 49 4e 49  fine TLS_TCL_INI
1560: 54 09 28 31 3c 3c 32 29 09 2f 2a 20 49 6e 69 74  T.(1<<2)./* Init
1570: 69 61 6c 69 7a 69 6e 67 20 63 6f 6e 6e 65 63 74  ializing connect
1580: 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 54  ion */.#define T
1590: 4c 53 5f 54 43 4c 5f 44 45 42 55 47 09 28 31 3c  LS_TCL_DEBUG.(1<
15a0: 3c 33 29 09 2f 2a 20 53 68 6f 77 20 64 65 62 75  <3)./* Show debu
15b0: 67 20 74 72 61 63 69 6e 67 20 2a 2f 0a 23 64 65  g tracing */.#de
15c0: 66 69 6e 65 20 54 4c 53 5f 54 43 4c 5f 43 41 4c  fine TLS_TCL_CAL
15d0: 4c 42 41 43 4b 09 28 31 3c 3c 34 29 09 2f 2a 20  LBACK.(1<<4)./* 
15e0: 49 6e 20 61 20 63 61 6c 6c 62 61 63 6b 2c 20 70  In a callback, p
15f0: 72 65 76 65 6e 74 20 75 70 64 61 74 65 0a 09 09  revent update...
1600: 09 09 09 20 2a 20 6c 6f 6f 70 69 6e 67 20 70 72  ... * looping pr
1610: 6f 62 6c 65 6d 2e 20 5b 42 75 67 20 31 36 35 32  oblem. [Bug 1652
1620: 33 38 30 5d 20 2a 2f 0a 23 64 65 66 69 6e 65 20  380] */.#define 
1630: 54 4c 53 5f 54 43 4c 5f 48 41 4e 44 53 48 41 4b  TLS_TCL_HANDSHAK
1640: 45 5f 46 41 49 4c 45 44 20 28 31 3c 3c 35 29 20  E_FAILED (1<<5) 
1650: 2f 2a 20 53 65 74 20 6f 6e 20 68 61 6e 64 73 68  /* Set on handsh
1660: 61 6b 65 20 66 61 69 6c 75 72 65 73 20 61 6e 64  ake failures and
1670: 20 6f 6e 63 65 0a 20 20 20 20 20 20 20 20 20 20   once.          
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 20 20 20 20 20 20 2a                 *
16a0: 20 73 65 74 2c 20 61 6c 6c 20 66 75 72 74 68 65   set, all furthe
16b0: 72 20 49 2f 4f 20 77 69 6c 6c 20 72 65 73 75 6c  r I/O will resul
16c0: 74 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20  t.              
16d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
16e0: 20 20 20 20 20 20 20 20 20 20 20 2a 20 69 6e 20             * in 
16f0: 45 43 4f 4e 4e 41 42 4f 52 54 45 44 20 65 72 72  ECONNABORTED err
1700: 6f 72 73 2e 20 2a 2f 0a 23 64 65 66 69 6e 65 20  ors. */.#define 
1710: 54 4c 53 5f 54 43 4c 5f 46 41 53 54 50 41 54 48  TLS_TCL_FASTPATH
1720: 20 28 31 3c 3c 36 29 20 20 20 20 20 20 20 20 20   (1<<6)         
1730: 2f 2a 20 54 68 65 20 70 61 72 65 6e 74 20 63 68  /* The parent ch
1740: 61 6e 6e 65 6c 20 69 73 20 62 65 69 6e 67 20 75  annel is being u
1750: 73 65 64 20 64 69 72 65 63 74 6c 79 20 62 79 20  sed directly by 
1760: 74 68 65 20 53 53 4c 20 6c 69 62 72 61 72 79 20  the SSL library 
1770: 2a 2f 0a 23 64 65 66 69 6e 65 20 54 4c 53 5f 54  */.#define TLS_T
1780: 43 4c 5f 45 4f 46 20 28 31 3c 3c 37 29 20 20 20  CL_EOF (1<<7)   
1790: 20 20 20 20 20 20 2f 2a 20 57 65 20 69 6e 69 74        /* We init
17a0: 69 61 74 65 64 20 45 4f 46 2c 20 61 6e 79 20 66  iated EOF, any f
17b0: 75 72 74 68 65 72 20 61 74 74 65 6d 70 74 73 20  urther attempts 
17c0: 74 6f 20 77 72 69 74 65 20 77 69 6c 6c 20 72 65  to write will re
17d0: 74 75 72 6e 20 61 6e 20 65 72 72 6f 72 20 2a 2f  turn an error */
17e0: 0a 23 64 65 66 69 6e 65 20 54 4c 53 5f 54 43 4c  .#define TLS_TCL
17f0: 5f 44 45 4c 41 59 20 28 35 29 0a 0a 2f 2a 0a 20  _DELAY (5)../*. 
1800: 2a 20 54 68 69 73 20 73 74 72 75 63 74 75 72 65  * This structure
1810: 20 64 65 73 63 72 69 62 65 73 20 74 68 65 20 70   describes the p
1820: 65 72 2d 69 6e 73 74 61 6e 63 65 20 73 74 61 74  er-instance stat
1830: 65 0a 20 2a 20 6f 66 20 61 6e 20 73 73 6c 20 63  e. * of an ssl c
1840: 68 61 6e 6e 65 6c 2e 0a 20 2a 0a 20 2a 20 54 68  hannel.. *. * Th
1850: 65 20 53 53 4c 20 70 72 6f 63 65 73 73 69 6e 67  e SSL processing
1860: 20 63 6f 6e 74 65 78 74 20 69 73 20 6d 61 69 6e   context is main
1870: 74 61 69 6e 65 64 20 68 65 72 65 2c 20 69 6e 20  tained here, in 
1880: 74 68 65 20 43 6c 69 65 6e 74 44 61 74 61 0a 20  the ClientData. 
1890: 2a 2f 0a 74 79 70 65 64 65 66 20 73 74 72 75 63  */.typedef struc
18a0: 74 20 53 74 61 74 65 20 7b 0a 09 54 63 6c 5f 43  t State {..Tcl_C
18b0: 68 61 6e 6e 65 6c 20 73 65 6c 66 3b 20 20 20 20  hannel self;    
18c0: 20 20 20 2f 2a 20 74 68 69 73 20 73 6f 63 6b 65     /* this socke
18d0: 74 20 63 68 61 6e 6e 65 6c 20 2a 2f 0a 09 54 63  t channel */..Tc
18e0: 6c 5f 54 69 6d 65 72 54 6f 6b 65 6e 20 74 69 6d  l_TimerToken tim
18f0: 65 72 3b 0a 0a 09 69 6e 74 20 66 6c 61 67 73 3b  er;...int flags;
1900: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a                /*
1910: 20 73 65 65 20 53 74 61 74 65 2e 66 6c 61 67 73   see State.flags
1920: 20 61 62 6f 76 65 20 20 2a 2f 0a 09 69 6e 74 20   above  */..int 
1930: 77 61 74 63 68 4d 61 73 6b 3b 20 20 20 20 20 20  watchMask;      
1940: 20 20 20 20 2f 2a 20 63 75 72 72 65 6e 74 20 57      /* current W
1950: 61 74 63 68 50 72 6f 63 20 6d 61 73 6b 20 2a 2f  atchProc mask */
1960: 0a 09 69 6e 74 20 6d 6f 64 65 3b 20 20 20 20 20  ..int mode;     
1970: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 63 75 72            /* cur
1980: 72 65 6e 74 20 6d 6f 64 65 20 6f 66 20 70 61 72  rent mode of par
1990: 65 6e 74 20 63 68 61 6e 6e 65 6c 20 2a 2f 0a 0a  ent channel */..
19a0: 09 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74  .Tcl_Interp *int
19b0: 65 72 70 3b 20 20 20 20 20 2f 2a 20 69 6e 74 65  erp;     /* inte
19c0: 72 70 72 65 74 65 72 20 69 6e 20 77 68 69 63 68  rpreter in which
19d0: 20 74 68 69 73 20 72 65 73 69 64 65 73 20 2a 2f   this resides */
19e0: 0a 09 54 63 6c 5f 4f 62 6a 20 2a 63 61 6c 6c 62  ..Tcl_Obj *callb
19f0: 61 63 6b 3b 20 20 20 20 20 20 2f 2a 20 73 63 72  ack;      /* scr
1a00: 69 70 74 20 63 61 6c 6c 65 64 20 66 6f 72 20 74  ipt called for t
1a10: 72 61 63 69 6e 67 2c 20 76 65 72 69 66 79 69 6e  racing, verifyin
1a20: 67 20 61 6e 64 20 65 72 72 6f 72 73 20 2a 2f 0a  g and errors */.
1a30: 09 54 63 6c 5f 4f 62 6a 20 2a 70 61 73 73 77 6f  .Tcl_Obj *passwo
1a40: 72 64 3b 20 20 20 20 20 20 2f 2a 20 73 63 72 69  rd;      /* scri
1a50: 70 74 20 63 61 6c 6c 65 64 20 66 6f 72 20 63 65  pt called for ce
1a60: 72 74 69 66 69 63 61 74 65 20 70 61 73 73 77 6f  rtificate passwo
1a70: 72 64 20 2a 2f 20 0a 0a 09 69 6e 74 20 76 66 6c  rd */ ...int vfl
1a80: 61 67 73 3b 20 20 20 20 20 20 20 20 20 20 20 20  ags;            
1a90: 20 2f 2a 20 76 65 72 69 66 79 20 66 6c 61 67 73   /* verify flags
1aa0: 20 2a 2f 0a 09 53 53 4c 20 2a 73 73 6c 3b 20 20   */..SSL *ssl;  
1ab0: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20               /* 
1ac0: 53 74 72 75 63 74 20 66 6f 72 20 53 53 4c 20 70  Struct for SSL p
1ad0: 72 6f 63 65 73 73 69 6e 67 20 2a 2f 0a 09 53 53  rocessing */..SS
1ae0: 4c 5f 43 54 58 20 2a 63 74 78 3b 20 20 20 20 20  L_CTX *ctx;     
1af0: 20 20 20 20 20 20 2f 2a 20 53 53 4c 20 43 6f 6e        /* SSL Con
1b00: 74 65 78 74 20 2a 2f 0a 09 42 49 4f 20 2a 62 69  text */..BIO *bi
1b10: 6f 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20  o;              
1b20: 20 2f 2a 20 53 74 72 75 63 74 20 66 6f 72 20 53   /* Struct for S
1b30: 53 4c 20 70 72 6f 63 65 73 73 69 6e 67 20 2a 2f  SL processing */
1b40: 0a 09 42 49 4f 20 2a 70 5f 62 69 6f 3b 20 20 20  ..BIO *p_bio;   
1b50: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 50 61 72            /* Par
1b60: 65 6e 74 20 42 49 4f 20 28 74 68 61 74 20 69 73  ent BIO (that is
1b70: 20 6c 61 79 65 72 65 64 20 6f 6e 20 54 63 6c 5f   layered on Tcl_
1b80: 43 68 61 6e 6e 65 6c 29 20 2a 2f 0a 0a 09 63 68  Channel) */...ch
1b90: 61 72 20 2a 65 72 72 3b 0a 7d 20 53 74 61 74 65  ar *err;.} State
1ba0: 3b 0a 0a 23 69 66 64 65 66 20 55 53 45 5f 54 43  ;..#ifdef USE_TC
1bb0: 4c 5f 53 54 55 42 53 0a 23 69 66 6e 64 65 66 20  L_STUBS.#ifndef 
1bc0: 54 63 6c 5f 53 74 61 63 6b 43 68 61 6e 6e 65 6c  Tcl_StackChannel
1bd0: 0a 23 65 72 72 6f 72 20 22 55 6e 61 62 6c 65 20  .#error "Unable 
1be0: 74 6f 20 63 6f 6d 70 69 6c 65 20 6f 6e 20 74 68  to compile on th
1bf0: 69 73 20 76 65 72 73 69 6f 6e 20 6f 66 20 54 63  is version of Tc
1c00: 6c 22 0a 23 65 6e 64 69 66 20 2f 2a 20 54 63 6c  l".#endif /* Tcl
1c10: 5f 47 65 74 53 74 61 63 6b 65 64 43 68 61 6e 6e  _GetStackedChann
1c20: 65 6c 20 2a 2f 0a 23 65 6e 64 69 66 20 2f 2a 20  el */.#endif /* 
1c30: 55 53 45 5f 54 43 4c 5f 53 54 55 42 53 20 2a 2f  USE_TCL_STUBS */
1c40: 0a 0a 2f 2a 0a 20 2a 20 46 6f 72 77 61 72 64 20  ../*. * Forward 
1c50: 64 65 63 6c 61 72 61 74 69 6f 6e 73 0a 20 2a 2f  declarations. */
1c60: 0a 54 63 6c 5f 43 68 61 6e 6e 65 6c 54 79 70 65  .Tcl_ChannelType
1c70: 20 2a 54 6c 73 5f 43 68 61 6e 6e 65 6c 54 79 70   *Tls_ChannelTyp
1c80: 65 28 76 6f 69 64 29 3b 0a 54 63 6c 5f 43 68 61  e(void);.Tcl_Cha
1c90: 6e 6e 65 6c 20 20 20 20 20 54 6c 73 5f 47 65 74  nnel     Tls_Get
1ca0: 50 61 72 65 6e 74 28 53 74 61 74 65 20 2a 73 74  Parent(State *st
1cb0: 61 74 65 50 74 72 2c 20 69 6e 74 20 6d 61 73 6b  atePtr, int mask
1cc0: 46 6c 61 67 73 29 3b 0a 0a 54 63 6c 5f 4f 62 6a  Flags);..Tcl_Obj
1cd0: 20 20 20 20 20 20 20 20 20 2a 54 6c 73 5f 4e 65           *Tls_Ne
1ce0: 77 58 35 30 39 4f 62 6a 28 54 63 6c 5f 49 6e 74  wX509Obj(Tcl_Int
1cf0: 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 58 35 30  erp *interp, X50
1d00: 39 20 2a 63 65 72 74 29 3b 0a 76 6f 69 64 20 20  9 *cert);.void  
1d10: 20 20 20 20 20 20 20 20 20 20 54 6c 73 5f 45 72            Tls_Er
1d20: 72 6f 72 28 53 74 61 74 65 20 2a 73 74 61 74 65  ror(State *state
1d30: 50 74 72 2c 20 63 68 61 72 20 2a 6d 73 67 29 3b  Ptr, char *msg);
1d40: 0a 76 6f 69 64 20 20 20 20 20 20 20 20 20 20 20  .void           
1d50: 20 54 6c 73 5f 46 72 65 65 28 63 68 61 72 20 2a   Tls_Free(char *
1d60: 62 6c 6f 63 6b 50 74 72 29 3b 0a 76 6f 69 64 20  blockPtr);.void 
1d70: 20 20 20 20 20 20 20 20 20 20 20 54 6c 73 5f 43             Tls_C
1d80: 6c 65 61 6e 28 53 74 61 74 65 20 2a 73 74 61 74  lean(State *stat
1d90: 65 50 74 72 29 3b 0a 69 6e 74 20 20 20 20 20 20  ePtr);.int      
1da0: 20 20 20 20 20 20 20 54 6c 73 5f 57 61 69 74 46         Tls_WaitF
1db0: 6f 72 43 6f 6e 6e 65 63 74 28 53 74 61 74 65 20  orConnect(State 
1dc0: 2a 73 74 61 74 65 50 74 72 2c 20 69 6e 74 20 2a  *statePtr, int *
1dd0: 65 72 72 6f 72 43 6f 64 65 50 74 72 2c 20 69 6e  errorCodePtr, in
1de0: 74 20 68 61 6e 64 73 68 61 6b 65 46 61 69 6c 75  t handshakeFailu
1df0: 72 65 49 73 50 65 72 6d 61 6e 65 6e 74 29 3b 0a  reIsPermanent);.
1e00: 0a 42 49 4f 20 20 20 20 20 20 20 20 20 20 20 20  .BIO            
1e10: 20 2a 42 49 4f 5f 6e 65 77 5f 74 63 6c 28 53 74   *BIO_new_tcl(St
1e20: 61 74 65 2a 20 73 74 61 74 65 50 74 72 2c 20 69  ate* statePtr, i
1e30: 6e 74 20 66 6c 61 67 73 29 3b 0a 0a 23 64 65 66  nt flags);..#def
1e40: 69 6e 65 20 50 54 52 32 49 4e 54 28 78 29 20 28  ine PTR2INT(x) (
1e50: 28 69 6e 74 29 20 28 28 69 6e 74 70 74 72 5f 74  (int) ((intptr_t
1e60: 29 20 28 78 29 29 29 0a 0a 23 65 6e 64 69 66 20  ) (x)))..#endif 
1e70: 2f 2a 20 5f 54 4c 53 49 4e 54 5f 48 20 2a 2f 0a  /* _TLSINT_H */.