Skip to content

Commit

Permalink
#50 Support PKCS#5 AES-256-CBC encrypted private keys
Browse files Browse the repository at this point in the history
Reviewed by: Alex Wilson <[email protected]>
  • Loading branch information
nahuel authored and Alex Wilson committed Oct 11, 2018
1 parent 6b68d49 commit 53e23fe
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ function assertCompatible(obj, klass, needVer, name) {

var CIPHER_LEN = {
'des-ede3-cbc': { key: 7, iv: 8 },
'aes-128-cbc': { key: 16, iv: 16 }
'aes-128-cbc': { key: 16, iv: 16 },
'aes-256-cbc': { key: 32, iv: 16 }
};
var PKCS5_SALT_LEN = 8;

Expand Down
30 changes: 30 additions & 0 deletions test/assets/p50key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-256-CBC,C874518D21E3C9C4F0CA44C8060D631B

6kCcRk72I+6eYBpvDpMu/hxJKVI9xpsJikmfyc//0HLBP6e95cuk3EHWUG5/2cLb
RSniNWjeIBmxMUlJP7vCdmdnJQ+so/9JzmztwHIEk/kMW1jgNnWH53pUhuNTllFy
M7/c2IOD5gWSrl/MijNNhYaglh2Zn5djJvuoJmmT3lXsIFc1FQw0luDBxYE7l5Rf
PuZxuRgpHwbuAAJ2UW2NDlYxtpOI3ilh90GHl+G/DEks3N/tWvWQKWbkGy10I2Nm
TbBlGf78KU5Br3fIdau5YdKUFT7vFfhuX/txB1eqV7wbMBjeDKEJNylfwANGQyMk
iUZo54FdNCfZC9IYHOxJ2ntNYlV0qnD+JwffE3fmDL+QXAdr5kHY5D/C5vgLelpS
1JNQPNnRll04Sj0b3ozfmPShLhTfyRUXqyngiqLl1rp0/52B4WCZuZUz17JErwas
AN8e0jmNn4nGP/MZAb4sZ2ENirkguoi+yqqeGVRVylAAHzp7yPNLDp53l4vYo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BXbmEaBVLMgz7QDWzuIGdnq+IfVYCn37UyxdCyVkHBr
-----END RSA PRIVATE KEY-----
16 changes: 16 additions & 0 deletions test/private-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,22 @@ test('parse and produce encrypted ssh-private ecdsa', function (t) {
t.end();
});

test('pem pkcs#5 encrypted with aes-256-cbc', function (t) {
var keyPem = fs.readFileSync(path.join(testDir, 'p50key.pem'));
t.throws(function () {
sshpk.parsePrivateKey(keyPem, 'pem');
});
t.throws(function () {
sshpk.parsePrivateKey(keyPem, 'pem',
{ passphrase: 'incorrect' });
});
var key = sshpk.parsePrivateKey(keyPem, 'pem',
{ passphrase: 'pass' });
t.strictEqual(key.type, 'rsa');
t.strictEqual(key.size, 2048);
t.end();
});

var KEY_RSA, KEY_DSA, KEY_ECDSA, KEY_ECDSA2, KEY_ED25519;

test('setup keys', function (t) {
Expand Down

0 comments on commit 53e23fe

Please sign in to comment.