2
* Copyright (C) 2011 Apple Inc. All rights reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
7
* 1. Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer.
9
* 2. Redistributions in binary form must reproduce the above copyright
10
* notice, this list of conditions and the following disclaimer in the
11
* documentation and/or other materials provided with the distribution.
13
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
* THE POSSIBILITY OF SUCH DAMAGE.
25
#import "WebProcessShim.h"
27
#import <Security/SecItem.h>
28
#import <wtf/Platform.h>
30
#define DYLD_INTERPOSE(_replacement,_replacee) \
31
__attribute__((used)) static struct{ const void* replacement; const void* replacee; } _interpose_##_replacee \
32
__attribute__ ((section ("__DATA,__interpose"))) = { (const void*)(unsigned long)&_replacement, (const void*)(unsigned long)&_replacee };
36
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
38
extern "C" void WebKitWebProcessSecItemShimInitialize(const WebProcessSecItemShimCallbacks&);
40
static WebProcessSecItemShimCallbacks secItemShimCallbacks;
42
static OSStatus shimSecItemCopyMatching(CFDictionaryRef query, CFTypeRef* result)
44
return secItemShimCallbacks.secItemCopyMatching(query, result);
47
static OSStatus shimSecItemAdd(CFDictionaryRef query, CFTypeRef* result)
49
return secItemShimCallbacks.secItemAdd(query, result);
52
static OSStatus shimSecItemUpdate(CFDictionaryRef query, CFDictionaryRef attributesToUpdate)
54
return secItemShimCallbacks.secItemUpdate(query, attributesToUpdate);
57
static OSStatus shimSecItemDelete(CFDictionaryRef query)
59
return secItemShimCallbacks.secItemDelete(query);
62
DYLD_INTERPOSE(shimSecItemCopyMatching, SecItemCopyMatching)
63
DYLD_INTERPOSE(shimSecItemAdd, SecItemAdd)
64
DYLD_INTERPOSE(shimSecItemUpdate, SecItemUpdate)
65
DYLD_INTERPOSE(shimSecItemDelete, SecItemDelete)
67
__attribute__((visibility("default")))
68
void WebKitWebProcessSecItemShimInitialize(const WebProcessSecItemShimCallbacks& callbacks)
70
secItemShimCallbacks = callbacks;
73
#endif // __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
75
#if __MAC_OS_X_VERSION_MIN_REQUIRED == 1060
77
extern "C" void WebKitWebProcessKeychainItemShimInitialize(const WebProcessKeychainItemShimCallbacks&);
79
static WebProcessKeychainItemShimCallbacks keychainItemShimCallbacks;
81
static OSStatus shimSecKeychainItemCopyContent(SecKeychainItemRef item, SecItemClass* itemClass, SecKeychainAttributeList* attrList, UInt32* length, void** outData)
83
return keychainItemShimCallbacks.secKeychainItemCopyContent(item, itemClass, attrList, length, outData);
86
static OSStatus shimSecKeychainItemCreateFromContent(SecItemClass itemClass, SecKeychainAttributeList* attrList, UInt32 length, const void* data,
87
SecKeychainRef keychainRef, SecAccessRef initialAccess, SecKeychainItemRef *itemRef)
89
// We don't support shimming SecKeychainItemCreateFromContent with Keychain or Access arguments at this time
90
if (keychainRef || initialAccess)
91
return SecKeychainItemCreateFromContent(itemClass, attrList, length, data, keychainRef, initialAccess, itemRef);
92
return keychainItemShimCallbacks.secKeychainItemCreateFromContent(itemClass, attrList, length, data, itemRef);
95
static OSStatus shimSecKeychainItemModifyContent(SecKeychainItemRef itemRef, const SecKeychainAttributeList* attrList, UInt32 length, const void* data)
97
return keychainItemShimCallbacks.secKeychainItemModifyContent(itemRef, attrList, length, data);
100
static OSStatus shimSecKeychainItemFreeContent(SecKeychainAttributeList* attrList, void* data)
102
bool attrListHandled = !attrList || keychainItemShimCallbacks.freeAttributeListContent(attrList);
103
bool keychainItemContentHandled = !data || keychainItemShimCallbacks.freeKeychainItemContentData(data);
105
// If both items were handled by the shim handlers, return now.
106
if (attrListHandled && keychainItemContentHandled)
107
return errSecSuccess;
109
// Have the native function handle whichever item wasn't already handled.
110
return SecKeychainItemFreeContent(attrListHandled ? attrList : NULL, keychainItemContentHandled ? data : NULL);
113
DYLD_INTERPOSE(shimSecKeychainItemCopyContent, SecKeychainItemCopyContent)
114
DYLD_INTERPOSE(shimSecKeychainItemCreateFromContent, SecKeychainItemCreateFromContent)
115
DYLD_INTERPOSE(shimSecKeychainItemModifyContent, SecKeychainItemModifyContent)
116
DYLD_INTERPOSE(shimSecKeychainItemFreeContent, SecKeychainItemFreeContent)
118
__attribute__((visibility("default")))
119
void WebKitWebProcessKeychainItemShimInitialize(const WebProcessKeychainItemShimCallbacks& callbacks)
121
keychainItemShimCallbacks = callbacks;
124
#endif // __MAC_OS_X_VERSION_MIN_REQUIRED == 1060
126
} // namespace WebKit