Title: [284890] trunk
Revision
284890
Author
[email protected]
Date
2021-10-26 12:50:30 -0700 (Tue, 26 Oct 2021)

Log Message

Update PCM test public key to one with RSA-PSS OID
https://bugs.webkit.org/show_bug.cgi?id=231048

Patch by Alex Christensen <[email protected]> on 2021-10-26
Reviewed by John Wilander.

Source/WTF:

* wtf/PlatformHave.h:

Tools:

In rdar://79069615 support for public keys with rsaEncryption OIDs was removed as stated on the blog at
https://webkit.org/blog/11940/pcm-click-fraud-prevention-and-attribution-sent-to-advertiser/
This implements enough ASN1 serialization to serialize a public key in the form accepted by WebKit now,
which is described at https://datatracker.ietf.org/doc/html/rfc8017#appendix-A.2.3

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebCore/ASN1Utilities.cpp: Added.
(ASN1::Object::sizeSerializedSize const):
(ASN1::Object::serializeSize const):
(ASN1::ObjectIdentifier::ObjectIdentifier):
(ASN1::ObjectIdentifier::bytes const):
(ASN1::Sequence::create):
(ASN1::Sequence::Sequence):
(ASN1::Sequence::elementEncodedLengthBytes const):
(ASN1::IndexWrapper::IndexWrapper):
(ASN1::Integer::Integer):
(ASN1::BitString::BitString):
(TestWebKitAPI::wrapPublicKeyWithRSAPSSOID):
* TestWebKitAPI/Tests/WebCore/ASN1Utilities.h: Added.
* TestWebKitAPI/Tests/WebCore/PrivateClickMeasurement.cpp:
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebCore/cocoa/PrivateClickMeasurementCocoa.mm:
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKitCocoa/EventAttribution.mm:
(TestWebKitAPI::TEST):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (284889 => 284890)


--- trunk/Source/WTF/ChangeLog	2021-10-26 19:44:14 UTC (rev 284889)
+++ trunk/Source/WTF/ChangeLog	2021-10-26 19:50:30 UTC (rev 284890)
@@ -1,3 +1,12 @@
+2021-10-26  Alex Christensen  <[email protected]>
+
+        Update PCM test public key to one with RSA-PSS OID
+        https://bugs.webkit.org/show_bug.cgi?id=231048
+
+        Reviewed by John Wilander.
+
+        * wtf/PlatformHave.h:
+
 2021-10-26  Fujii Hironori  <[email protected]>
 
         [WebCore] Remove unneeded WTF:: namespace prefix

Modified: trunk/Source/WTF/wtf/PlatformHave.h (284889 => 284890)


--- trunk/Source/WTF/wtf/PlatformHave.h	2021-10-26 19:44:14 UTC (rev 284889)
+++ trunk/Source/WTF/wtf/PlatformHave.h	2021-10-26 19:50:30 UTC (rev 284890)
@@ -934,6 +934,13 @@
 #define HAVE_VM_FLAGS_PERMANENT 1
 #endif
 
+#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 120400) \
+    || (PLATFORM(IOS_FAMILY) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 150400) \
+    || (PLATFORM(APPLETV) && __TV_OS_VERSION_MAX_ALLOWED >= 150400) \
+    || (PLATFORM(WATCHOS) && __WATCH_OS_VERSION_MAX_ALLOWED >= 80400)
+#define HAVE_RSA_PSS_OID 1
+#endif
+
 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101600) \
     || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 140000) \
     || (PLATFORM(WATCHOS) && __WATCH_OS_VERSION_MIN_REQUIRED >= 70000) \

Modified: trunk/Tools/ChangeLog (284889 => 284890)


