password saving

This commit is contained in:
jessop 2019-08-27 22:35:07 -04:00 committed by Sean Yesmunt
parent ec1f48484e
commit 5c06fa2dd8
19 changed files with 103 additions and 101 deletions

View file

@ -1,3 +1,5 @@
/* eslint no-console:0 */
/* eslint space-before-function-paren:0 */
// Module imports
import '@babel/polyfill';
import keytar from 'keytar';
@ -29,6 +31,7 @@ let showingAutoUpdateCloseAlert = false;
// object is garbage collected.
let rendererWindow;
// eslint-disable-next-line no-unused-vars
let tray;
let daemon;
@ -44,6 +47,7 @@ if (isDev) {
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = true;
}
// eslint-disable-next-line space-before-function-paren
const startDaemon = async () => {
let isDaemonRunning = false;
@ -110,6 +114,7 @@ if (!gotSingleInstanceLock) {
}
});
// eslint-disable-next-line space-before-function-paren
app.on('ready', async () => {
await startDaemon();
startSandbox();
@ -312,6 +317,26 @@ ipcMain.on('set-auth-token', (event, token) => {
keytar.setPassword('LBRY', 'auth_token', token ? token.toString().trim() : null);
});
ipcMain.on('get-password', event => {
keytar.getPassword('LBRY', 'wallet_password').then(password => {
event.sender.send('get-password-response', password ? password.toString() : null);
});
});
ipcMain.on('set-password', (event, password) => {
if (password || password === '') {
keytar.setPassword('LBRY', 'wallet_password', password).then(res => {
event.sender.send('get-password-response', res);
});
}
});
ipcMain.on('delete-password', (event, password) => {
keytar.deletePassword('LBRY', 'wallet_password', password).then(res => {
event.sender.send('get-password-response', res);
});
});
process.on('uncaughtException', error => {
console.log(error);
dialog.showErrorBox('Error Encountered', `Caught error: ${error}`);

View file

@ -6,12 +6,6 @@ import { Lbry, buildURI, parseURI } from 'lbry-redux';
import Router from 'component/router/index';
import ModalRouter from 'modal/modalRouter';
import ReactModal from 'react-modal';
<<<<<<< HEAD
import SideBar from 'component/sideBar';
import Header from 'component/header';
import Button from 'component/button';
=======
>>>>>>> add createChannel to first run flow
import { openContextMenu } from 'util/context-menu';
import useKonamiListener from 'util/enhanced-layout';
import Yrbl from 'component/yrbl';

View file

@ -10,7 +10,6 @@ import {
selectWalletIsEncrypted,
selectHasTransactions,
} from 'lbry-redux';
import { doPasswordSaved } from 'redux/actions/app';
import WalletSecurityAndSync from './view';
import {
doCheckSync,
@ -27,7 +26,6 @@ import {
selectHashChanged,
selectUser,
} from 'lbryinc';
import { selectIsPasswordSaved } from 'redux/selectors/app';
import { doSetClientSetting } from 'redux/actions/settings';
import { makeSelectClientSetting } from 'redux/selectors/settings';
@ -46,7 +44,6 @@ const select = state => ({
syncApplyErrorMessage: selectSyncApplyErrorMessage(state),
syncData: selectSyncData(state),
syncHash: selectSyncHash(state),
isPasswordSaved: selectIsPasswordSaved(state),
hashChanged: selectHashChanged(state),
});
@ -54,7 +51,6 @@ const perform = dispatch => ({
encryptWallet: password => dispatch(doWalletEncrypt(password)),
decryptWallet: () => dispatch(doWalletDecrypt()),
updateWalletStatus: () => dispatch(doWalletStatus()),
setPasswordSaved: saved => dispatch(doPasswordSaved(saved)),
syncApply: (hash, data, password) => dispatch(doSyncApply(hash, data, password)),
getSync: password => dispatch(doGetSync(password)),
checkSync: () => dispatch(doCheckSync()),

View file

@ -6,7 +6,6 @@ import UserEmail from 'component/userEmail';
import * as ICONS from 'constants/icons';
import { getSavedPassword, setSavedPassword, deleteSavedPassword } from 'util/saved-passwords';
import { KEY_WALLET_PASSWORD } from 'constants/keychain';
type Props = {
// wallet statuses
@ -70,10 +69,7 @@ function WalletSecurityAndSync(props: Props) {
walletEncrypted,
encryptWallet,
decryptWallet,
setPasswordSaved,
syncEnabled,
setClientSetting,
isPasswordSaved,
user,
hasSyncedWallet,
getSyncIsPending,
@ -84,7 +80,7 @@ function WalletSecurityAndSync(props: Props) {
syncApply,
checkSync,
hasTransactions,
// setDefaultAccount,
setDefaultAccount,
} = props;
const defaultComponentState: State = {
@ -111,7 +107,7 @@ function WalletSecurityAndSync(props: Props) {
// on mount
useEffect(() => {
checkSync();
getSavedPassword(KEY_WALLET_PASSWORD).then(p => {
getSavedPassword().then(p => {
if (p) {
setComponentState({
...componentState,
@ -140,7 +136,7 @@ function WalletSecurityAndSync(props: Props) {
function onChangeRememberPassword(event: SyntheticInputEvent<>) {
if (componentState.rememberPassword) {
deleteSavedPassword(KEY_WALLET_PASSWORD);
deleteSavedPassword();
}
setComponentState({ ...componentState, rememberPassword: event.target.checked });
}
@ -204,7 +200,7 @@ function WalletSecurityAndSync(props: Props) {
}
if (componentState.rememberPassword && !componentState.failed) {
setSavedPassword(KEY_WALLET_PASSWORD, componentState.newPassword);
setSavedPassword(componentState.newPassword);
}
}
@ -374,13 +370,13 @@ function WalletSecurityAndSync(props: Props) {
onClick={() => syncApply(syncHash, syncData, componentState.newPassword)}
/>{' '}
<Button button="primary" label={__('Check Sync')} onClick={() => checkSync()} />{' '}
<Button button="primary" label={__('Setpass test')} onClick={() => setSavedPassword('test', 'testpass')} />{' '}
<Button button="primary" label={__('Setpass test')} onClick={() => setSavedPassword('testpass')} />{' '}
<Button
button="primary"
label={__('Getpass test')}
onClick={() => getSavedPassword('test').then(p => setComponentState({ ...componentState, newPassword: p }))}
onClick={() => getSavedPassword().then(p => setComponentState({ ...componentState, newPassword: p }))}
/>{' '}
<Button button="primary" label={__('Deletepass test')} onClick={() => deleteSavedPassword('test')} />{' '}
<Button button="primary" label={__('Deletepass test')} onClick={() => deleteSavedPassword()} />{' '}
<p>
password:{' '}
{componentState.newPassword

View file

@ -1,3 +0,0 @@
export const AUTH_ORG = 'LBRY';
export const KEY_WALLET_PASSWORD = 'wallet_password';
export const KEY_AUTH_TOKEN = 'auth_token';

View file

@ -1,12 +1,11 @@
import { connect } from 'react-redux';
import ModalPasswordUnsave from './view';
import { doHideModal, doPasswordSaved } from 'redux/actions/app';
import { doHideModal } from 'redux/actions/app';
// const select = () => ({});
//
const perform = dispatch => ({
closeModal: () => dispatch(doHideModal()),
setPasswordSaved: saved => dispatch(doPasswordSaved(saved)),
});
export default connect(

View file

@ -1,11 +1,10 @@
// @flow
import React from 'react';
import { Modal } from 'modal/modal';
// import keytar from 'keytar';
import { deleteSavedPassword } from 'util/saved-passwords';
type Props = {
closeModal: () => void,
setPasswordSaved: boolean => void,
};
class ModalPasswordUnsave extends React.PureComponent<Props> {
@ -18,12 +17,10 @@ class ModalPasswordUnsave extends React.PureComponent<Props> {
type="confirm"
confirmButtonLabel={__('Forget')}
abortButtonLabel={__('Nevermind')}
onConfirmed={
() => {}
// keytar.deletePassword('LBRY', 'wallet_password').then(() => {
// this.props.setPasswordSaved(false);
// this.props.closeModal();
// })
onConfirmed={() =>
deleteSavedPassword().then(() => {
this.props.closeModal();
})
}
onAborted={this.props.closeModal}
>

View file

@ -1,19 +1,16 @@
import { connect } from 'react-redux';
import { doWalletStatus, doWalletDecrypt, selectWalletDecryptSucceeded } from 'lbry-redux';
import { doHideModal, doPasswordSaved } from 'redux/actions/app';
import { doHideModal } from 'redux/actions/app';
import ModalWalletDecrypt from './view';
import { selectIsPasswordSaved } from 'redux/selectors/app';
const select = state => ({
walletDecryptSucceded: selectWalletDecryptSucceeded(state),
isPasswordSaved: selectIsPasswordSaved(state),
});
const perform = dispatch => ({
closeModal: () => dispatch(doHideModal()),
decryptWallet: password => dispatch(doWalletDecrypt(password)),
updateWalletStatus: () => dispatch(doWalletStatus()),
setPasswordSaved: saved => dispatch(doPasswordSaved(saved)),
});
export default connect(

View file

@ -2,15 +2,13 @@
import React from 'react';
import { Modal } from 'modal/modal';
import Button from 'component/button';
// import keytar from 'keytar';
import { deleteSavedPassword } from 'util/saved-passwords';
type Props = {
closeModal: () => void,
decryptWallet: () => void,
updateWalletStatus: () => void,
walletDecryptSucceded: boolean,
passwordUnsaved: () => void,
setPasswordSaved: boolean => void,
};
type State = {
@ -26,8 +24,7 @@ class ModalWalletDecrypt extends React.PureComponent<Props, State> {
const { props, state } = this;
if (state.submitted && props.walletDecryptSucceded === true) {
// keytar.deletePassword('LBRY', 'wallet_password');
props.setPasswordSaved(false);
deleteSavedPassword();
props.closeModal();
props.updateWalletStatus();
}

View file

@ -1,6 +1,6 @@
import { connect } from 'react-redux';
import { doWalletStatus, doWalletEncrypt, selectWalletEncryptSucceeded, selectWalletEncryptResult } from 'lbry-redux';
import { doHideModal, doPasswordSaved } from 'redux/actions/app';
import { doHideModal } from 'redux/actions/app';
import ModalWalletEncrypt from './view';
const select = state => ({
@ -12,7 +12,6 @@ const perform = dispatch => ({
closeModal: () => dispatch(doHideModal()),
encryptWallet: password => dispatch(doWalletEncrypt(password)),
updateWalletStatus: () => dispatch(doWalletStatus()),
setPasswordSaved: saved => dispatch(doPasswordSaved(saved)),
});
export default connect(

View file

@ -3,6 +3,7 @@ import React from 'react';
import { Form, FormField, Submit } from 'component/common/form';
import { Modal } from 'modal/modal';
import Button from 'component/button';
import { setSavedPassword } from 'util/saved-passwords';
type Props = {
closeModal: () => void,
@ -10,7 +11,6 @@ type Props = {
updateWalletStatus: boolean,
encryptWallet: (?string) => void,
updateWalletStatus: () => void,
setPasswordSaved: boolean => void,
};
type State = {
@ -87,8 +87,7 @@ class ModalWalletEncrypt extends React.PureComponent<Props, State> {
return;
}
if (state.rememberPassword === true) {
this.props.setPasswordSaved(true);
// keytar.setPassword('LBRY', 'wallet_password', state.newPassword);
setSavedPassword(state.newPassword);
}
this.setState({ submitted: true });
this.props.encryptWallet(state.newPassword);

View file

@ -1,6 +1,6 @@
import { connect } from 'react-redux';
import { doWalletUnlock, selectWalletUnlockSucceeded } from 'lbry-redux';
import { doQuit, doHideModal, doPasswordSaved } from 'redux/actions/app';
import { doQuit, doHideModal } from 'redux/actions/app';
import ModalWalletUnlock from './view';
const select = state => ({
@ -11,7 +11,6 @@ const perform = dispatch => ({
closeModal: () => dispatch(doHideModal()),
quit: () => dispatch(doQuit()),
unlockWallet: password => dispatch(doWalletUnlock(password)),
setPasswordSaved: saved => dispatch(doPasswordSaved(saved)),
});
export default connect(

View file

@ -3,14 +3,13 @@ import React from 'react';
import { Form, FormField } from 'component/common/form';
import { Modal } from 'modal/modal';
import Button from 'component/button';
// import keytar from 'keytar';
import { getSavedPassword, setSavedPassword } from 'util/saved-passwords';
type Props = {
quit: () => void,
closeModal: () => void,
unlockWallet: (?string) => void,
walletUnlockSucceded: boolean,
setPasswordSaved: boolean => void,
};
type State = {
@ -24,13 +23,21 @@ class ModalWalletUnlock extends React.PureComponent<Props, State> {
rememberPassword: false,
};
componentDidMount() {
getSavedPassword()
.then(p => {
if (p) {
this.setState({ password: p, rememberPassword: true });
}
})
.catch();
}
componentDidUpdate() {
const { props } = this;
if (props.walletUnlockSucceded === true) {
if (this.state.rememberPassword) {
this.props.setPasswordSaved(true);
// keytar.setPassword('LBRY', 'wallet_password', this.state.password);
setSavedPassword(this.state.password);
}
props.closeModal();
}

View file

@ -36,7 +36,6 @@ const perform = dispatch => ({
decryptWallet: () => dispatch(doNotifyDecryptWallet()),
updateWalletStatus: () => dispatch(doWalletStatus()),
confirmForgetPassword: modalProps => dispatch(doNotifyForgetPassword(modalProps)),
setPasswordSaved: saved => dispatch(doPasswordSaved(saved)),
clearPlayingUri: () => dispatch(doSetPlayingUri(null)),
setDarkTime: (time, options) => dispatch(doSetDarkTime(time, options)),
});

View file

@ -11,9 +11,8 @@ import I18nMessage from 'component/i18nMessage';
import Page from 'component/page';
import SettingLanguage from 'component/settingLanguage';
import FileSelector from 'component/common/file-selector';
import UnsupportedOnWeb from 'component/common/unsupported-on-web';
// import keytar from 'keytar';
import WalletSecurityAndSync from '../../component/walletSecurityAndSync';
import { getSavedPassword } from 'util/saved-passwords';
type Price = {
currency: string,
@ -64,8 +63,6 @@ type Props = {
userBlockedChannelsCount?: number,
hideBalance: boolean,
confirmForgetPassword: () => void,
isPasswordSaved: boolean,
setPasswordSaved: boolean => void,
floatingPlayer: boolean,
clearPlayingUri: () => void,
darkModeTimes: DarkModeTimes,
@ -94,18 +91,17 @@ class SettingsPage extends React.PureComponent<Props, State> {
(this: any).onAutomaticDarkModeChange = this.onAutomaticDarkModeChange.bind(this);
(this: any).clearCache = this.clearCache.bind(this);
(this: any).onChangeTime = this.onChangeTime.bind(this);
(this: any).onConfirmForgetPassword = this.onConfirmForgetPassword.bind(this);
}
componentDidMount() {
this.props.getThemes();
this.props.updateWalletStatus();
// keytar.getPassword('LBRY', 'wallet_password').then(p => {
// if (p || p === '') {
// this.props.setPasswordSaved(true);
// } else {
// this.props.setPasswordSaved(false);
// }
// });
getSavedPassword().then(p => {
if (p) {
this.setState({ storedPassword: true });
}
});
}
onKeyFeeChange(newValue: Price) {
@ -209,7 +205,6 @@ class SettingsPage extends React.PureComponent<Props, State> {
floatingPlayer,
clearPlayingUri,
darkModeTimes,
isPasswordSaved,
} = this.props;
const noDaemonSettings = !daemonSettings || Object.keys(daemonSettings).length === 0;
@ -519,7 +514,7 @@ class SettingsPage extends React.PureComponent<Props, State> {
</React.Fragment>
}
/>
{isPasswordSaved && (
{this.state.storedPassword && (
<p className="card__subtitle card__help">
{__('Your password is saved in your OS keychain.')}{' '}
<Button

View file

@ -14,14 +14,8 @@ const select = (state, props) => {
const { pathname, hash } = props.location;
const urlPath = pathname + hash;
// Remove the leading "/" added by the browser
<<<<<<< HEAD
const path = urlPath.slice(1).replace(/:/g, '#');
=======
const path = pathname.slice(1).replace(/:/g, '#');
console.log('path', path);
debugger;
>>>>>>> rebase and comment out keytar
let uri;
try {
uri = normalizeURI(path);

View file

@ -313,27 +313,12 @@ export function doNotifyForgetPassword() {
};
}
export function doNotifySyncWallet() {
return dispatch => {
dispatch(doOpenModal(MODALS.WALLET_SYNC));
};
}
export function doAlertError(errorList) {
return dispatch => {
dispatch(doError(errorList));
};
}
export function doPasswordSaved(saved) {
return dispatch => {
dispatch({
type: ACTIONS.PASSWORD_SAVED,
data: saved,
});
};
}
export function doDaemonReady() {
return (dispatch, getState) => {
const state = getState();

View file

@ -1,17 +1,45 @@
// import keytar from 'keytar';
import { AUTH_ORG } from 'constants/keychain';
import { ipcRenderer } from 'electron';
export const setSavedPassword = (key, value) => {
// keytar.setPassword(AUTH_ORG, key, value);
export const setSavedPassword = value => {
return new Promise(
resolve => {
ipcRenderer.once('set-password-response', (event, success) => {
resolve(success);
});
ipcRenderer.send('set-password', value);
},
reject => {
reject(false);
}
);
};
export const getSavedPassword = key => {
// return keytar
// .getPassword(AUTH_ORG, key)
// .then(p => p)
// .catch(e => console.error(e));
export const getSavedPassword = () => {
return new Promise(
resolve => {
ipcRenderer.once('get-password-response', (event, password) => {
resolve(password);
});
ipcRenderer.send('get-password');
},
reject => reject(false)
);
};
export const deleteSavedPassword = key => {
// keytar.deletePassword(AUTH_ORG, key).catch(e => console.error(e));
export const deleteSavedPassword = () => {
return new Promise(
resolve => {
ipcRenderer.once('delete-password-response', (event, success) => {
resolve(success);
});
ipcRenderer.send('delete-password');
},
reject => {
reject(false);
}
);
};
export const testKeychain = () => {
// we should make sure it works on startup
};

View file

@ -655,7 +655,6 @@
"Block": "Block",
"% downloaded": "% downloaded",
"'claimName' should no longer be used. Use 'streamClaimName' or 'channelClaimName' instead": "'claimName' should no longer be used. Use 'streamClaimName' or 'channelClaimName' instead",
"Portuguese": "Portuguese",
"Vietnamese": "Vietnamese",
"Thai": "Thai",
"Arabic": "Arabic",