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: support for change cipher spec messages
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: hdskchgc.c Contains support for change cipher spec messages
48 Simple support for encoding and decoding change cipher spec messages;
49 the decode message also installs the pending read cipher (if it is
52 ****************************************************************** */
77 SSLEncodeChangeCipherSpec(SSLRecord
*rec
, SSLContext
*ctx
)
80 CASSERT(ctx
->writePending
.ready
);
83 dprintf0("===Sending changeCipherSpec msg\n");
85 rec
->contentType
= SSL_change_cipher_spec
;
86 rec
->protocolVersion
= SSL_Version_3_0
;
87 rec
->contents
.length
= 1;
88 if ((err
= SSLAllocBuffer(&rec
->contents
, 1, &ctx
->sysCtx
)) != 0)
90 rec
->contents
.data
[0] = 1;
96 SSLProcessChangeCipherSpec(SSLRecord rec
, SSLContext
*ctx
)
99 if (rec
.contents
.length
!= 1 || rec
.contents
.data
[0] != 1)
100 { SSLFatalSessionAlert(alert_unexpected_message
, ctx
);
101 errorLog2("***bad changeCipherSpec msg: length %d data 0x%x\n",
102 (unsigned)rec
.contents
.length
, (unsigned)rec
.contents
.data
[0]);
103 return SSLProtocolErr
;
106 if (!ctx
->readPending
.ready
|| ctx
->state
!= HandshakeChangeCipherSpec
)
107 { SSLFatalSessionAlert(alert_unexpected_message
, ctx
);
108 errorLog2("***bad changeCipherSpec msg: readPending.ready %d state %d\n",
109 (unsigned)ctx
->readPending
.ready
, (unsigned)ctx
->state
);
110 return SSLProtocolErr
;
114 dprintf0("===Processing changeCipherSpec msg\n");
117 /* Install new cipher spec on read side */
118 if ((err
= SSLDisposeCipherSuite(&ctx
->readCipher
, ctx
)) != 0)
119 { SSLFatalSessionAlert(alert_close_notify
, ctx
);
122 ctx
->readCipher
= ctx
->readPending
;
123 ctx
->readCipher
.ready
= 0; /* Can't send data until Finished is sent */
124 SSLChangeHdskState(ctx
, HandshakeFinished
);
125 memset(&ctx
->readPending
, 0, sizeof(CipherContext
)); /* Zero out old data */
130 SSLDisposeCipherSuite(CipherContext
*cipher
, SSLContext
*ctx
)
134 { if ((err
= cipher
->symCipher
->finish(cipher
, ctx
)) != 0)