--- trunk/Tools/ChangeLog	2021-10-26 19:44:14 UTC (rev 284889)
+++ trunk/Tools/ChangeLog	2021-10-26 19:50:30 UTC (rev 284890)
@@ -1,3 +1,36 @@
+2021-10-26  Alex Christensen  <[email protected]>
+
+        Update PCM test public key to one with RSA-PSS OID
+        https://bugs.webkit.org/show_bug.cgi?id=231048
+
+        Reviewed by John Wilander.
+
+        In rdar://79069615 support for public keys with rsaEncryption OIDs was removed as stated on the blog at
+        https://webkit.org/blog/11940/pcm-click-fraud-prevention-and-attribution-sent-to-advertiser/
+        This implements enough ASN1 serialization to serialize a public key in the form accepted by WebKit now,
+        which is described at https://datatracker.ietf.org/doc/html/rfc8017#appendix-A.2.3
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebCore/ASN1Utilities.cpp: Added.
+        (ASN1::Object::sizeSerializedSize const):
+        (ASN1::Object::serializeSize const):
+        (ASN1::ObjectIdentifier::ObjectIdentifier):
+        (ASN1::ObjectIdentifier::bytes const):
+        (ASN1::Sequence::create):
+        (ASN1::Sequence::Sequence):
+        (ASN1::Sequence::elementEncodedLengthBytes const):
+        (ASN1::IndexWrapper::IndexWrapper):
+        (ASN1::Integer::Integer):
+        (ASN1::BitString::BitString):
+        (TestWebKitAPI::wrapPublicKeyWithRSAPSSOID):
+        * TestWebKitAPI/Tests/WebCore/ASN1Utilities.h: Added.
+        * TestWebKitAPI/Tests/WebCore/PrivateClickMeasurement.cpp:
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/Tests/WebCore/cocoa/PrivateClickMeasurementCocoa.mm:
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/Tests/WebKitCocoa/EventAttribution.mm:
+        (TestWebKitAPI::TEST):
+
 2021-10-26  Tim Horton  <[email protected]>
 
         DisplayList::Recorder's clipBounds() becomes empty if a flip is applied to the CTM

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (284889 => 284890)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2021-10-26 19:44:14 UTC (rev 284889)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2021-10-26 19:50:30 UTC (rev 284890)
@@ -1150,6 +1150,7 @@
 		CEDA12412437C9FB00C28A9E /* editable-region-composited-and-non-composited-overlap.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CEDA12402437C9EA00C28A9E /* editable-region-composited-and-non-composited-overlap.html */; };
 		D34E08761E4E42E1005FF14A /* WKWebViewGetContents.mm in Sources */ = {isa = PBXBuildFile; fileRef = D3BE5E341E4CE85E00FD563A /* WKWebViewGetContents.mm */; };
 		DF4B273921A47728009BD1CA /* WKNSDictionaryEmptyDictionaryCrash.mm in Sources */ = {isa = PBXBuildFile; fileRef = DF4B273821A47727009BD1CA /* WKNSDictionaryEmptyDictionaryCrash.mm */; };
+		DF6580942722168900B3F1C1 /* ASN1Utilities.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DF6580922722168900B3F1C1 /* ASN1Utilities.cpp */; };
 		DFB80E38261512C1002D4771 /* TestAwakener.mm in Sources */ = {isa = PBXBuildFile; fileRef = DFB80E362615124E002D4771 /* TestAwakener.mm */; };
 		DFB8FF322492F52400F00B0D /* Preconnect.mm in Sources */ = {isa = PBXBuildFile; fileRef = DFB8FF312492F51A00F00B0D /* Preconnect.mm */; };
 		E1220DCA155B28AA0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = E1220DC9155B287D0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html */; };
