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: Misc. SSL utility functions
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: sslutil.c Utility functions for encoding structures
48 Handles encoding endian-independant wire representation of 2, 3, or 4
51 ****************************************************************** */
69 #include <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacTypes.h>
72 SSLDecodeInt(const unsigned char *p
, int length
)
75 val
= (val
<< 8) | *p
++;
80 SSLEncodeInt(unsigned char *p
, UInt32 value
, int length
)
81 { unsigned char *retVal
= p
+ length
; /* Return pointer to char after int */
82 CASSERT(length
> 0 && length
<= 4);
83 while (length
--) /* Assemble backwards */
84 { p
[length
] = (UInt8
)value
; /* Implicit masking to low byte */
91 SSLEncodeUInt64(UInt8
*p
, sslUint64 value
)
92 { p
= SSLEncodeInt(p
, value
.high
, 4);
93 return SSLEncodeInt(p
, value
.low
, 4);
98 IncrementUInt64(sslUint64
*v
)
99 { if (++v
->low
== 0) /* Must have just rolled over */
104 SSLGetCertificateChainLength(const SSLCertificate
*c
)
116 Boolean
sslIsSessionActive(const SSLContext
*ctx
)
118 CASSERT(ctx
!= NULL
);
120 case SSLUninitialized
:
121 case HandshakeServerUninit
:
122 case HandshakeClientUninit
:
123 case SSLGracefulClose
:
131 OSStatus
sslDeleteCertificateChain(
132 SSLCertificate
*certs
,
135 SSLCertificate
*cert
;
136 SSLCertificate
*nextCert
;
138 CASSERT(ctx
!= NULL
);
140 while(cert
!= NULL
) {
141 nextCert
= cert
->next
;
142 SSLFreeBuffer(&cert
->derCert
, &ctx
->sysCtx
);
151 const char *protocolVersStr(SSLProtocolVersion prot
)
154 case SSL_Version_Undetermined
: return "SSL_Version_Undetermined";
155 case SSL_Version_3_0_With_2_0_Hello
: return "SSL_Version_3_0_With_2_0_Hello";
156 case SSL_Version_3_0_Only
: return "SSL_Version_3_0_Only";
157 case SSL_Version_2_0
: return "SSL_Version_2_0";
158 case SSL_Version_3_0
: return "SSL_Version_3_0";
159 case TLS_Version_1_0
: return "TLS_Version_1_0";
160 case TLS_Version_1_0_Only
: return "TLS_Version_1_0_Only";
161 default: sslPanic("protocolVersStr: bad prot");
163 return NULL
; /* NOT REACHED */
166 #endif /* SSL_DEBUG */