Rev 33 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | daniel-mar | 1 | #!/usr/bin/php |
2 | <?php |
||
3 | |||
33 | daniel-mar | 4 | /* |
5 | * VNag - Nagios Framework for PHP |
||
6 | * Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com> |
||
7 | * Licensed under the terms of the Apache 2.0 license |
||
8 | * |
||
9 | * Revision 2018-07-11 |
||
10 | */ |
||
11 | |||
2 | daniel-mar | 12 | $file = $argv[1]; |
13 | |||
14 | $cont = file_get_contents($file); |
||
15 | |||
16 | if (!preg_match('@<\?php /\* <ViaThinkSoftSignature>(.+)</ViaThinkSoftSignature> \*/ \?>\n@ismU', $cont, $m)) { |
||
17 | die("File $file not signed\n"); |
||
18 | } |
||
19 | $signature = base64_decode($m[1]); |
||
20 | |||
21 | $naked = preg_replace('@<\?php /\* <ViaThinkSoftSignature>(.+)</ViaThinkSoftSignature> \*/ \?>\n@ismU', '', $cont); |
||
22 | $hash = hash("sha256", $naked.basename($file)); |
||
23 | |||
24 | $public_key = file_get_contents(__DIR__.'/public.pem'); |
||
25 | if (!openssl_verify($hash, $signature, $public_key, OPENSSL_ALGO_SHA256)) { |
||
26 | die("Signature invalid\n"); |
||
27 | } |
||
28 | |||
29 | echo "Signature valid\n"; |