diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-09-20 15:07:40 +0200 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-09-20 15:07:40 +0200 |
| commit | 2a619ceba75a4c16b25de12d59a87eac795a4468 (patch) | |
| tree | 1d63a35217011fa761b703633b3f91fd839ec71e /wrappers/php/src | |
| parent | 7e309b67de74fe5bd5a1c70c1880c2a381c4f78b (diff) | |
Remove: unused wrappers
Diffstat (limited to 'wrappers/php/src')
| -rw-r--r-- | wrappers/php/src/Discovery.php | 74 | ||||
| -rw-r--r-- | wrappers/php/src/Impl/GoSlice.php | 43 | ||||
| -rw-r--r-- | wrappers/php/src/InvalidSignatureException.php | 12 | ||||
| -rw-r--r-- | wrappers/php/src/InvalidSignatureUnknownKeyException.php | 12 | ||||
| -rw-r--r-- | wrappers/php/src/SignatureTooOldException.php | 12 | ||||
| -rw-r--r-- | wrappers/php/src/UnknownVerifyException.php | 12 | ||||
| -rw-r--r-- | wrappers/php/src/VerifyException.php | 14 |
7 files changed, 0 insertions, 179 deletions
diff --git a/wrappers/php/src/Discovery.php b/wrappers/php/src/Discovery.php deleted file mode 100644 index 39aa53d..0000000 --- a/wrappers/php/src/Discovery.php +++ /dev/null @@ -1,74 +0,0 @@ -<?php declare(strict_types=1); - -namespace EduVpn\Common; - -use EduVpn\Common\Impl\GoSlice; -use Error; -use FFI; -use InvalidArgumentException; - -final class Discovery -{ - public function __construct() { } - - const LIB_NAME = 'eduvpn_common'; - - private static ?FFI $ffi = null; - - private static function ffi(): FFI - { - if (!self::$ffi) { - if (!(self::$ffi = FFI::load(__DIR__ . '/headers/' . self::LIB_NAME . '_php.h'))) - throw new Error('failed to load ' . self::LIB_NAME); - } - return self::$ffi; - } - - /** - * Verifies the signature on the JSON server_list.json/organization_list.json file. - * If the function returns, the signature is valid for the given file type. - * - * @param string $signature .minisig signature file contents. - * @param string $signedJson Signed .json file contents. - * @param string $expectedFileName The file type to be verified, one of "server_list.json" or - * "organization_list.json". - * @param int $minSignTime Minimum time for signature (UNIX timestamp, seconds). Should be set to at least - * the time of the previous signature. - * @return void - * @throws InvalidArgumentException If expectedFileName is not one of the allowed values. - * @throws VerifyException If signature verification fails. - */ - public static function verify(string $signature, string $signedJson, string $expectedFileName, - int $minSignTime): void - { - $ffi = self::ffi(); - $signatureData = new GoSlice($ffi, $signature); - $jsonData = new GoSlice($ffi, $signedJson); - $expectedNameData = new GoSlice($ffi, $expectedFileName); - - $result = $ffi->Verify($signatureData->slice(), $jsonData->slice(), $expectedNameData->slice(), $minSignTime); - - switch ($result) { - case 0: - return; - case 1: - throw new InvalidArgumentException('unknown expected file name', $result); - case 2: - throw new InvalidSignatureException(); - case 3: - throw new InvalidSignatureUnknownKeyException(); - case 4: - throw new SignatureTooOldException(); - default: - throw new UnknownVerifyException($result); - } - } - - /** @internal Use for testing only, see Go documentation. */ - public static function insecureTestingSetExtraKey(string $keyString): void - { - $ffi = self::ffi(); - $keyData = new GoSlice($ffi, $keyString); - $ffi->InsecureTestingSetExtraKey($keyData->slice()); - } -} diff --git a/wrappers/php/src/Impl/GoSlice.php b/wrappers/php/src/Impl/GoSlice.php deleted file mode 100644 index b285cfd..0000000 --- a/wrappers/php/src/Impl/GoSlice.php +++ /dev/null @@ -1,43 +0,0 @@ -<?php declare(strict_types=1); - -/** @internal */ - -namespace EduVpn\Common\Impl; - -use FFI; -use FFI\CData; -use RuntimeException; - -/** @internal */ -class GoSlice -{ - // Will be destroyed along with this GoSlice - private CData $cData, $slice; - - public function __construct(FFI $ffi, string $data) - { - $len = strlen($data); - $cData = FFI::new(FFI::arrayType(FFI::type('char'), [$len]), false); - if ($cData === null) throw new RuntimeException('error allocating buffer'); - $this->cData = $cData; - FFI::memcpy($cData, $data, $len); - - $slice = $ffi->new('GoSlice'); - if ($slice === null) throw new RuntimeException('error allocating buffer'); - $this->slice = $slice; - $slice->data = FFI::addr($cData); // $cData must not be destroyed while $slice is in use - $slice->cap = $slice->len = $len; - } - - public function slice(): CData - { - return $this->slice; - } - - public function __destruct() - { - // Make sure we do not unknowingly use a slice with deallocated data - $this->slice->data = null; - $this->slice->cap = $this->slice->len = 0; - } -} diff --git a/wrappers/php/src/InvalidSignatureException.php b/wrappers/php/src/InvalidSignatureException.php deleted file mode 100644 index d5d4164..0000000 --- a/wrappers/php/src/InvalidSignatureException.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php declare(strict_types=1); - -namespace EduVpn\Common; - -/** Signature is invalid (for the expected file type). */ -final class InvalidSignatureException extends VerifyException -{ - public function __construct() - { - parent::__construct('invalid signature', 2); - } -} diff --git a/wrappers/php/src/InvalidSignatureUnknownKeyException.php b/wrappers/php/src/InvalidSignatureUnknownKeyException.php deleted file mode 100644 index 73a535e..0000000 --- a/wrappers/php/src/InvalidSignatureUnknownKeyException.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php declare(strict_types=1); - -namespace EduVpn\Common; - -/** Signature was created with an unknown key and has not been verified. */ -final class InvalidSignatureUnknownKeyException extends VerifyException -{ - public function __construct() - { - parent::__construct('invalid signature (unknown key)', 3); - } -} diff --git a/wrappers/php/src/SignatureTooOldException.php b/wrappers/php/src/SignatureTooOldException.php deleted file mode 100644 index 4b7e341..0000000 --- a/wrappers/php/src/SignatureTooOldException.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php declare(strict_types=1); - -namespace EduVpn\Common; - -/** Signature timestamp smaller than specified minimum signing time (rollback). */ -final class SignatureTooOldException extends VerifyException -{ - public function __construct() - { - parent::__construct('replay of previous signature (rollback)', 4); - } -} diff --git a/wrappers/php/src/UnknownVerifyException.php b/wrappers/php/src/UnknownVerifyException.php deleted file mode 100644 index 1290cc3..0000000 --- a/wrappers/php/src/UnknownVerifyException.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php declare(strict_types=1); - -namespace EduVpn\Common; - -/** Other unknown error. */ -final class UnknownVerifyException extends VerifyException -{ - public function __construct(int $code) - { - parent::__construct("unknown verify error ($code)", $code); - } -} diff --git a/wrappers/php/src/VerifyException.php b/wrappers/php/src/VerifyException.php deleted file mode 100644 index 101f728..0000000 --- a/wrappers/php/src/VerifyException.php +++ /dev/null @@ -1,14 +0,0 @@ -<?php declare(strict_types=1); - -namespace EduVpn\Common; - -use Exception; - -/** Verification failed, do not trust the file. */ -abstract class VerifyException extends Exception -{ - public function __construct(string $message, int $code) - { - parent::__construct($message, $code); - } -} |
