Skip to content
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

Implement Steam Guard code generation #336

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "Carthage/Checkouts/OneTimePassword"]
path = Carthage/Checkouts/OneTimePassword
url = https://github.com/mattrubin/OneTimePassword.git
url = https://github.com/bmwalters/OneTimePassword.git
[submodule "Carthage/Checkouts/xcconfigs"]
path = Carthage/Checkouts/xcconfigs
url = https://github.com/jspahrsummers/xcconfigs.git
Expand Down
21 changes: 19 additions & 2 deletions Authenticator/Source/TokenEntryForm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import Base32

private let defaultTimerFactor = Generator.Factor.timer(period: 30)
private let defaultCounterFactor = Generator.Factor.counter(0)
private let steamguardFactor = Generator.Factor.timer(period: 30)

struct TokenEntryForm: Component {
private var issuer: String = ""
Expand Down Expand Up @@ -91,9 +92,10 @@ extension TokenEntryForm {
rows: !showsAdvancedOptions ? [] :
[
tokenTypeRowModel,
] + (tokenType == .steamguard ? [] : [
digitCountRowModel,
algorithmRowModel,
]
])
),
],
doneKeyAction: .submit
Expand Down Expand Up @@ -190,8 +192,16 @@ extension TokenEntryForm {
self.name = name
case let .secret(secret):
self.secret = secret
case .tokenType(.steamguard):
self.tokenType = .steamguard
// All Steam Guard tokens use the following settings.
self.algorithm = .sha1
self.digitCount = 5
case let .tokenType(tokenType):
self.tokenType = tokenType
// The digit count may have been lowered by
// switching to Steam Guard, so clamp it.
self.digitCount = max(self.digitCount, 6)
case let .digitCount(digitCount):
self.digitCount = digitCount
case let .algorithm(algorithm):
Expand All @@ -217,18 +227,25 @@ extension TokenEntryForm {
}

let factor: Generator.Factor
let representation: Generator.Representation
switch tokenType {
case .counter:
factor = defaultCounterFactor
representation = .numeric
case .timer:
factor = defaultTimerFactor
representation = .numeric
case .steamguard:
factor = steamguardFactor
representation = .steamguard
}

guard let generator = Generator(
factor: factor,
secret: secretData,
algorithm: algorithm,
digits: digitCount
digits: digitCount,
representation: representation
) else {
// This UI doesn't allow the user to create an invalid period or digit count,
// so a generic error message is acceptable here.
Expand Down
3 changes: 2 additions & 1 deletion Authenticator/Source/TokenFormModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ enum TokenFormRowModel<Action>: Identifiable {
}

enum TokenType {
case counter, timer
case counter, timer, steamguard
}

extension TextFieldRowViewModel {
Expand Down Expand Up @@ -96,6 +96,7 @@ extension SegmentedControlRowViewModel {
let options = [
(title: "Time Based", value: TokenType.timer),
(title: "Counter Based", value: TokenType.counter),
(title: "Steam Guard", value: TokenType.steamguard),
]
self.init(options: options, value: value, changeAction: changeAction)
}
Expand Down
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Configuration for Carthage (https://github.com/Carthage/Carthage)

github "mattrubin/OneTimePassword" ~> 3.1.4
github "bmwalters/OneTimePassword" "feature/steamguard"
github "SVProgressHUD/SVProgressHUD" ~> 2.0
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github "SVProgressHUD/SVProgressHUD" "2.2.5"
github "bmwalters/OneTimePassword" "d00dd01e81d89d0dafd4770e4d50141733007584"
github "jspahrsummers/xcconfigs" "1.0"
github "mattrubin/Base32" "1.1.2+xcode10.2"
github "mattrubin/OneTimePassword" "3.1.5"
github "shinydevelopment/SimulatorStatusMagic" "2.4.1"
2 changes: 1 addition & 1 deletion Carthage/Checkouts/OneTimePassword
Submodule OneTimePassword updated 39 files
+0 −1 .swift-version
+11 −2 .swiftlint.yml
+35 −33 .travis.yml
+16 −0 CHANGELOG.md
+1 −1 Cartfile.private
+1 −1 Cartfile.resolved
+1 −1 Carthage/Checkouts/xcconfigs
+0 −5 CommonCrypto/README.md
+0 −4 CommonCrypto/appletvos/module.modulemap
+0 −4 CommonCrypto/appletvsimulator/module.modulemap
+0 −62 CommonCrypto/injectXcodePath.sh
+0 −4 CommonCrypto/iphoneos/module.modulemap
+0 −4 CommonCrypto/iphonesimulator/module.modulemap
+0 −4 CommonCrypto/macosx/module.modulemap
+0 −4 CommonCrypto/watchos/module.modulemap
+0 −4 CommonCrypto/watchsimulator/module.modulemap
+0 −8 Configuration/OneTimePassword.xcconfig
+1 −1 LICENSE.md
+2 −18 OneTimePassword.podspec
+70 −103 OneTimePassword.xcodeproj/project.pbxproj
+14 −0 OneTimePassword.xcodeproj/xcshareddata/xcschemes/OneTimePassword (iOS).xcscheme
+14 −0 OneTimePassword.xcodeproj/xcshareddata/xcschemes/OneTimePassword (watchOS).xcscheme
+1 −1 OneTimePasswordLegacyTests/OTPToken.swift
+4 −2 OneTimePasswordLegacyTests/OTPTokenSerializationTests.m
+1 −3 OneTimePasswordLegacyTests/OTPTypeStrings.m
+10 −8 README.md
+58 −12 Sources/Crypto.swift
+74 −44 Sources/Generator.swift
+2 −2 Sources/Info.plist
+2 −2 Sources/Keychain.swift
+0 −24 Sources/OneTimePassword.h
+4 −13 Sources/PersistentToken.swift
+33 −4 Sources/Token+URL.swift
+1 −11 Sources/Token.swift
+33 −33 Tests/EquatableTests.swift
+52 −29 Tests/GeneratorTests.swift
+1 −1 Tests/KeychainTests.swift
+94 −2 Tests/TokenSerializationTests.swift
+20 −20 Tests/TokenTests.swift