Skip to content

Refactor tests, add documentation and fix bugs #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 35 commits into from
Mar 22, 2023
Merged

Refactor tests, add documentation and fix bugs #19

merged 35 commits into from
Mar 22, 2023

Conversation

marius-se
Copy link
Collaborator

@marius-se marius-se commented Feb 22, 2023

This PR adds a lot of tests and test infrastructure.
Besides that I renamed some properties to follow the WebAuthn spec more closely, I renamed the User protocol to WebAuthnUser, which closes #18, and I updated the README a little bit.

Finally a lot of work went into adding attestation verification for packed and TPM attestation formats, but there are still too many pieces missing to release it. To fully support attestation verification we'll have to have support for:

  • android key
  • android safetynet
  • apple
  • fido u2f
  • packed (95% done)
  • tpm (70% done)

@marius-se marius-se marked this pull request as ready for review March 15, 2023 13:06
@marius-se marius-se requested review from 0xTim and removed request for 0xTim March 15, 2023 13:06
@marius-se marius-se changed the title Add attestation formats Refactor tests, add documentation and fix bugs Mar 15, 2023
@marius-se marius-se requested a review from 0xTim March 15, 2023 13:15
Copy link
Member

@0xTim 0xTim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests look way better! Added some comments and queries. Most changes are around documentation of public types

Comment on lines +66 to +82
// case .packed:
// try await PackedAttestation.verify(
// attStmt: attestationStatement,
// authenticatorData: rawAuthenticatorData,
// clientDataHash: Data(clientDataHash),
// credentialPublicKey: credentialPublicKey,
// pemRootCertificates: pemRootCertificates
// )
// case .tpm:
// try TPMAttestation.verify(
// attStmt: attestationStatement,
// authenticatorData: rawAuthenticatorData,
// attestedCredentialData: attestedCredentialData,
// clientDataHash: Data(clientDataHash),
// credentialPublicKey: credentialPublicKey,
// pemRootCertificates: pemRootCertificates
// )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove if not needed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need this once attestation verification is ready. If uncommented it should compile, but the verification flow is not done yet.

}

// MARK: - Credential parameters

public struct PublicKeyCredentialParameters: Equatable, Codable {
public let type: String
public let algorithm: COSEAlgorithmIdentifier
public let alg: COSEAlgorithmIdentifier
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to rename this? alg might be unclear (we can use CodingKeys if it's a JSON thing

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regular users of this library shouldn't care about this. They'll just encode this and send it to the frontend/ client without inspecting what's in there.

Internally following the naming conventions of the WebAuthn specs makes things a lot easier during development. But I'm happy to change it back since I know the codebase, I'm just worrying about newbies.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok fair enough

requireUserVerification: Bool = false,
confirmCredentialIDNotRegisteredYet: (String) async throws -> Bool = { _ in true }
) async throws -> Credential {
try await webAuthnManager.finishRegistration(
challenge: challenge,
credentialCreationData: RegistrationCredential(
id: id,
id: id.asString(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth extracting this to it's own type instead of just a String?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're handling a lot of base64/base64url data and having some base64 "type safety" is super helpful.

@marius-se marius-se requested a review from 0xTim March 20, 2023 09:15
Copy link
Member

@0xTim 0xTim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@marius-se marius-se merged commit d92d409 into main Mar 22, 2023
@marius-se marius-se deleted the marius branch March 22, 2023 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

User is a very common name for a public symbol
2 participants