Ошибка дешифрования SMIME при использовании openssl в файле PHP - PullRequest
0 голосов
/ 02 марта 2019

Я занимаюсь разработкой PHP-кода для дешифрования и шифрования сообщений, получаемых через http-связь.Теперь я получаю сообщение об ошибке при расшифровке сообщения SMIME, которое отправляется партнером по протоколу HTTP.Не могли бы вы помочь мне решить эту проблему

Это часть расшифровки блока кода, где генерируется ошибка

public function decrypt($input){
        /*file_put_contents('/tmp/decrypt', '---------------------------------------------------------------'."\n", FILE_APPEND);
        file_put_contents('/tmp/decrypt', 'try to decrypt file :'."\n", FILE_APPEND);
        file_put_contents('/tmp/decrypt', '---------------------------------------------------------------'."\n", FILE_APPEND);
        file_put_contents('/tmp/decrypt', print_r(file_get_contents($input), true)."\n", FILE_APPEND);*/

        try {
            $private_key = self::getPrivateFromPKCS12($this->partner_to->sec_pkcs12, $this->partner_to->sec_pkcs12_password, '');
            if (!$private_key)
                throw new AS2Exception('Unable to extract private key from PKCS12 file. (' . $this->partner_to->sec_pkcs12 . ' - using:' . $this->partner_to->sec_pkcs12_password.')');

            $output = self::getTempFilename();

            $command = self::$ssl_openssl . ' smime '    . 
                                            ' -decrypt ' . 
                                            ' -in '      . escapeshellarg($input) . 
                                            ' -inkey '   . escapeshellarg($private_key) . 
                                            ' -out '     . escapeshellarg($output);

            // seems to generate non-conform message
            /*$security = ' -pkcs12 '.escapeshellarg($this->partner_to->sec_pkcs12).
                ($this->partner_to->sec_pkcs12_password?' -password '.escapeshellarg($this->partner_to->sec_pkcs12_password):' -nopassword');

            $command = self::$javapath.' -jar '.escapeshellarg(AS2_DIR_BIN.self::$ssl_adapter).
                                       ' decrypt'.
                                       $security.
                                       ' -in '.escapeshellarg($input).
                                       ' -out '.escapeshellarg($output).
                                       ' >/dev/null';*/

            $result = $this->exec($command);

            return $output;
        }
        catch(Exception $e){
            throw $e;
        }
    }

Когда я запускаю этот код, я получаю ошибку ниже

exception 'Exception' with message 'Unexpected error in command line : openssl smime  -decrypt  -in '/tmp/as2file_ZK6OOB' -inkey '/tmp/as2file_vdZbjP' -out '/tmp/as2file_9yaBN2'' in /var/www/vhosts/industrialbuy.com/industrial-buy.com/edi/AS2Secure/lib/AS2Adapter.php:570
Stack trace:
#0 /var/www/vhosts/industrialbuy.com/industrial-buy.com/edi/AS2Secure/lib/AS2Adapter.php(393): AS2Adapter::exec('openssl smime  ...')
#1 /var/www/vhosts/industrialbuy.com/industrial-buy.com/edi/AS2Secure/lib/AS2Request.php(100): AS2Adapter->decrypt('/tmp/as2file_ZK...')
#2 /var/www/vhosts/industrialbuy.com/industrial-buy.com/edi/AS2Secure/lib/AS2Server.php(88): AS2Request->decrypt()
#3 /var/www/vhosts/industrialbuy.com/industrial-buy.com/edi/AS2Secure/www/as2/HttpReceiver/index.php(60): AS2Server::handle()

Дайте мне знать, если вам нужна дополнительная информация.

...