2 * Copyright (c) 2002 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.
18 #include <Security/SecTrustedApplicationPriv.h>
19 #include <Security/TrustedApplication.h>
20 #include <Security/ssclient.h>
22 #include "SecBridge.h"
26 SecTrustedApplicationGetTypeID(void)
30 return gTypes().TrustedApplication
.typeID
;
32 END_SECAPI1(_kCFRuntimeNotATypeID
)
37 SecTrustedApplicationCreateFromPath(const char *path
, SecTrustedApplicationRef
*appRef
)
40 SecPointer
<TrustedApplication
> app
=
41 path
? new TrustedApplication(path
) : new TrustedApplication
;
42 Required(appRef
) = app
->handle();
48 OSStatus
SecTrustedApplicationCopyData(SecTrustedApplicationRef appRef
,
52 const CssmData
&data
= TrustedApplication::required(appRef
)->data();
53 Required(dataRef
) = CFDataCreate(NULL
, (const UInt8
*)data
.data(), data
.length());
57 OSStatus
SecTrustedApplicationSetData(SecTrustedApplicationRef appRef
,
61 TrustedApplication::required(appRef
)->data(cfData(dataRef
));
67 SecTrustedApplicationValidateWithPath(SecTrustedApplicationRef appRef
, const char *path
)
70 TrustedApplication
&app
= *TrustedApplication::required(appRef
);
71 if (!app
.sameSignature(path
? path
: app
.path()))
72 return CSSMERR_CSP_VERIFY_FAILED
;
78 SecTrustedApplicationMakeEquivalent(SecTrustedApplicationRef oldRef
,
79 SecTrustedApplicationRef newRef
, UInt32 flags
)
82 if (flags
& ~kSecApplicationValidFlags
)
84 SecurityServer::ClientSession
ss(CssmAllocator::standard(), CssmAllocator::standard());
85 TrustedApplication
*oldApp
= TrustedApplication::required(oldRef
);
86 TrustedApplication
*newApp
= TrustedApplication::required(newRef
);
87 ss
.addCodeEquivalence(oldApp
->signature(), newApp
->signature(), oldApp
->path(),
88 flags
& kSecApplicationFlagSystemwide
);
93 SecTrustedApplicationRemoveEquivalence(SecTrustedApplicationRef appRef
, UInt32 flags
)
96 if (flags
& ~kSecApplicationValidFlags
)
98 SecurityServer::ClientSession
ss(CssmAllocator::standard(), CssmAllocator::standard());
99 TrustedApplication
*app
= TrustedApplication::required(appRef
);
100 ss
.removeCodeEquivalence(app
->signature(), app
->path(),
101 flags
& kSecApplicationFlagSystemwide
);
107 * Check to see if an application at a given path is a candidate for
108 * pre-emptive code equivalency establishment
111 SecTrustedApplicationIsUpdateCandidate(const char *installroot
, const char *path
)
117 size_t rootlen
= strlen(installroot
);
118 if (!strncmp(installroot
, path
, rootlen
))
119 path
+= rootlen
- 1; // keep the slash
122 // look up in database
123 static ModuleNexus
<PathDatabase
> paths
;
125 return CSSMERR_DL_RECORD_NOT_FOUND
; // whatever
131 * Point the system at another system root for equivalence use.
132 * This is for system update installers (only)!
135 SecTrustedApplicationUseAlternateSystem(const char *systemRoot
)
138 Required(systemRoot
);
139 SecurityServer::ClientSession
ss(CssmAllocator::standard(), CssmAllocator::standard());
140 ss
.setAlternateSystemRoot(systemRoot
);