1
0
mirror of https://github.com/danog/tgseclib.git synced 2024-11-27 12:44:38 +01:00

Misc fixes

- make it so '' is a legit password and doesn't unset the pw to pass bantu's unit tests (unit test could have been updated too but whatever)
- make it so not passing in any parameters to Crypt_RSA::setPassword() works without E_NOTICE or E_WARNING as per example in docs
- add missing phpdoc headers to File_ANSI
- cryan -> cyan in File_ANSI
This commit is contained in:
terrafrost 2012-08-23 08:59:49 -05:00
parent ed67b3b68d
commit 6c4fcd34d3
3 changed files with 29 additions and 11 deletions

View File

@ -117,7 +117,7 @@ class Crypt_Hash {
* @var String * @var String
* @access private * @access private
*/ */
var $key = ''; var $key = false;
/** /**
* Outer XOR (Internal HMAC) * Outer XOR (Internal HMAC)
@ -170,7 +170,7 @@ class Crypt_Hash {
* @access public * @access public
* @param String $key * @param String $key
*/ */
function setKey($key) function setKey($key = false)
{ {
$this->key = $key; $this->key = $key;
} }
@ -296,7 +296,7 @@ class Crypt_Hash {
{ {
$mode = is_array($this->hash) ? CRYPT_HASH_MODE_INTERNAL : CRYPT_HASH_MODE; $mode = is_array($this->hash) ? CRYPT_HASH_MODE_INTERNAL : CRYPT_HASH_MODE;
if (!empty($this->key)) { if (!empty($this->key) || is_string($this->key)) {
switch ( $mode ) { switch ( $mode ) {
case CRYPT_HASH_MODE_MHASH: case CRYPT_HASH_MODE_MHASH:
$output = mhash($this->hash, $text, $this->key); $output = mhash($this->hash, $text, $this->key);

View File

@ -399,7 +399,7 @@ class Crypt_RSA {
* @var String * @var String
* @access private * @access private
*/ */
var $password = ''; var $password = false;
/** /**
* Components * Components
@ -695,7 +695,7 @@ class Crypt_RSA {
return false; return false;
} }
$key = "PuTTY-User-Key-File-2: ssh-rsa\r\nEncryption: "; $key = "PuTTY-User-Key-File-2: ssh-rsa\r\nEncryption: ";
$encryption = (!empty($this->password)) ? 'aes256-cbc' : 'none'; $encryption = (!empty($this->password) || is_string($this->password)) ? 'aes256-cbc' : 'none';
$key.= $encryption; $key.= $encryption;
$key.= "\r\nComment: " . CRYPT_RSA_COMMENT . "\r\n"; $key.= "\r\nComment: " . CRYPT_RSA_COMMENT . "\r\n";
$public = pack('Na*Na*Na*', $public = pack('Na*Na*Na*',
@ -712,7 +712,7 @@ class Crypt_RSA {
strlen($raw['privateExponent']), $raw['privateExponent'], strlen($raw['prime1']), $raw['prime1'], strlen($raw['privateExponent']), $raw['privateExponent'], strlen($raw['prime1']), $raw['prime1'],
strlen($raw['prime2']), $raw['prime2'], strlen($raw['coefficient']), $raw['coefficient'] strlen($raw['prime2']), $raw['prime2'], strlen($raw['coefficient']), $raw['coefficient']
); );
if (empty($this->password)) { if (empty($this->password) && !is_string($this->password)) {
$source.= pack('Na*', strlen($private), $private); $source.= pack('Na*', strlen($private), $private);
$hashkey = 'putty-private-key-file-mac-key'; $hashkey = 'putty-private-key-file-mac-key';
} else { } else {
@ -775,7 +775,7 @@ class Crypt_RSA {
$RSAPrivateKey = pack('Ca*a*', CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($RSAPrivateKey)), $RSAPrivateKey); $RSAPrivateKey = pack('Ca*a*', CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($RSAPrivateKey)), $RSAPrivateKey);
if (!empty($this->password)) { if (!empty($this->password) || is_string($this->password)) {
$iv = $this->_random(8); $iv = $this->_random(8);
$symkey = pack('H*', md5($this->password . $iv)); // symkey is short for symmetric key $symkey = pack('H*', md5($this->password . $iv)); // symkey is short for symmetric key
$symkey.= substr(pack('H*', md5($symkey . $this->password . $iv)), 0, 8); $symkey.= substr(pack('H*', md5($symkey . $this->password . $iv)), 0, 8);
@ -1347,14 +1347,14 @@ class Crypt_RSA {
* Sets the password * Sets the password
* *
* Private keys can be encrypted with a password. To unset the password, pass in the empty string or false. * Private keys can be encrypted with a password. To unset the password, pass in the empty string or false.
* Or rather, pass in $password such that empty($password) is true. * Or rather, pass in $password such that empty($password) && !is_string($password) is true.
* *
* @see createKey() * @see createKey()
* @see loadKey() * @see loadKey()
* @access public * @access public
* @param String $password * @param String $password
*/ */
function setPassword($password) function setPassword($password = false)
{ {
$this->password = $password; $this->password = $password;
} }

View File

@ -396,7 +396,7 @@ class File_ANSI {
case 33: $front = 'yellow'; break; case 33: $front = 'yellow'; break;
case 34: $front = 'blue'; break; case 34: $front = 'blue'; break;
case 35: $front = 'magenta'; break; case 35: $front = 'magenta'; break;
case 36: $front = 'cryan'; break; case 36: $front = 'cyan'; break;
case 37: $front = 'white'; break; case 37: $front = 'white'; break;
case 40: $back = 'black'; break; case 40: $back = 'black'; break;
@ -405,7 +405,7 @@ class File_ANSI {
case 43: $back = 'yellow'; break; case 43: $back = 'yellow'; break;
case 44: $back = 'blue'; break; case 44: $back = 'blue'; break;
case 45: $back = 'magenta'; break; case 45: $back = 'magenta'; break;
case 46: $back = 'cryan'; break; case 46: $back = 'cyan'; break;
case 47: $back = 'white'; break; case 47: $back = 'white'; break;
default: default:
@ -479,6 +479,12 @@ class File_ANSI {
} }
} }
/**
* Returns the current screen without preformating
*
* @access private
* @return String
*/
function _getScreen() function _getScreen()
{ {
$output = ''; $output = '';
@ -496,11 +502,23 @@ class File_ANSI {
return rtrim($output); return rtrim($output);
} }
/**
* Returns the current screen
*
* @access public
* @return String
*/
function getScreen() function getScreen()
{ {
return '<pre style="color: white; background: black" width="' . ($this->max_x + 1) . '">' . $this->_getScreen() . '</pre>'; return '<pre style="color: white; background: black" width="' . ($this->max_x + 1) . '">' . $this->_getScreen() . '</pre>';
} }
/**
* Returns the current screen and the x previous lines
*
* @access public
* @return String
*/
function getHistory() function getHistory()
{ {
$scrollback = ''; $scrollback = '';