Fix a bug about TOTP refresh
This commit is contained in:
parent
af1ea3ee3e
commit
3cf88dcbc8
2 changed files with 26 additions and 10 deletions
|
|
@ -170,20 +170,16 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch token.generator.factor {
|
switch token.generator.factor {
|
||||||
case .counter:
|
case .timer:
|
||||||
// htop
|
|
||||||
break
|
|
||||||
case .timer(let period):
|
|
||||||
// totp
|
// totp
|
||||||
let timeSinceEpoch = Date().timeIntervalSince1970
|
if let (title, otp) = strongSelf.password?.getOtpStrings() {
|
||||||
let validTime = Int(period - timeSinceEpoch.truncatingRemainder(dividingBy: period))
|
strongSelf.tableData[indexPath.section].item[indexPath.row].title = title
|
||||||
strongSelf.tableData[indexPath.section].item[indexPath.row].title = "time-based (expiring in \(validTime)s)"
|
|
||||||
cell.cellData?.title = "time-based (valid within \(validTime)s)"
|
|
||||||
if validTime <= 1 || validTime >= Int(period - 1) {
|
|
||||||
let otp = token.currentPassword ?? "error"
|
|
||||||
strongSelf.tableData[indexPath.section].item[indexPath.row].content = otp
|
strongSelf.tableData[indexPath.section].item[indexPath.row].content = otp
|
||||||
|
cell.cellData?.title = title
|
||||||
cell.cellData?.content = otp
|
cell.cellData?.content = otp
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -239,4 +239,24 @@ class Password {
|
||||||
}
|
}
|
||||||
self.updatePassword(name: self.name, plainText: lines.joined(separator: "\n"))
|
self.updatePassword(name: self.name, plainText: lines.joined(separator: "\n"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// return the description and the password strings
|
||||||
|
func getOtpStrings() -> (description: String, otp: String)? {
|
||||||
|
guard let token = self.otpToken else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
var description : String
|
||||||
|
switch token.generator.factor {
|
||||||
|
case .counter:
|
||||||
|
// htop
|
||||||
|
description = "HMAC-based"
|
||||||
|
case .timer(let period):
|
||||||
|
// totp
|
||||||
|
let timeSinceEpoch = Date().timeIntervalSince1970
|
||||||
|
let validTime = Int(period - timeSinceEpoch.truncatingRemainder(dividingBy: period))
|
||||||
|
description = "time-based (expiring in \(validTime)s)"
|
||||||
|
}
|
||||||
|
let otp = self.otpToken?.currentPassword ?? "error"
|
||||||
|
return (description, otp)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue