-
Notifications
You must be signed in to change notification settings - Fork 250
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
Check for clock skew on login #1236
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
// @flow | ||
|
||
import { createSimpleConfirmModal, showModal } from 'edge-components' | ||
import type { EdgeAccount } from 'edge-core-js' | ||
import React from 'react' | ||
import { Platform } from 'react-native' | ||
import Locale from 'react-native-locale' | ||
import PushNotification from 'react-native-push-notification' | ||
|
@@ -29,6 +31,7 @@ import { | |
import * as CORE_SELECTORS from '../Core/selectors' | ||
import { updateWalletsRequest } from '../Core/Wallets/action.js' | ||
import type { Dispatch, GetState } from '../ReduxTypes' | ||
import { Icon } from '../UI/components/Icon/Icon.ui.js' | ||
|
||
const localeInfo = Locale.constants() // should likely be moved to login system and inserted into Redux | ||
|
||
|
@@ -180,6 +183,30 @@ export const initializeAccount = (account: EdgeAccount, touchIdInfo: Object) => | |
accountInitObject.pinMode = coreFinal.pinMode | ||
accountInitObject.otpMode = coreFinal.otpMode | ||
|
||
// Check clock skew against atomic time | ||
try { | ||
const remoteTime = await fetch('http://worldtimeapi.org/api/timezone/Etc/GMT') | ||
const body = await remoteTime.json() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not put a blocking network call in initAccount as this can slow down login times for users. This should run in the background and throw a modal once complete. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, we should probably have this at app startup time instead of initAccount as the user might not be able to login at all. This would entail moving almost the entire PR to the edge-login-ui repo which is a good idea so SDK partners get it as well. |
||
const remoteSecondsSinceEpoch = body.unixtime | ||
|
||
const localSecondsSinceEpoch = Date.now() / 1000 | ||
|
||
const clockSkew = Math.abs(localSecondsSinceEpoch - remoteSecondsSinceEpoch) | ||
|
||
if (clockSkew > 30) { | ||
const modal = createSimpleConfirmModal({ | ||
title: s.strings.clock_skew_modal_title, | ||
message: s.strings.clock_skew_modal_message, | ||
icon: <Icon type={Constants.FONT_AWESOME} name={Constants.CLOCK} size={35} />, | ||
buttonText: s.strings.string_ok | ||
}) | ||
|
||
showModal(modal) | ||
} | ||
} catch (e) { | ||
console.log('Time check error: ', e) | ||
} | ||
|
||
dispatch({ | ||
type: 'ACCOUNT_INIT_COMPLETE', | ||
data: { ...accountInitObject } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe this will work in production apps as Apple is strict about https