Skip to content

Commit 1fcae32

Browse files
[PM-10080] Don't constrain OTP auth codes to base-32 secrets (#784)
1 parent 926c990 commit 1fcae32

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

BitwardenShared/Core/Vault/Services/TOTP/OTPAuthModel.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ public struct OTPAuthModel: Equatable, Hashable, Sendable {
6666
guard let urlComponents = URLComponents(string: otpAuthKey),
6767
urlComponents.scheme == "otpauth",
6868
let queryItems = urlComponents.queryItems,
69-
let secret = queryItems.first(where: { $0.name == "secret" })?.value,
70-
secret.uppercased().isBase32 else {
69+
let secret = queryItems.first(where: { $0.name == "secret" })?.value else {
7170
return nil
7271
}
7372

BitwardenShared/Core/Vault/Services/TOTP/OTPAuthModelTests.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,23 @@ class OTPAuthModelTests: BitwardenTestCase {
8585
)
8686
}
8787

88+
/// Tests that an OTP Auth string with a non-base32 key creates a model.
89+
func test_init_otpAuthKey_success_nonbase32() {
90+
let subject = OTPAuthModel(otpAuthKey: .otpAuthUriKeyNonBase32)
91+
XCTAssertEqual(
92+
subject,
93+
OTPAuthModel(
94+
accountName: nil,
95+
algorithm: .sha1,
96+
digits: 6,
97+
issuer: nil,
98+
key: "1234567890",
99+
period: 30,
100+
uri: .otpAuthUriKeyNonBase32
101+
)
102+
)
103+
}
104+
88105
/// Tests that a partially formatted OTP Auth string creates the model.
89106
func test_init_otpAuthKey_success_partial() {
90107
let subject = OTPAuthModel(otpAuthKey: .otpAuthUriKeyPartial)

BitwardenShared/UI/Vault/PreviewContent/String+TOTPFixtures.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ extension String {
55
// swiftlint:disable:next line_length
66
static let otpAuthUriKeyComplete = "otpauth://totp/Example:[email protected]?secret=JBSWY3DPEHPK3PXP&issuer=Example&algorithm=SHA256&digits=6&period=30"
77
static let otpAuthUriKeyMinimum = "otpauth://totp/:?secret=JBSWY3DPEHPK3PXP"
8+
static let otpAuthUriKeyNonBase32 = "otpauth://totp/:?secret=1234567890"
89
static let otpAuthUriKeyPartial = "otpauth://totp/Example:[email protected]?secret=JBSWY3DPEHPK3PXP"
910
// swiftlint:disable:next line_length
1011
static let otpAuthUriKeySHA512 = "otpauth://totp/Example:[email protected]?secret=JBSWY3DPEHPK3PXP&algorithm=SHA512"

0 commit comments

Comments
 (0)