From b3690e0fde16be0a3abdb7a518c37a0e3cfb41df Mon Sep 17 00:00:00 2001 From: Jim Wigginton Date: Sun, 5 Sep 2010 03:04:29 +0000 Subject: [PATCH] - added support for AES-128-CBC encrypted private keys (ie. the default format of OpenSSH 5.4+) git-svn-id: http://phpseclib.svn.sourceforge.net/svnroot/phpseclib/trunk@119 21d32557-59b3-4da0-833f-c5933fad653e --- phpseclib/Crypt/RSA.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/phpseclib/Crypt/RSA.php b/phpseclib/Crypt/RSA.php index be33b519..b8742235 100644 --- a/phpseclib/Crypt/RSA.php +++ b/phpseclib/Crypt/RSA.php @@ -62,7 +62,7 @@ * @author Jim Wigginton * @copyright MMIX Jim Wigginton * @license http://www.gnu.org/licenses/lgpl.txt - * @version $Id: RSA.php,v 1.17 2010-07-11 02:33:13 terrafrost Exp $ + * @version $Id: RSA.php,v 1.18 2010-09-05 03:04:29 terrafrost Exp $ * @link http://phpseclib.sourceforge.net */ @@ -770,7 +770,7 @@ class Crypt_RSA { * OpenSSL is the de facto standard. It's utilized by OpenSSH and other projects */ if (preg_match('#DEK-Info: (.+),(.+)#', $key, $matches)) { $iv = pack('H*', trim($matches[2])); - $symkey = pack('H*', md5($this->password . $iv)); // symkey is short for symmetric key + $symkey = pack('H*', md5($this->password . substr($iv, 0, 8))); // symkey is short for symmetric key $symkey.= substr(pack('H*', md5($symkey . $this->password . $iv)), 0, 8); $ciphertext = preg_replace('#.+(\r|\n|\r\n)\1|[\r\n]|-.+-#s', '', $key); $ciphertext = preg_match('#^[a-zA-Z\d/+]*={0,2}$#', $ciphertext) ? base64_decode($ciphertext) : false; @@ -778,6 +778,12 @@ class Crypt_RSA { $ciphertext = $key; } switch ($matches[1]) { + case 'AES-128-CBC': + if (!class_exists('Crypt_AES')) { + require_once('Crypt/AES.php'); + } + $symkey = substr($symkey, 0, 16); + break; case 'DES-EDE3-CBC': if (!class_exists('Crypt_TripleDES')) { require_once('Crypt/TripleDES.php');