@lethevimlet/sshift 1.1.5 → 1.1.7
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/package.json
CHANGED
|
@@ -15,14 +15,14 @@ function registerUtilsEndpoints(app, io) {
|
|
|
15
15
|
});
|
|
16
16
|
|
|
17
17
|
app.post('/api/utils/convert-key', async (req, res) => {
|
|
18
|
-
const { content } = req.body;
|
|
18
|
+
const { content, passphrase } = req.body;
|
|
19
19
|
if (!content || !content.trim()) {
|
|
20
20
|
return res.status(400).json({ error: 'No key content provided' });
|
|
21
21
|
}
|
|
22
22
|
const info = detectKeyFormat(content);
|
|
23
23
|
if (info.format === 'ppk') {
|
|
24
24
|
try {
|
|
25
|
-
const converted = await convertPPKToOpenSSH(content);
|
|
25
|
+
const converted = await convertPPKToOpenSSH(content, passphrase);
|
|
26
26
|
res.json({ success: true, key: converted, format: 'openssh' });
|
|
27
27
|
} catch (e) {
|
|
28
28
|
res.status(400).json({ error: e.message });
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const { Client } = require('ssh2');
|
|
2
|
+
const { convertKeyIfNeeded } = require('../utils/key-converter');
|
|
2
3
|
|
|
3
4
|
class SFTPManager {
|
|
4
5
|
constructor() {
|
|
@@ -7,7 +8,24 @@ class SFTPManager {
|
|
|
7
8
|
this.nextUploadId = 1;
|
|
8
9
|
}
|
|
9
10
|
|
|
10
|
-
connect(socket, options) {
|
|
11
|
+
async connect(socket, options) {
|
|
12
|
+
// Pre-process private key (auto-convert PPK to OpenSSH format)
|
|
13
|
+
if (options.privateKey && options.privateKey.length > 0) {
|
|
14
|
+
try {
|
|
15
|
+
let keyContent = options.privateKey;
|
|
16
|
+
if (!keyContent.includes('BEGIN')) {
|
|
17
|
+
keyContent = Buffer.from(keyContent, 'base64').toString('utf8');
|
|
18
|
+
}
|
|
19
|
+
options = {
|
|
20
|
+
...options,
|
|
21
|
+
privateKey: await convertKeyIfNeeded(keyContent, options.passphrase)
|
|
22
|
+
};
|
|
23
|
+
} catch (e) {
|
|
24
|
+
console.error('[SFTP] Key conversion failed:', e.message);
|
|
25
|
+
return Promise.reject(new Error(e.message));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
11
29
|
return new Promise((resolve, reject) => {
|
|
12
30
|
const conn = new Client();
|
|
13
31
|
const sessionId = options.sessionId || require('uuid').v4();
|
|
@@ -25,22 +43,12 @@ class SFTPManager {
|
|
|
25
43
|
keepaliveCountMax: options.sshKeepaliveCountMax || 1000
|
|
26
44
|
};
|
|
27
45
|
|
|
28
|
-
// Authentication method
|
|
46
|
+
// Authentication method (key already pre-processed above)
|
|
29
47
|
if (options.password && options.password.length > 0) {
|
|
30
48
|
config.password = options.password;
|
|
31
49
|
console.log('[SFTP] Using password authentication');
|
|
32
50
|
} else if (options.privateKey && options.privateKey.length > 0) {
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
if (options.privateKey.includes('BEGIN')) {
|
|
36
|
-
config.privateKey = options.privateKey;
|
|
37
|
-
} else {
|
|
38
|
-
const decoded = Buffer.from(options.privateKey, 'base64').toString('utf8');
|
|
39
|
-
config.privateKey = decoded;
|
|
40
|
-
}
|
|
41
|
-
} catch (e) {
|
|
42
|
-
config.privateKey = options.privateKey;
|
|
43
|
-
}
|
|
51
|
+
config.privateKey = options.privateKey;
|
|
44
52
|
if (options.passphrase && options.passphrase.length > 0) {
|
|
45
53
|
config.passphrase = options.passphrase;
|
|
46
54
|
}
|
|
@@ -2,6 +2,7 @@ const { Client } = require('ssh2');
|
|
|
2
2
|
const { Terminal } = require('@xterm/headless');
|
|
3
3
|
const { SerializeAddon } = require('@xterm/addon-serialize');
|
|
4
4
|
const pluginManager = require('../plugins/plugin-manager');
|
|
5
|
+
const { convertKeyIfNeeded } = require('../utils/key-converter');
|
|
5
6
|
|
|
6
7
|
class SSHManager {
|
|
7
8
|
constructor() {
|
|
@@ -18,7 +19,24 @@ class SSHManager {
|
|
|
18
19
|
this.io = io;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
connect(socket, options) {
|
|
22
|
+
async connect(socket, options) {
|
|
23
|
+
// Pre-process private key (auto-convert PPK to OpenSSH format)
|
|
24
|
+
if (options.privateKey && options.privateKey.length > 0) {
|
|
25
|
+
try {
|
|
26
|
+
let keyContent = options.privateKey;
|
|
27
|
+
if (!keyContent.includes('BEGIN')) {
|
|
28
|
+
keyContent = Buffer.from(keyContent, 'base64').toString('utf8');
|
|
29
|
+
}
|
|
30
|
+
options = {
|
|
31
|
+
...options,
|
|
32
|
+
privateKey: await convertKeyIfNeeded(keyContent, options.passphrase)
|
|
33
|
+
};
|
|
34
|
+
} catch (e) {
|
|
35
|
+
console.error('[SSH] Key conversion failed:', e.message);
|
|
36
|
+
return Promise.reject(new Error(e.message));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
22
40
|
return new Promise((resolve, reject) => {
|
|
23
41
|
const conn = new Client();
|
|
24
42
|
const sessionId = options.sessionId || require('uuid').v4();
|
|
@@ -78,22 +96,12 @@ class SSHManager {
|
|
|
78
96
|
keepaliveCountMax: options.sshKeepaliveCountMax || 1000
|
|
79
97
|
};
|
|
80
98
|
|
|
81
|
-
// Authentication method
|
|
99
|
+
// Authentication method (key already pre-processed above)
|
|
82
100
|
if (options.password && options.password.length > 0) {
|
|
83
101
|
config.password = options.password;
|
|
84
102
|
console.log('[SSH] Using password authentication');
|
|
85
103
|
} else if (options.privateKey && options.privateKey.length > 0) {
|
|
86
|
-
|
|
87
|
-
try {
|
|
88
|
-
if (options.privateKey.includes('BEGIN')) {
|
|
89
|
-
config.privateKey = options.privateKey;
|
|
90
|
-
} else {
|
|
91
|
-
const decoded = Buffer.from(options.privateKey, 'base64').toString('utf8');
|
|
92
|
-
config.privateKey = decoded;
|
|
93
|
-
}
|
|
94
|
-
} catch (e) {
|
|
95
|
-
config.privateKey = options.privateKey;
|
|
96
|
-
}
|
|
104
|
+
config.privateKey = options.privateKey;
|
|
97
105
|
if (options.passphrase && options.passphrase.length > 0) {
|
|
98
106
|
config.passphrase = options.passphrase;
|
|
99
107
|
}
|
|
@@ -51,7 +51,7 @@ function detectKeyFormat(keyContent) {
|
|
|
51
51
|
return { format: 'unknown', type: 'unknown' };
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
function convertPPKViaPuttygen(ppkContent) {
|
|
54
|
+
function convertPPKViaPuttygen(ppkContent, passphrase) {
|
|
55
55
|
return new Promise((resolve, reject) => {
|
|
56
56
|
const tmpDir = os.tmpdir();
|
|
57
57
|
const inputFile = path.join(tmpDir, `sshift-ppk-${Date.now()}-${Math.random().toString(36).slice(2)}.ppk`);
|
|
@@ -63,29 +63,86 @@ function convertPPKViaPuttygen(ppkContent) {
|
|
|
63
63
|
return reject(new Error('Failed to write temporary PPK file: ' + writeErr.message));
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
const args = [inputFile, '-O', 'private-openssh-new', '-o', outputFile];
|
|
67
|
+
if (passphrase) {
|
|
68
|
+
args.splice(1, 0, `--old-passphrase=${passphrase}`);
|
|
69
|
+
}
|
|
68
70
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
'. If the PPK file is encrypted, decrypt it first using PuTTYgen.'
|
|
74
|
-
));
|
|
71
|
+
execFile('puttygen', args, (err, stdout, stderr) => {
|
|
72
|
+
if (err && passphrase) {
|
|
73
|
+
tryConvertPPKWithPassphraseFile(inputFile, outputFile, passphrase, resolve, reject);
|
|
74
|
+
return;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
try { fs.unlinkSync(outputFile); } catch (e) { /* ignore */ }
|
|
79
|
-
if (readErr) {
|
|
80
|
-
return reject(new Error('Failed to read converted key: ' + readErr.message));
|
|
81
|
-
}
|
|
82
|
-
resolve(data);
|
|
83
|
-
});
|
|
77
|
+
cleanupAndResolve(err, stdout, stderr, inputFile, outputFile, reject, resolve);
|
|
84
78
|
});
|
|
85
79
|
});
|
|
86
80
|
});
|
|
87
81
|
}
|
|
88
82
|
|
|
83
|
+
function tryConvertPPKWithPassphraseFile(inputFile, outputFile, passphrase, resolve, reject) {
|
|
84
|
+
const tmpDir = os.tmpdir();
|
|
85
|
+
const passphraseFile = path.join(tmpDir, `sshift-ppk-pass-${Date.now()}-${Math.random().toString(36).slice(2)}.txt`);
|
|
86
|
+
|
|
87
|
+
fs.writeFile(passphraseFile, passphrase, { mode: 0o600 }, (writeErr) => {
|
|
88
|
+
if (writeErr) {
|
|
89
|
+
cleanupTempFiles([inputFile, outputFile]);
|
|
90
|
+
return reject(new Error(
|
|
91
|
+
'Failed to write passphrase file for PPK conversion: ' + writeErr.message
|
|
92
|
+
));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const args = [inputFile, '-O', 'private-openssh-new', '-o', outputFile, `--old-passphrase-file=${passphraseFile}`];
|
|
96
|
+
|
|
97
|
+
execFile('puttygen', args, (err, stdout, stderr) => {
|
|
98
|
+
try { fs.unlinkSync(passphraseFile); } catch (e) { /* ignore */ }
|
|
99
|
+
|
|
100
|
+
if (err) {
|
|
101
|
+
cleanupTempFiles([inputFile, outputFile]);
|
|
102
|
+
return reject(new Error(
|
|
103
|
+
'puttygen conversion failed: ' + (stderr || err.message) +
|
|
104
|
+
'. Ensure puttygen is installed and the passphrase is correct.'
|
|
105
|
+
));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
fs.readFile(outputFile, 'utf8', (readErr, data) => {
|
|
109
|
+
try { fs.unlinkSync(inputFile); } catch (e) { /* ignore */ }
|
|
110
|
+
try { fs.unlinkSync(outputFile); } catch (e) { /* ignore */ }
|
|
111
|
+
if (readErr) {
|
|
112
|
+
return reject(new Error('Failed to read converted key: ' + readErr.message));
|
|
113
|
+
}
|
|
114
|
+
resolve(data);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function cleanupTempFiles(files) {
|
|
121
|
+
for (const f of files) {
|
|
122
|
+
try { fs.unlinkSync(f); } catch (e) { /* ignore */ }
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function cleanupAndResolve(err, stdout, stderr, inputFile, outputFile, reject, resolve) {
|
|
127
|
+
try { fs.unlinkSync(inputFile); } catch (e) { /* ignore */ }
|
|
128
|
+
|
|
129
|
+
if (err) {
|
|
130
|
+
try { fs.unlinkSync(outputFile); } catch (e) { /* ignore */ }
|
|
131
|
+
return reject(new Error(
|
|
132
|
+
'puttygen conversion failed: ' + (stderr || err.message) +
|
|
133
|
+
'. If the PPK file is encrypted, provide the correct passphrase.'
|
|
134
|
+
));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
fs.readFile(outputFile, 'utf8', (readErr, data) => {
|
|
138
|
+
try { fs.unlinkSync(outputFile); } catch (e) { /* ignore */ }
|
|
139
|
+
if (readErr) {
|
|
140
|
+
return reject(new Error('Failed to read converted key: ' + readErr.message));
|
|
141
|
+
}
|
|
142
|
+
resolve(data);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
89
146
|
function convertPPKV2ToOpenSSH(ppkContent) {
|
|
90
147
|
const lines = ppkContent.split('\n');
|
|
91
148
|
|
|
@@ -324,31 +381,37 @@ function encodeOpenSSHPrivateKey(keyParts) {
|
|
|
324
381
|
return `-----BEGIN OPENSSH PRIVATE KEY-----\n${lines.join('\n')}\n-----END OPENSSH PRIVATE KEY-----\n`;
|
|
325
382
|
}
|
|
326
383
|
|
|
327
|
-
async function convertPPKToOpenSSH(ppkContent) {
|
|
384
|
+
async function convertPPKToOpenSSH(ppkContent, passphrase) {
|
|
328
385
|
const info = detectKeyFormat(ppkContent);
|
|
329
386
|
|
|
330
387
|
if (info.format !== 'ppk') {
|
|
331
388
|
throw new Error('Not a PPK key');
|
|
332
389
|
}
|
|
333
390
|
|
|
334
|
-
if (info.encrypted) {
|
|
391
|
+
if (info.encrypted && !passphrase) {
|
|
335
392
|
throw new Error(
|
|
336
|
-
'This PPK key is encrypted.
|
|
337
|
-
'load the PPK, enter the passphrase, then export as OpenSSH key.'
|
|
393
|
+
'This PPK key is encrypted. Provide a passphrase or decrypt it first using PuTTYgen.'
|
|
338
394
|
);
|
|
339
395
|
}
|
|
340
396
|
|
|
341
|
-
// Try puttygen first (handles all PPK versions including v3)
|
|
397
|
+
// Try puttygen first (handles all PPK versions including v3 and encrypted)
|
|
342
398
|
try {
|
|
343
|
-
const result = await convertPPKViaPuttygen(ppkContent);
|
|
344
|
-
if (result && result.includes('BEGIN
|
|
399
|
+
const result = await convertPPKViaPuttygen(ppkContent, passphrase);
|
|
400
|
+
if (result && result.includes('BEGIN')) {
|
|
345
401
|
return result;
|
|
346
402
|
}
|
|
347
403
|
} catch (e) {
|
|
348
|
-
// puttygen
|
|
404
|
+
// If puttygen failed and key is encrypted, don't try built-in (it can't handle encryption)
|
|
405
|
+
if (info.encrypted) {
|
|
406
|
+
throw new Error(
|
|
407
|
+
'Could not convert encrypted PPK key: ' + e.message +
|
|
408
|
+
'. Ensure puttygen is installed and the passphrase is correct.'
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
// puttygen not available, try built-in v2 parser for unencrypted keys
|
|
349
412
|
}
|
|
350
413
|
|
|
351
|
-
// Fall back to built-in PPK v2 converter
|
|
414
|
+
// Fall back to built-in PPK v2 converter (unencrypted only)
|
|
352
415
|
try {
|
|
353
416
|
return convertPPKV2ToOpenSSH(ppkContent);
|
|
354
417
|
} catch (e) {
|
|
@@ -360,4 +423,22 @@ async function convertPPKToOpenSSH(ppkContent) {
|
|
|
360
423
|
}
|
|
361
424
|
}
|
|
362
425
|
|
|
363
|
-
|
|
426
|
+
async function convertKeyIfNeeded(keyContent, passphrase) {
|
|
427
|
+
if (!keyContent || !keyContent.trim()) {
|
|
428
|
+
return keyContent;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
const info = detectKeyFormat(keyContent);
|
|
432
|
+
if (info.format !== 'ppk') {
|
|
433
|
+
return keyContent;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
try {
|
|
437
|
+
const converted = await convertPPKToOpenSSH(keyContent, passphrase);
|
|
438
|
+
return converted;
|
|
439
|
+
} catch (e) {
|
|
440
|
+
throw new Error('PPK key conversion failed: ' + e.message);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
module.exports = { detectKeyFormat, convertPPKToOpenSSH, convertKeyIfNeeded };
|
package/src/webapp/js/app.js
CHANGED
|
@@ -307,7 +307,7 @@ class SSHIFTClient {
|
|
|
307
307
|
}
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
-
_showPasswordModal(options, onSubmit) {
|
|
310
|
+
_showPasswordModal(options, onSubmit, onCancel) {
|
|
311
311
|
const modal = document.getElementById('passwordModal');
|
|
312
312
|
const title = document.getElementById('passwordModalTitle');
|
|
313
313
|
const label = document.getElementById('passwordModalLabel');
|
|
@@ -357,8 +357,8 @@ class SSHIFTClient {
|
|
|
357
357
|
await onSubmit(password);
|
|
358
358
|
};
|
|
359
359
|
|
|
360
|
-
const handleCancel = () => cleanup();
|
|
361
|
-
const handleBackdrop = (e) => { if (e.target === modal) cleanup(); };
|
|
360
|
+
const handleCancel = () => { cleanup(); if (onCancel) onCancel(); };
|
|
361
|
+
const handleBackdrop = (e) => { if (e.target === modal) { cleanup(); if (onCancel) onCancel(); } };
|
|
362
362
|
const handleKeydown = (e) => { if (e.key === 'Enter') handleSubmit(); };
|
|
363
363
|
|
|
364
364
|
submitBtn.addEventListener('click', handleSubmit);
|
|
@@ -5819,6 +5819,9 @@ const wheelHandler = (e) => {
|
|
|
5819
5819
|
const clearBtn = document.getElementById(clearBtnId);
|
|
5820
5820
|
const textarea = document.getElementById(textareaId);
|
|
5821
5821
|
|
|
5822
|
+
const passphraseId = textareaId === 'connPrivateKey' ? 'connPassphrase' : 'bookmarkPassphrase';
|
|
5823
|
+
const passphraseEl = document.getElementById(passphraseId);
|
|
5824
|
+
|
|
5822
5825
|
badge.style.display = 'inline-flex';
|
|
5823
5826
|
badge.textContent = 'Reading...';
|
|
5824
5827
|
badge.className = 'key-format-badge';
|
|
@@ -5832,8 +5835,43 @@ const wheelHandler = (e) => {
|
|
|
5832
5835
|
return;
|
|
5833
5836
|
}
|
|
5834
5837
|
|
|
5835
|
-
|
|
5838
|
+
let passphrase = passphraseEl ? passphraseEl.value : '';
|
|
5839
|
+
|
|
5840
|
+
if (!passphrase) {
|
|
5841
|
+
const needsPassphrase = this._keyNeedsPassphrase(content);
|
|
5842
|
+
if (needsPassphrase) {
|
|
5843
|
+
const promptedPassphrase = await this._promptForKeyPassphrase();
|
|
5844
|
+
if (promptedPassphrase === null) {
|
|
5845
|
+
badge.textContent = 'Encrypted key';
|
|
5846
|
+
badge.classList.add('format-warning');
|
|
5847
|
+
badge.style.display = 'inline-flex';
|
|
5848
|
+
textarea.value = content;
|
|
5849
|
+
clearBtn.style.display = 'inline-flex';
|
|
5850
|
+
this.showToast('Encrypted key requires a passphrase', 'info');
|
|
5851
|
+
event.target.value = '';
|
|
5852
|
+
return;
|
|
5853
|
+
}
|
|
5854
|
+
passphrase = promptedPassphrase;
|
|
5855
|
+
if (passphraseEl) passphraseEl.value = passphrase;
|
|
5856
|
+
}
|
|
5857
|
+
}
|
|
5858
|
+
|
|
5859
|
+
const detectResult = await this.detectAndConvertKey(content, passphrase);
|
|
5836
5860
|
if (detectResult.error) {
|
|
5861
|
+
if (this._isPassphraseError(detectResult.error) && !passphrase) {
|
|
5862
|
+
const promptedPassphrase = await this._promptForKeyPassphrase();
|
|
5863
|
+
if (promptedPassphrase !== null) {
|
|
5864
|
+
passphrase = promptedPassphrase;
|
|
5865
|
+
if (passphraseEl) passphraseEl.value = passphrase;
|
|
5866
|
+
const retryResult = await this.detectAndConvertKey(content, passphrase);
|
|
5867
|
+
if (!retryResult.error) {
|
|
5868
|
+
this._applyKeyResult(textarea, badge, clearBtn, retryResult);
|
|
5869
|
+
event.target.value = '';
|
|
5870
|
+
return;
|
|
5871
|
+
}
|
|
5872
|
+
this.showToast(retryResult.error, 'error');
|
|
5873
|
+
}
|
|
5874
|
+
}
|
|
5837
5875
|
badge.textContent = detectResult.format || 'Error';
|
|
5838
5876
|
badge.classList.add('format-error');
|
|
5839
5877
|
badge.style.display = 'inline-flex';
|
|
@@ -5843,44 +5881,7 @@ const wheelHandler = (e) => {
|
|
|
5843
5881
|
return;
|
|
5844
5882
|
}
|
|
5845
5883
|
|
|
5846
|
-
textarea
|
|
5847
|
-
|
|
5848
|
-
let formatLabel = detectResult.format;
|
|
5849
|
-
if (detectResult.wasConverted) {
|
|
5850
|
-
formatLabel = `PPK → OpenSSH`;
|
|
5851
|
-
} else if (detectResult.format === 'openssh') {
|
|
5852
|
-
formatLabel = 'OpenSSH';
|
|
5853
|
-
} else if (detectResult.format === 'pem-rsa') {
|
|
5854
|
-
formatLabel = 'PEM (RSA)';
|
|
5855
|
-
} else if (detectResult.format === 'pem-ec') {
|
|
5856
|
-
formatLabel = 'PEM (EC)';
|
|
5857
|
-
} else if (detectResult.format === 'pem-dsa') {
|
|
5858
|
-
formatLabel = 'PEM (DSA)';
|
|
5859
|
-
} else if (detectResult.format === 'pkcs8') {
|
|
5860
|
-
formatLabel = 'PKCS8';
|
|
5861
|
-
} else if (detectResult.format === 'pkcs8-encrypted') {
|
|
5862
|
-
formatLabel = 'PKCS8 (Encrypted)';
|
|
5863
|
-
}
|
|
5864
|
-
|
|
5865
|
-
badge.textContent = formatLabel;
|
|
5866
|
-
badge.className = 'key-format-badge';
|
|
5867
|
-
if (detectResult.encrypted) {
|
|
5868
|
-
badge.classList.add('format-warning');
|
|
5869
|
-
}
|
|
5870
|
-
badge.style.display = 'inline-flex';
|
|
5871
|
-
clearBtn.style.display = 'inline-flex';
|
|
5872
|
-
|
|
5873
|
-
if (detectResult.wasConverted) {
|
|
5874
|
-
this.showToast('PPK key converted to OpenSSH format', 'success');
|
|
5875
|
-
} else if (detectResult.format === 'openssh') {
|
|
5876
|
-
this.showToast('OpenSSH key loaded', 'success');
|
|
5877
|
-
} else if (detectResult.format === 'pem-rsa' || detectResult.format === 'pem-ec' || detectResult.format === 'pem-dsa') {
|
|
5878
|
-
this.showToast('PEM key loaded', 'success');
|
|
5879
|
-
} else if (detectResult.format === 'pkcs8') {
|
|
5880
|
-
this.showToast('PKCS8 key loaded', 'success');
|
|
5881
|
-
} else if (detectResult.format === 'pkcs8-encrypted') {
|
|
5882
|
-
this.showToast('Encrypted PKCS8 key loaded - passphrase required', 'info');
|
|
5883
|
-
}
|
|
5884
|
+
this._applyKeyResult(textarea, badge, clearBtn, detectResult);
|
|
5884
5885
|
} catch (err) {
|
|
5885
5886
|
badge.textContent = 'Error';
|
|
5886
5887
|
badge.classList.add('format-error');
|
|
@@ -5891,7 +5892,86 @@ const wheelHandler = (e) => {
|
|
|
5891
5892
|
event.target.value = '';
|
|
5892
5893
|
}
|
|
5893
5894
|
|
|
5894
|
-
|
|
5895
|
+
_keyNeedsPassphrase(content) {
|
|
5896
|
+
const trimmed = (content || '').trim();
|
|
5897
|
+
if (/^PuTTY-User-Key-File-/im.test(trimmed)) {
|
|
5898
|
+
const lines = trimmed.split('\n');
|
|
5899
|
+
for (const line of lines) {
|
|
5900
|
+
const colonIdx = line.indexOf(':');
|
|
5901
|
+
if (colonIdx !== -1) {
|
|
5902
|
+
const key = line.substring(0, colonIdx).trim();
|
|
5903
|
+
const value = line.substring(colonIdx + 1).trim();
|
|
5904
|
+
if (key === 'Encryption' && value !== 'none') return true;
|
|
5905
|
+
}
|
|
5906
|
+
}
|
|
5907
|
+
}
|
|
5908
|
+
if (trimmed.includes('-----BEGIN ENCRYPTED PRIVATE KEY-----')) return true;
|
|
5909
|
+
if (trimmed.includes('ENCRYPTED') && trimmed.includes('-----BEGIN')) return true;
|
|
5910
|
+
return false;
|
|
5911
|
+
}
|
|
5912
|
+
|
|
5913
|
+
_promptForKeyPassphrase() {
|
|
5914
|
+
return new Promise((resolve) => {
|
|
5915
|
+
this._showPasswordModal(
|
|
5916
|
+
{
|
|
5917
|
+
title: 'Encrypted Key',
|
|
5918
|
+
label: 'Enter the key passphrase',
|
|
5919
|
+
confirmText: 'Decrypt'
|
|
5920
|
+
},
|
|
5921
|
+
(passphrase) => { resolve(passphrase); },
|
|
5922
|
+
() => { resolve(null); }
|
|
5923
|
+
);
|
|
5924
|
+
});
|
|
5925
|
+
}
|
|
5926
|
+
|
|
5927
|
+
_isPassphraseError(errorMessage) {
|
|
5928
|
+
if (!errorMessage) return false;
|
|
5929
|
+
const lower = errorMessage.toLowerCase();
|
|
5930
|
+
return lower.includes('encrypted') || lower.includes('passphrase') || lower.includes('password');
|
|
5931
|
+
}
|
|
5932
|
+
|
|
5933
|
+
_applyKeyResult(textarea, badge, clearBtn, detectResult) {
|
|
5934
|
+
textarea.value = detectResult.key;
|
|
5935
|
+
|
|
5936
|
+
let formatLabel = detectResult.format;
|
|
5937
|
+
if (detectResult.wasConverted) {
|
|
5938
|
+
formatLabel = `PPK → OpenSSH`;
|
|
5939
|
+
} else if (detectResult.format === 'openssh') {
|
|
5940
|
+
formatLabel = 'OpenSSH';
|
|
5941
|
+
} else if (detectResult.format === 'pem-rsa') {
|
|
5942
|
+
formatLabel = 'PEM (RSA)';
|
|
5943
|
+
} else if (detectResult.format === 'pem-ec') {
|
|
5944
|
+
formatLabel = 'PEM (EC)';
|
|
5945
|
+
} else if (detectResult.format === 'pem-dsa') {
|
|
5946
|
+
formatLabel = 'PEM (DSA)';
|
|
5947
|
+
} else if (detectResult.format === 'pkcs8') {
|
|
5948
|
+
formatLabel = 'PKCS8';
|
|
5949
|
+
} else if (detectResult.format === 'pkcs8-encrypted') {
|
|
5950
|
+
formatLabel = 'PKCS8 (Encrypted)';
|
|
5951
|
+
}
|
|
5952
|
+
|
|
5953
|
+
badge.textContent = formatLabel;
|
|
5954
|
+
badge.className = 'key-format-badge';
|
|
5955
|
+
if (detectResult.encrypted) {
|
|
5956
|
+
badge.classList.add('format-warning');
|
|
5957
|
+
}
|
|
5958
|
+
badge.style.display = 'inline-flex';
|
|
5959
|
+
clearBtn.style.display = 'inline-flex';
|
|
5960
|
+
|
|
5961
|
+
if (detectResult.wasConverted) {
|
|
5962
|
+
this.showToast('PPK key converted to OpenSSH format', 'success');
|
|
5963
|
+
} else if (detectResult.format === 'openssh') {
|
|
5964
|
+
this.showToast('OpenSSH key loaded', 'success');
|
|
5965
|
+
} else if (detectResult.format === 'pem-rsa' || detectResult.format === 'pem-ec' || detectResult.format === 'pem-dsa') {
|
|
5966
|
+
this.showToast('PEM key loaded', 'success');
|
|
5967
|
+
} else if (detectResult.format === 'pkcs8') {
|
|
5968
|
+
this.showToast('PKCS8 key loaded', 'success');
|
|
5969
|
+
} else if (detectResult.format === 'pkcs8-encrypted') {
|
|
5970
|
+
this.showToast('Encrypted PKCS8 key loaded - passphrase required for connection', 'info');
|
|
5971
|
+
}
|
|
5972
|
+
}
|
|
5973
|
+
|
|
5974
|
+
async detectAndConvertKey(content, passphrase) {
|
|
5895
5975
|
try {
|
|
5896
5976
|
const response = await fetch('/api/utils/detect-key', {
|
|
5897
5977
|
method: 'POST',
|
|
@@ -5910,7 +5990,7 @@ const wheelHandler = (e) => {
|
|
|
5910
5990
|
const convertResponse = await fetch('/api/utils/convert-key', {
|
|
5911
5991
|
method: 'POST',
|
|
5912
5992
|
headers: { 'Content-Type': 'application/json' },
|
|
5913
|
-
body: JSON.stringify({ content })
|
|
5993
|
+
body: JSON.stringify({ content, passphrase: passphrase || '' })
|
|
5914
5994
|
});
|
|
5915
5995
|
|
|
5916
5996
|
if (!convertResponse.ok) {
|
|
@@ -5963,7 +6043,7 @@ const wheelHandler = (e) => {
|
|
|
5963
6043
|
encrypted: info.encrypted || false
|
|
5964
6044
|
};
|
|
5965
6045
|
} catch (e) {
|
|
5966
|
-
if (
|
|
6046
|
+
if (/PuTTY-User-Key-File-/i.test(content)) {
|
|
5967
6047
|
return {
|
|
5968
6048
|
format: 'PPK',
|
|
5969
6049
|
key: content,
|
|
@@ -5987,7 +6067,7 @@ const wheelHandler = (e) => {
|
|
|
5987
6067
|
if (content.includes('BEGIN DSA PRIVATE KEY')) return 'pem-dsa';
|
|
5988
6068
|
if (content.includes('BEGIN PRIVATE KEY')) return 'pkcs8';
|
|
5989
6069
|
if (content.includes('BEGIN ENCRYPTED PRIVATE KEY')) return 'pkcs8-encrypted';
|
|
5990
|
-
if (
|
|
6070
|
+
if (/PuTTY-User-Key-File-/i.test(content)) return 'ppk';
|
|
5991
6071
|
return 'unknown';
|
|
5992
6072
|
}
|
|
5993
6073
|
|
|
@@ -10001,7 +10081,7 @@ async syncTabsFromServer(tabs) {
|
|
|
10001
10081
|
}
|
|
10002
10082
|
}
|
|
10003
10083
|
|
|
10004
|
-
connectFromBookmark(bookmark) {
|
|
10084
|
+
async connectFromBookmark(bookmark) {
|
|
10005
10085
|
// Close sidebar on mobile when connecting
|
|
10006
10086
|
const isMobile = window.innerWidth <= 768;
|
|
10007
10087
|
if (isMobile) {
|
|
@@ -10019,7 +10099,7 @@ async syncTabsFromServer(tabs) {
|
|
|
10019
10099
|
return;
|
|
10020
10100
|
}
|
|
10021
10101
|
|
|
10022
|
-
//
|
|
10102
|
+
// Build connection data from bookmark
|
|
10023
10103
|
const connectionData = {
|
|
10024
10104
|
name: bookmark.name,
|
|
10025
10105
|
host: bookmark.host,
|
|
@@ -10030,6 +10110,23 @@ async syncTabsFromServer(tabs) {
|
|
|
10030
10110
|
passphrase: bookmark.passphrase || ''
|
|
10031
10111
|
};
|
|
10032
10112
|
|
|
10113
|
+
// Auto-convert PPK keys to OpenSSH format before connecting
|
|
10114
|
+
if (connectionData.privateKey && /PuTTY-User-Key-File-/i.test(connectionData.privateKey)) {
|
|
10115
|
+
try {
|
|
10116
|
+
const convertResult = await this.detectAndConvertKey(connectionData.privateKey);
|
|
10117
|
+
if (convertResult.key && !convertResult.error) {
|
|
10118
|
+
connectionData.privateKey = convertResult.key;
|
|
10119
|
+
this.showToast('PPK key converted to OpenSSH format', 'success');
|
|
10120
|
+
} else if (convertResult.error) {
|
|
10121
|
+
this.showToast('PPK key conversion failed: ' + convertResult.error, 'error');
|
|
10122
|
+
return;
|
|
10123
|
+
}
|
|
10124
|
+
} catch (e) {
|
|
10125
|
+
this.showToast('PPK key conversion failed: ' + e.message, 'error');
|
|
10126
|
+
return;
|
|
10127
|
+
}
|
|
10128
|
+
}
|
|
10129
|
+
|
|
10033
10130
|
// Show connecting status
|
|
10034
10131
|
this.showToast(`Connecting to ${bookmark.name}...`, 'info');
|
|
10035
10132
|
|
|
@@ -10042,7 +10139,7 @@ async syncTabsFromServer(tabs) {
|
|
|
10042
10139
|
}
|
|
10043
10140
|
}
|
|
10044
10141
|
|
|
10045
|
-
openSFTPFromBookmark(bookmark) {
|
|
10142
|
+
async openSFTPFromBookmark(bookmark) {
|
|
10046
10143
|
// Close sidebar on mobile when opening SFTP
|
|
10047
10144
|
const isMobile = window.innerWidth <= 768;
|
|
10048
10145
|
if (isMobile) {
|
|
@@ -10052,7 +10149,7 @@ async syncTabsFromServer(tabs) {
|
|
|
10052
10149
|
if (sidebarOverlay) sidebarOverlay.classList.remove('active');
|
|
10053
10150
|
}
|
|
10054
10151
|
|
|
10055
|
-
//
|
|
10152
|
+
// Build connection data from bookmark
|
|
10056
10153
|
const connectionData = {
|
|
10057
10154
|
name: `${bookmark.name} (SFTP)`,
|
|
10058
10155
|
host: bookmark.host,
|
|
@@ -10063,6 +10160,23 @@ async syncTabsFromServer(tabs) {
|
|
|
10063
10160
|
passphrase: bookmark.passphrase || ''
|
|
10064
10161
|
};
|
|
10065
10162
|
|
|
10163
|
+
// Auto-convert PPK keys to OpenSSH format before connecting
|
|
10164
|
+
if (connectionData.privateKey && /PuTTY-User-Key-File-/i.test(connectionData.privateKey)) {
|
|
10165
|
+
try {
|
|
10166
|
+
const convertResult = await this.detectAndConvertKey(connectionData.privateKey);
|
|
10167
|
+
if (convertResult.key && !convertResult.error) {
|
|
10168
|
+
connectionData.privateKey = convertResult.key;
|
|
10169
|
+
this.showToast('PPK key converted to OpenSSH format', 'success');
|
|
10170
|
+
} else if (convertResult.error) {
|
|
10171
|
+
this.showToast('PPK key conversion failed: ' + convertResult.error, 'error');
|
|
10172
|
+
return;
|
|
10173
|
+
}
|
|
10174
|
+
} catch (e) {
|
|
10175
|
+
this.showToast('PPK key conversion failed: ' + e.message, 'error');
|
|
10176
|
+
return;
|
|
10177
|
+
}
|
|
10178
|
+
}
|
|
10179
|
+
|
|
10066
10180
|
// Show connecting status
|
|
10067
10181
|
this.showToast(`Opening SFTP for ${bookmark.name}...`, 'info');
|
|
10068
10182
|
|