Bug 233295 - More webpushd architecture work
Summary: More webpushd architecture work
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Brady Eidson
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-11-17 16:52 PST by Brady Eidson
Modified: 2021-12-01 14:32 PST (History)
6 users (show)

See Also:


Attachments
EWS v1 (35.99 KB, patch)
2021-11-17 16:54 PST, Brady Eidson
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
EWS v2 (39.83 KB, patch)
2021-11-17 18:10 PST, Brady Eidson
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
EWS v3 (40.03 KB, patch)
2021-11-17 19:06 PST, Brady Eidson
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
EWS v4 (40.05 KB, patch)
2021-11-17 19:43 PST, Brady Eidson
no flags Details | Formatted Diff | Diff
EWS v5 (40.13 KB, patch)
2021-11-17 23:07 PST, Brady Eidson
achristensen: review-
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Updated for review feedback, still building locally to explore Mac API test failure (40.20 KB, patch)
2021-11-18 16:55 PST, Brady Eidson
achristensen: review+
Details | Formatted Diff | Diff
More for EWS while I explore Mac API thingy (41.82 KB, patch)
2021-11-18 21:26 PST, Brady Eidson
no flags Details | Formatted Diff | Diff
PFL v1 (42.87 KB, patch)
2021-11-19 01:17 PST, Brady Eidson
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
PFL v2 (42.68 KB, patch)
2021-11-19 11:08 PST, Brady Eidson
no flags Details | Formatted Diff | Diff
PFL v3 (42.68 KB, patch)
2021-11-19 12:26 PST, Brady Eidson
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brady Eidson 2021-11-17 16:52:49 PST
More webpushd architecture work
Comment 1 Brady Eidson 2021-11-17 16:54:48 PST
Created attachment 444609 [details]
EWS v1

Besides missing ChangeLogs, I know this'll need more work. Need EWS to tell me how much more.
Comment 2 Brady Eidson 2021-11-17 18:10:25 PST
Created attachment 444623 [details]
EWS v2
Comment 3 Brady Eidson 2021-11-17 19:06:17 PST
Created attachment 444628 [details]
EWS v3
Comment 4 Brady Eidson 2021-11-17 19:43:32 PST
Created attachment 444631 [details]
EWS v4
Comment 5 Brady Eidson 2021-11-17 23:07:36 PST
Created attachment 444641 [details]
EWS v5
Comment 6 Brady Eidson 2021-11-18 08:49:06 PST
Going to mark for review even while I work on resolving the api-mac failure
Comment 7 Alex Christensen 2021-11-18 11:51:33 PST
Comment on attachment 444641 [details]
EWS v5

View in context: https://bugs.webkit.org/attachment.cgi?id=444641&action=review

> Source/WebKit/NetworkProcess/Notifications/NetworkNotificationManager.cpp:45
> +        auto cfData = m_networkSession.networkProcess().sourceApplicationAuditData();

You can probably do this from sourceApplicationAuditToken to be slightly more efficient.

> Source/WebKit/Shared/Cocoa/CodeSigning.mm:78
> +    auto pair = codeSigningIdentifierAndPlatformBinaryStatus(token);

This doesn't need to call SecTaskGetCodeSignStatus.

> Source/WebKit/webpushd/PushClientConnection.mm:42
> +void ClientConnection::setAuditTokenData(const Vector<uint8_t>& tokenData)

This is a little strange.  Isn't xpc_connection_get_audit_token enough?

> Source/WebKit/webpushd/PushClientConnection.mm:72
> +        m_hostHasPushEntitlement = WTF::hasEntitlement(*m_hostAppAuditToken, "com.apple.private.webkit.webpush");

This is typically done at the time a connection is being received, then terminating the connection if it doesn't have an entitlement.  That way you avoid bugs where you forgot to check the entitlement.  If you have a connection, then it is entitled.

> Source/WebKit/webpushd/WebPushDaemon.h:56
> +    void echoTwice(ClientConnection*, const String&, CompletionHandler<void(const String&)>&& replySender);

We can probably remove this at some point.

> Source/WebKit/webpushd/WebPushDaemon.h:77
> +    HashMap<xpc_connection_t, std::unique_ptr<ClientConnection>> m_connectionMap;

