Skip to content

Commit

Permalink
m
Browse files Browse the repository at this point in the history
  • Loading branch information
uc-itcom committed May 29, 2020
1 parent d5a3733 commit 0251bc5
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions CryptoProCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ class CryptoProCli
*/
public static $cryptcpExec = '/opt/cprocsp/bin/amd64/cryptcp';

private static function getCryptcpExec()
{
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
return '"'.self::$cryptcpExec.'"';
} else {
return self::$cryptcpExec;
}
}

/**
* Подписать ранее неподписанный файл
Expand All @@ -27,7 +35,7 @@ class CryptoProCli
*/
public static function signFile($file, $thumbprint, $toFile = null)
{
$shellCommand = self::$cryptcpExec .
$shellCommand = self::getCryptcpExec() .
' -sign -thumbprint ' . $thumbprint . ' ' . $file . ' ' . $toFile;
$result = shell_exec($shellCommand);

Expand Down Expand Up @@ -67,12 +75,27 @@ public static function signData($data, $thumbprint)
*/
public static function addSignToFile($file, $thumbprint)
{
$shellCommand = self::$cryptcpExec .
$shellCommand = self::getCryptcpExec() .
' -addsign -thumbprint ' . $thumbprint . ' ' . $file;
$result = shell_exec($shellCommand);

if (strpos($result, "Signed message is created.") <= 0) {
throw new \Exception('В ответе Cryptcp не найдена строка Signed message is created: ' . $result . ' команда ' . $shellCommand);
}
}

/**
* @param $file
* @throws \Exception
*/
public static function verifyFile($file)
{
$shellCommand = self::getCryptcpExec() .
' -verify -verall ' . $file;
$result = shell_exec($shellCommand);
if (strpos($result, "[ErrorCode: 0x00000000]") === false && strpos($result, "[ReturnCode: 0]") === false) {
//Проверка неуспешна
throw new \Exception('В ответе Cryptcp не найдена строка [ErrorCode: 0x00000000] и [ReturnCode: 0]: ' . $result . ' команда ' . $shellCommand);
}
}
}

0 comments on commit 0251bc5

Please sign in to comment.