Skip to content

Commit

Permalink
Merge pull request #135 from vitrine-app/fix/crossplatform-encryption
Browse files Browse the repository at this point in the history
release: v0.11.0
  • Loading branch information
Paul Roman authored Mar 6, 2019
2 parents 00cb81c + ea8b266 commit a82ce88
Show file tree
Hide file tree
Showing 17 changed files with 411 additions and 228 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Vitrine Changelog

## 0.11.0 (06/03/2019)
- fix: Vitrine now uses the new IGDB 3000 API

## 0.10.1 (17/02/2019)
- fix: Vitrine no longer launches forever at first startup

Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vitrine",
"version": "0.10.1",
"version": "0.11.0",
"description": "Centralize all of your games within a simple interface.",
"main": "public/server.js",
"productName": "Vitrine",
Expand All @@ -23,6 +23,7 @@
"@fortawesome/fontawesome-free-solid": "^5.0.8",
"@fortawesome/react-fontawesome": "0.0.17",
"aphrodite": "2.2.0",
"apicalypse": "^0.1.3",
"axios": "^0.18.0",
"chunk": "^0.0.2",
"compare-versions": "^3.4.0",
Expand All @@ -35,7 +36,6 @@
"gamepad-listener": "0.4.0",
"glob": "^7.1.2",
"glob-promise": "^3.4.0",
"google-translate-api": "^2.3.0",
"igdb-api-node": "3.1.4",
"jsonwebtoken": "^8.3.0",
"moment": "^2.22.0",
Expand Down Expand Up @@ -73,6 +73,7 @@
"@types/source-map-support": "^0.4.1",
"@types/uuid": "^3.4.3",
"@types/winreg": "^1.2.30",
"aes-cross": "^1.0.9",
"asar": "^0.14.3",
"base64-inline-loader": "^1.1.1",
"chai": "^4.1.2",
Expand Down Expand Up @@ -105,6 +106,7 @@
"tslint": "^5.9.1",
"tslint-config-prettier": "^1.17.0",
"tslint-eslint-rules": "^5.1.0",
"tslint-plugin-prettier": "^2.0.1",
"tslint-react": "^3.5.1",
"tweetnacl": "^1.0.0",
"tweetnacl-util": "^0.15.0",
Expand Down Expand Up @@ -133,7 +135,6 @@
"lint:app": "tslint sources/**/*.ts*",
"lint:server": "tslint sources/server/**/*.ts sources/models/**/*.ts",
"lint:client": "tslint sources/client/**/*.ts*",
"lint:prettier": "prettier --write sources/**/*.ts*",
"watch:client": "cross-env NO_LOADER=true parallel-webpack --progress --config=webpack/client.config.js --watch",
"keys:encrypt": "node scripts/crypto encrypt",
"keys:decrypt": "node scripts/crypto decrypt",
Expand Down Expand Up @@ -163,7 +164,7 @@
},
"husky": {
"hooks": {
"precommit": "tslint --fix sources/**/*.ts* && yarn lint:prettier"
"precommit": "tslint --fix sources/**/*.ts*"
}
}
}
24 changes: 8 additions & 16 deletions scripts/crypto.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
const fs = require('fs-extra');
const openpgp = require('openpgp');
const aes = require('aes-cross');

const secret = process.env.VITRINE_KEY;
if (!secret)
if (!process.env.VITRINE_KEY)
throw new Error('VITRINE_KEY is missing.');
const secret = Buffer.from(process.env.VITRINE_KEY, 'utf8');

async function encrypt() {
const file = await fs.readFile('./sources/modules/keysProvider/srcs/keys.hh');
const { data } = await openpgp.encrypt({
message: await openpgp.message.fromBinary(file),
passwords: [ secret ],
armor: true
});
await fs.writeFile('./sources/modules/keysProvider/srcs/keys.hh.asc', data);
const encrypted = aes.encText(file.toString(), secret);
await fs.writeFile('./sources/modules/keysProvider/srcs/keys.asc', encrypted);
}

async function decrypt() {
const file = await fs.readFile('./sources/modules/keysProvider/srcs/keys.hh.asc');
const { data } = await openpgp.decrypt({
message: await openpgp.message.readArmored(file.toString()),
passwords: [ secret ],
format: 'ascii'
});
await fs.writeFile('./sources/modules/keysProvider/srcs/keys.hh', Buffer.from(data));
const file = await fs.readFile('./sources/modules/keysProvider/srcs/keys.asc');
const decrypted = aes.decText(file.toString(), secret);
await fs.writeFile('./sources/modules/keysProvider/srcs/keys.hh', decrypted);
}

