Skip to content

Add support for generating Steam Guard codes#225

Open
bmwalters wants to merge 1 commit intomattrubin:developfrom
bmwalters:feature/steamguard
Open

Add support for generating Steam Guard codes#225
bmwalters wants to merge 1 commit intomattrubin:developfrom
bmwalters:feature/steamguard

Conversation

@bmwalters
Copy link
Copy Markdown

Fixes #211

Overview

  • Adds a new parameter to Generator named "Representation". This is an enum with two values: numeric and steamguard.
    • Steam Guard codes are 5 alphanumeric digits instead of base-10.
    • There is only one valid configuration of parameters to obtain a valid Steam Guard token generator: 30 second TOTP, sha1, 5 digits, steamguard representation.
      • To keep the interface more general, this is not enforced in the API contract (such as by adding a separate constructor init(steamGuardSecret:)). Instead, the user of the API is expected to pass the correct parameters.
  • Adds test for TOTP values and serialization.
  • Updates interface in a hopefully backwards compatible way.
  • Users are expected to figure out how to obtain their Steam Guard secret on their own.
  • Companion Authenticator PR

}
}

func testSteamGuardSerialization() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Function Body Length Violation: Function body should span 40 lines or less excluding comments and whitespace: currently spans 50 lines (function_body_length)

1590895162: "RFQNR",
]

let generator = Generator(factor: .timer(period: 30), secret: secret, algorithm: .sha1, digits: 5, representation: .steamguard)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Line Length Violation: Line should be 120 characters or less: currently 135 characters (line_length)

let secret = MF_Base32Codec.data(fromBase32String: "I6FMHELVR57Z2PCNB7D22MS6I2SRSQIB")!
let expectedValues: [TimeInterval: String] = [
1590895077: "Y4323",
1590895162: "RFQNR",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Trailing Comma Violation: Collection literals should not have trailing commas. (trailing_comma)


for (algorithm, expectedPasswords) in expectedValues {
let generator = Generator(factor: .timer(period: 30), secret: secret, algorithm: algorithm, digits: 6)
let generator = Generator(factor: .timer(period: 30), secret: secret, algorithm: algorithm, digits: 6, representation: .numeric)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Line Length Violation: Line should be 120 characters or less: currently 140 characters (line_length)

for (algorithm, secretKey) in secretKeys {
let secret = secretKey.data(using: String.Encoding.ascii)!
let generator = Generator(factor: .timer(period: 30), secret: secret, algorithm: algorithm, digits: 8)
let generator = Generator(factor: .timer(period: 30), secret: secret, algorithm: algorithm, digits: 8, representation: .numeric)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Line Length Violation: Line should be 120 characters or less: currently 140 characters (line_length)

Comment thread Sources/Token+URL.swift

let algorithm = try queryItems.value(for: kQueryAlgorithmKey).map(algorithmFromString) ?? defaultAlgorithm
let digits = try queryItems.value(for: kQueryDigitsKey).map(parseDigits) ?? defaultDigits
let representation = try queryItems.value(for: kQueryRepresentationKey).map(representationFromString) ?? defaultRepresentation
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Line Length Violation: Line should be 120 characters or less: currently 130 characters (line_length)

Comment thread Sources/Token+URL.swift
}
}

private func urlForToken(name: String, issuer: String, factor: Generator.Factor, algorithm: Generator.Algorithm, digits: Int, representation: Generator.Representation) throws -> URL {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Function Parameter Count Violation: Function should have 5 parameters or less: it currently has 6 (function_parameter_count)
Line Length Violation: Line should be 120 characters or less: currently 183 characters (line_length)

Comment thread Sources/Generator.swift
// same initializer signature with both throwing an failable versions, this new initializer is currently prefixed
// with an underscore and marked as internal.
internal init(_factor factor: Factor, secret: Data, algorithm: Algorithm, digits: Int) throws {
internal init(_factor factor: Factor, secret: Data, algorithm: Algorithm, digits: Int, representation: Representation) throws {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Line Length Violation: Line should be 120 characters or less: currently 131 characters (line_length)

Comment thread Sources/Generator.swift
public init?(factor: Factor, secret: Data, algorithm: Algorithm, digits: Int) {
try? self.init(_factor: factor, secret: secret, algorithm: algorithm, digits: digits)
public init?(factor: Factor, secret: Data, algorithm: Algorithm, digits: Int, representation: Representation = .numeric) {
try? self.init(_factor: factor, secret: secret, algorithm: algorithm, digits: digits, representation: representation)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Line Length Violation: Line should be 120 characters or less: currently 125 characters (line_length)

Comment thread Sources/Generator.swift
/// are invalid.
public init?(factor: Factor, secret: Data, algorithm: Algorithm, digits: Int) {
try? self.init(_factor: factor, secret: secret, algorithm: algorithm, digits: digits)
public init?(factor: Factor, secret: Data, algorithm: Algorithm, digits: Int, representation: Representation = .numeric) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Line Length Violation: Line should be 120 characters or less: currently 126 characters (line_length)

@codecov
Copy link
Copy Markdown

codecov Bot commented May 31, 2020

Codecov Report

❌ Patch coverage is 96.72131% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.95%. Comparing base (7af91b9) to head (d00dd01).
⚠️ Report is 162 commits behind head on develop.

Files with missing lines Patch % Lines
Sources/Token+URL.swift 90.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #225      +/-   ##
===========================================
- Coverage    97.38%   96.95%   -0.43%     
===========================================
  Files            6        6              
  Lines          420      427       +7     
===========================================
+ Hits           409      414       +5     
- Misses          11       13       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Can you support steam totp?

1 participant