]> git.saurik.com Git - apple/security.git/blame - libsecurity_manifest/lib/SecureDownload.cpp
Security-55179.13.tar.gz
[apple/security.git] / libsecurity_manifest / lib / SecureDownload.cpp
CommitLineData
b1ab9ed8
A
1/*
2 * Copyright (c) 2004 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
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>
28
29#include "Download.h"
30#include "SecureDownload.h"
31
32
33#define API_BEGIN \
34 try {
35
36#define API_END \
37 } \
38 catch (const MacOSError &err) { return err.osStatus(); } \
39 catch (const std::bad_alloc &) { return memFullErr; } \
40 catch (...) { return internalComponentErr; } \
41 return noErr;
42
43#define API_END_GENERIC_CATCH } catch (...) { return; }
44
45#define API_END_ERROR_CATCH(bad) } catch (...) { return bad; }
46
47
48
49OSStatus SecureDownloadCreateWithTicket (CFDataRef ticket,
50 SecureDownloadTrustSetupCallback setup,
51 void* setupContext,
52 SecureDownloadTrustEvaluateCallback evaluate,
53 void* evaluateContext,
54 SecureDownloadRef* downloadRef)
55{
56 API_BEGIN
57
58 Download* sd = new Download ();
59 sd->Initialize (ticket, setup, setupContext, evaluate, evaluateContext);
60 Required (downloadRef) = sd;
61
62 API_END
63}
64
65
66
67OSStatus SecureDownloadCopyURLs (SecureDownloadRef downloadRef, CFArrayRef* urls)
68{
69 API_BEGIN
70
71 Required (downloadRef);
72 Download* d = (Download*) downloadRef;
73 Required (urls) = d->CopyURLs ();
74
75 API_END
76}
77
78
79
80OSStatus SecureDownloadCopyName (SecureDownloadRef downloadRef, CFStringRef* name)
81{
82 API_BEGIN
83
84 Required (downloadRef);
85 Download* d = (Download*) downloadRef;
86 Required (name) = d->CopyName ();
87
88 API_END
89}
90
91
92
93OSStatus SecureDownloadCopyCreationDate (SecureDownloadRef downloadRef, CFDateRef* date)
94{
95 API_BEGIN
96
97 Required (downloadRef);
98 Download* d = (Download*) downloadRef;
99 Required (date) = d->CopyDate ();
100
101 API_END
102}
103
104
105
106OSStatus SecureDownloadGetDownloadSize (SecureDownloadRef downloadRef, SInt64* size)
107{
108 API_BEGIN
109
110 Required (downloadRef);
111 Download* d = (Download*) downloadRef;
112 Required (size) = d->GetDownloadSize ();
113
114 API_END
115}
116
117
118
119OSStatus SecureDownloadUpdateWithData (SecureDownloadRef downloadRef, CFDataRef data)
120{
121 API_BEGIN
122 Required (downloadRef);
123 Required (data);
124 Download* d = (Download*) downloadRef;
125 d->UpdateWithData (data);
126 API_END
127}
128
129
130
131OSStatus SecureDownloadFinished (SecureDownloadRef downloadRef)
132{
133 API_BEGIN
134 Required (downloadRef);
135 Download* d = (Download*) downloadRef;
136 d->Finalize ();
137 API_END
138}
139
140
141
142OSStatus SecureDownloadRelease (SecureDownloadRef downloadRef)
143{
144 API_BEGIN
145 Required (downloadRef);
146 delete (Download*) downloadRef;
147 API_END
148}
149
150
151
152OSStatus SecureDownloadCopyTicketLocation (CFURLRef url, CFURLRef *ticketLocation)
153{
154 API_BEGIN
155 Required (ticketLocation);
156 Required (url);
157
158 // copy the resource specifier
159 CFStringRef resourceSpecifier = CFURLCopyResourceSpecifier (url);
160 if (resourceSpecifier == NULL)
161 {
162 CFError::throwMe ();
163 }
164
165 // make a new URL from the resource specifier
166 *ticketLocation = CFURLCreateWithString (NULL, resourceSpecifier, NULL);
167 if (*ticketLocation == NULL)
168 {
169 CFError::throwMe ();
170 }
171
172 // check the scheme to make sure that it isn't a file url
173 CFStringRef scheme = CFURLCopyScheme (*ticketLocation);
174 if (scheme != NULL)
175 {
176 CFComparisonResult equal = CFStringCompare (scheme, CFSTR("file"), kCFCompareCaseInsensitive);
177 CFRelease (scheme);
178
179 if (equal == kCFCompareEqualTo)
180 {
181 CFRelease (*ticketLocation);
182 *ticketLocation = NULL;
183 MacOSError::throwMe (errSecureDownloadInvalidDownload);
184 }
185 }
186
187 CFRelease (resourceSpecifier);
188 API_END
189}