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.
22 Contains: SSL 3.0 handshake state machine.
24 Written by: Doug Mitchell, based on Netscape SSLRef 3.0
26 Copyright: (c) 1999 by Apple Computer, Inc., all rights reserved.
29 /* *********************************************************************
32 SSLRef 3.0 Final -- 11/19/96
34 Copyright (c)1996 by Netscape Communications Corp.
36 By retrieving this software you are bound by the licensing terms
37 disclosed in the file "LICENSE.txt". Please read it, and if you don't
38 accept the terms, delete this software.
40 SSLRef 3.0 was developed by Netscape Communications Corp. of Mountain
41 View, California <http://home.netscape.com/> and Consensus Development
42 Corporation of Berkeley, California <http://www.consensus.com/>.
44 *********************************************************************
46 File: sslhdshk.c SSL 3.0 handshake state machine
48 Support for SSL Handshake messages, including extracting handshake
49 messages from record layer records, processing those messages
50 (including verifying their appropriateness) and then advancing the
51 handshake by generating response messages and/or changing the state
52 such that different messages are expected. In addition, controls when
55 ****************************************************************** */
85 #ifndef _APPLE_CDSA_H_
86 #include "appleCdsa.h"
93 #define REQUEST_CERT_CORRECT 0
95 static SSLErr
SSLProcessHandshakeMessage(SSLHandshakeMsg message
, SSLContext
*ctx
);
98 SSLProcessHandshakeRecord(SSLRecord rec
, SSLContext
*ctx
)
102 SSLHandshakeMsg message
;
103 SSLBuffer messageData
;
105 if (ctx
->fragmentedMessageCache
.data
!= 0)
106 { if ((err
= SSLReallocBuffer(&ctx
->fragmentedMessageCache
,
107 ctx
->fragmentedMessageCache
.length
+ rec
.contents
.length
,
109 { ERR(SSLFatalSessionAlert(alert_close_notify
, ctx
));
112 memcpy(ctx
->fragmentedMessageCache
.data
+ ctx
->fragmentedMessageCache
.length
,
113 rec
.contents
.data
, rec
.contents
.length
);
114 remaining
= ctx
->fragmentedMessageCache
.length
;
115 p
= ctx
->fragmentedMessageCache
.data
;
118 { remaining
= rec
.contents
.length
;
119 p
= rec
.contents
.data
;
122 while (remaining
> 0)
124 break; /* we must have at least a header */
126 messageData
.data
= p
;
127 message
.type
= (SSLHandshakeType
)*p
++;
128 message
.contents
.length
= SSLDecodeInt(p
, 3);
129 if ((message
.contents
.length
+ 4) > remaining
)
133 message
.contents
.data
= p
;
134 p
+= message
.contents
.length
;
135 messageData
.length
= 4 + message
.contents
.length
;
136 CASSERT(p
== messageData
.data
+ messageData
.length
);
138 /* message fragmentation */
139 remaining
-= messageData
.length
;
140 if (ERR(err
= SSLProcessHandshakeMessage(message
, ctx
)) != 0)
143 if (message
.type
!= SSL_hello_request
)
144 { if (ERR(err
= SSLHashSHA1
.update(ctx
->shaState
, messageData
)) != 0 ||
145 ERR(err
= SSLHashMD5
.update(ctx
->md5State
, messageData
)) != 0)
146 { ERR(SSLFatalSessionAlert(alert_close_notify
, ctx
));
151 if (ERR(err
= SSLAdvanceHandshake(message
.type
, ctx
)) != 0)
155 if (remaining
> 0) /* Fragmented handshake message */
156 { /* If there isn't a cache, allocate one */
157 if (ctx
->fragmentedMessageCache
.data
== 0)
158 { if (ERR(err
= SSLAllocBuffer(&ctx
->fragmentedMessageCache
, remaining
, &ctx
->sysCtx
)) != 0)
159 { ERR(SSLFatalSessionAlert(alert_close_notify
, ctx
));
163 if (p
!= ctx
->fragmentedMessageCache
.data
)
164 { memcpy(ctx
->fragmentedMessageCache
.data
, p
, remaining
);
165 ctx
->fragmentedMessageCache
.length
= remaining
;
168 else if (ctx
->fragmentedMessageCache
.data
!= 0)
169 { if (ERR(err
= SSLFreeBuffer(&ctx
->fragmentedMessageCache
, &ctx
->sysCtx
)) != 0)
170 { ERR(SSLFatalSessionAlert(alert_close_notify
, ctx
));
179 SSLProcessHandshakeMessage(SSLHandshakeMsg message
, SSLContext
*ctx
)
183 SSLLogHdskMsg(message
.type
, 0);
184 switch (message
.type
)
185 { case SSL_hello_request
:
186 if (ctx
->protocolSide
!= SSL_ClientSide
)
188 if (message
.contents
.length
> 0)
189 err
= ERR(SSLProtocolErr
);
191 case SSL_client_hello
:
192 if (ctx
->state
!= HandshakeServerUninit
)
194 ERR(err
= SSLProcessClientHello(message
.contents
, ctx
));
196 case SSL_server_hello
:
197 if (ctx
->state
!= HandshakeServerHello
&&
198 ctx
->state
!= HandshakeServerHelloUnknownVersion
)
200 ERR(err
= SSLProcessServerHello(message
.contents
, ctx
));
202 case SSL_certificate
:
203 if (ctx
->state
!= HandshakeCertificate
&&
204 ctx
->state
!= HandshakeClientCertificate
)
206 ERR(err
= SSLProcessCertificate(message
.contents
, ctx
));
208 case SSL_certificate_request
:
209 if ((ctx
->state
!= HandshakeHelloDone
&& ctx
->state
!= HandshakeKeyExchange
)
210 || ctx
->certRequested
)
212 ERR(err
= SSLProcessCertificateRequest(message
.contents
, ctx
));
214 case SSL_server_key_exchange
:
216 * Since this message is optional, and completely at the
217 * server's discretion, we need to be able to handle this
218 * in one of two states...
221 case HandshakeKeyExchange
: /* explicitly waiting for this */
222 case HandshakeHelloDone
:
227 ERR(err
= SSLProcessServerKeyExchange(message
.contents
, ctx
));
229 case SSL_server_hello_done
:
230 if (ctx
->state
!= HandshakeHelloDone
)
232 ERR(err
= SSLProcessServerHelloDone(message
.contents
, ctx
));
234 case SSL_certificate_verify
:
235 if (ctx
->state
!= HandshakeClientCertVerify
)
237 ERR(err
= SSLProcessCertificateVerify(message
.contents
, ctx
));
239 case SSL_client_key_exchange
:
240 if (ctx
->state
!= HandshakeClientKeyExchange
)
242 ERR(err
= SSLProcessKeyExchange(message
.contents
, ctx
));
245 if (ctx
->state
!= HandshakeFinished
)
247 ERR(err
= SSLProcessFinished(message
.contents
, ctx
));
255 { if (err
== SSLProtocolErr
)
256 ERR(SSLFatalSessionAlert(alert_illegal_parameter
, ctx
));
257 else if (err
== SSLNegotiationErr
)
258 ERR(SSLFatalSessionAlert(alert_handshake_failure
, ctx
));
260 ERR(SSLFatalSessionAlert(alert_close_notify
, ctx
));
265 ERR(SSLFatalSessionAlert(alert_unexpected_message
, ctx
));
266 return ERR(SSLProtocolErr
);
270 SSLAdvanceHandshake(SSLHandshakeType processed
, SSLContext
*ctx
)
272 SSLBuffer sessionIdentifier
;
275 { case SSL_hello_request
:
276 if (ERR(err
= SSLPrepareAndQueueMessage(SSLEncodeClientHello
, ctx
)) != 0)
278 SSLChangeHdskState(ctx
, HandshakeServerHello
);
280 case SSL_client_hello
:
281 CASSERT(ctx
->protocolSide
== SSL_ServerSide
);
282 if (ctx
->sessionID
.data
!= 0) /* If session ID != 0, client is trying to resume */
283 { if (ctx
->resumableSession
.data
!= 0)
284 { if (ERR(err
= SSLRetrieveSessionID(ctx
->resumableSession
, &sessionIdentifier
, ctx
)) != 0)
286 if (sessionIdentifier
.length
== ctx
->sessionID
.length
&&
287 memcmp(sessionIdentifier
.data
, ctx
->sessionID
.data
, ctx
->sessionID
.length
) == 0)
288 { /* Everything matches; resume the session */
289 //DEBUGMSG("Using resumed SSL3 Session");
290 SSLLogResumSess("===RESUMING SSL3 server-side session\n");
291 if (ERR(err
= SSLInstallSessionFromData(ctx
->resumableSession
,
293 { ERR(SSLFatalSessionAlert(alert_close_notify
, ctx
));
296 if (ERR(err
= SSLPrepareAndQueueMessage(SSLEncodeServerHello
, ctx
)) != 0)
298 if (ERR(err
= SSLInitPendingCiphers(ctx
)) != 0 ||
299 ERR(err
= SSLFreeBuffer(&sessionIdentifier
, &ctx
->sysCtx
)) != 0)
300 { ERR(SSLFatalSessionAlert(alert_close_notify
, ctx
));
303 if (ERR(err
= SSLPrepareAndQueueMessage(SSLEncodeChangeCipherSpec
, ctx
)) != 0)
305 /* Install new cipher spec on write side */
306 if (ERR(err
= SSLDisposeCipherSuite(&ctx
->writeCipher
, ctx
)) != 0)
307 { ERR(SSLFatalSessionAlert(alert_close_notify
, ctx
));
310 ctx
->writeCipher
= ctx
->writePending
;
311 ctx
->writeCipher
.ready
= 0; /* Can't send data until Finished is sent */
312 memset(&ctx
->writePending
, 0, sizeof(CipherContext
)); /* Zero out old data */
313 if (ERR(err
= SSLPrepareAndQueueMessage(SSLEncodeFinishedMessage
, ctx
)) != 0)
315 /* Finished has been sent; enable data dransfer on write channel */
316 ctx
->writeCipher
.ready
= 1;
317 SSLChangeHdskState(ctx
, HandshakeChangeCipherSpec
);
322 "===FAILED TO RESUME SSL3 server-side session\n");
324 if (ERR(err
= SSLFreeBuffer(&sessionIdentifier
, &ctx
->sysCtx
)) != 0 ||
325 ERR(err
= SSLDeleteSessionData(ctx
)) != 0)
326 { ERR(SSLFatalSessionAlert(alert_close_notify
, ctx
));
330 if (ERR(err
= SSLFreeBuffer(&ctx
->sessionID
, &ctx
->sysCtx
)) != 0)
331 { ERR(SSLFatalSessionAlert(alert_close_notify
, ctx
));
336 /* If we get here, we're not resuming; generate a new session ID if we know our peer */
337 if (ctx
->peerID
.data
!= 0)
338 { /* Ignore errors; just treat as uncached session */
339 CASSERT(ctx
->sessionID
.data
== 0);
340 ERR(err
= SSLAllocBuffer(&ctx
->sessionID
, SSL_SESSION_ID_LEN
, &ctx
->sysCtx
));
343 if((err
= sslRand(ctx
, &ctx
->sessionID
)) != 0)
344 { ERR(SSLFatalSessionAlert(alert_close_notify
, ctx
));
350 if (ERR(err
= SSLPrepareAndQueueMessage(SSLEncodeServerHello
, ctx
)) != 0)
352 switch (ctx
->selectedCipherSpec
->keyExchangeMethod
)
353 { case SSL_NULL_auth
:
357 case SSL_DH_anon_EXPORT
:
358 #if ST_SERVER_MODE_ENABLE
359 if(ctx
->clientAuth
== kAlwaysAuthenticate
) {
360 /* APPLE_CDSA change: app requires this; abort */
361 SSLFatalSessionAlert(alert_handshake_failure
, ctx
);
362 return SSLNegotiationErr
;
364 ctx
->tryClientAuth
= false;
365 #else /* ST_SERVER_MODE_ENABLE */
366 /* server side needs work */
367 #endif /* ST_SERVER_MODE_ENABLE*/
369 default: /* everything else */
370 if (ERR(err
= SSLPrepareAndQueueMessage(SSLEncodeCertificate
, ctx
)) != 0)
375 * At this point we decide whether to send a server key exchange
376 * method. For Apple servers, I think we'll ALWAYS do this, because
377 * of key usage restrictions (can't decrypt and sign with the same
378 * private key), but conceptually in this code, we do it if
379 * enabled by the presence of encryptPrivKey.
381 #if SSL_SERVER_KEYEXCH_HACK
383 * This is currently how we work with Netscape. It requires
384 * a CSP which can handle private keys which can both
387 if((ctx
->selectedCipherSpec
->keyExchangeMethod
!= SSL_RSA
) &&
388 (ctx
->encryptPrivKey
!= NULL
)) {
389 err
= SSLPrepareAndQueueMessage(SSLEncodeServerKeyExchange
, ctx
);
394 #else /* !SSL_SERVER_KEYEXCH_HACK */
396 * This is, I believe the "right" way, but Netscape doesn't
399 if (ctx
->encryptPrivKey
!= NULL
) {
400 err
= SSLPrepareAndQueueMessage(SSLEncodeServerKeyExchange
, ctx
);
405 #endif /* SSL_SERVER_KEYEXCH_HACK */
407 #if ST_SERVER_MODE_ENABLE
408 if (ctx
->tryClientAuth
)
409 { if (ERR(err
= SSLPrepareAndQueueMessage(SSLEncodeCertificateRequest
, ctx
)) != 0)
411 ctx
->certRequested
= 1;
413 #else /* !ST_SERVER_MODE_ENABLE */
414 /* disabled for now */
415 #endif /* ST_SERVER_MODE_ENABLE */
416 if (ERR(err
= SSLPrepareAndQueueMessage(SSLEncodeServerHelloDone
, ctx
)) != 0)
418 if (ctx
->certRequested
) {
419 SSLChangeHdskState(ctx
, HandshakeClientCertificate
);
422 SSLChangeHdskState(ctx
, HandshakeClientKeyExchange
);
425 case SSL_server_hello
:
426 if (ctx
->resumableSession
.data
!= 0 && ctx
->sessionID
.data
!= 0)
427 { if (ERR(err
= SSLRetrieveSessionID(ctx
->resumableSession
, &sessionIdentifier
, ctx
)) != 0)
428 { ERR(SSLFatalSessionAlert(alert_close_notify
, ctx
));
431 if (sessionIdentifier
.length
== ctx
->sessionID
.length
&&
432 memcmp(sessionIdentifier
.data
, ctx
->sessionID
.data
, ctx
->sessionID
.length
) == 0)
433 { /* Everything matches; resume the session */
434 SSLLogResumSess("===RESUMING SSL3 client-side session\n");
435 if (ERR(err
= SSLInstallSessionFromData(ctx
->resumableSession
,
437 ERR(err
= SSLInitPendingCiphers(ctx
)) != 0 ||
438 ERR(err
= SSLFreeBuffer(&sessionIdentifier
, &ctx
->sysCtx
)) != 0)
439 { ERR(SSLFatalSessionAlert(alert_close_notify
, ctx
));
442 SSLChangeHdskState(ctx
, HandshakeChangeCipherSpec
);
446 SSLLogResumSess("===FAILED TO RESUME SSL3 client-side session\n");
448 if (ERR(err
= SSLFreeBuffer(&sessionIdentifier
, &ctx
->sysCtx
)) != 0)
449 { ERR(SSLFatalSessionAlert(alert_close_notify
, ctx
));
453 switch (ctx
->selectedCipherSpec
->keyExchangeMethod
)
455 /* these require a key exchange message */
458 case SSL_DH_anon_EXPORT
:
459 SSLChangeHdskState(ctx
, HandshakeKeyExchange
);
463 case SSL_DH_DSS_EXPORT
:
465 case SSL_DH_RSA_EXPORT
:
468 case SSL_DHE_DSS_EXPORT
:
470 case SSL_DHE_RSA_EXPORT
:
472 SSLChangeHdskState(ctx
, HandshakeCertificate
);
475 ASSERTMSG("Unknown key exchange method");
479 case SSL_certificate
:
480 if (ctx
->state
== HandshakeCertificate
)
481 switch (ctx
->selectedCipherSpec
->keyExchangeMethod
)
484 * I really think the two RSA cases should be
485 * handled the same here - the server key exchange is
486 * optional, and is up to the server.
487 * Note this isn't the same as SSL_SERVER_KEYEXCH_HACK;
488 * we're a client here.
492 case SSL_DH_DSS_EXPORT
:
494 case SSL_DH_RSA_EXPORT
:
495 SSLChangeHdskState(ctx
, HandshakeHelloDone
);
498 case SSL_DHE_DSS_EXPORT
:
500 case SSL_DHE_RSA_EXPORT
:
502 SSLChangeHdskState(ctx
, HandshakeKeyExchange
);
505 ASSERTMSG("Unknown or unexpected key exchange method");
508 else if (ctx
->state
== HandshakeClientCertificate
)
509 { SSLChangeHdskState(ctx
, HandshakeClientKeyExchange
);
510 if (ctx
->peerCert
!= 0)
511 ctx
->certReceived
= 1;
514 case SSL_certificate_request
: /* state stays in HandshakeHelloDone; distinction is in ctx->certRequested */
515 if (ctx
->peerCert
== 0)
516 { ERR(SSLFatalSessionAlert(alert_handshake_failure
, ctx
));
517 return ERR(SSLProtocolErr
);
519 ctx
->certRequested
= 1;
521 case SSL_server_key_exchange
:
522 SSLChangeHdskState(ctx
, HandshakeHelloDone
);
524 case SSL_server_hello_done
:
525 if (ctx
->certRequested
)
526 { if (ctx
->localCert
!= 0 && ctx
->x509Requested
)
527 { if (ERR(err
= SSLPrepareAndQueueMessage(SSLEncodeCertificate
, ctx
)) != 0)
531 { if (ERR(err
= SSLSendAlert(alert_warning
, alert_no_certificate
, ctx
)) != 0)
535 if (ERR(err
= SSLPrepareAndQueueMessage(SSLEncodeKeyExchange
, ctx
)) != 0)
537 assert(ctx
->sslTslCalls
!= NULL
);
538 if (ERR(err
= ctx
->sslTslCalls
->generateMasterSecret(ctx
)) != 0 ||
539 ERR(err
= SSLInitPendingCiphers(ctx
)) != 0)
540 { ERR(SSLFatalSessionAlert(alert_close_notify
, ctx
));
543 memset(ctx
->preMasterSecret
.data
, 0, ctx
->preMasterSecret
.length
);
544 if (ERR(err
= SSLFreeBuffer(&ctx
->preMasterSecret
, &ctx
->sysCtx
)) != 0)
547 if (ERR(err
= SSLPrepareAndQueueMessage(SSLEncodeCertificateVerify
, ctx
)) != 0)
549 if (ERR(err
= SSLPrepareAndQueueMessage(SSLEncodeChangeCipherSpec
, ctx
)) != 0)
551 /* Install new cipher spec on write side */
552 if (ERR(err
= SSLDisposeCipherSuite(&ctx
->writeCipher
, ctx
)) != 0)
553 { ERR(SSLFatalSessionAlert(alert_close_notify
, ctx
));
556 ctx
->writeCipher
= ctx
->writePending
;
557 /* Can't send data until Finished is sent */
558 ctx
->writeCipher
.ready
= 0;
560 /* Zero out old data */
561 memset(&ctx
->writePending
, 0, sizeof(CipherContext
));
562 if (ERR(err
= SSLPrepareAndQueueMessage(SSLEncodeFinishedMessage
, ctx
)) != 0)
564 /* Finished has been sent; enable data dransfer on write channel */
565 ctx
->writeCipher
.ready
= 1;
566 SSLChangeHdskState(ctx
, HandshakeChangeCipherSpec
);
568 case SSL_certificate_verify
:
569 SSLChangeHdskState(ctx
, HandshakeChangeCipherSpec
);
571 case SSL_client_key_exchange
:
572 assert(ctx
->sslTslCalls
!= NULL
);
573 if (ERR(err
= ctx
->sslTslCalls
->generateMasterSecret(ctx
)) != 0 ||
574 ERR(err
= SSLInitPendingCiphers(ctx
)) != 0)
575 { ERR(SSLFatalSessionAlert(alert_close_notify
, ctx
));
578 memset(ctx
->preMasterSecret
.data
, 0, ctx
->preMasterSecret
.length
);
579 if (ERR(err
= SSLFreeBuffer(&ctx
->preMasterSecret
, &ctx
->sysCtx
)) != 0)
581 if (ctx
->certReceived
) {
582 SSLChangeHdskState(ctx
, HandshakeClientCertVerify
);
585 SSLChangeHdskState(ctx
, HandshakeChangeCipherSpec
);
589 /* Handshake is over; enable data transfer on read channel */
590 ctx
->readCipher
.ready
= 1;
591 /* If writePending is set, we haven't yet sent a finished message; send it */
592 if (ctx
->writePending
.ready
!= 0)
593 { if (ERR(err
= SSLPrepareAndQueueMessage(SSLEncodeChangeCipherSpec
, ctx
)) != 0)
596 /* Install new cipher spec on write side */
597 if (ERR(err
= SSLDisposeCipherSuite(&ctx
->writeCipher
, ctx
)) != 0)
598 { SSLFatalSessionAlert(alert_close_notify
, ctx
);
601 ctx
->writeCipher
= ctx
->writePending
;
602 ctx
->writeCipher
.ready
= 0; /* Can't send data until Finished is sent */
603 memset(&ctx
->writePending
, 0, sizeof(CipherContext
)); /* Zero out old data */
604 if (ERR(err
= SSLPrepareAndQueueMessage(SSLEncodeFinishedMessage
, ctx
)) != 0)
606 ctx
->writeCipher
.ready
= 1;
608 if (ctx
->protocolSide
== SSL_ServerSide
) {
609 SSLChangeHdskState(ctx
, HandshakeServerReady
);
612 SSLChangeHdskState(ctx
, HandshakeClientReady
);
614 if (ctx
->peerID
.data
!= 0)
615 ERR(SSLAddSessionData(ctx
));
618 ASSERTMSG("Unknown State");
626 SSLPrepareAndQueueMessage(EncodeMessageFunc msgFunc
, SSLContext
*ctx
)
630 if (ERR(err
= msgFunc(&rec
, ctx
)) != 0)
631 { ERR(SSLFatalSessionAlert(alert_close_notify
, ctx
));
635 if (rec
.contentType
== SSL_handshake
)
636 { if (ERR(err
= SSLHashSHA1
.update(ctx
->shaState
, rec
.contents
)) != 0 ||
637 ERR(err
= SSLHashMD5
.update(ctx
->md5State
, rec
.contents
)) != 0)
638 { ERR(SSLFatalSessionAlert(alert_close_notify
, ctx
));
641 SSLLogHdskMsg((SSLHandshakeType
)rec
.contents
.data
[0], 1);
644 assert(ctx
->sslTslCalls
!= NULL
);
645 if (ERR(err
= ctx
->sslTslCalls
->writeRecord(rec
, ctx
)) != 0)
650 SSLFreeBuffer(&rec
.contents
, &ctx
->sysCtx
);
656 SSL3ReceiveSSL2ClientHello(SSLRecord rec
, SSLContext
*ctx
)
659 if (ERR(err
= SSLInitMessageHashes(ctx
)) != 0)
662 if (ERR(err
= SSLHashSHA1
.update(ctx
->shaState
, rec
.contents
)) != 0 ||
663 ERR(err
= SSLHashMD5
.update(ctx
->md5State
, rec
.contents
)) != 0)
664 { ERR(SSLFatalSessionAlert(alert_close_notify
, ctx
));
668 if (ERR(err
= SSLAdvanceHandshake(SSL_client_hello
, ctx
)) != 0)
674 /* log changes in handshake state */
679 char *hdskStateToStr(SSLHandshakeState state
)
681 static char badStr
[100];
684 case SSLUninitialized
:
685 return "SSLUninitialized";
686 case HandshakeServerUninit
:
687 return "HandshakeServerUninit";
688 case HandshakeClientUninit
:
689 return "HandshakeClientUninit";
690 case SSLGracefulClose
:
691 return "SSLGracefulClose";
693 return "SSLErrorClose";
694 case SSLNoNotifyClose
:
695 return "SSLNoNotifyClose";
696 case HandshakeServerHello
:
697 return "HandshakeServerHello";
698 case HandshakeServerHelloUnknownVersion
:
699 return "HandshakeServerHelloUnknownVersion";
700 case HandshakeKeyExchange
:
701 return "HandshakeKeyExchange";
702 case HandshakeCertificate
:
703 return "HandshakeCertificate";
704 case HandshakeHelloDone
:
705 return "HandshakeHelloDone";
706 case HandshakeClientCertificate
:
707 return "HandshakeClientCertificate";
708 case HandshakeClientKeyExchange
:
709 return "HandshakeClientKeyExchange";
710 case HandshakeClientCertVerify
:
711 return "HandshakeClientCertVerify";
712 case HandshakeChangeCipherSpec
:
713 return "HandshakeChangeCipherSpec";
714 case HandshakeFinished
:
715 return "HandshakeFinished";
716 case HandshakeSSL2ClientMasterKey
:
717 return "HandshakeSSL2ClientMasterKey";
718 case HandshakeSSL2ClientFinished
:
719 return "HandshakeSSL2ClientFinished";
720 case HandshakeSSL2ServerHello
:
721 return "HandshakeSSL2ServerHello";
722 case HandshakeSSL2ServerVerify
:
723 return "HandshakeSSL2ServerVerify";
724 case HandshakeSSL2ServerFinished
:
725 return "HandshakeSSL2ServerFinished";
726 case HandshakeServerReady
:
727 return "HandshakeServerReady";
728 case HandshakeClientReady
:
729 return "HandshakeClientReady";
731 sprintf(badStr
, "Unknown state (%d(d)", state
);
736 void SSLChangeHdskState(SSLContext
*ctx
, SSLHandshakeState newState
)
738 printf("...hdskState = %s\n", hdskStateToStr(newState
));
739 ctx
->state
= newState
;
742 #endif /* LOG_HDSK_STATE */
744 /* log handshake messages */
750 static char *hdskMsgToStr(SSLHandshakeType msg
)
752 static char badStr
[100];
755 case SSL_hello_request
:
756 return "SSL_hello_request";
757 case SSL_client_hello
:
758 return "SSL_client_hello";
759 case SSL_server_hello
:
760 return "SSL_server_hello";
761 case SSL_certificate
:
762 return "SSL_certificate";
763 case SSL_server_key_exchange
:
764 return "SSL_server_key_exchange";
765 case SSL_certificate_request
:
766 return "SSL_certificate_request";
767 case SSL_server_hello_done
:
768 return "SSL_server_hello_done";
769 case SSL_certificate_verify
:
770 return "SSL_certificate_verify";
771 case SSL_client_key_exchange
:
772 return "SSL_client_key_exchange";
774 return "SSL_finished";
775 case SSL_MAGIC_no_certificate_alert
:
776 return "SSL_MAGIC_no_certificate_alert";
778 sprintf(badStr
, "Unknown state (%d(d)", msg
);
783 void SSLLogHdskMsg(SSLHandshakeType msg
, char sent
)
785 printf("---%s handshake msg %s\n",
786 hdskMsgToStr(msg
), (sent
? "sent" : "recv"));
789 #endif /* LOG_HDSK_MSG */