2 * Copyright (c) 2004 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 #include <Security/Security.h>
25 #include <security_utilities/security_utilities.h>
26 #include <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacErrors.h>
27 #include <security_cdsa_utilities/cssmbridge.h>
30 #include "SecureDownload.h"
38 catch (const MacOSError &err) { return err.osStatus(); } \
39 catch (const std::bad_alloc &) { return memFullErr; } \
40 catch (...) { return internalComponentErr; } \
43 #define API_END_GENERIC_CATCH } catch (...) { return; }
45 #define API_END_ERROR_CATCH(bad) } catch (...) { return bad; }
49 OSStatus
SecureDownloadCreateWithTicket (CFDataRef ticket
,
50 SecureDownloadTrustSetupCallback setup
,
52 SecureDownloadTrustEvaluateCallback evaluate
,
53 void* evaluateContext
,
54 SecureDownloadRef
* downloadRef
)
58 Download
* sd
= new Download ();
59 sd
->Initialize (ticket
, setup
, setupContext
, evaluate
, evaluateContext
);
60 Required (downloadRef
) = sd
;
67 OSStatus
SecureDownloadCopyURLs (SecureDownloadRef downloadRef
, CFArrayRef
* urls
)
71 Required (downloadRef
);
72 Download
* d
= (Download
*) downloadRef
;
73 Required (urls
) = d
->CopyURLs ();
80 OSStatus
SecureDownloadCopyName (SecureDownloadRef downloadRef
, CFStringRef
* name
)
84 Required (downloadRef
);
85 Download
* d
= (Download
*) downloadRef
;
86 Required (name
) = d
->CopyName ();
93 OSStatus
SecureDownloadCopyCreationDate (SecureDownloadRef downloadRef
, CFDateRef
* date
)
97 Required (downloadRef
);
98 Download
* d
= (Download
*) downloadRef
;
99 Required (date
) = d
->CopyDate ();
106 OSStatus
SecureDownloadGetDownloadSize (SecureDownloadRef downloadRef
, SInt64
* size
)
110 Required (downloadRef
);
111 Download
* d
= (Download
*) downloadRef
;
112 Required (size
) = d
->GetDownloadSize ();
119 OSStatus
SecureDownloadUpdateWithData (SecureDownloadRef downloadRef
, CFDataRef data
)
122 Required (downloadRef
);
124 Download
* d
= (Download
*) downloadRef
;
125 d
->UpdateWithData (data
);
131 OSStatus
SecureDownloadFinished (SecureDownloadRef downloadRef
)
134 Required (downloadRef
);
135 Download
* d
= (Download
*) downloadRef
;
142 OSStatus
SecureDownloadRelease (SecureDownloadRef downloadRef
)
145 Required (downloadRef
);
146 delete (Download
*) downloadRef
;
152 OSStatus
SecureDownloadCopyTicketLocation (CFURLRef url
, CFURLRef
*ticketLocation
)
155 Required (ticketLocation
);
158 // copy the resource specifier
159 CFStringRef resourceSpecifier
= CFURLCopyResourceSpecifier (url
);
160 if (resourceSpecifier
== NULL
)
165 // make a new URL from the resource specifier
166 *ticketLocation
= CFURLCreateWithString (NULL
, resourceSpecifier
, NULL
);
167 if (*ticketLocation
== NULL
)
172 // check the scheme to make sure that it isn't a file url
173 CFStringRef scheme
= CFURLCopyScheme (*ticketLocation
);
176 CFComparisonResult equal
= CFStringCompare (scheme
, CFSTR("file"), kCFCompareCaseInsensitive
);
179 if (equal
== kCFCompareEqualTo
)
181 CFRelease (*ticketLocation
);
182 *ticketLocation
= NULL
;
183 MacOSError::throwMe (errSecureDownloadInvalidDownload
);
187 CFRelease (resourceSpecifier
);