Skip to content

Commit

Permalink
#58 des-ede3-cbc encrypted keys broken
Browse files Browse the repository at this point in the history
Reviewed by: Cody Peter Mello <cody.mello@joyent.com>
  • Loading branch information
Alex Wilson committed Oct 30, 2018
1 parent 2ab4f2a commit c7a6c68
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function assertCompatible(obj, klass, needVer, name) {
}

var CIPHER_LEN = {
'des-ede3-cbc': { key: 7, iv: 8 },
'des-ede3-cbc': { key: 24, iv: 8 },
'aes-128-cbc': { key: 16, iv: 16 },
'aes-256-cbc': { key: 32, iv: 16 }
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sshpk",
"version": "1.15.1",
"version": "1.15.2",
"description": "A library for finding and using SSH public keys",
"main": "lib/index.js",
"scripts": {
Expand Down
30 changes: 30 additions & 0 deletions test/assets/3des.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: DES-EDE3-CBC,91DE47E39A642704

T5h5N8sO/mT8zRfqVDc2Kmgy5Az9w63T91Gvl57XhAxd7jD2vZhbAdD3qdnYc9Ue
h4uve27OcJXQXHTUaAZY2ZR/9e9NFIkSnbEQHVzMa0W5I7v7JvN9Ms8z9WJuxd9k
9M8t6rYiLQXbdKG3RhEyS+m5O/tU1dxWakwIxlE9fpLcHWgEO2YEPwKjiM/WY0Uj
+eH02oaPIVIC6Eyni7CTCjkhgTn8xI+yHfIow94IUYg4OJNes27dhruH/nybPYPt
gW6eQfENrXZNTCzp3E71/WB/27JVI8eNkTtluoFTn8KAeiDNIB0b/KFpJoIFTgWX
ysYqiv6a5q7Q+mxEet+krZ40LBsh2cNLqJGCRh/nGU3Zs8hozyUfkhBMzjvLc36E
F2cqtjBGeds1k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OSzTUujBEoeB0ObFN
B4PWao7GOeh/WUTF83AYOtEk+J/8CYMNB1IClrpZszcCyAAkx26OdoOPAGMBD1V/
HnE2S4h22855esmjQOggwNCtf0Tg6PG7+jhb8MwerYwaiqfn2hQpAz6ZKff2Qeh5
-----END RSA PRIVATE KEY-----
1 change: 1 addition & 0 deletions test/assets/3des.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDLISAQ2h/VFo0tGe3irSmk3KU5x5IYtPke1yk8hSgd/AKbJlDuqPF3BfbEkmV/gA7EpxPhr5QkfcLCkAjWZhUJccn0Dmz6Ypd615IQrEPMS48wFl4yRSDaPyGcOi+lcgrgclcnTG9/vEqRfqw7y8aRZIq880nNoxHe/TQbeQuuGf0Zdts4t5YFbm8MkwCMSlY+DRSy462YZ4h7zBYOA6TDcSJvvHVGe937xqavMK2btj9wIij2qtCP4L23zDl2QCM+c9DxC+FvNY6fyNrePs2pbyZb2z3Bg+SR/J+hSqMUSYKLBYzQnG/c0T8xE59bk1P8jOeJGVgQGS6m9CSwVOgZ test
15 changes: 15 additions & 0 deletions test/pem.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright 2011 Joyent, Inc. All rights reserved.

var test = require('tape').test;
var path = require('path');
var fs = require('fs');

var sshpk = require('../lib/index');
var Buffer = require('safer-buffer').Buffer;
Expand Down Expand Up @@ -177,6 +179,8 @@ var ECDSA_PEM = '-----BEGIN PUBLIC KEY-----\n' +
var RFC_AUTO = Buffer.from('AAAAC3NzaC1lZDI1NTE5AAAAIEi0pkfPe/+kbmnTSH0mfr0J' +
'4Fq7M7bshFAKB6uCyLDm', 'base64');

var testDir = path.join(__dirname, 'assets');

///--- Tests

test('1024b pem to rsa ssh key', function(t) {
Expand Down Expand Up @@ -341,3 +345,14 @@ test('encrypted ecdsa private key with pw', function(t) {
t.equal(k.type, 'ecdsa');
t.end();
});

test('encrypted rsa private key (3des)', function (t) {
var keyPem = fs.readFileSync(path.join(testDir, '3des.pem'));
var key = sshpk.parsePrivateKey(keyPem, 'pem',
{ passphrase: 'testing123' });
t.equal(key.type, 'rsa');
key.comment = 'test';
var keySsh = fs.readFileSync(path.join(testDir, '3des.pub'), 'ascii');
t.equal(key.toPublic().toString('ssh'), keySsh.trim());
t.end();
});

0 comments on commit c7a6c68

Please sign in to comment.