Skip to content

Commit

Permalink
Revert "Issue #10730: Implement CAPICOM PRNG source for Windows servers"
Browse files Browse the repository at this point in the history
This reverts commit ab7dad3.

Relying upon the CAPICOM.Utilities.1 library for providing a PRNG source
for Windows environments seems to be problematic. Problems include lack
of CAPICOM libraries in certain Windows environments as well as
potentially garbled and unpredictable output from the CAPICOM library.
  • Loading branch information
davidhicks committed Mar 1, 2010
1 parent ba97560 commit 457d8c9
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions core/crypto_api.php
Expand Up @@ -57,16 +57,18 @@ function crypto_init() {
* randomness if less security is needed or a strong source of randomness isn't
* available. The use of weak randomness for cryptographic purposes is strongly
* discouraged because it contains low entropy and is predictable.
*
* Note that openssl_random_pseudo_bytes seems to perform very poorly on
* Windows servers. Therefore we don't event attempt to use this PRNG source
* if the server is running Windows.
*
* @param int $p_bytes Number of bytes of randomness required
* @param bool $p_require_strong_generator Whether or not a weak source of randomness can be used by this function
* @return string|null Raw binary string containing the requested number of bytes of random output or null if the output couldn't be created
*/
function crypto_generate_random_string( $p_bytes, $p_require_strong_generator = true ) {

# First we attempt to use the secure PRNG provided by OpenSSL in PHP 5.3.
# Note that openssl_random_pseudo_bytes seems to perform very poorly on
# Windows servers. Therefore we don't even attempt to use this PRNG source
# if the server is running Windows.
# First we attempt to use the secure PRNG provided by OpenSSL in PHP 5.3
if ( !is_windows_server() && function_exists( 'openssl_random_pseudo_bytes' ) ) {
$t_random_bytes = openssl_random_pseudo_bytes( $p_bytes, $t_strong );
if ( $t_random_bytes !== false ) {
Expand All @@ -93,18 +95,9 @@ function crypto_generate_random_string( $p_bytes, $p_require_strong_generator =
}
}

# For Windows systems we can try using Microsoft CryptoAPI as a secure source of
# randomness.
if ( is_windows_server() ) {
if ( class_exists( 'COM' ) ) {
try {
$CAPICOM_utility = new COM( 'CAPICOM.Utilities.1' );
# Second argument to GetRandom is CAPICOM_ENCODE_BINARY (=1)
# as per http://msdn.microsoft.com/en-us/library/aa388182%28VS.85%29.aspx
$t_random_string = $CAPICOM_Utility->GetRandom( $p_bytes, 1 );
} catch (Exception $e) {}
}
}
# For Windows systems, we can try using Microsoft CryptoAPI to retrieve
# more reliable PRNG output than what PHP can provide by itself.
# !TODO

# At this point we've run out of possibilities for generating randomness
# from a strong source. Unless weak output is specifically allowed by the
Expand Down

0 comments on commit 457d8c9

Please sign in to comment.