Skip to content

Commit 7238f93

Browse files
committed
encrypt steam accounts
1 parent f1de631 commit 7238f93

File tree

7 files changed

+77
-3
lines changed

7 files changed

+77
-3
lines changed

.env.example

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ NODE_ENV=development
22
WEB_PORT=3000
33
SOCKET_PORT=8080
44

5+
APP_KEY=
6+
57
DATABASE_URL=postgres://app:secret@localhost:5432/app
68
DATABASE_DEBUG=true
79
DATABASE_SSL=false

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,5 @@ jspm_packages
5252

5353
# Yarn Integrity file
5454
.yarn-integrity
55+
56+
tmp/

config/default.js

+8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const { env } = process;
55

66
module.exports = {
77
env: env.NODE_ENV || 'development',
8+
appKey: env.APP_KEY,
89
webPort: env.WEB_PORT || 3000,
910
socketPort: env.SOCKET_PORT || 8080,
1011

@@ -22,5 +23,12 @@ module.exports = {
2223

2324
steam: {
2425
apiKey: env.STEAM_API_KEY,
26+
accounts: [
27+
{
28+
username: 'chesc0s42',
29+
password: '2ad4faa6fcff3674c2775a244d78ed6c:725afb94b0f9bb95114b81bc',
30+
sharedSecret: '14a5daf4e431ac30b61b3414aa06127c:69cbb6c0535619cd57100ba1cfff4da462e8e19e1a5eda78ee15c829',
31+
},
32+
],
2533
},
2634
};

modules/Encryption.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const crypto = require('crypto');
2+
const config = require('config');
3+
4+
const key = config.get('appKey');
5+
const algorithm = 'aes-256-ctr';
6+
const ivLength = 16;
7+
8+
class Encryption {
9+
static encrypt(text) {
10+
const iv = crypto.randomBytes(ivLength);
11+
const cipher = crypto.createCipheriv(algorithm, Buffer.from(key), iv);
12+
let encrypted = cipher.update(text);
13+
encrypted = Buffer.concat([encrypted, cipher.final()]);
14+
15+
return `${iv.toString('hex')}:${encrypted.toString('hex')}`;
16+
}
17+
18+
static decrypt(text) {
19+
const textParts = text.split(':');
20+
const iv = Buffer.from(textParts.shift(), 'hex');
21+
const encryptedText = Buffer.from(textParts.join(':'), 'hex');
22+
const decipher = crypto.createDecipheriv(algorithm, Buffer.from(key), iv);
23+
let decrypted = decipher.update(encryptedText);
24+
decrypted = Buffer.concat([decrypted, decipher.final()]);
25+
26+
return decrypted.toString();
27+
}
28+
}
29+
30+
module.exports = Encryption;

modules/Inspector.js

+29-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
1+
const config = require('config');
12
const SteamUser = require('steam-user');
23
const GlobalOffensive = require('globaloffensive');
34
const SteamTotp = require('steam-totp');
45
const _ = require('lodash');
56
const logger = require('./Logger');
7+
const Encryption = require('./Encryption');
68

7-
// TODO: Add this to a config or to a database and encrypt it.
8-
const accounts = [];
9+
const accounts = config.get('steam.accounts').map((account) => ({
10+
username: account.username,
11+
password: Encryption.decrypt(account.password),
12+
sharedSecret: Encryption.decrypt(account.sharedSecret),
13+
}));
914

1015
const clients = [];
1116

1217
accounts.forEach((account) => {
13-
const client = new SteamUser();
18+
const client = new SteamUser({
19+
// This is necessary for `ownsApp` to work.
20+
enablePicsCache: true,
21+
});
22+
1423
const csgo = new GlobalOffensive(client);
1524

1625
client.logOn({
@@ -25,6 +34,23 @@ accounts.forEach((account) => {
2534
client.gamesPlayed(730, true);
2635
});
2736

37+
client.on('appOwnershipCached', () => {
38+
// If the account does not own CS:GO yet, claim the free license first.
39+
// This is necessary to connect to the game coordinator via `gamesPlayed`,
40+
// and `gamesPlayed` is necessary to inspect skins.
41+
if (!client.ownsApp(730)) {
42+
client.requestFreeLicense(730, (err) => {
43+
if (err) {
44+
logger.warn('Failed to acquire lisence for CS:GO');
45+
logger.error(err);
46+
} else {
47+
logger.info('Successfully acquired license for CS:GO');
48+
client.gamesPlayed(730, true);
49+
}
50+
});
51+
}
52+
});
53+
2854
client.on('error', (e) => {
2955
// Some error occurred during logon
3056
logger.error('Client error');

package-lock.json

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"colors": "^1.4.0",
1616
"commander": "^5.1.0",
1717
"config": "^3.3.1",
18+
"crypto": "^1.0.1",
1819
"dotenv": "^8.2.0",
1920
"express": "^4.17.1",
2021
"express-validator": "^6.6.0",

0 commit comments

Comments
 (0)