Skip to content

Commit

Permalink
[Tech] User credentials are no longer stored in plain text
Browse files Browse the repository at this point in the history
  • Loading branch information
dawidgarus committed Mar 27, 2022
1 parent 785b49f commit 857ea6f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
10 changes: 5 additions & 5 deletions electron/gog/credentials.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import Store from 'electron-store';
import { CredentialsManager } from '../shared/credentials';
import { GOGLoginData } from '../types';
import Store from 'electron-store'
import { CredentialsManager } from '../shared/credentials'
import { GOGLoginData } from '../types'

export class GogStoreCredentials extends CredentialsManager<GOGLoginData> {
private store = new Store({
cwd: 'gog_store'
})

protected doGet(): string | GOGLoginData | null {
return this.store.get('credentials') as GOGLoginData || null
return (this.store.get('credentials') as GOGLoginData) || null
}

protected doPut(credentials: string | GOGLoginData | null): void {
if (credentials === null) {
this.store.delete('credentials');
this.store.delete('credentials')
} else {
this.store.set('credentials', credentials)
}
Expand Down
2 changes: 1 addition & 1 deletion electron/gog/games.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { gogStoreCredentials } from './credentials';
import { gogStoreCredentials } from './credentials'
import { GOGLibrary } from './library'
import { BrowserWindow } from 'electron'
import Store from 'electron-store'
Expand Down
2 changes: 1 addition & 1 deletion electron/gog/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios from 'axios'
import Store from 'electron-store'
import { logError, logInfo, LogPrefix, logWarning } from '../logger/logger'
import { GOGLoginData } from '../types'
import { gogStoreCredentials } from './credentials';
import { gogStoreCredentials } from './credentials'

const configStore = new Store({
cwd: 'gog_store'
Expand Down
2 changes: 1 addition & 1 deletion electron/legendary/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class LegendaryUser {
}
})
})
const userInfoObject = JSON.parse(userInfoContent);
const userInfoObject = JSON.parse(userInfoContent)
const info: UserInfo = {
account_id: userInfoObject.account_id,
displayName: userInfoObject.displayName,
Expand Down
10 changes: 6 additions & 4 deletions electron/shared/credentials.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { safeStorage } from 'electron'

export abstract class CredentialsManager<T extends object> {
protected abstract doPut(credentials: T | string | null): void;
protected abstract doGet(): T | string | null;
protected abstract doPut(credentials: T | string | null): void
protected abstract doGet(): T | string | null

private lastEncoded: string
private lastCredentials: T

get(): T | null {
const credentialsOrEncoded = this.doGet();
const credentialsOrEncoded = this.doGet()
if (!credentialsOrEncoded) {
return null
}
Expand All @@ -27,7 +27,9 @@ export abstract class CredentialsManager<T extends object> {
} else {
// migrate if available
if (safeStorage.isEncryptionAvailable()) {
const encrypted = safeStorage.encryptString(JSON.stringify(credentialsOrEncoded))
const encrypted = safeStorage.encryptString(
JSON.stringify(credentialsOrEncoded)
)
const encoded = encrypted.toString('base64')
this.lastEncoded = encoded
this.lastCredentials = credentialsOrEncoded
Expand Down

0 comments on commit 857ea6f

Please sign in to comment.