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 IncrementUInt64(sslUint64
*v
)
92 { if (++v
->low
== 0) /* Must have just rolled over */
97 SSLGetCertificateChainLength(const SSLCertificate
*c
)
109 Boolean
sslIsSessionActive(const SSLContext
*ctx
)
111 CASSERT(ctx
!= NULL
);
113 case SSLUninitialized
:
114 case HandshakeServerUninit
:
115 case HandshakeClientUninit
:
116 case SSLGracefulClose
:
124 OSStatus
sslDeleteCertificateChain(
125 SSLCertificate
*certs
,
128 SSLCertificate
*cert
;
129 SSLCertificate
*nextCert
;
131 CASSERT(ctx
!= NULL
);
133 while(cert
!= NULL
) {
134 nextCert
= cert
->next
;
135 SSLFreeBuffer(&cert
->derCert
, &ctx
->sysCtx
);
144 const char *protocolVersStr(SSLProtocolVersion prot
)
147 case SSL_Version_Undetermined
: return "SSL_Version_Undetermined";
148 case SSL_Version_3_0_With_2_0_Hello
: return "SSL_Version_3_0_With_2_0_Hello";
149 case SSL_Version_3_0_Only
: return "SSL_Version_3_0_Only";
150 case SSL_Version_2_0
: return "SSL_Version_2_0";
151 case SSL_Version_3_0
: return "SSL_Version_3_0";
152 default: sslPanic("protocolVersStr: bad prot");
154 return NULL
; /* NOT REACHED */
157 #endif /* SSL_DEBUG */