/trunk/plugins/viathinksoft/publicPages/100_whois/whois/json/vendor/sergeybrook/php-jws/LICENSE |
---|
0,0 → 1,21 |
MIT License |
Copyright (c) 2019 Sergey Brook |
Permission is hereby granted, free of charge, to any person obtaining a copy |
of this software and associated documentation files (the "Software"), to deal |
in the Software without restriction, including without limitation the rights |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
copies of the Software, and to permit persons to whom the Software is |
furnished to do so, subject to the following conditions: |
The above copyright notice and this permission notice shall be included in all |
copies or substantial portions of the Software. |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
SOFTWARE. |
/trunk/plugins/viathinksoft/publicPages/100_whois/whois/json/vendor/sergeybrook/php-jws/README.md |
---|
0,0 → 1,35 |
# PHP - JWS |
JSON Web Signature (JWS) library for PHP |
There are two signing algorithms implemented: |
- Class JwsMac: For HMAC signature using SHA-256, SHA-384 or SHA-512. |
- Class JwsRsa: For RSASSA-PKCS1-v1_5 signature using SHA-256, SHA-384 or SHA-512. |
## Installation: |
Using [Composer](https://getcomposer.org/): |
```bash |
$ composer require sergeybrook/php-jws |
``` |
Or: |
- Copy "src" dir to your project (optionally rename it to whatever you want). |
- Require class autoloader (included): |
```php |
<?php |
require_once("<src_dir>/autoload.php"); |
... |
``` |
## Usage: |
See `/examples` dir. |
## Specs: |
- JSON Web Signature (JWS) - [RFC 7515](https://tools.ietf.org/html/rfc7515) |
- JSON Web Algorithms (JWA) - [RFC 7518](https://tools.ietf.org/html/rfc7518) |
/trunk/plugins/viathinksoft/publicPages/100_whois/whois/json/vendor/sergeybrook/php-jws/VERSION.md |
---|
0,0 → 1,8 |
### 1.0.1 - 2019-04-08 |
- `Changed:` Set key methods now throws exception rather than returns status. |
- `Changed:` Remove only those JWS header parameters that contains zero-length string. |
### 1.0.0 - 2019-04-07 - Initial stable release. |
--- |
Semantic Versioning: https://semver.org |
/trunk/plugins/viathinksoft/publicPages/100_whois/whois/json/vendor/sergeybrook/php-jws/composer.json |
---|
0,0 → 1,24 |
{ |
"name": "sergeybrook/php-jws", |
"description": "JSON Web Signature (JWS) library for PHP", |
"type": "library", |
"keywords": ["JWS", "HMAC", "RSASSA-PKCS1-v1_5", "SHA-256", "SHA-384", "SHA-512"], |
"license": "MIT", |
"authors": [ |
{"name": "Sergey Brook", "email": "brook.sergey@gmail.com", "role": "Developer"} |
], |
"support": { |
"email": "brook.sergey@gmail.com", |
"issues": "https://github.com/SergeyBrook/php-jws/issues" |
}, |
"require": { |
"php": ">=7.0", |
"ext-json": "*", |
"ext-openssl": "*" |
}, |
"autoload": { |
"psr-4": { |
"SBrook\\": "src/" |
} |
} |
} |
/trunk/plugins/viathinksoft/publicPages/100_whois/whois/json/vendor/sergeybrook/php-jws/examples/cert/create-cert.sh |
---|
0,0 → 1,14 |
#!/bin/bash |
# Generate private key and self-signed certificate. |
# Make sure script has execute permissions, if not: |
# $ chmod +x ./create-cert.sh |
# Usage: |
# $ ./create-cert.sh NAME DAYS |
# Where: |
# NAME - Key / certificate name |
# DAYS - Certificate validity days |
## Generate password protected private key: |
openssl genrsa -des3 -out ./prv-${1}.key 2048 |
## Create and self-sign certificate with private key: |
openssl req -x509 -sha256 -new -config ./openssl.cnf -key ./prv-${1}.key -days ${2} -out ./pub-${1}.crt |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/trunk/plugins/viathinksoft/publicPages/100_whois/whois/json/vendor/sergeybrook/php-jws/examples/cert/openssl.cnf |
---|
0,0 → 1,8 |
[req] |
default_bits = 2048 |
default_md = sha256 |
distinguished_name = req_dn |
[req_dn] |
commonName = Common Name (e.g. server FQDN or YOUR name) |
commonName_max = 64 |
/trunk/plugins/viathinksoft/publicPages/100_whois/whois/json/vendor/sergeybrook/php-jws/examples/jws-mac.php |
---|
0,0 → 1,95 |
<?php |
/** |
* JWS-MAC example |
* Usage: |
* 1. Run from examples dir: |
* $ php ./jws-rsa.php |
*/ |
use SBrook\JWS\JwsMac; |
use SBrook\JWS\Exception\JwsException; |
// Stand-alone: |
require_once("../src/autoload.php"); |
// Composer: |
//require_once("../vendor/autoload.php"); |
$exitCode = 0; |
$secretOne = "8AA829AC3E1FAF5B75C1EC67A610670FFE56BF37"; |
$secretTwo = "6FB2486F46632DFC171B36ED64E9FA1BAE06FC29"; |
// For JWS registered header parameter names see (RFC 7515, Section 4.1) |
$header = [ |
"typ" => "TXT", |
"ts0" => "", |
"ts1" => 0, |
"ts2" => false, |
"ts3" => null, |
"ts4" => chr(32), |
"ts5" => chr(7) |
]; |
$payloadOne = "Original message content"; |
$payloadTwo = "Fake message content"; |
try { |
// Create JwsMac instance: |
$jws = new JwsMac($secretOne); |
// Create original message from $payloadOne and sign with secret key $secretOne (set in constructor): |
$message = $jws->sign($payloadOne, $header); |
echo "\nOriginal message:\n"; |
echo "--- BEGIN JWS ---\n$message\n---- END JWS ----\n"; |
// Get original message header: |
$h = $jws->getHeader($message); |
// JSON encode just to more clearly show the values: |
echo "\nHeader => " . json_encode($h) . "\n"; |
// Get original message payload: |
$p = $jws->getPayload($message); |
echo "\nPayload => \"$p\"\n"; |
// Verify original message with right secret key $secretOne (set in constructor): |
$v = $jws->verify($message); |
echo "\nVerifying original message with right secret key:\n"; |
echo "Message is " . ($v ? "VALID" : "INVALID") . "\n"; |
// Verify original message with wrong secret key $secretTwo: |
$jws->setSecretKey($secretTwo); |
$v = $jws->verify($message); |
echo "\nVerifying original message with wrong secret key:\n"; |
echo "Message is " . ($v ? "VALID" : "INVALID") . "\n"; |
echo "\n" . str_repeat("=", 80) . "\n"; |
// Now, let's manipulate original message by putting a fake content into it: |
// Get header and signature from original message: |
list($h, , $s) = explode(".", $message); |
// Rebuild message with fake payload $payloadTwo: |
$fakeMessage = $h . "." . base64_encode($payloadTwo) . "." . $s; |
echo "\nFake message:\n"; |
echo "--- BEGIN JWS ---\n$fakeMessage\n---- END JWS ----\n"; |
// Get fake message payload: |
$p = $jws->getPayload($fakeMessage); |
echo "\nPayload => \"$p\"\n"; |
// Verify fake message with right secret key $secretOne: |
$jws->setSecretKey($secretOne); |
$v = $jws->verify($fakeMessage); |
echo "\nVerifying fake message with right secret key:\n"; |
echo "Message is " . ($v ? "VALID" : "INVALID") . "\n"; |
} catch (JwsException $e) { |
$exitCode = 1; |
do { |
echo "Error (".$e->getCode()."): ".$e->getMessage()."\n\tIn file: ".$e->getFile()." line: ".$e->getLine()."\n"; |
} while ($e = $e->getPrevious()); |
} |
exit($exitCode); |
/trunk/plugins/viathinksoft/publicPages/100_whois/whois/json/vendor/sergeybrook/php-jws/examples/jws-rsa.php |
---|
0,0 → 1,105 |
<?php |
/** |
* JWS-RSA example |
* Usage: |
* 1. Generate two key/certificate pairs - run from examples/cert dir: |
* $ ./create-cert.sh one 365 |
* $ ./create-cert.sh two 365 |
* This will create "prv-one.key"/"pub-one.crt" and "prv-two.key"/"pub-two.crt" pairs in examples/cert dir. |
* 2. Run from examples dir: |
* $ php ./jws-rsa.php |
*/ |
use SBrook\JWS\JwsRsa; |
use SBrook\JWS\Exception\JwsException; |
// Stand-alone: |
require_once("../src/autoload.php"); |
// Composer: |
//require_once("../vendor/autoload.php"); |
$exitCode = 0; |
$prvOne = "file://./cert/prv-one.key"; |
$prvOnePass = "password"; |
$pubOne = "file://./cert/pub-one.crt"; |
$pubTwo = "file://./cert/pub-two.crt"; |
// For JWS registered header parameter names see (RFC 7515, Section 4.1) |
$header = [ |
"typ" => "TXT", |
"ts0" => "", |
"ts1" => 0, |
"ts2" => false, |
"ts3" => null, |
"ts4" => chr(32), |
"ts5" => chr(7) |
]; |
$payloadOne = "Original message content"; |
$payloadTwo = "Fake message content"; |
try { |
// Create JwsRsa instance: |
$jws = new JwsRsa(); |
// Create original message from $payloadOne and sign with private key $prvOne: |
$jws->setPrivateKey($prvOne, $prvOnePass); |
$message = $jws->sign($payloadOne, $header); |
echo "\nOriginal message:\n"; |
echo "--- BEGIN JWS ---\n$message\n---- END JWS ----\n"; |
// Get original message header: |
$h = $jws->getHeader($message); |
// JSON encode just to more clearly show the values: |
echo "\nHeader => " . json_encode($h) . "\n"; |
// Get original message payload: |
$p = $jws->getPayload($message); |
echo "\nPayload => \"$p\"\n"; |
// Verify original message with right public key $pubOne: |
$jws->setPublicKey($pubOne); |
$v = $jws->verify($message); |
echo "\nVerifying original message with right public key:\n"; |
echo "Message is " . ($v ? "VALID" : "INVALID") . "\n"; |
// Verify original message with wrong public key $pubTwo: |
$jws->setPublicKey($pubTwo); |
$v = $jws->verify($message); |
echo "\nVerifying original message with wrong public key:\n"; |
echo "Message is " . ($v ? "VALID" : "INVALID") . "\n"; |
echo "\n" . str_repeat("=", 80) . "\n"; |
// Now, let's manipulate original message by putting a fake content into it: |
// Get header and signature from original message: |
list($h, , $s) = explode(".", $message); |
// Rebuild message with fake payload $payloadTwo: |
$fakeMessage = $h . "." . base64_encode($payloadTwo) . "." . $s; |
echo "\nFake message:\n"; |
echo "--- BEGIN JWS ---\n$fakeMessage\n---- END JWS ----\n"; |
// Get fake message payload: |
$p = $jws->getPayload($fakeMessage); |
echo "\nPayload => \"$p\"\n"; |
// Verify fake message with right public key $pubOne: |
$jws->setPublicKey($pubOne); |
$v = $jws->verify($fakeMessage); |
echo "\nVerifying fake message with right public key:\n"; |
echo "Message is " . ($v ? "VALID" : "INVALID") . "\n"; |
} catch (JwsException $e) { |
$exitCode = 1; |
do { |
echo "Error (".$e->getCode()."): ".$e->getMessage()."\n\tIn file: ".$e->getFile()." line: ".$e->getLine()."\n"; |
} while ($e = $e->getPrevious()); |
} |
exit($exitCode); |
/trunk/plugins/viathinksoft/publicPages/100_whois/whois/json/vendor/sergeybrook/php-jws/src/JWS/Asymmetric.php |
---|
0,0 → 1,25 |
<?php |
/** |
* SBrook\JWS\Asymmetric |
*/ |
namespace SBrook\JWS; |
/** |
* Interface Asymmetric |
* @package SBrook\JWS |
*/ |
interface Asymmetric { |
/** |
* Set private key. |
* @param $key - Private key. |
* @param $pass - Private key password. |
*/ |
public function setPrivateKey($key, $pass); |
/** |
* Set public key. |
* @param $key - Public key. |
*/ |
public function setPublicKey($key); |
} |
/trunk/plugins/viathinksoft/publicPages/100_whois/whois/json/vendor/sergeybrook/php-jws/src/JWS/Exception/JwsException.php |
---|
0,0 → 1,27 |
<?php |
/** |
* SBrook\JWS\Exception\JwsException |
*/ |
namespace SBrook\JWS\Exception; |
use Exception; |
/** |
* Class JwsException |
* @package SBrook\JWS\Exception |
*/ |
class JwsException extends Exception { |
// Redefine the exception so message isn't optional: |
public function __construct($message, $code = 0, Exception $previous = null) { |
// Some code |
// Make sure everything is assigned properly: |
parent::__construct($message, $code, $previous); |
} |
// Custom string representation of object: |
public function __toString() { |
return __CLASS__ . ": [{$this->code}]: {$this->message}\n"; |
} |
} |
/trunk/plugins/viathinksoft/publicPages/100_whois/whois/json/vendor/sergeybrook/php-jws/src/JWS/Jws.php |
---|
0,0 → 1,153 |
<?php |
/** |
* SBrook\JWS\Jws |
*/ |
namespace SBrook\JWS; |
use SBrook\JWS\Exception\JwsException; |
/** |
* Class Jws |
* @package SBrook\JWS |
* @throws JwsException: |
* Encode: |
* 10. Header should be an array |
* 11. Payload should be a non empty string |
* 12. Unknown signature algorithm in header |
* Decode: |
* 20. JWS should be a non empty string |
* 21. Invalid JWS header |
* 22. Error while decoding JWS header |
* 23. Error while decoding JWS payload |
*/ |
abstract class Jws { |
/** |
* Create JWS from payload and optional header and sign it. |
* @param $payload - Payload. |
* @param $header - Header data. |
*/ |
abstract public function sign($payload, $header); |
/** |
* Verify JWS signature. |
* @param $jws - JWS. |
*/ |
abstract public function verify($jws); |
/** |
* Check validity of signature algorithm. |
* @param string $algorithm - Algorithm name. |
* @return bool - TRUE on valid algorithm, FALSE on invalid. |
*/ |
abstract protected function isValidAlgorithm(string $algorithm): bool; |
/** |
* Get JWS header. |
* @param string $jws - JWS. |
* @return array - Decoded JWS header. |
* @throws JwsException |
*/ |
public function getHeader($jws) { |
if (is_string($jws) && strlen($jws) > 0) { |
list($h, , ) = explode(".", $jws); |
$header = json_decode(base64_decode($h, true), true); |
if (is_null($header)) { |
throw new JwsException("Error while decoding JWS header", 22); |
} else { |
return $header; |
} |
} else { |
throw new JwsException("JWS should be a non empty string", 20); |
} |
} |
/** |
* Get JWS payload. |
* @param string $jws - JWS. |
* @return string - Decoded JWS payload. |
* @throws JwsException |
*/ |
public function getPayload($jws) { |
if (is_string($jws) && strlen($jws) > 0) { |
list(, $p, ) = explode(".", $jws); |
$payload = base64_decode($p, true); |
if ($payload) { |
return $payload; |
} else { |
throw new JwsException("Error while decoding JWS payload", 23); |
} |
} else { |
throw new JwsException("JWS should be a non empty string", 20); |
} |
} |
/** |
* Validate and prepare data to sign JWS. |
* @param string $defaultAlgo - Default signature algorithm name. |
* @param string $payload - Payload. |
* @param array $header - Header data. |
* @return array - Required data to sign JWS. |
* @throws JwsException |
*/ |
protected function prepareSign($defaultAlgo, $payload, $header): array { |
if (is_array($header)) { |
if (is_string($payload) && strlen($payload) > 0) { |
// Remove header parameters with empty string values: |
foreach ($header as $key => $value) { |
if (is_string($value) && strlen($value) == 0) { |
unset($header[$key]); |
} |
} |
// If not specified, set default signature algorithm: |
if (!array_key_exists("alg", $header)) { |
$header["alg"] = $defaultAlgo; |
} |
// Don't trust anyone: |
$header["alg"] = strtoupper($header["alg"]); |
if ($this->isValidAlgorithm($header["alg"])) { |
return [ |
"alg" => $header["alg"], |
"h" => base64_encode(json_encode($header)), |
"p" => base64_encode($payload) |
]; |
} else { |
throw new JwsException("Unknown signature algorithm in header", 12); |
} |
} else { |
throw new JwsException("Payload should be a non empty string", 11); |
} |
} else { |
throw new JwsException("Header should be an array", 10); |
} |
} |
/** |
* Validate and prepare data to verify JWS. |
* @param string $jws - JWS. |
* @return array - Required data to verify JWS. |
* @throws JwsException |
*/ |
protected function prepareVerify($jws): array { |
if (is_string($jws) && strlen(trim($jws)) > 0) { |
list($h, $p, $s) = explode(".", $jws); |
$header = json_decode(base64_decode($h, true), true); |
if (is_array($header) && array_key_exists("alg", $header) && $this->isValidAlgorithm($header["alg"])) { |
return [ |
"alg" => strtoupper($header["alg"]), |
"sig" => base64_decode($s), |
"h" => $h, |
"p" => $p |
]; |
} else { |
throw new JwsException("Invalid JWS header", 21); |
} |
} else { |
throw new JwsException("JWS should be a non empty string", 20); |
} |
} |
} |
/trunk/plugins/viathinksoft/publicPages/100_whois/whois/json/vendor/sergeybrook/php-jws/src/JWS/JwsMac.php |
---|
0,0 → 1,114 |
<?php |
/** |
* SBrook\JWS\JwsMac |
*/ |
namespace SBrook\JWS; |
use SBrook\JWS\Exception\JwsException; |
/** |
* Class JwsMac |
* @package SBrook\JWS |
* @throws JwsException: |
* 30. Secret key should be a non empty string |
*/ |
class JwsMac extends Jws implements Symmetric { |
/** |
* JWS signature secret key. |
* @var string |
*/ |
protected $secretKey = ""; |
/** |
* Default signature algorithm. |
* @var string |
*/ |
protected $defaultAlgo = "HS256"; |
/** |
* Signature algorithms map JWS => hash_hmac(). |
* |
* JWS signature algorithms (RFC 7518, Section 3.2) - "alg": |
* HS256: HMAC using SHA-256 - Min recommended key length: 32 bytes |
* HS384: HMAC using SHA-384 - Min recommended key length: 48 bytes |
* HS512: HMAC using SHA-512 - Min recommended key length: 64 bytes |
* |
* @var array |
*/ |
protected $algos = [ |
"HS256" => "SHA256", |
"HS384" => "SHA384", |
"HS512" => "SHA512" |
]; |
/** |
* JwsMac constructor. |
* @param string $key - JWS signature secret key. |
* @throws JwsException |
*/ |
public function __construct($key) { |
if (is_string($key) && strlen($key) > 0) { |
$this->secretKey = $key; |
} else { |
throw new JwsException("Secret key should be a non empty string", 30); |
} |
} |
/** |
* JwsMac destructor. |
*/ |
public function __destruct() { |
unset( |
$this->secretKey, |
$this->defaultAlgo, |
$this->algos |
); |
} |
/** |
* Set JWS signature secret key - overwrites previously set key. |
* @param string $key - JWS signature secret key. |
* @param $pass - (Optional) Not in use. |
* @throws JwsException |
*/ |
public function setSecretKey($key, $pass = "") { |
if (is_string($key) && strlen($key) > 0) { |
$this->secretKey = $key; |
} else { |
throw new JwsException("Secret key should be a non empty string", 30); |
} |
} |
/** |
* Create JWS from payload and optional header and sign it. |
* @param string $payload - Payload. |
* @param array $header - (Optional) Header data. |
* @return string - JWS. |
* @throws JwsException |
*/ |
public function sign($payload, $header = []) { |
$d = $this->prepareSign($this->defaultAlgo, $payload, $header); |
return $d["h"] . "." . $d["p"] . "." . base64_encode(hash_hmac($this->algos[$d["alg"]], $d["h"] . "." . $d["p"], $this->secretKey, true)); |
} |
/** |
* Verify JWS signature. |
* @param string $jws - JWS. |
* @return bool - TRUE on valid signature, FALSE on invalid. |
* @throws JwsException |
*/ |
public function verify($jws) { |
$d = $this->prepareVerify($jws); |
return hash_equals($d["sig"], hash_hmac($this->algos[$d["alg"]], $d["h"] . "." . $d["p"], $this->secretKey, true)); |
} |
/** |
* Check validity of signature algorithm. |
* @param string $algorithm - Algorithm name. |
* @return bool - TRUE on valid algorithm, FALSE on invalid. |
*/ |
protected function isValidAlgorithm(string $algorithm): bool { |
return array_key_exists(strtoupper($algorithm), $this->algos); |
} |
} |
/trunk/plugins/viathinksoft/publicPages/100_whois/whois/json/vendor/sergeybrook/php-jws/src/JWS/JwsRsa.php |
---|
0,0 → 1,174 |
<?php |
/** |
* SBrook\JWS\JwsRsa |
*/ |
namespace SBrook\JWS; |
use SBrook\JWS\Exception\JwsException; |
/** |
* Class JwsRsa |
* @package SBrook\JWS |
* @throws JwsException: |
* 40. Private key is not set |
* 41. Public key is not set |
* 49. Forwarded openssl error(s) |
*/ |
class JwsRsa extends Jws implements Asymmetric |
{ |
/** |
* JWS signature private key. |
* @var resource |
*/ |
protected $privateKey = false; |
/** |
* JWS signature public key. |
* @var resource |
*/ |
protected $publicKey = false; |
/** |
* Default signature algorithm. |
* @var string |
*/ |
protected $defaultAlgo = "RS256"; |
/** |
* Signature algorithms map JWS => openssl_sign() / openssl_verify(). |
* |
* JWS signature algorithms (RFC 7518, Section 3.3) - "alg": |
* RS256: RSASSA-PKCS1-v1_5 using SHA-256 |
* RS384: RSASSA-PKCS1-v1_5 using SHA-384 |
* RS512: RSASSA-PKCS1-v1_5 using SHA-512 |
* |
* @var array |
*/ |
protected $algos = [ |
"RS256" => OPENSSL_ALGO_SHA256, |
"RS384" => OPENSSL_ALGO_SHA384, |
"RS512" => OPENSSL_ALGO_SHA512 |
]; |
/** |
* JwsRsa destructor. |
*/ |
public function __destruct() |
{ |
if ($this->privateKey) { |
openssl_pkey_free($this->privateKey); |
} |
if ($this->publicKey) { |
openssl_pkey_free($this->publicKey); |
} |
unset( |
$this->defaultAlgo, |
$this->algos |
); |
} |
/** |
* Set private key - overwrites previously set key. |
* @param string $key - Private key. Same as openssl_pkey_get_private "key" parameter (http://php.net/manual/en/function.openssl-pkey-get-private.php). |
* @param string $pass - (Optional) Private key password. Same as openssl_pkey_get_private "passphrase" parameter (http://php.net/manual/en/function.openssl-pkey-get-private.php). |
* @throws JwsException |
*/ |
public function setPrivateKey($key, $pass = "") { |
if ($this->privateKey) { |
openssl_pkey_free($this->privateKey); |
} |
$this->privateKey = openssl_pkey_get_private($key, $pass); |
if (!$this->privateKey) { |
throw new JwsException($this->getOpensslErrors(), 49); |
} |
} |
/** |
* Set public key - overwrites previously set key. |
* @param string $key - Public key. Same as openssl_pkey_get_public "certificate" parameter (http://php.net/manual/en/function.openssl-pkey-get-public.php). |
* @throws JwsException |
*/ |
public function setPublicKey($key) { |
if ($this->publicKey) { |
openssl_pkey_free($this->publicKey); |
} |
$this->publicKey = openssl_pkey_get_public($key); |
if (!$this->publicKey) { |
throw new JwsException($this->getOpensslErrors(), 49); |
} |
} |
/** |
* Create JWS from payload and optional header and sign it. |
* @param string $payload - Payload. |
* @param array $header - (Optional) Header data. |
* @return string - JWS. |
* @throws JwsException |
*/ |
public function sign($payload, $header = []) { |
if ($this->privateKey) { |
$d = $this->prepareSign($this->defaultAlgo, $payload, $header); |
$signature = null; |
$v = openssl_sign($d["h"] . "." . $d["p"], $signature, $this->privateKey, $this->algos[$d["alg"]]); |
if ($v) { |
return $d["h"] . "." . $d["p"] . "." . base64_encode($signature); |
} else { |
throw new JwsException($this->getOpensslErrors(), 49); |
} |
} else { |
throw new JwsException("Private key is not set", 40); |
} |
} |
/** |
* Verify JWS signature. |
* @param string $jws - JWS. |
* @return bool - TRUE on valid signature, FALSE on invalid. |
* @throws JwsException |
*/ |
public function verify($jws) { |
if ($this->publicKey) { |
$d = $this->prepareVerify($jws); |
$v = openssl_verify($d["h"] . "." . $d["p"], $d["sig"], $this->publicKey, $this->algos[$d["alg"]]); |
if ($v == 1) { |
return true; |
} else if ($v == 0) { |
return false; |
} else { |
throw new JwsException($this->getOpensslErrors(), 49); |
} |
} else { |
throw new JwsException("Public key is not set", 41); |
} |
} |
/** |
* Check validity of signature algorithm. |
* @param string $algorithm - Algorithm name. |
* @return bool - TRUE on valid algorithm, FALSE on invalid. |
*/ |
protected function isValidAlgorithm(string $algorithm): bool { |
return array_key_exists(strtoupper($algorithm), $this->algos); |
} |
/** |
* Get openssl error queue. |
* @return string - Openssl error message(s). |
*/ |
protected function getOpensslErrors() { |
$message = "OpenSSL Error(s):"; |
while ($m = openssl_error_string()) { |
$message .= " " . $m; |
} |
return $message; |
} |
} |
/trunk/plugins/viathinksoft/publicPages/100_whois/whois/json/vendor/sergeybrook/php-jws/src/JWS/Symmetric.php |
---|
0,0 → 1,19 |
<?php |
/** |
* SBrook\JWS\Symmetric |
*/ |
namespace SBrook\JWS; |
/** |
* Interface Symmetric |
* @package SBrook\JWS |
*/ |
interface Symmetric { |
/** |
* Set secret key. |
* @param $key - Secret key. |
* @param $pass - Secret key password. |
*/ |
public function setSecretKey($key, $pass); |
} |
/trunk/plugins/viathinksoft/publicPages/100_whois/whois/json/vendor/sergeybrook/php-jws/src/autoload.php |
---|
0,0 → 1,12 |
<?php |
/** |
* Class files autoloader. |
*/ |
spl_autoload_register(function ($className) { |
$search = ["\\", "SBrook"]; |
$replace = [DIRECTORY_SEPARATOR, __DIR__]; |
/** @noinspection PhpIncludeInspection */ |
include(str_replace($search, $replace, $className).".php"); |
}); |