@lethevimlet/sshift 1.1.7 → 1.1.8

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lethevimlet/sshift",
3
- "version": "1.1.7",
3
+ "version": "1.1.8",
4
4
  "description": "Web-based SSH + SFTP terminal client with tabs and bookmarks",
5
5
  "main": "src/server/index.js",
6
6
  "bin": {
@@ -63,14 +63,21 @@ function convertPPKViaPuttygen(ppkContent, passphrase) {
63
63
  return reject(new Error('Failed to write temporary PPK file: ' + writeErr.message));
64
64
  }
65
65
 
66
- const args = [inputFile, '-O', 'private-openssh-new', '-o', outputFile];
67
- if (passphrase) {
68
- args.splice(1, 0, `--old-passphrase=${passphrase}`);
69
- }
66
+ const args = passphrase
67
+ ? [inputFile, '--old-passphrase=' + passphrase, '-O', 'private-openssh-new', '-o', outputFile]
68
+ : [inputFile, '-O', 'private-openssh-new', '-o', outputFile];
70
69
 
71
70
  execFile('puttygen', args, (err, stdout, stderr) => {
72
71
  if (err && passphrase) {
73
- tryConvertPPKWithPassphraseFile(inputFile, outputFile, passphrase, resolve, reject);
72
+ const errStr = (stderr || err.message || '').toLowerCase();
73
+ if (!errStr.includes('no such option')) {
74
+ cleanupAndResolve(err, stdout, stderr, inputFile, outputFile, reject, resolve);
75
+ return;
76
+ }
77
+ const argsAlt = [inputFile, '--old-passphrase', passphrase, '-O', 'private-openssh-new', '-o', outputFile];
78
+ execFile('puttygen', argsAlt, (err2, stdout2, stderr2) => {
79
+ cleanupAndResolve(err2, stdout2, stderr2, inputFile, outputFile, reject, resolve);
80
+ });
74
81
  return;
75
82
  }
76
83
 
@@ -80,58 +87,30 @@ function convertPPKViaPuttygen(ppkContent, passphrase) {
80
87
  });
81
88
  }
82
89
 
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`);
90
+ function cleanupAndResolve(err, stdout, stderr, inputFile, outputFile, reject, resolve) {
91
+ try { fs.unlinkSync(inputFile); } catch (e) { /* ignore */ }
86
92
 
87
- fs.writeFile(passphraseFile, passphrase, { mode: 0o600 }, (writeErr) => {
88
- if (writeErr) {
89
- cleanupTempFiles([inputFile, outputFile]);
93
+ if (err) {
94
+ try { fs.unlinkSync(outputFile); } catch (e) { /* ignore */ }
95
+ const stderrStr = (stderr || '').trim();
96
+ const errMsg = stderrStr || err.message;
97
+
98
+ if (stderrStr.includes('no such option') && stderrStr.includes('--old-passphrase')) {
90
99
  return reject(new Error(
91
- 'Failed to write passphrase file for PPK conversion: ' + writeErr.message
100
+ 'puttygen on this system does not support the --old-passphrase option. ' +
101
+ 'Please upgrade puttygen (PuTTY 0.71+) or decrypt the PPK key manually: ' +
102
+ 'run "puttygen key.ppk -O private-openssh-new -o key.pem" with the passphrase entered interactively.'
92
103
  ));
93
104
  }
94
105
 
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 */ }
106
+ if (stderrStr.toLowerCase().includes('wrong passphrase') || stderrStr.toLowerCase().includes('unable to read')) {
107
+ return reject(new Error(
108
+ 'PPK passphrase is incorrect. Please check the passphrase and try again. ' +
109
+ '(puttygen error: ' + stderrStr + ')'
110
+ ));
111
+ }
128
112
 
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
- ));
113
+ return reject(new Error('puttygen conversion failed: ' + errMsg));
135
114
  }
136
115
 
137
116
  fs.readFile(outputFile, 'utf8', (readErr, data) => {
@@ -5858,7 +5858,7 @@ const wheelHandler = (e) => {
5858
5858
 
5859
5859
  const detectResult = await this.detectAndConvertKey(content, passphrase);
5860
5860
  if (detectResult.error) {
5861
- if (this._isPassphraseError(detectResult.error) && !passphrase) {
5861
+ if (this._isPassphraseError(detectResult.error)) {
5862
5862
  const promptedPassphrase = await this._promptForKeyPassphrase();
5863
5863
  if (promptedPassphrase !== null) {
5864
5864
  passphrase = promptedPassphrase;