Skip to content

Commit

Permalink
Updated 2FAS import (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldavidw authored Aug 7, 2024
1 parent 98479f1 commit 2cefd05
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
7 changes: 3 additions & 4 deletions Chronos/Services/Import/ImportService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ImportService {
case .CHRONOS:
return importFromChronos(json: inputJson)
case .TWOFAS:
return importFrom2FAS(json: inputJson)
return importFromTwoFAS(json: inputJson)
case .AEGIS:
return importFromAegis(json: inputJson)
case .RAIVO:
Expand Down Expand Up @@ -100,12 +100,11 @@ extension ImportService {
}
}

func importFrom2FAS(json: JSON) -> [Token]? {
func importFromTwoFAS(json: JSON) -> [Token]? {
var tokens: [Token] = []

for (key, subJson) in json["services"] {
guard
let issuer = subJson["otp"]["issuer"].string,
let account = subJson["otp"]["account"].string,
let secret = subJson["secret"].string,
let digits = subJson["otp"]["digits"].int,
Expand All @@ -121,7 +120,7 @@ extension ImportService {
}

let token = Token()
token.issuer = issuer
token.issuer = subJson["otp"]["issuer"].string ?? ""
token.account = account
token.secret = secret
token.digits = digits
Expand Down
36 changes: 36 additions & 0 deletions ChronosTests/Import/2FAS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,34 @@ final class TwoFASTests: XCTestCase {
"serviceTypeID": "3cb83fc3-8e25-4df5-bdde-1f35611c1d0a",
"updatedAt": 1_721_919_046_000,
],
[
"icon": [
"iconCollection": [
"id": "A5B3FB65-4EC5-43E6-8EC1-49E24CA9E7AD",
],
"label": [
"backgroundColor": "Green",
"text": "UN",
],
"selected": "Label",
],
"name": "Unknown",
"order": [
"position": 7,
],
"otp": [
"account": "[email protected]",
"algorithm": "SHA1",
"counter": 22,
"digits": 6,
"period": 0,
"source": "manual",
"tokenType": "HOTP",
],
"secret": "KQOZTMLOJBSMYWIO4BG4UTXDSR",
"serviceTypeID": "3cb83fc3-8e25-4df5-bdde-1f35611c1d0a",
"updatedAt": 1_721_919_046_000,
],
],
]

Expand Down Expand Up @@ -315,6 +343,14 @@ final class TwoFASTests: XCTestCase {
XCTAssertEqual(tokens[7].account, "")
XCTAssertEqual(tokens[7].counter, 22)
XCTAssertEqual(tokens[7].secret, "KQOZTMLOJBSMYWIO4BG4UTXDSR")

Check warning on line 346 in ChronosTests/Import/2FAS.swift

View workflow job for this annotation

GitHub Actions / Lint

Remove trailing space at end of a line. (trailingSpace)
XCTAssertEqual(tokens[8].digits, 6)
XCTAssertEqual(tokens[8].type, TokenTypeEnum.HOTP)
XCTAssertEqual(tokens[8].algorithm, TokenAlgorithmEnum.SHA1)
XCTAssertEqual(tokens[8].issuer, "")
XCTAssertEqual(tokens[8].account, "[email protected]")
XCTAssertEqual(tokens[8].counter, 22)
XCTAssertEqual(tokens[8].secret, "BB6B7FAYHW2G42ZA4FJHLRWWHU")
}

func testValidImport_Period() throws {
Expand Down

0 comments on commit 2cefd05

Please sign in to comment.