-
Notifications
You must be signed in to change notification settings - Fork 29
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
Changes from all commits
1444fe3
aa0fed9
8d10736
fddc05e
3478bf6
8551399
fca7208
a9628d5
a885b8c
efee659
52b2141
8021e66
3dcf451
a2f2a45
0da2398
39a5934
f68f50d
acb4417
058e55b
47c7c8f
cc775cd
d3a4b1a
a4e6607
f749353
e2f4a9d
3160d60
603f3aa
ff58bbd
d4fa8c8
2f5c9be
e3e691f
1e5f67e
4f8f597
a1d0cf1
c7626a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,12 @@ | ||
disabled_rules: | ||
- comment_spacing | ||
- comment_spacing | ||
excluded: | ||
- .build | ||
- .build | ||
|
||
|
||
identifier_name: | ||
excluded: | ||
- id | ||
|
||
line_length: | ||
ignores_comments: true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the WebAuthn Swift open source project | ||
// | ||
// Copyright (c) 2022 the WebAuthn Swift project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of WebAuthn Swift project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
/// Options to specify the Relying Party's preference regarding attestation conveyance during credential generation. | ||
/// | ||
/// Currently only supports `none`. | ||
public enum AttestationConveyancePreference: String, Codable { | ||
/// Indicates the Relying Party is not interested in authenticator attestation. | ||
case none | ||
// case indirect | ||
// case direct | ||
// case enterprise | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,17 +12,24 @@ | |
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import Foundation | ||
import Crypto | ||
import SwiftCBOR | ||
|
||
/// Contains the cryptographic attestation that a new key pair was created by that authenticator. | ||
public struct AttestationObject: Equatable { | ||
public struct AttestationObject { | ||
let authenticatorData: AuthenticatorData | ||
let rawAuthenticatorData: [UInt8] | ||
let rawAuthenticatorData: Data | ||
let format: AttestationFormat | ||
let attestationStatement: CBOR | ||
|
||
func verify(relyingPartyID: String, verificationRequired: Bool, clientDataHash: SHA256.Digest) throws { | ||
func verify( | ||
relyingPartyID: String, | ||
verificationRequired: Bool, | ||
clientDataHash: SHA256.Digest, | ||
supportedPublicKeyAlgorithms: [PublicKeyCredentialParameters], | ||
pemRootCertificatesByFormat: [AttestationFormat: [Data]] = [:] | ||
) async throws -> AttestedCredentialData { | ||
let relyingPartyIDHash = SHA256.hash(data: relyingPartyID.data(using: .utf8)!) | ||
|
||
guard relyingPartyIDHash == authenticatorData.relyingPartyIDHash else { | ||
|
@@ -39,14 +46,44 @@ public struct AttestationObject: Equatable { | |
} | ||
} | ||
|
||
guard let attestedCredentialData = authenticatorData.attestedData else { | ||
throw WebAuthnError.attestedCredentialDataMissing | ||
} | ||
|
||
// Step 17. | ||
let credentialPublicKey = try CredentialPublicKey(publicKeyBytes: attestedCredentialData.publicKey) | ||
guard supportedPublicKeyAlgorithms.map(\.alg).contains(credentialPublicKey.key.algorithm) else { | ||
throw WebAuthnError.unsupportedCredentialPublicKeyAlgorithm | ||
} | ||
|
||
// let pemRootCertificates = pemRootCertificatesByFormat[format] ?? [] | ||
switch format { | ||
case .none: | ||
// if format is `none` statement must be empty | ||
guard attestationStatement == .map([:]) else { | ||
throw WebAuthnError.attestationStatementMustBeEmpty | ||
} | ||
// 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 | ||
// ) | ||
Comment on lines
+66
to
+82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove if not needed There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
default: | ||
throw WebAuthnError.attestationVerificationNotSupported | ||
} | ||
|
||
return attestedCredentialData | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.