[BUGFIX] ext:rsaauth cliBackend pollutes cli output 77/29877/7
authorChristian Kuhn <lolli@schwarzbu.ch>
Mon, 5 May 2014 16:50:52 +0000 (18:50 +0200)
committerNicole Cordes <typo3@cordes.co>
Tue, 6 May 2014 15:40:20 +0000 (17:40 +0200)
The CommandLineBackend using exec "openssl genrsa" outputs its key
generation to standard error. If SAPI is cli (eg. in unit tests),
this is is shown to the user. The patch silences openssl by
redirecting stderr to /dev/null (NUL on Windows systems).

Resolves: #58530
Related: #51436
Releases: 6.2
Change-Id: I702d2d3180bc2e32e5548a4402d4eefb02dd2523
Reviewed-on: https://review.typo3.org/29877
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Stefan Neufeind
Reviewed-by: Markus Klein
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
Reviewed-by: Nicole Cordes
Tested-by: Nicole Cordes
typo3/sysext/rsaauth/Classes/Backend/CommandLineBackend.php
typo3/sysext/rsaauth/Tests/Unit/Backend/CommandLineBackendTest.php

index 5e09106..2ef268e 100644 (file)
@@ -84,6 +84,10 @@ class CommandLineBackend extends \TYPO3\CMS\Rsaauth\Backend\AbstractBackend {
                        return $keyPair;
                }
 
+               if ($this->opensslPath === FALSE) {
+                       return NULL;
+               }
+
                // Create a temporary file. Security: tempnam() sets permissions to 0600
                $privateKeyFile = tempnam($this->temporaryDirectory, uniqid());
 
@@ -93,6 +97,11 @@ class CommandLineBackend extends \TYPO3\CMS\Rsaauth\Backend\AbstractBackend {
                // to do the same and use the F4 (0x10001) exponent. This is the most
                // secure.
                $command = $this->opensslPath . ' genrsa -out ' . escapeshellarg($privateKeyFile) . ' 1024';
+               if (TYPO3_OS === 'WIN') {
+                       $command .= ' 2>NUL';
+               } else {
+                       $command .= ' 2>/dev/null';
+               }
                \TYPO3\CMS\Core\Utility\CommandUtility::exec($command);
                // Test that we got a private key
                $privateKey = file_get_contents($privateKeyFile);
index db95cc3..d528998 100644 (file)
@@ -40,6 +40,10 @@ class CommandLineBackendTest extends \TYPO3\CMS\Core\Tests\UnitTestCase  {
        protected $subject = NULL;
 
        public function setUp() {
+               if (TYPO3_OS === 'WIN') {
+                       $this->markTestSkipped('This test is not available on Windows.');
+               }
+
                $this->subject = new CommandLineBackend();
        }
 
@@ -47,18 +51,26 @@ class CommandLineBackendTest extends \TYPO3\CMS\Core\Tests\UnitTestCase  {
         * @test
         */
        public function createNewKeyPairCreatesReadyKeyPair() {
-               $this->assertTrue(
-                       $this->subject->createNewKeyPair()->isReady()
-               );
+               $keyPair = $this->subject->createNewKeyPair();
+               if ($keyPair === NULL) {
+                       $this->markTestSkipped('KeyPair could not be generated. Maybe openssl was not found.');
+               }
+
+               $this->assertTrue($keyPair->isReady());
        }
 
        /**
         * @test
         */
        public function createNewKeyPairCreatesKeyPairWithDefaultExponent() {
+               $keyPair = $this->subject->createNewKeyPair();
+               if ($keyPair === NULL) {
+                       $this->markTestSkipped('KeyPair could not be generated. Maybe openssl was not found.');
+               }
+
                $this->assertSame(
                        CommandLineBackend::DEFAULT_EXPONENT,
-                       $this->subject->createNewKeyPair()->getExponent()
+                       $keyPair->getExponent()
                );
        }