Skip to content

Commit

Permalink
Use SHA1 algorithm for Remote OTP QR due to Authy's lack of support f…
Browse files Browse the repository at this point in the history
…or others.
  • Loading branch information
gestrich committed Apr 16, 2022
1 parent 4edd730 commit ddeb09f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions NightscoutServiceKit/OTPManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public class OTPManager {

private var secretStore: OTPSecretStore
private var nowDateSource: () -> Date
let algorithm: Generator.Algorithm = .sha512
let algorithm: Generator.Algorithm = .sha1
let issuerName = "Loop"
var tokenPeriod: TimeInterval
var passwordDigitCount = 6
public static var defaultTokenPeriod: TimeInterval = 30
Expand Down Expand Up @@ -143,7 +144,7 @@ public class OTPManager {
}

let generator = Generator(factor: .timer(period: TimeInterval(self.tokenPeriod)), secret: secretKeyData, algorithm: algorithm, digits: passwordDigitCount)!
return Token(name: "\(secretKeyName)", issuer: "Loop", generator: generator)
return Token(name: secretKeyName, issuer: issuerName, generator: generator)
}

public func getLastPasswordsAscending(count: Int) -> [String] {
Expand Down Expand Up @@ -179,16 +180,18 @@ public class OTPManager {
guard let secretKey = secretStore.tokenSecretKey(), let tokenName = secretStore.tokenSecretKeyName() else {
return nil
}

//otpauth://totp/blah:1630787634876?secret=V45JRIB4TC37FUACFN2YZFKC54EIV7C2&issuer=Loop&algorithm=SHA1&digits=6&period=30
let queryItems = [
URLQueryItem(name: "algorithm", value: algorithm.otpURLStringComponent()),
URLQueryItem(name: "digits", value: "\(passwordDigitCount)"),
URLQueryItem(name: "issuer", value: "Loop"),
URLQueryItem(name: "issuer", value: issuerName),
URLQueryItem(name: "period", value: "\(Int(tokenPeriod))"),
URLQueryItem(name: "secret", value: secretKey),
]

//otpauth://totp/Loop:1630787634876?secret=V45JRIB4TC37FUACFN2YZFK\C54EIV7C2&issuer=Loop&algorithm=SHA1&digits=6&period=30
//otpauth://totp/Loop:1630787634876?secret=V45JRIB4TC37FUACFN2YZFKC54EIV7C2&issuer=Loop&algorithm=SHA1&digits=6&period=30
let components = URLComponents(scheme: "otpauth", host: "totp", path: "/" + tokenName, queryItems: queryItems)
print(components.url?.absoluteString)
return components.url?.absoluteString
}

Expand Down

0 comments on commit ddeb09f

Please sign in to comment.