Skip to content

Commit

Permalink
Apply patch. rdar://125794592
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Robson committed Apr 5, 2024
1 parent e6123d8 commit a092821
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 21 deletions.
47 changes: 47 additions & 0 deletions Source/WebCore/Modules/webauthn/WebAuthenticationUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,53 @@ Vector<uint8_t> encodeRawPublicKey(const Vector<uint8_t>& x, const Vector<uint8_
return rawKey;
}

String toString(AuthenticatorTransport transport)
{
switch (transport) {
case AuthenticatorTransport::Usb:
return authenticatorTransportUsb;
break;
case AuthenticatorTransport::Nfc:
return authenticatorTransportNfc;
break;
case AuthenticatorTransport::Ble:
return authenticatorTransportBle;
break;
case AuthenticatorTransport::Internal:
return authenticatorTransportInternal;
break;
case AuthenticatorTransport::Cable:
return authenticatorTransportCable;
case AuthenticatorTransport::Hybrid:
return authenticatorTransportHybrid;
case AuthenticatorTransport::SmartCard:
return authenticatorTransportSmartCard;
default:
break;
}
ASSERT_NOT_REACHED();
return nullString();
}

std::optional<AuthenticatorTransport> convertStringToAuthenticatorTransport(const String& transport)
{
if (transport == authenticatorTransportUsb)
return AuthenticatorTransport::Usb;
if (transport == authenticatorTransportNfc)
return AuthenticatorTransport::Nfc;
if (transport == authenticatorTransportBle)
return AuthenticatorTransport::Ble;
if (transport == authenticatorTransportInternal)
return AuthenticatorTransport::Internal;
if (transport == authenticatorTransportCable)
return AuthenticatorTransport::Cable;
if (transport == authenticatorTransportHybrid)
return AuthenticatorTransport::Hybrid;
if (transport == authenticatorTransportSmartCard)
return AuthenticatorTransport::SmartCard;
return std::nullopt;
}

} // namespace WebCore

#endif // ENABLE(WEB_AUTHN)
5 changes: 5 additions & 0 deletions Source/WebCore/Modules/webauthn/WebAuthenticationUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ WEBCORE_EXPORT cbor::CBORValue::MapValue buildUserEntityMap(const Vector<uint8_t

// encodeRawPublicKey takes X & Y and returns them as a 0x04 || X || Y byte array.
WEBCORE_EXPORT Vector<uint8_t> encodeRawPublicKey(const Vector<uint8_t>& X, const Vector<uint8_t>& Y);

WEBCORE_EXPORT String toString(AuthenticatorTransport);

WEBCORE_EXPORT std::optional<AuthenticatorTransport> convertStringToAuthenticatorTransport(const String& transport);

} // namespace WebCore

#endif // ENABLE(WEB_AUTHN)
19 changes: 0 additions & 19 deletions Source/WebCore/Modules/webauthn/fido/DeviceResponseConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,6 @@ static ProtocolVersion convertStringToProtocolVersion(const String& version)
return ProtocolVersion::kUnknown;
}

static std::optional<AuthenticatorTransport> convertStringToAuthenticatorTransport(const String& transport)
{
if (transport == authenticatorTransportUsb)
return AuthenticatorTransport::Usb;
if (transport == authenticatorTransportNfc)
return AuthenticatorTransport::Nfc;
if (transport == authenticatorTransportBle)
return AuthenticatorTransport::Ble;
if (transport == authenticatorTransportInternal)
return AuthenticatorTransport::Internal;
if (transport == authenticatorTransportCable)
return AuthenticatorTransport::Cable;
if (transport == authenticatorTransportHybrid)
return AuthenticatorTransport::Hybrid;
if (transport == authenticatorTransportSmartCard)
return AuthenticatorTransport::SmartCard;
return std::nullopt;
}

std::optional<cbor::CBORValue> decodeResponseMap(const Vector<uint8_t>& inBuffer)
{
if (inBuffer.size() <= kResponseCodeLength || getResponseCode(inBuffer) != CtapDeviceResponseCode::kSuccess)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ typedef NSString *ASAuthorizationSecurityKeyPublicKeyCredentialDescriptorTranspo
@end

@interface ASAuthorizationSecurityKeyPublicKeyCredentialRegistration : NSObject <ASAuthorizationPublicKeyCredentialRegistration>
@property (nonatomic, readonly) NSArray<ASAuthorizationSecurityKeyPublicKeyCredentialDescriptorTransport> *transports;
@end

typedef NSInteger ASCOSEAlgorithmIdentifier NS_TYPED_EXTENSIBLE_ENUM;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,16 @@ static inline bool isCrossPlatformRequest(const Vector<AuthenticatorTransport>&
}
}

inline static Vector<AuthenticatorTransport> toTransports(NSArray<ASAuthorizationSecurityKeyPublicKeyCredentialDescriptorTransport> *asTransports)
{
Vector<AuthenticatorTransport> transports;
for (ASAuthorizationSecurityKeyPublicKeyCredentialDescriptorTransport asTransport : asTransports) {
if (auto transport = convertStringToAuthenticatorTransport(asTransport))
transports.append(*transport);
}
return transports;
}

#endif // HAVE(WEB_AUTHN_AS_MODERN)

void WebAuthenticatorCoordinatorProxy::performRequest(WebAuthenticationRequestData &&requestData, RequestCompletionHandler &&handler)
Expand Down Expand Up @@ -466,7 +476,7 @@ static inline bool isCrossPlatformRequest(const Vector<AuthenticatorTransport>&
auto credential = retainPtr((ASAuthorizationPlatformPublicKeyCredentialRegistration *)auth.get().credential);
response.rawId = toArrayBuffer(credential.get().credentialID);
response.attestationObject = toArrayBuffer(credential.get().rawAttestationObject);
response.transports = { };
response.transports = { AuthenticatorTransport::Internal, AuthenticatorTransport::Hybrid };
response.clientDataJSON = toArrayBuffer(credential.get().rawClientDataJSON);
if (credential.get().largeBlob)
response.extensionOutputs = { { std::nullopt, std::nullopt, { { credential.get().largeBlob.isSupported, nullptr, std::nullopt } } } };
Expand All @@ -488,7 +498,10 @@ static inline bool isCrossPlatformRequest(const Vector<AuthenticatorTransport>&
response.isAuthenticatorAttestationResponse = true;
response.rawId = toArrayBuffer(credential.get().credentialID);
response.attestationObject = toArrayBuffer(credential.get().rawAttestationObject);
response.transports = { };
if ([credential respondsToSelector:@selector(transports)])
response.transports = toTransports(credential.get().transports);
else
response.transports = { };
response.clientDataJSON = toArrayBuffer(credential.get().rawClientDataJSON);
} else if ([auth.get().credential isKindOfClass:getASAuthorizationSecurityKeyPublicKeyCredentialAssertionClass()]) {
auto credential = retainPtr((ASAuthorizationSecurityKeyPublicKeyCredentialAssertion *)auth.get().credential);
Expand Down

0 comments on commit a092821

Please sign in to comment.