otoro-cli 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/config.js +43 -2
- package/package.json +1 -1
package/lib/config.js
CHANGED
|
@@ -6,10 +6,39 @@ const readline = require('readline')
|
|
|
6
6
|
const https = require('https')
|
|
7
7
|
const http = require('http')
|
|
8
8
|
|
|
9
|
+
const crypto = require('crypto')
|
|
10
|
+
|
|
9
11
|
const CONFIG_DIR = path.join(os.homedir(), '.otoro')
|
|
10
12
|
const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json')
|
|
11
13
|
const PROJECT_FILE = '.otoro.json'
|
|
12
14
|
|
|
15
|
+
// Encryption for API key storage — key derived from machine ID
|
|
16
|
+
const ENCRYPTION_KEY = crypto
|
|
17
|
+
.createHash('sha256')
|
|
18
|
+
.update(os.hostname() + os.userInfo().username + '__otoro_seal__')
|
|
19
|
+
.digest()
|
|
20
|
+
|
|
21
|
+
function encrypt(text) {
|
|
22
|
+
const iv = crypto.randomBytes(16)
|
|
23
|
+
const cipher = crypto.createCipheriv('aes-256-cbc', ENCRYPTION_KEY, iv)
|
|
24
|
+
let encrypted = cipher.update(text, 'utf8', 'hex')
|
|
25
|
+
encrypted += cipher.final('hex')
|
|
26
|
+
return iv.toString('hex') + ':' + encrypted
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function decrypt(data) {
|
|
30
|
+
try {
|
|
31
|
+
const [ivHex, encrypted] = data.split(':')
|
|
32
|
+
const iv = Buffer.from(ivHex, 'hex')
|
|
33
|
+
const decipher = crypto.createDecipheriv('aes-256-cbc', ENCRYPTION_KEY, iv)
|
|
34
|
+
let decrypted = decipher.update(encrypted, 'hex', 'utf8')
|
|
35
|
+
decrypted += decipher.final('utf8')
|
|
36
|
+
return decrypted
|
|
37
|
+
} catch {
|
|
38
|
+
return '' // corrupted or wrong machine
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
13
42
|
const DEFAULT_CONFIG = {
|
|
14
43
|
api_url: 'https://otoroagi.com/api/otoro',
|
|
15
44
|
gpu_url: '',
|
|
@@ -23,7 +52,13 @@ const DEFAULT_CONFIG = {
|
|
|
23
52
|
function getConfig() {
|
|
24
53
|
try {
|
|
25
54
|
if (fs.existsSync(CONFIG_FILE)) {
|
|
26
|
-
|
|
55
|
+
const raw = JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'))
|
|
56
|
+
// Decrypt API key if encrypted
|
|
57
|
+
if (raw._api_key_enc) {
|
|
58
|
+
raw.api_key = decrypt(raw._api_key_enc)
|
|
59
|
+
delete raw._api_key_enc
|
|
60
|
+
}
|
|
61
|
+
return { ...DEFAULT_CONFIG, ...raw }
|
|
27
62
|
}
|
|
28
63
|
} catch {}
|
|
29
64
|
return DEFAULT_CONFIG
|
|
@@ -31,7 +66,13 @@ function getConfig() {
|
|
|
31
66
|
|
|
32
67
|
function saveConfig(config) {
|
|
33
68
|
fs.mkdirSync(CONFIG_DIR, { recursive: true })
|
|
34
|
-
|
|
69
|
+
// Encrypt the API key before saving
|
|
70
|
+
const toSave = { ...config }
|
|
71
|
+
if (toSave.api_key) {
|
|
72
|
+
toSave._api_key_enc = encrypt(toSave.api_key)
|
|
73
|
+
delete toSave.api_key
|
|
74
|
+
}
|
|
75
|
+
fs.writeFileSync(CONFIG_FILE, JSON.stringify(toSave, null, 2), { mode: 0o600 })
|
|
35
76
|
}
|
|
36
77
|
|
|
37
78
|
function isLoggedIn() {
|
package/package.json
CHANGED