switch (process.argv[2]) {
Expand Down
2 changes: 1 addition & 1 deletion sources/client/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const mapDispatchToProps = (dispatch: Dispatch<Action>) => ({
updateSettings(settings: any) {
dispatch(updateSettings(settings));
dispatch(setLocale(settings.lang || 'mdr'));
},
}
});

const AppContainer = connect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class PotentialGamesAddModal extends VitrineComponent<Props, State> {
</Progress>
</React.Fragment>
);
// TODO: re-implement feature to add every game at once
return (
<FadingModal
onClose={this.props.closePotentialGamesAddModal}
Expand All @@ -141,14 +142,7 @@ class PotentialGamesAddModal extends VitrineComponent<Props, State> {
title={
this.state.addAllGames
? this.props.intl.formatMessage({ id: 'actions.addAllPotentialGames' })
: {
rightElement: (
<Button primary={true} className={css(styles.addAllGamesButton)} onClick={this.addAllGamesClick}>
<FormattedMessage id={'actions.addAllPotentialGames'} />
</Button>
),
title: this.props.intl.formatMessage({ id: 'actions.addGames' })
}
: this.props.intl.formatMessage({ id: 'actions.addGames' })
}
visible={this.props.visible}
>
Expand Down
4 changes: 2 additions & 2 deletions sources/modules/keysProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export function discordRpcKey(): string {
return keysProvider.discordRpcKey();
}

export function vitrineSecretKey(): string {
return keysProvider.vitrineSecretKey();
export function igdbKey(): string {
return keysProvider.igdbKey();
}
6 changes: 3 additions & 3 deletions sources/modules/keysProvider/srcs/KeysProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ void getDiscordRpcKey(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(String::NewFromUtf8(Isolate::GetCurrent(), DISCORD_RPC_KEY));
}

void getVitrineSecretKey(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(String::NewFromUtf8(Isolate::GetCurrent(), VITRINE_SECRET_KEY));
void getIgdbKey(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(String::NewFromUtf8(Isolate::GetCurrent(), IGDB_KEY));
}

void init(Local<Object> exports) {
NODE_SET_METHOD(exports, "steamKey", getSteamKey);
NODE_SET_METHOD(exports, "discordRpcKey", getDiscordRpcKey);
NODE_SET_METHOD(exports, "vitrineSecretKey", getVitrineSecretKey);
NODE_SET_METHOD(exports, "igdbKey", getIgdbKey);
}

NODE_MODULE(NODE_GYP_MODULE_NAME, init);
1 change: 1 addition & 0 deletions sources/modules/keysProvider/srcs/keys.asc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1J+7uxD9BLyfEu06BwL3SzGK+Wugxs+eP5F6Z3zG4cLWDrcYnJiJR4IJPEuLn5jDlTTM7WSmuJpYLsH/+KaRARlzyjYdgWy5uqRJWn5Fufi+0pHMA8Wl8rU7RmFEeKoTD1b7KJdiBDDY5TVkXN//IM4cGoPBOpfdwZRwVzKEKgL44C8sUECjp/I0sHY5nCEYKbwUX6BuDny4ZfxKya+BkScudkTpRzkyiKBzL1SJldo=
12 changes: 0 additions & 12 deletions sources/modules/keysProvider/srcs/keys.hh.asc

This file was deleted.

11 changes: 9 additions & 2 deletions sources/server/PotentialGamesCacher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as path from 'path';

import { getEnvFolder } from '@models/env';
import { PotentialGame } from '@models/PotentialGame';
import { searchIgdbGame } from './api/ServerWrapper';
import { searchGame, searchSteamGame } from './api/igdbWrapper';
import { logger } from './Logger';

export class PotentialGamesCacher {
Expand All @@ -23,7 +23,14 @@ export class PotentialGamesCacher {
const populatedPotentialGames: PotentialGame[] = await Promise.all(
potentialGames.map(async (potentialGame: PotentialGame) => {
if (!potentialGamesCache[potentialGame.uuid]) {
const [{ cover }]: any[] = await searchIgdbGame(potentialGame.name, 1);
let cover: string;
if (potentialGame.details && potentialGame.details.steamId) {
const { cover: gameCover } = await searchSteamGame(potentialGame.details.steamId);
cover = gameCover;
} else {
const [{ cover: gameCover }]: any[] = await searchGame(potentialGame.name, 1);
cover = gameCover;
}
potentialGamesCache[potentialGame.uuid] = {
cover,
name: potentialGame.name
Expand Down
41 changes: 23 additions & 18 deletions sources/server/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { getEnvFolder, isProduction, randomHashedString } from '@models/env';
import { GamesCollection } from '@models/GamesCollection';
import { PlayableGame } from '@models/PlayableGame';
import { GameSource, PotentialGame } from '@models/PotentialGame';
import { fillFirstIgdbResult, fillIgdbGame, searchIgdbGame } from './api/ServerWrapper';
import { getFirstGame, getGameById, searchGame } from './api/igdbWrapper';
import { findSteamData } from './api/SteamDataFinder';
import { getSteamGamePlayTime, getSteamGamesPlayTimes } from './api/SteamPlayTimeWrapper';
import { searchBattleNetGames } from './crawlers/BattleNetCrawler';
Expand Down Expand Up @@ -126,15 +126,15 @@ export class Server {

public async fillIgdbGame(gameId: number) {
try {
this.windowsHandler.sendToClient('send-igdb-game', await fillIgdbGame(gameId, this.vitrineConfig.lang));
this.windowsHandler.sendToClient('send-igdb-game', await getGameById(gameId, this.vitrineConfig.lang));
} catch (error) {
this.throwServerError(error);
}
}

public async searchIgdbGames(gameName: string, resultsNb?: number) {
try {
this.windowsHandler.sendToClient('send-igdb-searches', gameName, await searchIgdbGame(gameName, resultsNb));
this.windowsHandler.sendToClient('send-igdb-searches', gameName, await searchGame(gameName, resultsNb));
} catch (error) {
this.throwServerError(error);
}
Expand All @@ -144,7 +144,7 @@ export class Server {
try {
await Promise.all(
[...this.potentialGames.getGames()].map(async (potentialGame: PotentialGame) => {
const filledGame: any = await fillFirstIgdbResult(potentialGame.name, this.vitrineConfig.lang);
const filledGame: any = await getFirstGame(potentialGame.name, this.vitrineConfig.lang);
const [executable, ...args]: string[] = potentialGame.commandLine;
filledGame.executable = executable;
filledGame.arguments = args.join(' ');
Expand All @@ -167,6 +167,7 @@ export class Server {
})
);
} catch (error) {
console.log(error);
this.throwServerError(error);
}
}
Expand Down Expand Up @@ -230,20 +231,24 @@ export class Server {
}

public async findPotentialGames() {
logger.info('Server', 'Beginning to search potential games.');
this.windowsHandler.sendToClient('potential-games-search-begin');
this.potentialGames.clear();
await Promise.all([
// TODO: return PotentialGames[] and refactor crawlers
this.searchSteamGames(),
this.searchOriginGames(),
this.searchBattleNetGames(),
this.searchEmulatedGames()
]);
this.potentialGames.alphaSort();
this.potentialGames.setGames(await potentialGamesCacher.cache(this.potentialGames.getGames()));
logger.info('Server', `${this.potentialGames.size()} potential games sent to client.`);
this.windowsHandler.sendToClient('add-potential-games', this.potentialGames.getGames());
try {
logger.info('Server', 'Beginning to search potential games.');
this.windowsHandler.sendToClient('potential-games-search-begin');
this.potentialGames.clear();
await Promise.all([
// TODO: return PotentialGames[] and refactor crawlers
this.searchSteamGames(),
this.searchOriginGames(),
this.searchBattleNetGames(),
this.searchEmulatedGames()
]);
this.potentialGames.alphaSort();
this.potentialGames.setGames(await potentialGamesCacher.cache(this.potentialGames.getGames()));
logger.info('Server', `${this.potentialGames.size()} potential games sent to client.`);
this.windowsHandler.sendToClient('add-potential-games', this.potentialGames.getGames());
} catch (error) {
this.throwServerError(error);
}
}

public async updateSettings(settingsForm: any) {
Expand Down
97 changes: 0 additions & 97 deletions sources/server/api/ServerWrapper.ts

This file was deleted.

Loading

0 comments on commit a82ce88

Please sign in to comment.