1/* 2 * Copyright (C) 2013 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 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. 12 * 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. 24 */ 25 26#include "config.h" 27#include "SecItemShimProxy.h" 28 29#if USE(SECURITY_FRAMEWORK) 30 31#include "SecItemRequestData.h" 32#include "SecItemResponseData.h" 33#include "SecItemShimMessages.h" 34#include "SecItemShimProxyMessages.h" 35#include <Security/SecItem.h> 36 37namespace WebKit { 38 39SecItemShimProxy& SecItemShimProxy::shared() 40{ 41 static SecItemShimProxy* proxy; 42 static dispatch_once_t once; 43 dispatch_once(&once, ^{ 44 proxy = adoptRef(new SecItemShimProxy).leakRef(); 45 }); 46 return *proxy; 47} 48 49SecItemShimProxy::SecItemShimProxy() 50 : m_queue(WorkQueue::create("com.apple.WebKit.SecItemShimProxy")) 51{ 52} 53 54void SecItemShimProxy::initializeConnection(CoreIPC::Connection* connection) 55{ 56 connection->addWorkQueueMessageReceiver(Messages::SecItemShimProxy::messageReceiverName(), m_queue.get(), this); 57} 58 59void SecItemShimProxy::secItemRequest(CoreIPC::Connection* connection, uint64_t requestID, const SecItemRequestData& request) 60{ 61 SecItemResponseData response; 62 63 switch (request.type()) { 64 case SecItemRequestData::Invalid: 65 ASSERT_NOT_REACHED(); 66 return; 67 68 case SecItemRequestData::CopyMatching: { 69 CFTypeRef resultObject = 0; 70 OSStatus resultCode = SecItemCopyMatching(request.query(), &resultObject); 71 response = SecItemResponseData(resultCode, adoptCF(resultObject).get()); 72 break; 73 } 74 75 case SecItemRequestData::Add: { 76 CFTypeRef resultObject = 0; 77 OSStatus resultCode = SecItemAdd(request.query(), &resultObject); 78 response = SecItemResponseData(resultCode, adoptCF(resultObject).get()); 79 break; 80 } 81 82 case SecItemRequestData::Update: { 83 OSStatus resultCode = SecItemUpdate(request.query(), request.attributesToMatch()); 84 response = SecItemResponseData(resultCode, 0); 85 break; 86 } 87 88 case SecItemRequestData::Delete: { 89 OSStatus resultCode = SecItemDelete(request.query()); 90 response = SecItemResponseData(resultCode, 0); 91 break; 92 } 93 } 94 95 connection->send(Messages::SecItemShim::SecItemResponse(requestID, response), 0); 96} 97 98} // namespace WebKit 99 100#endif // USE(SECURITY_FRAMEWORK) 101