Skip to content

Commit

Permalink
Make WebAuthn interface easier to call from Swift
Browse files Browse the repository at this point in the history
rdar://124490616

Reviewed by Brent Fulgham.

This patch updates a few bits from the WebAuthn interface to make them easier to call from
Swift.

* Source/WebKit/UIProcess/API/Cocoa/_WKAuthenticatorAssertionResponse.mm:
(-[_WKAuthenticatorAssertionResponse initWithClientDataJSON:rawId:extensions:authenticatorData:signature:userHandle:attachment:]):
(-[_WKAuthenticatorAssertionResponse initWithClientDataJSON:rawId:extensionOutputsCBOR:authenticatorData:signature:userHandle:attachment:]):
(-[_WKAuthenticatorAssertionResponse dealloc]):
None of the ivars in this class were being retained/released. This hasn't been an issue
for ObjC because they're all retained by the callsite, but it matters for Swift due to the
bridging between Data and NSData. The superclass already retains/releases its ivars
correctly.

* Source/WebKit/UIProcess/API/Cocoa/_WKWebAuthenticationPanel.h:
All of the results in these completion handlers are nullable (e.g. we never expect to
return an assertion _and_ an error). ObjC doesn't care if they're annotated incorrectly,
but Swift does.

Canonical link: https://commits.webkit.org/276180@main
  • Loading branch information
Garrett Davidson authored and Pascoe committed Mar 15, 2024
1 parent 2464f16 commit 6f20a05
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ - (instancetype)initWithClientDataJSON:(NSData *)clientDataJSON rawId:(NSData *)
if (!(self = [super initWithClientDataJSON:clientDataJSON rawId:rawId extensions:WTFMove(extensions) attachment:attachment]))
return nil;

_authenticatorData = authenticatorData;
_signature = signature;
_userHandle = userHandle;
_authenticatorData = [authenticatorData retain];
_signature = [signature retain];
_userHandle = [userHandle retain];
return self;
}

Expand All @@ -48,10 +48,18 @@ - (instancetype)initWithClientDataJSON:(NSData *)clientDataJSON rawId:(NSData *)
if (!(self = [super initWithClientDataJSON:clientDataJSON rawId:rawId extensionOutputsCBOR:extensionOutputsCBOR attachment:attachment]))
return nil;

_authenticatorData = authenticatorData;
_signature = signature;
_userHandle = userHandle;
_authenticatorData = [authenticatorData retain];
_signature = [signature retain];
_userHandle = [userHandle retain];
return self;
}

- (void)dealloc
{
[_authenticatorData release];
[_signature release];
[_userHandle release];
[super dealloc];
}

@end
12 changes: 6 additions & 6 deletions Source/WebKit/UIProcess/API/Cocoa/_WKWebAuthenticationPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ WK_CLASS_AVAILABLE(macos(10.15.4), ios(13.4))
- (instancetype)init;

// FIXME: <rdar://problem/71509485> Adds detailed NSError.
- (void)makeCredentialWithChallenge:(NSData *)challenge origin:(NSString *)origin options:(_WKPublicKeyCredentialCreationOptions *)options completionHandler:(void (^)(_WKAuthenticatorAttestationResponse *, NSError *))handler WK_API_AVAILABLE(macos(12.0), ios(15.0));
- (void)makeCredentialWithClientDataHash:(NSData *)clientDataHash options:(_WKPublicKeyCredentialCreationOptions *)options completionHandler:(void (^)(_WKAuthenticatorAttestationResponse *, NSError *))handler WK_API_AVAILABLE(macos(13.0), ios(16.0));
- (void)makeCredentialWithMediationRequirement:(_WKWebAuthenticationMediationRequirement)mediation clientDataHash:(NSData *)clientDataHash options:(_WKPublicKeyCredentialCreationOptions *)options completionHandler:(void (^)(_WKAuthenticatorAttestationResponse *, NSError *))handler WK_API_AVAILABLE(macos(13.0), ios(16.0));
- (void)getAssertionWithChallenge:(NSData *)challenge origin:(NSString *)origin options:(_WKPublicKeyCredentialRequestOptions *)options completionHandler:(void (^)(_WKAuthenticatorAssertionResponse *, NSError *))handler WK_API_AVAILABLE(macos(12.0), ios(15.0));
- (void)getAssertionWithClientDataHash:(NSData *)clientDataHash options:(_WKPublicKeyCredentialRequestOptions *)options completionHandler:(void (^)(_WKAuthenticatorAssertionResponse *, NSError *))handler WK_API_AVAILABLE(macos(13.0), ios(16.0));
- (void)getAssertionWithMediationRequirement:(_WKWebAuthenticationMediationRequirement)mediation clientDataHash:(NSData *)clientDataHash options:(_WKPublicKeyCredentialRequestOptions *)options completionHandler:(void (^)(_WKAuthenticatorAssertionResponse *, NSError *))handler WK_API_AVAILABLE(macos(13.0), ios(16.0));
- (void)makeCredentialWithChallenge:(NSData *)challenge origin:(NSString *)origin options:(_WKPublicKeyCredentialCreationOptions *)options completionHandler:(void (^)(_WKAuthenticatorAttestationResponse * _Nullable, NSError * _Nullable))handler WK_API_AVAILABLE(macos(12.0), ios(15.0));
- (void)makeCredentialWithClientDataHash:(NSData *)clientDataHash options:(_WKPublicKeyCredentialCreationOptions *)options completionHandler:(void (^)(_WKAuthenticatorAttestationResponse * _Nullable, NSError * _Nullable))handler WK_API_AVAILABLE(macos(13.0), ios(16.0));
- (void)makeCredentialWithMediationRequirement:(_WKWebAuthenticationMediationRequirement)mediation clientDataHash:(NSData *)clientDataHash options:(_WKPublicKeyCredentialCreationOptions *)options completionHandler:(void (^)(_WKAuthenticatorAttestationResponse * _Nullable, NSError * _Nullable))handler WK_API_AVAILABLE(macos(13.0), ios(16.0));
- (void)getAssertionWithChallenge:(NSData *)challenge origin:(NSString *)origin options:(_WKPublicKeyCredentialRequestOptions *)options completionHandler:(void (^)(_WKAuthenticatorAssertionResponse * _Nullable, NSError * _Nullable))handler WK_API_AVAILABLE(macos(12.0), ios(15.0));
- (void)getAssertionWithClientDataHash:(NSData *)clientDataHash options:(_WKPublicKeyCredentialRequestOptions *)options completionHandler:(void (^)(_WKAuthenticatorAssertionResponse * _Nullable, NSError * _Nullable))handler WK_API_AVAILABLE(macos(13.0), ios(16.0));
- (void)getAssertionWithMediationRequirement:(_WKWebAuthenticationMediationRequirement)mediation clientDataHash:(NSData *)clientDataHash options:(_WKPublicKeyCredentialRequestOptions *)options completionHandler:(void (^)(_WKAuthenticatorAssertionResponse * _Nullable, NSError * _Nullable))handler WK_API_AVAILABLE(macos(13.0), ios(16.0));
- (void)cancel;

// FIXME: <rdar://problem/71509848> Deprecate the following properties.
Expand Down

0 comments on commit 6f20a05

Please sign in to comment.