59 $path = trim(GeneralUtility::makeInstance(ExtensionConfiguration::class)->
get(
'rsaauth',
'temporaryDirectory'));
60 if ($path !==
'' && $path[0] ===
'/' && @is_dir($path) && is_writable($path)) {
61 $this->temporaryDirectory = $path;
72 $this->opensslPath =
null;
73 $this->temporaryDirectory =
null;
75 throw new \RuntimeException(
76 __CLASS__ .
' cannot be unserialized',
92 $keyPair = GeneralUtility::makeInstance(\
TYPO3\CMS\Rsaauth\Keypair::class);
93 if ($keyPair->isReady()) {
97 if ($this->opensslPath ===
false) {
109 $command = $this->opensslPath .
' genrsa -out ' . escapeshellarg($privateKeyFile) .
' 1024';
111 $command .=
' 2>NUL';
113 $command .=
' 2>/dev/null';
117 $privateKey = file_get_contents($privateKeyFile);
118 if (
false !== strpos($privateKey,
'BEGIN RSA PRIVATE KEY')) {
120 $command = $this->opensslPath .
' rsa -noout -modulus -in ' . escapeshellarg($privateKeyFile);
122 if (strpos($value,
'Modulus=') === 0) {
123 $publicKey = substr($value, 8);
125 $keyPair->setExponent(self::DEFAULT_EXPONENT);
126 $keyPair->setPrivateKey($privateKey);
127 $keyPair->setPublicKey($publicKey);
133 @unlink($privateKeyFile);
143 public function decrypt($privateKey, $data)
147 file_put_contents($privateKeyFile, $privateKey);
149 file_put_contents($dataFile, base64_decode($data));
151 $command = $this->opensslPath .
' rsautl -inkey ' . escapeshellarg($privateKeyFile) .
' -in ' . escapeshellarg($dataFile) .
' -decrypt';
156 @unlink($privateKeyFile);
171 if ($this->opensslPath) {
174 $result = strpos($test,
'OpenSSL ') === 0;