@lethevimlet/sshift 1.1.6 → 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
|
@@ -65,32 +65,84 @@ function convertPPKViaPuttygen(ppkContent, passphrase) {
|
|
|
65
65
|
|
|
66
66
|
const args = [inputFile, '-O', 'private-openssh-new', '-o', outputFile];
|
|
67
67
|
if (passphrase) {
|
|
68
|
-
args.splice(1, 0,
|
|
68
|
+
args.splice(1, 0, `--old-passphrase=${passphrase}`);
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
execFile('puttygen', args, (err, stdout, stderr) => {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
try { fs.unlinkSync(outputFile); } catch (e) { /* ignore */ }
|
|
76
|
-
return reject(new Error(
|
|
77
|
-
'puttygen conversion failed: ' + (stderr || err.message) +
|
|
78
|
-
'. If the PPK file is encrypted, provide the correct passphrase.'
|
|
79
|
-
));
|
|
72
|
+
if (err && passphrase) {
|
|
73
|
+
tryConvertPPKWithPassphraseFile(inputFile, outputFile, passphrase, resolve, reject);
|
|
74
|
+
return;
|
|
80
75
|
}
|
|
81
76
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
77
|
+
cleanupAndResolve(err, stdout, stderr, inputFile, outputFile, reject, resolve);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
}
|
|
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);
|
|
89
115
|
});
|
|
90
116
|
});
|
|
91
117
|
});
|
|
92
118
|
}
|
|
93
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
|
+
|
|
94
146
|
function convertPPKV2ToOpenSSH(ppkContent) {
|
|
95
147
|
const lines = ppkContent.split('\n');
|
|
96
148
|
|
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) && !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
|
+
}
|
|
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', {
|