Bug 222401 - WKRemoteObjectCoder should be able to handle NSErrors from TLS failures
Summary: WKRemoteObjectCoder should be able to handle NSErrors from TLS failures
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Alex Christensen
URL:
Keywords: InRadar
Depends on: 222954
Blocks:
  Show dependency treegraph
 
Reported: 2021-02-24 20:15 PST by Alex Christensen
Modified: 2021-03-08 16:31 PST (History)
3 users (show)

See Also:


Attachments
Patch (14.36 KB, patch)
2021-02-24 20:20 PST, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (14.21 KB, patch)
2021-03-02 21:26 PST, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (14.23 KB, patch)
2021-03-02 21:29 PST, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (14.16 KB, patch)
2021-03-03 22:31 PST, Alex Christensen
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Christensen 2021-02-24 20:15:03 PST
WKRemoteObjectCoder should be able to handle NSErrors from TLS failures
Comment 1 Alex Christensen 2021-02-24 20:20:41 PST
Created attachment 421496 [details]
Patch
Comment 2 Alex Christensen 2021-02-24 20:20:44 PST
<rdar://problem/72103865>
Comment 3 Chris Dumez 2021-03-02 14:44:00 PST
Comment on attachment 421496 [details]
Patch

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

> Source/WebKit/Shared/API/Cocoa/WKRemoteObjectCoder.mm:317
> +    return [result autorelease];

I spent a lot of time getting rid of all the explicit [objc autorelease] in our internal code. Please use RetainPtr<>.

> Source/WebKit/Shared/API/Cocoa/WKRemoteObjectCoder.mm:343
> +    return (NSData *)data.autorelease();

I cc'd Darin because I seem to remember that this sort of things (casting from CF to NS and autoreleasing) makes ARC transition complicated.

Overall, we should be using RetainPtr<>.
Comment 4 Darin Adler 2021-03-02 17:14:02 PST
Comment on attachment 421496 [details]
Patch

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

I suggest using a lot more RetainPtr.

> Source/WebKit/Shared/API/Cocoa/WKRemoteObjectCoder.mm:303
> +static id decodeObjCObject(WKRemoteObjectDecoder *decoder, Class objectClass)

This should return a RetainPtr<id>.

> Source/WebKit/Shared/API/Cocoa/WKRemoteObjectCoder.mm:322
> +NSString *peerCertificateKey = @"NSErrorPeerCertificateChainKey";
> +NSString *peerTrustKey = @"NSURLErrorFailingURLPeerTrustErrorKey";
> +NSString *clientCertificateKey = @"NSErrorClientCertificateChainKey";

Should these have static constexpr in front of them?

> Source/WebKit/Shared/API/Cocoa/WKRemoteObjectCoder.mm:324
> +static NSArray *transformCertificatesToData(NSArray *input)

This should return a RetainPtr<NSArray>.

> Source/WebKit/Shared/API/Cocoa/WKRemoteObjectCoder.mm:335
> +static NSData *transformTrustToData(SecTrustRef trust)

This should return a RetainPtr<CFDataRef>.

>> Source/WebKit/Shared/API/Cocoa/WKRemoteObjectCoder.mm:343
>> +    return (NSData *)data.autorelease();
> 
> I cc'd Darin because I seem to remember that this sort of things (casting from CF to NS and autoreleasing) makes ARC transition complicated.
> 
> Overall, we should be using RetainPtr<>.

For our own functions we should use RetainPtr for return values, not autoreleased objects. However, I don’t know exactly how to change a RetainPtr<CFDataRef> into a RetainPtr<NSData>. I suggest we sidestep that issue by having this function return RetainPtr<CFDataRef>.

> Source/WebKit/Shared/API/Cocoa/WKRemoteObjectCoder.mm:348
> +    NSMutableDictionary *copy = nil;

This should be a RetainPtr.

> Source/WebKit/Shared/API/Cocoa/WKRemoteObjectCoder.mm:374
> +static NSArray *transformDataToCertificates(NSArray *input)

This should return a RetainPtr<NSArray>.

> Source/WebKit/Shared/API/Cocoa/WKRemoteObjectCoder.mm:388
> +static id transformDataToTrust(NSData *data)

This should probably return a RetainPtr<CFTypeRef>.

> Source/WebKit/Shared/API/Cocoa/WKRemoteObjectCoder.mm:399
> +static NSError *decodeError(WKRemoteObjectDecoder *decoder)

This should return a RetainPtr<NSError>.
Comment 5 Alex Christensen 2021-03-02 21:26:52 PST
Created attachment 422041 [details]
Patch
Comment 6 Alex Christensen 2021-03-02 21:29:14 PST
Created attachment 422042 [details]
Patch
Comment 7 Alex Christensen 2021-03-02 21:30:54 PST
(In reply to Darin Adler from comment #4)
> > Source/WebKit/Shared/API/Cocoa/WKRemoteObjectCoder.mm:322
> > +NSString *peerCertificateKey = @"NSErrorPeerCertificateChainKey";
> > +NSString *peerTrustKey = @"NSURLErrorFailingURLPeerTrustErrorKey";
> > +NSString *clientCertificateKey = @"NSErrorClientCertificateChainKey";
> 
> Should these have static constexpr in front of them?

This blew my mind a little bit.  Static I get, but I definitely need to do more thinking about exactly what a constexpr NSString* is.
Comment 8 Darin Adler 2021-03-03 09:37:39 PST
(In reply to Alex Christensen from comment #7)
> This blew my mind a little bit.  Static I get, but I definitely need to do
> more thinking about exactly what a constexpr NSString* is.

Roughly speaking, it's an NSString * with a value known at compile time and that never changes.
Comment 9 Chris Dumez 2021-03-03 09:56:33 PST
Comment on attachment 422042 [details]
Patch

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

r=me with a couple of changes.

> Tools/TestWebKitAPI/Tests/WebKitCocoa/RemoteObjectRegistry.mm:237
> +    auto webView = [[[WKWebView alloc] initWithFrame:CGRectZero configuration:[WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"RemoteObjectRegistryPlugIn"]] autorelease];

no autorelease] please. Just use adoptNS().

> Tools/TestWebKitAPI/Tests/WebKitCocoa/RemoteObjectRegistry.mm:238
> +    auto delegate = [[TestNavigationDelegate new] autorelease];

ditto.
Comment 10 Alex Christensen 2021-03-03 22:31:39 PST
Created attachment 422183 [details]
Patch
Comment 11 EWS 2021-03-03 23:22:37 PST
Committed r273875: <https://commits.webkit.org/r273875>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 422183 [details].