mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-12-24 02:33:44 +03:00
Merge PR #120.
This commit is contained in:
commit
1c9d585b27
@ -247,7 +247,7 @@ class OathManager(
|
||||
val code =
|
||||
if (credentialData.oathType == OathType.TOTP && !requireTouch) {
|
||||
// recalculate the code
|
||||
calculateCode(session, credential, System.currentTimeMillis())
|
||||
calculateCode(session, credential)
|
||||
} else null
|
||||
|
||||
val addedCred = _model.add(
|
||||
@ -348,7 +348,7 @@ class OathManager(
|
||||
val code = _model.updateCode(
|
||||
session.deviceId,
|
||||
credential.model(session.deviceId),
|
||||
calculateCode(session, credential, System.currentTimeMillis()).model()
|
||||
calculateCode(session, credential).model()
|
||||
)
|
||||
|
||||
if (code != null) {
|
||||
@ -371,20 +371,21 @@ class OathManager(
|
||||
* Returns Steam code or standard TOTP code based on the credential.
|
||||
* @param session OathSession which calculates the TOTP code
|
||||
* @param credential
|
||||
* @param timestamp time for TOTP calculation
|
||||
*
|
||||
* @return calculated Code
|
||||
*/
|
||||
private fun calculateCode(
|
||||
session: OathSession,
|
||||
credential: Credential,
|
||||
timestamp: Long
|
||||
) =
|
||||
if (credential.isSteamCredential()) {
|
||||
credential: Credential
|
||||
): Code {
|
||||
// Manual calculate, need to pad timer to avoid immediate expiration
|
||||
val timestamp = System.currentTimeMillis() + 10000
|
||||
return if (credential.isSteamCredential()) {
|
||||
session.calculateSteamCode(credential, timestamp)
|
||||
} else {
|
||||
session.calculateCode(credential, timestamp)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun sendDeviceInfo(device: YubiKeyDevice) {
|
||||
|
||||
@ -490,11 +491,15 @@ class OathManager(
|
||||
}
|
||||
|
||||
private fun calculateOathCodes(session: OathSession): Map<Credential, Code> {
|
||||
val timeStamp = System.currentTimeMillis()
|
||||
return session.calculateCodes(timeStamp).map { (credential, code) ->
|
||||
var timestamp = System.currentTimeMillis()
|
||||
if (!_isUsbKey) {
|
||||
// NFC, need to pad timer to avoid immediate expiration
|
||||
timestamp += 10000
|
||||
}
|
||||
return session.calculateCodes(timestamp).map { (credential, code) ->
|
||||
Pair(
|
||||
credential, if (credential.isSteamCredential()) {
|
||||
session.calculateSteamCode(credential, timeStamp)
|
||||
credential, if (credential.isSteamCredential() && !credential.isTouchRequired) {
|
||||
session.calculateSteamCode(credential, timestamp)
|
||||
} else {
|
||||
code
|
||||
}
|
||||
|
@ -240,6 +240,11 @@ class _DesktopCredentialListNotifier extends OathCredentialListNotifier {
|
||||
@override
|
||||
Future<OathCode> calculate(OathCredential credential,
|
||||
{bool update = true}) async {
|
||||
var now = DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||
if (update) {
|
||||
// Manually triggered, need to pad timer to avoid immediate expiration
|
||||
now += 10;
|
||||
}
|
||||
final OathCode code;
|
||||
final signaler = Signaler();
|
||||
UserInteractionController? controller;
|
||||
@ -256,7 +261,7 @@ class _DesktopCredentialListNotifier extends OathCredentialListNotifier {
|
||||
}
|
||||
});
|
||||
if (credential.isSteam) {
|
||||
final timeStep = DateTime.now().millisecondsSinceEpoch ~/ 30000;
|
||||
final timeStep = now ~/ 30;
|
||||
var result = await _session.command('calculate',
|
||||
target: ['accounts', credential.id],
|
||||
params: {
|
||||
@ -266,8 +271,12 @@ class _DesktopCredentialListNotifier extends OathCredentialListNotifier {
|
||||
code = OathCode(_formatSteam(result['response']), timeStep * 30,
|
||||
(timeStep + 1) * 30);
|
||||
} else {
|
||||
var result = await _session.command('code',
|
||||
target: ['accounts', credential.id], signal: signaler);
|
||||
var result = await _session.command(
|
||||
'code',
|
||||
target: ['accounts', credential.id],
|
||||
params: {'timestamp': now},
|
||||
signal: signaler,
|
||||
);
|
||||
code = OathCode.fromJson(result);
|
||||
}
|
||||
_log.debug('Calculate', jsonEncode(code));
|
||||
|
Loading…
Reference in New Issue
Block a user