@@ -3011,6 +3012,8 @@
 		D3BE5E341E4CE85E00FD563A /* WKWebViewGetContents.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewGetContents.mm; sourceTree = "<group>"; };
 		DC69AA621CF77C6500C6272F /* ScopedLambda.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScopedLambda.cpp; sourceTree = "<group>"; };
 		DF4B273821A47727009BD1CA /* WKNSDictionaryEmptyDictionaryCrash.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKNSDictionaryEmptyDictionaryCrash.mm; sourceTree = "<group>"; };
+		DF6580922722168900B3F1C1 /* ASN1Utilities.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ASN1Utilities.cpp; sourceTree = "<group>"; };
+		DF6580932722168900B3F1C1 /* ASN1Utilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASN1Utilities.h; sourceTree = "<group>"; };
 		DF6BC46F2534E120008F63CC /* TestDownloadDelegate.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = TestDownloadDelegate.mm; path = cocoa/TestDownloadDelegate.mm; sourceTree = "<group>"; };
 		DF6BC4702534E120008F63CC /* TestDownloadDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = TestDownloadDelegate.h; path = cocoa/TestDownloadDelegate.h; sourceTree = "<group>"; };
 		DF8A2E41267BEFAB00ED59DF /* WebSocket.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebSocket.mm; sourceTree = "<group>"; };
@@ -3783,6 +3786,8 @@
 				712E4BC025DDC52A0007201C /* AnimationFrameRate.cpp */,
 				57152B5D21CC2045000C37CA /* ApduTest.cpp */,
 				6354F4D01F7C3AB500D89DF3 /* ApplicationManifestParser.cpp */,
+				DF6580922722168900B3F1C1 /* ASN1Utilities.cpp */,
+				DF6580932722168900B3F1C1 /* ASN1Utilities.h */,
 				93A720E518F1A0E800A848E1 /* CalculationValue.cpp */,
 				07C046C91E42573E007201E7 /* CARingBuffer.cpp */,
 				57303BC220071E2200355965 /* CBORReaderTest.cpp */,
@@ -5454,6 +5459,7 @@
 				63F668221F97F7F90032EE51 /* ApplicationManifest.mm in Sources */,
 				6354F4D11F7C3AB500D89DF3 /* ApplicationManifestParser.cpp in Sources */,
 				49EF6AD52677C0BE007967DC /* AppPrivacyReport.mm in Sources */,
