@lethevimlet/sshift 1.1.6 → 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
|
@@ -63,34 +63,65 @@ 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 =
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
)
|
|
71
|
+
if (err && passphrase) {
|
|
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
|
+
});
|
|
81
|
+
return;
|
|
80
82
|
}
|
|
81
83
|
|
|
82
|
-
|
|
83
|
-
try { fs.unlinkSync(outputFile); } catch (e) { /* ignore */ }
|
|
84
|
-
if (readErr) {
|
|
85
|
-
return reject(new Error('Failed to read converted key: ' + readErr.message));
|
|
86
|
-
}
|
|
87
|
-
resolve(data);
|
|
88
|
-
});
|
|
84
|
+
cleanupAndResolve(err, stdout, stderr, inputFile, outputFile, reject, resolve);
|
|
89
85
|
});
|
|
90
86
|
});
|
|
91
87
|
});
|
|
92
88
|
}
|
|
93
89
|
|
|
90
|
+
function cleanupAndResolve(err, stdout, stderr, inputFile, outputFile, reject, resolve) {
|
|
91
|
+
try { fs.unlinkSync(inputFile); } catch (e) { /* ignore */ }
|
|
92
|
+
|
|
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')) {
|
|
99
|
+
return reject(new Error(
|
|
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.'
|
|
103
|
+
));
|
|
104
|
+
}
|
|
105
|
+
|
|
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
|
+
}
|
|
112
|
+
|
|
113
|
+
return reject(new Error('puttygen conversion failed: ' + errMsg));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
fs.readFile(outputFile, 'utf8', (readErr, data) => {
|
|
117
|
+
try { fs.unlinkSync(outputFile); } catch (e) { /* ignore */ }
|
|
118
|
+
if (readErr) {
|
|
119
|
+
return reject(new Error('Failed to read converted key: ' + readErr.message));
|
|
120
|
+
}
|
|
121
|
+
resolve(data);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
94
125
|
function convertPPKV2ToOpenSSH(ppkContent) {
|
|
95
126
|
const lines = ppkContent.split('\n');
|
|
96
127
|
|
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,10 +5819,8 @@ 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
5822
|
const passphraseId = textareaId === 'connPrivateKey' ? 'connPassphrase' : 'bookmarkPassphrase';
|
|
5824
5823
|
const passphraseEl = document.getElementById(passphraseId);
|
|
5825
|
-
const passphrase = passphraseEl ? passphraseEl.value : '';
|
|
5826
5824
|
|
|
5827
5825
|
badge.style.display = 'inline-flex';
|
|
5828
5826
|
badge.textContent = 'Reading...';
|
|
@@ -5837,8 +5835,43 @@ const wheelHandler = (e) => {
|
|
|
5837
5835
|
return;
|
|
5838
5836
|
}
|
|
5839
5837
|
|
|
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
|
+
|
|
5840
5859
|
const detectResult = await this.detectAndConvertKey(content, passphrase);
|
|
5841
5860
|
if (detectResult.error) {
|
|
5861
|
+
if (this._isPassphraseError(detectResult.error)) {
|
|
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
|
+
}
|
|
5842
5875
|
badge.textContent = detectResult.format || 'Error';
|
|
5843
5876
|
badge.classList.add('format-error');
|
|
5844
5877
|
badge.style.display = 'inline-flex';
|
|
@@ -5848,44 +5881,7 @@ const wheelHandler = (e) => {
|
|
|
5848
5881
|
return;
|
|
5849
5882
|
}
|
|
5850
5883
|
|
|
5851
|
-
textarea
|
|
5852
|
-
|
|
5853
|
-
let formatLabel = detectResult.format;
|
|
5854
|
-
if (detectResult.wasConverted) {
|
|
5855
|
-
formatLabel = `PPK → OpenSSH`;
|
|
5856
|
-
} else if (detectResult.format === 'openssh') {
|
|
5857
|
-
formatLabel = 'OpenSSH';
|
|
5858
|
-
} else if (detectResult.format === 'pem-rsa') {
|
|
5859
|
-
formatLabel = 'PEM (RSA)';
|
|
5860
|
-
} else if (detectResult.format === 'pem-ec') {
|
|
5861
|
-
formatLabel = 'PEM (EC)';
|
|
5862
|
-
} else if (detectResult.format === 'pem-dsa') {
|
|
5863
|
-
formatLabel = 'PEM (DSA)';
|
|
5864
|
-
} else if (detectResult.format === 'pkcs8') {
|
|
5865
|
-
formatLabel = 'PKCS8';
|
|
5866
|
-
} else if (detectResult.format === 'pkcs8-encrypted') {
|
|
5867
|
-
formatLabel = 'PKCS8 (Encrypted)';
|
|
5868
|
-
}
|
|
5869
|
-
|
|
5870
|
-
badge.textContent = formatLabel;
|
|
5871
|
-
badge.className = 'key-format-badge';
|
|
5872
|
-
if (detectResult.encrypted) {
|
|
5873
|
-
badge.classList.add('format-warning');
|
|
5874
|
-
}
|
|
5875
|
-
badge.style.display = 'inline-flex';
|
|
5876
|
-
clearBtn.style.display = 'inline-flex';
|
|
5877
|
-
|
|
5878
|
-
if (detectResult.wasConverted) {
|
|
5879
|
-
this.showToast('PPK key converted to OpenSSH format', 'success');
|
|
5880
|
-
} else if (detectResult.format === 'openssh') {
|
|
5881
|
-
this.showToast('OpenSSH key loaded', 'success');
|
|
5882
|
-
} else if (detectResult.format === 'pem-rsa' || detectResult.format === 'pem-ec' || detectResult.format === 'pem-dsa') {
|
|
5883
|
-
this.showToast('PEM key loaded', 'success');
|
|
5884
|
-
} else if (detectResult.format === 'pkcs8') {
|
|
5885
|
-
this.showToast('PKCS8 key loaded', 'success');
|
|
5886
|
-
} else if (detectResult.format === 'pkcs8-encrypted') {
|
|
5887
|
-
this.showToast('Encrypted PKCS8 key loaded - passphrase required', 'info');
|
|
5888
|
-
}
|
|
5884
|
+
this._applyKeyResult(textarea, badge, clearBtn, detectResult);
|
|
5889
5885
|
} catch (err) {
|
|
5890
5886
|
badge.textContent = 'Error';
|
|
5891
5887
|
badge.classList.add('format-error');
|
|
@@ -5896,6 +5892,85 @@ const wheelHandler = (e) => {
|
|
|
5896
5892
|
event.target.value = '';
|
|
5897
5893
|
}
|
|
5898
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
|
+
|
|
5899
5974
|
async detectAndConvertKey(content, passphrase) {
|
|
5900
5975
|
try {
|
|
5901
5976
|
const response = await fetch('/api/utils/detect-key', {
|