2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
20 File: sslHandshake.cpp
22 Contains: SSL 3.0 handshake state machine.
24 Written by: Doug Mitchell
26 Copyright: (c) 1999 by Apple Computer, Inc., all rights reserved.
30 #include "sslContext.h"
31 #include "sslHandshake.h"
32 #include "sslMemory.h"
33 #include "sslAlertMessage.h"
34 #include "sslSession.h"
37 #include "appleCdsa.h"
38 #include "sslDigests.h"
43 #define REQUEST_CERT_CORRECT 0
45 static OSStatus
SSLProcessHandshakeMessage(SSLHandshakeMsg message
, SSLContext
*ctx
);
48 SSLProcessHandshakeRecord(SSLRecord rec
, SSLContext
*ctx
)
52 SSLHandshakeMsg message
;
53 SSLBuffer messageData
;
55 if (ctx
->fragmentedMessageCache
.data
!= 0)
56 { if ((err
= SSLReallocBuffer(ctx
->fragmentedMessageCache
,
57 ctx
->fragmentedMessageCache
.length
+ rec
.contents
.length
,
59 { SSLFatalSessionAlert(SSL_AlertCloseNotify
, ctx
);
62 memcpy(ctx
->fragmentedMessageCache
.data
+ ctx
->fragmentedMessageCache
.length
,
63 rec
.contents
.data
, rec
.contents
.length
);
64 remaining
= ctx
->fragmentedMessageCache
.length
;
65 p
= ctx
->fragmentedMessageCache
.data
;
68 { remaining
= rec
.contents
.length
;
69 p
= rec
.contents
.data
;
74 break; /* we must have at least a header */
77 message
.type
= (SSLHandshakeType
)*p
++;
78 message
.contents
.length
= SSLDecodeInt(p
, 3);
79 if (((int)(message
.contents
.length
+ 4)) > remaining
)
83 message
.contents
.data
= p
;
84 p
+= message
.contents
.length
;
85 messageData
.length
= 4 + message
.contents
.length
;
86 assert(p
== messageData
.data
+ messageData
.length
);
88 /* message fragmentation */
89 remaining
-= messageData
.length
;
90 if ((err
= SSLProcessHandshakeMessage(message
, ctx
)) != 0)
93 if (message
.type
!= SSL_HdskHelloRequest
)
94 { if ((err
= SSLHashSHA1
.update(ctx
->shaState
, messageData
)) != 0 ||
95 (err
= SSLHashMD5
.update(ctx
->md5State
, messageData
)) != 0)
96 { SSLFatalSessionAlert(SSL_AlertCloseNotify
, ctx
);
101 if ((err
= SSLAdvanceHandshake(message
.type
, ctx
)) != 0)
105 if (remaining
> 0) /* Fragmented handshake message */
106 { /* If there isn't a cache, allocate one */
107 if (ctx
->fragmentedMessageCache
.data
== 0)
108 { if ((err
= SSLAllocBuffer(ctx
->fragmentedMessageCache
, remaining
, ctx
)) != 0)
109 { SSLFatalSessionAlert(SSL_AlertCloseNotify
, ctx
);
113 if (p
!= ctx
->fragmentedMessageCache
.data
)
114 { memcpy(ctx
->fragmentedMessageCache
.data
, p
, remaining
);
115 ctx
->fragmentedMessageCache
.length
= remaining
;
118 else if (ctx
->fragmentedMessageCache
.data
!= 0)
119 { if ((err
= SSLFreeBuffer(ctx
->fragmentedMessageCache
, ctx
)) != 0)
120 { SSLFatalSessionAlert(SSL_AlertCloseNotify
, ctx
);
129 SSLProcessHandshakeMessage(SSLHandshakeMsg message
, SSLContext
*ctx
)
133 SSLLogHdskMsg(message
.type
, 0);
134 switch (message
.type
)
135 { case SSL_HdskHelloRequest
:
136 if (ctx
->protocolSide
!= SSL_ClientSide
)
138 if (message
.contents
.length
> 0)
139 err
= errSSLProtocol
;
141 case SSL_HdskClientHello
:
142 if (ctx
->state
!= SSL_HdskStateServerUninit
)
144 err
= SSLProcessClientHello(message
.contents
, ctx
);
146 case SSL_HdskServerHello
:
147 if (ctx
->state
!= SSL_HdskStateServerHello
&&
148 ctx
->state
!= SSL_HdskStateServerHelloUnknownVersion
)
150 err
= SSLProcessServerHello(message
.contents
, ctx
);
153 if (ctx
->state
!= SSL_HdskStateCert
&&
154 ctx
->state
!= SSL_HdskStateClientCert
)
156 err
= SSLProcessCertificate(message
.contents
, ctx
);
157 if(ctx
->protocolSide
== SSL_ServerSide
) {
159 ctx
->clientCertState
= kSSLClientCertRejected
;
161 else if(ctx
->peerCert
!= NULL
) {
163 * This still might change if cert verify msg
164 * fails. Note we avoid going to state
165 * if we get en empty cert message which is
168 ctx
->clientCertState
= kSSLClientCertSent
;
172 case SSL_HdskCertRequest
:
173 if (((ctx
->state
!= SSL_HdskStateHelloDone
) &&
174 (ctx
->state
!= SSL_HdskStateKeyExchange
))
175 || ctx
->certRequested
)
177 err
= SSLProcessCertificateRequest(message
.contents
, ctx
);
179 case SSL_HdskServerKeyExchange
:
181 * Since this message is optional, and completely at the
182 * server's discretion, we need to be able to handle this
183 * in one of two states...
186 case SSL_HdskStateKeyExchange
: /* explicitly waiting for this */
187 case SSL_HdskStateHelloDone
:
192 err
= SSLProcessServerKeyExchange(message
.contents
, ctx
);
194 case SSL_HdskServerHelloDone
:
195 if (ctx
->state
!= SSL_HdskStateHelloDone
)
197 err
= SSLProcessServerHelloDone(message
.contents
, ctx
);
199 case SSL_HdskCertVerify
:
200 if (ctx
->state
!= SSL_HdskStateClientCertVerify
)
202 err
= SSLProcessCertificateVerify(message
.contents
, ctx
);
203 assert(ctx
->protocolSide
== SSL_ServerSide
);
205 ctx
->clientCertState
= kSSLClientCertRejected
;
208 case SSL_HdskClientKeyExchange
:
209 if (ctx
->state
!= SSL_HdskStateClientKeyExchange
)
211 err
= SSLProcessKeyExchange(message
.contents
, ctx
);
213 case SSL_HdskFinished
:
214 if (ctx
->state
!= SSL_HdskStateFinished
)
216 err
= SSLProcessFinished(message
.contents
, ctx
);
224 { if (err
== errSSLProtocol
)
225 SSLFatalSessionAlert(SSL_AlertIllegalParam
, ctx
);
226 else if (err
== errSSLNegotiation
)
227 SSLFatalSessionAlert(SSL_AlertHandshakeFail
, ctx
);
229 SSLFatalSessionAlert(SSL_AlertCloseNotify
, ctx
);
234 SSLFatalSessionAlert(SSL_AlertUnexpectedMsg
, ctx
);
235 return errSSLProtocol
;
239 SSLAdvanceHandshake(SSLHandshakeType processed
, SSLContext
*ctx
)
241 SSLBuffer sessionIdentifier
;
244 { case SSL_HdskHelloRequest
:
246 * Reset the client auth state machine in case this is
249 ctx
->certRequested
= 0;
251 ctx
->certReceived
= 0;
252 ctx
->x509Requested
= 0;
253 ctx
->clientCertState
= kSSLClientCertNone
;
254 if ((err
= SSLPrepareAndQueueMessage(SSLEncodeClientHello
, ctx
)) != 0)
256 SSLChangeHdskState(ctx
, SSL_HdskStateServerHello
);
258 case SSL_HdskClientHello
:
259 assert(ctx
->protocolSide
== SSL_ServerSide
);
260 if (ctx
->sessionID
.data
!= 0)
261 /* If session ID != 0, client is trying to resume */
262 { if (ctx
->resumableSession
.data
!= 0)
263 { if ((err
= SSLRetrieveSessionID(ctx
->resumableSession
,
264 &sessionIdentifier
, ctx
)) != 0)
266 if (sessionIdentifier
.length
== ctx
->sessionID
.length
&&
267 memcmp(sessionIdentifier
.data
, ctx
->sessionID
.data
,
268 ctx
->sessionID
.length
) == 0)
269 { /* Everything matches; resume the session */
270 sslLogResumSessDebug("===RESUMING SSL3 server-side session");
271 if ((err
= SSLInstallSessionFromData(ctx
->resumableSession
,
273 { SSLFatalSessionAlert(SSL_AlertCloseNotify
, ctx
);
276 if ((err
= SSLPrepareAndQueueMessage(SSLEncodeServerHello
,
279 if ((err
= SSLInitPendingCiphers(ctx
)) != 0 ||
280 (err
= SSLFreeBuffer(sessionIdentifier
, ctx
)) != 0)
281 { SSLFatalSessionAlert(SSL_AlertCloseNotify
, ctx
);
285 SSLPrepareAndQueueMessage(SSLEncodeChangeCipherSpec
,
288 /* Install new cipher spec on write side */
289 if ((err
= SSLDisposeCipherSuite(&ctx
->writeCipher
,
291 { SSLFatalSessionAlert(SSL_AlertCloseNotify
, ctx
);
294 ctx
->writeCipher
= ctx
->writePending
;
295 ctx
->writeCipher
.ready
= 0;
296 /* Can't send data until Finished is sent */
297 memset(&ctx
->writePending
, 0, sizeof(CipherContext
));
298 /* Zero out old data */
299 if ((err
= SSLPrepareAndQueueMessage(SSLEncodeFinishedMessage
,
302 /* Finished has been sent; enable data t6ransfer on
304 ctx
->writeCipher
.ready
= 1;
305 SSLChangeHdskState(ctx
, SSL_HdskStateChangeCipherSpec
);
309 sslLogResumSessDebug(
310 "===FAILED TO RESUME SSL3 server-side session");
312 if ((err
= SSLFreeBuffer(sessionIdentifier
, ctx
)) != 0 ||
313 (err
= SSLDeleteSessionData(ctx
)) != 0)
314 { SSLFatalSessionAlert(SSL_AlertCloseNotify
, ctx
);
318 if ((err
= SSLFreeBuffer(ctx
->sessionID
, ctx
)) != 0)
319 { SSLFatalSessionAlert(SSL_AlertCloseNotify
, ctx
);
325 * If we get here, we're not resuming; generate a new session ID
326 * if we know our peer
328 if (ctx
->peerID
.data
!= 0)
329 { /* Ignore errors; just treat as uncached session */
330 assert(ctx
->sessionID
.data
== 0);
331 err
= SSLAllocBuffer(ctx
->sessionID
, SSL_SESSION_ID_LEN
, ctx
);
334 if((err
= sslRand(ctx
, &ctx
->sessionID
)) != 0)
335 { SSLFatalSessionAlert(SSL_AlertCloseNotify
, ctx
);
341 if ((err
= SSLPrepareAndQueueMessage(SSLEncodeServerHello
, ctx
)) != 0)
343 switch (ctx
->selectedCipherSpec
->keyExchangeMethod
)
344 { case SSL_NULL_auth
:
347 case SSL_DH_anon_EXPORT
:
348 if(ctx
->clientAuth
== kAlwaysAuthenticate
) {
349 /* app requires this; abort */
350 SSLFatalSessionAlert(SSL_AlertHandshakeFail
, ctx
);
351 return errSSLNegotiation
;
353 ctx
->tryClientAuth
= false;
354 /* DH server side needs work */
356 #endif /* APPLE_DH */
357 default: /* everything else */
358 if ((err
= SSLPrepareAndQueueMessage(SSLEncodeCertificate
,
364 * At this point we decide whether to send a server key exchange
365 * method. For Apple servers, I think we'll ALWAYS do this, because
366 * of key usage restrictions (can't decrypt and sign with the same
367 * private key), but conceptually in this code, we do it if
368 * enabled by the presence of encryptPrivKey.
370 #if SSL_SERVER_KEYEXCH_HACK
372 * This is currently how we work with Netscape. It requires
373 * a CSP which can handle private keys which can both
376 if((ctx
->selectedCipherSpec
->keyExchangeMethod
!= SSL_RSA
) &&
377 (ctx
->encryptPrivKey
!= NULL
)) {
378 err
= SSLPrepareAndQueueMessage(SSLEncodeServerKeyExchange
, ctx
);
383 #else /* !SSL_SERVER_KEYEXCH_HACK */
385 * This is, I believe the "right" way, but Netscape doesn't
388 if (ctx
->encryptPrivKey
!= NULL
) {
389 err
= SSLPrepareAndQueueMessage(SSLEncodeServerKeyExchange
, ctx
);
394 #endif /* SSL_SERVER_KEYEXCH_HACK */
396 if (ctx
->tryClientAuth
)
397 { if ((err
= SSLPrepareAndQueueMessage(SSLEncodeCertificateRequest
,
400 ctx
->certRequested
= 1;
401 ctx
->clientCertState
= kSSLClientCertRequested
;
403 if ((err
= SSLPrepareAndQueueMessage(SSLEncodeServerHelloDone
, ctx
)) != 0)
405 if (ctx
->certRequested
) {
406 SSLChangeHdskState(ctx
, SSL_HdskStateClientCert
);
409 SSLChangeHdskState(ctx
, SSL_HdskStateClientKeyExchange
);
412 case SSL_HdskServerHello
:
413 if (ctx
->resumableSession
.data
!= 0 && ctx
->sessionID
.data
!= 0)
414 { if ((err
= SSLRetrieveSessionID(ctx
->resumableSession
,
415 &sessionIdentifier
, ctx
)) != 0)
416 { SSLFatalSessionAlert(SSL_AlertCloseNotify
, ctx
);
419 if (sessionIdentifier
.length
== ctx
->sessionID
.length
&&
420 memcmp(sessionIdentifier
.data
, ctx
->sessionID
.data
,
421 ctx
->sessionID
.length
) == 0)
422 { /* Everything matches; resume the session */
423 sslLogResumSessDebug("===RESUMING SSL3 client-side session");
424 if ((err
= SSLInstallSessionFromData(ctx
->resumableSession
,
426 (err
= SSLInitPendingCiphers(ctx
)) != 0 ||
427 (err
= SSLFreeBuffer(sessionIdentifier
, ctx
)) != 0)
428 { SSLFatalSessionAlert(SSL_AlertCloseNotify
, ctx
);
431 SSLChangeHdskState(ctx
, SSL_HdskStateChangeCipherSpec
);
435 sslLogResumSessDebug("===FAILED TO RESUME SSL3 client-side "
438 if ((err
= SSLFreeBuffer(sessionIdentifier
, ctx
)) != 0)
439 { SSLFatalSessionAlert(SSL_AlertCloseNotify
, ctx
);
443 switch (ctx
->selectedCipherSpec
->keyExchangeMethod
)
445 /* these require a key exchange message */
448 case SSL_DH_anon_EXPORT
:
449 SSLChangeHdskState(ctx
, SSL_HdskStateKeyExchange
);
453 case SSL_DH_DSS_EXPORT
:
455 case SSL_DH_RSA_EXPORT
:
458 case SSL_DHE_DSS_EXPORT
:
460 case SSL_DHE_RSA_EXPORT
:
462 SSLChangeHdskState(ctx
, SSL_HdskStateCert
);
465 assert("Unknown key exchange method");
470 if (ctx
->state
== SSL_HdskStateCert
)
471 switch (ctx
->selectedCipherSpec
->keyExchangeMethod
)
474 * I really think the two RSA cases should be
475 * handled the same here - the server key exchange is
476 * optional, and is up to the server.
477 * Note this isn't the same as SSL_SERVER_KEYEXCH_HACK;
478 * we're a client here.
482 case SSL_DH_DSS_EXPORT
:
484 case SSL_DH_RSA_EXPORT
:
485 SSLChangeHdskState(ctx
, SSL_HdskStateHelloDone
);
488 case SSL_DHE_DSS_EXPORT
:
490 case SSL_DHE_RSA_EXPORT
:
492 SSLChangeHdskState(ctx
, SSL_HdskStateKeyExchange
);
495 assert("Unknown or unexpected key exchange method");
498 else if (ctx
->state
== SSL_HdskStateClientCert
)
499 { SSLChangeHdskState(ctx
, SSL_HdskStateClientKeyExchange
);
500 if (ctx
->peerCert
!= 0)
501 ctx
->certReceived
= 1;
504 case SSL_HdskCertRequest
:
505 /* state stays in SSL_HdskStateHelloDone; distinction is in
506 * ctx->certRequested */
507 if (ctx
->peerCert
== 0)
508 { SSLFatalSessionAlert(SSL_AlertHandshakeFail
, ctx
);
509 return errSSLProtocol
;
511 ctx
->certRequested
= 1;
512 ctx
->clientCertState
= kSSLClientCertRequested
;
514 case SSL_HdskServerKeyExchange
:
515 SSLChangeHdskState(ctx
, SSL_HdskStateHelloDone
);
517 case SSL_HdskServerHelloDone
:
518 if (ctx
->certRequested
) {
520 * Server wants a client authentication cert - do
523 if (ctx
->localCert
!= 0 && ctx
->x509Requested
) {
524 if ((err
= SSLPrepareAndQueueMessage(SSLEncodeCertificate
,
530 /* response for no cert depends on protocol version */
531 if(ctx
->negProtocolVersion
== TLS_Version_1_0
) {
532 /* TLS: send empty cert msg */
533 if ((err
= SSLPrepareAndQueueMessage(SSLEncodeCertificate
,
539 /* SSL3: "no cert" alert */
540 if ((err
= SSLSendAlert(SSL_AlertLevelWarning
, SSL_AlertNoCert
,
545 } /* no cert to send */
546 } /* server requested a cert */
547 if ((err
= SSLPrepareAndQueueMessage(SSLEncodeKeyExchange
, ctx
)) != 0)
549 assert(ctx
->sslTslCalls
!= NULL
);
550 if ((err
= ctx
->sslTslCalls
->generateMasterSecret(ctx
)) != 0 ||
551 (err
= SSLInitPendingCiphers(ctx
)) != 0)
552 { SSLFatalSessionAlert(SSL_AlertCloseNotify
, ctx
);
555 memset(ctx
->preMasterSecret
.data
, 0, ctx
->preMasterSecret
.length
);
556 if ((err
= SSLFreeBuffer(ctx
->preMasterSecret
, ctx
)) != 0) {
560 if ((err
= SSLPrepareAndQueueMessage(SSLEncodeCertificateVerify
,
565 if ((err
= SSLPrepareAndQueueMessage(SSLEncodeChangeCipherSpec
,
569 /* Install new cipher spec on write side */
570 if ((err
= SSLDisposeCipherSuite(&ctx
->writeCipher
, ctx
)) != 0)
571 { SSLFatalSessionAlert(SSL_AlertCloseNotify
, ctx
);
574 ctx
->writeCipher
= ctx
->writePending
;
575 /* Can't send data until Finished is sent */
576 ctx
->writeCipher
.ready
= 0;
578 /* Zero out old data */
579 memset(&ctx
->writePending
, 0, sizeof(CipherContext
));
580 ctx
->writePending
.encrypting
= 1;
581 if ((err
= SSLPrepareAndQueueMessage(SSLEncodeFinishedMessage
, ctx
)) != 0)
583 /* Finished has been sent; enable data transfer on write channel */
584 ctx
->writeCipher
.ready
= 1;
585 SSLChangeHdskState(ctx
, SSL_HdskStateChangeCipherSpec
);
587 case SSL_HdskCertVerify
:
588 SSLChangeHdskState(ctx
, SSL_HdskStateChangeCipherSpec
);
590 case SSL_HdskClientKeyExchange
:
591 assert(ctx
->sslTslCalls
!= NULL
);
592 if ((err
= ctx
->sslTslCalls
->generateMasterSecret(ctx
)) != 0 ||
593 (err
= SSLInitPendingCiphers(ctx
)) != 0)
594 { SSLFatalSessionAlert(SSL_AlertCloseNotify
, ctx
);
597 memset(ctx
->preMasterSecret
.data
, 0, ctx
->preMasterSecret
.length
);
598 if ((err
= SSLFreeBuffer(ctx
->preMasterSecret
, ctx
)) != 0)
600 if (ctx
->certReceived
) {
601 SSLChangeHdskState(ctx
, SSL_HdskStateClientCertVerify
);
604 SSLChangeHdskState(ctx
, SSL_HdskStateChangeCipherSpec
);
607 case SSL_HdskFinished
:
608 /* Handshake is over; enable data transfer on read channel */
609 ctx
->readCipher
.ready
= 1;
610 /* If writePending is set, we haven't yet sent a finished message;
612 if (ctx
->writePending
.ready
!= 0)
613 { if ((err
= SSLPrepareAndQueueMessage(SSLEncodeChangeCipherSpec
,
617 /* Install new cipher spec on write side */
618 if ((err
= SSLDisposeCipherSuite(&ctx
->writeCipher
, ctx
)) != 0)
619 { SSLFatalSessionAlert(SSL_AlertCloseNotify
, ctx
);
622 ctx
->writeCipher
= ctx
->writePending
;
623 ctx
->writeCipher
.ready
= 0;
624 /* Can't send data until Finished is sent */
625 memset(&ctx
->writePending
, 0, sizeof(CipherContext
));
626 /* Zero out old data */
627 if ((err
= SSLPrepareAndQueueMessage(SSLEncodeFinishedMessage
,
630 ctx
->writeCipher
.ready
= 1;
632 if (ctx
->protocolSide
== SSL_ServerSide
) {
633 SSLChangeHdskState(ctx
, SSL2_HdskStateServerReady
);
636 SSLChangeHdskState(ctx
, SSL2_HdskStateClientReady
);
638 if (ctx
->peerID
.data
!= 0)
639 SSLAddSessionData(ctx
);
642 assert("Unknown State");
650 SSLPrepareAndQueueMessage(EncodeMessageFunc msgFunc
, SSLContext
*ctx
)
654 if ((err
= msgFunc(rec
, ctx
)) != 0)
655 { SSLFatalSessionAlert(SSL_AlertCloseNotify
, ctx
);
659 if (rec
.contentType
== SSL_RecordTypeHandshake
)
660 { if ((err
= SSLHashSHA1
.update(ctx
->shaState
, rec
.contents
)) != 0 ||
661 (err
= SSLHashMD5
.update(ctx
->md5State
, rec
.contents
)) != 0)
662 { SSLFatalSessionAlert(SSL_AlertCloseNotify
, ctx
);
665 SSLLogHdskMsg((SSLHandshakeType
)rec
.contents
.data
[0], 1);
668 assert(ctx
->sslTslCalls
!= NULL
);
669 if ((err
= ctx
->sslTslCalls
->writeRecord(rec
, ctx
)) != 0)
674 SSLFreeBuffer(rec
.contents
, ctx
);
680 SSL3ReceiveSSL2ClientHello(SSLRecord rec
, SSLContext
*ctx
)
683 if ((err
= SSLInitMessageHashes(ctx
)) != 0)
686 if ((err
= SSLHashSHA1
.update(ctx
->shaState
, rec
.contents
)) != 0 ||
687 (err
= SSLHashMD5
.update(ctx
->md5State
, rec
.contents
)) != 0)
688 { SSLFatalSessionAlert(SSL_AlertCloseNotify
, ctx
);
692 if ((err
= SSLAdvanceHandshake(SSL_HdskClientHello
, ctx
)) != 0)
698 /* log changes in handshake state */
702 char *hdskStateToStr(SSLHandshakeState state
)
704 static char badStr
[100];
707 case SSL_HdskStateUninit
:
709 case SSL_HdskStateServerUninit
:
710 return "ServerUninit";
711 case SSL_HdskStateClientUninit
:
712 return "ClientUninit";
713 case SSL_HdskStateGracefulClose
:
714 return "GracefulClose";
715 case SSL_HdskStateErrorClose
:
717 case SSL_HdskStateNoNotifyClose
:
718 return "NoNotifyClose";
719 case SSL_HdskStateServerHello
:
720 return "ServerHello";
721 case SSL_HdskStateServerHelloUnknownVersion
:
722 return "ServerHelloUnknownVersion";
723 case SSL_HdskStateKeyExchange
:
724 return "KeyExchange";
725 case SSL_HdskStateCert
:
727 case SSL_HdskStateHelloDone
:
729 case SSL_HdskStateClientCert
:
731 case SSL_HdskStateClientKeyExchange
:
732 return "ClientKeyExchange";
733 case SSL_HdskStateClientCertVerify
:
734 return "ClientCertVerify";
735 case SSL_HdskStateChangeCipherSpec
:
736 return "ChangeCipherSpec";
737 case SSL_HdskStateFinished
:
739 case SSL2_HdskStateClientMasterKey
:
740 return "SSL2_ClientMasterKey";
741 case SSL2_HdskStateClientFinished
:
742 return "SSL2_ClientFinished";
743 case SSL2_HdskStateServerHello
:
744 return "SSL2_ServerHello";
745 case SSL2_HdskStateServerVerify
:
746 return "SSL2_ServerVerify";
747 case SSL2_HdskStateServerFinished
:
748 return "SSL2_ServerFinished";
749 case SSL2_HdskStateServerReady
:
750 return "SSL2_ServerReady";
751 case SSL2_HdskStateClientReady
:
752 return "SSL2_ClientReady";
754 sprintf(badStr
, "Unknown state (%d(d)", state
);
759 void SSLChangeHdskState(SSLContext
*ctx
, SSLHandshakeState newState
)
761 /* FIXME - this ifndef should not be necessary */
763 sslHdskStateDebug("...hdskState = %s", hdskStateToStr(newState
));
765 ctx
->state
= newState
;
769 /* log handshake messages */
771 static char *hdskMsgToStr(SSLHandshakeType msg
)
773 static char badStr
[100];
776 case SSL_HdskHelloRequest
:
777 return "SSL_HdskHelloRequest";
778 case SSL_HdskClientHello
:
779 return "SSL_HdskClientHello";
780 case SSL_HdskServerHello
:
781 return "SSL_HdskServerHello";
783 return "SSL_HdskCert";
784 case SSL_HdskServerKeyExchange
:
785 return "SSL_HdskServerKeyExchange";
786 case SSL_HdskCertRequest
:
787 return "SSL_HdskCertRequest";
788 case SSL_HdskServerHelloDone
:
789 return "SSL_HdskServerHelloDone";
790 case SSL_HdskCertVerify
:
791 return "SSL_HdskCertVerify";
792 case SSL_HdskClientKeyExchange
:
793 return "SSL_HdskClientKeyExchange";
794 case SSL_HdskFinished
:
795 return "SSL_HdskFinished";
796 case SSL_HdskNoCertAlert
:
797 return "SSL_HdskNoCertAlert";
799 sprintf(badStr
, "Unknown state (%d(d)", msg
);
804 void SSLLogHdskMsg(SSLHandshakeType msg
, char sent
)
806 sslHdskMsgDebug("---%s handshake msg %s",
807 hdskMsgToStr(msg
), (sent
? "sent" : "recv"));