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

fix: 2FAS import #63

Merged
merged 1 commit into from
Aug 7, 2024
Merged
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
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 @@
"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 @@
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
Loading