︙ | | | ︙ | |
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
* Also work done by the follow people provided the impetus to do this "right":
* tclSSL (Colin McCormack, Shared Technology)
* SSLtcl (Peter Antman)
*
*/
#include "tlsInt.h"
/*
* Forward declarations
*/
static void TlsChannelHandlerTimer(ClientData clientData);
/*
|
>
|
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
* Also work done by the follow people provided the impetus to do this "right":
* tclSSL (Colin McCormack, Shared Technology)
* SSLtcl (Peter Antman)
*
*/
#include "tlsInt.h"
#include <errno.h>
/*
* Forward declarations
*/
static void TlsChannelHandlerTimer(ClientData clientData);
/*
|
︙ | | | ︙ | |
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
*
*------------------------------------------------------*
*/
int Tls_WaitForConnect(State *statePtr, int *errorCodePtr, int handshakeFailureIsPermanent) {
unsigned long backingError;
int err, rc;
int bioShouldRetry;
dprintf("WaitForConnect(%p)", (void *) statePtr);
dprintFlags(statePtr);
if (!(statePtr->flags & TLS_TCL_INIT)) {
dprintf("Tls_WaitForConnect called on already initialized channel -- returning with immediate success");
*errorCodePtr = 0;
return(0);
}
if (statePtr->flags & TLS_TCL_HANDSHAKE_FAILED) {
/*
* Different types of operations have different requirements
* SSL being established
|
>
<
|
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
*
*------------------------------------------------------*
*/
int Tls_WaitForConnect(State *statePtr, int *errorCodePtr, int handshakeFailureIsPermanent) {
unsigned long backingError;
int err, rc;
int bioShouldRetry;
*errorCodePtr = 0;
dprintf("WaitForConnect(%p)", (void *) statePtr);
dprintFlags(statePtr);
if (!(statePtr->flags & TLS_TCL_INIT)) {
dprintf("Tls_WaitForConnect called on already initialized channel -- returning with immediate success");
return(0);
}
if (statePtr->flags & TLS_TCL_HANDSHAKE_FAILED) {
/*
* Different types of operations have different requirements
* SSL being established
|
︙ | | | ︙ | |
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
}
}
dprintf("We have either completely established the session or completely failed it -- there is no more need to ever retry it though");
break;
}
*errorCodePtr = EINVAL;
switch (rc) {
case SSL_ERROR_NONE:
/* The connection is up, we are done here */
dprintf("The connection is up");
break;
case SSL_ERROR_ZERO_RETURN:
dprintf("SSL_ERROR_ZERO_RETURN: Connect returned an invalid value...")
return(-1);
case SSL_ERROR_SYSCALL:
backingError = ERR_get_error();
if (backingError == 0 && err == 0) {
dprintf("EOF reached")
*errorCodePtr = ECONNRESET;
|
<
<
>
|
>
|
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
}
}
dprintf("We have either completely established the session or completely failed it -- there is no more need to ever retry it though");
break;
}
switch (rc) {
case SSL_ERROR_NONE:
/* The connection is up, we are done here */
dprintf("The connection is up");
*errorCodePtr = 0;
break;
case SSL_ERROR_ZERO_RETURN:
dprintf("SSL_ERROR_ZERO_RETURN: Connect returned an invalid value...");
*errorCodePtr = EINVAL;
return(-1);
case SSL_ERROR_SYSCALL:
backingError = ERR_get_error();
if (backingError == 0 && err == 0) {
dprintf("EOF reached")
*errorCodePtr = ECONNRESET;
|
︙ | | | ︙ | |
304
305
306
307
308
309
310
311
312
313
314
315
316
317
|
return(0);
}
dprintf("Calling Tls_WaitForConnect");
tlsConnect = Tls_WaitForConnect(statePtr, errorCodePtr, 0);
if (tlsConnect < 0) {
dprintf("Got an error waiting to connect (tlsConnect = %i, *errorCodePtr = %i)", tlsConnect, *errorCodePtr);
bytesRead = -1;
if (*errorCodePtr == ECONNRESET) {
dprintf("Got connection reset");
/* Soft EOF */
*errorCodePtr = 0;
bytesRead = 0;
|
>
|
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
|
return(0);
}
dprintf("Calling Tls_WaitForConnect");
tlsConnect = Tls_WaitForConnect(statePtr, errorCodePtr, 0);
if (tlsConnect < 0) {
dprintf("Got an error waiting to connect (tlsConnect = %i, *errorCodePtr = %i)", tlsConnect, *errorCodePtr);
Tls_Error(statePtr, strerror(*errorCodePtr));
bytesRead = -1;
if (*errorCodePtr == ECONNRESET) {
dprintf("Got connection reset");
/* Soft EOF */
*errorCodePtr = 0;
bytesRead = 0;
|
︙ | | | ︙ | |
391
392
393
394
395
396
397
398
399
400
401
402
403
404
|
default:
dprintf("Unknown error (err = %i), mapping to EOF", err);
*errorCodePtr = 0;
bytesRead = 0;
break;
}
dprintf("Input(%d) -> %d [%d]", bufSize, bytesRead, *errorCodePtr);
return(bytesRead);
}
/*
*-------------------------------------------------------------------
*
|
>
>
>
|
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
|
default:
dprintf("Unknown error (err = %i), mapping to EOF", err);
*errorCodePtr = 0;
bytesRead = 0;
break;
}
if (*errorCodePtr < 0) {
Tls_Error(statePtr, strerror(*errorCodePtr));
}
dprintf("Input(%d) -> %d [%d]", bufSize, bytesRead, *errorCodePtr);
return(bytesRead);
}
/*
*-------------------------------------------------------------------
*
|
︙ | | | ︙ | |
434
435
436
437
438
439
440
441
442
443
444
445
446
447
|
return(-1);
}
dprintf("Calling Tls_WaitForConnect");
tlsConnect = Tls_WaitForConnect(statePtr, errorCodePtr, 1);
if (tlsConnect < 0) {
dprintf("Got an error waiting to connect (tlsConnect = %i, *errorCodePtr = %i)", tlsConnect, *errorCodePtr);
written = -1;
if (*errorCodePtr == ECONNRESET) {
dprintf("Got connection reset");
/* Soft EOF */
*errorCodePtr = 0;
written = 0;
|
>
|
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
|
return(-1);
}
dprintf("Calling Tls_WaitForConnect");
tlsConnect = Tls_WaitForConnect(statePtr, errorCodePtr, 1);
if (tlsConnect < 0) {
dprintf("Got an error waiting to connect (tlsConnect = %i, *errorCodePtr = %i)", tlsConnect, *errorCodePtr);
Tls_Error(statePtr, strerror(*errorCodePtr));
written = -1;
if (*errorCodePtr == ECONNRESET) {
dprintf("Got connection reset");
/* Soft EOF */
*errorCodePtr = 0;
written = 0;
|
︙ | | | ︙ | |
534
535
536
537
538
539
540
541
542
543
544
545
546
547
|
break;
default:
dprintf(" unknown err: %d", err);
break;
}
dprintf("Output(%d) -> %d", toWrite, written);
return(written);
}
/*
*-------------------------------------------------------------------
*
|
>
>
>
|
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
|
break;
default:
dprintf(" unknown err: %d", err);
break;
}
if (*errorCodePtr < 0) {
Tls_Error(statePtr, strerror(*errorCodePtr));
}
dprintf("Output(%d) -> %d", toWrite, written);
return(written);
}
/*
*-------------------------------------------------------------------
*
|
︙ | | | ︙ | |
773
774
775
776
777
778
779
780
781
782
783
784
785
786
|
dprintf("Returning 0 due to callback");
return 0;
}
dprintf("Calling Tls_WaitForConnect");
errorCode = 0;
if (Tls_WaitForConnect(statePtr, &errorCode, 1) < 0) {
if (errorCode == EAGAIN) {
dprintf("Async flag could be set (didn't check) and errorCode == EAGAIN: Returning 0");
return 0;
}
dprintf("Tls_WaitForConnect returned an error");
|
>
|
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
|
dprintf("Returning 0 due to callback");
return 0;
}
dprintf("Calling Tls_WaitForConnect");
errorCode = 0;
if (Tls_WaitForConnect(statePtr, &errorCode, 1) < 0) {
Tls_Error(statePtr, strerror(errorCode));
if (errorCode == EAGAIN) {
dprintf("Async flag could be set (didn't check) and errorCode == EAGAIN: Returning 0");
return 0;
}
dprintf("Tls_WaitForConnect returned an error");
|
︙ | | | ︙ | |