+				DF6580942722168900B3F1C1 /* ASN1Utilities.cpp in Sources */,
 				51B40D9E23AC962400E05241 /* AsyncFunction.mm in Sources */,
 				834138C7203261CA00F26960 /* AsyncPolicyForNavigationResponse.mm in Sources */,
 				7CCE7EB41A411A7E00447C4C /* AttributedString.mm in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebCore/ASN1Utilities.cpp (0 => 284890)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/ASN1Utilities.cpp	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/ASN1Utilities.cpp	2021-10-26 19:50:30 UTC (rev 284890)
@@ -0,0 +1,246 @@
+/*
+ * Copyright (C) 2021 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.
+ */
+
+#include "config.h"
+#include "ASN1Utilities.h"
+
+#include <wtf/UniqueRef.h>
+#include <wtf/Vector.h>
+
+namespace ASN1 {
+
+struct Object {
+    WTF_MAKE_STRUCT_FAST_ALLOCATED;
+    virtual size_t encodedLengthBytes() const = 0;
+    virtual void serializeTo(Vector<uint8_t>&) const = 0;
+    virtual ~Object() = default;
+protected:
+    size_t sizeSerializedSize(size_t size) const
+    {
+        if (size <= 0x7F)
+            return 1;
+        ASSERT(size <= std::numeric_limits<uint16_t>::max());
+        return 3;
+    }
+    void serializeSize(Vector<uint8_t>& vector, size_t size) const
+    {
+        ASSERT(size <= std::numeric_limits<uint16_t>::max());
+        if (size > 0x7F) {
+            vector.append(0x82);
+            vector.append(static_cast<uint8_t>(size >> 8));
+        }
+        vector.append(static_cast<uint8_t>(size));
+    }
+};
+
+struct ObjectIdentifier : Object {
+    WTF_MAKE_STRUCT_FAST_ALLOCATED;
+    enum class Type : uint8_t {
+        RsaEncryption,
+        Rsapss,
+        Sha384,
+        Pkcs1MGF
+    };
+    ObjectIdentifier(Type type)
+        : type(type) { }
+private:
+    const Type type;
+    size_t encodedLengthBytes() const final { return 11; }
+    void serializeTo(Vector<uint8_t>& vector) const final
+    {
+        vector.append(0x6);
+        auto oidBytes = bytes();
+        vector.append(oidBytes.size());
+        vector.append(oidBytes.data(), oidBytes.size());
+    }
+    std::array<uint8_t, 9> bytes() const
+    {
+        switch (type) {
+        case Type::RsaEncryption:
+            return { 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01 };
+        case Type::Rsapss:
+            return { 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0A };
+        case Type::Sha384:
+            return { 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02 };
+        case Type::Pkcs1MGF:
+            return { 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x08 };
+        }
+    }
+};
+
+struct Sequence : Object {
+    WTF_MAKE_STRUCT_FAST_ALLOCATED;
+    template<typename... Types>
+    static UniqueRef<Sequence> create(Types... types)
+    {
+        return makeUniqueRef<Sequence>(Vector<UniqueRef<Object>>::from(std::forward<Types>(types)...));
+    }
+    Sequence(Vector<UniqueRef<Object>>&& elements)
+        : elements(WTFMove(elements)) { }
+private:
+    const Vector<UniqueRef<Object>> elements;
+    size_t encodedLengthBytes() const final
+    {
+        size_t elementBytes = elementEncodedLengthBytes();
+        return 1 + sizeSerializedSize(elementBytes) + elementBytes;
+    }
+    void serializeTo(Vector<uint8_t>& vector) const final
+    {
+        vector.append(0x30);
+        serializeSize(vector, elementEncodedLengthBytes());
+        for (const auto& object : elements)
+            object->serializeTo(vector);
+    }
+    size_t elementEncodedLengthBytes() const
+    {
+        size_t total = 0;
+        for (const auto& element : elements)
+            total += element->encodedLengthBytes();
+        return total;
+    }
+};
+
+struct Null : Object {
+    WTF_MAKE_STRUCT_FAST_ALLOCATED;
+private:
+    size_t encodedLengthBytes() const final { return 2; }
+    void serializeTo(Vector<uint8_t>& vector) const final
+    {
+        vector.append(0x05);
+        vector.append(0x00);
+    }
+};
+
+struct IndexWrapper : Object {
+    WTF_MAKE_STRUCT_FAST_ALLOCATED;
+    IndexWrapper(uint8_t index, UniqueRef<Object>&& wrapped)
+        : index(index), wrapped(WTFMove(wrapped)) { }
+private:
+    const uint8_t index;
+    UniqueRef<Object> wrapped;
+    size_t encodedLengthBytes() const final
+    {
+        size_t wrappedBytes = wrapped->encodedLengthBytes();
+        return 1 + sizeSerializedSize(wrappedBytes) + wrappedBytes;
+    }
+    void serializeTo(Vector<uint8_t>& vector) const final
+    {
+        switch (index) {
+        case 0:
+            vector.append(0xa0);
+            break;
+        case 1:
+            vector.append(0xa1);
+            break;
+        case 2:
+            vector.append(0xa2);
+            break;
+        default:
+            ASSERT_NOT_REACHED();
+        }
+        serializeSize(vector, wrapped->encodedLengthBytes());
+        wrapped->serializeTo(vector);
+    }
+};
+
+struct Integer : Object {
+    WTF_MAKE_STRUCT_FAST_ALLOCATED;
+    Integer(uint8_t value)
+        : value(value) { }
+private:
+    const uint8_t value;
+    size_t encodedLengthBytes() const final
+    {
+        return 3;
+    }
+    void serializeTo(Vector<uint8_t>& vector) const final
+    {
+        vector.append(0x02);
+        vector.append(0x01);
+        vector.append(value);
+    }
+};
+
+struct BitString : Object {
+    WTF_MAKE_STRUCT_FAST_ALLOCATED;
+    BitString(Vector<uint8_t>&& bytes)
+        : bytes(WTFMove(bytes)) { }
+private:
+    const Vector<uint8_t> bytes;
+    size_t encodedLengthBytes() const final
+    {
+        size_t byteSize = bytes.size();
+        return 2 + sizeSerializedSize(byteSize) + byteSize;
+    }
+    void serializeTo(Vector<uint8_t>& vector) const final
+    {
+        vector.append(0x03);
+        serializeSize(vector, bytes.size() + 1);
+        vector.append(0x00);
+        vector.appendVector(bytes);
+    }
+};
+
+} // namespace ASN1
+
+namespace TestWebKitAPI {
+
+Vector<uint8_t> wrapPublicKeyWithRSAPSSOID(Vector<uint8_t>&& publicKey)
+{
+#if HAVE(RSA_PSS_OID)
+    auto sequence = ASN1::Sequence::create(
+        ASN1::Sequence::create(
+            makeUniqueRef<ASN1::ObjectIdentifier>(ASN1::ObjectIdentifier::Type::Rsapss),
+            ASN1::Sequence::create(
+                makeUniqueRef<ASN1::IndexWrapper>(0, ASN1::Sequence::create(
+                    makeUniqueRef<ASN1::ObjectIdentifier>(ASN1::ObjectIdentifier::Type::Sha384)
+                )),
+                makeUniqueRef<ASN1::IndexWrapper>(1, ASN1::Sequence::create(
+                    makeUniqueRef<ASN1::ObjectIdentifier>(ASN1::ObjectIdentifier::Type::Pkcs1MGF),
+                    ASN1::Sequence::create(
+                        makeUniqueRef<ASN1::ObjectIdentifier>(ASN1::ObjectIdentifier::Type::Sha384)
+                    )
+                )),
+                makeUniqueRef<ASN1::IndexWrapper>(2, makeUniqueRef<ASN1::Integer>(48))
+            )
+        ),
+        makeUniqueRef<ASN1::BitString>(WTFMove(publicKey))
+    );
+#else
+    auto sequence = ASN1::Sequence::create(
+        ASN1::Sequence::create(
+            makeUniqueRef<ASN1::ObjectIdentifier>(ASN1::ObjectIdentifier::Type::RsaEncryption),
+            makeUniqueRef<ASN1::Null>()
+        ),
+        makeUniqueRef<ASN1::BitString>(WTFMove(publicKey))
+    );
+#endif
+
+    Vector<uint8_t> wrapped;
+    static_cast<ASN1::Object&>(sequence.get()).serializeTo(wrapped);
+    return wrapped;
+}
+
+}

