diff --git a/phpseclib/Crypt/DES.php b/phpseclib/Crypt/DES.php index f6c1f301..0d6dd00e 100644 --- a/phpseclib/Crypt/DES.php +++ b/phpseclib/Crypt/DES.php @@ -723,7 +723,7 @@ class Crypt_DES { mcrypt_generic_init($this->demcrypt, $this->keys, $this->decryptIV); } - return $this->mode != 'ctr' ? $this->_unpad($plaintext) : $plaintext; + return $this->paddable ? $this->_unpad($plaintext) : $plaintext; } if (!is_array($this->keys)) { diff --git a/phpseclib/Crypt/TripleDES.php b/phpseclib/Crypt/TripleDES.php index bbabf169..faf8c18a 100644 --- a/phpseclib/Crypt/TripleDES.php +++ b/phpseclib/Crypt/TripleDES.php @@ -265,6 +265,7 @@ class Crypt_TripleDES { new Crypt_DES(CRYPT_DES_MODE_CBC), new Crypt_DES(CRYPT_DES_MODE_CBC) ); + $this->paddable = true; // we're going to be doing the padding, ourselves, so disable it in the Crypt_DES objects $this->des[0]->disablePadding(); diff --git a/phpseclib/File/X509.php b/phpseclib/File/X509.php index 21a6cb6a..6ad74675 100644 --- a/phpseclib/File/X509.php +++ b/phpseclib/File/X509.php @@ -59,15 +59,35 @@ if (!class_exists('File_ASN1')) { */ define('FILE_X509_VALIDATE_SIGNATURE_BY_CA', 1); +/**#@+ + * @access public + * @see File_X509::getDN() + */ /** - * Name format tokens for the getDN() method. + * Return internal array representation */ define('FILE_X509_DN_ARRAY', 0); // Internal array representation. -define('FILE_X509_DN_STRING', 1); // String. -define('FILE_X509_DN_ASN1', 2); // ASN.1 Name string. -define('FILE_X509_DN_OPENSSL', 3); // OpenSSL compatible array. -define('FILE_X509_DN_CANON', 4); // Canonical ASN.1 RDNs string. -define('FILE_X509_DN_HASH', 5); // Name hash for file indexing. +/** + * Return string + */ +define('FILE_X509_DN_STRING', 1); +/** + * Return ASN.1 name string + */ +define('FILE_X509_DN_ASN1', 2); +/** + * Return OpenSSL compatible array + */ +define('FILE_X509_DN_OPENSSL', 3); +/** + * Return canonical ASN.1 RDNs string + */ +define('FILE_X509_DN_CANON', 4); +/** + * Return name ash for file indexing + */ +define('FILE_X509_DN_HASH', 5); +/**#@-*/ /** * Pure-PHP X.509 Parser @@ -1346,8 +1366,11 @@ class File_X509 { subject=/O=organization/OU=org unit/CN=common name issuer=/O=organization/CN=common name */ - $cert = preg_replace('#^(?:[^-].+[\r\n]+)+|-.+-|[\r\n]| #', '', $cert); - $cert = preg_match('#^[a-zA-Z\d/+]*={0,2}$#', $cert) ? base64_decode($cert) : false; + $temp = preg_replace('#^(?:[^-].+[\r\n]+)+|-.+-|[\r\n]| #', '', $cert); + $temp = preg_match('#^[a-zA-Z\d/+]*={0,2}$#', $temp) ? base64_decode($temp) : false; + if ($temp != false) { + $cert = $temp; + } if ($cert === false) { $this->currentCert = false; @@ -1637,8 +1660,16 @@ class File_X509 { */ function loadCA($cert) { + $olddn = $this->dn; + $oldcert = $this->currentCert; + $oldsigsubj = $this->signatureSubject; + $cert = $this->loadX509($cert); if (!$cert) { + $this->dn = $olddn; + $this->currentCert = $oldcert; + $this->signatureSubject = $oldsigsubj; + return false; } @@ -1667,8 +1698,10 @@ class File_X509 { //} $this->CAs[] = $cert; - unset($this->currentCert); - unset($this->signatureSubject); + + $this->dn = $olddn; + $this->currentCert = $oldcert; + $this->signatureSubject = $oldsigsubj; return true; } @@ -2209,7 +2242,7 @@ class File_X509 { function getDN($format = FILE_X509_DN_ARRAY, $dn = NULL) { if (!isset($dn)) { - $dn = $this->dn; + $dn = isset($this->currentCert['tbsCertList']) ? $this->currentCert['tbsCertList']['issuer'] : $this->dn; } switch ((int) $format) { @@ -2361,7 +2394,7 @@ class File_X509 { return $this->getDN($format, $this->currentCert['tbsCertList']['issuer']); } - return false; + return false; } /** @@ -2385,7 +2418,7 @@ class File_X509 { return $this->getDN($format, $this->currentCert['certificationRequestInfo']['subject']); } - return false; + return false; } /** @@ -2407,7 +2440,7 @@ class File_X509 { return $this->getDNProp($propname, $this->currentCert['tbsCertList']['issuer'], $withType); } - return false; + return false; } /** @@ -2431,7 +2464,7 @@ class File_X509 { return $this->getDNProp($propname, $this->currentCert['certificationRequestInfo']['subject'], $withType); } - return false; + return false; } /** @@ -2518,8 +2551,12 @@ class File_X509 { $asn1 = new File_ASN1(); - $csr = preg_replace('#^(?:[^-].+[\r\n]+)+|-.+-|[\r\n]| #', '', $csr); - $orig = $csr = preg_match('#^[a-zA-Z\d/+]*={0,2}$#', $csr) ? base64_decode($csr) : false; + $temp = preg_replace('#^(?:[^-].+[\r\n]+)+|-.+-|[\r\n]| #', '', $csr); + $temp = preg_match('#^[a-zA-Z\d/+]*={0,2}$#', $temp) ? base64_decode($temp) : false; + if ($temp != false) { + $csr = $temp; + } + $orig = $csr; if ($csr === false) { $this->currentCert = false; @@ -2612,8 +2649,12 @@ class File_X509 { { $asn1 = new File_ASN1(); - $crl = preg_replace('#^(?:[^-].+[\r\n]+)+|-.+-|[\r\n]#', '', $crl); - $orig = $crl = preg_match('#^[a-zA-Z\d/+]*={0,2}$#', $crl) ? base64_decode($crl) : false; + $temp = preg_replace('#^(?:[^-].+[\r\n]+)+|-.+-|[\r\n]| #', '', $csr); + $temp = preg_match('#^[a-zA-Z\d/+]*={0,2}$#', $temp) ? base64_decode($temp) : false; + if ($temp != false) { + $crl = $temp; + } + $orig = $crl; if ($crl === false) { $this->currentCert = false; @@ -3625,7 +3666,7 @@ class File_X509 { $result = array(); - if (!is_array($rclist = $this->_subArray($crl, 'tbsCertList/revokedCertificates'))) { + if (is_array($rclist = $this->_subArray($crl, 'tbsCertList/revokedCertificates'))) { foreach ($rclist as $rc) { $result[] = $rc['userCertificate']->toString(); } diff --git a/phpseclib/Net/SSH1.php b/phpseclib/Net/SSH1.php index 69669aa7..67e09652 100644 --- a/phpseclib/Net/SSH1.php +++ b/phpseclib/Net/SSH1.php @@ -428,7 +428,7 @@ class Net_SSH1 { * @var Array * @access private */ - var $interactive_buffer = ''; + var $interactiveBuffer = ''; /** * Default Constructor.