Changeset 286075 in webkit
- Timestamp:
- Nov 19, 2021, 1:43:17 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 17 edited
- 1 copied
-
Source/WebKit/ChangeLog (modified) (1 diff)
-
Source/WebKit/NetworkProcess/Notifications/NetworkNotificationManager.cpp (modified) (3 diffs)
-
Source/WebKit/NetworkProcess/Notifications/NetworkNotificationManager.h (modified) (1 diff)
-
Source/WebKit/Resources/ios/XPCService-embedded-simulator.entitlements (modified) (1 diff)
-
Source/WebKit/Scripts/process-entitlements.sh (modified) (2 diffs)
-
Source/WebKit/Shared/Cocoa/CodeSigning.h (modified) (1 diff)
-
Source/WebKit/Shared/Cocoa/CodeSigning.mm (modified) (2 diffs)
-
Source/WebKit/Shared/WebPushDaemonConstants.h (modified) (2 diffs)
-
Source/WebKit/WebKit.xcodeproj/project.pbxproj (modified) (7 diffs)
-
Source/WebKit/webpushd/PushClientConnection.h (copied) (copied from trunk/Source/WebKit/Shared/Cocoa/CodeSigning.h ) (2 diffs)
-
Source/WebKit/webpushd/PushClientConnection.mm (added)
-
Source/WebKit/webpushd/WebPushDaemon.h (modified) (3 diffs)
-
Source/WebKit/webpushd/WebPushDaemon.mm (modified) (9 diffs)
-
Source/WebKit/webpushd/WebPushDaemonMain.mm (modified) (1 diff)
-
Tools/ChangeLog (modified) (1 diff)
-
Tools/TestWebKitAPI/Configurations/TestWebKitAPI-iOS.entitlements (modified) (1 diff)
-
Tools/TestWebKitAPI/Configurations/TestWebKitAPI-macOS-internal.entitlements (modified) (1 diff)
-
Tools/TestWebKitAPI/Configurations/TestWebKitAPI-macOS.entitlements (modified) (1 diff)
-
Tools/TestWebKitAPI/Tests/WebKitCocoa/WebPushDaemon.mm (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r286073 r286075 1 2021-11-19 Brady Eidson <beidson@apple.com> 2 3 More webpushd architecture work 4 https://bugs.webkit.org/show_bug.cgi?id=233295 5 6 Reviewed by Alex Christensen. 7 8 Covered by API tests. 9 10 This patch: 11 - Adds entitlement checks for connections to webpushd 12 - Adds a "ClientConnection" object to the daemon to manage per-connection state 13 - Adds a debug enabled setting 14 - Adds the ability for the connecting app (com.apple.WebKit.Networking) to pass the host app's audit_token 15 - Tests some of the above 16 - Adds the beginnings of other future infrastructure 17 18 * NetworkProcess/Notifications/NetworkNotificationManager.cpp: 19 (WebKit::NetworkNotificationManager::NetworkNotificationManager): 20 21 * Resources/ios/XPCService-embedded-simulator.entitlements: 22 * Scripts/process-entitlements.sh: 23 24 * Shared/Cocoa/CodeSigning.h: 25 * Shared/Cocoa/CodeSigning.mm: 26 (WebKit::codeSigningIdentifierAndPlatformBinaryStatus): 27 (WebKit::codeSigningIdentifier): 28 29 * Shared/WebPushDaemonConstants.h: 30 (WebKit::WebPushD::messageTypeSendsReply): 31 32 * WebKit.xcodeproj/project.pbxproj: 33 34 * webpushd/PushClientConnection.h: Copied from Source/WebKit/Shared/Cocoa/CodeSigning.h. 35 (WebPushD::ClientConnection::hasAuditToken const): 36 (WebPushD::ClientConnection::debugModeIsEnabled const): 37 * webpushd/PushClientConnection.mm: Added. 38 (WebPushD::ClientConnection::ClientConnection): 39 (WebPushD::ClientConnection::setAuditTokenData): 40 (WebPushD::ClientConnection::hostCodeSigningIdentifier): 41 (WebPushD::ClientConnection::hostHasPushEntitlement): 42 (WebPushD::ClientConnection::setDebugModeIsEnabled): 43 44 * webpushd/WebPushDaemon.h: 45 * webpushd/WebPushDaemon.mm: 46 (WebPushD::handleWebPushDMessageWithReply): 47 (WebPushD::handleWebPushDMessage): 48 (WebPushD::Daemon::broadcastDebugMessage): 49 (WebPushD::Daemon::connectionEventHandler): 50 (WebPushD::Daemon::connectionAdded): 51 (WebPushD::Daemon::connectionRemoved): 52 (WebPushD::Daemon::decodeAndHandleMessage): 53 (WebPushD::Daemon::echoTwice): 54 (WebPushD::Daemon::canRegisterForNotifications): 55 (WebPushD::Daemon::requestSystemNotificationPermission): 56 (WebPushD::Daemon::getOriginsWithPushAndNotificationPermissions): 57 (WebPushD::Daemon::deletePushAndNotificationRegistration): 58 (WebPushD::Daemon::setHostAppAuditToken): 59 (WebPushD::Daemon::setDebugModeIsEnabled): 60 (WebPushD::Daemon::toClientConnection): 61 * webpushd/WebPushDaemonMain.mm: 62 (main): 63 1 64 2021-11-19 Brent Fulgham <bfulgham@apple.com> 2 65 -
trunk/Source/WebKit/NetworkProcess/Notifications/NetworkNotificationManager.cpp
r285121 r286075 44 44 } 45 45 46 void NetworkNotificationManager::maybeSendHostAppAuditToken() const 47 { 48 if (m_sentHostAppAuditToken) 49 return; 50 m_sentHostAppAuditToken = true; 51 52 #if PLATFORM(COCOA) 53 auto token = m_networkSession.networkProcess().parentProcessConnection()->getAuditToken(); 54 if (!token) 55 return; 56 57 Vector<uint8_t> auditTokenData; 58 auditTokenData.resize(sizeof(*token)); 59 memcpy(auditTokenData.data(), &(*token), sizeof(*token)); 60 61 sendMessage<WebPushD::MessageType::SetHostAppAuditToken>(auditTokenData); 62 #endif 63 } 64 46 65 void NetworkNotificationManager::requestSystemNotificationPermission(const String& originString, CompletionHandler<void(bool)>&& completionHandler) 47 66 { … … 104 123 { 105 124 RELEASE_ASSERT(m_connection); 125 126 maybeSendHostAppAuditToken(); 127 106 128 Daemon::Encoder encoder; 107 129 encoder.encode(std::forward<Args>(args)...); … … 165 187 { 166 188 RELEASE_ASSERT(m_connection); 189 190 maybeSendHostAppAuditToken(); 167 191 168 192 Daemon::Encoder encoder; -
trunk/Source/WebKit/NetworkProcess/Notifications/NetworkNotificationManager.h
r285121 r286075 63 63 void didDestroyNotification(uint64_t notificationID) final; 64 64 65 void maybeSendHostAppAuditToken() const; 66 65 67 NetworkSession& m_networkSession; 66 68 std::unique_ptr<WebPushD::Connection> m_connection; 69 mutable bool m_sentHostAppAuditToken { false }; 67 70 68 71 template<WebPushD::MessageType messageType, typename... Args> -
trunk/Source/WebKit/Resources/ios/XPCService-embedded-simulator.entitlements
r265260 r286075 7 7 <key>com.apple.private.webkit.use-xpc-endpoint</key> 8 8 <true/> 9 <key>com.apple.private.webkit.webpush</key> 10 <true/> 9 11 </dict> 10 12 </plist> -
trunk/Source/WebKit/Scripts/process-entitlements.sh
r286032 r286075 132 132 plistbuddy Add :com.apple.symptom_analytics.configure bool YES 133 133 plistbuddy Add :com.apple.private.webkit.adattributiond bool YES 134 plistbuddy Add :com.apple.private.webkit.webpush bool YES 134 135 fi 135 136 } … … 402 403 { 403 404 plistbuddy Add :com.apple.private.webkit.adattributiond bool YES 405 plistbuddy Add :com.apple.private.webkit.webpush bool YES 404 406 plistbuddy Add :com.apple.multitasking.systemappassertions bool YES 405 407 plistbuddy Add :com.apple.payment.all-access bool YES -
trunk/Source/WebKit/Shared/Cocoa/CodeSigning.h
r280451 r286075 34 34 String codeSigningIdentifierForCurrentProcess(); 35 35 String codeSigningIdentifier(xpc_connection_t); 36 String codeSigningIdentifier(audit_token_t); 36 37 bool currentProcessIsPlatformBinary(); 37 38 std::pair<String, bool> codeSigningIdentifierAndPlatformBinaryStatus(xpc_connection_t); -
trunk/Source/WebKit/Shared/Cocoa/CodeSigning.mm
r280451 r286075 58 58 } 59 59 60 st d::pair<String, bool> codeSigningIdentifierAndPlatformBinaryStatus(xpc_connection_t connection)60 static std::pair<String, bool> codeSigningIdentifierAndPlatformBinaryStatus(audit_token_t auditToken) 61 61 { 62 audit_token_t auditToken;63 xpc_connection_get_audit_token(connection, &auditToken);64 62 auto task = adoptCF(SecTaskCreateWithAuditToken(kCFAllocatorDefault, auditToken)); 65 63 bool isPlatformBinary = SecTaskGetCodeSignStatus(task.get()) & CS_PLATFORM_BINARY; … … 68 66 } 69 67 68 std::pair<String, bool> codeSigningIdentifierAndPlatformBinaryStatus(xpc_connection_t connection) 69 { 70 audit_token_t auditToken; 71 xpc_connection_get_audit_token(connection, &auditToken); 72 73 return codeSigningIdentifierAndPlatformBinaryStatus(auditToken); 74 } 75 76 String codeSigningIdentifier(audit_token_t token) 77 { 78 auto pair = codeSigningIdentifierAndPlatformBinaryStatus(token); 79 return pair.first; 80 } 81 70 82 } // namespace WebKit 71 83 -
trunk/Source/WebKit/Shared/WebPushDaemonConstants.h
r285121 r286075 41 41 DeletePushAndNotificationRegistration, 42 42 GetOriginsWithPushAndNotificationPermissions, 43 SetHostAppAuditToken, 44 SetDebugModeIsEnabled, 43 45 }; 44 46 … … 51 53 case MessageType::RequestSystemNotificationPermission: 52 54 return true; 55 case MessageType::SetHostAppAuditToken: 56 case MessageType::SetDebugModeIsEnabled: 57 return false; 53 58 } 54 59 ASSERT_NOT_REACHED(); -
trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj
r286067 r286075 1048 1048 51F060E11654318500F3282F /* WebMDNSRegisterMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51F060DD1654317500F3282F /* WebMDNSRegisterMessageReceiver.cpp */; }; 1049 1049 51F060E11654318500F3283F /* NetworkMDNSRegisterMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51F060DD1654317500F3283F /* NetworkMDNSRegisterMessageReceiver.cpp */; }; 1050 51F7BB7B2744C50700C45A72 /* PushClientConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 51F7BB792744C50700C45A72 /* PushClientConnection.h */; }; 1051 51F7BB7C2744C50700C45A72 /* PushClientConnection.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51F7BB7A2744C50700C45A72 /* PushClientConnection.mm */; }; 1052 51F7BB7D2745640400C45A72 /* CodeSigning.mm in Sources */ = {isa = PBXBuildFile; fileRef = CE11AD4F1CBC47F800681EE5 /* CodeSigning.mm */; }; 1053 51F7BB7F274564A100C45A72 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 51F7BB7E274564A100C45A72 /* Security.framework */; }; 1050 1054 51F886A61F2C228100C193EF /* WKTestingSupport.h in Headers */ = {isa = PBXBuildFile; fileRef = 51F886A41F2C214A00C193EF /* WKTestingSupport.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1051 1055 51FAEC3A1B0657630009C4E7 /* AuxiliaryProcessMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 51FAEC371B0657310009C4E7 /* AuxiliaryProcessMessages.h */; }; … … 4256 4260 51F060DD1654317500F3283F /* NetworkMDNSRegisterMessageReceiver.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = NetworkMDNSRegisterMessageReceiver.cpp; path = DerivedSources/WebKit2/NetworkMDNSRegisterMessageReceiver.cpp; sourceTree = BUILT_PRODUCTS_DIR; }; 4257 4261 51F060DE1654317500F3281B /* WebResourceLoaderMessages.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = WebResourceLoaderMessages.h; path = DerivedSources/WebKit2/WebResourceLoaderMessages.h; sourceTree = BUILT_PRODUCTS_DIR; }; 4262 51F7BB792744C50700C45A72 /* PushClientConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PushClientConnection.h; sourceTree = "<group>"; }; 4263 51F7BB7A2744C50700C45A72 /* PushClientConnection.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PushClientConnection.mm; sourceTree = "<group>"; }; 4264 51F7BB7E274564A100C45A72 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; }; 4258 4265 51F886A31F2C214A00C193EF /* WKTestingSupport.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKTestingSupport.cpp; sourceTree = "<group>"; }; 4259 4266 51F886A41F2C214A00C193EF /* WKTestingSupport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKTestingSupport.h; sourceTree = "<group>"; }; … … 6230 6237 buildActionMask = 2147483647; 6231 6238 files = ( 6239 51F7BB7F274564A100C45A72 /* Security.framework in Frameworks */, 6232 6240 ); 6233 6241 runOnlyForDeploymentPostprocessing = 0; … … 9346 9354 isa = PBXGroup; 9347 9355 children = ( 9356 51F7BB7E274564A100C45A72 /* Security.framework */, 9348 9357 57A9FF15252C6AEF006A2040 /* libWTF.a */, 9349 9358 5750F32A2032D4E500389347 /* LocalAuthentication.framework */, … … 9596 9605 children = ( 9597 9606 5CBB6D4D271F67CC00FD1A5D /* com.apple.webkit.webpushd.plist */, 9607 51F7BB792744C50700C45A72 /* PushClientConnection.h */, 9608 51F7BB7A2744C50700C45A72 /* PushClientConnection.mm */, 9598 9609 512CD69D2723393A00F7F8EC /* WebPushDaemon.h */, 9599 9610 512CD69E2723393A00F7F8EC /* WebPushDaemon.mm */, … … 12069 12080 buildActionMask = 2147483647; 12070 12081 files = ( 12082 51F7BB7B2744C50700C45A72 /* PushClientConnection.h in Headers */, 12071 12083 5C1579FC2717AF5000ED5280 /* DaemonUtilities.h in Headers */, 12072 12084 512CD69F2723393A00F7F8EC /* WebPushDaemon.h in Headers */, … … 14547 14559 buildActionMask = 2147483647; 14548 14560 files = ( 14561 51F7BB7D2745640400C45A72 /* CodeSigning.mm in Sources */, 14549 14562 5C157A012717B7FB00ED5280 /* ArgumentCoders.cpp in Sources */, 14550 14563 5C1579FF2717B6D200ED5280 /* DaemonDecoder.cpp in Sources */, 14564 51F7BB7C2744C50700C45A72 /* PushClientConnection.mm in Sources */, 14551 14565 5C1579FE2717B6C100ED5280 /* DaemonEncoder.cpp in Sources */, 14552 14566 5C1579FB2717AF5000ED5280 /* DaemonUtilities.mm in Sources */, -
trunk/Source/WebKit/webpushd/PushClientConnection.h
r286074 r286075 1 1 /* 2 * Copyright (C) 20 16-2021 Apple Inc. All rights reserved.2 * Copyright (C) 2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 26 26 #pragma once 27 27 28 #include <optional> 28 29 #include <wtf/Forward.h> 30 #include <wtf/OSObjectPtr.h> 29 31 #include <wtf/spi/darwin/XPCSPI.h> 32 #include <wtf/text/WTFString.h> 30 33 31 namespace Web Kit{34 namespace WebPushD { 32 35 33 // These functions return a null string if the process is unsigned. 34 String codeSigningIdentifierForCurrentProcess(); 35 String codeSigningIdentifier(xpc_connection_t); 36 bool currentProcessIsPlatformBinary(); 37 std::pair<String, bool> codeSigningIdentifierAndPlatformBinaryStatus(xpc_connection_t); 36 class ClientConnection { 37 WTF_MAKE_FAST_ALLOCATED; 38 public: 39 ClientConnection(xpc_connection_t); 38 40 39 } // namespace WebKit 41 bool hasHostAppAuditToken() const { return !!m_hostAppAuditToken; } 42 void setHostAppAuditTokenData(const Vector<uint8_t>&); 43 44 const String& hostAppCodeSigningIdentifier(); 45 bool hostAppHasPushEntitlement(); 46 47 bool debugModeIsEnabled() const { return m_debugModeEnabled; } 48 void setDebugModeIsEnabled(bool); 49 50 private: 51 OSObjectPtr<xpc_connection_t> m_xpcConnection; 52 53 std::optional<audit_token_t> m_hostAppAuditToken; 54 std::optional<String> m_hostAppCodeSigningIdentifier; 55 std::optional<bool> m_hostAppHasPushEntitlement; 56 57 bool m_debugModeEnabled { false }; 58 }; 59 60 } // namespace WebPushD -
trunk/Source/WebKit/webpushd/WebPushDaemon.h
r285121 r286075 26 26 #pragma once 27 27 28 #include "PushClientConnection.h" 28 29 #include "WebPushDaemonConstants.h" 29 30 #include <wtf/Forward.h> 31 #include <wtf/HashMap.h> 30 32 #include <wtf/HashSet.h> 31 33 #include <wtf/OSObjectPtr.h> … … 33 35 #include <wtf/spi/darwin/XPCSPI.h> 34 36 35 using WebKit::WebPushD::MessageType; 37 38 namespace JSC { 39 enum class MessageLevel : uint8_t; 40 } 36 41 37 42 namespace WebPushD { … … 49 54 50 55 // Message handlers 51 void echoTwice(const String&, CompletionHandler<void(const String&)>&& replySender); 52 void requestSystemNotificationPermission(const String&, CompletionHandler<void(bool)>&& replySender); 53 void getOriginsWithPushAndNotificationPermissions(CompletionHandler<void(const Vector<String>&)>&& replySender); 54 void deletePushAndNotificationRegistration(const String& originString, CompletionHandler<void(const String&)>&& replySender); 56 void echoTwice(ClientConnection*, const String&, CompletionHandler<void(const String&)>&& replySender); 57 void requestSystemNotificationPermission(ClientConnection*, const String&, CompletionHandler<void(bool)>&& replySender); 58 void getOriginsWithPushAndNotificationPermissions(ClientConnection*, CompletionHandler<void(const Vector<String>&)>&& replySender); 59 void deletePushAndNotificationRegistration(ClientConnection*, const String& originString, CompletionHandler<void(const String&)>&& replySender); 60 void setHostAppAuditToken(ClientConnection*, const Vector<uint8_t>&); 61 void setDebugModeIsEnabled(ClientConnection*, bool); 62 63 void broadcastDebugMessage(JSC::MessageLevel, const String&); 55 64 56 65 private: 57 66 Daemon() = default; 58 67 59 CompletionHandler<void(EncodedMessage&&)> createReplySender(MessageType, OSObjectPtr<xpc_object_t>&& request); 60 void decodeAndHandleMessage(MessageType, Span<const uint8_t> encodedMessage, CompletionHandler<void(EncodedMessage&&)>&&); 68 CompletionHandler<void(EncodedMessage&&)> createReplySender(WebKit::WebPushD::MessageType, OSObjectPtr<xpc_object_t>&& request); 69 void decodeAndHandleMessage(xpc_connection_t, WebKit::WebPushD::MessageType, Span<const uint8_t> encodedMessage, CompletionHandler<void(EncodedMessage&&)>&&); 70 71 bool canRegisterForNotifications(ClientConnection&); 72 73 ClientConnection* toClientConnection(xpc_connection_t); 61 74 62 75 HashSet<String> m_inMemoryOriginStringsWithPermissionForTesting; 76 77 HashMap<xpc_connection_t, std::unique_ptr<ClientConnection>> m_connectionMap; 63 78 }; 64 79 -
trunk/Source/WebKit/webpushd/WebPushDaemon.mm
r285121 r286075 69 69 END 70 70 71 FUNCTION(setHostAppAuditToken) 72 ARGUMENTS(Vector<uint8_t>) 73 END 74 75 FUNCTION(setDebugModeIsEnabled) 76 ARGUMENTS(bool) 77 END 78 71 79 #undef FUNCTION 72 80 #undef ARGUMENTS … … 105 113 106 114 template<typename Info> 107 void handleWebPushDMessageWithReply( Span<const uint8_t> encodedMessage, CompletionHandler<void(WebPushD::EncodedMessage&&)>&& replySender)115 void handleWebPushDMessageWithReply(ClientConnection* connection, Span<const uint8_t> encodedMessage, CompletionHandler<void(WebPushD::EncodedMessage&&)>&& replySender) 108 116 { 109 117 WebKit::Daemon::Decoder decoder(encodedMessage); … … 118 126 } }; 119 127 120 IPC::callMemberFunction(WTFMove(*arguments), WTFMove(completionHandler), &WebPushD::Daemon::singleton(), Info::MemberFunction); 128 IPC::callMemberFunction(tuple_cat(std::make_tuple(connection), WTFMove(*arguments)), WTFMove(completionHandler), &WebPushD::Daemon::singleton(), Info::MemberFunction); 129 } 130 131 template<typename Info> 132 void handleWebPushDMessage(ClientConnection* connection, Span<const uint8_t> encodedMessage) 133 { 134 WebKit::Daemon::Decoder decoder(encodedMessage); 135 136 std::optional<typename Info::ArgsTuple> arguments; 137 decoder >> arguments; 138 if (UNLIKELY(!arguments)) 139 return; 140 141 IPC::callMemberFunction(tuple_cat(std::make_tuple(connection), WTFMove(*arguments)), &WebPushD::Daemon::singleton(), Info::MemberFunction); 121 142 } 122 143 … … 125 146 static NeverDestroyed<Daemon> daemon; 126 147 return daemon; 148 } 149 150 void Daemon::broadcastDebugMessage(JSC::MessageLevel messageLevel, const String& message) 151 { 152 auto dictionary = adoptOSObject(xpc_dictionary_create(nullptr, nullptr, 0)); 153 xpc_dictionary_set_uint64(dictionary.get(), protocolDebugMessageLevelKey, static_cast<uint64_t>(messageLevel)); 154 xpc_dictionary_set_string(dictionary.get(), protocolDebugMessageKey, message.utf8().data()); 155 for (auto& iterator : m_connectionMap) { 156 if (iterator.value->debugModeIsEnabled()) 157 xpc_connection_send_message(iterator.key, dictionary.get()); 158 } 127 159 } 128 160 … … 143 175 Span<const uint8_t> encodedMessage { static_cast<const uint8_t*>(data), dataSize }; 144 176 145 decodeAndHandleMessage(messageType, encodedMessage, createReplySender(messageType, request)); 146 } 147 148 void Daemon::connectionAdded(xpc_connection_t) 149 { 150 // FIXME: Track connections 151 } 152 153 void Daemon::connectionRemoved(xpc_connection_t) 154 { 155 // FIXME: Track connections 177 decodeAndHandleMessage(xpc_dictionary_get_remote_connection(request), messageType, encodedMessage, createReplySender(messageType, request)); 178 } 179 180 void Daemon::connectionAdded(xpc_connection_t connection) 181 { 182 RELEASE_ASSERT(!m_connectionMap.contains(connection)); 183 m_connectionMap.set(connection, WTF::makeUnique<ClientConnection>(connection)); 184 } 185 186 void Daemon::connectionRemoved(xpc_connection_t connection) 187 { 188 RELEASE_ASSERT(m_connectionMap.contains(connection)); 189 m_connectionMap.remove(connection); 156 190 } 157 191 … … 170 204 } 171 205 172 void Daemon::decodeAndHandleMessage( MessageType messageType, Span<const uint8_t> encodedMessage, CompletionHandler<void(EncodedMessage&&)>&& replySender)206 void Daemon::decodeAndHandleMessage(xpc_connection_t connection, MessageType messageType, Span<const uint8_t> encodedMessage, CompletionHandler<void(EncodedMessage&&)>&& replySender) 173 207 { 174 208 ASSERT(messageTypeSendsReply(messageType) == !!replySender); 209 210 auto* clientConnection = toClientConnection(connection); 175 211 176 212 switch (messageType) { 177 213 case MessageType::EchoTwice: 178 handleWebPushDMessageWithReply<MessageInfo::echoTwice>( encodedMessage, WTFMove(replySender));214 handleWebPushDMessageWithReply<MessageInfo::echoTwice>(clientConnection, encodedMessage, WTFMove(replySender)); 179 215 break; 180 216 case MessageType::GetOriginsWithPushAndNotificationPermissions: 181 handleWebPushDMessageWithReply<MessageInfo::getOriginsWithPushAndNotificationPermissions>( encodedMessage, WTFMove(replySender));217 handleWebPushDMessageWithReply<MessageInfo::getOriginsWithPushAndNotificationPermissions>(clientConnection, encodedMessage, WTFMove(replySender)); 182 218 break; 183 219 case MessageType::DeletePushAndNotificationRegistration: 184 handleWebPushDMessageWithReply<MessageInfo::deletePushAndNotificationRegistration>( encodedMessage, WTFMove(replySender));220 handleWebPushDMessageWithReply<MessageInfo::deletePushAndNotificationRegistration>(clientConnection, encodedMessage, WTFMove(replySender)); 185 221 break; 186 222 case MessageType::RequestSystemNotificationPermission: 187 handleWebPushDMessageWithReply<MessageInfo::requestSystemNotificationPermission>(encodedMessage, WTFMove(replySender)); 188 break; 189 } 190 } 191 192 void Daemon::echoTwice(const String& message, CompletionHandler<void(const String&)>&& replySender) 223 handleWebPushDMessageWithReply<MessageInfo::requestSystemNotificationPermission>(clientConnection, encodedMessage, WTFMove(replySender)); 224 break; 225 case MessageType::SetHostAppAuditToken: 226 handleWebPushDMessage<MessageInfo::setHostAppAuditToken>(clientConnection, encodedMessage); 227 break; 228 case MessageType::SetDebugModeIsEnabled: 229 handleWebPushDMessage<MessageInfo::setDebugModeIsEnabled>(clientConnection, encodedMessage); 230 break; 231 } 232 } 233 234 void Daemon::echoTwice(ClientConnection*, const String& message, CompletionHandler<void(const String&)>&& replySender) 193 235 { 194 236 replySender(makeString(message, message)); 195 237 } 196 238 197 void Daemon::requestSystemNotificationPermission(const String& originString, CompletionHandler<void(bool)>&& replySender) 198 { 239 bool Daemon::canRegisterForNotifications(ClientConnection& connection) 240 { 241 if (connection.hostAppCodeSigningIdentifier().isEmpty()) { 242 NSLog(@"ClientConnection cannot interact with notifications: Unknown host application code signing identifier"); 243 return false; 244 } 245 246 return true; 247 } 248 249 void Daemon::requestSystemNotificationPermission(ClientConnection* connection, const String& originString, CompletionHandler<void(bool)>&& replySender) 250 { 251 if (!canRegisterForNotifications(*connection)) { 252 replySender(false); 253 return; 254 } 255 199 256 // FIXME: This is for an API testing checkpoint 200 257 // Next step is actually perform a persistent permissions request on a per-platform basis … … 203 260 } 204 261 205 void Daemon::getOriginsWithPushAndNotificationPermissions(CompletionHandler<void(const Vector<String>&)>&& replySender) 206 { 262 void Daemon::getOriginsWithPushAndNotificationPermissions(ClientConnection* connection, CompletionHandler<void(const Vector<String>&)>&& replySender) 263 { 264 if (!canRegisterForNotifications(*connection)) { 265 replySender({ }); 266 return; 267 } 268 207 269 // FIXME: This is for an API testing checkpoint 208 270 // Next step is actually gather persistent permissions from the system on a per-platform basis … … 210 272 } 211 273 212 void Daemon::deletePushAndNotificationRegistration(const String& originString, CompletionHandler<void(const String&)>&& replySender) 213 { 274 void Daemon::deletePushAndNotificationRegistration(ClientConnection* connection, const String& originString, CompletionHandler<void(const String&)>&& replySender) 275 { 276 if (!canRegisterForNotifications(*connection)) { 277 replySender("Could not delete push and notification registrations for connection: Unknown host application code signing identifier"); 278 return; 279 } 280 214 281 // FIXME: This is for an API testing checkpoint 215 282 // Next step is actually delete any persistent permissions on a per-platform basis … … 220 287 } 221 288 289 void Daemon::setHostAppAuditToken(ClientConnection* clientConnection, const Vector<uint8_t>& tokenData) 290 { 291 clientConnection->setHostAppAuditTokenData(tokenData); 292 } 293 294 void Daemon::setDebugModeIsEnabled(ClientConnection* clientConnection, bool enabled) 295 { 296 clientConnection->setDebugModeIsEnabled(enabled); 297 } 298 299 ClientConnection* Daemon::toClientConnection(xpc_connection_t connection) 300 { 301 auto clientConnection = m_connectionMap.get(connection); 302 RELEASE_ASSERT(clientConnection); 303 return clientConnection; 304 } 305 222 306 } // namespace WebPushD -
trunk/Source/WebKit/webpushd/WebPushDaemonMain.mm
r284887 r286075 65 65 66 66 @autoreleasepool { 67 // FIXME: Add a sandbox. 68 // FIXME: Add an entitlement check. 69 WebKit::startListeningForMachServiceConnections(machServiceName, nullptr, WebPushD::connectionAdded, WebPushD::connectionRemoved, WebPushD::connectionEventHandler); 67 WebKit::startListeningForMachServiceConnections(machServiceName, "com.apple.private.webkit.webpush", WebPushD::connectionAdded, WebPushD::connectionRemoved, WebPushD::connectionEventHandler); 70 68 WTF::initializeMainThread(); 71 69 } -
trunk/Tools/ChangeLog
r286074 r286075 1 2021-11-19 Brady Eidson <beidson@apple.com> 2 3 More webpushd architecture work 4 https://bugs.webkit.org/show_bug.cgi?id=233295 5 6 Reviewed by Alex Christensen. 7 8 * TestWebKitAPI/Configurations/TestWebKitAPI-iOS.entitlements: 9 * TestWebKitAPI/Configurations/TestWebKitAPI-macOS-internal.entitlements: 10 * TestWebKitAPI/Configurations/TestWebKitAPI-macOS.entitlements: 11 * TestWebKitAPI/Tests/WebKitCocoa/WebPushDaemon.mm: 12 (TestWebKitAPI::TEST): 13 1 14 2021-11-18 Jonathan Bedard <jbedard@apple.com> 2 15 -
trunk/Tools/TestWebKitAPI/Configurations/TestWebKitAPI-iOS.entitlements
r285799 r286075 11 11 <key>com.apple.Pasteboard.paste-unchecked</key> 12 12 <true/> 13 <key>com.apple.private.webkit.webpush</key> 14 <true/> 13 15 <key>com.apple.private.xpc.launchd.job-manager</key> 14 16 <string>TestWebKitAPI</string> -
trunk/Tools/TestWebKitAPI/Configurations/TestWebKitAPI-macOS-internal.entitlements
r282368 r286075 5 5 <key>com.apple.private.xpc.launchd.job-manager</key> 6 6 <string>TestWebKitAPI</string> 7 <key>com.apple.private.webkit.webpush</key> 8 <true/> 7 9 <key>com.apple.hid.manager.user-access-device</key> 8 10 <true/> -
trunk/Tools/TestWebKitAPI/Configurations/TestWebKitAPI-macOS.entitlements
r282368 r286075 9 9 <string>com.apple.TestWebKitAPI</string> 10 10 </array> 11 <key>com.apple.private.webkit.webpush</key> 12 <true/> 11 13 <key>com.apple.security.temporary-exception.sbpl</key> 12 14 <array> -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebPushDaemon.mm
r285963 r286075 32 32 #import <WebKit/WKUIDelegatePrivate.h> 33 33 #import <WebKit/_WKExperimentalFeature.h> 34 #import <mach/mach_init.h> 35 #import <mach/task.h> 34 36 35 37 #if PLATFORM(MAC) || PLATFORM(IOS) … … 157 159 158 160 // FIXME: Re-enable this test for Monterey+ once webkit.org/232857 is resolved. 159 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 120000161 #if __MAC_OS_X_VERSION_MIN_REQUIRED < 110000 || __MAC_OS_X_VERSION_MIN_REQUIRED >= 120000 160 162 TEST(WebPushD, DISABLED_BasicCommunication) 161 163 #else … … 166 168 167 169 auto connection = adoptNS(xpc_connection_create_mach_service("org.webkit.webpushtestdaemon.service", dispatch_get_main_queue(), 0)); 168 xpc_connection_set_event_handler(connection.get(), ^(xpc_object_t) { }); 170 171 __block bool done = false; 172 xpc_connection_set_event_handler(connection.get(), ^(xpc_object_t request) { 173 if (xpc_get_type(request) != XPC_TYPE_DICTIONARY) 174 return; 175 const char* debugMessage = xpc_dictionary_get_string(request, "debug message"); 176 if (!debugMessage) 177 return; 178 179 bool stringMatches = !strcmp(debugMessage, "[webpushd - TestWebKitAPI] Turned Debug Mode on"); 180 if (!stringMatches) 181 stringMatches = !strcmp(debugMessage, "[webpushd - com.apple.WebKit.TestWebKitAPI] Turned Debug Mode on"); 182 183 EXPECT_TRUE(stringMatches); 184 185 done = true; 186 }); 187 169 188 xpc_connection_activate(connection.get()); 189 190 audit_token_t token = { 0, 0, 0, 0, 0, 0, 0, 0 }; 191 mach_msg_type_number_t auditTokenCount = TASK_AUDIT_TOKEN_COUNT; 192 kern_return_t result = task_info(mach_task_self(), TASK_AUDIT_TOKEN, (task_info_t)(&token), &auditTokenCount); 193 if (result != KERN_SUCCESS) { 194 EXPECT_TRUE(false); 195 return; 196 } 197 198 // Send audit token 199 { 200 std::array<uint8_t, 40> encodedMessage; 201 encodedMessage.fill(0); 202 encodedMessage[0] = 32; 203 memcpy(&encodedMessage[8], &token, sizeof(token)); 204 auto dictionary = adoptNS(xpc_dictionary_create(nullptr, nullptr, 0)); 205 xpc_dictionary_set_uint64(dictionary.get(), "protocol version", 1); 206 xpc_dictionary_set_uint64(dictionary.get(), "message type", 5); 207 xpc_dictionary_set_data(dictionary.get(), "encoded message", encodedMessage.data(), encodedMessage.size()); 208 xpc_connection_send_message(connection.get(), dictionary.get()); 209 } 210 211 // Enable debug messages, and wait for the resulting debug message 212 { 213 auto dictionary = adoptNS(xpc_dictionary_create(nullptr, nullptr, 0)); 214 std::array<uint8_t, 1> encodedMessage { 1 }; 215 xpc_dictionary_set_uint64(dictionary.get(), "protocol version", 1); 216 xpc_dictionary_set_uint64(dictionary.get(), "message type", 6); 217 xpc_dictionary_set_data(dictionary.get(), "encoded message", encodedMessage.data(), encodedMessage.size()); 218 219 xpc_connection_send_message(connection.get(), dictionary.get()); 220 TestWebKitAPI::Util::run(&done); 221 } 222 223 // Echo and wait for a reply 170 224 auto dictionary = adoptNS(xpc_dictionary_create(nullptr, nullptr, 0)); 171 172 225 std::array<uint8_t, 10> encodedString { 5, 0, 0, 0, 1, 'h', 'e', 'l', 'l', 'o' }; 173 226 xpc_dictionary_set_uint64(dictionary.get(), "protocol version", 1); 174 227 xpc_dictionary_set_uint64(dictionary.get(), "message type", 1); 175 228 xpc_dictionary_set_data(dictionary.get(), "encoded message", encodedString.data(), encodedString.size()); 176 177 __block booldone = false;229 230 done = false; 178 231 xpc_connection_send_message_with_reply(connection.get(), dictionary.get(), dispatch_get_main_queue(), ^(xpc_object_t reply) { 179 232 if (xpc_get_type(reply) != XPC_TYPE_DICTIONARY) { … … 203 256 204 257 // FIXME: Re-enable this test for Monterey+ once webkit.org/232857 is resolved. 205 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 120000258 #if __MAC_OS_X_VERSION_MIN_REQUIRED < 110000 || __MAC_OS_X_VERSION_MIN_REQUIRED >= 120000 206 259 TEST(WebPushD, DISABLED_PermissionManagement) 207 260 #else
Note:
See TracChangeset
for help on using the changeset viewer.