2 * Copyright (c) 2004,2011,2013-2014 Apple 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 <security_cdsa_utilities/cssmbridge.h>
27 #include <../sec/Security/SecBase.h>
29 #include "SecureDownload.h"
37 catch (const MacOSError &err) { return err.osStatus(); } \
38 catch (const std::bad_alloc &) { return errSecAllocate; } \
39 catch (...) { return errSecInternalComponent; } \
42 #define API_END_GENERIC_CATCH } catch (...) { return; }
44 #define API_END_ERROR_CATCH(bad) } catch (...) { return bad; }
48 OSStatus
SecureDownloadCreateWithTicket (CFDataRef ticket
,
49 SecureDownloadTrustSetupCallback setup
,
51 SecureDownloadTrustEvaluateCallback evaluate
,
52 void* evaluateContext
,
53 SecureDownloadRef
* downloadRef
)
57 Download
* sd
= new Download ();
58 sd
->Initialize (ticket
, setup
, setupContext
, evaluate
, evaluateContext
);
59 Required (downloadRef
) = sd
;
66 OSStatus
SecureDownloadCopyURLs (SecureDownloadRef downloadRef
, CFArrayRef
* urls
)
70 Required (downloadRef
);
71 Download
* d
= (Download
*) downloadRef
;
72 Required (urls
) = d
->CopyURLs ();
79 OSStatus
SecureDownloadCopyName (SecureDownloadRef downloadRef
, CFStringRef
* name
)
83 Required (downloadRef
);
84 Download
* d
= (Download
*) downloadRef
;
85 Required (name
) = d
->CopyName ();
92 OSStatus
SecureDownloadCopyCreationDate (SecureDownloadRef downloadRef
, CFDateRef
* date
)
96 Required (downloadRef
);
97 Download
* d
= (Download
*) downloadRef
;
98 Required (date
) = d
->CopyDate ();
105 OSStatus
SecureDownloadGetDownloadSize (SecureDownloadRef downloadRef
, SInt64
* size
)
109 Required (downloadRef
);
110 Download
* d
= (Download
*) downloadRef
;
111 Required (size
) = d
->GetDownloadSize ();
118 OSStatus
SecureDownloadUpdateWithData (SecureDownloadRef downloadRef
, CFDataRef data
)
121 Required (downloadRef
);
123 Download
* d
= (Download
*) downloadRef
;
124 d
->UpdateWithData (data
);
130 OSStatus
SecureDownloadFinished (SecureDownloadRef downloadRef
)
133 Required (downloadRef
);
134 Download
* d
= (Download
*) downloadRef
;
141 OSStatus
SecureDownloadRelease (SecureDownloadRef downloadRef
)
144 Required (downloadRef
);
145 delete (Download
*) downloadRef
;
151 OSStatus
SecureDownloadCopyTicketLocation (CFURLRef url
, CFURLRef
*ticketLocation
)
154 Required (ticketLocation
);
157 // copy the resource specifier
158 CFStringRef resourceSpecifier
= CFURLCopyResourceSpecifier (url
);
159 if (resourceSpecifier
== NULL
)
164 // make a new URL from the resource specifier
165 *ticketLocation
= CFURLCreateWithString (NULL
, resourceSpecifier
, NULL
);
166 if (*ticketLocation
== NULL
)
171 // check the scheme to make sure that it isn't a file url
172 CFStringRef scheme
= CFURLCopyScheme (*ticketLocation
);
175 CFComparisonResult equal
= CFStringCompare (scheme
, CFSTR("file"), kCFCompareCaseInsensitive
);
178 if (equal
== kCFCompareEqualTo
)
180 CFRelease (*ticketLocation
);
181 *ticketLocation
= NULL
;
182 MacOSError::throwMe (errSecureDownloadInvalidDownload
);
186 CFRelease (resourceSpecifier
);