Added: trunk/Tools/TestWebKitAPI/Tests/WebCore/ASN1Utilities.h (0 => 284890)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/ASN1Utilities.h	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/ASN1Utilities.h	2021-10-26 19:50:30 UTC (rev 284890)
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2021 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
+
+#include <wtf/Forward.h>
+
+namespace TestWebKitAPI {
+
+Vector<uint8_t> wrapPublicKeyWithRSAPSSOID(Vector<uint8_t>&& publicKey);
+
+}

Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/PrivateClickMeasurement.cpp (284889 => 284890)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/PrivateClickMeasurement.cpp	2021-10-26 19:44:14 UTC (rev 284889)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/PrivateClickMeasurement.cpp	2021-10-26 19:50:30 UTC (rev 284890)
@@ -301,7 +301,11 @@
 #if HAVE(RSA_BSSA)
 TEST(PrivateClickMeasurement, InvalidBlindedSecret)
 {
+#if HAVE(RSA_PSS_OID)
+    const char serverPublicKeyBase64URL[] = "MIICUjA9BgkqhkiG9w0BAQowMKANMAsGCWCGSAFlAwQCAqEaMBgGCSqGSIb3DQEBCDALBglghkgBZQMEAgKiAwIBMAOCAg8AMIICCgKCAgEAoGhU5Mgsbb51ZbJVPHSgf8c93TJdtkxeKfyxQ5fCpwE2Fe9xJ7tByExdGKj4XO-HFi7npmtEPzR4cRXdsAL7YcH5UXNbVhXmVcbFCBXks-Ih-jqLwfNac0wPLG5K1Zzhf1gZ--JBzVjw87zvqpWrzzxviuV__0sn_u7f01E1OdaD83110fhfiXp_Ex62Q2uhcek0hqbqEvyKlLVBOjlJFJc2FLyw-l8-9xd7GcX1ZRyPx4lITvYG7KIbSMrFTfuQNOyJf4DlO97qq08R6Utl249AnBfLe3ZDbWBnl0fDOwkJgBmbaa7EnRlQ3p6Ir2SY1hNTnzW-p2ceytIMYwTMSES7-j21oeTUC-OmcC_5g05AgxROzUJPZdyY33m4Q7lqkHkLAYtdN2TVCP79MuswS-fJJQOD_dDCqq_hk0MySLCbnUGe5lyFBoO5vBMH5k38LjSQuN6jfP7quYA6cOONzmn842eLT61tIjRoX2czeUJrSmx89SfY8WnFE2fhk9G52cXp6L2Vzr5IV7rOws3ZPw-RnjKnZZaejs0bKGOXC1-jl-u4A5ip55ohlUjm7lvDtKFAeJ7gajJBtiNnq3s3m_IMkv7ztCQpv0pBxst6MmvNOO0jOQvYkzQbGooI1_qjeDup0BYY67xxyNRaA9V4CKEJ7j_hznrAmjSiz0LSqTkCAwEAAQ==";
+#else
     const char serverPublicKeyBase64URL[] = "MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAzb1dThrtYwVh46SjInegKhAqpbJwm1XnTBCvybSK8zk53R0Am1hG33AVF5J1lqYf36wp663GasclHtqzvxFZIvDA1DUSH4aZz_fDHCTTxEeJVPORS3zNN2UjWwbtnwsh4BmDTi-z_cDn0LAz2JuZyKlyFt5GgVLAQvL9H3VLHU9_XHNK-uboyXfcHRTtrDnpu3c6wvX5dd-AJoLmIQTZBEJfVkxBGznk1qKHjc6nASAirKF_wJCnuwAK8C6BAcjNcwUWCeKp0YECzCXU--JXd2OEU-QhxPC67faiDOh3V0vlfqZLtrlbnanUCKrvhw7GaGOGYotIrnZtuNfxC14d_XNVd1FS8nHjRTHnEgw_jnlSssfgStz0uJtcmkfgoJBvOE4mIRpi7iSlRfXNkKsWX1J-gwcnCVo5u0uJEW6X6NyvEGYJ8w5BPfwsQuK9y-4Z7ikt9IOucEHY7ThDmi9TNNhHBVj0Gu4wGoSjq3a6vL5N10ZSHXoq1XgfGPrmHhhL90cjvWonoyOXsUqlXEzTjD2W9897Q-Mx9BUNrGQPqmIx8F5MwxWcOrye8WRp4Q88n2YSUnV7C8ayld3v1Fh7N5jeSqeVmtDVRYTn2sVfNqgXrzgdigJcQR8vFENu6nzFPwsrXPMaCiLUnZNUmQ1ZSLQeQyhYXxHqRJrnuCDWXLkCAwEAAQ";
+#endif
 
     WebCore::PrivateClickMeasurement pcm(
         WebCore::PrivateClickMeasurement::SourceID({ }),

Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/cocoa/PrivateClickMeasurementCocoa.mm (284889 => 284890)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/cocoa/PrivateClickMeasurementCocoa.mm	2021-10-26 19:44:14 UTC (rev 284889)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/cocoa/PrivateClickMeasurementCocoa.mm	2021-10-26 19:50:30 UTC (rev 284890)
@@ -28,15 +28,14 @@
 
 #if HAVE(RSA_BSSA)
 
+#include "ASN1Utilities.h"
 #include "CoreCryptoSPI.h"
-
 #include <WebCore/PrivateClickMeasurement.h>
 #include <wtf/spi/cocoa/SecuritySPI.h>
 
+namespace TestWebKitAPI {
 using namespace WebCore;
 
-namespace TestWebKitAPI {
-
 TEST(PrivateClickMeasurement, ValidBlindedSecret)
 {
     auto ephemeralNonce = PrivateClickMeasurement::EphemeralSourceNonce { "ABCDEFabcdef0123456789"_s };
@@ -70,21 +69,15 @@
     const struct ccrsabssa_ciphersuite *ciphersuite = &ccrsabssa_ciphersuite_rsa4096_sha384;
 
     size_t exportSize = ccder_encode_rsa_pub_size(rsaPublicKey);
-    auto publicKey = adoptNS([[NSMutableData alloc] initWithLength:exportSize]);
-    ccder_encode_rsa_pub(rsaPublicKey, static_cast<uint8_t*>([publicKey mutableBytes]), static_cast<uint8_t*>([publicKey mutableBytes]) + [publicKey length]);
+    Vector<uint8_t> rawKeyBytes(exportSize);
+    ccder_encode_rsa_pub(rsaPublicKey, rawKeyBytes.data(), rawKeyBytes.data() + exportSize);
 
-    auto secKey = adoptCF(SecKeyCreateWithData((__bridge CFDataRef)publicKey.get(), (__bridge CFDictionaryRef)@{
-        (__bridge id)kSecAttrKeyType: (__bridge id)kSecAttrKeyTypeRSA,
-        (__bridge id)kSecAttrKeyClass: (__bridge id)kSecAttrKeyClassPublic
-    }, nil));
-    EXPECT_NOT_NULL(secKey);
+    auto wrappedKeyBytes = wrapPublicKeyWithRSAPSSOID(WTFMove(rawKeyBytes));
 
-    auto spkiData = adoptCF(SecKeyCopySubjectPublicKeyInfo(secKey.get()));
-    auto *nsSpkiData = (__bridge NSData *)spkiData.get();
-
     // Continue the test.
-    auto errorMessage = pcm.calculateAndUpdateSourceUnlinkableToken(base64URLEncodeToString(nsSpkiData.bytes, nsSpkiData.length));
+    auto errorMessage = pcm.calculateAndUpdateSourceUnlinkableToken(base64URLEncodeToString(wrappedKeyBytes.data(), wrappedKeyBytes.size()));
     EXPECT_FALSE(errorMessage);
+    
     auto sourceUnlinkableToken = pcm.tokenSignatureJSON();
     EXPECT_EQ(sourceUnlinkableToken->asObject()->size(), 4ul);
     EXPECT_STREQ(sourceUnlinkableToken->getString("source_engagement_type"_s).utf8().data(), "click");

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/EventAttribution.mm (284889 => 284890)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/EventAttribution.mm	2021-10-26 19:44:14 UTC (rev 284889)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/EventAttribution.mm	2021-10-26 19:50:30 UTC (rev 284890)
@@ -25,6 +25,7 @@
 
 #import "config.h"
 
+#import "ASN1Utilities.h"
 #import "DaemonTestUtilities.h"
 #import "HTTPServer.h"
 #import "PlatformUtilities.h"
@@ -216,12 +217,11 @@
         (__bridge id)kSecAttrKeyType: (__bridge id)kSecAttrKeyTypeRSA,
         (__bridge id)kSecAttrKeyClass: (__bridge id)kSecAttrKeyClassPublic
     }, nil));
+    Vector<uint8_t> rawKeyBytes(static_cast<const uint8_t*>(publicKey.get().bytes), publicKey.get().length);
+    auto wrappedKeyBytes = wrapPublicKeyWithRSAPSSOID(WTFMove(rawKeyBytes));
 
-    auto spkiData = adoptCF(SecKeyCopySubjectPublicKeyInfo(secKey.get()));
-    auto *nsSpkiData = (__bridge NSData *)spkiData.get();
+    auto keyData = base64URLEncodeToString(wrappedKeyBytes.data(), wrappedKeyBytes.size());
 
-    auto keyData = base64URLEncodeToString(nsSpkiData.bytes, nsSpkiData.length);
-
     // The server.
     HTTPServer server([&done, connectionCount = 0, &rsaPrivateKey, &modulusNBytes, &rng, &keyData, &secKey] (Connection connection) mutable {
         switch (++connectionCount) {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to