@lethevimlet/sshift 1.1.5 → 1.1.6
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,23 @@ 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
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
11
28
|
return new Promise((resolve, reject) => {
|
|
12
29
|
const conn = new Client();
|
|
13
30
|
const sessionId = options.sessionId || require('uuid').v4();
|
|
@@ -25,22 +42,12 @@ class SFTPManager {
|
|
|
25
42
|
keepaliveCountMax: options.sshKeepaliveCountMax || 1000
|
|
26
43
|
};
|
|
27
44
|
|
|
28
|
-
// Authentication method
|
|
45
|
+
// Authentication method (key already pre-processed above)
|
|
29
46
|
if (options.password && options.password.length > 0) {
|
|
30
47
|
config.password = options.password;
|
|
31
48
|
console.log('[SFTP] Using password authentication');
|
|
32
49
|
} 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
|
-
}
|
|
50
|
+
config.privateKey = options.privateKey;
|
|
44
51
|
if (options.passphrase && options.passphrase.length > 0) {
|
|
45
52
|
config.passphrase = options.passphrase;
|
|
46
53
|
}
|
|
@@ -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,23 @@ 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
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
22
39
|
return new Promise((resolve, reject) => {
|
|
23
40
|
const conn = new Client();
|
|
24
41
|
const sessionId = options.sessionId || require('uuid').v4();
|
|
@@ -78,22 +95,12 @@ class SSHManager {
|
|
|
78
95
|
keepaliveCountMax: options.sshKeepaliveCountMax || 1000
|
|
79
96
|
};
|
|
80
97
|
|
|
81
|
-
// Authentication method
|
|
98
|
+
// Authentication method (key already pre-processed above)
|
|
82
99
|
if (options.password && options.password.length > 0) {
|
|
83
100
|
config.password = options.password;
|
|
84
101
|
console.log('[SSH] Using password authentication');
|
|
85
102
|
} 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
|
-
}
|
|
103
|
+
config.privateKey = options.privateKey;
|
|
97
104
|
if (options.passphrase && options.passphrase.length > 0) {
|
|
98
105
|
config.passphrase = options.passphrase;
|
|
99
106
|
}
|
|
@@ -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,14 +63,19 @@ function convertPPKViaPuttygen(ppkContent) {
|
|
|
63
63
|
return reject(new Error('Failed to write temporary PPK file: ' + writeErr.message));
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
const args = [inputFile, '-O', 'private-openssh-new', '-o', outputFile];
|
|
67
|
+
if (passphrase) {
|
|
68
|
+
args.splice(1, 0, '--old-passphrase', passphrase);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
execFile('puttygen', args, (err, stdout, stderr) => {
|
|
67
72
|
try { fs.unlinkSync(inputFile); } catch (e) { /* ignore */ }
|
|
68
73
|
|
|
69
74
|
if (err) {
|
|
70
75
|
try { fs.unlinkSync(outputFile); } catch (e) { /* ignore */ }
|
|
71
76
|
return reject(new Error(
|
|
72
77
|
'puttygen conversion failed: ' + (stderr || err.message) +
|
|
73
|
-
'. If the PPK file is encrypted,
|
|
78
|
+
'. If the PPK file is encrypted, provide the correct passphrase.'
|
|
74
79
|
));
|
|
75
80
|
}
|
|
76
81
|
|
|
@@ -324,31 +329,37 @@ function encodeOpenSSHPrivateKey(keyParts) {
|
|
|
324
329
|
return `-----BEGIN OPENSSH PRIVATE KEY-----\n${lines.join('\n')}\n-----END OPENSSH PRIVATE KEY-----\n`;
|
|
325
330
|
}
|
|
326
331
|
|
|
327
|
-
async function convertPPKToOpenSSH(ppkContent) {
|
|
332
|
+
async function convertPPKToOpenSSH(ppkContent, passphrase) {
|
|
328
333
|
const info = detectKeyFormat(ppkContent);
|
|
329
334
|
|
|
330
335
|
if (info.format !== 'ppk') {
|
|
331
336
|
throw new Error('Not a PPK key');
|
|
332
337
|
}
|
|
333
338
|
|
|
334
|
-
if (info.encrypted) {
|
|
339
|
+
if (info.encrypted && !passphrase) {
|
|
335
340
|
throw new Error(
|
|
336
|
-
'This PPK key is encrypted.
|
|
337
|
-
'load the PPK, enter the passphrase, then export as OpenSSH key.'
|
|
341
|
+
'This PPK key is encrypted. Provide a passphrase or decrypt it first using PuTTYgen.'
|
|
338
342
|
);
|
|
339
343
|
}
|
|
340
344
|
|
|
341
|
-
// Try puttygen first (handles all PPK versions including v3)
|
|
345
|
+
// Try puttygen first (handles all PPK versions including v3 and encrypted)
|
|
342
346
|
try {
|
|
343
|
-
const result = await convertPPKViaPuttygen(ppkContent);
|
|
344
|
-
if (result && result.includes('BEGIN
|
|
347
|
+
const result = await convertPPKViaPuttygen(ppkContent, passphrase);
|
|
348
|
+
if (result && result.includes('BEGIN')) {
|
|
345
349
|
return result;
|
|
346
350
|
}
|
|
347
351
|
} catch (e) {
|
|
348
|
-
// puttygen
|
|
352
|
+
// If puttygen failed and key is encrypted, don't try built-in (it can't handle encryption)
|
|
353
|
+
if (info.encrypted) {
|
|
354
|
+
throw new Error(
|
|
355
|
+
'Could not convert encrypted PPK key: ' + e.message +
|
|
356
|
+
'. Ensure puttygen is installed and the passphrase is correct.'
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
// puttygen not available, try built-in v2 parser for unencrypted keys
|
|
349
360
|
}
|
|
350
361
|
|
|
351
|
-
// Fall back to built-in PPK v2 converter
|
|
362
|
+
// Fall back to built-in PPK v2 converter (unencrypted only)
|
|
352
363
|
try {
|
|
353
364
|
return convertPPKV2ToOpenSSH(ppkContent);
|
|
354
365
|
} catch (e) {
|
|
@@ -360,4 +371,22 @@ async function convertPPKToOpenSSH(ppkContent) {
|
|
|
360
371
|
}
|
|
361
372
|
}
|
|
362
373
|
|
|
363
|
-
|
|
374
|
+
async function convertKeyIfNeeded(keyContent, passphrase) {
|
|
375
|
+
if (!keyContent || !keyContent.trim()) {
|
|
376
|
+
return keyContent;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const info = detectKeyFormat(keyContent);
|
|
380
|
+
if (info.format !== 'ppk') {
|
|
381
|
+
return keyContent;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
try {
|
|
385
|
+
const converted = await convertPPKToOpenSSH(keyContent, passphrase);
|
|
386
|
+
return converted;
|
|
387
|
+
} catch (e) {
|
|
388
|
+
throw new Error('PPK key conversion failed: ' + e.message);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
module.exports = { detectKeyFormat, convertPPKToOpenSSH, convertKeyIfNeeded };
|
package/src/webapp/js/app.js
CHANGED
|
@@ -5819,6 +5819,11 @@ const wheelHandler = (e) => {
|
|
|
5819
5819
|
const clearBtn = document.getElementById(clearBtnId);
|
|
5820
5820
|
const textarea = document.getElementById(textareaId);
|
|
5821
5821
|
|
|
5822
|
+
// Derive passphrase field ID from textarea ID
|
|
5823
|
+
const passphraseId = textareaId === 'connPrivateKey' ? 'connPassphrase' : 'bookmarkPassphrase';
|
|
5824
|
+
const passphraseEl = document.getElementById(passphraseId);
|
|
5825
|
+
const passphrase = passphraseEl ? passphraseEl.value : '';
|
|
5826
|
+
|
|
5822
5827
|
badge.style.display = 'inline-flex';
|
|
5823
5828
|
badge.textContent = 'Reading...';
|
|
5824
5829
|
badge.className = 'key-format-badge';
|
|
@@ -5832,7 +5837,7 @@ const wheelHandler = (e) => {
|
|
|
5832
5837
|
return;
|
|
5833
5838
|
}
|
|
5834
5839
|
|
|
5835
|
-
const detectResult = await this.detectAndConvertKey(content);
|
|
5840
|
+
const detectResult = await this.detectAndConvertKey(content, passphrase);
|
|
5836
5841
|
if (detectResult.error) {
|
|
5837
5842
|
badge.textContent = detectResult.format || 'Error';
|
|
5838
5843
|
badge.classList.add('format-error');
|
|
@@ -5891,7 +5896,7 @@ const wheelHandler = (e) => {
|
|
|
5891
5896
|
event.target.value = '';
|
|
5892
5897
|
}
|
|
5893
5898
|
|
|
5894
|
-
async detectAndConvertKey(content) {
|
|
5899
|
+
async detectAndConvertKey(content, passphrase) {
|
|
5895
5900
|
try {
|
|
5896
5901
|
const response = await fetch('/api/utils/detect-key', {
|
|
5897
5902
|
method: 'POST',
|
|
@@ -5910,7 +5915,7 @@ const wheelHandler = (e) => {
|
|
|
5910
5915
|
const convertResponse = await fetch('/api/utils/convert-key', {
|
|
5911
5916
|
method: 'POST',
|
|
5912
5917
|
headers: { 'Content-Type': 'application/json' },
|
|
5913
|
-
body: JSON.stringify({ content })
|
|
5918
|
+
body: JSON.stringify({ content, passphrase: passphrase || '' })
|
|
5914
5919
|
});
|
|
5915
5920
|
|
|
5916
5921
|
if (!convertResponse.ok) {
|
|
@@ -5963,7 +5968,7 @@ const wheelHandler = (e) => {
|
|
|
5963
5968
|
encrypted: info.encrypted || false
|
|
5964
5969
|
};
|
|
5965
5970
|
} catch (e) {
|
|
5966
|
-
if (
|
|
5971
|
+
if (/PuTTY-User-Key-File-/i.test(content)) {
|
|
5967
5972
|
return {
|
|
5968
5973
|
format: 'PPK',
|
|
5969
5974
|
key: content,
|
|
@@ -5987,7 +5992,7 @@ const wheelHandler = (e) => {
|
|
|
5987
5992
|
if (content.includes('BEGIN DSA PRIVATE KEY')) return 'pem-dsa';
|
|
5988
5993
|
if (content.includes('BEGIN PRIVATE KEY')) return 'pkcs8';
|
|
5989
5994
|
if (content.includes('BEGIN ENCRYPTED PRIVATE KEY')) return 'pkcs8-encrypted';
|
|
5990
|
-
if (
|
|
5995
|
+
if (/PuTTY-User-Key-File-/i.test(content)) return 'ppk';
|
|
5991
5996
|
return 'unknown';
|
|
5992
5997
|
}
|
|
5993
5998
|
|
|
@@ -10001,7 +10006,7 @@ async syncTabsFromServer(tabs) {
|
|
|
10001
10006
|
}
|
|
10002
10007
|
}
|
|
10003
10008
|
|
|
10004
|
-
connectFromBookmark(bookmark) {
|
|
10009
|
+
async connectFromBookmark(bookmark) {
|
|
10005
10010
|
// Close sidebar on mobile when connecting
|
|
10006
10011
|
const isMobile = window.innerWidth <= 768;
|
|
10007
10012
|
if (isMobile) {
|
|
@@ -10019,7 +10024,7 @@ async syncTabsFromServer(tabs) {
|
|
|
10019
10024
|
return;
|
|
10020
10025
|
}
|
|
10021
10026
|
|
|
10022
|
-
//
|
|
10027
|
+
// Build connection data from bookmark
|
|
10023
10028
|
const connectionData = {
|
|
10024
10029
|
name: bookmark.name,
|
|
10025
10030
|
host: bookmark.host,
|
|
@@ -10030,6 +10035,23 @@ async syncTabsFromServer(tabs) {
|
|
|
10030
10035
|
passphrase: bookmark.passphrase || ''
|
|
10031
10036
|
};
|
|
10032
10037
|
|
|
10038
|
+
// Auto-convert PPK keys to OpenSSH format before connecting
|
|
10039
|
+
if (connectionData.privateKey && /PuTTY-User-Key-File-/i.test(connectionData.privateKey)) {
|
|
10040
|
+
try {
|
|
10041
|
+
const convertResult = await this.detectAndConvertKey(connectionData.privateKey);
|
|
10042
|
+
if (convertResult.key && !convertResult.error) {
|
|
10043
|
+
connectionData.privateKey = convertResult.key;
|
|
10044
|
+
this.showToast('PPK key converted to OpenSSH format', 'success');
|
|
10045
|
+
} else if (convertResult.error) {
|
|
10046
|
+
this.showToast('PPK key conversion failed: ' + convertResult.error, 'error');
|
|
10047
|
+
return;
|
|
10048
|
+
}
|
|
10049
|
+
} catch (e) {
|
|
10050
|
+
this.showToast('PPK key conversion failed: ' + e.message, 'error');
|
|
10051
|
+
return;
|
|
10052
|
+
}
|
|
10053
|
+
}
|
|
10054
|
+
|
|
10033
10055
|
// Show connecting status
|
|
10034
10056
|
this.showToast(`Connecting to ${bookmark.name}...`, 'info');
|
|
10035
10057
|
|
|
@@ -10042,7 +10064,7 @@ async syncTabsFromServer(tabs) {
|
|
|
10042
10064
|
}
|
|
10043
10065
|
}
|
|
10044
10066
|
|
|
10045
|
-
openSFTPFromBookmark(bookmark) {
|
|
10067
|
+
async openSFTPFromBookmark(bookmark) {
|
|
10046
10068
|
// Close sidebar on mobile when opening SFTP
|
|
10047
10069
|
const isMobile = window.innerWidth <= 768;
|
|
10048
10070
|
if (isMobile) {
|
|
@@ -10052,7 +10074,7 @@ async syncTabsFromServer(tabs) {
|
|
|
10052
10074
|
if (sidebarOverlay) sidebarOverlay.classList.remove('active');
|
|
10053
10075
|
}
|
|
10054
10076
|
|
|
10055
|
-
//
|
|
10077
|
+
// Build connection data from bookmark
|
|
10056
10078
|
const connectionData = {
|
|
10057
10079
|
name: `${bookmark.name} (SFTP)`,
|
|
10058
10080
|
host: bookmark.host,
|
|
@@ -10063,6 +10085,23 @@ async syncTabsFromServer(tabs) {
|
|
|
10063
10085
|
passphrase: bookmark.passphrase || ''
|
|
10064
10086
|
};
|
|
10065
10087
|
|
|
10088
|
+
// Auto-convert PPK keys to OpenSSH format before connecting
|
|
10089
|
+
if (connectionData.privateKey && /PuTTY-User-Key-File-/i.test(connectionData.privateKey)) {
|
|
10090
|
+
try {
|
|
10091
|
+
const convertResult = await this.detectAndConvertKey(connectionData.privateKey);
|
|
10092
|
+
if (convertResult.key && !convertResult.error) {
|
|
10093
|
+
connectionData.privateKey = convertResult.key;
|
|
10094
|
+
this.showToast('PPK key converted to OpenSSH format', 'success');
|
|
10095
|
+
} else if (convertResult.error) {
|
|
10096
|
+
this.showToast('PPK key conversion failed: ' + convertResult.error, 'error');
|
|
10097
|
+
return;
|
|
10098
|
+
}
|
|
10099
|
+
} catch (e) {
|
|
10100
|
+
this.showToast('PPK key conversion failed: ' + e.message, 'error');
|
|
10101
|
+
return;
|
|
10102
|
+
}
|
|
10103
|
+
}
|
|
10104
|
+
|
|
10066
10105
|
// Show connecting status
|
|
10067
10106
|
this.showToast(`Opening SFTP for ${bookmark.name}...`, 'info');
|
|
10068
10107
|
|