Skip to content

Commit

Permalink
Generate serialization for SecCertificateRef
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=268108
rdar://121624808

Reviewed by beidson (Brady Eidson), sheeparegreat (Simon Lewis), achristensen07 (Alex Christensen).

* Source/WebKit/DerivedSources-input.xcfilelist:
* Source/WebKit/DerivedSources.make:
* Source/WebKit/Platform/IPC/ArgumentCoders.h:
* Source/WebKit/Shared/cf/ArgumentCodersCF.cpp:
(IPC::ArgumentCoder<SecCertificateRef>::encode): Deleted.
(IPC::ArgumentCoder<RetainPtr<SecCertificateRef>>::decode): Deleted.
* Source/WebKit/Shared/cf/ArgumentCodersCF.h:
* Source/WebKit/Shared/cf/CFTypes.serialization.in:
* Source/WebKit/Shared/cf/CoreIPCSecCertificate.h: Added.
(WebKit::CoreIPCSecCertificate::CoreIPCSecCertificate):
(WebKit::CoreIPCSecCertificate::createSecCertificate):
(WebKit::CoreIPCSecCertificate::base64StringFromCertificate):
* Source/WebKit/Shared/cf/CoreIPCSecCertificate.serialization.in: Copied from Source/WebKit/Shared/cf/CFTypes.serialization.in.
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:

Canonical link: https://commits.webkit.org/273866@main
  • Loading branch information
mscottapple authored and beidson committed Jan 31, 2024
1 parent 990d138 commit da1fed5
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 26 deletions.
1 change: 1 addition & 0 deletions Source/WebKit/DerivedSources-input.xcfilelist
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ $(PROJECT_DIR)/Shared/XR/XRSystem.serialization.in
$(PROJECT_DIR)/Shared/cf/CFTypes.serialization.in
$(PROJECT_DIR)/Shared/cf/CoreIPCBoolean.serialization.in
$(PROJECT_DIR)/Shared/cf/CoreIPCNumber.serialization.in
$(PROJECT_DIR)/Shared/cf/CoreIPCSecCertificate.serialization.in
$(PROJECT_DIR)/Shared/ios/DynamicViewportSizeUpdate.serialization.in
$(PROJECT_DIR)/Shared/ios/GestureTypes.serialization.in
$(PROJECT_DIR)/Shared/ios/InteractionInformationAtPosition.serialization.in
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/DerivedSources.make
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ SERIALIZATION_DESCRIPTION_FILES = \
Shared/cf/CFTypes.serialization.in \
Shared/cf/CoreIPCBoolean.serialization.in \
Shared/cf/CoreIPCNumber.serialization.in \
Shared/cf/CoreIPCSecCertificate.serialization.in \
Shared/mac/PDFContextMenuItem.serialization.in \
Shared/mac/SecItemRequestData.serialization.in \
Shared/mac/SecItemResponseData.serialization.in \
Expand Down
19 changes: 0 additions & 19 deletions Source/WebKit/Shared/cf/ArgumentCodersCF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,25 +553,6 @@ std::optional<RetainPtr<CGColorSpaceRef>> ArgumentCoder<RetainPtr<CGColorSpaceRe
return colorSpace;
}

template<typename Encoder>
void ArgumentCoder<SecCertificateRef>::encode(Encoder& encoder, SecCertificateRef certificate)
{
encoder << adoptCF(SecCertificateCopyData(certificate));
}

template void ArgumentCoder<SecCertificateRef>::encode<Encoder>(Encoder&, SecCertificateRef);
template void ArgumentCoder<SecCertificateRef>::encode<StreamConnectionEncoder>(StreamConnectionEncoder&, SecCertificateRef);

std::optional<RetainPtr<SecCertificateRef>> ArgumentCoder<RetainPtr<SecCertificateRef>>::decode(Decoder& decoder)
{
std::optional<RetainPtr<CFDataRef>> data;
decoder >> data;
if (!data)
return std::nullopt;

return adoptCF(SecCertificateCreateWithData(0, data->get()));
}

#if HAVE(SEC_KEYCHAIN)
template<typename Encoder>
void ArgumentCoder<SecKeychainItemRef>::encode(Encoder& encoder, SecKeychainItemRef keychainItem)
Expand Down
7 changes: 0 additions & 7 deletions Source/WebKit/Shared/cf/ArgumentCodersCF.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,6 @@ template<> struct ArgumentCoder<RetainPtr<CGColorSpaceRef>> : CFRetainPtrArgumen
static std::optional<RetainPtr<CGColorSpaceRef>> decode(Decoder&);
};