It's a little strange that the connection is both in the key and the value.
Comment 8 Brady Eidson 2021-11-18 13:59:20 PST
(In reply to Alex Christensen from comment #7)
> Comment on attachment 444641 [details]
> EWS v5
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=444641&action=review
> 
> > Source/WebKit/NetworkProcess/Notifications/NetworkNotificationManager.cpp:45
> > +        auto cfData = m_networkSession.networkProcess().sourceApplicationAuditData();
> 
> You can probably do this from sourceApplicationAuditToken to be slightly
> more efficient.

Yes.

> 
> > Source/WebKit/Shared/Cocoa/CodeSigning.mm:78
> > +    auto pair = codeSigningIdentifierAndPlatformBinaryStatus(token);
> 
> This doesn't need to call SecTaskGetCodeSignStatus.

I was trying to reuse the existing abstractions, but will open it up a bit more.

> 
> > Source/WebKit/webpushd/PushClientConnection.mm:42
> > +void ClientConnection::setAuditTokenData(const Vector<uint8_t>& tokenData)
> 
> This is a little strange.  Isn't xpc_connection_get_audit_token enough?

xpc_connection_get_audit_token gets the audit token of the remote process.

For example, in webpushd, it gets the audit token of com.apple.WebKit.Networking

We need the remote-remote audit token. E.g. if com.apple.WebKit.Networking is running on behalf of Safari, we need Safari's audit token.

This would've been made much clearer if I named these methods more precisely.

> 
> > Source/WebKit/webpushd/PushClientConnection.mm:72
> > +        m_hostHasPushEntitlement = WTF::hasEntitlement(*m_hostAppAuditToken, "com.apple.private.webkit.webpush");
> 
> This is typically done at the time a connection is being received, then
> terminating the connection if it doesn't have an entitlement.  That way you
> avoid bugs where you forgot to check the entitlement.  If you have a
> connection, then it is entitled.

Once again, see above: This isn't the remote connection... this is the host app *of* the remote connection.

So it cannot be done at connection time.

> 
> > Source/WebKit/webpushd/WebPushDaemon.h:56
> > +    void echoTwice(ClientConnection*, const String&, CompletionHandler<void(const String&)>&& replySender);
> 
> We can probably remove this at some point.

Sure. Will do separately.

> 
> > Source/WebKit/webpushd/WebPushDaemon.h:77
> > +    HashMap<xpc_connection_t, std::unique_ptr<ClientConnection>> m_connectionMap;
> 
> It's a little strange that the connection is both in the key and the value.

I have no alternative suggestions though.
Comment 9 Brady Eidson 2021-11-18 16:55:30 PST
Created attachment 444760 [details]
Updated for review feedback, still building locally to explore Mac API test failure
Comment 10 Alex Christensen 2021-11-18 17:15:32 PST
In DaemonConnectionSet I made the map a map from the connection to a collection of metadata that doesn't contain another reference to the connection.  That's my alternative suggestion
Comment 11 Brady Eidson 2021-11-18 17:47:40 PST
(In reply to Alex Christensen from comment #10)
> In DaemonConnectionSet I made the map a map from the connection to a
> collection of metadata that doesn't contain another reference to the
> connection.  That's my alternative suggestion

I'm not clear on how that's better - It's still a map of xpc_connection_t to information about those connections.

For future reference: ClientConnection WILL have more data and behaviors than just what this patch introduces, very soon.

It will be supremely useful for things like "This xpc connection dropped - Find it's resulting WebPushD::ClientConnection object and have it clean up outstanding activities"
Comment 12 Brady Eidson 2021-11-18 17:48:36 PST
I figured out the Mac API test issue, but need to finish a full Mac build to resolve. Will do soon. This patch still reviewable.
Comment 13 Alex Christensen 2021-11-18 17:54:16 PST
Comment on attachment 444760 [details]
Updated for review feedback, still building locally to explore Mac API test failure

View in context: https://bugs.webkit.org/attachment.cgi?id=444760&action=review

> Source/WebKit/NetworkProcess/Notifications/NetworkNotificationManager.cpp:39
>  NetworkNotificationManager::NetworkNotificationManager(NetworkSession& networkSession, const String& webPushMachServiceName)

nit: mach service names can be a CString because they are always ASCII.

> Source/WebKit/NetworkProcess/Notifications/NetworkNotificationManager.cpp:53
> +        sendMessage<WebPushD::MessageType::SetHostAppAuditToken>(auditTokenData);

Sending the first message will start the daemon if it hasn't been started, so we probably want to lazily send this to prevent unnecessary daemon starting.

> Source/WebKit/webpushd/PushClientConnection.h:44
> +    String hostAppCodeSigningIdentifier();

nit: can this return a const String& ?
Comment 14 Brady Eidson 2021-11-18 21:26:49 PST
Created attachment 444780 [details]
More for EWS while I explore Mac API thingy
Comment 15 Brady Eidson 2021-11-18 22:56:38 PST
Can't reproduce the mac-api test failure locally. My suspicion is internal vs non-internal SDK. (related to entitlements or audit tokens somehow)

Building on a public SDK now.
Comment 16 Brady Eidson 2021-11-19 01:17:37 PST
Created attachment 444787 [details]
PFL v1

The Mac-api-test failure was because the source application audit token wasn't making its way through.
This was because USE_SOURCE_APPLICATION_AUDIT_DATA was true for Mac only in the internal SDK... but it seems to work great in the public SDK as well.

Enabling that and giving it a test run.
Comment 17 Brady Eidson 2021-11-19 09:06:17 PST
(In reply to Brady Eidson from comment #16)
> Created attachment 444787 [details]
> PFL v1
> 
> The Mac-api-test failure was because the source application audit token
> wasn't making its way through.
> This was because USE_SOURCE_APPLICATION_AUDIT_DATA was true for Mac only in
> the internal SDK... but it seems to work great in the public SDK as well.
> 
> Enabling that and giving it a test run.

And it's obvious that we're not ready for all the related fallout from that.

Doing something more limited.
Comment 18 Brady Eidson 2021-11-19 11:08:05 PST
Created attachment 444838 [details]
PFL v2
Comment 19 Brady Eidson 2021-11-19 12:26:00 PST
Created attachment 444844 [details]
PFL v3
Comment 20 EWS 2021-11-19 13:43:24 PST
Committed r286075 (244462@main): <https://commits.webkit.org/244462@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 444844 [details].
Comment 21 Radar WebKit Bug Importer 2021-11-19 13:44:26 PST
<rdar://problem/85618026>