Skip to content

Commit ff8e863

Browse files
authored
Merge pull request #47 from dimitribouniol/dimitry/relying-party-spelling
Relying Party Spelling
2 parents 956ea25 + 5d0efcb commit ff8e863

8 files changed

+30
-27
lines changed

Sources/WebAuthn/Ceremonies/Authentication/AuthenticatorAssertionResponse.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ struct ParsedAuthenticatorAssertionResponse {
102102
relyingPartyOrigin: relyingPartyOrigin
103103
)
104104

105-
guard let expectedRpIDData = relyingPartyID.data(using: .utf8) else {
105+
guard let expectedRelyingPartyIDData = relyingPartyID.data(using: .utf8) else {
106106
throw WebAuthnError.invalidRelyingPartyID
107107
}
108-
let expectedRpIDHash = SHA256.hash(data: expectedRpIDData)
109-
guard expectedRpIDHash == authenticatorData.relyingPartyIDHash else {
108+
let expectedRelyingPartyIDHash = SHA256.hash(data: expectedRelyingPartyIDData)
109+
guard expectedRelyingPartyIDHash == authenticatorData.relyingPartyIDHash else {
110110
throw WebAuthnError.relyingPartyIDHashDoesNotMatch
111111
}
112112

Sources/WebAuthn/Ceremonies/Authentication/PublicKeyCredentialRequestOptions.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ public struct PublicKeyCredentialRequestOptions: Encodable {
3232
/// See https://www.w3.org/TR/webauthn-2/#dictionary-assertion-options
3333
public let timeout: Duration?
3434

35-
/// The Relying Party ID.
36-
public let rpId: String?
35+
/// The ID of the Relying Party making the request.
36+
///
37+
/// This is configured on ``WebAuthnManager`` before its ``WebAuthnManager/beginAuthentication(timeout:allowCredentials:userVerification:)`` method is called.
38+
/// - Note: When encoded, this field appears as `rpId` to match the expectations of `navigator.credentials.get()`.
39+
public let relyingPartyID: String?
3740

3841
/// Optionally used by the client to find authenticators eligible for this authentication ceremony.
3942
public let allowCredentials: [PublicKeyCredentialDescriptor]?
@@ -48,15 +51,15 @@ public struct PublicKeyCredentialRequestOptions: Encodable {
4851

4952
try container.encode(challenge.base64URLEncodedString(), forKey: .challenge)
5053
try container.encodeIfPresent(timeout?.milliseconds, forKey: .timeout)
51-
try container.encodeIfPresent(rpId, forKey: .rpId)
54+
try container.encodeIfPresent(relyingPartyID, forKey: .rpID)
5255
try container.encodeIfPresent(allowCredentials, forKey: .allowCredentials)
5356
try container.encodeIfPresent(userVerification, forKey: .userVerification)
5457
}
5558

5659
private enum CodingKeys: String, CodingKey {
5760
case challenge
5861
case timeout
59-
case rpId
62+
case rpID = "rpId"
6063
case allowCredentials
6164
case userVerification
6265
}

Sources/WebAuthn/Ceremonies/Registration/PublicKeyCredentialCreationOptions.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public struct PublicKeyCredentialCreationOptions: Encodable {
3232
public let user: PublicKeyCredentialUserEntity
3333

3434
/// Contains a name and an identifier for the Relying Party responsible for the request
35-
public let relyingParty: PublicKeyCredentialRpEntity
35+
public let relyingParty: PublicKeyCredentialRelyingPartyEntity
3636

3737
/// A list of key types and signature algorithms the Relying Party supports. Ordered from most preferred to least
3838
/// preferred.
@@ -102,9 +102,9 @@ extension Array where Element == PublicKeyCredentialParameters {
102102
// MARK: - Credential entities
103103

104104
/// From §5.4.2 (https://www.w3.org/TR/webauthn/#sctn-rp-credential-params).
105-
/// The PublicKeyCredentialRpEntity dictionary is used to supply additional Relying Party attributes when
105+
/// The PublicKeyCredentialRelyingPartyEntity dictionary is used to supply additional Relying Party attributes when
106106
/// creating a new credential.
107-
public struct PublicKeyCredentialRpEntity: Encodable {
107+
public struct PublicKeyCredentialRelyingPartyEntity: Encodable {
108108
/// A unique identifier for the Relying Party entity.
109109
public let id: String
110110

Sources/WebAuthn/WebAuthnManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public struct WebAuthnManager {
143143
return PublicKeyCredentialRequestOptions(
144144
challenge: challenge,
145145
timeout: timeout,
146-
rpId: configuration.relyingPartyID,
146+
relyingPartyID: configuration.relyingPartyID,
147147
allowCredentials: allowCredentials,
148148
userVerification: userVerification
149149
)

Tests/WebAuthnTests/Utils/TestModels/TestAuthData.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ import Crypto
1717
import WebAuthn
1818

1919
struct TestAuthData {
20-
var rpIDHash: [UInt8]?
20+
var relyingPartyIDHash: [UInt8]?
2121
var flags: UInt8?
2222
var counter: [UInt8]?
2323
var attestedCredData: [UInt8]?
2424
var extensions: [UInt8]?
2525

2626
var byteArrayRepresentation: [UInt8] {
2727
var value: [UInt8] = []
28-
if let rpIDHash {
29-
value += rpIDHash
28+
if let relyingPartyIDHash {
29+
value += relyingPartyIDHash
3030
}
3131
if let flags {
3232
value += [flags]
@@ -61,7 +61,7 @@ struct TestAuthDataBuilder {
6161

6262
func validMock() -> Self {
6363
self
64-
.rpIDHash(fromRpID: "example.com")
64+
.relyingPartyIDHash(fromRelyingPartyID: "example.com")
6565
.flags(0b11000101)
6666
.counter([0b00000000, 0b00000000, 0b00000000, 0b00000000])
6767
.attestedCredData(
@@ -75,23 +75,23 @@ struct TestAuthDataBuilder {
7575

7676
/// Creates a valid authData
7777
///
78-
/// rpID = "example.com", user
78+
/// relyingPartyID = "example.com", user
7979
/// flags "extension data included", "user verified" and "user present" are set
8080
/// sign count is set to 0
8181
/// random extension data is included
8282
func validAuthenticationMock() -> Self {
8383
self
84-
.rpIDHash(fromRpID: "example.com")
84+
.relyingPartyIDHash(fromRelyingPartyID: "example.com")
8585
.flags(0b10000101)
8686
.counter([0b00000000, 0b00000000, 0b00000000, 0b00000000])
8787
.extensions([UInt8](repeating: 0, count: 20))
8888
}
8989

90-
func rpIDHash(fromRpID rpID: String) -> Self {
91-
let rpIDData = rpID.data(using: .utf8)!
92-
let rpIDHash = SHA256.hash(data: rpIDData)
90+
func relyingPartyIDHash(fromRelyingPartyID relyingPartyID: String) -> Self {
91+
let relyingPartyIDData = relyingPartyID.data(using: .utf8)!
92+
let relyingPartyIDHash = SHA256.hash(data: relyingPartyIDData)
9393
var temp = self
94-
temp.wrapped.rpIDHash = [UInt8](rpIDHash)
94+
temp.wrapped.relyingPartyIDHash = [UInt8](relyingPartyIDHash)
9595
return temp
9696
}
9797

@@ -148,7 +148,7 @@ struct TestAuthDataBuilder {
148148
extension TestAuthData {
149149
static var valid: Self {
150150
TestAuthData(
151-
rpIDHash: [1],
151+
relyingPartyIDHash: [1],
152152
flags: 1,
153153
counter: [1],
154154
attestedCredData: [2],

Tests/WebAuthnTests/WebAuthnManagerAuthenticationTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ final class WebAuthnManagerAuthenticationTests: XCTestCase {
4444

4545
XCTAssertEqual(options.challenge, challenge)
4646
XCTAssertEqual(options.timeout, .seconds(1234))
47-
XCTAssertEqual(options.rpId, relyingPartyID)
47+
XCTAssertEqual(options.relyingPartyID, relyingPartyID)
4848
XCTAssertEqual(options.allowCredentials, allowCredentials)
4949
XCTAssertEqual(options.userVerification, .preferred)
5050
}
@@ -76,7 +76,7 @@ final class WebAuthnManagerAuthenticationTests: XCTestCase {
7676
finishAuthentication(
7777
authenticatorData: TestAuthDataBuilder()
7878
.validAuthenticationMock()
79-
.rpIDHash(fromRpID: "wrong-id.org")
79+
.relyingPartyIDHash(fromRelyingPartyID: "wrong-id.org")
8080
.build()
8181
.byteArrayRepresentation
8282
),

Tests/WebAuthnTests/WebAuthnManagerIntegrationTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ final class WebAuthnManagerIntegrationTests: XCTestCase {
106106
userVerification: userVerification
107107
)
108108

109-
XCTAssertEqual(authenticationOptions.rpId, configuration.relyingPartyID)
109+
XCTAssertEqual(authenticationOptions.relyingPartyID, configuration.relyingPartyID)
110110
XCTAssertEqual(authenticationOptions.timeout, authenticationTimeout)
111111
XCTAssertEqual(authenticationOptions.challenge, mockChallenge)
112112
XCTAssertEqual(authenticationOptions.userVerification, userVerification)
@@ -115,7 +115,7 @@ final class WebAuthnManagerIntegrationTests: XCTestCase {
115115
// Now send `authenticationOptions` to client, which in turn will send the authenticator's response back to us:
116116
// The following lines reflect what an authenticator normally produces
117117
let authenticatorData = TestAuthDataBuilder().validAuthenticationMock()
118-
.rpIDHash(fromRpID: configuration.relyingPartyID)
118+
.relyingPartyIDHash(fromRelyingPartyID: configuration.relyingPartyID)
119119
.counter([0, 0, 0, 1]) // we authenticated once now, so authenticator likely increments the sign counter
120120
.build()
121121
.byteArrayRepresentation

Tests/WebAuthnTests/WebAuthnManagerRegistrationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ final class WebAuthnManagerRegistrationTests: XCTestCase {
235235
await finishRegistration(
236236
attestationObject: TestAttestationObjectBuilder()
237237
.validMock()
238-
.authData(TestAuthDataBuilder().validMock().rpIDHash(fromRpID: "invalid-id.com"))
238+
.authData(TestAuthDataBuilder().validMock().relyingPartyIDHash(fromRelyingPartyID: "invalid-id.com"))
239239
.build()
240240
.cborEncoded
241241
),

0 commit comments

Comments
 (0)