template<> struct ArgumentCoder<SecCertificateRef> {
template<typename Encoder> static void encode(Encoder&, SecCertificateRef);
};
template<> struct ArgumentCoder<RetainPtr<SecCertificateRef>> : CFRetainPtrArgumentCoder<SecCertificateRef> {
static std::optional<RetainPtr<SecCertificateRef>> decode(Decoder&);
};

#if HAVE(SEC_KEYCHAIN)
template<> struct ArgumentCoder<SecKeychainItemRef> {
template<typename Encoder> static void encode(Encoder&, SecKeychainItemRef);
Expand Down
4 changes: 4 additions & 0 deletions Source/WebKit/Shared/cf/CFTypes.serialization.in
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
[WebKitPlatform, CustomHeader, AdditionalEncoder=StreamConnectionEncoder, ToCFMethod=result->createCFURL()] CFURLRef wrapped by WebKit::CoreIPCCFURL {
}

additional_forward_declaration: typedef struct __SecCertificate *SecCertificateRef
[WebKitPlatform, CustomHeader, AdditionalEncoder=StreamConnectionEncoder, ToCFMethod=result->createSecCertificate()] SecCertificateRef wrapped by WebKit::CoreIPCSecCertificate {
}

#endif

#if USE(CG)
Expand Down
81 changes: 81 additions & 0 deletions Source/WebKit/Shared/cf/CoreIPCSecCertificate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (C) 2024 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#if USE(CF)

#import <Security/SecCertificate.h>
#import <wtf/RetainPtr.h>

namespace WebKit {

class CoreIPCSecCertificate {
public:
CoreIPCSecCertificate(SecCertificateRef certificate)
: m_certificateData(dataFromCertificate(certificate))
{
}

CoreIPCSecCertificate(RetainPtr<CFDataRef> data)
: m_certificateData(data)
{
}

CoreIPCSecCertificate(const IPC::DataReference& data)
: m_certificateData(adoptCF(CFDataCreate(kCFAllocatorDefault, data.data(), data.size())))
{
}

RetainPtr<SecCertificateRef> createSecCertificate() const
{
auto certificate = adoptCF(SecCertificateCreateWithData(kCFAllocatorDefault, m_certificateData.get()));
ASSERT(certificate);
return certificate;
}

IPC::DataReference dataReference() const
{
RELEASE_ASSERT(m_certificateData);
CFDataRef data = m_certificateData.get();
RELEASE_ASSERT(data);
return { CFDataGetBytePtr(data), static_cast<size_t>(CFDataGetLength(data)) };
}

private:
RetainPtr<CFDataRef> dataFromCertificate(SecCertificateRef certificate) const
{
ASSERT(certificate);
auto data = adoptCF(SecCertificateCopyData(certificate));
ASSERT(data);
return data;
}

RetainPtr<CFDataRef> m_certificateData;
};

} // namespace WebKit

#endif // USE(CF)
31 changes: 31 additions & 0 deletions Source/WebKit/Shared/cf/CoreIPCSecCertificate.serialization.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (C) 2023 Apple Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#if USE(CF)

webkit_platform_headers: "CoreIPCSecCertificate.h"

[WebKitPlatform, AdditionalEncoder=StreamConnectionEncoder] class WebKit::CoreIPCSecCertificate {
IPC::DataReference dataReference();
}

#endif // USE(CF)
8 changes: 8 additions & 0 deletions Source/WebKit/WebKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1331,6 +1331,8 @@
535BCB922069C49C00CCCE02 /* NetworkActivityTracker.h in Headers */ = {isa = PBXBuildFile; fileRef = 535BCB902069C49C00CCCE02 /* NetworkActivityTracker.h */; };
53BA47D11DC2EF5E004DF4AD /* NetworkDataTaskBlob.h in Headers */ = {isa = PBXBuildFile; fileRef = 539EB5471DC2EE40009D48CF /* NetworkDataTaskBlob.h */; };
53CFBBC82224D1B500266546 /* TextCheckerCompletion.h in Headers */ = {isa = PBXBuildFile; fileRef = 53CFBBC72224D1B000266546 /* TextCheckerCompletion.h */; };
561A54532B61E49E00073A72 /* CoreIPCSecCertificate.h in Headers */ = {isa = PBXBuildFile; fileRef = 561A54512B61E49E00073A72 /* CoreIPCSecCertificate.h */; };
561A54542B61E49E00073A72 /* CoreIPCSecCertificate.serialization.in in Sources */ = {isa = PBXBuildFile; fileRef = 561A54522B61E49E00073A72 /* CoreIPCSecCertificate.serialization.in */; };
570AB8F320AE3BD700B8BE87 /* SecKeyProxyStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 570AB8F220AE3BD700B8BE87 /* SecKeyProxyStore.h */; };
570DAAAE23026F5C00E8FC04 /* NfcService.h in Headers */ = {isa = PBXBuildFile; fileRef = 570DAAAC23026F5C00E8FC04 /* NfcService.h */; };
570DAAC22303730300E8FC04 /* NfcConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 570DAAC02303730300E8FC04 /* NfcConnection.h */; };
Expand Down Expand Up @@ -5651,6 +5653,8 @@
550640A324071A6100AAE045 /* RemoteRenderingBackend.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RemoteRenderingBackend.h; sourceTree = "<group>"; };
550640A424071C2100AAE045 /* RemoteRenderingBackend.messages.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = RemoteRenderingBackend.messages.in; sourceTree = "<group>"; };
55AD09422408A02E00DE4D2F /* RemoteImageBuffer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RemoteImageBuffer.h; sourceTree = "<group>"; };
561A54512B61E49E00073A72 /* CoreIPCSecCertificate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CoreIPCSecCertificate.h; sourceTree = "<group>"; };
561A54522B61E49E00073A72 /* CoreIPCSecCertificate.serialization.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = CoreIPCSecCertificate.serialization.in; sourceTree = "<group>"; };
570AB8F220AE3BD700B8BE87 /* SecKeyProxyStore.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SecKeyProxyStore.h; sourceTree = "<group>"; };
570AB90020B2517400B8BE87 /* AuthenticationChallengeProxyCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AuthenticationChallengeProxyCocoa.mm; sourceTree = "<group>"; };
570AB90320B2541C00B8BE87 /* SecKeyProxyStore.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SecKeyProxyStore.mm; sourceTree = "<group>"; };
Expand Down Expand Up @@ -9020,6 +9024,8 @@
51D1943A2AEC9BC900E8E475 /* CoreIPCBoolean.serialization.in */,
F4EFF36B2AF0267200479AB8 /* CoreIPCNumber.h */,
F4EFF36A2AF0267200479AB8 /* CoreIPCNumber.serialization.in */,
561A54512B61E49E00073A72 /* CoreIPCSecCertificate.h */,
561A54522B61E49E00073A72 /* CoreIPCSecCertificate.serialization.in */,
);
path = cf;
sourceTree = "<group>";
Expand Down Expand Up @@ -15604,6 +15610,7 @@
F4EFF36D2AF0267300479AB8 /* CoreIPCNumber.h in Headers */,
5157AE0A2B23E96A00C0E095 /* CoreIPCPassKit.h in Headers */,
51AD56912B1C4704001A0ECB /* CoreIPCPersonNameComponents.h in Headers */,
561A54532B61E49E00073A72 /* CoreIPCSecCertificate.h in Headers */,
5197FAE92AFD33CF009180C5 /* CoreIPCSecureCoding.h in Headers */,
5197FAE52AFD33CF009180C5 /* CoreIPCString.h in Headers */,
51D1B6942B09723A00FEA5CB /* CoreIPCTypes.h in Headers */,
Expand Down Expand Up @@ -18539,6 +18546,7 @@
E326E357284E580E00157372 /* AuxiliaryProcessProxyCocoa.mm in Sources */,
413E5C9229B0CF7C002F4987 /* BackgroundFetchStateCocoa.mm in Sources */,
1C62747E288B4C3E00CED3A2 /* CocoaHelpers.mm in Sources */,
561A54542B61E49E00073A72 /* CoreIPCSecCertificate.serialization.in in Sources */,
49DC1DE127E5129100C1CB36 /* CSPExtensionUtilities.mm in Sources */,
522F792C28D531970069B45B /* CtapAuthenticator.cpp in Sources */,
526C5723284ADCBC00E08955 /* CtapCcidDriver.cpp in Sources */,
Expand Down

0 comments on commit da1fed5

Please sign in to comment.