Hashar has uploaded a new change for review.
https://gerrit.wikimedia.org/r/320784
Change subject: CryptRand: remove newlines from logging message
......................................................................
CryptRand: remove newlines from logging message
5bd6de6 converted CryptRand to use the logger command but kept the
newlines in the message which is needed for wfDebug() but not with the
logger interface.
Patch also removed a call to wfGetAllCallers() from the first debug
message of generate(), leaving an uneeded debugging message.
Hence we had output such as:
---
[CryptRand] Generating cryptographic random bytes for
[CryptRand] mcrypt_create_iv generated 20 bytes of randomness.
[CryptRand] 0 bytes of randomness leftover in the buffer.
---
Drop the newlines from all debug message.
Drop the lonely debug message from generate().
Result:
---
[CryptRand] mcrypt_create_iv generated 20 bytes of randomness.
[CryptRand] 0 bytes of randomness leftover in the buffer.
---
Change-Id: I572206296fc3a0a498febb18925672a67480eb18
---
M includes/libs/CryptRand.php
1 file changed, 10 insertions(+), 12 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/84/320784/1
diff --git a/includes/libs/CryptRand.php b/includes/libs/CryptRand.php
index 6d18c81..10088f2 100644
--- a/includes/libs/CryptRand.php
+++ b/includes/libs/CryptRand.php
@@ -182,7 +182,7 @@
$this->logger->debug( "Clock drift calculation " .
"(time-taken=" . ( $timeTaken * 1000 ) . "ms, " .
"iterations=$iterations, " .
- "time-per-iteration=" . ( $timeTaken / $iterations *
1e6 ) . "us)\n" );
+ "time-per-iteration=" . ( $timeTaken / $iterations *
1e6 ) . "us)" );
return $data;
}
@@ -235,8 +235,6 @@
*/
public function generate( $bytes, $forceStrong = false ) {
- $this->logger->debug( "Generating cryptographic random bytes
for\n" );
-
$bytes = floor( $bytes );
static $buffer = '';
if ( is_null( $this->strong ) ) {
@@ -255,11 +253,11 @@
$rem = $bytes - strlen( $buffer );
$iv = mcrypt_create_iv( $rem,
MCRYPT_DEV_URANDOM );
if ( $iv === false ) {
- $this->logger->debug( "mcrypt_create_iv
returned false.\n" );
+ $this->logger->debug( "mcrypt_create_iv
returned false." );
} else {
$buffer .= $iv;
$this->logger->debug( "mcrypt_create_iv
generated " . strlen( $iv ) .
- " bytes of randomness.\n" );
+ " bytes of randomness." );
}
}
}
@@ -269,12 +267,12 @@
$rem = $bytes - strlen( $buffer );
$openssl_bytes = openssl_random_pseudo_bytes(
$rem, $openssl_strong );
if ( $openssl_bytes === false ) {
- $this->logger->debug(
"openssl_random_pseudo_bytes returned false.\n" );
+ $this->logger->debug(
"openssl_random_pseudo_bytes returned false." );
} else {
$buffer .= $openssl_bytes;
$this->logger->debug(
"openssl_random_pseudo_bytes generated " .
strlen( $openssl_bytes ) . "
bytes of " .
- ( $openssl_strong ? "strong" :
"weak" ) . " randomness.\n" );
+ ( $openssl_strong ? "strong" :
"weak" ) . " randomness." );
}
if ( strlen( $buffer ) >= $bytes ) {
// openssl tells us if the random
source was strong, if some of our data was generated
@@ -291,7 +289,7 @@
$rem = $bytes - strlen( $buffer );
if ( !function_exists( 'stream_set_read_buffer' ) &&
$forceStrong ) {
$this->logger->debug( "Was forced to read from
/dev/urandom " .
- "without control over the buffer
size.\n" );
+ "without control over the buffer size."
);
}
// /dev/urandom is generally considered the best
possible commonly
// available random source, and is available on most
*nix systems.
@@ -317,14 +315,14 @@
$buffer .= $random_bytes;
fclose( $urandom );
$this->logger->debug( "/dev/urandom generated "
. strlen( $random_bytes ) .
- " bytes of randomness.\n" );
+ " bytes of randomness." );
if ( strlen( $buffer ) >= $bytes ) {
// urandom is always strong, set to
true if all our data was generated using it
$this->strong = true;
}
} else {
- $this->logger->debug( "/dev/urandom could not
be opened.\n" );
+ $this->logger->debug( "/dev/urandom could not
be opened." );
}
}
@@ -336,7 +334,7 @@
// out and being used to predict the /randomness/ that follows.
if ( strlen( $buffer ) < $bytes ) {
$this->logger->debug( __METHOD__ .
- ": Falling back to using a pseudo random state
to generate randomness.\n" );
+ ": Falling back to using a pseudo random state
to generate randomness." );
}
while ( strlen( $buffer ) < $bytes ) {
$buffer .= MWCryptHash::hmac( $this->randomState(),
strval( mt_rand() ) );
@@ -352,7 +350,7 @@
$buffer = substr( $buffer, $bytes );
$this->logger->debug( strlen( $buffer ) .
- " bytes of randomness leftover in the buffer.\n" );
+ " bytes of randomness leftover in the buffer." );
return $generated;
}
--
To view, visit https://gerrit.wikimedia.org/r/320784
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I572206296fc3a0a498febb18925672a67480eb18
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Hashar <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits