Skip to content

Commit f2632cf

Browse files
committed
security reinforcement
1 parent c46ad68 commit f2632cf

File tree

17 files changed

+169
-107
lines changed

17 files changed

+169
-107
lines changed

config.example.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ export const cointypes = {
77
decimals:9
88
}
99
/**
10-
* 锁定时间,默认10分钟
10+
* 锁定时间,默认24小时
1111
*/
12-
export const LOCK_TIME = 120 * 60 * 1000
12+
export const LOCK_TIME = 24 * 60
1313

1414
/**
1515
* 系统版本

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "auro-wallet",
3-
"version": "0.1.0",
3+
"version": "1.0.5",
44
"private": true,
55
"dependencies": {
66
"@babel/plugin-proposal-class-properties": "7.12.1",
@@ -47,7 +47,8 @@
4747
"redux": "4.0.5",
4848
"safe-buffer": "5.2.1",
4949
"valid-url": "1.0.9",
50-
"webpack": "4.44.2"
50+
"webpack": "4.44.2",
51+
"react-idle-timer": "4.2.5"
5152
},
5253
"scripts": {
5354
"build": "webpack --mode production",

public/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"short_name": "__MSG_appName__",
44
"description": "__MSG_appDescription__",
55
"manifest_version": 2,
6-
"version": "1.0.4",
6+
"version": "1.0.5",
77
"default_locale": "en",
88
"icons": {
99
"16": "img/16.png",

src/background/APIService.js

Lines changed: 82 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { EXPLORER_URL } from '../../config';
2-
import { FROM_BACK_TO_RECORD, TX_SUCCESS } from '../constant/types';
1+
import { EXPLORER_URL, LOCK_TIME } from '../../config';
2+
import { FROM_BACK_TO_RECORD, SET_LOCK, TX_SUCCESS } from '../constant/types';
33
import { getLanguage } from '../i18n';
44
import { getTxStatus, sendStakeTx, sendTx } from './api';
55
import { signPayment, stakePayment } from './lib';
66
import { get, removeValue, save } from './storageService';
7-
import {ACCOUNT_TYPE} from "../constant/walletType"
7+
import { ACCOUNT_TYPE } from "../constant/walletType"
88
import extension from 'extensionizer'
99

1010
const ObservableStore = require('obs-store')
@@ -26,20 +26,26 @@ class APIService {
2626
data: '',
2727
password: '',
2828
currentAccount: {},
29-
mne:""
29+
mne: ""
3030
})
3131
}
3232
getStore = () => {
3333
return this.memStore.getState()
3434
};
35-
getCreateMnemonic=()=>{
36-
let mne = this.getStore().mne
37-
if(mne){
38-
return mne
39-
}else{
35+
getCreateMnemonic = (isNewMne) => {
36+
if (isNewMne) {
4037
let mnemonic = generateMne()
4138
this.memStore.updateState({ mne: mnemonic })
4239
return mnemonic
40+
} else {
41+
let mne = this.getStore().mne
42+
if (mne) {
43+
return mne
44+
} else {
45+
let mnemonic = generateMne()
46+
this.memStore.updateState({ mne: mnemonic })
47+
return mnemonic
48+
}
4349
}
4450
}
4551
filterCurrentAccount = (accountList, currentAddress) => {
@@ -62,16 +68,41 @@ class APIService {
6268
})
6369
return this.getAccountWithoutPrivate(currentAccount)
6470
} catch (error) {
65-
return { error: 'passwordError',type:"local" }
71+
return { error: 'passwordError', type: "local" }
6672
}
6773
};
6874
checkPassword(password) {
6975
return this.getStore().password === password
7076
}
77+
setLastActiveTime() {
78+
const timeoutMinutes = LOCK_TIME
79+
let localData = this.getStore().data
80+
let isUnlocked = this.getStore().isUnlocked
81+
if (localData && isUnlocked) {
82+
if (this.timer) {
83+
clearTimeout(this.timer)
84+
}
85+
if (!timeoutMinutes) {
86+
return
87+
}
88+
89+
this.timer = setTimeout(() => {
90+
this.setUnlockedStatus(false)
91+
}, timeoutMinutes * 60 * 1000)
92+
}
93+
94+
}
7195
setUnlockedStatus(status) {
7296
let account = this.memStore.getState().currentAccount
7397
if (!status) {
74-
this.memStore.updateState({ currentAccount: { ...account } })
98+
this.memStore.updateState({
99+
currentAccount: { ...account },
100+
password: ""
101+
})
102+
extension.runtime.sendMessage({
103+
type: FROM_BACK_TO_RECORD,
104+
action: SET_LOCK,
105+
});
75106
}
76107
this.memStore.updateState({ isUnlocked: status })
77108
};
@@ -177,7 +208,7 @@ class APIService {
177208
for (let index = 0; index < accounts.length; index++) {
178209
const account = accounts[index];
179210
if (account.address === address) {
180-
error = { "error": 'improtRepeat',type:"local" }
211+
error = { "error": 'improtRepeat', type: "local" }
181212
break
182213
}
183214
}
@@ -227,7 +258,7 @@ class APIService {
227258
this.memStore.updateState({ currentAccount: account })
228259
return this.getAccountWithoutPrivate(account)
229260
} catch (error) {
230-
return { "error": "privateError" ,type:"local"}
261+
return { "error": "privateError", type: "local" }
231262
}
232263

233264
}
@@ -238,45 +269,45 @@ class APIService {
238269
* @param {*} accountName
239270
* @returns
240271
*/
241-
addAccountByKeyStore = async(keystore,password,accountName)=>{
242-
let wallet = await importWalletByKeystore(keystore,password)
243-
if(wallet.error){
272+
addAccountByKeyStore = async (keystore, password, accountName) => {
273+
let wallet = await importWalletByKeystore(keystore, password)
274+
if (wallet.error) {
244275
return wallet
245276
}
246-
let currentAccount = await this.addImportAccount(wallet.priKey,accountName)
277+
let currentAccount = await this.addImportAccount(wallet.priKey, accountName)
247278
return currentAccount
248279
}
249280
addWatchModeAccount = async (address, accountName) => {
250-
try {
251-
let data = this.getStore().data
252-
let accounts = data[0].accounts
253-
let error = this._checkWalletRepeat(accounts, address);
254-
if (error.error) {
255-
return error
256-
}
257-
let typeIndex = this._findWalletIndex(accounts, ACCOUNT_TYPE.WALLET_WATCH);
258-
const account = {
259-
address: address,
260-
type: ACCOUNT_TYPE.WALLET_WATCH,
261-
accountName,
262-
typeIndex
263-
}
264-
data[0].currentAddress = account.address
265-
data[0].accounts.push(account)
266-
let encryptData = await encryptUtils.encrypt(this.getStore().password, data)
281+
try {
282+
let data = this.getStore().data
283+
let accounts = data[0].accounts
284+
let error = this._checkWalletRepeat(accounts, address);
285+
if (error.error) {
286+
return error
287+
}
288+
let typeIndex = this._findWalletIndex(accounts, ACCOUNT_TYPE.WALLET_WATCH);
289+
const account = {
290+
address: address,
291+
type: ACCOUNT_TYPE.WALLET_WATCH,
292+
accountName,
293+
typeIndex
294+
}
295+
data[0].currentAddress = account.address
296+
data[0].accounts.push(account)
297+
let encryptData = await encryptUtils.encrypt(this.getStore().password, data)
267298

268-
this.memStore.updateState({ data: data })
269-
save({ keyringData: encryptData })
270-
this.memStore.updateState({ currentAccount: account })
271-
return this.getAccountWithoutPrivate(account)
272-
} catch (error) {
273-
return { "error": JSON.stringify(error)}
274-
}
299+
this.memStore.updateState({ data: data })
300+
save({ keyringData: encryptData })
301+
this.memStore.updateState({ currentAccount: account })
302+
return this.getAccountWithoutPrivate(account)
303+
} catch (error) {
304+
return { "error": JSON.stringify(error) }
305+
}
275306
}
276307
/**
277308
* 导入ledger钱包
278309
*/
279-
addLedgerAccount = async (address, accountName, ledgerPathAccountIndex)=>{
310+
addLedgerAccount = async (address, accountName, ledgerPathAccountIndex) => {
280311
try {
281312
let data = this.getStore().data
282313
let accounts = data[0].accounts
@@ -302,7 +333,7 @@ class APIService {
302333
this.memStore.updateState({ currentAccount: account })
303334
return this.getAccountWithoutPrivate(account)
304335
} catch (error) {
305-
return { "error": JSON.stringify(error)}
336+
return { "error": JSON.stringify(error) }
306337
}
307338
}
308339
/**
@@ -361,7 +392,7 @@ class APIService {
361392
return item.address !== address
362393
})
363394
let currentAccount = this.getStore().currentAccount
364-
if(address === currentAccount.address){
395+
if (address === currentAccount.address) {
365396
currentAccount = accounts[0]
366397
data[0].currentAddress = currentAccount.address
367398
}
@@ -371,7 +402,7 @@ class APIService {
371402
save({ keyringData: encryptData })
372403
return this.getAccountWithoutPrivate(currentAccount)
373404
} else {
374-
return { error: 'passwordError' ,type:"local"}
405+
return { error: 'passwordError', type: "local" }
375406
}
376407
}
377408
getMnemonic = async (pwd) => {
@@ -382,7 +413,7 @@ class APIService {
382413
let mnemonic = await encryptUtils.decrypt(this.getStore().password, mnemonicEn)
383414
return mnemonic
384415
} else {
385-
return { error: 'passwordError',type:"local" }
416+
return { error: 'passwordError', type: "local" }
386417
}
387418
}
388419
updateSecPassword = async (oldPwd, pwd) => {
@@ -417,10 +448,10 @@ class APIService {
417448
await save({ keyringData: encryptData })
418449
return { code: 0 }
419450
} else {
420-
return { error: 'passwordError',type:"local" }
451+
return { error: 'passwordError', type: "local" }
421452
}
422453
} catch (error) {
423-
return { error: 'passwordError',type:"local" }
454+
return { error: 'passwordError', type: "local" }
424455
}
425456

426457
}
@@ -436,7 +467,7 @@ class APIService {
436467
const privateKey = await encryptUtils.decrypt(pwd, nowAccount.privateKey)
437468
return privateKey
438469
} else {
439-
return { error: 'passwordError',type:"local" }
470+
return { error: 'passwordError', type: "local" }
440471
}
441472
}
442473
getCurrentPrivateKey = async () => {
@@ -487,7 +518,7 @@ class APIService {
487518
notification = (hash) => {
488519
let id = hash
489520
extension.notifications &&
490-
extension.notifications.onClicked.addListener(function (id) {
521+
extension.notifications.onClicked.addListener(function (id) {
491522
let url = EXPLORER_URL + id
492523
extension.tabs.create({ url: url });
493524
});
@@ -518,7 +549,7 @@ class APIService {
518549
if (this.timer) {
519550
clearTimeout(this.timer);
520551
this.timer = null;
521-
}
552+
}
522553
} else {
523554
this.timer = setTimeout(() => {
524555
this.fetchTransactionStatus(paymentId, hash);

src/background/messageListener.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import {
2121
WALLET_CHECK_TX_STATUS,
2222
WALLET_IMPORT_LEDGER,
2323
WALLET_IMPORT_KEY_STORE,
24-
WALLET_GET_CREATE_MNEMONIC, WALLET_IMPORT_WATCH_MODE
24+
WALLET_GET_CREATE_MNEMONIC, WALLET_IMPORT_WATCH_MODE,
25+
WALLET_RESET_LAST_ACTIVE_TIME
2526
} from "../constant/types";
2627
import apiService from "./APIService";
2728
import * as storage from "./storageService";
@@ -137,8 +138,10 @@ function internalMessageListener(message, sender, sendResponse) {
137138
})
138139
break;
139140
case WALLET_GET_CREATE_MNEMONIC:
140-
sendResponse(apiService.getCreateMnemonic())
141+
sendResponse(apiService.getCreateMnemonic(payload.isNewMne))
141142
break
143+
case WALLET_RESET_LAST_ACTIVE_TIME:
144+
sendResponse(apiService.setLastActiveTime())
142145
default:
143146
break;
144147
}

src/constant/types.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,25 +95,34 @@ export const WALLET_CHECK_TX_STATUS = "WALLET_CHECK_TX_STATUS"
9595
/**
9696
* 导入ledger钱包
9797
*/
98-
export const WALLET_IMPORT_LEDGER = "WALLET_IMPORT_LEDGER"
98+
export const WALLET_IMPORT_LEDGER = "WALLET_IMPORT_LEDGER"
9999

100100
/**
101101
* 导入watch mode钱包
102102
*/
103-
export const WALLET_IMPORT_WATCH_MODE = "WALLET_IMPORT_WATCH_MODE"
103+
export const WALLET_IMPORT_WATCH_MODE = "WALLET_IMPORT_WATCH_MODE"
104104

105105

106-
/**
107-
* 导入keystore钱包
108-
*/
109-
export const WALLET_IMPORT_KEY_STORE = "WALLET_IMPORT_KEY_STORE"
106+
/**
107+
* 导入keystore钱包
108+
*/
109+
export const WALLET_IMPORT_KEY_STORE = "WALLET_IMPORT_KEY_STORE"
110110

111111

112112

113113
/**
114114
* 后台生成助记词
115115
*/
116-
export const WALLET_GET_CREATE_MNEMONIC = "WALLET_GET_CREATE_MNEMONIC"
116+
export const WALLET_GET_CREATE_MNEMONIC = "WALLET_GET_CREATE_MNEMONIC"
117+
118+
119+
/**
120+
* 更新最后活跃时间
121+
*/
122+
export const WALLET_RESET_LAST_ACTIVE_TIME = "WALLET_RESET_LAST_ACTIVE_TIME"
123+
124+
125+
117126

118127
// ====================================================================================bottom back to popup
119128

@@ -127,9 +136,14 @@ export const FROM_BACK_TO_RECORD = "FROM_BACK_TO_RECORD"
127136
*/
128137
export const TX_SUCCESS = "TX_SUCCESS"
129138

139+
/**
140+
* 进入锁定页面
141+
*/
142+
export const SET_LOCK = "SET_LOCK"
143+
130144

131145
/**
132146
* LEDGER 连接成功
133147
* @type {string}
134148
*/
135-
export const LEDGER_CONNECTED_SUCCESSFULLY = 'LEDGER_CONNECTED_SUCCESSFULLY';
149+
export const LEDGER_CONNECTED_SUCCESSFULLY = 'LEDGER_CONNECTED_SUCCESSFULLY';

0 commit comments

Comments
 (0)