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: Glue layer between Apple SecureTransport and
25 Written by: Doug Mitchell, based on Netscape RSARef 3.0
27 Copyright: (c) 1999 by Apple Computer, Inc., all rights reserved.
43 #ifndef _APPLE_GLUE_H_
44 #include "appleGlue.h"
51 #include <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacErrors.h>
56 * Cruft used to map between private SSLErr's and the SSL-specific
57 * OSStatus values in SecureTransport.h. Eventually we should do
58 * away with SSLErr....
65 static const _sslErrMap sslErrMap
[] = {
67 { SSLMemoryErr
, memFullErr
},
68 { SSLUnsupportedErr
, unimpErr
},
69 { SSLProtocolErr
, errSSLProtocol
},
70 { SSLNegotiationErr
, errSSLNegotiation
},
71 { SSLFatalAlert
, errSSLFatalAlert
},
72 { SSLWouldBlockErr
, errSSLWouldBlock
},
74 { SSLSessionNotFoundErr
, errSSLSessionNotFound
},
75 { SSLConnectionClosedGraceful
, errSSLClosedGraceful
},
76 { SSLConnectionClosedError
, errSSLClosedAbort
},
77 { X509CertChainInvalidErr
, errSSLXCertChainInvalid
},
78 { SSLBadCert
, errSSLBadCert
},
79 { SSLCryptoError
, errSSLCrypto
},
80 { SSLInternalError
, errSSLInternal
},
81 { SSLDataOverflow
, errSSLCrypto
},
82 { SSLAttachFailure
, errSSLModuleAttach
},
83 { SSLUnknownRootCert
, errSSLUnknownRootCert
},
84 { SSLNoRootCert
, errSSLNoRootCert
},
85 { SSLCertExpired
, errSSLCertExpired
},
86 { SSLCertNotYetValid
, errSSLCertNotYetValid
},
87 { SSLBadStateErr
, badReqErr
},
88 { SSLConnectionClosedNoNotify
, errSSLClosedNoNotify
},
91 #define SIZEOF_ERR_MAP (sizeof(sslErrMap) / sizeof(_sslErrMap))
94 * Functions to allow old code to use SSLBuffer-based I/O calls.
95 * We redirect the calls here to an SSL{Write,Read}Func.
96 * This is of course way inefficient due to an extra copy for
97 * each I/O, but let's do it this way until the port settles down.
101 UInt32
*actualLength
,
104 UInt32 dataLength
= buf
.length
;
108 ortn
= (ctx
->ioCtx
.read
)(ctx
->ioCtx
.ioRef
,
111 *actualLength
= dataLength
;
112 return sslErrFromOsStatus(ortn
);
117 UInt32
*actualLength
,
120 UInt32 dataLength
= buf
.length
;
124 ortn
= (ctx
->ioCtx
.write
)(ctx
->ioCtx
.ioRef
,
127 *actualLength
= dataLength
;
128 return sslErrFromOsStatus(ortn
);
132 * Convert between SSLErr and OSStatus.
133 * These will go away eventually.
135 SSLErr
sslErrFromOsStatus(OSStatus o
)
138 const _sslErrMap
*emap
= sslErrMap
;
140 for(i
=0; i
<SIZEOF_ERR_MAP
; i
++) {
141 if(emap
->oerr
== o
) {
146 return SSLIOErr
; /* normal: bad error */
149 OSStatus
sslErrToOsStatus(SSLErr s
)
152 const _sslErrMap
*emap
= sslErrMap
;
154 for(i
=0; i
<SIZEOF_ERR_MAP
; i
++) {
155 if(emap
->serr
== s
) {
160 CASSERT(0); /* Debug: panic */
161 return paramErr
; /* normal: bad error */
165 * Time functions - replaces SSLRef's SSLTimeFunc, SSLConvertTimeFunc
166 * Weird - this is just used to generate a random number in
169 SSLErr
sslTime(UInt32
*tim
)
171 time((time_t *)&tim
);
177 SSLErr
sslConvertTime(UInt32
*time
)
179 return SSLUnsupportedErr
;