Commit c7e06e5711ce00326af9cfb872666a1b73c0c661

Authored by Edmar Moretti
1 parent 89d166f6

Inclusão de pasta para código PHP baseado no Composer na pasta pacotes. Instalaç…

…ão da biblioteca Defuse/php-encryption via Composer. Implementação de criptografia de arquivo nas funções de download e upload de um mapfile.
Showing 70 changed files with 6935 additions and 8 deletions   Show diff stats
admin/admin.db
No preview for this file type
classesphp/classe_metaestatinfo.php
... ... @@ -422,6 +422,19 @@ class MetaestatInfo{
422 422 );
423 423 }
424 424 /**
  425 + * Retorna o sql de uma string obtida do elemento data de um layer mapserver
  426 + * Remove a referencia a coluna geo
  427 + * @param string obtida de DATA de um LAYER mapserver
  428 + */
  429 + function dataLayer2sql ($data){
  430 + //remove marcadores geo
  431 + $sqlf = explode("/*SE*/",$data);
  432 + $sqlf = explode("/*SG*/",$sqlf[1]);
  433 + $sqlf = $sqlf[0]." ".$sqlf[2];
  434 + $sqlf = str_replace(", FROM"," FROM",$sqlf);
  435 + return $sqlf;
  436 + }
  437 + /**
425 438 * Retorna os ids das regioes que permitem partir de uma regiao filha chegar a uma regiao pai
426 439 * Usado para descobrir que regioes devem ser sequencialmente agregadas
427 440 * @param partir da regiao
... ...
classesphp/metaestat_controle.php
... ... @@ -34,6 +34,10 @@ include (dirname ( __FILE__ ) . "/classe_metaestatinfo.php");
34 34 $retorno = "";
35 35  
36 36 switch (strtoupper ( $funcao )) {
  37 + case "LAYERS2CSV" :
  38 + $layers = explode(",",$_pg["layers"]);
  39 + $map = ms_newMapObj($map_file);
  40 + break;
37 41 case "RELATORIOCOMPLETO" :
38 42 $m = new MetaestatInfo();
39 43 if(empty($_pg ["codigo_variavel"])){
... ...
ferramentas/carregamapa/upload.php
1 1 <?php
  2 +require __DIR__ . '/../../pacotes/composer/vendor/autoload.php';
  3 +use Defuse\Crypto\Key;
  4 +use Defuse\Crypto\File;
  5 +
2 6 include(dirname(__FILE__)."/../safe.php");
3 7 verificaBlFerramentas(basename(dirname(__FILE__)),$i3geoBlFerramentas,false);
4 8 //
... ... @@ -34,15 +38,25 @@ if (isset($_FILES[&#39;i3GEOcarregamapafilemap&#39;][&#39;name&#39;]) &amp;&amp; strlen(basename($_FILES
34 38  
35 39 verificaNome($Arquivo);
36 40  
37   - $checkphp = fileContemString($_FILES['i3GEOcarregamapafilemap']['tmp_name'],"<?");
38   - if($checkphp == true){
39   - exit;
  41 + if(isset($i3geoKeys) && $i3geoKeys["salvaMapfile"] != ""){
  42 + $status = move_uploaded_file($_FILES['i3GEOcarregamapafilemap']['tmp_name'],$dirmap."/".$Arquivo."temp.map");
  43 + $keyAscii = $i3geoKeys["salvaMapfile"];
  44 + $key = Key::loadFromAsciiSafeString($keyAscii);
  45 + $inputFilename = $dirmap."/".$Arquivo."temp.map";
  46 + $outputFilename = $dirmap."/".$Arquivo;
  47 + File::decryptFile($inputFilename, $outputFilename, $key);
40 48 }
41   - $checkphp = fileContemString($_FILES['i3GEOcarregamapafilemap']['tmp_name'],".php");
42   - if($checkphp == true){
43   - exit;
  49 + else {
  50 + $checkphp = fileContemString($_FILES['i3GEOcarregamapafilemap']['tmp_name'],"<?");
  51 + if($checkphp == true){
  52 + exit;
  53 + }
  54 + $checkphp = fileContemString($_FILES['i3GEOcarregamapafilemap']['tmp_name'],".php");
  55 + if($checkphp == true){
  56 + exit;
  57 + }
  58 + $status = move_uploaded_file($_FILES['i3GEOcarregamapafilemap']['tmp_name'],$dirmap."/".$Arquivo);
44 59 }
45   - $status = move_uploaded_file($_FILES['i3GEOcarregamapafilemap']['tmp_name'],$dirmap."/".$Arquivo);
46 60 if($status != 1){
47 61 echo "<p class='paragrafo' >Ocorreu um erro no envio do arquivo";
48 62 paraAguarde();
... ...
ferramentas/salvamapa/forcedownload.php
1 1 <?php
  2 +require __DIR__ . '/../../pacotes/composer/vendor/autoload.php';
  3 +use Defuse\Crypto\Crypto;
  4 +use Defuse\Crypto\Key;
  5 +use Defuse\Crypto\File;
  6 +
2 7 include(dirname(__FILE__)."/../safe.php");
3 8 verificaBlFerramentas(basename(dirname(__FILE__)),$i3geoBlFerramentas,false);
4 9 //
5 10 //o usuario deve ter entrado pelo i3Geo
6 11 //
7 12 if(empty($fingerprint)){
8   - echo "<p class='paragrafo' >Erro ao enviar o arquivo.";
9 13 return;
10 14 }
11 15 //
  16 +//verifica se deve ser utilizado o metodo de criptografia
  17 +//
  18 +include(dirname(__FILE__)."/../../ms_configura.php");
  19 +if(isset($i3geoKeys)){
  20 + if( $i3geoKeys["salvaMapfile"] != "" ){
  21 + $keyAscii = $i3geoKeys["salvaMapfile"];
  22 + $key = Key::loadFromAsciiSafeString($keyAscii);
  23 + /*
  24 + $secret_data = "teste";
  25 + $ciphertext = Crypto::encrypt($secret_data, $key);
  26 + $data = Crypto::decrypt($ciphertext, $key);
  27 + echo $ciphertext;
  28 + echo $data;
  29 + */
  30 + $inputFilename = $map_file;
  31 + $outputFilename = dirname(dirname($map_file))."/mapfile_".nomeRandomico(6).".map";
  32 + File::encryptFile($inputFilename, $outputFilename, $key);
  33 + //File::decryptFile($outputFilename, $outputFilename.".map", $key);
  34 + header("Content-Type:text/plain");
  35 + header('Content-Disposition: attachment; filename="'.basename($outputFilename).'"');
  36 + readfile($outputFilename);
  37 + return;
  38 + }
  39 +}
  40 +//
12 41 //faz uma copia temporaria do mapfile
13 42 //
14 43 $arquivo = dirname(dirname($map_file))."/mapfile_".nomeRandomico(6).".map";
... ...
ms_configura.php
... ... @@ -68,6 +68,30 @@ array(array(&quot;usuario&quot;=&gt;&quot;admin&quot;, &quot;senha&quot;=&gt;&quot;adminx&quot;));
68 68 $i3geomaster = array(
69 69 array("usuario"=>"admin", "senha"=>"admin")
70 70 );
  71 +/*
  72 +Variable: i3geoKeys
  73 +
  74 +Chaves utilizadas para criptografar/descriptografar arquivos ou strings.
  75 +
  76 +As chaves devem ser geradas por meio do aplicativo php-encryption.
  77 +
  78 +Para gerar uma chave veja o tutorial: https://github.com/defuse/php-encryption/blob/master/docs/Tutorial.md#scenario-1-keep-data-secret-from-the-database-administrator
  79 +
  80 +i3geoKeys e um array onde o indice corresponde a funcionalidade onde a criptografia sera utilizada
  81 +
  82 +Para decidir sobre o uso ou nao da criptografia, veja a documentacao: https://github.com/defuse/php-encryption
  83 +
  84 +Funcionalidades:
  85 +
  86 +salvaMapfile - utilizado na opcao de download do arquivo mapfile em uso para posterior upload.
  87 +Se a chave nao existir a opcao de download/upload ira funcionar no modo padrao.
  88 +Nesse caso as informacoes de conexao e fontes de dados (DATA) sao removidas do mapfile e a recuperaco do mapa,
  89 +via upload, ira remover LAYERS que nao forem encontrados na pasta i3geo/temas.
  90 +Quando a chave for especificada, o mapfile nao e alterado ao ser feito o download, mantendo suas caracteristicas originais.
  91 +*/
  92 +$i3geoKeys = array(
  93 + "salvaMapfile"=>"def00000881f5d29aa8604e109797766cd26754c4cc06be02c09163810a78a8a59564bdfd00170d20cdce0e8ac5342db0286d243f78de63b8b26f52d9bc55ee53080bd68"
  94 +);
71 95 //TODO documentar no moodle
72 96 /*
73 97 Variable: $i3geoPermiteLogin
... ...
pacotes/composer/composer.json 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +{
  2 + "require": {
  3 + "defuse/php-encryption": "^2.1"
  4 + }
  5 +}
... ...
pacotes/composer/composer.lock 0 → 100644
... ... @@ -0,0 +1,129 @@
  1 +{
  2 + "_readme": [
  3 + "This file locks the dependencies of your project to a known state",
  4 + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
  5 + "This file is @generated automatically"
  6 + ],
  7 + "content-hash": "953af41a64d66e588e9c5cc2b820778a",
  8 + "packages": [
  9 + {
  10 + "name": "defuse/php-encryption",
  11 + "version": "v2.1.0",
  12 + "source": {
  13 + "type": "git",
  14 + "url": "https://github.com/defuse/php-encryption.git",
  15 + "reference": "5176f5abb38d3ea8a6e3ac6cd3bbb54d8185a689"
  16 + },
  17 + "dist": {
  18 + "type": "zip",
  19 + "url": "https://api.github.com/repos/defuse/php-encryption/zipball/5176f5abb38d3ea8a6e3ac6cd3bbb54d8185a689",
  20 + "reference": "5176f5abb38d3ea8a6e3ac6cd3bbb54d8185a689",
  21 + "shasum": ""
  22 + },
  23 + "require": {
  24 + "ext-openssl": "*",
  25 + "paragonie/random_compat": "~2.0",
  26 + "php": ">=5.4.0"
  27 + },
  28 + "require-dev": {
  29 + "nikic/php-parser": "^2.0|^3.0",
  30 + "phpunit/phpunit": "^4|^5"
  31 + },
  32 + "bin": [
  33 + "bin/generate-defuse-key"
  34 + ],
  35 + "type": "library",
  36 + "autoload": {
  37 + "psr-4": {
  38 + "Defuse\\Crypto\\": "src"
  39 + }
  40 + },
  41 + "notification-url": "https://packagist.org/downloads/",
  42 + "license": [
  43 + "MIT"
  44 + ],
  45 + "authors": [
  46 + {
  47 + "name": "Taylor Hornby",
  48 + "email": "taylor@defuse.ca",
  49 + "homepage": "https://defuse.ca/"
  50 + },
  51 + {
  52 + "name": "Scott Arciszewski",
  53 + "email": "info@paragonie.com",
  54 + "homepage": "https://paragonie.com"
  55 + }
  56 + ],
  57 + "description": "Secure PHP Encryption Library",
  58 + "keywords": [
  59 + "aes",
  60 + "authenticated encryption",
  61 + "cipher",
  62 + "crypto",
  63 + "cryptography",
  64 + "encrypt",
  65 + "encryption",
  66 + "openssl",
  67 + "security",
  68 + "symmetric key cryptography"
  69 + ],
  70 + "time": "2017-05-18T21:28:48+00:00"
  71 + },
  72 + {
  73 + "name": "paragonie/random_compat",
  74 + "version": "v2.0.10",
  75 + "source": {
  76 + "type": "git",
  77 + "url": "https://github.com/paragonie/random_compat.git",
  78 + "reference": "634bae8e911eefa89c1abfbf1b66da679ac8f54d"
  79 + },
  80 + "dist": {
  81 + "type": "zip",
  82 + "url": "https://api.github.com/repos/paragonie/random_compat/zipball/634bae8e911eefa89c1abfbf1b66da679ac8f54d",
  83 + "reference": "634bae8e911eefa89c1abfbf1b66da679ac8f54d",
  84 + "shasum": ""
  85 + },
  86 + "require": {
  87 + "php": ">=5.2.0"
  88 + },
  89 + "require-dev": {
  90 + "phpunit/phpunit": "4.*|5.*"
  91 + },
  92 + "suggest": {
  93 + "ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes."
  94 + },
  95 + "type": "library",
  96 + "autoload": {
  97 + "files": [
  98 + "lib/random.php"
  99 + ]
  100 + },
  101 + "notification-url": "https://packagist.org/downloads/",
  102 + "license": [
  103 + "MIT"
  104 + ],
  105 + "authors": [
  106 + {
  107 + "name": "Paragon Initiative Enterprises",
  108 + "email": "security@paragonie.com",
  109 + "homepage": "https://paragonie.com"
  110 + }
  111 + ],
  112 + "description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7",
  113 + "keywords": [
  114 + "csprng",
  115 + "pseudorandom",
  116 + "random"
  117 + ],
  118 + "time": "2017-03-13T16:27:32+00:00"
  119 + }
  120 + ],
  121 + "packages-dev": [],
  122 + "aliases": [],
  123 + "minimum-stability": "stable",
  124 + "stability-flags": [],
  125 + "prefer-stable": false,
  126 + "prefer-lowest": false,
  127 + "platform": [],
  128 + "platform-dev": []
  129 +}
... ...
pacotes/composer/vendor/autoload.php 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +<?php
  2 +
  3 +// autoload.php @generated by Composer
  4 +
  5 +require_once __DIR__ . '/composer/autoload_real.php';
  6 +
  7 +return ComposerAutoloaderInitece12a4b6932decff48d185ec5733960::getLoader();
... ...
pacotes/composer/vendor/bin/generate-defuse-key 0 → 120000
... ... @@ -0,0 +1 @@
  1 +../defuse/php-encryption/bin/generate-defuse-key
0 2 \ No newline at end of file
... ...
pacotes/composer/vendor/composer/ClassLoader.php 0 → 100644
... ... @@ -0,0 +1,445 @@
  1 +<?php
  2 +
  3 +/*
  4 + * This file is part of Composer.
  5 + *
  6 + * (c) Nils Adermann <naderman@naderman.de>
  7 + * Jordi Boggiano <j.boggiano@seld.be>
  8 + *
  9 + * For the full copyright and license information, please view the LICENSE
  10 + * file that was distributed with this source code.
  11 + */
  12 +
  13 +namespace Composer\Autoload;
  14 +
  15 +/**
  16 + * ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
  17 + *
  18 + * $loader = new \Composer\Autoload\ClassLoader();
  19 + *
  20 + * // register classes with namespaces
  21 + * $loader->add('Symfony\Component', __DIR__.'/component');
  22 + * $loader->add('Symfony', __DIR__.'/framework');
  23 + *
  24 + * // activate the autoloader
  25 + * $loader->register();
  26 + *
  27 + * // to enable searching the include path (eg. for PEAR packages)
  28 + * $loader->setUseIncludePath(true);
  29 + *
  30 + * In this example, if you try to use a class in the Symfony\Component
  31 + * namespace or one of its children (Symfony\Component\Console for instance),
  32 + * the autoloader will first look for the class under the component/
  33 + * directory, and it will then fallback to the framework/ directory if not
  34 + * found before giving up.
  35 + *
  36 + * This class is loosely based on the Symfony UniversalClassLoader.
  37 + *
  38 + * @author Fabien Potencier <fabien@symfony.com>
  39 + * @author Jordi Boggiano <j.boggiano@seld.be>
  40 + * @see http://www.php-fig.org/psr/psr-0/
  41 + * @see http://www.php-fig.org/psr/psr-4/
  42 + */
  43 +class ClassLoader
  44 +{
  45 + // PSR-4
  46 + private $prefixLengthsPsr4 = array();
  47 + private $prefixDirsPsr4 = array();
  48 + private $fallbackDirsPsr4 = array();
  49 +
  50 + // PSR-0
  51 + private $prefixesPsr0 = array();
  52 + private $fallbackDirsPsr0 = array();
  53 +
  54 + private $useIncludePath = false;
  55 + private $classMap = array();
  56 + private $classMapAuthoritative = false;
  57 + private $missingClasses = array();
  58 + private $apcuPrefix;
  59 +
  60 + public function getPrefixes()
  61 + {
  62 + if (!empty($this->prefixesPsr0)) {
  63 + return call_user_func_array('array_merge', $this->prefixesPsr0);
  64 + }
  65 +
  66 + return array();
  67 + }
  68 +
  69 + public function getPrefixesPsr4()
  70 + {
  71 + return $this->prefixDirsPsr4;
  72 + }
  73 +
  74 + public function getFallbackDirs()
  75 + {
  76 + return $this->fallbackDirsPsr0;
  77 + }
  78 +
  79 + public function getFallbackDirsPsr4()
  80 + {
  81 + return $this->fallbackDirsPsr4;
  82 + }
  83 +
  84 + public function getClassMap()
  85 + {
  86 + return $this->classMap;
  87 + }
  88 +
  89 + /**
  90 + * @param array $classMap Class to filename map
  91 + */
  92 + public function addClassMap(array $classMap)
  93 + {
  94 + if ($this->classMap) {
  95 + $this->classMap = array_merge($this->classMap, $classMap);
  96 + } else {
  97 + $this->classMap = $classMap;
  98 + }
  99 + }
  100 +
  101 + /**
  102 + * Registers a set of PSR-0 directories for a given prefix, either
  103 + * appending or prepending to the ones previously set for this prefix.
  104 + *
  105 + * @param string $prefix The prefix
  106 + * @param array|string $paths The PSR-0 root directories
  107 + * @param bool $prepend Whether to prepend the directories
  108 + */
  109 + public function add($prefix, $paths, $prepend = false)
  110 + {
  111 + if (!$prefix) {
  112 + if ($prepend) {
  113 + $this->fallbackDirsPsr0 = array_merge(
  114 + (array) $paths,
  115 + $this->fallbackDirsPsr0
  116 + );
  117 + } else {
  118 + $this->fallbackDirsPsr0 = array_merge(
  119 + $this->fallbackDirsPsr0,
  120 + (array) $paths
  121 + );
  122 + }
  123 +
  124 + return;
  125 + }
  126 +
  127 + $first = $prefix[0];
  128 + if (!isset($this->prefixesPsr0[$first][$prefix])) {
  129 + $this->prefixesPsr0[$first][$prefix] = (array) $paths;
  130 +
  131 + return;
  132 + }
  133 + if ($prepend) {
  134 + $this->prefixesPsr0[$first][$prefix] = array_merge(
  135 + (array) $paths,
  136 + $this->prefixesPsr0[$first][$prefix]
  137 + );
  138 + } else {
  139 + $this->prefixesPsr0[$first][$prefix] = array_merge(
  140 + $this->prefixesPsr0[$first][$prefix],
  141 + (array) $paths
  142 + );
  143 + }
  144 + }
  145 +
  146 + /**
  147 + * Registers a set of PSR-4 directories for a given namespace, either
  148 + * appending or prepending to the ones previously set for this namespace.
  149 + *
  150 + * @param string $prefix The prefix/namespace, with trailing '\\'
  151 + * @param array|string $paths The PSR-4 base directories
  152 + * @param bool $prepend Whether to prepend the directories
  153 + *
  154 + * @throws \InvalidArgumentException
  155 + */
  156 + public function addPsr4($prefix, $paths, $prepend = false)
  157 + {
  158 + if (!$prefix) {
  159 + // Register directories for the root namespace.
  160 + if ($prepend) {
  161 + $this->fallbackDirsPsr4 = array_merge(
  162 + (array) $paths,
  163 + $this->fallbackDirsPsr4
  164 + );
  165 + } else {
  166 + $this->fallbackDirsPsr4 = array_merge(
  167 + $this->fallbackDirsPsr4,
  168 + (array) $paths
  169 + );
  170 + }
  171 + } elseif (!isset($this->prefixDirsPsr4[$prefix])) {
  172 + // Register directories for a new namespace.
  173 + $length = strlen($prefix);
  174 + if ('\\' !== $prefix[$length - 1]) {
  175 + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
  176 + }
  177 + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
  178 + $this->prefixDirsPsr4[$prefix] = (array) $paths;
  179 + } elseif ($prepend) {
  180 + // Prepend directories for an already registered namespace.
  181 + $this->prefixDirsPsr4[$prefix] = array_merge(
  182 + (array) $paths,
  183 + $this->prefixDirsPsr4[$prefix]
  184 + );
  185 + } else {
  186 + // Append directories for an already registered namespace.
  187 + $this->prefixDirsPsr4[$prefix] = array_merge(
  188 + $this->prefixDirsPsr4[$prefix],
  189 + (array) $paths
  190 + );
  191 + }
  192 + }
  193 +
  194 + /**
  195 + * Registers a set of PSR-0 directories for a given prefix,
  196 + * replacing any others previously set for this prefix.
  197 + *
  198 + * @param string $prefix The prefix
  199 + * @param array|string $paths The PSR-0 base directories
  200 + */
  201 + public function set($prefix, $paths)
  202 + {
  203 + if (!$prefix) {
  204 + $this->fallbackDirsPsr0 = (array) $paths;
  205 + } else {
  206 + $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
  207 + }
  208 + }
  209 +
  210 + /**
  211 + * Registers a set of PSR-4 directories for a given namespace,
  212 + * replacing any others previously set for this namespace.
  213 + *
  214 + * @param string $prefix The prefix/namespace, with trailing '\\'
  215 + * @param array|string $paths The PSR-4 base directories
  216 + *
  217 + * @throws \InvalidArgumentException
  218 + */
  219 + public function setPsr4($prefix, $paths)
  220 + {
  221 + if (!$prefix) {
  222 + $this->fallbackDirsPsr4 = (array) $paths;
  223 + } else {
  224 + $length = strlen($prefix);
  225 + if ('\\' !== $prefix[$length - 1]) {
  226 + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
  227 + }
  228 + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
  229 + $this->prefixDirsPsr4[$prefix] = (array) $paths;
  230 + }
  231 + }
  232 +
  233 + /**
  234 + * Turns on searching the include path for class files.
  235 + *
  236 + * @param bool $useIncludePath
  237 + */
  238 + public function setUseIncludePath($useIncludePath)
  239 + {
  240 + $this->useIncludePath = $useIncludePath;
  241 + }
  242 +
  243 + /**
  244 + * Can be used to check if the autoloader uses the include path to check
  245 + * for classes.
  246 + *
  247 + * @return bool
  248 + */
  249 + public function getUseIncludePath()
  250 + {
  251 + return $this->useIncludePath;
  252 + }
  253 +
  254 + /**
  255 + * Turns off searching the prefix and fallback directories for classes
  256 + * that have not been registered with the class map.
  257 + *
  258 + * @param bool $classMapAuthoritative
  259 + */
  260 + public function setClassMapAuthoritative($classMapAuthoritative)
  261 + {
  262 + $this->classMapAuthoritative = $classMapAuthoritative;
  263 + }
  264 +
  265 + /**
  266 + * Should class lookup fail if not found in the current class map?
  267 + *
  268 + * @return bool
  269 + */
  270 + public function isClassMapAuthoritative()
  271 + {
  272 + return $this->classMapAuthoritative;
  273 + }
  274 +
  275 + /**
  276 + * APCu prefix to use to cache found/not-found classes, if the extension is enabled.
  277 + *
  278 + * @param string|null $apcuPrefix
  279 + */
  280 + public function setApcuPrefix($apcuPrefix)
  281 + {
  282 + $this->apcuPrefix = function_exists('apcu_fetch') && ini_get('apc.enabled') ? $apcuPrefix : null;
  283 + }
  284 +
  285 + /**
  286 + * The APCu prefix in use, or null if APCu caching is not enabled.
  287 + *
  288 + * @return string|null
  289 + */
  290 + public function getApcuPrefix()
  291 + {
  292 + return $this->apcuPrefix;
  293 + }
  294 +
  295 + /**
  296 + * Registers this instance as an autoloader.
  297 + *
  298 + * @param bool $prepend Whether to prepend the autoloader or not
  299 + */
  300 + public function register($prepend = false)
  301 + {
  302 + spl_autoload_register(array($this, 'loadClass'), true, $prepend);
  303 + }
  304 +
  305 + /**
  306 + * Unregisters this instance as an autoloader.
  307 + */
  308 + public function unregister()
  309 + {
  310 + spl_autoload_unregister(array($this, 'loadClass'));
  311 + }
  312 +
  313 + /**
  314 + * Loads the given class or interface.
  315 + *
  316 + * @param string $class The name of the class
  317 + * @return bool|null True if loaded, null otherwise
  318 + */
  319 + public function loadClass($class)
  320 + {
  321 + if ($file = $this->findFile($class)) {
  322 + includeFile($file);
  323 +
  324 + return true;
  325 + }
  326 + }
  327 +
  328 + /**
  329 + * Finds the path to the file where the class is defined.
  330 + *
  331 + * @param string $class The name of the class
  332 + *
  333 + * @return string|false The path if found, false otherwise
  334 + */
  335 + public function findFile($class)
  336 + {
  337 + // class map lookup
  338 + if (isset($this->classMap[$class])) {
  339 + return $this->classMap[$class];
  340 + }
  341 + if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
  342 + return false;
  343 + }
  344 + if (null !== $this->apcuPrefix) {
  345 + $file = apcu_fetch($this->apcuPrefix.$class, $hit);
  346 + if ($hit) {
  347 + return $file;
  348 + }
  349 + }
  350 +
  351 + $file = $this->findFileWithExtension($class, '.php');
  352 +
  353 + // Search for Hack files if we are running on HHVM
  354 + if (false === $file && defined('HHVM_VERSION')) {
  355 + $file = $this->findFileWithExtension($class, '.hh');
  356 + }
  357 +
  358 + if (null !== $this->apcuPrefix) {
  359 + apcu_add($this->apcuPrefix.$class, $file);
  360 + }
  361 +
  362 + if (false === $file) {
  363 + // Remember that this class does not exist.
  364 + $this->missingClasses[$class] = true;
  365 + }
  366 +
  367 + return $file;
  368 + }
  369 +
  370 + private function findFileWithExtension($class, $ext)
  371 + {
  372 + // PSR-4 lookup
  373 + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
  374 +
  375 + $first = $class[0];
  376 + if (isset($this->prefixLengthsPsr4[$first])) {
  377 + $subPath = $class;
  378 + while (false !== $lastPos = strrpos($subPath, '\\')) {
  379 + $subPath = substr($subPath, 0, $lastPos);
  380 + $search = $subPath.'\\';
  381 + if (isset($this->prefixDirsPsr4[$search])) {
  382 + foreach ($this->prefixDirsPsr4[$search] as $dir) {
  383 + $length = $this->prefixLengthsPsr4[$first][$search];
  384 + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
  385 + return $file;
  386 + }
  387 + }
  388 + }
  389 + }
  390 + }
  391 +
  392 + // PSR-4 fallback dirs
  393 + foreach ($this->fallbackDirsPsr4 as $dir) {
  394 + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
  395 + return $file;
  396 + }
  397 + }
  398 +
  399 + // PSR-0 lookup
  400 + if (false !== $pos = strrpos($class, '\\')) {
  401 + // namespaced class name
  402 + $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
  403 + . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
  404 + } else {
  405 + // PEAR-like class name
  406 + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
  407 + }
  408 +
  409 + if (isset($this->prefixesPsr0[$first])) {
  410 + foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
  411 + if (0 === strpos($class, $prefix)) {
  412 + foreach ($dirs as $dir) {
  413 + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
  414 + return $file;
  415 + }
  416 + }
  417 + }
  418 + }
  419 + }
  420 +
  421 + // PSR-0 fallback dirs
  422 + foreach ($this->fallbackDirsPsr0 as $dir) {
  423 + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
  424 + return $file;
  425 + }
  426 + }
  427 +
  428 + // PSR-0 include paths.
  429 + if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
  430 + return $file;
  431 + }
  432 +
  433 + return false;
  434 + }
  435 +}
  436 +
  437 +/**
  438 + * Scope isolated include.
  439 + *
  440 + * Prevents access to $this/self from included files.
  441 + */
  442 +function includeFile($file)
  443 +{
  444 + include $file;
  445 +}
... ...
pacotes/composer/vendor/composer/LICENSE 0 → 100644
... ... @@ -0,0 +1,21 @@
  1 +
  2 +Copyright (c) Nils Adermann, Jordi Boggiano
  3 +
  4 +Permission is hereby granted, free of charge, to any person obtaining a copy
  5 +of this software and associated documentation files (the "Software"), to deal
  6 +in the Software without restriction, including without limitation the rights
  7 +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8 +copies of the Software, and to permit persons to whom the Software is furnished
  9 +to do so, subject to the following conditions:
  10 +
  11 +The above copyright notice and this permission notice shall be included in all
  12 +copies or substantial portions of the Software.
  13 +
  14 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16 +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17 +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18 +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19 +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20 +THE SOFTWARE.
  21 +
... ...
pacotes/composer/vendor/composer/autoload_classmap.php 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +<?php
  2 +
  3 +// autoload_classmap.php @generated by Composer
  4 +
  5 +$vendorDir = dirname(dirname(__FILE__));
  6 +$baseDir = dirname($vendorDir);
  7 +
  8 +return array(
  9 +);
... ...
pacotes/composer/vendor/composer/autoload_files.php 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +<?php
  2 +
  3 +// autoload_files.php @generated by Composer
  4 +
  5 +$vendorDir = dirname(dirname(__FILE__));
  6 +$baseDir = dirname($vendorDir);
  7 +
  8 +return array(
  9 + '5255c38a0faeba867671b61dfda6d864' => $vendorDir . '/paragonie/random_compat/lib/random.php',
  10 +);
... ...
pacotes/composer/vendor/composer/autoload_namespaces.php 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +<?php
  2 +
  3 +// autoload_namespaces.php @generated by Composer
  4 +
  5 +$vendorDir = dirname(dirname(__FILE__));
  6 +$baseDir = dirname($vendorDir);
  7 +
  8 +return array(
  9 +);
... ...
pacotes/composer/vendor/composer/autoload_psr4.php 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +<?php
  2 +
  3 +// autoload_psr4.php @generated by Composer
  4 +
  5 +$vendorDir = dirname(dirname(__FILE__));
  6 +$baseDir = dirname($vendorDir);
  7 +
  8 +return array(
  9 + 'Defuse\\Crypto\\' => array($vendorDir . '/defuse/php-encryption/src'),
  10 +);
... ...
pacotes/composer/vendor/composer/autoload_real.php 0 → 100644
... ... @@ -0,0 +1,70 @@
  1 +<?php
  2 +
  3 +// autoload_real.php @generated by Composer
  4 +
  5 +class ComposerAutoloaderInitece12a4b6932decff48d185ec5733960
  6 +{
  7 + private static $loader;
  8 +
  9 + public static function loadClassLoader($class)
  10 + {
  11 + if ('Composer\Autoload\ClassLoader' === $class) {
  12 + require __DIR__ . '/ClassLoader.php';
  13 + }
  14 + }
  15 +
  16 + public static function getLoader()
  17 + {
  18 + if (null !== self::$loader) {
  19 + return self::$loader;
  20 + }
  21 +
  22 + spl_autoload_register(array('ComposerAutoloaderInitece12a4b6932decff48d185ec5733960', 'loadClassLoader'), true, true);
  23 + self::$loader = $loader = new \Composer\Autoload\ClassLoader();
  24 + spl_autoload_unregister(array('ComposerAutoloaderInitece12a4b6932decff48d185ec5733960', 'loadClassLoader'));
  25 +
  26 + $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
  27 + if ($useStaticLoader) {
  28 + require_once __DIR__ . '/autoload_static.php';
  29 +
  30 + call_user_func(\Composer\Autoload\ComposerStaticInitece12a4b6932decff48d185ec5733960::getInitializer($loader));
  31 + } else {
  32 + $map = require __DIR__ . '/autoload_namespaces.php';
  33 + foreach ($map as $namespace => $path) {
  34 + $loader->set($namespace, $path);
  35 + }
  36 +
  37 + $map = require __DIR__ . '/autoload_psr4.php';
  38 + foreach ($map as $namespace => $path) {
  39 + $loader->setPsr4($namespace, $path);
  40 + }
  41 +
  42 + $classMap = require __DIR__ . '/autoload_classmap.php';
  43 + if ($classMap) {
  44 + $loader->addClassMap($classMap);
  45 + }
  46 + }
  47 +
  48 + $loader->register(true);
  49 +
  50 + if ($useStaticLoader) {
  51 + $includeFiles = Composer\Autoload\ComposerStaticInitece12a4b6932decff48d185ec5733960::$files;
  52 + } else {
  53 + $includeFiles = require __DIR__ . '/autoload_files.php';
  54 + }
  55 + foreach ($includeFiles as $fileIdentifier => $file) {
  56 + composerRequireece12a4b6932decff48d185ec5733960($fileIdentifier, $file);
  57 + }
  58 +
  59 + return $loader;
  60 + }
  61 +}
  62 +
  63 +function composerRequireece12a4b6932decff48d185ec5733960($fileIdentifier, $file)
  64 +{
  65 + if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
  66 + require $file;
  67 +
  68 + $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
  69 + }
  70 +}
... ...
pacotes/composer/vendor/composer/autoload_static.php 0 → 100644
... ... @@ -0,0 +1,35 @@
  1 +<?php
  2 +
  3 +// autoload_static.php @generated by Composer
  4 +
  5 +namespace Composer\Autoload;
  6 +
  7 +class ComposerStaticInitece12a4b6932decff48d185ec5733960
  8 +{
  9 + public static $files = array (
  10 + '5255c38a0faeba867671b61dfda6d864' => __DIR__ . '/..' . '/paragonie/random_compat/lib/random.php',
  11 + );
  12 +
  13 + public static $prefixLengthsPsr4 = array (
  14 + 'D' =>
  15 + array (
  16 + 'Defuse\\Crypto\\' => 14,
  17 + ),
  18 + );
  19 +
  20 + public static $prefixDirsPsr4 = array (
  21 + 'Defuse\\Crypto\\' =>
  22 + array (
  23 + 0 => __DIR__ . '/..' . '/defuse/php-encryption/src',
  24 + ),
  25 + );
  26 +
  27 + public static function getInitializer(ClassLoader $loader)
  28 + {
  29 + return \Closure::bind(function () use ($loader) {
  30 + $loader->prefixLengthsPsr4 = ComposerStaticInitece12a4b6932decff48d185ec5733960::$prefixLengthsPsr4;
  31 + $loader->prefixDirsPsr4 = ComposerStaticInitece12a4b6932decff48d185ec5733960::$prefixDirsPsr4;
  32 +
  33 + }, null, ClassLoader::class);
  34 + }
  35 +}
... ...
pacotes/composer/vendor/composer/installed.json 0 → 100644
... ... @@ -0,0 +1,117 @@
  1 +[
  2 + {
  3 + "name": "paragonie/random_compat",
  4 + "version": "v2.0.10",
  5 + "version_normalized": "2.0.10.0",
  6 + "source": {
  7 + "type": "git",
  8 + "url": "https://github.com/paragonie/random_compat.git",
  9 + "reference": "634bae8e911eefa89c1abfbf1b66da679ac8f54d"
  10 + },
  11 + "dist": {
  12 + "type": "zip",
  13 + "url": "https://api.github.com/repos/paragonie/random_compat/zipball/634bae8e911eefa89c1abfbf1b66da679ac8f54d",
  14 + "reference": "634bae8e911eefa89c1abfbf1b66da679ac8f54d",
  15 + "shasum": ""
  16 + },
  17 + "require": {
  18 + "php": ">=5.2.0"
  19 + },
  20 + "require-dev": {
  21 + "phpunit/phpunit": "4.*|5.*"
  22 + },
  23 + "suggest": {
  24 + "ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes."
  25 + },
  26 + "time": "2017-03-13T16:27:32+00:00",
  27 + "type": "library",
  28 + "installation-source": "dist",
  29 + "autoload": {
  30 + "files": [
  31 + "lib/random.php"
  32 + ]
  33 + },
  34 + "notification-url": "https://packagist.org/downloads/",
  35 + "license": [
  36 + "MIT"
  37 + ],
  38 + "authors": [
  39 + {
  40 + "name": "Paragon Initiative Enterprises",
  41 + "email": "security@paragonie.com",
  42 + "homepage": "https://paragonie.com"
  43 + }
  44 + ],
  45 + "description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7",
  46 + "keywords": [
  47 + "csprng",
  48 + "pseudorandom",
  49 + "random"
  50 + ]
  51 + },
  52 + {
  53 + "name": "defuse/php-encryption",
  54 + "version": "v2.1.0",
  55 + "version_normalized": "2.1.0.0",
  56 + "source": {
  57 + "type": "git",
  58 + "url": "https://github.com/defuse/php-encryption.git",
  59 + "reference": "5176f5abb38d3ea8a6e3ac6cd3bbb54d8185a689"
  60 + },
  61 + "dist": {
  62 + "type": "zip",
  63 + "url": "https://api.github.com/repos/defuse/php-encryption/zipball/5176f5abb38d3ea8a6e3ac6cd3bbb54d8185a689",
  64 + "reference": "5176f5abb38d3ea8a6e3ac6cd3bbb54d8185a689",
  65 + "shasum": ""
  66 + },
  67 + "require": {
  68 + "ext-openssl": "*",
  69 + "paragonie/random_compat": "~2.0",
  70 + "php": ">=5.4.0"
  71 + },
  72 + "require-dev": {
  73 + "nikic/php-parser": "^2.0|^3.0",
  74 + "phpunit/phpunit": "^4|^5"
  75 + },
  76 + "time": "2017-05-18T21:28:48+00:00",
  77 + "bin": [
  78 + "bin/generate-defuse-key"
  79 + ],
  80 + "type": "library",
  81 + "installation-source": "dist",
  82 + "autoload": {
  83 + "psr-4": {
  84 + "Defuse\\Crypto\\": "src"
  85 + }
  86 + },
  87 + "notification-url": "https://packagist.org/downloads/",
  88 + "license": [
  89 + "MIT"
  90 + ],
  91 + "authors": [
  92 + {
  93 + "name": "Taylor Hornby",
  94 + "email": "taylor@defuse.ca",
  95 + "homepage": "https://defuse.ca/"
  96 + },
  97 + {
  98 + "name": "Scott Arciszewski",
  99 + "email": "info@paragonie.com",
  100 + "homepage": "https://paragonie.com"
  101 + }
  102 + ],
  103 + "description": "Secure PHP Encryption Library",
  104 + "keywords": [
  105 + "aes",
  106 + "authenticated encryption",
  107 + "cipher",
  108 + "crypto",
  109 + "cryptography",
  110 + "encrypt",
  111 + "encryption",
  112 + "openssl",
  113 + "security",
  114 + "symmetric key cryptography"
  115 + ]
  116 + }
  117 +]
... ...
pacotes/composer/vendor/defuse/php-encryption/.gitignore 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +*~
  2 +/test/unit/File/big-generated-file
  3 +/composer.lock
  4 +/vendor
  5 +defuse-crypto.phar
  6 +defuse-crypto.phar.sig
  7 +composer.phar
  8 +box.phar
  9 +phpunit.phar
  10 +phpunit.phar.asc
  11 +test/unit/File/tmp
... ...
pacotes/composer/vendor/defuse/php-encryption/.php_cs 0 → 100644
... ... @@ -0,0 +1,60 @@
  1 +<?php
  2 +
  3 +$config = Symfony\CS\Config\Config::create()
  4 + ->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
  5 + ->fixers([
  6 + 'blankline_after_open_tag',
  7 + 'empty_return',
  8 + 'extra_empty_lines',
  9 + 'function_typehint_space',
  10 + 'join_function',
  11 + 'method_argument_default_value',
  12 + 'multiline_array_trailing_comma',
  13 + 'no_blank_lines_after_class_opening',
  14 + 'no_empty_lines_after_phpdocs',
  15 + 'phpdoc_indent',
  16 + 'phpdoc_no_access',
  17 + 'phpdoc_no_empty_return',
  18 + 'phpdoc_no_package',
  19 + 'phpdoc_params',
  20 + 'phpdoc_scalar',
  21 + 'phpdoc_separation',
  22 + 'phpdoc_trim',
  23 + 'phpdoc_type_to_var',
  24 + 'phpdoc_types',
  25 + 'phpdoc_var_without_name',
  26 + 'remove_leading_slash_use',
  27 + 'remove_lines_between_uses',
  28 + 'short_bool_cast',
  29 + 'single_quote',
  30 + 'spaces_after_semicolon',
  31 + 'spaces_before_semicolon',
  32 + 'spaces_cast',
  33 + 'standardize_not_equal',
  34 + 'ternary_spaces',
  35 + 'trim_array_spaces',
  36 + 'unneeded_control_parentheses',
  37 + 'unused_use',
  38 + 'whitespacy_lines',
  39 + 'align_double_arrow',
  40 + 'concat_with_spaces',
  41 + 'logical_not_operators_with_successor_space',
  42 + 'multiline_spaces_before_semicolon',
  43 + 'newline_after_open_tag',
  44 + 'ordered_use',
  45 + 'php_unit_construct',
  46 + 'phpdoc_order',
  47 + 'short_array_syntax',
  48 + ]);
  49 +
  50 +if (null === $input->getArgument('path')) {
  51 + $config
  52 + ->finder(
  53 + Symfony\CS\Finder\DefaultFinder::create()
  54 + ->in('src')
  55 + ->in('test')
  56 + ->exclude('vendor')
  57 + );
  58 +}
  59 +
  60 +return $config;
... ...
pacotes/composer/vendor/defuse/php-encryption/LICENSE 0 → 100644
... ... @@ -0,0 +1,21 @@
  1 +The MIT License (MIT)
  2 +
  3 +Copyright (c) 2016 Taylor Hornby <https://defuse.ca> and Paragon Initiative
  4 +Enterprises <https://paragonie.com>.
  5 +
  6 +Permission is hereby granted, free of charge, to any person obtaining a copy of
  7 +this software and associated documentation files (the "Software"), to deal in
  8 +the Software without restriction, including without limitation the rights to
  9 +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10 +the Software, and to permit persons to whom the Software is furnished to do so,
  11 +subject to the following conditions:
  12 +
  13 +The above copyright notice and this permission notice shall be included in all
  14 +copies or substantial portions of the Software.
  15 +
  16 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18 +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19 +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20 +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21 +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
... ...
pacotes/composer/vendor/defuse/php-encryption/README.md 0 → 100644
... ... @@ -0,0 +1,88 @@
  1 +php-encryption
  2 +===============
  3 +
  4 +[![Build Status](https://travis-ci.org/defuse/php-encryption.svg?branch=master)](https://travis-ci.org/defuse/php-encryption)
  5 +
  6 +This is a library for encrypting data with a key or password in PHP. **It
  7 +requires PHP 5.4 or newer.** The current version is v2.0.0, which is expected to
  8 +remain stable and supported by its authors with security and bugfixes until at
  9 +least January 1st, 2019.
  10 +
  11 +The library is a joint effort between [Taylor Hornby](https://defuse.ca/) and
  12 +[Scott Arciszewski](https://paragonie.com/blog/author/scott-arcizewski) as well
  13 +as numerous open-source contributors.
  14 +
  15 +What separates this library from other PHP encryption libraries is, firstly,
  16 +that it is secure. The authors used to encounter insecure PHP encryption code on
  17 +a daily basis, so they created this library to bring more security to the
  18 +ecosystem. Secondly, this library is "difficult to misuse." Like
  19 +[libsodium](https://github.com/jedisct1/libsodium), its API is designed to be
  20 +easy to use in a secure way and hard to use in an insecure way.
  21 +
  22 +Dependencies
  23 +------------
  24 +
  25 +This library requres no special dependencies except for PHP 5.4 or newer with
  26 +the OpenSSL extensions enabled (this is the default). It uses
  27 +[random\_compat](https://github.com/paragonie/random_compat), which is bundled
  28 +in with this library so that your users will not need to follow any special
  29 +installation steps.
  30 +
  31 +Getting Started
  32 +----------------
  33 +
  34 +Start with the [**Tutorial**](docs/Tutorial.md). You can find instructions for
  35 +obtaining this library's code securely in the [Installing and
  36 +Verifying](docs/InstallingAndVerifying.md) documentation.
  37 +
  38 +After you've read the tutorial and got the code, refer to the formal
  39 +documentation for each of the classes this library provides:
  40 +
  41 +- [Crypto](docs/classes/Crypto.md)
  42 +- [File](docs/classes/File.md)
  43 +- [Key](docs/classes/Key.md)
  44 +- [KeyProtectedByPassword](docs/classes/KeyProtectedByPassword.md)
  45 +
  46 +If you encounter difficulties, see the [FAQ](docs/FAQ.md) answers. The fixes to
  47 +the most commonly-reported problems are explained there.
  48 +
  49 +If you're a cryptographer and want to understand the nitty-gritty details of how
  50 +this library works, look at the [Cryptography Details](docs/CryptoDetails.md)
  51 +documentation.
  52 +
  53 +If you're interested in contributing to this library, see the [Internal
  54 +Developer Documentation](docs/InternalDeveloperDocs.md).
  55 +
  56 +Examples
  57 +---------
  58 +
  59 +If the documentation is not enough for you to understand how to use this
  60 +library, then you can look at an example project that uses this library:
  61 +
  62 +- [encutil](https://github.com/defuse/encutil)
  63 +- [fileencrypt](https://github.com/tsusanka/fileencrypt)
  64 +
  65 +Security Audit Status
  66 +---------------------
  67 +
  68 +This code has not been subjected to a formal, paid, security audit. However, it
  69 +has received lots of review from members of the PHP security community, and the
  70 +authors are experienced with cryptography. In all likelihood, you are safer
  71 +using this library than almost any other encryption library for PHP.
  72 +
  73 +If you use this library as a part of your business and would like to help fund
  74 +a formal audit, please [contact Taylor Hornby](https://defuse.ca/contact.htm).
  75 +
  76 +Public Keys
  77 +------------
  78 +
  79 +The GnuPG public key used to sign releases is available in
  80 +[dist/signingkey.asc](https://github.com/defuse/php-encryption/raw/master/dist/signingkey.asc). Its fingerprint is:
  81 +
  82 +```
  83 +2FA6 1D8D 99B9 2658 6BAC 3D53 385E E055 A129 1538
  84 +```
  85 +
  86 +You can verify it against the Taylor Hornby's [contact
  87 +page](https://defuse.ca/contact.htm) and
  88 +[twitter](https://twitter.com/DefuseSec/status/723741424253059074).
... ...
pacotes/composer/vendor/defuse/php-encryption/composer.json 0 → 100644
... ... @@ -0,0 +1,35 @@
  1 +{
  2 + "name": "defuse/php-encryption",
  3 + "description": "Secure PHP Encryption Library",
  4 + "license": "MIT",
  5 + "keywords": ["security", "encryption", "AES", "openssl", "cipher", "cryptography", "symmetric key cryptography", "crypto", "encrypt", "authenticated encryption"],
  6 + "authors": [
  7 + {
  8 + "name": "Taylor Hornby",
  9 + "email": "taylor@defuse.ca",
  10 + "homepage": "https://defuse.ca/"
  11 + },
  12 + {
  13 + "name": "Scott Arciszewski",
  14 + "email": "info@paragonie.com",
  15 + "homepage": "https://paragonie.com"
  16 + }
  17 + ],
  18 + "autoload": {
  19 + "psr-4": {
  20 + "Defuse\\Crypto\\": "src"
  21 + }
  22 + },
  23 + "require": {
  24 + "paragonie/random_compat": "~2.0",
  25 + "ext-openssl": "*",
  26 + "php": ">=5.4.0"
  27 + },
  28 + "require-dev": {
  29 + "phpunit/phpunit": "^4|^5",
  30 + "nikic/php-parser": "^2.0|^3.0"
  31 + },
  32 + "bin": [
  33 + "bin/generate-defuse-key"
  34 + ]
  35 +}
... ...
pacotes/composer/vendor/defuse/php-encryption/dist/Makefile 0 → 100644
... ... @@ -0,0 +1,37 @@
  1 +# This builds defuse-crypto.phar. To run this Makefile, `box` and `composer`
  2 +# must be installed and in your $PATH. Run it from inside the dist/ directory.
  3 +
  4 +box := $(shell which box)
  5 +composer := "composer"
  6 +
  7 +.PHONY: all
  8 +all: build-phar
  9 +
  10 +.PHONY: sign-phar
  11 +sign-phar:
  12 + gpg -u 7B4B2D98 --armor --output defuse-crypto.phar.sig --detach-sig defuse-crypto.phar
  13 +
  14 +# ensure we run in clean tree. export git tree and run there.
  15 +.PHONY: build-phar
  16 +build-phar:
  17 + @echo "Creating .phar from revision $(shell git rev-parse HEAD)."
  18 + rm -rf worktree
  19 + install -d worktree
  20 + (cd $(CURDIR)/..; git archive HEAD) | tar -x -C worktree
  21 + $(MAKE) -f $(CURDIR)/Makefile -C worktree defuse-crypto.phar
  22 + mv worktree/*.phar .
  23 + rm -rf worktree
  24 +
  25 +.PHONY: clean
  26 +clean:
  27 + rm -vf defuse-crypto.phar defuse-crypto.phar.sig
  28 +
  29 +# Inside workdir/:
  30 +
  31 +defuse-crypto.phar: dist/box.json composer.lock
  32 + cp dist/box.json .
  33 + php -d phar.readonly=0 $(box) build -c box.json -v
  34 +
  35 +composer.lock:
  36 + $(composer) install --no-dev
  37 +
... ...
pacotes/composer/vendor/defuse/php-encryption/dist/box.json 0 → 100644
... ... @@ -0,0 +1,25 @@
  1 +{
  2 + "chmod": "0755",
  3 + "finder": [
  4 + {
  5 + "in": "src",
  6 + "name": "*.php"
  7 + },
  8 + {
  9 + "in": "vendor/composer",
  10 + "name": "*.php"
  11 + },
  12 + {
  13 + "in": "vendor/paragonie",
  14 + "name": "*.php",
  15 + "exclude": "other"
  16 + }
  17 + ],
  18 + "compactors": [
  19 + "Herrera\\Box\\Compactor\\Php"
  20 + ],
  21 + "main": "vendor/autoload.php",
  22 + "output": "defuse-crypto.phar",
  23 + "shebang": false,
  24 + "stub": true
  25 +}
... ...
pacotes/composer/vendor/defuse/php-encryption/dist/signingkey.asc 0 → 100644
... ... @@ -0,0 +1,52 @@
  1 +-----BEGIN PGP PUBLIC KEY BLOCK-----
  2 +Version: GnuPG v2
  3 +
  4 +mQINBFarvO4BEACdQBaLt6SUBx1cB5liUu1qo+YwVLh9bxTregQtmEREMdTVqXYt
  5 +e5b79uL4pQp2GlKHcEyRURS+6rIIruM0oh9ZYGTJYPAkCDzJxaU2awZeFbfBvpCm
  6 +iF66/O4ZJI4mlT8dFKmxBJxDhfeOR2UmmhDiEsJK9FxBKUzvo/dWrX2pBzf8Y122
  7 +iIaVraSo+tymaf7vriaIf/NnSKhDw8dtQYGM4NMrxxsPTfbCF8XiboDgTkoD2A+6
  8 +NpOJYxA4Veedsf2TP9YLhljH4m5yYlfjjqBzbBCPWuE6Hhy5Xze9mncgDr7LKenm
  9 +Ctf2NxW6y4O3RCI+9eLlBfFWB+KuGV87/b5daetX7NNLbjID8z2rqEa+d6wu5xA5
  10 +Ta2uiVkAOEovr3XnkayZ9zth+Za7w7Ai0ln0N/LVMkM+Gu4z/pJv6HjmTGDM2wJb
  11 +fs+UOM0TFdg+N81Do67XT2M4o0MeHyUqsIiWpYa2Qf1PNmqTQNJnRk8uZZ9I96Nh
  12 +eCgNuCbhsQiYBMicox+xmuWAlGAfA06y0kCtmqGhiBGArdJlWvUqPqGiZ4Hln9z0
  13 +FJmXDOh0Q/FIPxcDg8mKRRbx+lOP389PLsPpj4b2B/4PEgfpCCOwuKpLotATZxC1
  14 +9JwFk0Y/cvUUkq4a+nAJBNtBbtRJkEesuuUnRq6XexmnE3uUucDcV0XCSwARAQAB
  15 +tCBUYXlsb3IgSG9ybmJ5IDx0YXlsb3JAZGVmdXNlLmNhPokCPQQTAQgAJwUCVqu8
  16 +7gIbAwUJB4TOAAULCQgHAgYVCAkKCwIEFgIDAQIeAQIXgAAKCRA4XuBVoSkVOJbx
  17 +EACG0F9blPMAsK05EWyNnnS4mw25zPfbaqqEvYbquAeM0nBpRDm7sRn2MNR0AL4g
  18 +7XrtxE/4qYkdEl6f2wFCQeRhZgxE3w22llredzLme11Hic8hn4i7ysdIw0r9dMMR
  19 +kjgR5UcWpv8iU847czyK09PkKW2EaLRbX2qbA7rNU5qCFKeD4Sy4bBTteISeVsHo
  20 +Vr9o1/bRrMhgZ++ts8hYf0LmujIf5cxp+qcdKwCXSnS/gmmXaKRMCPv/Wdlq9bt6
  21 +LX9jZB9lXBdGxcBJeFOsTG+QRDiVjg3d6i3o3TAKV87ALBI4v2ADEYtN8lviHo3/
  22 +SovVKv6zrUsZHxhoGiLTiksNrYsKMmiMxdJCoOazmtUPnZ4UOtT8NdqMPoKvdoRz
  23 +f4rhZ+f5jSVD9OuX2PDmfyq21Rdiym7Vcgr+uTIFJ3ShRHjWb/ytCwoB2FeGY6+G
  24 +AKY58bTQvUIqEJvSov/+TAqZ4BfOuSdTLcHglV1OdUu2SFZvU2gmyVp0l5elGv5t
  25 +FyUlBJUkQT9MtvsdLOR7vQi8QapV+9LWpqwvaj9hyEJz848DQ2sdYTphUytFHv7H
  26 +k58DAtVhTrVjHyeefjiYtMl6vSAgTjy5LWAUpo5TfhdGrAi0Tdd/GD7amHoWoDy8
  27 +EKXKq2xPLo3JOdkWYQUi5NErzEskfsSzpCOgyDJmGetWK7kCDQRWq7zuARAAu7/i
  28 +cm8cjgLhHEX/bgfwOT2hLOLSjjve0O8YFSuJO9XqIHXqmfVOrqWtfG0Mh4bwlfqc
  29 +MAvBfF5NSSPfAE4ftBAQ1e5jEv8hJeqICpq3IHTFX4etBs49NfNkyveQl/amVTu1
  30 ++/O5J4CuIcsEf3y0Xuu38n7EB3SfMQCWLcOR1NyZoX3bI+CGRpOVVoFse3ljSWL4
  31 +LhLVl0WiEMXULsussEoN+c6x9KCyAi/jFOrxrTrFC//sZesKj6KucoqKGfwMWrrv
  32 +IeRT9Ga8Wn5MJnQu0aWg+zVVYqTedXZLNLODgQIInFnXO0seBXy15yDok1y5bkx2
  33 +sinKg4+mueYaGUpoUti0hM3J3yaC34i6Cwa8MQoLNw1JIS/oNtKjpMxyV10w8aoc
  34 +PHRK3n7UYp10mJHx7aM+lldSKvVS1NTQmI4vloNLwMp324H5ANDFAlRUz7mysVnu
  35 +DEEvigPSPxs5ZYENu/i7pCQC5qHfhrlBrQwTjhegr0pQPcumy2fO5SGC9l/5B7ev
  36 +bqQSZmDeWWoTvh2w2wl5/RWAsgZKx6rDtkCqYx7sSBY17uorrxP24LP4zhq7NxRV
  37 +nfdsLogbCFNVQ66u7qvq5zFccdFtg9h1HQWdS7wbnKSBGZoo5gl6js7GGtxfGbb0
  38 +oQ9kp6eciF4U92r6POhVgbRe4CfPo50nqgZBddkAEQEAAYkCJQQYAQgADwUCVqu8
  39 +7gIbDAUJB4TOAAAKCRA4XuBVoSkVOFJ8D/9J8IJ4XWUU3FYIaHJ3XeSoxDmTi7d5
  40 +WmNdf1lmwz82MQjG4uw17oCbvQzmj4/a/CM1Ly4v0WwBhUf9aiNErD0ByHASFnuc
  41 +tlQBLVJdk0vRyD0fZakGg64qCA76hiySjMhlGHkQFyP2mDORc2GNu/OqFGm79pXT
  42 +ZUplXxd431E603/agM5xJrweutMMpP1nBFTSEMJvbMNzDVN8I1A1CH4zVmAVxOUk
  43 +sQ5L5rXW+KeXWyiMF24+l2CMnkQ2CxfHpkcpfPJs1Cbt+TIBSSofIqK8QJXrb/2f
  44 +Zpl/ftqW7Xe86rJFrB/Y/77LDWx10rqWEvfCqrBxrMj7ONAQfbKQF/IjAwDN17Wf
  45 +1K74rqKnRu+KHCyNM89s1iDbQC9kzZfzYt4AEOvAH/ZQDMZffzPSbnfkBerExFpa
  46 +93XMuiR66jiBsf9IXIQeydpJD4Ogl2sSUSxFEJxJ/bBSxPxC5w7/BVMA7Am1y8Zo
  47 +3hrpqnX2PBzxG7L0FZ6fYkfR3p8JS7vI6nByBf2IDv8W32wn43olPf+u6uobHLvt
  48 +ttapOjwPAhPDalRuxs9U6WSg06QJkT/0F8TFUPWpsFmKTl+G4Ty7PHWsjeeNHJCL
  49 +7/5RQboFY3k8Jy3/sIofABO6Un9LJivDuu9PxqA0IgvaS6Mja8JdCCk9Nyk4vHB7
  50 +IEgAL/CYqrk38w==
  51 +=lmD7
  52 +-----END PGP PUBLIC KEY BLOCK-----
... ...
pacotes/composer/vendor/defuse/php-encryption/docs/CryptoDetails.md 0 → 100644
... ... @@ -0,0 +1,64 @@
  1 +Cryptography Details
  2 +=====================
  3 +
  4 +Here is a high-level description of how this library works. Any discrepancy
  5 +between this documentation and the actual implementation will be considered
  6 +a security bug.
  7 +
  8 +Let's start with the following definitions:
  9 +
  10 +- HKDF-SHA256(*k*, *n*, *info*, *s*) is the key derivation function specified in
  11 + RFC 5869 (using the SHA256 hash function). The parameters are:
  12 + - *k*: The initial keying material.
  13 + - *n*: The number of output bytes.
  14 + - *info*: The info string.
  15 + - *s*: The salt.
  16 +- AES-256-CTR(*m*, *k*, *iv*) is AES-256 encryption in CTR mode. The parameters
  17 + are:
  18 + - *m*: An arbitrary-length (possibly zero-length) message.
  19 + - *k*: A 32-byte key.
  20 + - *iv*: A 16-byte initialization vector (nonce).
  21 +- PBKDF2-SHA256(*p*, *s*, *i*, *n*) is the password-based key derivation
  22 + function defined in RFC 2898 (using the SHA256 hash function). The parameters
  23 + are:
  24 + - *p*: The password string.
  25 + - *s*: The salt string.
  26 + - *i*: The iteration count.
  27 + - *n*: The output length in bytes.
  28 +- VERSION is the string `"\xDE\xF5\x02\x00"`.
  29 +- AUTHINFO is the string `"DefusePHP|V2|KeyForAuthentication"`.
  30 +- ENCRINFO is the string `"DefusePHP|V2|KeyForEncryption"`.
  31 +
  32 +To encrypt a message *m* using a 32-byte key *k*, the following steps are taken:
  33 +
  34 +1. Generate a random 32-byte string *salt*.
  35 +2. Derive the 32-byte authentication key *akey* = HKDF-SHA256(*k*, 32, AUTHINFO, *salt*).
  36 +3. Derive the 32-byte encryption key *ekey* = HKDF-SHA256(*k*, 32, ENCRINFO, *salt*).
  37 +4. Generate a random 16-byte initialization vector *iv*.
  38 +5. Compute *c* = AES-256-CTR(*m*, *ekey*, *iv*).
  39 +6. Combine *ctxt* = VERSION || *salt* || *iv* || *c*.
  40 +7. Compute *h* = HMAC-SHA256(*ctxt*, *akey*).
  41 +8. Output *ctxt* || *h*.
  42 +
  43 +Decryption is roughly the reverse process (see the code for details, since the
  44 +security of the decryption routine is highly implementation-dependent).
  45 +
  46 +For encryption using a password *p*, steps 1-3 above are replaced by:
  47 +
  48 +1. Generate a random 32-byte string *salt*.
  49 +2. Compute *k* = PBKDF2-SHA256(SHA256(*p*), *salt*, 100000, 32).
  50 +3. Derive the 32-byte authentication key *akey* = HKDF-SHA256(*k*, 32, AUTHINFO, *salt*)
  51 +4. Derive the 32-byte encryption key *ekey* = HKDF-SHA256(*k*, 32, ENCRINFO, *salt*)
  52 +
  53 +The remainder of the process is the same. Notice the reuse of the same *salt*
  54 +for PBKDF2-SHA256 and HKDF-SHA256. The prehashing of the password in step 2 is
  55 +done to prevent a [DoS attack using long
  56 +passwords](https://github.com/defuse/php-encryption/issues/230).
  57 +
  58 +For `KeyProtectedByPassword`, the serialized key is encrypted according to the
  59 +password encryption defined above. However, the actual password used for
  60 +encryption is the SHA256 hash of the password the user provided. This is done in
  61 +order to provide domain separation between the message encryption in the user's
  62 +application and the internal key encryption done by this library. It fixes
  63 +a [key replacement chosen-protocol
  64 +attack](https://github.com/defuse/php-encryption/issues/240).
... ...
pacotes/composer/vendor/defuse/php-encryption/docs/FAQ.md 0 → 100644
... ... @@ -0,0 +1,39 @@
  1 +Frequently Asked Questions
  2 +===========================
  3 +
  4 +How do I use this library to encrypt passwords?
  5 +------------------------------------------------
  6 +
  7 +Passwords should not be encrypted, they should be hashed with a *slow* password
  8 +hashing function that's designed to slow down password guessing attacks. See
  9 +[How to Safely Store Your Users' Passwords in
  10 +2016](https://paragonie.com/blog/2016/02/how-safely-store-password-in-2016).
  11 +
  12 +How do I give it the same key every time instead of a new random key?
  13 +----------------------------------------------------------------------
  14 +
  15 +A `Key` object can be saved to a string by calling its `saveToAsciiSafeString()`
  16 +method. You will have to save that string somewhere safe, and then load it back
  17 +into a `Key` object using `Key`'s `loadFromAsciiSafeString` static method.
  18 +
  19 +Where you store the string depends on your application. For example if you are
  20 +using `KeyProtectedByPassword` to encrypt files with a user's login password,
  21 +then you should not store the `Key` at all. If you are protecting sensitive data
  22 +on a server that may be compromised, then you should store it in a hardware
  23 +security module. When in doubt, consult a security expert.
  24 +
  25 +Why is an EnvironmentIsBrokenException getting thrown?
  26 +-------------------------------------------------------
  27 +
  28 +Either you've encountered a bug in this library, or your system doesn't support
  29 +the use of this library. For example, if your system does not have a secure
  30 +random number generator, this library will refuse to run, by throwing that
  31 +exception, instead of falling back to an insecure random number generator.
  32 +
  33 +Why am I getting a BadFormatException when loading a Key from a string?
  34 +------------------------------------------------------------------------
  35 +
  36 +If you're getting this exception, then the string you're giving to
  37 +`loadFromAsciiSafeString()` is *not* the same as the string you got from
  38 +`saveToAsciiSafeString()`. Perhaps your database column isn't wide enough and
  39 +it's truncating the string as you insert it?
... ...
pacotes/composer/vendor/defuse/php-encryption/docs/InstallingAndVerifying.md 0 → 100644
... ... @@ -0,0 +1,53 @@
  1 +Getting The Code
  2 +=================
  3 +
  4 +There are two ways to use this library in your applications. You can either:
  5 +
  6 +1. Use [Composer](https://getcomposer.org/), or
  7 +2. `require_once` a single `.phar` file in your application.
  8 +
  9 +If you are not using either option (for example, because you're using Git submodules), you may need to write your own autoloader ([example](https://gist.github.com/paragonie-scott/949daee819bb7f19c50e5e103170b400)).
  10 +
  11 +Option 1: Using Composer
  12 +-------------------------
  13 +
  14 +Run this inside the directory of your composer-enabled project:
  15 +
  16 +```sh
  17 +composer require defuse/php-encryption
  18 +```
  19 +
  20 +Unfortunately, composer doesn't provide a way for you to verify that the code
  21 +you're getting was signed by this library's authors. If you want a more secure
  22 +option, use the `.phar` method described below.
  23 +
  24 +Option 2: Including a PHAR
  25 +----------------------------
  26 +
  27 +The `.phar` option lets you include this library into your project simply by
  28 +calling `require_once` on a single file. Download `defuse-crypto.phar` and
  29 +`defuse-crypto.phar.sig` from this project's
  30 +[releases](https://github.com/defuse/php-encryption/releases) page.
  31 +
  32 +You should verify the integrity of the `.phar`. The `defuse-crypto.phar.sig`
  33 +contains the signature of `defuse-crypto.phar`. It is signed with Taylor
  34 +Hornby's PGP key. You can find Taylor's public key in `dist/signingkey.asc`. You
  35 +can verify the public key's fingerprint against the Taylor Hornby's [contact
  36 +page](https://defuse.ca/contact.htm) and
  37 +[twitter](https://twitter.com/DefuseSec/status/723741424253059074).
  38 +
  39 +Once you have verified the signature, it is safe to use the `.phar`. Place it
  40 +somewhere in your file system, e.g. `/var/www/lib/defuse-crypto.phar`, and then
  41 +pass that path to `require_once`.
  42 +
  43 +```php
  44 +<?php
  45 +
  46 + require_once('/var/www/lib/defuse-crypto.phar');
  47 +
  48 + // ... the Crypto, File, Key, and KeyProtectedByPassword classes are now
  49 + // available ...
  50 +
  51 + // ...
  52 +```
  53 +
... ...
pacotes/composer/vendor/defuse/php-encryption/docs/InternalDeveloperDocs.md 0 → 100644
... ... @@ -0,0 +1,160 @@
  1 +Information for the Developers of php-encryption
  2 +=================================================
  3 +
  4 +Status
  5 +-------
  6 +
  7 +This library is currently frozen under a long-term support release. We do not
  8 +plan to add any new features. We will maintain the library by fixing any bugs
  9 +that are reported, or security vulnerabilities that are found.
  10 +
  11 +Development Environment
  12 +------------------------
  13 +
  14 +Development is done on Linux. To run the tests, you will need to have the
  15 +following tools installed:
  16 +
  17 +- `php` (with OpenSSL enabled, if you're compiling from source).
  18 +- `gpg`
  19 +- `composer`
  20 +
  21 +Running the Tests
  22 +------------------
  23 +
  24 +First do `composer install` and then you can run the tests by running
  25 +`./test.sh`. This will download a PHPUnit PHAR, verify its cryptographic
  26 +signatures, and then use it to run the tests in `test/unit`.
  27 +
  28 +Getting and Using Psalm
  29 +-----------------------
  30 +
  31 +[Psalm](https://github.com/vimeo/psalm) is a static analysis suite for PHP projects.
  32 +We use Psalm to ensure type safety throughout our library.
  33 +
  34 +To install Psalm, you just need to run one command:
  35 +
  36 + composer require --dev "vimeo/psalm:dev-master"
  37 +
  38 +To verify that your code changes are still strictly type-safe, run the following
  39 +command:
  40 +
  41 + vendor/bin/psalm
  42 +
  43 +Reporting Bugs
  44 +---------------
  45 +
  46 +Please report bugs, even critical security vulnerabilities, by opening an issue
  47 +on GitHub. We recommend disclosing security vulnerabilities found in this
  48 +library *publicly* as soon as possible.
  49 +
  50 +Philosophy
  51 +-----------
  52 +
  53 +This library is developed around several core values:
  54 +
  55 +- Rule #1: Security is prioritized over everything else.
  56 +
  57 + > Whenever there is a conflict between security and some other property,
  58 + > security will be favored. For example, the library has runtime tests,
  59 + > which make it slower, but will hopefully stop it from encrypting stuff
  60 + > if the platform it's running on is broken.
  61 +
  62 +- Rule #2: It should be difficult to misuse the library.
  63 +
  64 + > We assume the developers using this library have no experience with
  65 + > cryptography. We only assume that they know that the "key" is something
  66 + > you need to encrypt and decrypt the messages, and that it must be kept
  67 + > secret. Whenever possible, the library should refuse to encrypt or decrypt
  68 + > messages when it is not being used correctly.
  69 +
  70 +- Rule #3: The library aims only to be compatible with itself.
  71 +
  72 + > Other PHP encryption libraries try to support every possible type of
  73 + > encryption, even the insecure ones (e.g. ECB mode). Because there are so
  74 + > many options, inexperienced developers must decide whether to use "CBC
  75 + > mode" or "ECB mode" when both are meaningless terms to them. This
  76 + > inevitably leads to vulnerabilities.
  77 +
  78 + > This library will only support one secure mode. A developer using this
  79 + > library will call "encrypt" and "decrypt" methods without worrying about
  80 + > how they are implemented.
  81 +
  82 +- Rule #4: The library should require no special installation.
  83 +
  84 + > Some PHP encryption libraries, like libsodium-php, are not straightforward
  85 + > to install and cannot packaged with "just download and extract"
  86 + > applications. This library will always be just a handful of PHP files that
  87 + > you can copy to your source tree and require().
  88 +
  89 +Publishing Releases
  90 +--------------------
  91 +
  92 +To make a release, you will need to install [composer](https://getcomposer.org/)
  93 +and [box](https://github.com/box-project/box2) on your system. They will need to
  94 +be available in your `$PATH` so that running the commands `composer` and `box`
  95 +in your terminal run them, respectively. You will also need the private key for
  96 +signing (ID: 7B4B2D98) available.
  97 +
  98 +Once you have those tools installed and the key available follow these steps:
  99 +
  100 +**Remember to set the version number in `composer.json`!**
  101 +
  102 +Make a fresh clone of the repository:
  103 +
  104 +```
  105 +git clone <url>
  106 +```
  107 +
  108 +Check out the branch you want to release:
  109 +
  110 +```
  111 +git checkout <branchname>
  112 +```
  113 +
  114 +Check that the version number in composer.json is correct:
  115 +
  116 +```
  117 +cat composer.json
  118 +```
  119 +
  120 +Run the tests:
  121 +
  122 +```
  123 +composer install
  124 +./test.sh
  125 +```
  126 +
  127 +Generate the `.phar`:
  128 +
  129 +```
  130 +cd dist
  131 +make build-phar
  132 +```
  133 +
  134 +Test the `.phar`:
  135 +
  136 +```
  137 +cd ../
  138 +./test.sh dist/defuse-crypto.phar
  139 +```
  140 +
  141 +Sign the `.phar`:
  142 +
  143 +```
  144 +cd dist
  145 +make sign-phar
  146 +```
  147 +
  148 +Tag the release:
  149 +
  150 +```
  151 +git -c user.signingkey=7B4B2D98 tag -s "<TAG NAME>" -m "<TAG MESSAGE>"
  152 +```
  153 +
  154 +`<TAG NAME>` should be in the format `v2.0.0` and `<TAG MESSAGE>` should look
  155 +like "Release of v2.0.0."
  156 +
  157 +Push the tag to github, then use the
  158 +[releases](https://github.com/defuse/php-encryption/releases) page to draft
  159 +a new release for that tag. Upload the `.phar` and the `.phar.sig` file to be
  160 +included as part of that release.
... ...
pacotes/composer/vendor/defuse/php-encryption/docs/Tutorial.md 0 → 100644
... ... @@ -0,0 +1,298 @@
  1 +Tutorial
  2 +=========
  3 +
  4 +Hello! If you're reading this file, it's because you want to add encryption to
  5 +one of your PHP projects. My job, as the person writing this documentation, is
  6 +to help you make sure you're doing the right thing and then show you how to use
  7 +this library to do it. To help me help you, please read the documentation
  8 +*carefully* and *deliberately*.
  9 +
  10 +A Word of Caution
  11 +------------------
  12 +
  13 +Encryption is not magic dust you can sprinkle on a system to make it more
  14 +secure. The way encryption is integrated into a system's design needs to be
  15 +carefully thought out. Sometimes, encryption is the wrong thing to use. Other
  16 +times, encryption needs to be used in a very specific way in order for it to
  17 +work as intended. Even if you are sure of what you are doing, we strongly
  18 +recommend seeking advice from an expert.
  19 +
  20 +The first step is to think about your application's threat model. Ask yourself
  21 +the following questions. Who will want to attack my application, and what will
  22 +they get out of it? Are they trying to steal some information? Trying to alter
  23 +or destroy some information? Or just trying to make the system go down so people
  24 +can't access it? Then ask yourself how encryption can help combat those threats.
  25 +If you're going to add encryption to your application, you should have a very
  26 +clear idea of exactly which kinds of attacks it's helping to secure your
  27 +application against. Once you have your threat model, think about what kinds of
  28 +attacks it *does not* cover, and whether or not you should improve your threat
  29 +model to include those attacks.
  30 +
  31 +**This isn't for storing user login passwords:** The most common use of
  32 +cryptography in web applications is to protect the users' login passwords. If
  33 +you're trying to use this library to "encrypt" your users' passwords, you're in
  34 +the wrong place. Passwords shouldn't be *encrypted*, they should be *hashed*
  35 +with a slow computation-heavy function that makes password guessing attacks more
  36 +expensive. See [How to Safely Store Your Users' Passwords in
  37 +2016](https://paragonie.com/blog/2016/02/how-safely-store-password-in-2016).
  38 +
  39 +**This isn't for encrypting network communication:** Likewise, if you're trying
  40 +to encrypt messages sent between two parties over the Internet, you don't want
  41 +to be using this library. For that, set up a TLS connection between the two
  42 +points, or, if it's a chat app, use the [Signal
  43 +Protocol](https://whispersystems.org/blog/advanced-ratcheting/).
  44 +
  45 +What this library provides is symmetric encryption for "data at rest." This
  46 +means it is not suitable for use in building protocols where "data is in motion"
  47 +(i.e. moving over a network) except in limited set of cases.
  48 +
  49 +Getting the Code
  50 +-----------------
  51 +
  52 +There are several different ways to obtain this library's code and to add it to
  53 +your project. Even if you've already cloned the code from GitHub, you should
  54 +take steps to verify the cryptographic signatures to make sure the code you got
  55 +was not intercepted and modified by an attacker.
  56 +
  57 +Please head over to the [**Installing and
  58 +Verifying**](InstallingAndVerifying.md) documentation to get the code, and then
  59 +come back here to continue the tutorial.
  60 +
  61 +Using the Library
  62 +------------------
  63 +
  64 +I'm going to assume you know what symmetric encryption is, and the difference
  65 +between symmetric and asymmetric encryption. If you don't, I recommend taking
  66 +[Dan Boneh's Cryptography I course](https://www.coursera.org/learn/crypto/) on
  67 +Coursera.
  68 +
  69 +To give you a quick introduction to the library, I'm going to explain how it
  70 +would be used in two sterotypical scenarios. Hopefully, one of these sterotypes
  71 +is close enough to what you want to do that you'll be able to figure out what
  72 +needs to be different on your own.
  73 +
  74 +### Formal Documentation
  75 +
  76 +While this tutorial should get you up and running fast, it's important to
  77 +understand how this library behaves. Please make sure to read the formal
  78 +documentation of all of the functions you're using, since there are some
  79 +important security warnings there.
  80 +
  81 +The following classes are available for you to use:
  82 +
  83 +- [Crypto](classes/Crypto.md): Encrypting and decrypting strings.
  84 +- [File](classes/File.md): Encrypting and decrypting files.
  85 +- [Key](classes/Key.md): Represents a secret encryption key.
  86 +- [KeyProtectedByPassword](classes/KeyProtectedByPassword.md): Represents
  87 + a secret encryption key that needs to be "unlocked" by a password before it
  88 + can be used.
  89 +
  90 +### Scenario #1: Keep data secret from the database administrator
  91 +
  92 +In this scenario, our threat model is as follows. Alice is a server
  93 +administrator responsible for managing a trusted web server. Eve is a database
  94 +administrator responsible for managing a database server. Dave is a web
  95 +developer working on code that will eventually run on the trusted web server.
  96 +
  97 +Let's say Alice and Dave trust each other, and Alice is going to host Dave's
  98 +application on her server. But both Alice and Dave don't trust Eve. They know
  99 +Eve is a good database administrator, but she might have incentive to steal the
  100 +data from the database. They want to keep some of the web application's data
  101 +secret from Eve.
  102 +
  103 +In order to do that, Alice will use the included `generate-defuse-key` script
  104 +which generates a random encryption key and prints it to standard output:
  105 +
  106 +```sh
  107 +$ composer require defuse/php-encryption
  108 +$ vendor/bin/generate-defuse-key
  109 +```
  110 +
  111 +Alice will run this script once and save the output to a configuration file, say
  112 +in `/etc/daveapp-secret-key.txt` and set the file permissions so that only the
  113 +user that the website PHP scripts run as can access it.
  114 +
  115 +Dave will write his code to load the key from the configuration file:
  116 +
  117 +```php
  118 +<?php
  119 +use Defuse\Crypto\Key;
  120 +
  121 +function loadEncryptionKeyFromConfig()
  122 +{
  123 + $keyAscii = // ... load the contents of /etc/daveapp-secret-key.txt
  124 + return Key::loadFromAsciiSafeString($keyAscii);
  125 +}
  126 +```
  127 +
  128 +Then, whenever Dave wants to save a secret value to the database, he will first
  129 +encrypt it:
  130 +
  131 +```php
  132 +<?php
  133 +use Defuse\Crypto\Crypto;
  134 +
  135 +// ...
  136 +$key = loadEncryptionKeyFromConfig();
  137 +// ...
  138 +$ciphertext = Crypto::encrypt($secret_data, $key);
  139 +// ... save $ciphertext into the database ...
  140 +```
  141 +
  142 +Whenever Dave wants to get the value back from the database, he must decrypt it
  143 +using the same key:
  144 +
  145 +```php
  146 +<?php
  147 +use Defuse\Crypto\Crypto;
  148 +
  149 +// ...
  150 +$key = loadEncryptionKeyFromConfig();
  151 +// ...
  152 +$ciphertext = // ... load $ciphertext from the database
  153 +try {
  154 + $secret_data = Crypto::decrypt($ciphertext, $key);
  155 +} catch (\Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException $ex) {
  156 + // An attack! Either the wrong key was loaded, or the ciphertext has
  157 + // changed since it was created -- either corrupted in the database or
  158 + // intentionally modified by Eve trying to carry out an attack.
  159 +
  160 + // ... handle this case in a way that's suitable to your application ...
  161 +}
  162 +```
  163 +
  164 +Note that if anyone ever steals the key from Alice's server, they can decrypt
  165 +all of the ciphertexts that are stored in the database. As part of our threat
  166 +model, we are assuming Alice's server administration skills and Dave's secure
  167 +coding skills are good enough to stop Eve from being able to steal the key.
  168 +Under those assumptions, this solution will prevent Eve from seeing data that's
  169 +stored in the database.
  170 +
  171 +However, notice that our threat model says nothing about what could happen if
  172 +Eve wants to *modify* the data. With this solution, Eve will not be able to
  173 +alter any individual ciphertext (because each ciphertext has its own
  174 +cryptographic integrity check), but Eve *will* be able to swap ciphertexts for
  175 +one another, and revert ciphertexts to what they used to be at previous times.
  176 +If we needed to defend against such attacks, we would have to re-design our
  177 +threat model and come up with a different solution.
  178 +
  179 +### Scenario #2: Encrypting account data with the user's login password
  180 +
  181 +This scenario is like Scenario 1, but subtly different. The threat model is as
  182 +follows. We have Alice, a server administrator, and Dave, the developer. Alice
  183 +and Dave trust each other, and Alice wants to host Dave's web application,
  184 +including its database, on her server. Alice is worried about her server getting
  185 +hacked. The application will store the users' credit card numbers, and Alice
  186 +wants to protect them in case the server gets hacked.
  187 +
  188 +We can model the situation like this: after the server gets hacked, the attacker
  189 +will have read and write access to all data on it until the attack is detected
  190 +and Alice rebuilds the server. We'll call the time the attacker has access to
  191 +the server the *exposure window.* One idea to minimize loss is to encrypt the
  192 +users' credit card numbers using a key made from their login password. Then, as
  193 +long as the users all have strong passwords, and they are never logged in during
  194 +the exposure window, their credit cards will be protected from the attacker.
  195 +
  196 +To implement this, Dave will use the `KeyProtectedByPassword` class. When a new
  197 +user account is created, Dave will save a new key to their account, one that's
  198 +protected by their login password:
  199 +
  200 +```php
  201 +<?php
  202 +use Defuse\Crypto\KeyProtectedByPassword;
  203 +
  204 +function CreateUserAccount($username, $password)
  205 +{
  206 + // ... other user account creation stuff, including password hashing
  207 +
  208 + $protected_key = KeyProtectedByPassword::createRandomPasswordProtectedKey($password);
  209 + $protected_key_encoded = $protected_key->saveToAsciiSafeString();
  210 + // ... save $protected_key_encoded into the user's account record
  211 +}
  212 +```
  213 +
  214 +Then, when the user logs in, Dave's code will load the protected key from the
  215 +user's account record, unlock it to get a `Key` object, and save the `Key`
  216 +object somewhere safe (like temporary memory-backed session storage). Note that
  217 +wherever Dave's code saves the key, it must be destroyed once the user logs out,
  218 +or else the attacker might be able to find users' keys even if they were never
  219 +logged in during the attack.
  220 +
  221 +```php
  222 +<?php
  223 +use Defuse\Crypto\KeyProtectedByPassword;
  224 +
  225 +// ... authenticate the user using a good password hashing scheme
  226 +// keep the user's password in $password
  227 +
  228 +$protected_key_encoded = // ... load it from the user's account record
  229 +$protected_key = KeyProtectedByPassword::loadFromAsciiSafeString($protected_key_encoded);
  230 +$user_key = $protected_key->unlockKey($password);
  231 +$user_key_encoded = $user_key->saveToAsciiSafeString();
  232 +// ... save $user_key_encoded in the session
  233 +```
  234 +
  235 +```php
  236 +<?php
  237 +// ... when the user is logging out ...
  238 +// ... securely wipe the saved $user_key_encoded from the system ...
  239 +```
  240 +
  241 +When a user adds their credit card number, Dave's code will get the key from the
  242 +session and use it to encrypt the credit card number:
  243 +
  244 +```php
  245 +<?php
  246 +use Defuse\Crypto\Crypto;
  247 +use Defuse\Crypto\Key;
  248 +
  249 +// ...
  250 +
  251 +$user_key_encoded = // ... get it out of the session ...
  252 +$user_key = Key::loadFromAsciiSafeString($user_key_encoded);
  253 +
  254 +// ...
  255 +
  256 +$credit_card_number = // ... get credit card number from the user
  257 +$encrypted_card_number = Crypto::encrypt($credit_card_number, $user_key);
  258 +// ... save $encrypted_card_number in the database
  259 +```
  260 +
  261 +When the application needs to use the credit card number, it will decrypt it:
  262 +
  263 +```php
  264 +<?php
  265 +use Defuse\Crypto\Crypto;
  266 +use Defuse\Crypto\Key;
  267 +
  268 +// ...
  269 +
  270 +$user_key_encoded = // ... get it out of the session
  271 +$user_key = Key::loadFromAsciiSafeString($user_key_encoded);
  272 +
  273 +// ...
  274 +
  275 +$encrypted_card_number = // ... load it from the database ...
  276 +try {
  277 + $credit_card_number = Crypto::decrypt($encrypted_card_number, $user_key);
  278 +} catch (Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException $ex) {
  279 + // Either there's a bug in our code, we're trying to decrypt with the
  280 + // wrong key, or the encrypted credit card number was corrupted in the
  281 + // database.
  282 +
  283 + // ... handle this case ...
  284 +}
  285 +```
  286 +
  287 +With all caveats carefully heeded, this solution limits credit card number
  288 +exposure in the case where Alice's server gets hacked for a short amount of
  289 +time. Remember to think about the attacks that *aren't* included in our threat
  290 +model. The attacker is still free to do all sorts of harmful things like
  291 +modifying the server's data which may go undetected if Alice doesn't have secure
  292 +backups to compare against.
  293 +
  294 +Getting Help
  295 +-------------
  296 +
  297 +If you're having difficulty using the library, see if your problem is already
  298 +solved by an answer in the [FAQ](FAQ.md).
... ...
pacotes/composer/vendor/defuse/php-encryption/docs/UpgradingFromV1.2.md 0 → 100644
... ... @@ -0,0 +1,51 @@
  1 +Upgrading From Version 1.2
  2 +===========================
  3 +
  4 +With version 2.0.0 of this library came major changes to the ciphertext format,
  5 +algorithms used for encryption, and API.
  6 +
  7 +In version 1.2, keys were represented by 16-byte string variables. In version
  8 +2.0.0, keys are represented by objects, instances of the `Key` class. This
  9 +change was made in order to make it harder to misuse the API. For example, in
  10 +version 1.2, you could pass in *any* 16-byte string, but in version 2.0.0 you
  11 +need a `Key` object, which you can only get if you're "doing the right thing."
  12 +
  13 +This means that for all of your old version 1.2 keys, you'll have to:
  14 +
  15 +1. Generate a new version 2.0.0 key.
  16 +2. For all of the ciphertexts encrypted under the old key:
  17 + 1. Decrypt the ciphertext using the old version 1.2 key.
  18 + 2. Re-encrypt it using the new version 2.0.0 key.
  19 +
  20 +Use the special `Crypto::legacyDecrypt()` method to decrypt the old ciphertexts
  21 +using the old key and then re-encrypt them using `Crypto::encrypt()` with the
  22 +new key. Your code will look something like the following. To avoid data loss,
  23 +securely back up your keys and data before running your upgrade code.
  24 +
  25 +```php
  26 +<?php
  27 +
  28 + // ...
  29 +
  30 + $legacy_ciphertext = // ... get the ciphertext you want to upgrade ...
  31 + $legacy_key = // ... get the key to decrypt this ciphertext ...
  32 +
  33 + // Generate the new key that we'll re-encrypt the ciphertext with.
  34 + $new_key = Key::createNewRandomKey();
  35 + // ... save it somewhere ...
  36 +
  37 + // Decrypt it.
  38 + try {
  39 + $plaintext = Crypto::legacyDecrypt($legacy_ciphertext, $legacy_key);
  40 + } catch (Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException $ex)
  41 + {
  42 + // ... TODO: handle this case appropriately ...
  43 + }
  44 +
  45 + // Re-encrypt it.
  46 + $new_ciphertext = Crypto::encrypt($plaintext, $new_key);
  47 +
  48 + // ... replace the old $legacy_ciphertext with the new $new_ciphertext
  49 +
  50 + // ...
  51 +```
... ...
pacotes/composer/vendor/defuse/php-encryption/docs/classes/Crypto.md 0 → 100644
... ... @@ -0,0 +1,260 @@
  1 +Class: Defuse\Crypto\Crypto
  2 +============================
  3 +
  4 +The `Crypto` class provides encryption and decryption of strings either using
  5 +a secret key or secret password. For encryption and decryption of large files,
  6 +see the `File` class.
  7 +
  8 +This code for this class is in `src/Crypto.php`.
  9 +
  10 +Instance Methods
  11 +-----------------
  12 +
  13 +This class has no instance methods.
  14 +
  15 +Static Methods
  16 +---------------
  17 +
  18 +### Crypto::encrypt($plaintext, Key $key, $raw\_binary = false)
  19 +
  20 +**Description:**
  21 +
  22 +Encrypts a plaintext string using a secret key.
  23 +
  24 +**Parameters:**
  25 +
  26 +1. `$plaintext` is the string to encrypt.
  27 +2. `$key` is an instance of `Key` containing the secret key for encryption.
  28 +3. `$raw_binary` determines whether the output will be a byte string (true) or
  29 + hex encoded (false, the default).
  30 +
  31 +**Return value:**
  32 +
  33 +Returns a ciphertext string representing `$plaintext` encrypted with the key
  34 +`$key`. Knowledge of `$key` is required in order to decrypt the ciphertext and
  35 +recover the plaintext.
  36 +
  37 +**Exceptions:**
  38 +
  39 +- `Defuse\Crypto\Exception\EnvironmentIsBrokenException` is thrown either when
  40 + the platform the code is running on cannot safely perform encryption for some
  41 + reason (e.g. it lacks a secure random number generator), or the runtime tests
  42 + detected a bug in this library.
  43 +
  44 +**Side-effects and performance:**
  45 +
  46 +This method runs a small and very fast set of self-tests if it is the very first
  47 +time one of the `Crypto` methods has been called. The performance overhead is
  48 +negligible and can be safely ignored in all applications.
  49 +
  50 +**Cautions:**
  51 +
  52 +The ciphertext returned by this method is decryptable by anyone with knowledge
  53 +of the key `$key`. It is the caller's responsibility to keep `$key` secret.
  54 +Where `$key` should be stored is up to the caller and depends on the threat
  55 +model the caller is designing their application under. If you are unsure where
  56 +to store `$key`, consult with a professional cryptographer to get help designing
  57 +your application.
  58 +
  59 +### Crypto::decrypt($ciphertext, Key $key, $raw\_binary = false)
  60 +
  61 +**Description:**
  62 +
  63 +Decrypts a ciphertext string using a secret key.
  64 +
  65 +**Parameters:**
  66 +
  67 +1. `$ciphertext` is the ciphertext to be decrypted.
  68 +2. `$key` is an instance of `Key` containing the secret key for decryption.
  69 +3. `$raw_binary` must have the same value as the `$raw_binary` given to the
  70 + call to `encrypt()` that generated `$ciphertext`.
  71 +
  72 +**Return value:**
  73 +
  74 +If the decryption succeeds, returns a string containing the same value as the
  75 +string that was passed to `encrypt()` when `$ciphertext` was produced. Upon
  76 +a successful return, the caller can be assured that `$ciphertext` could not have
  77 +been produced except by someone with knowledge of `$key`.
  78 +
  79 +**Exceptions:**
  80 +
  81 +- `Defuse\Crypto\Exception\EnvironmentIsBrokenException` is thrown either when
  82 + the platform the code is running on cannot safely perform encryption for some
  83 + reason (e.g. it lacks a secure random number generator), or the runtime tests
  84 + detected a bug in this library.
  85 +
  86 +- `Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException` is thrown if
  87 + the `$key` is not the correct key for the given ciphertext, or if the
  88 + ciphertext has been modified (possibly maliciously). There is no way to
  89 + distinguish between these two cases.
  90 +
  91 +**Side-effects and performance:**
  92 +
  93 +This method runs a small and very fast set of self-tests if it is the very first
  94 +time one of the `Crypto` methods has been called. The performance overhead is
  95 +negligible and can be safely ignored in all applications.
  96 +
  97 +**Cautions:**
  98 +
  99 +It is impossible in principle to distinguish between the case where you attempt
  100 +to decrypt with the wrong key and the case where you attempt to decrypt
  101 +a modified (corrupted) ciphertext. It is up to the caller how to best deal with
  102 +this ambiguity, as it depends on the application this library is being used in.
  103 +If in doubt, consult with a professional cryptographer.
  104 +
  105 +### Crypto::encryptWithPassword($plaintext, $password, $raw\_binary = false)
  106 +
  107 +**Description:**
  108 +
  109 +Encrypts a plaintext string using a secret password.
  110 +
  111 +**Parameters:**
  112 +
  113 +1. `$plaintext` is the string to encrypt.
  114 +2. `$password` is a string containing the secret password used for encryption.
  115 +3. `$raw_binary` determines whether the output will be a byte string (true) or
  116 + hex encoded (false, the default).
  117 +
  118 +**Return value:**
  119 +
  120 +Returns a ciphertext string representing `$plaintext` encrypted with a key
  121 +derived from `$password`. Knowledge of `$password` is required in order to
  122 +decrypt the ciphertext and recover the plaintext.
  123 +
  124 +**Exceptions:**
  125 +
  126 +- `Defuse\Crypto\Exception\EnvironmentIsBrokenException` is thrown either when
  127 + the platform the code is running on cannot safely perform encryption for some
  128 + reason (e.g. it lacks a secure random number generator), or the runtime tests
  129 + detected a bug in this library.
  130 +
  131 +**Side-effects and performance:**
  132 +
  133 +This method is intentionally slow, using a lot of CPU resources for a fraction
  134 +of a second. It applies key stretching to the password in order to make password
  135 +guessing attacks more computationally expensive. If you need a faster way to
  136 +encrypt multiple ciphertexts under the same password, see the
  137 +`KeyProtectedByPassword` class.
  138 +
  139 +This method runs a small and very fast set of self-tests if it is the very first
  140 +time one of the `Crypto` methods has been called. The performance overhead is
  141 +negligible and can be safely ignored in all applications.
  142 +
  143 +**Cautions:**
  144 +
  145 +PHP stack traces display (portions of) the arguments passed to methods on the
  146 +call stack. If an exception is thrown inside this call, and it is uncaught, the
  147 +value of `$password` may be leaked out to an attacker through the stack trace.
  148 +We recommend configuring PHP to never output stack traces (either displaying
  149 +them to the user or saving them to log files).
  150 +
  151 +### Crypto::decryptWithPassword($ciphertext, $password, $raw\_binary = false)
  152 +
  153 +**Description:**
  154 +
  155 +Decrypts a ciphertext string using a secret password.
  156 +
  157 +**Parameters:**
  158 +
  159 +1. `$ciphertext` is the ciphertext to be decrypted.
  160 +2. `$password` is a string containing the secret password used for decryption.
  161 +3. `$raw_binary` must have the same value as the `$raw_binary` given to the
  162 + call to `encryptWithPassword()` that generated `$ciphertext`.
  163 +
  164 +**Return value:**
  165 +
  166 +If the decryption succeeds, returns a string containing the same value as the
  167 +string that was passed to `encryptWithPassword()` when `$ciphertext` was
  168 +produced. Upon a successful return, the caller can be assured that `$ciphertext`
  169 +could not have been produced except by someone with knowledge of `$password`.
  170 +
  171 +**Exceptions:**
  172 +
  173 +- `Defuse\Crypto\Exception\EnvironmentIsBrokenException` is thrown either when
  174 + the platform the code is running on cannot safely perform encryption for some
  175 + reason (e.g. it lacks a secure random number generator), or the runtime tests
  176 + detected a bug in this library.
  177 +
  178 +- `Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException` is thrown if
  179 + the `$password` is not the correct password for the given ciphertext, or if
  180 + the ciphertext has been modified (possibly maliciously). There is no way to
  181 + distinguish between these two cases.
  182 +
  183 +**Side-effects:**
  184 +
  185 +This method is intentionally slow. It applies key stretching to the password in
  186 +order to make password guessing attacks more computationally expensive. If you
  187 +need a faster way to encrypt multiple ciphertexts under the same password, see
  188 +the `KeyProtectedByPassword` class.
  189 +
  190 +This method runs a small and very fast set of self-tests if it is the very first
  191 +time one of the `Crypto` methods has been called. The performance overhead is
  192 +negligible and can be safely ignored in all applications.
  193 +
  194 +**Cautions:**
  195 +
  196 +PHP stack traces display (portions of) the arguments passed to methods on the
  197 +call stack. If an exception is thrown inside this call, and it is uncaught, the
  198 +value of `$password` may be leaked out to an attacker through the stack trace.
  199 +We recommend configuring PHP to never output stack traces (either displaying
  200 +them to the user or saving them to log files).
  201 +
  202 +It is impossible in principle to distinguish between the case where you attempt
  203 +to decrypt with the wrong password and the case where you attempt to decrypt
  204 +a modified (corrupted) ciphertext. It is up to the caller how to best deal with
  205 +this ambiguity, as it depends on the application this library is being used in.
  206 +If in doubt, consult with a professional cryptographer.
  207 +
  208 +### Crypto::legacyDecrypt($ciphertext, $key)
  209 +
  210 +**Description:**
  211 +
  212 +Decrypts a ciphertext produced by version 1 of this library so that the
  213 +plaintext can be re-encrypted into a version 2 ciphertext. See [Upgrading from
  214 +v1.2](../UpgradingFromV1.2.md).
  215 +
  216 +**Parameters:**
  217 +
  218 +1. `$ciphertext` is a ciphertext produced by version 1.x of this library.
  219 +2. `$key` is a 16-byte string (*not* a Key object) containing the key that was
  220 + used with version 1.x of this library to produce `$ciphertext`.
  221 +
  222 +**Return value:**
  223 +
  224 +If the decryption succeeds, returns the string that was encrypted to make
  225 +`$ciphertext` by version 1.x of this library. Upon a successful return, the
  226 +caller can be assured that `$ciphertext` could not have been produced except by
  227 +someone with knowledge of `$key`.
  228 +
  229 +**Exceptions:**
  230 +
  231 +- `Defuse\Crypto\Exception\EnvironmentIsBrokenException` is thrown either when
  232 + the platform the code is running on cannot safely perform encryption for some
  233 + reason (e.g. it lacks a secure random number generator), or the runtime tests
  234 + detected a bug in this library.
  235 +
  236 +- `Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException` is thrown if
  237 + the `$key` is not the correct key for the given ciphertext, or if the
  238 + ciphertext has been modified (possibly maliciously). There is no way to
  239 + distinguish between these two cases.
  240 +
  241 +**Side-effects:**
  242 +
  243 +This method runs a small and very fast set of self-tests if it is the very first
  244 +time one of the `Crypto` methods has been called. The performance overhead is
  245 +negligible and can be safely ignored in all applications.
  246 +
  247 +**Cautions:**
  248 +
  249 +PHP stack traces display (portions of) the arguments passed to methods on the
  250 +call stack. If an exception is thrown inside this call, and it is uncaught, the
  251 +value of `$key` may be leaked out to an attacker through the stack trace. We
  252 +recommend configuring PHP to never output stack traces (either displaying them
  253 +to the user or saving them to log files).
  254 +
  255 +It is impossible in principle to distinguish between the case where you attempt
  256 +to decrypt with the wrong key and the case where you attempt to decrypt
  257 +a modified (corrupted) ciphertext. It is up to the caller how to best deal with
  258 +this ambiguity, as it depends on the application this library is being used in.
  259 +If in doubt, consult with a professional cryptographer.
  260 +
... ...
pacotes/composer/vendor/defuse/php-encryption/docs/classes/File.md 0 → 100644
... ... @@ -0,0 +1,446 @@
  1 +Class: Defuse\Crypto\File
  2 +==========================
  3 +
  4 +Instance Methods
  5 +-----------------
  6 +
  7 +This class has no instance methods.
  8 +
  9 +Static Methods
  10 +---------------
  11 +
  12 +### File::encryptFile($inputFilename, $outputFilename, Key $key)
  13 +
  14 +**Description:**
  15 +
  16 +Encrypts a file using a secret key.
  17 +
  18 +**Parameters:**
  19 +
  20 +1. `$inputFilename` is the path to a file containing the plaintext to encrypt.
  21 +2. `$outputFilename` is the path to save the ciphertext file.
  22 +3. `$key` is an instance of `Key` containing the secret key for encryption.
  23 +
  24 +**Behavior:**
  25 +
  26 +Encrypts the contents of the input file, writing the result to the output file.
  27 +If the output file already exists, it is overwritten.
  28 +
  29 +**Return value:**
  30 +
  31 +Does not return a value.
  32 +
  33 +**Exceptions:**
  34 +
  35 +- `Defuse\Crypto\Exception\IOException` is thrown if there is an I/O error.
  36 +
  37 +- `Defuse\Crypto\Exception\EnvironmentIsBrokenException` is thrown either when
  38 + the platform the code is running on cannot safely perform encryption for some
  39 + reason (e.g. it lacks a secure random number generator), or the runtime tests
  40 + detected a bug in this library.
  41 +
  42 +**Side-effects and performance:**
  43 +
  44 +None.
  45 +
  46 +**Cautions:**
  47 +
  48 +The ciphertext output by this method is decryptable by anyone with knowledge of
  49 +the key `$key`. It is the caller's responsibility to keep `$key` secret. Where
  50 +`$key` should be stored is up to the caller and depends on the threat model the
  51 +caller is designing their application under. If you are unsure where to store
  52 +`$key`, consult with a professional cryptographer to get help designing your
  53 +application.
  54 +
  55 +### File::decryptFile($inputFilename, $outputFilename, Key $key)
  56 +
  57 +**Description:**
  58 +
  59 +Decrypts a file using a secret key.
  60 +
  61 +**Parameters:**
  62 +
  63 +1. `$inputFilename` is the path to a file containing the ciphertext to decrypt.
  64 +2. `$outputFilename` is the path to save the decrypted plaintext file.
  65 +3. `$key` is an instance of `Key` containing the secret key for decryption.
  66 +
  67 +**Behavior:**
  68 +
  69 +Decrypts the contents of the input file, writing the result to the output file.
  70 +If the output file already exists, it is overwritten.
  71 +
  72 +**Return value:**
  73 +
  74 +Does not return a value.
  75 +
  76 +**Exceptions:**
  77 +
  78 +- `Defuse\Crypto\Exception\IOException` is thrown if there is an I/O error.
  79 +
  80 +- `Defuse\Crypto\Exception\EnvironmentIsBrokenException` is thrown either when
  81 + the platform the code is running on cannot safely perform encryption for some
  82 + reason (e.g. it lacks a secure random number generator), or the runtime tests
  83 + detected a bug in this library.
  84 +
  85 +- `Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException` is thrown if
  86 + the `$key` is not the correct key for the given ciphertext, or if the
  87 + ciphertext has been modified (possibly maliciously). There is no way to
  88 + distinguish between these two cases.
  89 +
  90 +**Side-effects and performance:**
  91 +
  92 +The input ciphertext is processed in two passes. The first pass verifies the
  93 +integrity and the second pass performs the actual decryption of the file and
  94 +writing to the output file. This is done in a streaming manner so that only
  95 +a small part of the file is ever loaded into memory at a time.
  96 +
  97 +**Cautions:**
  98 +
  99 +Be aware that when `Defuse\Crypto\WrongKeyOrModifiedCiphertextException` is
  100 +thrown, some partial plaintext data may have been written to the output. Any
  101 +plaintext data that is output is guaranteed to be a prefix of the original
  102 +plaintext (i.e. at worst it was truncated). This can only happen if an attacker
  103 +modifies the input between the first pass (integrity check) and the second pass
  104 +(decryption) over the file.
  105 +
  106 +It is impossible in principle to distinguish between the case where you attempt
  107 +to decrypt with the wrong key and the case where you attempt to decrypt
  108 +a modified (corrupted) ciphertext. It is up to the caller how to best deal with
  109 +this ambiguity, as it depends on the application this library is being used in.
  110 +If in doubt, consult with a professional cryptographer.
  111 +
  112 +### File::encryptFileWithPassword($inputFilename, $outputFilename, $password)
  113 +
  114 +**Description:**
  115 +
  116 +Encrypts a file with a password.
  117 +
  118 +**Parameters:**
  119 +
  120 +1. `$inputFilename` is the path to a file containing the plaintext to encrypt.
  121 +2. `$outputFilename` is the path to save the ciphertext file.
  122 +3. `$password` is the password used for decryption.
  123 +
  124 +**Behavior:**
  125 +
  126 +Encrypts the contents of the input file, writing the result to the output file.
  127 +If the output file already exists, it is overwritten.
  128 +
  129 +**Return value:**
  130 +
  131 +Does not return a value.
  132 +
  133 +**Exceptions:**
  134 +
  135 +- `Defuse\Crypto\Exception\IOException` is thrown if there is an I/O error.
  136 +
  137 +- `Defuse\Crypto\Exception\EnvironmentIsBrokenException` is thrown either when
  138 + the platform the code is running on cannot safely perform encryption for some
  139 + reason (e.g. it lacks a secure random number generator), or the runtime tests
  140 + detected a bug in this library.
  141 +
  142 +**Side-effects and performance:**
  143 +
  144 +This method is intentionally slow, using a lot of CPU resources for a fraction
  145 +of a second. It applies key stretching to the password in order to make password
  146 +guessing attacks more computationally expensive. If you need a faster way to
  147 +encrypt multiple ciphertexts under the same password, see the
  148 +`KeyProtectedByPassword` class.
  149 +
  150 +**Cautions:**
  151 +
  152 +PHP stack traces display (portions of) the arguments passed to methods on the
  153 +call stack. If an exception is thrown inside this call, and it is uncaught, the
  154 +value of `$password` may be leaked out to an attacker through the stack trace.
  155 +We recommend configuring PHP to never output stack traces (either displaying
  156 +them to the user or saving them to log files).
  157 +
  158 +### File::decryptFileWithPassword($inputFilename, $outputFilename, $password)
  159 +
  160 +**Description:**
  161 +
  162 +Decrypts a file with a password.
  163 +
  164 +**Parameters:**
  165 +
  166 +1. `$inputFilename` is the path to a file containing the ciphertext to decrypt.
  167 +2. `$outputFilename` is the path to save the decrypted plaintext file.
  168 +3. `$password` is the password used for decryption.
  169 +
  170 +**Behavior:**
  171 +
  172 +Decrypts the contents of the input file, writing the result to the output file.
  173 +If the output file already exists, it is overwritten.
  174 +
  175 +**Return value:**
  176 +
  177 +Does not return a value.
  178 +
  179 +**Exceptions:**
  180 +
  181 +- `Defuse\Crypto\Exception\IOException` is thrown if there is an I/O error.
  182 +
  183 +- `Defuse\Crypto\Exception\EnvironmentIsBrokenException` is thrown either when
  184 + the platform the code is running on cannot safely perform encryption for some
  185 + reason (e.g. it lacks a secure random number generator), or the runtime tests
  186 + detected a bug in this library.
  187 +
  188 +- `Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException` is thrown if
  189 + the `$password` is not the correct key for the given ciphertext, or if the
  190 + ciphertext has been modified (possibly maliciously). There is no way to
  191 + distinguish between these two cases.
  192 +
  193 +**Side-effects and performance:**
  194 +
  195 +This method is intentionally slow, using a lot of CPU resources for a fraction
  196 +of a second. It applies key stretching to the password in order to make password
  197 +guessing attacks more computationally expensive. If you need a faster way to
  198 +encrypt multiple ciphertexts under the same password, see the
  199 +`KeyProtectedByPassword` class.
  200 +
  201 +The input ciphertext is processed in two passes. The first pass verifies the
  202 +integrity and the second pass performs the actual decryption of the file and
  203 +writing to the output file. This is done in a streaming manner so that only
  204 +a small part of the file is ever loaded into memory at a time.
  205 +
  206 +**Cautions:**
  207 +
  208 +PHP stack traces display (portions of) the arguments passed to methods on the
  209 +call stack. If an exception is thrown inside this call, and it is uncaught, the
  210 +value of `$password` may be leaked out to an attacker through the stack trace.
  211 +We recommend configuring PHP to never output stack traces (either displaying
  212 +them to the user or saving them to log files).
  213 +
  214 +Be aware that when `Defuse\Crypto\WrongKeyOrModifiedCiphertextException` is
  215 +thrown, some partial plaintext data may have been written to the output. Any
  216 +plaintext data that is output is guaranteed to be a prefix of the original
  217 +plaintext (i.e. at worst it was truncated). This can only happen if an attacker
  218 +modifies the input between the first pass (integrity check) and the second pass
  219 +(decryption) over the file.
  220 +
  221 +It is impossible in principle to distinguish between the case where you attempt
  222 +to decrypt with the wrong password and the case where you attempt to decrypt
  223 +a modified (corrupted) ciphertext. It is up to the caller how to best deal with
  224 +this ambiguity, as it depends on the application this library is being used in.
  225 +If in doubt, consult with a professional cryptographer.
  226 +
  227 +### File::encryptResource($inputHandle, $outputHandle, Key $key)
  228 +
  229 +**Description:**
  230 +
  231 +Encrypts a resource (stream) with a secret key.
  232 +
  233 +**Parameters:**
  234 +
  235 +1. `$inputHandle` is a handle to a resource (like a file pointer) containing the
  236 + plaintext to encrypt.
  237 +2. `$outputHandle` is a handle to a resource (like a file pointer) that the
  238 + ciphertext will be written to.
  239 +3. `$key` is an instance of `Key` containing the secret key for encryption.
  240 +
  241 +**Behavior:**
  242 +
  243 +Encrypts the data read from the input stream and writes it to the output stream.
  244 +
  245 +**Return value:**
  246 +
  247 +Does not return a value.
  248 +
  249 +**Exceptions:**
  250 +
  251 +- `Defuse\Crypto\Exception\IOException` is thrown if there is an I/O error.
  252 +
  253 +- `Defuse\Crypto\Exception\EnvironmentIsBrokenException` is thrown either when
  254 + the platform the code is running on cannot safely perform encryption for some
  255 + reason (e.g. it lacks a secure random number generator), or the runtime tests
  256 + detected a bug in this library.
  257 +
  258 +**Side-effects and performance:**
  259 +
  260 +None.
  261 +
  262 +**Cautions:**
  263 +
  264 +The ciphertext output by this method is decryptable by anyone with knowledge of
  265 +the key `$key`. It is the caller's responsibility to keep `$key` secret. Where
  266 +`$key` should be stored is up to the caller and depends on the threat model the
  267 +caller is designing their application under. If you are unsure where to store
  268 +`$key`, consult with a professional cryptographer to get help designing your
  269 +application.
  270 +
  271 +### File::decryptResource($inputHandle, $outputHandle, Key $key)
  272 +
  273 +**Description:**
  274 +
  275 +Decrypts a resource (stream) with a secret key.
  276 +
  277 +**Parameters:**
  278 +
  279 +1. `$inputHandle` is a handle to a file-backed resource containing the
  280 + ciphertext to decrypt. It must be a file not a network stream or standard
  281 + input.
  282 +2. `$outputHandle` is a handle to a resource (like a file pointer) that the
  283 + plaintext will be written to.
  284 +3. `$key` is an instance of `Key` containing the secret key for decryption.
  285 +
  286 +**Behavior:**
  287 +
  288 +Decrypts the data read from the input stream and writes it to the output stream.
  289 +
  290 +**Return value:**
  291 +
  292 +Does not return a value.
  293 +
  294 +**Exceptions:**
  295 +
  296 +- `Defuse\Crypto\Exception\IOException` is thrown if there is an I/O error.
  297 +
  298 +- `Defuse\Crypto\Exception\EnvironmentIsBrokenException` is thrown either when
  299 + the platform the code is running on cannot safely perform encryption for some
  300 + reason (e.g. it lacks a secure random number generator), or the runtime tests
  301 + detected a bug in this library.
  302 +
  303 +- `Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException` is thrown if
  304 + the `$key` is not the correct key for the given ciphertext, or if the
  305 + ciphertext has been modified (possibly maliciously). There is no way to
  306 + distinguish between these two cases.
  307 +
  308 +**Side-effects and performance:**
  309 +
  310 +The input ciphertext is processed in two passes. The first pass verifies the
  311 +integrity and the second pass performs the actual decryption of the file and
  312 +writing to the output file. This is done in a streaming manner so that only
  313 +a small part of the file is ever loaded into memory at a time.
  314 +
  315 +**Cautions:**
  316 +
  317 +Be aware that when `Defuse\Crypto\WrongKeyOrModifiedCiphertextException` is
  318 +thrown, some partial plaintext data may have been written to the output. Any
  319 +plaintext data that is output is guaranteed to be a prefix of the original
  320 +plaintext (i.e. at worst it was truncated). This can only happen if an attacker
  321 +modifies the input between the first pass (integrity check) and the second pass
  322 +(decryption) over the file.
  323 +
  324 +It is impossible in principle to distinguish between the case where you attempt
  325 +to decrypt with the wrong key and the case where you attempt to decrypt
  326 +a modified (corrupted) ciphertext. It is up to the caller how to best deal with
  327 +this ambiguity, as it depends on the application this library is being used in.
  328 +If in doubt, consult with a professional cryptographer.
  329 +
  330 +### File::encryptResourceWithPassword($inputHandle, $outputHandle, $password)
  331 +
  332 +**Description:**
  333 +
  334 +Encrypts a resource (stream) with a password.
  335 +
  336 +**Parameters:**
  337 +
  338 +1. `$inputHandle` is a handle to a resource (like a file pointer) containing the
  339 + plaintext to encrypt.
  340 +2. `$outputHandle` is a handle to a resource (like a file pointer) that the
  341 + ciphertext will be written to.
  342 +3. `$password` is the password used for encryption.
  343 +
  344 +**Behavior:**
  345 +
  346 +Encrypts the data read from the input stream and writes it to the output stream.
  347 +
  348 +**Return value:**
  349 +
  350 +Does not return a value.
  351 +
  352 +**Exceptions:**
  353 +
  354 +- `Defuse\Crypto\Exception\IOException` is thrown if there is an I/O error.
  355 +
  356 +- `Defuse\Crypto\Exception\EnvironmentIsBrokenException` is thrown either when
  357 + the platform the code is running on cannot safely perform encryption for some
  358 + reason (e.g. it lacks a secure random number generator), or the runtime tests
  359 + detected a bug in this library.
  360 +
  361 +**Side-effects and performance:**
  362 +
  363 +This method is intentionally slow, using a lot of CPU resources for a fraction
  364 +of a second. It applies key stretching to the password in order to make password
  365 +guessing attacks more computationally expensive. If you need a faster way to
  366 +encrypt multiple ciphertexts under the same password, see the
  367 +`KeyProtectedByPassword` class.
  368 +
  369 +**Cautions:**
  370 +
  371 +PHP stack traces display (portions of) the arguments passed to methods on the
  372 +call stack. If an exception is thrown inside this call, and it is uncaught, the
  373 +value of `$password` may be leaked out to an attacker through the stack trace.
  374 +We recommend configuring PHP to never output stack traces (either displaying
  375 +them to the user or saving them to log files).
  376 +
  377 +### File::decryptResourceWithPassword($inputHandle, $outputHandle, $password)
  378 +
  379 +**Description:**
  380 +
  381 +Decrypts a resource (stream) with a password.
  382 +
  383 +**Parameters:**
  384 +
  385 +1. `$inputHandle` is a handle to a file-backed resource containing the
  386 + ciphertext to decrypt. It must be a file not a network stream or standard
  387 + input.
  388 +2. `$outputHandle` is a handle to a resource (like a file pointer) that the
  389 + plaintext will be written to.
  390 +3. `$password` is the password used for decryption.
  391 +
  392 +**Behavior:**
  393 +
  394 +Decrypts the data read from the input stream and writes it to the output stream.
  395 +
  396 +**Return value:**
  397 +
  398 +Does not return a value.
  399 +
  400 +**Exceptions:**
  401 +
  402 +- `Defuse\Crypto\Exception\IOException` is thrown if there is an I/O error.
  403 +
  404 +- `Defuse\Crypto\Exception\EnvironmentIsBrokenException` is thrown either when
  405 + the platform the code is running on cannot safely perform encryption for some
  406 + reason (e.g. it lacks a secure random number generator), or the runtime tests
  407 + detected a bug in this library.
  408 +
  409 +- `Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException` is thrown if
  410 + the `$password` is not the correct key for the given ciphertext, or if the
  411 + ciphertext has been modified (possibly maliciously). There is no way to
  412 + distinguish between these two cases.
  413 +
  414 +**Side-effects and performance:**
  415 +
  416 +This method is intentionally slow, using a lot of CPU resources for a fraction
  417 +of a second. It applies key stretching to the password in order to make password
  418 +guessing attacks more computationally expensive. If you need a faster way to
  419 +encrypt multiple ciphertexts under the same password, see the
  420 +`KeyProtectedByPassword` class.
  421 +
  422 +The input ciphertext is processed in two passes. The first pass verifies the
  423 +integrity and the second pass performs the actual decryption of the file and
  424 +writing to the output file. This is done in a streaming manner so that only
  425 +a small part of the file is ever loaded into memory at a time.
  426 +
  427 +**Cautions:**
  428 +
  429 +PHP stack traces display (portions of) the arguments passed to methods on the
  430 +call stack. If an exception is thrown inside this call, and it is uncaught, the
  431 +value of `$password` may be leaked out to an attacker through the stack trace.
  432 +We recommend configuring PHP to never output stack traces (either displaying
  433 +them to the user or saving them to log files).
  434 +
  435 +Be aware that when `Defuse\Crypto\WrongKeyOrModifiedCiphertextException` is
  436 +thrown, some partial plaintext data may have been written to the output. Any
  437 +plaintext data that is output is guaranteed to be a prefix of the original
  438 +plaintext (i.e. at worst it was truncated). This can only happen if an attacker
  439 +modifies the input between the first pass (integrity check) and the second pass
  440 +(decryption) over the file.
  441 +
  442 +It is impossible in principle to distinguish between the case where you attempt
  443 +to decrypt with the wrong password and the case where you attempt to decrypt
  444 +a modified (corrupted) ciphertext. It is up to the caller how to best deal with
  445 +this ambiguity, as it depends on the application this library is being used in.
  446 +If in doubt, consult with a professional cryptographer.
... ...
pacotes/composer/vendor/defuse/php-encryption/docs/classes/Key.md 0 → 100644
... ... @@ -0,0 +1,117 @@
  1 +Class: Defuse\Crypto\Key
  2 +=========================
  3 +
  4 +The `Key` class represents a secret key used for encrypting and decrypting. Once
  5 +you have a `Key` instance, you can use it with the `Crypto` class to encrypt and
  6 +decrypt strings and with the `File` class to encrypt and decrypt files.
  7 +
  8 +Instance Methods
  9 +-----------------
  10 +
  11 +### saveToAsciiSafeString()
  12 +
  13 +**Description:**
  14 +
  15 +Saves the encryption key to a string of printable ASCII characters, which can be
  16 +loaded again into a `Key` instance using `Key::loadFromAsciiSafeString()`.
  17 +
  18 +**Parameters:**
  19 +
  20 +This method does not take any parameters.
  21 +
  22 +**Return value:**
  23 +
  24 +Returns a string of printable ASCII characters representing this `Key` instance,
  25 +which can be loaded back into an instance of `Key` using
  26 +`Key::loadFromAsciiSafeString()`.
  27 +
  28 +**Exceptions:**
  29 +
  30 +- `Defuse\Crypto\Exception\EnvironmentIsBrokenException` is thrown either when
  31 + the platform the code is running on cannot safely perform encryption for some
  32 + reason (e.g. it lacks a secure random number generator), or the runtime tests
  33 + detected a bug in this library.
  34 +
  35 +**Side-effects and performance:**
  36 +
  37 +None.
  38 +
  39 +**Cautions:**
  40 +
  41 +This method currently returns a hexadecimal string. You should not rely on this
  42 +behavior. For example, it may be improved in the future to return a base64
  43 +string.
  44 +
  45 +Static Methods
  46 +---------------
  47 +
  48 +### Key::createNewRandomKey()
  49 +
  50 +**Description:**
  51 +
  52 +Generates a new random key and returns an instance of `Key`.
  53 +
  54 +**Parameters:**
  55 +
  56 +This method does not take any parameters.
  57 +
  58 +**Return value:**
  59 +
  60 +Returns an instance of `Key` containing a randomly-generated encryption key.
  61 +
  62 +**Exceptions:**
  63 +
  64 +- `Defuse\Crypto\Exception\EnvironmentIsBrokenException` is thrown either when
  65 + the platform the code is running on cannot safely perform encryption for some
  66 + reason (e.g. it lacks a secure random number generator), or the runtime tests
  67 + detected a bug in this library.
  68 +
  69 +**Side-effects and performance:**
  70 +
  71 +None.
  72 +
  73 +**Cautions:**
  74 +
  75 +None.
  76 +
  77 +### Key::loadFromAsciiSafeString($saved\_key\_string, $do\_not\_trim = false)
  78 +
  79 +**Description:**
  80 +
  81 +Loads an instance of `Key` that was saved to a string by
  82 +`saveToAsciiSafeString()`.
  83 +
  84 +By default, this function will call `Encoding::trimTrailingWhitespace()`
  85 +to remove trailing CR, LF, NUL, TAB, and SPACE characters, which are commonly
  86 +appended to files when working with text editors.
  87 +
  88 +**Parameters:**
  89 +
  90 +1. `$saved_key_string` is the string returned from `saveToAsciiSafeString()`
  91 + when the original `Key` instance was saved.
  92 +2. `$do_not_trim` should be set to `TRUE` if you do not wish for the library
  93 + to automatically strip trailing whitespace from the string.
  94 +
  95 +**Return value:**
  96 +
  97 +Returns an instance of `Key` representing the same encryption key as the one
  98 +that was represented by the `Key` instance that got saved into
  99 +`$saved_key_string` by a call to `saveToAsciiSafeString()`.
  100 +
  101 +**Exceptions:**
  102 +
  103 +- `Defuse\Crypto\Exception\EnvironmentIsBrokenException` is thrown either when
  104 + the platform the code is running on cannot safely perform encryption for some
  105 + reason (e.g. it lacks a secure random number generator), or the runtime tests
  106 + detected a bug in this library.
  107 +
  108 +- `Defuse\Crypto\Exception\BadFormatException` is thrown whenever
  109 + `$saved_key_string` does not represent a valid `Key` instance.
  110 +
  111 +**Side-effects and performance:**
  112 +
  113 +None.
  114 +
  115 +**Cautions:**
  116 +
  117 +None.
... ...
pacotes/composer/vendor/defuse/php-encryption/docs/classes/KeyProtectedByPassword.md 0 → 100644
... ... @@ -0,0 +1,191 @@
  1 +Class: Defuse\Crypto\KeyProtectedByPassword
  2 +============================================
  3 +
  4 +The `KeyProtectedByPassword` class represents a key that is "locked" with
  5 +a password. In order to obtain an instance of `Key` that you can use for
  6 +encrypting and decrypting, a `KeyProtectedByPassword` must first be "unlocked"
  7 +by providing the correct password.
  8 +
  9 +`KeyProtectedByPassword` provides an alternative to using the
  10 +`encryptWithPassword()`, `decryptWithPassword()`, `encryptFileWithPassword()`,
  11 +and `decryptFileWithPassword()` methods with several advantages:
  12 +
  13 +- The slow and computationally-expensive key stretching is run only once when
  14 + you unlock a `KeyProtectedByPassword` to obtain the `Key`.
  15 +- You do not have to keep the original password in memory to encrypt and decrypt
  16 + things. After you've obtained the `Key` from a `KeyProtectedByPassword`, the
  17 + password is no longer necessary.
  18 +
  19 +Instance Methods
  20 +-----------------
  21 +
  22 +### saveToAsciiSafeString()
  23 +
  24 +**Description:**
  25 +
  26 +Saves the protected key to a string of printable ASCII characters, which can be
  27 +loaded again into a `KeyProtectedByPassword` instance using
  28 +`KeyProtectedByPassword::loadFromAsciiSafeString()`.
  29 +
  30 +**Parameters:**
  31 +
  32 +This method does not take any parameters.
  33 +
  34 +**Return value:**
  35 +
  36 +Returns a string of printable ASCII characters representing this
  37 +`KeyProtectedByPassword` instance, which can be loaded back into an instance of
  38 +`KeyProtectedByPassword` using
  39 +`KeyProtectedByPassword::loadFromAsciiSafeString()`.
  40 +
  41 +**Exceptions:**
  42 +
  43 +- `Defuse\Crypto\Exception\EnvironmentIsBrokenException` is thrown either when
  44 + the platform the code is running on cannot safely perform encryption for some
  45 + reason (e.g. it lacks a secure random number generator), or the runtime tests
  46 + detected a bug in this library.
  47 +
  48 +**Side-effects and performance:**
  49 +
  50 +None.
  51 +
  52 +**Cautions:**
  53 +
  54 +This method currently returns a hexadecimal string. You should not rely on this
  55 +behavior. For example, it may be improved in the future to return a base64
  56 +string.
  57 +
  58 +### unlockKey($password)
  59 +
  60 +**Description:**
  61 +
  62 +Unlocks the password-protected key, obtaining a `Key` which can be used for
  63 +encryption and decryption.
  64 +
  65 +**Parameters:**
  66 +
  67 +1. `$password` is the password required to unlock this `KeyProtectedByPassword`
  68 + to obtain the `Key`.
  69 +
  70 +**Return value:**
  71 +
  72 +If `$password` is the correct password, then this method returns an instance of
  73 +the `Key` class.
  74 +
  75 +**Exceptions:**
  76 +
  77 +- `Defuse\Crypto\Exception\EnvironmentIsBrokenException` is thrown either when
  78 + the platform the code is running on cannot safely perform encryption for some
  79 + reason (e.g. it lacks a secure random number generator), or the runtime tests
  80 + detected a bug in this library.
  81 +
  82 +- `Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException` is thrown if
  83 + either the given `$password` is not the correct password for this
  84 + `KeyProtectedByPassword` or the ciphertext stored internally by this object
  85 + has been modified, i.e. it was accidentally corrupted or intentionally
  86 + corrupted by an attacker. There is no way for the caller to distinguish
  87 + between these two cases.
  88 +
  89 +**Side-effects and performance:**
  90 +
  91 +This method runs a small and very fast set of self-tests if it is the very first
  92 +time this method or one of the `Crypto` methods has been called. The performance
  93 +overhead is negligible and can be safely ignored in all applications.
  94 +
  95 +**Cautions:**
  96 +
  97 +PHP stack traces display (portions of) the arguments passed to methods on the
  98 +call stack. If an exception is thrown inside this call, and it is uncaught, the
  99 +value of `$password` may be leaked out to an attacker through the stack trace.
  100 +We recommend configuring PHP to never output stack traces (either displaying
  101 +them to the user or saving them to log files).
  102 +
  103 +It is impossible in principle to distinguish between the case where you attempt
  104 +to unlock with the wrong password and the case where you attempt to unlock
  105 +a modified (corrupted) `KeyProtectedByPassword. It is up to the caller how to
  106 +best deal with this ambiguity, as it depends on the application this library is
  107 +being used in. If in doubt, consult with a professional cryptographer.
  108 +
  109 +Static Methods
  110 +---------------
  111 +
  112 +### KeyProtectedByPassword::createRandomPasswordProtectedKey($password)
  113 +
  114 +**Description:**
  115 +
  116 +Generates a new random key that's protected by the string `$password` and
  117 +returns an instance of `KeyProtectedByPassword`.
  118 +
  119 +**Parameters:**
  120 +
  121 +1. `$password` is the password used to protect the random key.
  122 +
  123 +**Return value:**
  124 +
  125 +Returns an instance of `KeyProtectedByPassword` containing a randomly-generated
  126 +encryption key that's protected by the password `$password`.
  127 +
  128 +**Exceptions:**
  129 +
  130 +- `Defuse\Crypto\Exception\EnvironmentIsBrokenException` is thrown either when
  131 + the platform the code is running on cannot safely perform encryption for some
  132 + reason (e.g. it lacks a secure random number generator), or the runtime tests
  133 + detected a bug in this library.
  134 +
  135 +**Side-effects and performance:**
  136 +
  137 +This method runs a small and very fast set of self-tests if it is the very first
  138 +time this method or one of the `Crypto` methods has been called. The performance
  139 +overhead is negligible and can be safely ignored in all applications.
  140 +
  141 +**Cautions:**
  142 +
  143 +PHP stack traces display (portions of) the arguments passed to methods on the
  144 +call stack. If an exception is thrown inside this call, and it is uncaught, the
  145 +value of `$password` may be leaked out to an attacker through the stack trace.
  146 +We recommend configuring PHP to never output stack traces (either displaying
  147 +them to the user or saving them to log files).
  148 +
  149 +Be aware that if you protecting multiple keys with the same password, an
  150 +attacker with write access to your system will be able to swap the protected
  151 +keys around so that the wrong key gets used next time it is unlocked. This could
  152 +lead to data being encrypted with the wrong key, perhaps one that the attacker
  153 +knows.
  154 +
  155 +### KeyProtectedByPassword::loadFromAsciiSafeString($saved\_key\_string)
  156 +
  157 +**Description:**
  158 +
  159 +Loads an instance of `KeyProtectedByPassword` that was saved to a string by
  160 +`saveToAsciiSafeString()`.
  161 +
  162 +**Parameters:**
  163 +
  164 +1. `$saved_key_string` is the string returned from `saveToAsciiSafeString()`
  165 + when the original `KeyProtectedByPassword` instance was saved.
  166 +
  167 +**Return value:**
  168 +
  169 +Returns an instance of `KeyProtectedByPassword` representing the same
  170 +password-protected key as the one that was represented by the
  171 +`KeyProtectedByPassword` instance that got saved into `$saved_key_string` by
  172 +a call to `saveToAsciiSafeString()`.
  173 +
  174 +**Exceptions:**
  175 +
  176 +- `Defuse\Crypto\Exception\EnvironmentIsBrokenException` is thrown either when
  177 + the platform the code is running on cannot safely perform encryption for some
  178 + reason (e.g. it lacks a secure random number generator), or the runtime tests
  179 + detected a bug in this library.
  180 +
  181 +- `Defuse\Crypto\Exception\BadFormatException` is thrown whenever
  182 + `$saved_key_string` does not represent a valid `KeyProtectedByPassword`
  183 + instance.
  184 +
  185 +**Side-effects and performance:**
  186 +
  187 +None.
  188 +
  189 +**Cautions:**
  190 +
  191 +None.
... ...
pacotes/composer/vendor/defuse/php-encryption/psalm.xml 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +<?xml version="1.0"?>
  2 +<psalm
  3 + stopOnFirstError="false"
  4 + useDocblockTypes="true"
  5 +>
  6 + <projectFiles>
  7 + <directory name="src" />
  8 + </projectFiles>
  9 +</psalm>
... ...
pacotes/composer/vendor/defuse/php-encryption/src/Core.php 0 → 100644
... ... @@ -0,0 +1,446 @@
  1 +<?php
  2 +
  3 +namespace Defuse\Crypto;
  4 +
  5 +use Defuse\Crypto\Exception as Ex;
  6 +
  7 +final class Core
  8 +{
  9 + const HEADER_VERSION_SIZE = 4;
  10 + const MINIMUM_CIPHERTEXT_SIZE = 84;
  11 +
  12 + const CURRENT_VERSION = "\xDE\xF5\x02\x00";
  13 +
  14 + const CIPHER_METHOD = 'aes-256-ctr';
  15 + const BLOCK_BYTE_SIZE = 16;
  16 + const KEY_BYTE_SIZE = 32;
  17 + const SALT_BYTE_SIZE = 32;
  18 + const MAC_BYTE_SIZE = 32;
  19 + const HASH_FUNCTION_NAME = 'sha256';
  20 + const ENCRYPTION_INFO_STRING = 'DefusePHP|V2|KeyForEncryption';
  21 + const AUTHENTICATION_INFO_STRING = 'DefusePHP|V2|KeyForAuthentication';
  22 + const BUFFER_BYTE_SIZE = 1048576;
  23 +
  24 + const LEGACY_CIPHER_METHOD = 'aes-128-cbc';
  25 + const LEGACY_BLOCK_BYTE_SIZE = 16;
  26 + const LEGACY_KEY_BYTE_SIZE = 16;
  27 + const LEGACY_HASH_FUNCTION_NAME = 'sha256';
  28 + const LEGACY_MAC_BYTE_SIZE = 32;
  29 + const LEGACY_ENCRYPTION_INFO_STRING = 'DefusePHP|KeyForEncryption';
  30 + const LEGACY_AUTHENTICATION_INFO_STRING = 'DefusePHP|KeyForAuthentication';
  31 +
  32 + /*
  33 + * V2.0 Format: VERSION (4 bytes) || SALT (32 bytes) || IV (16 bytes) ||
  34 + * CIPHERTEXT (varies) || HMAC (32 bytes)
  35 + *
  36 + * V1.0 Format: HMAC (32 bytes) || IV (16 bytes) || CIPHERTEXT (varies).
  37 + */
  38 +
  39 + /**
  40 + * Adds an integer to a block-sized counter.
  41 + *
  42 + * @param string $ctr
  43 + * @param int $inc
  44 + *
  45 + * @throws Ex\EnvironmentIsBrokenException
  46 + *
  47 + * @return string
  48 + */
  49 + public static function incrementCounter($ctr, $inc)
  50 + {
  51 + if (Core::ourStrlen($ctr) !== Core::BLOCK_BYTE_SIZE) {
  52 + throw new Ex\EnvironmentIsBrokenException(
  53 + 'Trying to increment a nonce of the wrong size.'
  54 + );
  55 + }
  56 +
  57 + if (! \is_int($inc)) {
  58 + throw new Ex\EnvironmentIsBrokenException(
  59 + 'Trying to increment nonce by a non-integer.'
  60 + );
  61 + }
  62 +
  63 + if ($inc < 0) {
  64 + throw new Ex\EnvironmentIsBrokenException(
  65 + 'Trying to increment nonce by a negative amount.'
  66 + );
  67 + }
  68 +
  69 + if ($inc > PHP_INT_MAX - 255) {
  70 + throw new Ex\EnvironmentIsBrokenException(
  71 + 'Integer overflow may occur.'
  72 + );
  73 + }
  74 +
  75 + /*
  76 + * We start at the rightmost byte (big-endian)
  77 + * So, too, does OpenSSL: http://stackoverflow.com/a/3146214/2224584
  78 + */
  79 + for ($i = Core::BLOCK_BYTE_SIZE - 1; $i >= 0; --$i) {
  80 + $sum = \ord($ctr[$i]) + $inc;
  81 +
  82 + /* Detect integer overflow and fail. */
  83 + if (! \is_int($sum)) {
  84 + throw new Ex\EnvironmentIsBrokenException(
  85 + 'Integer overflow in CTR mode nonce increment.'
  86 + );
  87 + }
  88 +
  89 + $ctr[$i] = \pack('C', $sum & 0xFF);
  90 + $inc = $sum >> 8;
  91 + }
  92 + return $ctr;
  93 + }
  94 +
  95 + /**
  96 + * Returns a random byte string of the specified length.
  97 + *
  98 + * @param int $octets
  99 + *
  100 + * @throws Ex\EnvironmentIsBrokenException
  101 + *
  102 + * @return string
  103 + */
  104 + public static function secureRandom($octets)
  105 + {
  106 + self::ensureFunctionExists('random_bytes');
  107 + try {
  108 + return \random_bytes($octets);
  109 + } catch (\Exception $ex) {
  110 + throw new Ex\EnvironmentIsBrokenException(
  111 + 'Your system does not have a secure random number generator.'
  112 + );
  113 + }
  114 + }
  115 +
  116 + /**
  117 + * Computes the HKDF key derivation function specified in
  118 + * http://tools.ietf.org/html/rfc5869.
  119 + *
  120 + * @param string $hash Hash Function
  121 + * @param string $ikm Initial Keying Material
  122 + * @param int $length How many bytes?
  123 + * @param string $info What sort of key are we deriving?
  124 + * @param string $salt
  125 + *
  126 + * @throws Ex\EnvironmentIsBrokenException
  127 + * @psalm-suppress UndefinedFunction - We're checking if the function exists first.
  128 + *
  129 + * @return string
  130 + */
  131 + public static function HKDF($hash, $ikm, $length, $info = '', $salt = null)
  132 + {
  133 + static $nativeHKDF = null;
  134 + if ($nativeHKDF === null) {
  135 + $nativeHKDF = \is_callable('\\hash_hkdf');
  136 + }
  137 + if ($nativeHKDF) {
  138 + return \hash_hkdf($hash, $ikm, $length, $info, $salt);
  139 + }
  140 +
  141 + $digest_length = Core::ourStrlen(\hash_hmac($hash, '', '', true));
  142 +
  143 + // Sanity-check the desired output length.
  144 + if (empty($length) || ! \is_int($length) ||
  145 + $length < 0 || $length > 255 * $digest_length) {
  146 + throw new Ex\EnvironmentIsBrokenException(
  147 + 'Bad output length requested of HKDF.'
  148 + );
  149 + }
  150 +
  151 + // "if [salt] not provided, is set to a string of HashLen zeroes."
  152 + if (\is_null($salt)) {
  153 + $salt = \str_repeat("\x00", $digest_length);
  154 + }
  155 +
  156 + // HKDF-Extract:
  157 + // PRK = HMAC-Hash(salt, IKM)
  158 + // The salt is the HMAC key.
  159 + $prk = \hash_hmac($hash, $ikm, $salt, true);
  160 +
  161 + // HKDF-Expand:
  162 +
  163 + // This check is useless, but it serves as a reminder to the spec.
  164 + if (Core::ourStrlen($prk) < $digest_length) {
  165 + throw new Ex\EnvironmentIsBrokenException();
  166 + }
  167 +
  168 + // T(0) = ''
  169 + $t = '';
  170 + $last_block = '';
  171 + for ($block_index = 1; Core::ourStrlen($t) < $length; ++$block_index) {
  172 + // T(i) = HMAC-Hash(PRK, T(i-1) | info | 0x??)
  173 + $last_block = \hash_hmac(
  174 + $hash,
  175 + $last_block . $info . \chr($block_index),
  176 + $prk,
  177 + true
  178 + );
  179 + // T = T(1) | T(2) | T(3) | ... | T(N)
  180 + $t .= $last_block;
  181 + }
  182 +
  183 + // ORM = first L octets of T
  184 + /** @var string $orm */
  185 + $orm = Core::ourSubstr($t, 0, $length);
  186 + if (!\is_string($orm)) {
  187 + throw new Ex\EnvironmentIsBrokenException();
  188 + }
  189 + return $orm;
  190 + }
  191 +
  192 + /**
  193 + * Checks if two equal-length strings are the same without leaking
  194 + * information through side channels.
  195 + *
  196 + * @param string $expected
  197 + * @param string $given
  198 + *
  199 + * @throws Ex\EnvironmentIsBrokenException
  200 + *
  201 + * @return bool
  202 + */
  203 + public static function hashEquals($expected, $given)
  204 + {
  205 + static $native = null;
  206 + if ($native === null) {
  207 + $native = \function_exists('hash_equals');
  208 + }
  209 + if ($native) {
  210 + return \hash_equals($expected, $given);
  211 + }
  212 +
  213 + // We can't just compare the strings with '==', since it would make
  214 + // timing attacks possible. We could use the XOR-OR constant-time
  215 + // comparison algorithm, but that may not be a reliable defense in an
  216 + // interpreted language. So we use the approach of HMACing both strings
  217 + // with a random key and comparing the HMACs.
  218 +
  219 + // We're not attempting to make variable-length string comparison
  220 + // secure, as that's very difficult. Make sure the strings are the same
  221 + // length.
  222 + if (Core::ourStrlen($expected) !== Core::ourStrlen($given)) {
  223 + throw new Ex\EnvironmentIsBrokenException();
  224 + }
  225 +
  226 + $blind = Core::secureRandom(32);
  227 + $message_compare = \hash_hmac(Core::HASH_FUNCTION_NAME, $given, $blind);
  228 + $correct_compare = \hash_hmac(Core::HASH_FUNCTION_NAME, $expected, $blind);
  229 + return $correct_compare === $message_compare;
  230 + }
  231 + /**
  232 + * Throws an exception if the constant doesn't exist.
  233 + *
  234 + * @param string $name
  235 + * @return void
  236 + *
  237 + * @throws Ex\EnvironmentIsBrokenException
  238 + */
  239 + public static function ensureConstantExists($name)
  240 + {
  241 + if (! \defined($name)) {
  242 + throw new Ex\EnvironmentIsBrokenException();
  243 + }
  244 + }
  245 +
  246 + /**
  247 + * Throws an exception if the function doesn't exist.
  248 + *
  249 + * @param string $name
  250 + * @return void
  251 + *
  252 + * @throws Ex\EnvironmentIsBrokenException
  253 + */
  254 + public static function ensureFunctionExists($name)
  255 + {
  256 + if (! \function_exists($name)) {
  257 + throw new Ex\EnvironmentIsBrokenException();
  258 + }
  259 + }
  260 +
  261 + /*
  262 + * We need these strlen() and substr() functions because when
  263 + * 'mbstring.func_overload' is set in php.ini, the standard strlen() and
  264 + * substr() are replaced by mb_strlen() and mb_substr().
  265 + */
  266 +
  267 + /**
  268 + * Computes the length of a string in bytes.
  269 + *
  270 + * @param string $str
  271 + *
  272 + * @throws Ex\EnvironmentIsBrokenException
  273 + *
  274 + * @return int
  275 + */
  276 + public static function ourStrlen($str)
  277 + {
  278 + static $exists = null;
  279 + if ($exists === null) {
  280 + $exists = \function_exists('mb_strlen');
  281 + }
  282 + if ($exists) {
  283 + $length = \mb_strlen($str, '8bit');
  284 + if ($length === false) {
  285 + throw new Ex\EnvironmentIsBrokenException();
  286 + }
  287 + return $length;
  288 + } else {
  289 + return \strlen($str);
  290 + }
  291 + }
  292 +
  293 + /**
  294 + * Behaves roughly like the function substr() in PHP 7 does.
  295 + *
  296 + * @param string $str
  297 + * @param int $start
  298 + * @param int $length
  299 + *
  300 + * @throws Ex\EnvironmentIsBrokenException
  301 + *
  302 + * @return string|bool
  303 + */
  304 + public static function ourSubstr($str, $start, $length = null)
  305 + {
  306 + static $exists = null;
  307 + if ($exists === null) {
  308 + $exists = \function_exists('mb_substr');
  309 + }
  310 +
  311 + if ($exists) {
  312 + // mb_substr($str, 0, NULL, '8bit') returns an empty string on PHP
  313 + // 5.3, so we have to find the length ourselves.
  314 + if (! isset($length)) {
  315 + if ($start >= 0) {
  316 + $length = Core::ourStrlen($str) - $start;
  317 + } else {
  318 + $length = -$start;
  319 + }
  320 + }
  321 +
  322 + // This is required to make mb_substr behavior identical to substr.
  323 + // Without this, mb_substr() would return false, contra to what the
  324 + // PHP documentation says (it doesn't say it can return false.)
  325 + if ($start === Core::ourStrlen($str) && $length === 0) {
  326 + return '';
  327 + }
  328 +
  329 + if ($start > Core::ourStrlen($str)) {
  330 + return false;
  331 + }
  332 +
  333 + $substr = \mb_substr($str, $start, $length, '8bit');
  334 + if (Core::ourStrlen($substr) !== $length) {
  335 + throw new Ex\EnvironmentIsBrokenException(
  336 + 'Your version of PHP has bug #66797. Its implementation of
  337 + mb_substr() is incorrect. See the details here:
  338 + https://bugs.php.net/bug.php?id=66797'
  339 + );
  340 + }
  341 + return $substr;
  342 + }
  343 +
  344 + // Unlike mb_substr(), substr() doesn't accept NULL for length
  345 + if (isset($length)) {
  346 + return \substr($str, $start, $length);
  347 + } else {
  348 + return \substr($str, $start);
  349 + }
  350 + }
  351 +
  352 + /**
  353 + * Computes the PBKDF2 password-based key derivation function.
  354 + *
  355 + * The PBKDF2 function is defined in RFC 2898. Test vectors can be found in
  356 + * RFC 6070. This implementation of PBKDF2 was originally created by Taylor
  357 + * Hornby, with improvements from http://www.variations-of-shadow.com/.
  358 + *
  359 + * @param string $algorithm The hash algorithm to use. Recommended: SHA256
  360 + * @param string $password The password.
  361 + * @param string $salt A salt that is unique to the password.
  362 + * @param int $count Iteration count. Higher is better, but slower. Recommended: At least 1000.
  363 + * @param int $key_length The length of the derived key in bytes.
  364 + * @param bool $raw_output If true, the key is returned in raw binary format. Hex encoded otherwise.
  365 + *
  366 + * @throws Ex\EnvironmentIsBrokenException
  367 + *
  368 + * @return string A $key_length-byte key derived from the password and salt.
  369 + */
  370 + public static function pbkdf2($algorithm, $password, $salt, $count, $key_length, $raw_output = false)
  371 + {
  372 + // Type checks:
  373 + if (! \is_string($algorithm)) {
  374 + throw new \InvalidArgumentException(
  375 + 'pbkdf2(): algorithm must be a string'
  376 + );
  377 + }
  378 + if (! \is_string($password)) {
  379 + throw new \InvalidArgumentException(
  380 + 'pbkdf2(): password must be a string'
  381 + );
  382 + }
  383 + if (! \is_string($salt)) {
  384 + throw new \InvalidArgumentException(
  385 + 'pbkdf2(): salt must be a string'
  386 + );
  387 + }
  388 + // Coerce strings to integers with no information loss or overflow
  389 + $count += 0;
  390 + $key_length += 0;
  391 +
  392 + $algorithm = \strtolower($algorithm);
  393 + if (! \in_array($algorithm, \hash_algos(), true)) {
  394 + throw new Ex\EnvironmentIsBrokenException(
  395 + 'Invalid or unsupported hash algorithm.'
  396 + );
  397 + }
  398 +
  399 + // Whitelist, or we could end up with people using CRC32.
  400 + $ok_algorithms = [
  401 + 'sha1', 'sha224', 'sha256', 'sha384', 'sha512',
  402 + 'ripemd160', 'ripemd256', 'ripemd320', 'whirlpool',
  403 + ];
  404 + if (! \in_array($algorithm, $ok_algorithms, true)) {
  405 + throw new Ex\EnvironmentIsBrokenException(
  406 + 'Algorithm is not a secure cryptographic hash function.'
  407 + );
  408 + }
  409 +
  410 + if ($count <= 0 || $key_length <= 0) {
  411 + throw new Ex\EnvironmentIsBrokenException(
  412 + 'Invalid PBKDF2 parameters.'
  413 + );
  414 + }
  415 +
  416 + if (\function_exists('hash_pbkdf2')) {
  417 + // The output length is in NIBBLES (4-bits) if $raw_output is false!
  418 + if (! $raw_output) {
  419 + $key_length = $key_length * 2;
  420 + }
  421 + return \hash_pbkdf2($algorithm, $password, $salt, $count, $key_length, $raw_output);
  422 + }
  423 +
  424 + $hash_length = Core::ourStrlen(\hash($algorithm, '', true));
  425 + $block_count = \ceil($key_length / $hash_length);
  426 +
  427 + $output = '';
  428 + for ($i = 1; $i <= $block_count; $i++) {
  429 + // $i encoded as 4 bytes, big endian.
  430 + $last = $salt . \pack('N', $i);
  431 + // first iteration
  432 + $last = $xorsum = \hash_hmac($algorithm, $last, $password, true);
  433 + // perform the other $count - 1 iterations
  434 + for ($j = 1; $j < $count; $j++) {
  435 + $xorsum ^= ($last = \hash_hmac($algorithm, $last, $password, true));
  436 + }
  437 + $output .= $xorsum;
  438 + }
  439 +
  440 + if ($raw_output) {
  441 + return (string) Core::ourSubstr($output, 0, $key_length);
  442 + } else {
  443 + return Encoding::binToHex((string) Core::ourSubstr($output, 0, $key_length));
  444 + }
  445 + }
  446 +}
... ...
pacotes/composer/vendor/defuse/php-encryption/src/Crypto.php 0 → 100644
... ... @@ -0,0 +1,393 @@
  1 +<?php
  2 +
  3 +namespace Defuse\Crypto;
  4 +
  5 +use Defuse\Crypto\Exception as Ex;
  6 +
  7 +class Crypto
  8 +{
  9 + /**
  10 + * Encrypts a string with a Key.
  11 + *
  12 + * @param string $plaintext
  13 + * @param Key $key
  14 + * @param bool $raw_binary
  15 + *
  16 + * @throws Ex\EnvironmentIsBrokenException
  17 + *
  18 + * @return string
  19 + */
  20 + public static function encrypt($plaintext, Key $key, $raw_binary = false)
  21 + {
  22 + return self::encryptInternal(
  23 + $plaintext,
  24 + KeyOrPassword::createFromKey($key),
  25 + $raw_binary
  26 + );
  27 + }
  28 +
  29 + /**
  30 + * Encrypts a string with a password, using a slow key derivation function
  31 + * to make password cracking more expensive.
  32 + *
  33 + * @param string $plaintext
  34 + * @param string $password
  35 + * @param bool $raw_binary
  36 + *
  37 + * @throws Ex\EnvironmentIsBrokenException
  38 + *
  39 + * @return string
  40 + */
  41 + public static function encryptWithPassword($plaintext, $password, $raw_binary = false)
  42 + {
  43 + return self::encryptInternal(
  44 + $plaintext,
  45 + KeyOrPassword::createFromPassword($password),
  46 + $raw_binary
  47 + );
  48 + }
  49 +
  50 + /**
  51 + * Decrypts a ciphertext to a string with a Key.
  52 + *
  53 + * @param string $ciphertext
  54 + * @param Key $key
  55 + * @param bool $raw_binary
  56 + *
  57 + * @throws Ex\EnvironmentIsBrokenException
  58 + * @throws Ex\WrongKeyOrModifiedCiphertextException
  59 + *
  60 + * @return string
  61 + */
  62 + public static function decrypt($ciphertext, Key $key, $raw_binary = false)
  63 + {
  64 + return self::decryptInternal(
  65 + $ciphertext,
  66 + KeyOrPassword::createFromKey($key),
  67 + $raw_binary
  68 + );
  69 + }
  70 +
  71 + /**
  72 + * Decrypts a ciphertext to a string with a password, using a slow key
  73 + * derivation function to make password cracking more expensive.
  74 + *
  75 + * @param string $ciphertext
  76 + * @param string $password
  77 + * @param bool $raw_binary
  78 + *
  79 + * @throws Ex\EnvironmentIsBrokenException
  80 + * @throws Ex\WrongKeyOrModifiedCiphertextException
  81 + *
  82 + * @return string
  83 + */
  84 + public static function decryptWithPassword($ciphertext, $password, $raw_binary = false)
  85 + {
  86 + return self::decryptInternal(
  87 + $ciphertext,
  88 + KeyOrPassword::createFromPassword($password),
  89 + $raw_binary
  90 + );
  91 + }
  92 +
  93 + /**
  94 + * Decrypts a legacy ciphertext produced by version 1 of this library.
  95 + *
  96 + * @param string $ciphertext
  97 + * @param string $key
  98 + *
  99 + * @throws Ex\EnvironmentIsBrokenException
  100 + * @throws Ex\WrongKeyOrModifiedCiphertextException
  101 + *
  102 + * @return string
  103 + */
  104 + public static function legacyDecrypt($ciphertext, $key)
  105 + {
  106 + RuntimeTests::runtimeTest();
  107 +
  108 + // Extract the HMAC from the front of the ciphertext.
  109 + if (Core::ourStrlen($ciphertext) <= Core::LEGACY_MAC_BYTE_SIZE) {
  110 + throw new Ex\WrongKeyOrModifiedCiphertextException(
  111 + 'Ciphertext is too short.'
  112 + );
  113 + }
  114 + /**
  115 + * @var string
  116 + */
  117 + $hmac = Core::ourSubstr($ciphertext, 0, Core::LEGACY_MAC_BYTE_SIZE);
  118 + if (!\is_string($hmac)) {
  119 + throw new Ex\EnvironmentIsBrokenException();
  120 + }
  121 + /**
  122 + * @var string
  123 + */
  124 + $ciphertext = Core::ourSubstr($ciphertext, Core::LEGACY_MAC_BYTE_SIZE);
  125 + if (!\is_string($ciphertext)) {
  126 + throw new Ex\EnvironmentIsBrokenException();
  127 + }
  128 +
  129 + // Regenerate the same authentication sub-key.
  130 + $akey = Core::HKDF(
  131 + Core::LEGACY_HASH_FUNCTION_NAME,
  132 + $key,
  133 + Core::LEGACY_KEY_BYTE_SIZE,
  134 + Core::LEGACY_AUTHENTICATION_INFO_STRING,
  135 + null
  136 + );
  137 +
  138 + if (self::verifyHMAC($hmac, $ciphertext, $akey)) {
  139 + // Regenerate the same encryption sub-key.
  140 + $ekey = Core::HKDF(
  141 + Core::LEGACY_HASH_FUNCTION_NAME,
  142 + $key,
  143 + Core::LEGACY_KEY_BYTE_SIZE,
  144 + Core::LEGACY_ENCRYPTION_INFO_STRING,
  145 + null
  146 + );
  147 +
  148 + // Extract the IV from the ciphertext.
  149 + if (Core::ourStrlen($ciphertext) <= Core::LEGACY_BLOCK_BYTE_SIZE) {
  150 + throw new Ex\WrongKeyOrModifiedCiphertextException(
  151 + 'Ciphertext is too short.'
  152 + );
  153 + }
  154 + /**
  155 + * @var string
  156 + */
  157 + $iv = Core::ourSubstr($ciphertext, 0, Core::LEGACY_BLOCK_BYTE_SIZE);
  158 + if (!\is_string($iv)) {
  159 + throw new Ex\EnvironmentIsBrokenException();
  160 + }
  161 +
  162 + /**
  163 + * @var string
  164 + */
  165 + $actualCiphertext = Core::ourSubstr($ciphertext, Core::LEGACY_BLOCK_BYTE_SIZE);
  166 + if (!\is_string($actualCiphertext)) {
  167 + throw new Ex\EnvironmentIsBrokenException();
  168 + }
  169 +
  170 + // Do the decryption.
  171 + $plaintext = self::plainDecrypt($actualCiphertext, $ekey, $iv, Core::LEGACY_CIPHER_METHOD);
  172 + return $plaintext;
  173 + } else {
  174 + throw new Ex\WrongKeyOrModifiedCiphertextException(
  175 + 'Integrity check failed.'
  176 + );
  177 + }
  178 + }
  179 +
  180 + /**
  181 + * Encrypts a string with either a key or a password.
  182 + *
  183 + * @param string $plaintext
  184 + * @param KeyOrPassword $secret
  185 + * @param bool $raw_binary
  186 + *
  187 + * @return string
  188 + */
  189 + private static function encryptInternal($plaintext, KeyOrPassword $secret, $raw_binary)
  190 + {
  191 + RuntimeTests::runtimeTest();
  192 +
  193 + $salt = Core::secureRandom(Core::SALT_BYTE_SIZE);
  194 + $keys = $secret->deriveKeys($salt);
  195 + $ekey = $keys->getEncryptionKey();
  196 + $akey = $keys->getAuthenticationKey();
  197 + $iv = Core::secureRandom(Core::BLOCK_BYTE_SIZE);
  198 +
  199 + $ciphertext = Core::CURRENT_VERSION . $salt . $iv . self::plainEncrypt($plaintext, $ekey, $iv);
  200 + $auth = \hash_hmac(Core::HASH_FUNCTION_NAME, $ciphertext, $akey, true);
  201 + $ciphertext = $ciphertext . $auth;
  202 +
  203 + if ($raw_binary) {
  204 + return $ciphertext;
  205 + }
  206 + return Encoding::binToHex($ciphertext);
  207 + }
  208 +
  209 + /**
  210 + * Decrypts a ciphertext to a string with either a key or a password.
  211 + *
  212 + * @param string $ciphertext
  213 + * @param KeyOrPassword $secret
  214 + * @param bool $raw_binary
  215 + *
  216 + * @throws Ex\EnvironmentIsBrokenException
  217 + * @throws Ex\WrongKeyOrModifiedCiphertextException
  218 + *
  219 + * @return string
  220 + */
  221 + private static function decryptInternal($ciphertext, KeyOrPassword $secret, $raw_binary)
  222 + {
  223 + RuntimeTests::runtimeTest();
  224 +
  225 + if (! $raw_binary) {
  226 + try {
  227 + $ciphertext = Encoding::hexToBin($ciphertext);
  228 + } catch (Ex\BadFormatException $ex) {
  229 + throw new Ex\WrongKeyOrModifiedCiphertextException(
  230 + 'Ciphertext has invalid hex encoding.'
  231 + );
  232 + }
  233 + }
  234 +
  235 + if (Core::ourStrlen($ciphertext) < Core::MINIMUM_CIPHERTEXT_SIZE) {
  236 + throw new Ex\WrongKeyOrModifiedCiphertextException(
  237 + 'Ciphertext is too short.'
  238 + );
  239 + }
  240 +
  241 + // Get and check the version header.
  242 + /** @var string $header */
  243 + $header = Core::ourSubstr($ciphertext, 0, Core::HEADER_VERSION_SIZE);
  244 + if ($header !== Core::CURRENT_VERSION) {
  245 + throw new Ex\WrongKeyOrModifiedCiphertextException(
  246 + 'Bad version header.'
  247 + );
  248 + }
  249 +
  250 + // Get the salt.
  251 + /** @var string $salt */
  252 + $salt = Core::ourSubstr(
  253 + $ciphertext,
  254 + Core::HEADER_VERSION_SIZE,
  255 + Core::SALT_BYTE_SIZE
  256 + );
  257 + if (!\is_string($salt)) {
  258 + throw new Ex\EnvironmentIsBrokenException();
  259 + }
  260 +
  261 + // Get the IV.
  262 + /** @var string $iv */
  263 + $iv = Core::ourSubstr(
  264 + $ciphertext,
  265 + Core::HEADER_VERSION_SIZE + Core::SALT_BYTE_SIZE,
  266 + Core::BLOCK_BYTE_SIZE
  267 + );
  268 + if (!\is_string($iv)) {
  269 + throw new Ex\EnvironmentIsBrokenException();
  270 + }
  271 +
  272 + // Get the HMAC.
  273 + /** @var string $hmac */
  274 + $hmac = Core::ourSubstr(
  275 + $ciphertext,
  276 + Core::ourStrlen($ciphertext) - Core::MAC_BYTE_SIZE,
  277 + Core::MAC_BYTE_SIZE
  278 + );
  279 + if (!\is_string($hmac)) {
  280 + throw new Ex\EnvironmentIsBrokenException();
  281 + }
  282 +
  283 + // Get the actual encrypted ciphertext.
  284 + /** @var string $encrypted */
  285 + $encrypted = Core::ourSubstr(
  286 + $ciphertext,
  287 + Core::HEADER_VERSION_SIZE + Core::SALT_BYTE_SIZE +
  288 + Core::BLOCK_BYTE_SIZE,
  289 + Core::ourStrlen($ciphertext) - Core::MAC_BYTE_SIZE - Core::SALT_BYTE_SIZE -
  290 + Core::BLOCK_BYTE_SIZE - Core::HEADER_VERSION_SIZE
  291 + );
  292 + if (!\is_string($encrypted)) {
  293 + throw new Ex\EnvironmentIsBrokenException();
  294 + }
  295 +
  296 + // Derive the separate encryption and authentication keys from the key
  297 + // or password, whichever it is.
  298 + $keys = $secret->deriveKeys($salt);
  299 +
  300 + if (self::verifyHMAC($hmac, $header . $salt . $iv . $encrypted, $keys->getAuthenticationKey())) {
  301 + $plaintext = self::plainDecrypt($encrypted, $keys->getEncryptionKey(), $iv, Core::CIPHER_METHOD);
  302 + return $plaintext;
  303 + } else {
  304 + throw new Ex\WrongKeyOrModifiedCiphertextException(
  305 + 'Integrity check failed.'
  306 + );
  307 + }
  308 + }
  309 +
  310 + /**
  311 + * Raw unauthenticated encryption (insecure on its own).
  312 + *
  313 + * @param string $plaintext
  314 + * @param string $key
  315 + * @param string $iv
  316 + *
  317 + * @throws Ex\EnvironmentIsBrokenException
  318 + *
  319 + * @return string
  320 + */
  321 + protected static function plainEncrypt($plaintext, $key, $iv)
  322 + {
  323 + Core::ensureConstantExists('OPENSSL_RAW_DATA');
  324 + Core::ensureFunctionExists('openssl_encrypt');
  325 + /** @var string $ciphertext */
  326 + $ciphertext = \openssl_encrypt(
  327 + $plaintext,
  328 + Core::CIPHER_METHOD,
  329 + $key,
  330 + OPENSSL_RAW_DATA,
  331 + $iv
  332 + );
  333 +
  334 + if (!\is_string($ciphertext)) {
  335 + throw new Ex\EnvironmentIsBrokenException(
  336 + 'openssl_encrypt() failed.'
  337 + );
  338 + }
  339 +
  340 + return $ciphertext;
  341 + }
  342 +
  343 + /**
  344 + * Raw unauthenticated decryption (insecure on its own).
  345 + *
  346 + * @param string $ciphertext
  347 + * @param string $key
  348 + * @param string $iv
  349 + * @param string $cipherMethod
  350 + *
  351 + * @throws Ex\EnvironmentIsBrokenException
  352 + *
  353 + * @return string
  354 + */
  355 + protected static function plainDecrypt($ciphertext, $key, $iv, $cipherMethod)
  356 + {
  357 + Core::ensureConstantExists('OPENSSL_RAW_DATA');
  358 + Core::ensureFunctionExists('openssl_decrypt');
  359 +
  360 + /** @var string $plaintext */
  361 + $plaintext = \openssl_decrypt(
  362 + $ciphertext,
  363 + $cipherMethod,
  364 + $key,
  365 + OPENSSL_RAW_DATA,
  366 + $iv
  367 + );
  368 + if (!\is_string($plaintext)) {
  369 + throw new Ex\EnvironmentIsBrokenException(
  370 + 'openssl_decrypt() failed.'
  371 + );
  372 + }
  373 +
  374 + return $plaintext;
  375 + }
  376 +
  377 + /**
  378 + * Verifies an HMAC without leaking information through side-channels.
  379 + *
  380 + * @param string $expected_hmac
  381 + * @param string $message
  382 + * @param string $key
  383 + *
  384 + * @throws Ex\EnvironmentIsBrokenException
  385 + *
  386 + * @return bool
  387 + */
  388 + protected static function verifyHMAC($expected_hmac, $message, $key)
  389 + {
  390 + $message_hmac = \hash_hmac(Core::HASH_FUNCTION_NAME, $message, $key, true);
  391 + return Core::hashEquals($message_hmac, $expected_hmac);
  392 + }
  393 +}
... ...
pacotes/composer/vendor/defuse/php-encryption/src/DerivedKeys.php 0 → 100644
... ... @@ -0,0 +1,50 @@
  1 +<?php
  2 +
  3 +namespace Defuse\Crypto;
  4 +
  5 +/**
  6 + * Class DerivedKeys
  7 + * @package Defuse\Crypto
  8 + */
  9 +final class DerivedKeys
  10 +{
  11 + /**
  12 + * @var string
  13 + */
  14 + private $akey = '';
  15 +
  16 + /**
  17 + * @var string
  18 + */
  19 + private $ekey = '';
  20 +
  21 + /**
  22 + * Returns the authentication key.
  23 + * @return string
  24 + */
  25 + public function getAuthenticationKey()
  26 + {
  27 + return $this->akey;
  28 + }
  29 +
  30 + /**
  31 + * Returns the encryption key.
  32 + * @return string
  33 + */
  34 + public function getEncryptionKey()
  35 + {
  36 + return $this->ekey;
  37 + }
  38 +
  39 + /**
  40 + * Constructor for DerivedKeys.
  41 + *
  42 + * @param string $akey
  43 + * @param string $ekey
  44 + */
  45 + public function __construct($akey, $ekey)
  46 + {
  47 + $this->akey = $akey;
  48 + $this->ekey = $ekey;
  49 + }
  50 +}
... ...
pacotes/composer/vendor/defuse/php-encryption/src/Encoding.php 0 → 100644
... ... @@ -0,0 +1,270 @@
  1 +<?php
  2 +
  3 +namespace Defuse\Crypto;
  4 +
  5 +use Defuse\Crypto\Exception as Ex;
  6 +
  7 +final class Encoding
  8 +{
  9 + const CHECKSUM_BYTE_SIZE = 32;
  10 + const CHECKSUM_HASH_ALGO = 'sha256';
  11 + const SERIALIZE_HEADER_BYTES = 4;
  12 +
  13 + /**
  14 + * Converts a byte string to a hexadecimal string without leaking
  15 + * information through side channels.
  16 + *
  17 + * @param string $byte_string
  18 + *
  19 + * @throws Ex\EnvironmentIsBrokenException
  20 + *
  21 + * @return string
  22 + */
  23 + public static function binToHex($byte_string)
  24 + {
  25 + $hex = '';
  26 + $len = Core::ourStrlen($byte_string);
  27 + for ($i = 0; $i < $len; ++$i) {
  28 + $c = \ord($byte_string[$i]) & 0xf;
  29 + $b = \ord($byte_string[$i]) >> 4;
  30 + $hex .= \pack(
  31 + 'CC',
  32 + 87 + $b + ((($b - 10) >> 8) & ~38),
  33 + 87 + $c + ((($c - 10) >> 8) & ~38)
  34 + );
  35 + }
  36 + return $hex;
  37 + }
  38 +
  39 + /**
  40 + * Converts a hexadecimal string into a byte string without leaking
  41 + * information through side channels.
  42 + *
  43 + * @param string $hex_string
  44 + *
  45 + * @throws Ex\BadFormatException
  46 + * @throws Ex\EnvironmentIsBrokenException
  47 + *
  48 + * @return string
  49 + */
  50 + public static function hexToBin($hex_string)
  51 + {
  52 + $hex_pos = 0;
  53 + $bin = '';
  54 + $hex_len = Core::ourStrlen($hex_string);
  55 + $state = 0;
  56 + $c_acc = 0;
  57 +
  58 + while ($hex_pos < $hex_len) {
  59 + $c = \ord($hex_string[$hex_pos]);
  60 + $c_num = $c ^ 48;
  61 + $c_num0 = ($c_num - 10) >> 8;
  62 + $c_alpha = ($c & ~32) - 55;
  63 + $c_alpha0 = (($c_alpha - 10) ^ ($c_alpha - 16)) >> 8;
  64 + if (($c_num0 | $c_alpha0) === 0) {
  65 + throw new Ex\BadFormatException(
  66 + 'Encoding::hexToBin() input is not a hex string.'
  67 + );
  68 + }
  69 + $c_val = ($c_num0 & $c_num) | ($c_alpha & $c_alpha0);
  70 + if ($state === 0) {
  71 + $c_acc = $c_val * 16;
  72 + } else {
  73 + $bin .= \pack('C', $c_acc | $c_val);
  74 + }
  75 + $state ^= 1;
  76 + ++$hex_pos;
  77 + }
  78 + return $bin;
  79 + }
  80 +
  81 + /**
  82 + * Remove trialing whitespace without table look-ups or branches.
  83 + *
  84 + * Calling this function may leak the length of the string as well as the
  85 + * number of trailing whitespace characters through side-channels.
  86 + *
  87 + * @param string $string
  88 + * @return string
  89 + */
  90 + public static function trimTrailingWhitespace($string = '')
  91 + {
  92 + $length = Core::ourStrlen($string);
  93 + if ($length < 1) {
  94 + return '';
  95 + }
  96 + do {
  97 + $prevLength = $length;
  98 + $last = $length - 1;
  99 + $chr = \ord($string[$last]);
  100 +
  101 + /* Null Byte (0x00), a.k.a. \0 */
  102 + // if ($chr === 0x00) $length -= 1;
  103 + $sub = (($chr - 1) >> 8 ) & 1;
  104 + $length -= $sub;
  105 + $last -= $sub;
  106 +
  107 + /* Horizontal Tab (0x09) a.k.a. \t */
  108 + $chr = \ord($string[$last]);
  109 + // if ($chr === 0x09) $length -= 1;
  110 + $sub = (((0x08 - $chr) & ($chr - 0x0a)) >> 8) & 1;
  111 + $length -= $sub;
  112 + $last -= $sub;
  113 +
  114 + /* New Line (0x0a), a.k.a. \n */
  115 + $chr = \ord($string[$last]);
  116 + // if ($chr === 0x0a) $length -= 1;
  117 + $sub = (((0x09 - $chr) & ($chr - 0x0b)) >> 8) & 1;
  118 + $length -= $sub;
  119 + $last -= $sub;
  120 +
  121 + /* Carriage Return (0x0D), a.k.a. \r */
  122 + $chr = \ord($string[$last]);
  123 + // if ($chr === 0x0d) $length -= 1;
  124 + $sub = (((0x0c - $chr) & ($chr - 0x0e)) >> 8) & 1;
  125 + $length -= $sub;
  126 + $last -= $sub;
  127 +
  128 + /* Space */
  129 + $chr = \ord($string[$last]);
  130 + // if ($chr === 0x20) $length -= 1;
  131 + $sub = (((0x1f - $chr) & ($chr - 0x21)) >> 8) & 1;
  132 + $length -= $sub;
  133 + } while ($prevLength !== $length && $length > 0);
  134 + return (string) Core::ourSubstr($string, 0, $length);
  135 + }
  136 +
  137 + /*
  138 + * SECURITY NOTE ON APPLYING CHECKSUMS TO SECRETS:
  139 + *
  140 + * The checksum introduces a potential security weakness. For example,
  141 + * suppose we apply a checksum to a key, and that an adversary has an
  142 + * exploit against the process containing the key, such that they can
  143 + * overwrite an arbitrary byte of memory and then cause the checksum to
  144 + * be verified and learn the result.
  145 + *
  146 + * In this scenario, the adversary can extract the key one byte at
  147 + * a time by overwriting it with their guess of its value and then
  148 + * asking if the checksum matches. If it does, their guess was right.
  149 + * This kind of attack may be more easy to implement and more reliable
  150 + * than a remote code execution attack.
  151 + *
  152 + * This attack also applies to authenticated encryption as a whole, in
  153 + * the situation where the adversary can overwrite a byte of the key
  154 + * and then cause a valid ciphertext to be decrypted, and then
  155 + * determine whether the MAC check passed or failed.
  156 + *
  157 + * By using the full SHA256 hash instead of truncating it, I'm ensuring
  158 + * that both ways of going about the attack are equivalently difficult.
  159 + * A shorter checksum of say 32 bits might be more useful to the
  160 + * adversary as an oracle in case their writes are coarser grained.
  161 + *
  162 + * Because the scenario assumes a serious vulnerability, we don't try
  163 + * to prevent attacks of this style.
  164 + */
  165 +
  166 + /**
  167 + * INTERNAL USE ONLY: Applies a version header, applies a checksum, and
  168 + * then encodes a byte string into a range of printable ASCII characters.
  169 + *
  170 + * @param string $header
  171 + * @param string $bytes
  172 + *
  173 + * @throws Ex\EnvironmentIsBrokenException
  174 + *
  175 + * @return string
  176 + */
  177 + public static function saveBytesToChecksummedAsciiSafeString($header, $bytes)
  178 + {
  179 + // Headers must be a constant length to prevent one type's header from
  180 + // being a prefix of another type's header, leading to ambiguity.
  181 + if (Core::ourStrlen($header) !== self::SERIALIZE_HEADER_BYTES) {
  182 + throw new Ex\EnvironmentIsBrokenException(
  183 + 'Header must be ' . self::SERIALIZE_HEADER_BYTES . ' bytes.'
  184 + );
  185 + }
  186 +
  187 + return Encoding::binToHex(
  188 + $header .
  189 + $bytes .
  190 + \hash(
  191 + self::CHECKSUM_HASH_ALGO,
  192 + $header . $bytes,
  193 + true
  194 + )
  195 + );
  196 + }
  197 +
  198 + /**
  199 + * INTERNAL USE ONLY: Decodes, verifies the header and checksum, and returns
  200 + * the encoded byte string.
  201 + *
  202 + * @param string $expected_header
  203 + * @param string $string
  204 + *
  205 + * @throws Ex\EnvironmentIsBrokenException
  206 + * @throws Ex\BadFormatException
  207 + *
  208 + * @return string
  209 + */
  210 + public static function loadBytesFromChecksummedAsciiSafeString($expected_header, $string)
  211 + {
  212 + // Headers must be a constant length to prevent one type's header from
  213 + // being a prefix of another type's header, leading to ambiguity.
  214 + if (Core::ourStrlen($expected_header) !== self::SERIALIZE_HEADER_BYTES) {
  215 + throw new Ex\EnvironmentIsBrokenException(
  216 + 'Header must be 4 bytes.'
  217 + );
  218 + }
  219 +
  220 + /* If you get an exception here when attempting to load from a file, first pass your
  221 + key to Encoding::trimTrailingWhitespace() to remove newline characters, etc. */
  222 + $bytes = Encoding::hexToBin($string);
  223 +
  224 + /* Make sure we have enough bytes to get the version header and checksum. */
  225 + if (Core::ourStrlen($bytes) < self::SERIALIZE_HEADER_BYTES + self::CHECKSUM_BYTE_SIZE) {
  226 + throw new Ex\BadFormatException(
  227 + 'Encoded data is shorter than expected.'
  228 + );
  229 + }
  230 +
  231 + /* Grab the version header. */
  232 + $actual_header = (string) Core::ourSubstr($bytes, 0, self::SERIALIZE_HEADER_BYTES);
  233 +
  234 + if ($actual_header !== $expected_header) {
  235 + throw new Ex\BadFormatException(
  236 + 'Invalid header.'
  237 + );
  238 + }
  239 +
  240 + /* Grab the bytes that are part of the checksum. */
  241 + $checked_bytes = (string) Core::ourSubstr(
  242 + $bytes,
  243 + 0,
  244 + Core::ourStrlen($bytes) - self::CHECKSUM_BYTE_SIZE
  245 + );
  246 +
  247 + /* Grab the included checksum. */
  248 + $checksum_a = (string) Core::ourSubstr(
  249 + $bytes,
  250 + Core::ourStrlen($bytes) - self::CHECKSUM_BYTE_SIZE,
  251 + self::CHECKSUM_BYTE_SIZE
  252 + );
  253 +
  254 + /* Re-compute the checksum. */
  255 + $checksum_b = \hash(self::CHECKSUM_HASH_ALGO, $checked_bytes, true);
  256 +
  257 + /* Check if the checksum matches. */
  258 + if (! Core::hashEquals($checksum_a, $checksum_b)) {
  259 + throw new Ex\BadFormatException(
  260 + "Data is corrupted, the checksum doesn't match"
  261 + );
  262 + }
  263 +
  264 + return (string) Core::ourSubstr(
  265 + $bytes,
  266 + self::SERIALIZE_HEADER_BYTES,
  267 + Core::ourStrlen($bytes) - self::SERIALIZE_HEADER_BYTES - self::CHECKSUM_BYTE_SIZE
  268 + );
  269 + }
  270 +}
... ...
pacotes/composer/vendor/defuse/php-encryption/src/Exception/BadFormatException.php 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +<?php
  2 +
  3 +namespace Defuse\Crypto\Exception;
  4 +
  5 +class BadFormatException extends \Defuse\Crypto\Exception\CryptoException
  6 +{
  7 +}
... ...
pacotes/composer/vendor/defuse/php-encryption/src/Exception/CryptoException.php 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +<?php
  2 +
  3 +namespace Defuse\Crypto\Exception;
  4 +
  5 +class CryptoException extends \Exception
  6 +{
  7 +}
... ...
pacotes/composer/vendor/defuse/php-encryption/src/Exception/EnvironmentIsBrokenException.php 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +<?php
  2 +
  3 +namespace Defuse\Crypto\Exception;
  4 +
  5 +class EnvironmentIsBrokenException extends \Defuse\Crypto\Exception\CryptoException
  6 +{
  7 +}
... ...
pacotes/composer/vendor/defuse/php-encryption/src/Exception/IOException.php 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +<?php
  2 +
  3 +namespace Defuse\Crypto\Exception;
  4 +
  5 +class IOException extends \Defuse\Crypto\Exception\CryptoException
  6 +{
  7 +}
... ...
pacotes/composer/vendor/defuse/php-encryption/src/Exception/WrongKeyOrModifiedCiphertextException.php 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +<?php
  2 +
  3 +namespace Defuse\Crypto\Exception;
  4 +
  5 +class WrongKeyOrModifiedCiphertextException extends \Defuse\Crypto\Exception\CryptoException
  6 +{
  7 +}
... ...
pacotes/composer/vendor/defuse/php-encryption/src/File.php 0 → 100644
... ... @@ -0,0 +1,784 @@
  1 +<?php
  2 +
  3 +namespace Defuse\Crypto;
  4 +
  5 +use Defuse\Crypto\Exception as Ex;
  6 +
  7 +final class File
  8 +{
  9 + /**
  10 + * Encrypts the input file, saving the ciphertext to the output file.
  11 + *
  12 + * @param string $inputFilename
  13 + * @param string $outputFilename
  14 + * @param Key $key
  15 + * @return void
  16 + *
  17 + * @throws Ex\EnvironmentIsBrokenException
  18 + * @throws Ex\IOException
  19 + */
  20 + public static function encryptFile($inputFilename, $outputFilename, Key $key)
  21 + {
  22 + self::encryptFileInternal(
  23 + $inputFilename,
  24 + $outputFilename,
  25 + KeyOrPassword::createFromKey($key)
  26 + );
  27 + }
  28 +
  29 + /**
  30 + * Encrypts a file with a password, using a slow key derivation function to
  31 + * make password cracking more expensive.
  32 + *
  33 + * @param string $inputFilename
  34 + * @param string $outputFilename
  35 + * @param string $password
  36 + * @return void
  37 + *
  38 + * @throws Ex\EnvironmentIsBrokenException
  39 + * @throws Ex\IOException
  40 + */
  41 + public static function encryptFileWithPassword($inputFilename, $outputFilename, $password)
  42 + {
  43 + self::encryptFileInternal(
  44 + $inputFilename,
  45 + $outputFilename,
  46 + KeyOrPassword::createFromPassword($password)
  47 + );
  48 + }
  49 +
  50 + /**
  51 + * Decrypts the input file, saving the plaintext to the output file.
  52 + *
  53 + * @param string $inputFilename
  54 + * @param string $outputFilename
  55 + * @param Key $key
  56 + * @return void
  57 + *
  58 + * @throws Ex\EnvironmentIsBrokenException
  59 + * @throws Ex\IOException
  60 + * @throws Ex\WrongKeyOrModifiedCiphertextException
  61 + */
  62 + public static function decryptFile($inputFilename, $outputFilename, Key $key)
  63 + {
  64 + self::decryptFileInternal(
  65 + $inputFilename,
  66 + $outputFilename,
  67 + KeyOrPassword::createFromKey($key)
  68 + );
  69 + }
  70 +
  71 + /**
  72 + * Decrypts a file with a password, using a slow key derivation function to
  73 + * make password cracking more expensive.
  74 + *
  75 + * @param string $inputFilename
  76 + * @param string $outputFilename
  77 + * @param string $password
  78 + * @return void
  79 + *
  80 + * @throws Ex\EnvironmentIsBrokenException
  81 + * @throws Ex\IOException
  82 + * @throws Ex\WrongKeyOrModifiedCiphertextException
  83 + */
  84 + public static function decryptFileWithPassword($inputFilename, $outputFilename, $password)
  85 + {
  86 + self::decryptFileInternal(
  87 + $inputFilename,
  88 + $outputFilename,
  89 + KeyOrPassword::createFromPassword($password)
  90 + );
  91 + }
  92 +
  93 + /**
  94 + * Takes two resource handles and encrypts the contents of the first,
  95 + * writing the ciphertext into the second.
  96 + *
  97 + * @param resource $inputHandle
  98 + * @param resource $outputHandle
  99 + * @param Key $key
  100 + * @return void
  101 + *
  102 + * @throws Ex\EnvironmentIsBrokenException
  103 + * @throws Ex\WrongKeyOrModifiedCiphertextException
  104 + */
  105 + public static function encryptResource($inputHandle, $outputHandle, Key $key)
  106 + {
  107 + self::encryptResourceInternal(
  108 + $inputHandle,
  109 + $outputHandle,
  110 + KeyOrPassword::createFromKey($key)
  111 + );
  112 + }
  113 +
  114 + /**
  115 + * Encrypts the contents of one resource handle into another with a
  116 + * password, using a slow key derivation function to make password cracking
  117 + * more expensive.
  118 + *
  119 + * @param resource $inputHandle
  120 + * @param resource $outputHandle
  121 + * @param string $password
  122 + * @return void
  123 + *
  124 + * @throws Ex\EnvironmentIsBrokenException
  125 + * @throws Ex\IOException
  126 + * @throws Ex\WrongKeyOrModifiedCiphertextException
  127 + */
  128 + public static function encryptResourceWithPassword($inputHandle, $outputHandle, $password)
  129 + {
  130 + self::encryptResourceInternal(
  131 + $inputHandle,
  132 + $outputHandle,
  133 + KeyOrPassword::createFromPassword($password)
  134 + );
  135 + }
  136 +
  137 + /**
  138 + * Takes two resource handles and decrypts the contents of the first,
  139 + * writing the plaintext into the second.
  140 + *
  141 + * @param resource $inputHandle
  142 + * @param resource $outputHandle
  143 + * @param Key $key
  144 + * @return void
  145 + *
  146 + * @throws Ex\EnvironmentIsBrokenException
  147 + * @throws Ex\IOException
  148 + * @throws Ex\WrongKeyOrModifiedCiphertextException
  149 + */
  150 + public static function decryptResource($inputHandle, $outputHandle, Key $key)
  151 + {
  152 + self::decryptResourceInternal(
  153 + $inputHandle,
  154 + $outputHandle,
  155 + KeyOrPassword::createFromKey($key)
  156 + );
  157 + }
  158 +
  159 + /**
  160 + * Decrypts the contents of one resource into another with a password, using
  161 + * a slow key derivation function to make password cracking more expensive.
  162 + *
  163 + * @param resource $inputHandle
  164 + * @param resource $outputHandle
  165 + * @param string $password
  166 + * @return void
  167 + *
  168 + * @throws Ex\EnvironmentIsBrokenException
  169 + * @throws Ex\IOException
  170 + * @throws Ex\WrongKeyOrModifiedCiphertextException
  171 + */
  172 + public static function decryptResourceWithPassword($inputHandle, $outputHandle, $password)
  173 + {
  174 + self::decryptResourceInternal(
  175 + $inputHandle,
  176 + $outputHandle,
  177 + KeyOrPassword::createFromPassword($password)
  178 + );
  179 + }
  180 +
  181 + /**
  182 + * Encrypts a file with either a key or a password.
  183 + *
  184 + * @param string $inputFilename
  185 + * @param string $outputFilename
  186 + * @param KeyOrPassword $secret
  187 + * @return void
  188 + *
  189 + * @throws Ex\CryptoException
  190 + * @throws Ex\IOException
  191 + */
  192 + private static function encryptFileInternal($inputFilename, $outputFilename, KeyOrPassword $secret)
  193 + {
  194 + /* Open the input file. */
  195 + $if = @\fopen($inputFilename, 'rb');
  196 + if ($if === false) {
  197 + throw new Ex\IOException(
  198 + 'Cannot open input file for encrypting: ' .
  199 + self::getLastErrorMessage()
  200 + );
  201 + }
  202 + if (\is_callable('\\stream_set_read_buffer')) {
  203 + /* This call can fail, but the only consequence is performance. */
  204 + \stream_set_read_buffer($if, 0);
  205 + }
  206 +
  207 + /* Open the output file. */
  208 + $of = @\fopen($outputFilename, 'wb');
  209 + if ($of === false) {
  210 + \fclose($if);
  211 + throw new Ex\IOException(
  212 + 'Cannot open output file for encrypting: ' .
  213 + self::getLastErrorMessage()
  214 + );
  215 + }
  216 + if (\is_callable('\\stream_set_write_buffer')) {
  217 + /* This call can fail, but the only consequence is performance. */
  218 + \stream_set_write_buffer($of, 0);
  219 + }
  220 +
  221 + /* Perform the encryption. */
  222 + try {
  223 + self::encryptResourceInternal($if, $of, $secret);
  224 + } catch (Ex\CryptoException $ex) {
  225 + \fclose($if);
  226 + \fclose($of);
  227 + throw $ex;
  228 + }
  229 +
  230 + /* Close the input file. */
  231 + if (\fclose($if) === false) {
  232 + \fclose($of);
  233 + throw new Ex\IOException(
  234 + 'Cannot close input file after encrypting'
  235 + );
  236 + }
  237 +
  238 + /* Close the output file. */
  239 + if (\fclose($of) === false) {
  240 + throw new Ex\IOException(
  241 + 'Cannot close output file after encrypting'
  242 + );
  243 + }
  244 + }
  245 +
  246 + /**
  247 + * Decrypts a file with either a key or a password.
  248 + *
  249 + * @param string $inputFilename
  250 + * @param string $outputFilename
  251 + * @param KeyOrPassword $secret
  252 + * @return void
  253 + *
  254 + * @throws Ex\CryptoException
  255 + * @throws Ex\IOException
  256 + */
  257 + private static function decryptFileInternal($inputFilename, $outputFilename, KeyOrPassword $secret)
  258 + {
  259 + /* Open the input file. */
  260 + $if = @\fopen($inputFilename, 'rb');
  261 + if ($if === false) {
  262 + throw new Ex\IOException(
  263 + 'Cannot open input file for decrypting: ' .
  264 + self::getLastErrorMessage()
  265 + );
  266 + }
  267 +
  268 + if (\is_callable('\\stream_set_read_buffer')) {
  269 + /* This call can fail, but the only consequence is performance. */
  270 + \stream_set_read_buffer($if, 0);
  271 + }
  272 +
  273 + /* Open the output file. */
  274 + $of = @\fopen($outputFilename, 'wb');
  275 + if ($of === false) {
  276 + \fclose($if);
  277 + throw new Ex\IOException(
  278 + 'Cannot open output file for decrypting: ' .
  279 + self::getLastErrorMessage()
  280 + );
  281 + }
  282 +
  283 + if (\is_callable('\\stream_set_write_buffer')) {
  284 + /* This call can fail, but the only consequence is performance. */
  285 + \stream_set_write_buffer($of, 0);
  286 + }
  287 +
  288 + /* Perform the decryption. */
  289 + try {
  290 + self::decryptResourceInternal($if, $of, $secret);
  291 + } catch (Ex\CryptoException $ex) {
  292 + \fclose($if);
  293 + \fclose($of);
  294 + throw $ex;
  295 + }
  296 +
  297 + /* Close the input file. */
  298 + if (\fclose($if) === false) {
  299 + \fclose($of);
  300 + throw new Ex\IOException(
  301 + 'Cannot close input file after decrypting'
  302 + );
  303 + }
  304 +
  305 + /* Close the output file. */
  306 + if (\fclose($of) === false) {
  307 + throw new Ex\IOException(
  308 + 'Cannot close output file after decrypting'
  309 + );
  310 + }
  311 + }
  312 +
  313 + /**
  314 + * Encrypts a resource with either a key or a password.
  315 + *
  316 + * @param resource $inputHandle
  317 + * @param resource $outputHandle
  318 + * @param KeyOrPassword $secret
  319 + * @return void
  320 + *
  321 + * @throws Ex\EnvironmentIsBrokenException
  322 + * @throws Ex\IOException
  323 + */
  324 + private static function encryptResourceInternal($inputHandle, $outputHandle, KeyOrPassword $secret)
  325 + {
  326 + if (! \is_resource($inputHandle)) {
  327 + throw new Ex\IOException(
  328 + 'Input handle must be a resource!'
  329 + );
  330 + }
  331 + if (! \is_resource($outputHandle)) {
  332 + throw new Ex\IOException(
  333 + 'Output handle must be a resource!'
  334 + );
  335 + }
  336 +
  337 + $inputStat = \fstat($inputHandle);
  338 + $inputSize = $inputStat['size'];
  339 +
  340 + $file_salt = Core::secureRandom(Core::SALT_BYTE_SIZE);
  341 + $keys = $secret->deriveKeys($file_salt);
  342 + $ekey = $keys->getEncryptionKey();
  343 + $akey = $keys->getAuthenticationKey();
  344 +
  345 + $ivsize = Core::BLOCK_BYTE_SIZE;
  346 + $iv = Core::secureRandom($ivsize);
  347 +
  348 + /* Initialize a streaming HMAC state. */
  349 + /** @var resource $hmac */
  350 + $hmac = \hash_init(Core::HASH_FUNCTION_NAME, HASH_HMAC, $akey);
  351 + if (!\is_resource($hmac)) {
  352 + throw new Ex\EnvironmentIsBrokenException(
  353 + 'Cannot initialize a hash context'
  354 + );
  355 + }
  356 +
  357 + /* Write the header, salt, and IV. */
  358 + self::writeBytes(
  359 + $outputHandle,
  360 + Core::CURRENT_VERSION . $file_salt . $iv,
  361 + Core::HEADER_VERSION_SIZE + Core::SALT_BYTE_SIZE + $ivsize
  362 + );
  363 +
  364 + /* Add the header, salt, and IV to the HMAC. */
  365 + \hash_update($hmac, Core::CURRENT_VERSION);
  366 + \hash_update($hmac, $file_salt);
  367 + \hash_update($hmac, $iv);
  368 +
  369 + /* $thisIv will be incremented after each call to the encryption. */
  370 + $thisIv = $iv;
  371 +
  372 + /* How many blocks do we encrypt at a time? We increment by this value. */
  373 + $inc = (int) (Core::BUFFER_BYTE_SIZE / Core::BLOCK_BYTE_SIZE);
  374 +
  375 + /* Loop until we reach the end of the input file. */
  376 + $at_file_end = false;
  377 + while (! (\feof($inputHandle) || $at_file_end)) {
  378 + /* Find out if we can read a full buffer, or only a partial one. */
  379 + /** @var int */
  380 + $pos = \ftell($inputHandle);
  381 + if (!\is_int($pos)) {
  382 + throw new Ex\IOException(
  383 + 'Could not get current position in input file during encryption'
  384 + );
  385 + }
  386 + if ($pos + Core::BUFFER_BYTE_SIZE >= $inputSize) {
  387 + /* We're at the end of the file, so we need to break out of the loop. */
  388 + $at_file_end = true;
  389 + $read = self::readBytes(
  390 + $inputHandle,
  391 + $inputSize - $pos
  392 + );
  393 + } else {
  394 + $read = self::readBytes(
  395 + $inputHandle,
  396 + Core::BUFFER_BYTE_SIZE
  397 + );
  398 + }
  399 +
  400 + /* Encrypt this buffer. */
  401 + /** @var string */
  402 + $encrypted = \openssl_encrypt(
  403 + $read,
  404 + Core::CIPHER_METHOD,
  405 + $ekey,
  406 + OPENSSL_RAW_DATA,
  407 + $thisIv
  408 + );
  409 +
  410 + if (!\is_string($encrypted)) {
  411 + throw new Ex\EnvironmentIsBrokenException(
  412 + 'OpenSSL encryption error'
  413 + );
  414 + }
  415 +
  416 + /* Write this buffer's ciphertext. */
  417 + self::writeBytes($outputHandle, $encrypted, Core::ourStrlen($encrypted));
  418 + /* Add this buffer's ciphertext to the HMAC. */
  419 + \hash_update($hmac, $encrypted);
  420 +
  421 + /* Increment the counter by the number of blocks in a buffer. */
  422 + $thisIv = Core::incrementCounter($thisIv, $inc);
  423 + /* WARNING: Usually, unless the file is a multiple of the buffer
  424 + * size, $thisIv will contain an incorrect value here on the last
  425 + * iteration of this loop. */
  426 + }
  427 +
  428 + /* Get the HMAC and append it to the ciphertext. */
  429 + $final_mac = \hash_final($hmac, true);
  430 + self::writeBytes($outputHandle, $final_mac, Core::MAC_BYTE_SIZE);
  431 + }
  432 +
  433 + /**
  434 + * Decrypts a file-backed resource with either a key or a password.
  435 + *
  436 + * @param resource $inputHandle
  437 + * @param resource $outputHandle
  438 + * @param KeyOrPassword $secret
  439 + * @return void
  440 + *
  441 + * @throws Ex\EnvironmentIsBrokenException
  442 + * @throws Ex\IOException
  443 + * @throws Ex\WrongKeyOrModifiedCiphertextException
  444 + */
  445 + public static function decryptResourceInternal($inputHandle, $outputHandle, KeyOrPassword $secret)
  446 + {
  447 + if (! \is_resource($inputHandle)) {
  448 + throw new Ex\IOException(
  449 + 'Input handle must be a resource!'
  450 + );
  451 + }
  452 + if (! \is_resource($outputHandle)) {
  453 + throw new Ex\IOException(
  454 + 'Output handle must be a resource!'
  455 + );
  456 + }
  457 +
  458 + /* Make sure the file is big enough for all the reads we need to do. */
  459 + $stat = \fstat($inputHandle);
  460 + if ($stat['size'] < Core::MINIMUM_CIPHERTEXT_SIZE) {
  461 + throw new Ex\WrongKeyOrModifiedCiphertextException(
  462 + 'Input file is too small to have been created by this library.'
  463 + );
  464 + }
  465 +
  466 + /* Check the version header. */
  467 + $header = self::readBytes($inputHandle, Core::HEADER_VERSION_SIZE);
  468 + if ($header !== Core::CURRENT_VERSION) {
  469 + throw new Ex\WrongKeyOrModifiedCiphertextException(
  470 + 'Bad version header.'
  471 + );
  472 + }
  473 +
  474 + /* Get the salt. */
  475 + $file_salt = self::readBytes($inputHandle, Core::SALT_BYTE_SIZE);
  476 +
  477 + /* Get the IV. */
  478 + $ivsize = Core::BLOCK_BYTE_SIZE;
  479 + $iv = self::readBytes($inputHandle, $ivsize);
  480 +
  481 + /* Derive the authentication and encryption keys. */
  482 + $keys = $secret->deriveKeys($file_salt);
  483 + $ekey = $keys->getEncryptionKey();
  484 + $akey = $keys->getAuthenticationKey();
  485 +
  486 + /* We'll store the MAC of each buffer-sized chunk as we verify the
  487 + * actual MAC, so that we can check them again when decrypting. */
  488 + $macs = [];
  489 +
  490 + /* $thisIv will be incremented after each call to the decryption. */
  491 + $thisIv = $iv;
  492 +
  493 + /* How many blocks do we encrypt at a time? We increment by this value. */
  494 + $inc = (int) (Core::BUFFER_BYTE_SIZE / Core::BLOCK_BYTE_SIZE);
  495 +
  496 + /* Get the HMAC. */
  497 + if (\fseek($inputHandle, (-1 * Core::MAC_BYTE_SIZE), SEEK_END) === false) {
  498 + throw new Ex\IOException(
  499 + 'Cannot seek to beginning of MAC within input file'
  500 + );
  501 + }
  502 +
  503 + /* Get the position of the last byte in the actual ciphertext. */
  504 + /** @var int $cipher_end */
  505 + $cipher_end = \ftell($inputHandle);
  506 + if (!\is_int($cipher_end)) {
  507 + throw new Ex\IOException(
  508 + 'Cannot read input file'
  509 + );
  510 + }
  511 + /* We have the position of the first byte of the HMAC. Go back by one. */
  512 + --$cipher_end;
  513 +
  514 + /* Read the HMAC. */
  515 + /** @var string $stored_mac */
  516 + $stored_mac = self::readBytes($inputHandle, Core::MAC_BYTE_SIZE);
  517 +
  518 + /* Initialize a streaming HMAC state. */
  519 + /** @var resource $hmac */
  520 + $hmac = \hash_init(Core::HASH_FUNCTION_NAME, HASH_HMAC, $akey);
  521 + if (!\is_resource($hmac)) {
  522 + throw new Ex\EnvironmentIsBrokenException(
  523 + 'Cannot initialize a hash context'
  524 + );
  525 + }
  526 +
  527 + /* Reset file pointer to the beginning of the file after the header */
  528 + if (\fseek($inputHandle, Core::HEADER_VERSION_SIZE, SEEK_SET) === false) {
  529 + throw new Ex\IOException(
  530 + 'Cannot read seek within input file'
  531 + );
  532 + }
  533 +
  534 + /* Seek to the start of the actual ciphertext. */
  535 + if (\fseek($inputHandle, Core::SALT_BYTE_SIZE + $ivsize, SEEK_CUR) === false) {
  536 + throw new Ex\IOException(
  537 + 'Cannot seek input file to beginning of ciphertext'
  538 + );
  539 + }
  540 +
  541 + /* PASS #1: Calculating the HMAC. */
  542 +
  543 + \hash_update($hmac, $header);
  544 + \hash_update($hmac, $file_salt);
  545 + \hash_update($hmac, $iv);
  546 + /** @var resource $hmac2 */
  547 + $hmac2 = \hash_copy($hmac);
  548 +
  549 + $break = false;
  550 + while (! $break) {
  551 + /** @var int $pos */
  552 + $pos = \ftell($inputHandle);
  553 + if (!\is_int($pos)) {
  554 + throw new Ex\IOException(
  555 + 'Could not get current position in input file during decryption'
  556 + );
  557 + }
  558 +
  559 + /* Read the next buffer-sized chunk (or less). */
  560 + if ($pos + Core::BUFFER_BYTE_SIZE >= $cipher_end) {
  561 + $break = true;
  562 + $read = self::readBytes(
  563 + $inputHandle,
  564 + $cipher_end - $pos + 1
  565 + );
  566 + } else {
  567 + $read = self::readBytes(
  568 + $inputHandle,
  569 + Core::BUFFER_BYTE_SIZE
  570 + );
  571 + }
  572 +
  573 + /* Update the HMAC. */
  574 + \hash_update($hmac, $read);
  575 +
  576 + /* Remember this buffer-sized chunk's HMAC. */
  577 + /** @var resource $chunk_mac */
  578 + $chunk_mac = \hash_copy($hmac);
  579 + if (!\is_resource($chunk_mac)) {
  580 + throw new Ex\EnvironmentIsBrokenException(
  581 + 'Cannot duplicate a hash context'
  582 + );
  583 + }
  584 + $macs []= \hash_final($chunk_mac);
  585 + }
  586 +
  587 + /* Get the final HMAC, which should match the stored one. */
  588 + /** @var string $final_mac */
  589 + $final_mac = \hash_final($hmac, true);
  590 +
  591 + /* Verify the HMAC. */
  592 + if (! Core::hashEquals($final_mac, $stored_mac)) {
  593 + throw new Ex\WrongKeyOrModifiedCiphertextException(
  594 + 'Integrity check failed.'
  595 + );
  596 + }
  597 +
  598 + /* PASS #2: Decrypt and write output. */
  599 +
  600 + /* Rewind to the start of the actual ciphertext. */
  601 + if (\fseek($inputHandle, Core::SALT_BYTE_SIZE + $ivsize + Core::HEADER_VERSION_SIZE, SEEK_SET) === false) {
  602 + throw new Ex\IOException(
  603 + 'Could not move the input file pointer during decryption'
  604 + );
  605 + }
  606 +
  607 + $at_file_end = false;
  608 + while (! $at_file_end) {
  609 + /** @var int $pos */
  610 + $pos = \ftell($inputHandle);
  611 + if (!\is_int($pos)) {
  612 + throw new Ex\IOException(
  613 + 'Could not get current position in input file during decryption'
  614 + );
  615 + }
  616 +
  617 + /* Read the next buffer-sized chunk (or less). */
  618 + if ($pos + Core::BUFFER_BYTE_SIZE >= $cipher_end) {
  619 + $at_file_end = true;
  620 + $read = self::readBytes(
  621 + $inputHandle,
  622 + $cipher_end - $pos + 1
  623 + );
  624 + } else {
  625 + $read = self::readBytes(
  626 + $inputHandle,
  627 + Core::BUFFER_BYTE_SIZE
  628 + );
  629 + }
  630 +
  631 + /* Recalculate the MAC (so far) and compare it with the one we
  632 + * remembered from pass #1 to ensure attackers didn't change the
  633 + * ciphertext after MAC verification. */
  634 + \hash_update($hmac2, $read);
  635 + /** @var resource $calc_mac */
  636 + $calc_mac = \hash_copy($hmac2);
  637 + if (!\is_resource($calc_mac)) {
  638 + throw new Ex\EnvironmentIsBrokenException(
  639 + 'Cannot duplicate a hash context'
  640 + );
  641 + }
  642 + $calc = \hash_final($calc_mac);
  643 +
  644 + if (empty($macs)) {
  645 + throw new Ex\WrongKeyOrModifiedCiphertextException(
  646 + 'File was modified after MAC verification'
  647 + );
  648 + } elseif (! Core::hashEquals(\array_shift($macs), $calc)) {
  649 + throw new Ex\WrongKeyOrModifiedCiphertextException(
  650 + 'File was modified after MAC verification'
  651 + );
  652 + }
  653 +
  654 + /* Decrypt this buffer-sized chunk. */
  655 + /** @var string $decrypted */
  656 + $decrypted = \openssl_decrypt(
  657 + $read,
  658 + Core::CIPHER_METHOD,
  659 + $ekey,
  660 + OPENSSL_RAW_DATA,
  661 + $thisIv
  662 + );
  663 + if (!\is_string($decrypted)) {
  664 + throw new Ex\EnvironmentIsBrokenException(
  665 + 'OpenSSL decryption error'
  666 + );
  667 + }
  668 +
  669 + /* Write the plaintext to the output file. */
  670 + self::writeBytes(
  671 + $outputHandle,
  672 + $decrypted,
  673 + Core::ourStrlen($decrypted)
  674 + );
  675 +
  676 + /* Increment the IV by the amount of blocks in a buffer. */
  677 + /** @var string $thisIv */
  678 + $thisIv = Core::incrementCounter($thisIv, $inc);
  679 + /* WARNING: Usually, unless the file is a multiple of the buffer
  680 + * size, $thisIv will contain an incorrect value here on the last
  681 + * iteration of this loop. */
  682 + }
  683 + }
  684 +
  685 + /**
  686 + * Read from a stream; prevent partial reads.
  687 + *
  688 + * @param resource $stream
  689 + * @param int $num_bytes
  690 + * @return string
  691 + *
  692 + * @throws Ex\IOException
  693 + * @throws Ex\EnvironmentIsBrokenException
  694 + *
  695 + * @return string
  696 + */
  697 + public static function readBytes($stream, $num_bytes)
  698 + {
  699 + if ($num_bytes < 0) {
  700 + throw new Ex\EnvironmentIsBrokenException(
  701 + 'Tried to read less than 0 bytes'
  702 + );
  703 + } elseif ($num_bytes === 0) {
  704 + return '';
  705 + }
  706 + $buf = '';
  707 + $remaining = $num_bytes;
  708 + while ($remaining > 0 && ! \feof($stream)) {
  709 + /** @var string $read */
  710 + $read = \fread($stream, $remaining);
  711 + if (!\is_string($read)) {
  712 + throw new Ex\IOException(
  713 + 'Could not read from the file'
  714 + );
  715 + }
  716 + $buf .= $read;
  717 + $remaining -= Core::ourStrlen($read);
  718 + }
  719 + if (Core::ourStrlen($buf) !== $num_bytes) {
  720 + throw new Ex\IOException(
  721 + 'Tried to read past the end of the file'
  722 + );
  723 + }
  724 + return $buf;
  725 + }
  726 +
  727 + /**
  728 + * Write to a stream; prevents partial writes.
  729 + *
  730 + * @param resource $stream
  731 + * @param string $buf
  732 + * @param int $num_bytes
  733 + * @return int
  734 + *
  735 + * @throws Ex\IOException
  736 + *
  737 + * @return string
  738 + */
  739 + public static function writeBytes($stream, $buf, $num_bytes = null)
  740 + {
  741 + $bufSize = Core::ourStrlen($buf);
  742 + if ($num_bytes === null) {
  743 + $num_bytes = $bufSize;
  744 + }
  745 + if ($num_bytes > $bufSize) {
  746 + throw new Ex\IOException(
  747 + 'Trying to write more bytes than the buffer contains.'
  748 + );
  749 + }
  750 + if ($num_bytes < 0) {
  751 + throw new Ex\IOException(
  752 + 'Tried to write less than 0 bytes'
  753 + );
  754 + }
  755 + $remaining = $num_bytes;
  756 + while ($remaining > 0) {
  757 + /** @var int $written */
  758 + $written = \fwrite($stream, $buf, $remaining);
  759 + if (!\is_int($written)) {
  760 + throw new Ex\IOException(
  761 + 'Could not write to the file'
  762 + );
  763 + }
  764 + $buf = (string) Core::ourSubstr($buf, $written, null);
  765 + $remaining -= $written;
  766 + }
  767 + return $num_bytes;
  768 + }
  769 +
  770 + /**
  771 + * Returns the last PHP error's or warning's message string.
  772 + *
  773 + * @return string
  774 + */
  775 + private static function getLastErrorMessage()
  776 + {
  777 + $error = error_get_last();
  778 + if ($error === null) {
  779 + return '[no PHP error]';
  780 + } else {
  781 + return $error['message'];
  782 + }
  783 + }
  784 +}
... ...
pacotes/composer/vendor/defuse/php-encryption/src/Key.php 0 → 100644
... ... @@ -0,0 +1,95 @@
  1 +<?php
  2 +
  3 +namespace Defuse\Crypto;
  4 +
  5 +use Defuse\Crypto\Exception as Ex;
  6 +
  7 +final class Key
  8 +{
  9 + const KEY_CURRENT_VERSION = "\xDE\xF0\x00\x00";
  10 + const KEY_BYTE_SIZE = 32;
  11 +
  12 + /**
  13 + * @var string
  14 + */
  15 + private $key_bytes;
  16 +
  17 + /**
  18 + * Creates new random key.
  19 + *
  20 + * @throws Ex\EnvironmentIsBrokenException
  21 + *
  22 + * @return Key
  23 + */
  24 + public static function createNewRandomKey()
  25 + {
  26 + return new Key(Core::secureRandom(self::KEY_BYTE_SIZE));
  27 + }
  28 +
  29 + /**
  30 + * Loads a Key from its encoded form.
  31 + *
  32 + * By default, this function will call Encoding::trimTrailingWhitespace()
  33 + * to remove trailing CR, LF, NUL, TAB, and SPACE characters, which are
  34 + * commonly appended to files when working with text editors.
  35 + *
  36 + * @param string $saved_key_string
  37 + * @param bool $do_not_trim (default: false)
  38 + *
  39 + * @throws Ex\BadFormatException
  40 + * @throws Ex\EnvironmentIsBrokenException
  41 + *
  42 + * @return Key
  43 + */
  44 + public static function loadFromAsciiSafeString($saved_key_string, $do_not_trim = false)
  45 + {
  46 + if (!$do_not_trim) {
  47 + $saved_key_string = Encoding::trimTrailingWhitespace($saved_key_string);
  48 + }
  49 + $key_bytes = Encoding::loadBytesFromChecksummedAsciiSafeString(self::KEY_CURRENT_VERSION, $saved_key_string);
  50 + return new Key($key_bytes);
  51 + }
  52 +
  53 + /**
  54 + * Encodes the Key into a string of printable ASCII characters.
  55 + *
  56 + * @throws Ex\EnvironmentIsBrokenException
  57 + *
  58 + * @return string
  59 + */
  60 + public function saveToAsciiSafeString()
  61 + {
  62 + return Encoding::saveBytesToChecksummedAsciiSafeString(
  63 + self::KEY_CURRENT_VERSION,
  64 + $this->key_bytes
  65 + );
  66 + }
  67 +
  68 + /**
  69 + * Gets the raw bytes of the key.
  70 + *
  71 + * @return string
  72 + */
  73 + public function getRawBytes()
  74 + {
  75 + return $this->key_bytes;
  76 + }
  77 +
  78 + /**
  79 + * Constructs a new Key object from a string of raw bytes.
  80 + *
  81 + * @param string $bytes
  82 + *
  83 + * @throws Ex\EnvironmentIsBrokenException
  84 + */
  85 + private function __construct($bytes)
  86 + {
  87 + if (Core::ourStrlen($bytes) !== self::KEY_BYTE_SIZE) {
  88 + throw new Ex\EnvironmentIsBrokenException(
  89 + 'Bad key length.'
  90 + );
  91 + }
  92 + $this->key_bytes = $bytes;
  93 + }
  94 +
  95 +}
... ...
pacotes/composer/vendor/defuse/php-encryption/src/KeyOrPassword.php 0 → 100644
... ... @@ -0,0 +1,133 @@
  1 +<?php
  2 +
  3 +namespace Defuse\Crypto;
  4 +
  5 +use Defuse\Crypto\Exception as Ex;
  6 +
  7 +final class KeyOrPassword
  8 +{
  9 + const PBKDF2_ITERATIONS = 100000;
  10 + const SECRET_TYPE_KEY = 1;
  11 + const SECRET_TYPE_PASSWORD = 2;
  12 +
  13 + /**
  14 + * @var int
  15 + */
  16 + private $secret_type = 0;
  17 +
  18 + /**
  19 + * @var Key|string
  20 + */
  21 + private $secret;
  22 +
  23 + /**
  24 + * Initializes an instance of KeyOrPassword from a key.
  25 + *
  26 + * @param Key $key
  27 + *
  28 + * @return KeyOrPassword
  29 + */
  30 + public static function createFromKey(Key $key)
  31 + {
  32 + return new KeyOrPassword(self::SECRET_TYPE_KEY, $key);
  33 + }
  34 +
  35 + /**
  36 + * Initializes an instance of KeyOrPassword from a password.
  37 + *
  38 + * @param string $password
  39 + *
  40 + * @return KeyOrPassword
  41 + */
  42 + public static function createFromPassword($password)
  43 + {
  44 + return new KeyOrPassword(self::SECRET_TYPE_PASSWORD, $password);
  45 + }
  46 +
  47 + /**
  48 + * Derives authentication and encryption keys from the secret, using a slow
  49 + * key derivation function if the secret is a password.
  50 + *
  51 + * @param string $salt
  52 + *
  53 + * @throws Ex\CryptoException
  54 + * @throws Ex\EnvironmentIsBrokenException
  55 + *
  56 + * @return DerivedKeys
  57 + */
  58 + public function deriveKeys($salt)
  59 + {
  60 + if (Core::ourStrlen($salt) !== Core::SALT_BYTE_SIZE) {
  61 + throw new Ex\EnvironmentIsBrokenException('Bad salt.');
  62 + }
  63 +
  64 + if ($this->secret_type === self::SECRET_TYPE_KEY) {
  65 + if (!($this->secret instanceof Key)) {
  66 + throw new Ex\CryptoException('Expected a Key object');
  67 + }
  68 + $akey = Core::HKDF(
  69 + Core::HASH_FUNCTION_NAME,
  70 + $this->secret->getRawBytes(),
  71 + Core::KEY_BYTE_SIZE,
  72 + Core::AUTHENTICATION_INFO_STRING,
  73 + $salt
  74 + );
  75 + $ekey = Core::HKDF(
  76 + Core::HASH_FUNCTION_NAME,
  77 + $this->secret->getRawBytes(),
  78 + Core::KEY_BYTE_SIZE,
  79 + Core::ENCRYPTION_INFO_STRING,
  80 + $salt
  81 + );
  82 + return new DerivedKeys($akey, $ekey);
  83 + } elseif ($this->secret_type === self::SECRET_TYPE_PASSWORD) {
  84 + if (!\is_string($this->secret)) {
  85 + throw new Ex\CryptoException('Expected a string');
  86 + }
  87 + /* Our PBKDF2 polyfill is vulnerable to a DoS attack documented in
  88 + * GitHub issue #230. The fix is to pre-hash the password to ensure
  89 + * it is short. We do the prehashing here instead of in pbkdf2() so
  90 + * that pbkdf2() still computes the function as defined by the
  91 + * standard. */
  92 + $prehash = \hash(Core::HASH_FUNCTION_NAME, $this->secret, true);
  93 + $prekey = Core::pbkdf2(
  94 + Core::HASH_FUNCTION_NAME,
  95 + $prehash,
  96 + $salt,
  97 + self::PBKDF2_ITERATIONS,
  98 + Core::KEY_BYTE_SIZE,
  99 + true
  100 + );
  101 + $akey = Core::HKDF(
  102 + Core::HASH_FUNCTION_NAME,
  103 + $prekey,
  104 + Core::KEY_BYTE_SIZE,
  105 + Core::AUTHENTICATION_INFO_STRING,
  106 + $salt
  107 + );
  108 + /* Note the cryptographic re-use of $salt here. */
  109 + $ekey = Core::HKDF(
  110 + Core::HASH_FUNCTION_NAME,
  111 + $prekey,
  112 + Core::KEY_BYTE_SIZE,
  113 + Core::ENCRYPTION_INFO_STRING,
  114 + $salt
  115 + );
  116 + return new DerivedKeys($akey, $ekey);
  117 + } else {
  118 + throw new Ex\EnvironmentIsBrokenException('Bad secret type.');
  119 + }
  120 + }
  121 +
  122 + /**
  123 + * Constructor for KeyOrPassword.
  124 + *
  125 + * @param int $secret_type
  126 + * @param mixed $secret (either a Key or a password string)
  127 + */
  128 + private function __construct($secret_type, $secret)
  129 + {
  130 + $this->secret_type = $secret_type;
  131 + $this->secret = $secret;
  132 + }
  133 +}
... ...
pacotes/composer/vendor/defuse/php-encryption/src/KeyProtectedByPassword.php 0 → 100644
... ... @@ -0,0 +1,115 @@
  1 +<?php
  2 +
  3 +namespace Defuse\Crypto;
  4 +
  5 +use Defuse\Crypto\Exception as Ex;
  6 +
  7 +final class KeyProtectedByPassword
  8 +{
  9 + const PASSWORD_KEY_CURRENT_VERSION = "\xDE\xF1\x00\x00";
  10 +
  11 + /**
  12 + * @var string
  13 + */
  14 + private $encrypted_key = '';
  15 +
  16 + /**
  17 + * Creates a random key protected by the provided password.
  18 + *
  19 + * @param string $password
  20 + *
  21 + * @throws Ex\EnvironmentIsBrokenException
  22 + *
  23 + * @return KeyProtectedByPassword
  24 + */
  25 + public static function createRandomPasswordProtectedKey($password)
  26 + {
  27 + $inner_key = Key::createNewRandomKey();
  28 + /* The password is hashed as a form of poor-man's domain separation
  29 + * between this use of encryptWithPassword() and other uses of
  30 + * encryptWithPassword() that the user may also be using as part of the
  31 + * same protocol. */
  32 + $encrypted_key = Crypto::encryptWithPassword(
  33 + $inner_key->saveToAsciiSafeString(),
  34 + \hash(Core::HASH_FUNCTION_NAME, $password, true),
  35 + true
  36 + );
  37 +
  38 + return new KeyProtectedByPassword($encrypted_key);
  39 + }
  40 +
  41 + /**
  42 + * Loads a KeyProtectedByPassword from its encoded form.
  43 + *
  44 + * @param string $saved_key_string
  45 + *
  46 + * @throws Ex\BadFormatException
  47 + *
  48 + * @return KeyProtectedByPassword
  49 + */
  50 + public static function loadFromAsciiSafeString($saved_key_string)
  51 + {
  52 + $encrypted_key = Encoding::loadBytesFromChecksummedAsciiSafeString(
  53 + self::PASSWORD_KEY_CURRENT_VERSION,
  54 + $saved_key_string
  55 + );
  56 + return new KeyProtectedByPassword($encrypted_key);
  57 + }
  58 +
  59 + /**
  60 + * Encodes the KeyProtectedByPassword into a string of printable ASCII
  61 + * characters.
  62 + *
  63 + * @throws Ex\EnvironmentIsBrokenException
  64 + *
  65 + * @return string
  66 + */
  67 + public function saveToAsciiSafeString()
  68 + {
  69 + return Encoding::saveBytesToChecksummedAsciiSafeString(
  70 + self::PASSWORD_KEY_CURRENT_VERSION,
  71 + $this->encrypted_key
  72 + );
  73 + }
  74 +
  75 + /**
  76 + * Decrypts the protected key, returning an unprotected Key object that can
  77 + * be used for encryption and decryption.
  78 + *
  79 + * @throws Ex\EnvironmentIsBrokenException
  80 + * @throws Ex\WrongKeyOrModifiedCiphertextException
  81 + *
  82 + * @return Key
  83 + */
  84 + public function unlockKey($password)
  85 + {
  86 + try {
  87 + $inner_key_encoded = Crypto::decryptWithPassword(
  88 + $this->encrypted_key,
  89 + \hash(Core::HASH_FUNCTION_NAME, $password, true),
  90 + true
  91 + );
  92 + return Key::loadFromAsciiSafeString($inner_key_encoded);
  93 + } catch (Ex\BadFormatException $ex) {
  94 + /* This should never happen unless an attacker replaced the
  95 + * encrypted key ciphertext with some other ciphertext that was
  96 + * encrypted with the same password. We transform the exception type
  97 + * here in order to make the API simpler, avoiding the need to
  98 + * document that this method might throw an Ex\BadFormatException. */
  99 + throw new Ex\WrongKeyOrModifiedCiphertextException(
  100 + "The decrypted key was found to be in an invalid format. " .
  101 + "This very likely indicates it was modified by an attacker."
  102 + );
  103 + }
  104 + }
  105 +
  106 + /**
  107 + * Constructor for KeyProtectedByPassword.
  108 + *
  109 + * @param string $encrypted_key
  110 + */
  111 + private function __construct($encrypted_key)
  112 + {
  113 + $this->encrypted_key = $encrypted_key;
  114 + }
  115 +}
... ...
pacotes/composer/vendor/defuse/php-encryption/src/RuntimeTests.php 0 → 100644
... ... @@ -0,0 +1,247 @@
  1 +<?php
  2 +
  3 +namespace Defuse\Crypto;
  4 +
  5 +use Defuse\Crypto\Exception as Ex;
  6 +
  7 +/*
  8 + * We're using static class inheritance to get access to protected methods
  9 + * inside Crypto. To make it easy to know where the method we're calling can be
  10 + * found, within this file, prefix calls with `Crypto::` or `RuntimeTests::`,
  11 + * and don't use `self::`.
  12 + */
  13 +
  14 +class RuntimeTests extends Crypto
  15 +{
  16 + /**
  17 + * Runs the runtime tests.
  18 + *
  19 + * @throws Ex\EnvironmentIsBrokenException
  20 + * @return void
  21 + */
  22 + public static function runtimeTest()
  23 + {
  24 + // 0: Tests haven't been run yet.
  25 + // 1: Tests have passed.
  26 + // 2: Tests are running right now.
  27 + // 3: Tests have failed.
  28 + static $test_state = 0;
  29 +
  30 + if ($test_state === 1 || $test_state === 2) {
  31 + return;
  32 + }
  33 +
  34 + if ($test_state === 3) {
  35 + /* If an intermittent problem caused a test to fail previously, we
  36 + * want that to be indicated to the user with every call to this
  37 + * library. This way, if the user first does something they really
  38 + * don't care about, and just ignores all exceptions, they won't get
  39 + * screwed when they then start to use the library for something
  40 + * they do care about. */
  41 + throw new Ex\EnvironmentIsBrokenException('Tests failed previously.');
  42 + }
  43 +
  44 + try {
  45 + $test_state = 2;
  46 +
  47 + Core::ensureFunctionExists('openssl_get_cipher_methods');
  48 + if (\in_array(Core::CIPHER_METHOD, \openssl_get_cipher_methods()) === false) {
  49 + throw new Ex\EnvironmentIsBrokenException(
  50 + 'Cipher method not supported. This is normally caused by an outdated ' .
  51 + 'version of OpenSSL (and/or OpenSSL compiled for FIPS compliance). ' .
  52 + 'Please upgrade to a newer version of OpenSSL that supports ' .
  53 + Core::CIPHER_METHOD . ' to use this library.'
  54 + );
  55 + }
  56 +
  57 + RuntimeTests::AESTestVector();
  58 + RuntimeTests::HMACTestVector();
  59 + RuntimeTests::HKDFTestVector();
  60 +
  61 + RuntimeTests::testEncryptDecrypt();
  62 + if (Core::ourStrlen(Key::createNewRandomKey()->getRawBytes()) != Core::KEY_BYTE_SIZE) {
  63 + throw new Ex\EnvironmentIsBrokenException();
  64 + }
  65 +
  66 + if (Core::ENCRYPTION_INFO_STRING == Core::AUTHENTICATION_INFO_STRING) {
  67 + throw new Ex\EnvironmentIsBrokenException();
  68 + }
  69 + } catch (Ex\EnvironmentIsBrokenException $ex) {
  70 + // Do this, otherwise it will stay in the "tests are running" state.
  71 + $test_state = 3;
  72 + throw $ex;
  73 + }
  74 +
  75 + // Change this to '0' make the tests always re-run (for benchmarking).
  76 + $test_state = 1;
  77 + }
  78 +
  79 + /**
  80 + * High-level tests of Crypto operations.
  81 + *
  82 + * @throws Ex\EnvironmentIsBrokenException
  83 + * @return void
  84 + */
  85 + private static function testEncryptDecrypt()
  86 + {
  87 + $key = Key::createNewRandomKey();
  88 + $data = "EnCrYpT EvErYThInG\x00\x00";
  89 +
  90 + // Make sure encrypting then decrypting doesn't change the message.
  91 + $ciphertext = Crypto::encrypt($data, $key, true);
  92 + try {
  93 + $decrypted = Crypto::decrypt($ciphertext, $key, true);
  94 + } catch (Ex\WrongKeyOrModifiedCiphertextException $ex) {
  95 + // It's important to catch this and change it into a
  96 + // Ex\EnvironmentIsBrokenException, otherwise a test failure could trick
  97 + // the user into thinking it's just an invalid ciphertext!
  98 + throw new Ex\EnvironmentIsBrokenException();
  99 + }
  100 + if ($decrypted !== $data) {
  101 + throw new Ex\EnvironmentIsBrokenException();
  102 + }
  103 +
  104 + // Modifying the ciphertext: Appending a string.
  105 + try {
  106 + Crypto::decrypt($ciphertext . 'a', $key, true);
  107 + throw new Ex\EnvironmentIsBrokenException();
  108 + } catch (Ex\WrongKeyOrModifiedCiphertextException $e) { /* expected */
  109 + }
  110 +
  111 + // Modifying the ciphertext: Changing an HMAC byte.
  112 + $indices_to_change = [
  113 + 0, // The header.
  114 + Core::HEADER_VERSION_SIZE + 1, // the salt
  115 + Core::HEADER_VERSION_SIZE + Core::SALT_BYTE_SIZE + 1, // the IV
  116 + Core::HEADER_VERSION_SIZE + Core::SALT_BYTE_SIZE + Core::BLOCK_BYTE_SIZE + 1, // the ciphertext
  117 + ];
  118 +
  119 + foreach ($indices_to_change as $index) {
  120 + try {
  121 + $ciphertext[$index] = \chr((\ord($ciphertext[$index]) + 1) % 256);
  122 + Crypto::decrypt($ciphertext, $key, true);
  123 + throw new Ex\EnvironmentIsBrokenException();
  124 + } catch (Ex\WrongKeyOrModifiedCiphertextException $e) { /* expected */
  125 + }
  126 + }
  127 +
  128 + // Decrypting with the wrong key.
  129 + $key = Key::createNewRandomKey();
  130 + $data = 'abcdef';
  131 + $ciphertext = Crypto::encrypt($data, $key, true);
  132 + $wrong_key = Key::createNewRandomKey();
  133 + try {
  134 + Crypto::decrypt($ciphertext, $wrong_key, true);
  135 + throw new Ex\EnvironmentIsBrokenException();
  136 + } catch (Ex\WrongKeyOrModifiedCiphertextException $e) { /* expected */
  137 + }
  138 +
  139 + // Ciphertext too small.
  140 + $key = Key::createNewRandomKey();
  141 + $ciphertext = \str_repeat('A', Core::MINIMUM_CIPHERTEXT_SIZE - 1);
  142 + try {
  143 + Crypto::decrypt($ciphertext, $key, true);
  144 + throw new Ex\EnvironmentIsBrokenException();
  145 + } catch (Ex\WrongKeyOrModifiedCiphertextException $e) { /* expected */
  146 + }
  147 + }
  148 +
  149 + /**
  150 + * Test HKDF against test vectors.
  151 + *
  152 + * @throws Ex\EnvironmentIsBrokenException
  153 + * @return void
  154 + */
  155 + private static function HKDFTestVector()
  156 + {
  157 + // HKDF test vectors from RFC 5869
  158 +
  159 + // Test Case 1
  160 + $ikm = \str_repeat("\x0b", 22);
  161 + $salt = Encoding::hexToBin('000102030405060708090a0b0c');
  162 + $info = Encoding::hexToBin('f0f1f2f3f4f5f6f7f8f9');
  163 + $length = 42;
  164 + $okm = Encoding::hexToBin(
  165 + '3cb25f25faacd57a90434f64d0362f2a' .
  166 + '2d2d0a90cf1a5a4c5db02d56ecc4c5bf' .
  167 + '34007208d5b887185865'
  168 + );
  169 + $computed_okm = Core::HKDF('sha256', $ikm, $length, $info, $salt);
  170 + if ($computed_okm !== $okm) {
  171 + throw new Ex\EnvironmentIsBrokenException();
  172 + }
  173 +
  174 + // Test Case 7
  175 + $ikm = \str_repeat("\x0c", 22);
  176 + $length = 42;
  177 + $okm = Encoding::hexToBin(
  178 + '2c91117204d745f3500d636a62f64f0a' .
  179 + 'b3bae548aa53d423b0d1f27ebba6f5e5' .
  180 + '673a081d70cce7acfc48'
  181 + );
  182 + $computed_okm = Core::HKDF('sha1', $ikm, $length, '', null);
  183 + if ($computed_okm !== $okm) {
  184 + throw new Ex\EnvironmentIsBrokenException();
  185 + }
  186 + }
  187 +
  188 + /**
  189 + * Test HMAC against test vectors.
  190 + *
  191 + * @throws Ex\EnvironmentIsBrokenException
  192 + * @return void
  193 + */
  194 + private static function HMACTestVector()
  195 + {
  196 + // HMAC test vector From RFC 4231 (Test Case 1)
  197 + $key = \str_repeat("\x0b", 20);
  198 + $data = 'Hi There';
  199 + $correct = 'b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7';
  200 + if (\hash_hmac(Core::HASH_FUNCTION_NAME, $data, $key) !== $correct) {
  201 + throw new Ex\EnvironmentIsBrokenException();
  202 + }
  203 + }
  204 +
  205 + /**
  206 + * Test AES against test vectors.
  207 + *
  208 + * @throws Ex\EnvironmentIsBrokenException
  209 + * @return void
  210 + */
  211 + private static function AESTestVector()
  212 + {
  213 + // AES CTR mode test vector from NIST SP 800-38A
  214 + $key = Encoding::hexToBin(
  215 + '603deb1015ca71be2b73aef0857d7781' .
  216 + '1f352c073b6108d72d9810a30914dff4'
  217 + );
  218 + $iv = Encoding::hexToBin('f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff');
  219 + $plaintext = Encoding::hexToBin(
  220 + '6bc1bee22e409f96e93d7e117393172a' .
  221 + 'ae2d8a571e03ac9c9eb76fac45af8e51' .
  222 + '30c81c46a35ce411e5fbc1191a0a52ef' .
  223 + 'f69f2445df4f9b17ad2b417be66c3710'
  224 + );
  225 + $ciphertext = Encoding::hexToBin(
  226 + '601ec313775789a5b7a7f504bbf3d228' .
  227 + 'f443e3ca4d62b59aca84e990cacaf5c5' .
  228 + '2b0930daa23de94ce87017ba2d84988d' .
  229 + 'dfc9c58db67aada613c2dd08457941a6'
  230 + );
  231 +
  232 + $computed_ciphertext = Crypto::plainEncrypt($plaintext, $key, $iv);
  233 + if ($computed_ciphertext !== $ciphertext) {
  234 + echo \str_repeat("\n", 30);
  235 + echo \bin2hex($computed_ciphertext);
  236 + echo "\n---\n";
  237 + echo \bin2hex($ciphertext);
  238 + echo \str_repeat("\n", 30);
  239 + throw new Ex\EnvironmentIsBrokenException();
  240 + }
  241 +
  242 + $computed_plaintext = Crypto::plainDecrypt($ciphertext, $key, $iv, Core::CIPHER_METHOD);
  243 + if ($computed_plaintext !== $plaintext) {
  244 + throw new Ex\EnvironmentIsBrokenException();
  245 + }
  246 + }
  247 +}
... ...
pacotes/composer/vendor/paragonie/random_compat/LICENSE 0 → 100644
... ... @@ -0,0 +1,22 @@
  1 +The MIT License (MIT)
  2 +
  3 +Copyright (c) 2015 Paragon Initiative Enterprises
  4 +
  5 +Permission is hereby granted, free of charge, to any person obtaining a copy
  6 +of this software and associated documentation files (the "Software"), to deal
  7 +in the Software without restriction, including without limitation the rights
  8 +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9 +copies of the Software, and to permit persons to whom the Software is
  10 +furnished to do so, subject to the following conditions:
  11 +
  12 +The above copyright notice and this permission notice shall be included in all
  13 +copies or substantial portions of the Software.
  14 +
  15 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17 +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18 +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19 +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20 +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21 +SOFTWARE.
  22 +
... ...
pacotes/composer/vendor/paragonie/random_compat/build-phar.sh 0 → 100755
... ... @@ -0,0 +1,5 @@
  1 +#!/usr/bin/env bash
  2 +
  3 +basedir=$( dirname $( readlink -f ${BASH_SOURCE[0]} ) )
  4 +
  5 +php -dphar.readonly=0 "$basedir/other/build_phar.php" $*
0 6 \ No newline at end of file
... ...
pacotes/composer/vendor/paragonie/random_compat/composer.json 0 → 100644
... ... @@ -0,0 +1,37 @@
  1 +{
  2 + "name": "paragonie/random_compat",
  3 + "description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7",
  4 + "keywords": [
  5 + "csprng",
  6 + "random",
  7 + "pseudorandom"
  8 + ],
  9 + "license": "MIT",
  10 + "type": "library",
  11 + "authors": [
  12 + {
  13 + "name": "Paragon Initiative Enterprises",
  14 + "email": "security@paragonie.com",
  15 + "homepage": "https://paragonie.com"
  16 + }
  17 + ],
  18 + "support": {
  19 + "issues": "https://github.com/paragonie/random_compat/issues",
  20 + "email": "info@paragonie.com",
  21 + "source": "https://github.com/paragonie/random_compat"
  22 + },
  23 + "require": {
  24 + "php": ">=5.2.0"
  25 + },
  26 + "require-dev": {
  27 + "phpunit/phpunit": "4.*|5.*"
  28 + },
  29 + "suggest": {
  30 + "ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes."
  31 + },
  32 + "autoload": {
  33 + "files": [
  34 + "lib/random.php"
  35 + ]
  36 + }
  37 +}
... ...
pacotes/composer/vendor/paragonie/random_compat/dist/random_compat.phar.pubkey 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +-----BEGIN PUBLIC KEY-----
  2 +MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEEd+wCqJDrx5B4OldM0dQE0ZMX+lx1ZWm
  3 +pui0SUqD4G29L3NGsz9UhJ/0HjBdbnkhIK5xviT0X5vtjacF6ajgcCArbTB+ds+p
  4 ++h7Q084NuSuIpNb6YPfoUFgC/CL9kAoc
  5 +-----END PUBLIC KEY-----
... ...
pacotes/composer/vendor/paragonie/random_compat/dist/random_compat.phar.pubkey.asc 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +-----BEGIN PGP SIGNATURE-----
  2 +Version: GnuPG v2.0.22 (MingW32)
  3 +
  4 +iQEcBAABAgAGBQJWtW1hAAoJEGuXocKCZATaJf0H+wbZGgskK1dcRTsuVJl9IWip
  5 +QwGw/qIKI280SD6/ckoUMxKDCJiFuPR14zmqnS36k7N5UNPnpdTJTS8T11jttSpg
  6 +1LCmgpbEIpgaTah+cELDqFCav99fS+bEiAL5lWDAHBTE/XPjGVCqeehyPYref4IW
  7 +NDBIEsvnHPHPLsn6X5jq4+Yj5oUixgxaMPiR+bcO4Sh+RzOVB6i2D0upWfRXBFXA
  8 +NNnsg9/zjvoC7ZW73y9uSH+dPJTt/Vgfeiv52/v41XliyzbUyLalf02GNPY+9goV
  9 +JHG1ulEEBJOCiUD9cE1PUIJwHA/HqyhHIvV350YoEFiHl8iSwm7SiZu5kPjaq74=
  10 +=B6+8
  11 +-----END PGP SIGNATURE-----
... ...
pacotes/composer/vendor/paragonie/random_compat/lib/byte_safe_strings.php 0 → 100644
... ... @@ -0,0 +1,181 @@
  1 +<?php
  2 +/**
  3 + * Random_* Compatibility Library
  4 + * for using the new PHP 7 random_* API in PHP 5 projects
  5 + *
  6 + * The MIT License (MIT)
  7 + *
  8 + * Copyright (c) 2015 - 2017 Paragon Initiative Enterprises
  9 + *
  10 + * Permission is hereby granted, free of charge, to any person obtaining a copy
  11 + * of this software and associated documentation files (the "Software"), to deal
  12 + * in the Software without restriction, including without limitation the rights
  13 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14 + * copies of the Software, and to permit persons to whom the Software is
  15 + * furnished to do so, subject to the following conditions:
  16 + *
  17 + * The above copyright notice and this permission notice shall be included in
  18 + * all copies or substantial portions of the Software.
  19 + *
  20 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  26 + * SOFTWARE.
  27 + */
  28 +
  29 +if (!is_callable('RandomCompat_strlen')) {
  30 + if (
  31 + defined('MB_OVERLOAD_STRING') &&
  32 + ini_get('mbstring.func_overload') & MB_OVERLOAD_STRING
  33 + ) {
  34 + /**
  35 + * strlen() implementation that isn't brittle to mbstring.func_overload
  36 + *
  37 + * This version uses mb_strlen() in '8bit' mode to treat strings as raw
  38 + * binary rather than UTF-8, ISO-8859-1, etc
  39 + *
  40 + * @param string $binary_string
  41 + *
  42 + * @throws TypeError
  43 + *
  44 + * @return int
  45 + */
  46 + function RandomCompat_strlen($binary_string)
  47 + {
  48 + if (!is_string($binary_string)) {
  49 + throw new TypeError(
  50 + 'RandomCompat_strlen() expects a string'
  51 + );
  52 + }
  53 +
  54 + return (int) mb_strlen($binary_string, '8bit');
  55 + }
  56 +
  57 + } else {
  58 + /**
  59 + * strlen() implementation that isn't brittle to mbstring.func_overload
  60 + *
  61 + * This version just used the default strlen()
  62 + *
  63 + * @param string $binary_string
  64 + *
  65 + * @throws TypeError
  66 + *
  67 + * @return int
  68 + */
  69 + function RandomCompat_strlen($binary_string)
  70 + {
  71 + if (!is_string($binary_string)) {
  72 + throw new TypeError(
  73 + 'RandomCompat_strlen() expects a string'
  74 + );
  75 + }
  76 + return (int) strlen($binary_string);
  77 + }
  78 + }
  79 +}
  80 +
  81 +if (!is_callable('RandomCompat_substr')) {
  82 +
  83 + if (
  84 + defined('MB_OVERLOAD_STRING')
  85 + &&
  86 + ini_get('mbstring.func_overload') & MB_OVERLOAD_STRING
  87 + ) {
  88 + /**
  89 + * substr() implementation that isn't brittle to mbstring.func_overload
  90 + *
  91 + * This version uses mb_substr() in '8bit' mode to treat strings as raw
  92 + * binary rather than UTF-8, ISO-8859-1, etc
  93 + *
  94 + * @param string $binary_string
  95 + * @param int $start
  96 + * @param int $length (optional)
  97 + *
  98 + * @throws TypeError
  99 + *
  100 + * @return string
  101 + */
  102 + function RandomCompat_substr($binary_string, $start, $length = null)
  103 + {
  104 + if (!is_string($binary_string)) {
  105 + throw new TypeError(
  106 + 'RandomCompat_substr(): First argument should be a string'
  107 + );
  108 + }
  109 +
  110 + if (!is_int($start)) {
  111 + throw new TypeError(
  112 + 'RandomCompat_substr(): Second argument should be an integer'
  113 + );
  114 + }
  115 +
  116 + if ($length === null) {
  117 + /**
  118 + * mb_substr($str, 0, NULL, '8bit') returns an empty string on
  119 + * PHP 5.3, so we have to find the length ourselves.
  120 + */
  121 + $length = RandomCompat_strlen($binary_string) - $start;
  122 + } elseif (!is_int($length)) {
  123 + throw new TypeError(
  124 + 'RandomCompat_substr(): Third argument should be an integer, or omitted'
  125 + );
  126 + }
  127 +
  128 + // Consistency with PHP's behavior
  129 + if ($start === RandomCompat_strlen($binary_string) && $length === 0) {
  130 + return '';
  131 + }
  132 + if ($start > RandomCompat_strlen($binary_string)) {
  133 + return '';
  134 + }
  135 +
  136 + return (string) mb_substr($binary_string, $start, $length, '8bit');
  137 + }
  138 +
  139 + } else {
  140 +
  141 + /**
  142 + * substr() implementation that isn't brittle to mbstring.func_overload
  143 + *
  144 + * This version just uses the default substr()
  145 + *
  146 + * @param string $binary_string
  147 + * @param int $start
  148 + * @param int $length (optional)
  149 + *
  150 + * @throws TypeError
  151 + *
  152 + * @return string
  153 + */
  154 + function RandomCompat_substr($binary_string, $start, $length = null)
  155 + {
  156 + if (!is_string($binary_string)) {
  157 + throw new TypeError(
  158 + 'RandomCompat_substr(): First argument should be a string'
  159 + );
  160 + }
  161 +
  162 + if (!is_int($start)) {
  163 + throw new TypeError(
  164 + 'RandomCompat_substr(): Second argument should be an integer'
  165 + );
  166 + }
  167 +
  168 + if ($length !== null) {
  169 + if (!is_int($length)) {
  170 + throw new TypeError(
  171 + 'RandomCompat_substr(): Third argument should be an integer, or omitted'
  172 + );
  173 + }
  174 +
  175 + return (string) substr($binary_string, $start, $length);
  176 + }
  177 +
  178 + return (string) substr($binary_string, $start);
  179 + }
  180 + }
  181 +}
... ...
pacotes/composer/vendor/paragonie/random_compat/lib/cast_to_int.php 0 → 100644
... ... @@ -0,0 +1,74 @@
  1 +<?php
  2 +/**
  3 + * Random_* Compatibility Library
  4 + * for using the new PHP 7 random_* API in PHP 5 projects
  5 + *
  6 + * The MIT License (MIT)
  7 + *
  8 + * Copyright (c) 2015 - 2017 Paragon Initiative Enterprises
  9 + *
  10 + * Permission is hereby granted, free of charge, to any person obtaining a copy
  11 + * of this software and associated documentation files (the "Software"), to deal
  12 + * in the Software without restriction, including without limitation the rights
  13 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14 + * copies of the Software, and to permit persons to whom the Software is
  15 + * furnished to do so, subject to the following conditions:
  16 + *
  17 + * The above copyright notice and this permission notice shall be included in
  18 + * all copies or substantial portions of the Software.
  19 + *
  20 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  26 + * SOFTWARE.
  27 + */
  28 +
  29 +if (!is_callable('RandomCompat_intval')) {
  30 +
  31 + /**
  32 + * Cast to an integer if we can, safely.
  33 + *
  34 + * If you pass it a float in the range (~PHP_INT_MAX, PHP_INT_MAX)
  35 + * (non-inclusive), it will sanely cast it to an int. If you it's equal to
  36 + * ~PHP_INT_MAX or PHP_INT_MAX, we let it fail as not an integer. Floats
  37 + * lose precision, so the <= and => operators might accidentally let a float
  38 + * through.
  39 + *
  40 + * @param int|float $number The number we want to convert to an int
  41 + * @param boolean $fail_open Set to true to not throw an exception
  42 + *
  43 + * @return float|int
  44 + *
  45 + * @throws TypeError
  46 + */
  47 + function RandomCompat_intval($number, $fail_open = false)
  48 + {
  49 + if (is_int($number) || is_float($number)) {
  50 + $number += 0;
  51 + } elseif (is_numeric($number)) {
  52 + $number += 0;
  53 + }
  54 +
  55 + if (
  56 + is_float($number)
  57 + &&
  58 + $number > ~PHP_INT_MAX
  59 + &&
  60 + $number < PHP_INT_MAX
  61 + ) {
  62 + $number = (int) $number;
  63 + }
  64 +
  65 + if (is_int($number)) {
  66 + return (int) $number;
  67 + } elseif (!$fail_open) {
  68 + throw new TypeError(
  69 + 'Expected an integer.'
  70 + );
  71 + }
  72 + return $number;
  73 + }
  74 +}
... ...
pacotes/composer/vendor/paragonie/random_compat/lib/error_polyfill.php 0 → 100644
... ... @@ -0,0 +1,49 @@
  1 +<?php
  2 +/**
  3 + * Random_* Compatibility Library
  4 + * for using the new PHP 7 random_* API in PHP 5 projects
  5 + *
  6 + * The MIT License (MIT)
  7 + *
  8 + * Copyright (c) 2015 - 2017 Paragon Initiative Enterprises
  9 + *
  10 + * Permission is hereby granted, free of charge, to any person obtaining a copy
  11 + * of this software and associated documentation files (the "Software"), to deal
  12 + * in the Software without restriction, including without limitation the rights
  13 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14 + * copies of the Software, and to permit persons to whom the Software is
  15 + * furnished to do so, subject to the following conditions:
  16 + *
  17 + * The above copyright notice and this permission notice shall be included in
  18 + * all copies or substantial portions of the Software.
  19 + *
  20 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  26 + * SOFTWARE.
  27 + */
  28 +
  29 +if (!class_exists('Error', false)) {
  30 + // We can't really avoid making this extend Exception in PHP 5.
  31 + class Error extends Exception
  32 + {
  33 +
  34 + }
  35 +}
  36 +
  37 +if (!class_exists('TypeError', false)) {
  38 + if (is_subclass_of('Error', 'Exception')) {
  39 + class TypeError extends Error
  40 + {
  41 +
  42 + }
  43 + } else {
  44 + class TypeError extends Exception
  45 + {
  46 +
  47 + }
  48 + }
  49 +}
... ...
pacotes/composer/vendor/paragonie/random_compat/lib/random.php 0 → 100644
... ... @@ -0,0 +1,223 @@
  1 +<?php
  2 +/**
  3 + * Random_* Compatibility Library
  4 + * for using the new PHP 7 random_* API in PHP 5 projects
  5 + *
  6 + * @version 2.0.10
  7 + * @released 2017-03-13
  8 + *
  9 + * The MIT License (MIT)
  10 + *
  11 + * Copyright (c) 2015 - 2017 Paragon Initiative Enterprises
  12 + *
  13 + * Permission is hereby granted, free of charge, to any person obtaining a copy
  14 + * of this software and associated documentation files (the "Software"), to deal
  15 + * in the Software without restriction, including without limitation the rights
  16 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  17 + * copies of the Software, and to permit persons to whom the Software is
  18 + * furnished to do so, subject to the following conditions:
  19 + *
  20 + * The above copyright notice and this permission notice shall be included in
  21 + * all copies or substantial portions of the Software.
  22 + *
  23 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  24 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  25 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  26 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  27 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  28 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  29 + * SOFTWARE.
  30 + */
  31 +
  32 +if (!defined('PHP_VERSION_ID')) {
  33 + // This constant was introduced in PHP 5.2.7
  34 + $RandomCompatversion = array_map('intval', explode('.', PHP_VERSION));
  35 + define(
  36 + 'PHP_VERSION_ID',
  37 + $RandomCompatversion[0] * 10000
  38 + + $RandomCompatversion[1] * 100
  39 + + $RandomCompatversion[2]
  40 + );
  41 + $RandomCompatversion = null;
  42 +}
  43 +
  44 +/**
  45 + * PHP 7.0.0 and newer have these functions natively.
  46 + */
  47 +if (PHP_VERSION_ID >= 70000) {
  48 + return;
  49 +}
  50 +
  51 +if (!defined('RANDOM_COMPAT_READ_BUFFER')) {
  52 + define('RANDOM_COMPAT_READ_BUFFER', 8);
  53 +}
  54 +
  55 +$RandomCompatDIR = dirname(__FILE__);
  56 +
  57 +require_once $RandomCompatDIR . '/byte_safe_strings.php';
  58 +require_once $RandomCompatDIR . '/cast_to_int.php';
  59 +require_once $RandomCompatDIR . '/error_polyfill.php';
  60 +
  61 +if (!is_callable('random_bytes')) {
  62 + /**
  63 + * PHP 5.2.0 - 5.6.x way to implement random_bytes()
  64 + *
  65 + * We use conditional statements here to define the function in accordance
  66 + * to the operating environment. It's a micro-optimization.
  67 + *
  68 + * In order of preference:
  69 + * 1. Use libsodium if available.
  70 + * 2. fread() /dev/urandom if available (never on Windows)
  71 + * 3. mcrypt_create_iv($bytes, MCRYPT_DEV_URANDOM)
  72 + * 4. COM('CAPICOM.Utilities.1')->GetRandom()
  73 + *
  74 + * See RATIONALE.md for our reasoning behind this particular order
  75 + */
  76 + if (extension_loaded('libsodium')) {
  77 + // See random_bytes_libsodium.php
  78 + if (PHP_VERSION_ID >= 50300 && is_callable('\\Sodium\\randombytes_buf')) {
  79 + require_once $RandomCompatDIR . '/random_bytes_libsodium.php';
  80 + } elseif (method_exists('Sodium', 'randombytes_buf')) {
  81 + require_once $RandomCompatDIR . '/random_bytes_libsodium_legacy.php';
  82 + }
  83 + }
  84 +
  85 + /**
  86 + * Reading directly from /dev/urandom:
  87 + */
  88 + if (DIRECTORY_SEPARATOR === '/') {
  89 + // DIRECTORY_SEPARATOR === '/' on Unix-like OSes -- this is a fast
  90 + // way to exclude Windows.
  91 + $RandomCompatUrandom = true;
  92 + $RandomCompat_basedir = ini_get('open_basedir');
  93 +
  94 + if (!empty($RandomCompat_basedir)) {
  95 + $RandomCompat_open_basedir = explode(
  96 + PATH_SEPARATOR,
  97 + strtolower($RandomCompat_basedir)
  98 + );
  99 + $RandomCompatUrandom = (array() !== array_intersect(
  100 + array('/dev', '/dev/', '/dev/urandom'),
  101 + $RandomCompat_open_basedir
  102 + ));
  103 + $RandomCompat_open_basedir = null;
  104 + }
  105 +
  106 + if (
  107 + !is_callable('random_bytes')
  108 + &&
  109 + $RandomCompatUrandom
  110 + &&
  111 + @is_readable('/dev/urandom')
  112 + ) {
  113 + // Error suppression on is_readable() in case of an open_basedir
  114 + // or safe_mode failure. All we care about is whether or not we
  115 + // can read it at this point. If the PHP environment is going to
  116 + // panic over trying to see if the file can be read in the first
  117 + // place, that is not helpful to us here.
  118 +
  119 + // See random_bytes_dev_urandom.php
  120 + require_once $RandomCompatDIR . '/random_bytes_dev_urandom.php';
  121 + }
  122 + // Unset variables after use
  123 + $RandomCompat_basedir = null;
  124 + } else {
  125 + $RandomCompatUrandom = false;
  126 + }
  127 +
  128 + /**
  129 + * mcrypt_create_iv()
  130 + *
  131 + * We only want to use mcypt_create_iv() if:
  132 + *
  133 + * - random_bytes() hasn't already been defined
  134 + * - the mcrypt extensions is loaded
  135 + * - One of these two conditions is true:
  136 + * - We're on Windows (DIRECTORY_SEPARATOR !== '/')
  137 + * - We're not on Windows and /dev/urandom is readabale
  138 + * (i.e. we're not in a chroot jail)
  139 + * - Special case:
  140 + * - If we're not on Windows, but the PHP version is between
  141 + * 5.6.10 and 5.6.12, we don't want to use mcrypt. It will
  142 + * hang indefinitely. This is bad.
  143 + * - If we're on Windows, we want to use PHP >= 5.3.7 or else
  144 + * we get insufficient entropy errors.
  145 + */
  146 + if (
  147 + !is_callable('random_bytes')
  148 + &&
  149 + // Windows on PHP < 5.3.7 is broken, but non-Windows is not known to be.
  150 + (DIRECTORY_SEPARATOR === '/' || PHP_VERSION_ID >= 50307)
  151 + &&
  152 + // Prevent this code from hanging indefinitely on non-Windows;
  153 + // see https://bugs.php.net/bug.php?id=69833
  154 + (
  155 + DIRECTORY_SEPARATOR !== '/' ||
  156 + (PHP_VERSION_ID <= 50609 || PHP_VERSION_ID >= 50613)
  157 + )
  158 + &&
  159 + extension_loaded('mcrypt')
  160 + ) {
  161 + // See random_bytes_mcrypt.php
  162 + require_once $RandomCompatDIR . '/random_bytes_mcrypt.php';
  163 + }
  164 + $RandomCompatUrandom = null;
  165 +
  166 + /**
  167 + * This is a Windows-specific fallback, for when the mcrypt extension
  168 + * isn't loaded.
  169 + */
  170 + if (
  171 + !is_callable('random_bytes')
  172 + &&
  173 + extension_loaded('com_dotnet')
  174 + &&
  175 + class_exists('COM')
  176 + ) {
  177 + $RandomCompat_disabled_classes = preg_split(
  178 + '#\s*,\s*#',
  179 + strtolower(ini_get('disable_classes'))
  180 + );
  181 +
  182 + if (!in_array('com', $RandomCompat_disabled_classes)) {
  183 + try {
  184 + $RandomCompatCOMtest = new COM('CAPICOM.Utilities.1');
  185 + if (method_exists($RandomCompatCOMtest, 'GetRandom')) {
  186 + // See random_bytes_com_dotnet.php
  187 + require_once $RandomCompatDIR . '/random_bytes_com_dotnet.php';
  188 + }
  189 + } catch (com_exception $e) {
  190 + // Don't try to use it.
  191 + }
  192 + }
  193 + $RandomCompat_disabled_classes = null;
  194 + $RandomCompatCOMtest = null;
  195 + }
  196 +
  197 + /**
  198 + * throw new Exception
  199 + */
  200 + if (!is_callable('random_bytes')) {
  201 + /**
  202 + * We don't have any more options, so let's throw an exception right now
  203 + * and hope the developer won't let it fail silently.
  204 + *
  205 + * @param mixed $length
  206 + * @return void
  207 + * @throws Exception
  208 + */
  209 + function random_bytes($length)
  210 + {
  211 + unset($length); // Suppress "variable not used" warnings.
  212 + throw new Exception(
  213 + 'There is no suitable CSPRNG installed on your system'
  214 + );
  215 + }
  216 + }
  217 +}
  218 +
  219 +if (!is_callable('random_int')) {
  220 + require_once $RandomCompatDIR . '/random_int.php';
  221 +}
  222 +
  223 +$RandomCompatDIR = null;
... ...
pacotes/composer/vendor/paragonie/random_compat/lib/random_bytes_com_dotnet.php 0 → 100644
... ... @@ -0,0 +1,88 @@
  1 +<?php
  2 +/**
  3 + * Random_* Compatibility Library
  4 + * for using the new PHP 7 random_* API in PHP 5 projects
  5 + *
  6 + * The MIT License (MIT)
  7 + *
  8 + * Copyright (c) 2015 - 2017 Paragon Initiative Enterprises
  9 + *
  10 + * Permission is hereby granted, free of charge, to any person obtaining a copy
  11 + * of this software and associated documentation files (the "Software"), to deal
  12 + * in the Software without restriction, including without limitation the rights
  13 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14 + * copies of the Software, and to permit persons to whom the Software is
  15 + * furnished to do so, subject to the following conditions:
  16 + *
  17 + * The above copyright notice and this permission notice shall be included in
  18 + * all copies or substantial portions of the Software.
  19 + *
  20 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  26 + * SOFTWARE.
  27 + */
  28 +
  29 +if (!is_callable('random_bytes')) {
  30 + /**
  31 + * Windows with PHP < 5.3.0 will not have the function
  32 + * openssl_random_pseudo_bytes() available, so let's use
  33 + * CAPICOM to work around this deficiency.
  34 + *
  35 + * @param int $bytes
  36 + *
  37 + * @throws Exception
  38 + *
  39 + * @return string
  40 + */
  41 + function random_bytes($bytes)
  42 + {
  43 + try {
  44 + $bytes = RandomCompat_intval($bytes);
  45 + } catch (TypeError $ex) {
  46 + throw new TypeError(
  47 + 'random_bytes(): $bytes must be an integer'
  48 + );
  49 + }
  50 +
  51 + if ($bytes < 1) {
  52 + throw new Error(
  53 + 'Length must be greater than 0'
  54 + );
  55 + }
  56 +
  57 + $buf = '';
  58 + if (!class_exists('COM')) {
  59 + throw new Error(
  60 + 'COM does not exist'
  61 + );
  62 + }
  63 + $util = new COM('CAPICOM.Utilities.1');
  64 + $execCount = 0;
  65 +
  66 + /**
  67 + * Let's not let it loop forever. If we run N times and fail to
  68 + * get N bytes of random data, then CAPICOM has failed us.
  69 + */
  70 + do {
  71 + $buf .= base64_decode($util->GetRandom($bytes, 0));
  72 + if (RandomCompat_strlen($buf) >= $bytes) {
  73 + /**
  74 + * Return our random entropy buffer here:
  75 + */
  76 + return RandomCompat_substr($buf, 0, $bytes);
  77 + }
  78 + ++$execCount;
  79 + } while ($execCount < $bytes);
  80 +
  81 + /**
  82 + * If we reach here, PHP has failed us.
  83 + */
  84 + throw new Exception(
  85 + 'Could not gather sufficient random data'
  86 + );
  87 + }
  88 +}
0 89 \ No newline at end of file
... ...
pacotes/composer/vendor/paragonie/random_compat/lib/random_bytes_dev_urandom.php 0 → 100644
... ... @@ -0,0 +1,167 @@
  1 +<?php
  2 +/**
  3 + * Random_* Compatibility Library
  4 + * for using the new PHP 7 random_* API in PHP 5 projects
  5 + *
  6 + * The MIT License (MIT)
  7 + *
  8 + * Copyright (c) 2015 - 2017 Paragon Initiative Enterprises
  9 + *
  10 + * Permission is hereby granted, free of charge, to any person obtaining a copy
  11 + * of this software and associated documentation files (the "Software"), to deal
  12 + * in the Software without restriction, including without limitation the rights
  13 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14 + * copies of the Software, and to permit persons to whom the Software is
  15 + * furnished to do so, subject to the following conditions:
  16 + *
  17 + * The above copyright notice and this permission notice shall be included in
  18 + * all copies or substantial portions of the Software.
  19 + *
  20 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  26 + * SOFTWARE.
  27 + */
  28 +
  29 +if (!defined('RANDOM_COMPAT_READ_BUFFER')) {
  30 + define('RANDOM_COMPAT_READ_BUFFER', 8);
  31 +}
  32 +
  33 +if (!is_callable('random_bytes')) {
  34 + /**
  35 + * Unless open_basedir is enabled, use /dev/urandom for
  36 + * random numbers in accordance with best practices
  37 + *
  38 + * Why we use /dev/urandom and not /dev/random
  39 + * @ref http://sockpuppet.org/blog/2014/02/25/safely-generate-random-numbers
  40 + *
  41 + * @param int $bytes
  42 + *
  43 + * @throws Exception
  44 + *
  45 + * @return string
  46 + */
  47 + function random_bytes($bytes)
  48 + {
  49 + static $fp = null;
  50 + /**
  51 + * This block should only be run once
  52 + */
  53 + if (empty($fp)) {
  54 + /**
  55 + * We use /dev/urandom if it is a char device.
  56 + * We never fall back to /dev/random
  57 + */
  58 + $fp = fopen('/dev/urandom', 'rb');
  59 + if (!empty($fp)) {
  60 + $st = fstat($fp);
  61 + if (($st['mode'] & 0170000) !== 020000) {
  62 + fclose($fp);
  63 + $fp = false;
  64 + }
  65 + }
  66 +
  67 + if (!empty($fp)) {
  68 + /**
  69 + * stream_set_read_buffer() does not exist in HHVM
  70 + *
  71 + * If we don't set the stream's read buffer to 0, PHP will
  72 + * internally buffer 8192 bytes, which can waste entropy
  73 + *
  74 + * stream_set_read_buffer returns 0 on success
  75 + */
  76 + if (is_callable('stream_set_read_buffer')) {
  77 + stream_set_read_buffer($fp, RANDOM_COMPAT_READ_BUFFER);
  78 + }
  79 + if (is_callable('stream_set_chunk_size')) {
  80 + stream_set_chunk_size($fp, RANDOM_COMPAT_READ_BUFFER);
  81 + }
  82 + }
  83 + }
  84 +
  85 + try {
  86 + $bytes = RandomCompat_intval($bytes);
  87 + } catch (TypeError $ex) {
  88 + throw new TypeError(
  89 + 'random_bytes(): $bytes must be an integer'
  90 + );
  91 + }
  92 +
  93 + if ($bytes < 1) {
  94 + throw new Error(
  95 + 'Length must be greater than 0'
  96 + );
  97 + }
  98 +
  99 + /**
  100 + * This if() block only runs if we managed to open a file handle
  101 + *
  102 + * It does not belong in an else {} block, because the above
  103 + * if (empty($fp)) line is logic that should only be run once per
  104 + * page load.
  105 + */
  106 + if (!empty($fp)) {
  107 + /**
  108 + * @var int
  109 + */
  110 + $remaining = $bytes;
  111 +
  112 + /**
  113 + * @var string|bool
  114 + */
  115 + $buf = '';
  116 +
  117 + /**
  118 + * We use fread() in a loop to protect against partial reads
  119 + */
  120 + do {
  121 + /**
  122 + * @var string|bool
  123 + */
  124 + $read = fread($fp, $remaining);
  125 + if (!is_string($read)) {
  126 + if ($read === false) {
  127 + /**
  128 + * We cannot safely read from the file. Exit the
  129 + * do-while loop and trigger the exception condition
  130 + *
  131 + * @var string|bool
  132 + */
  133 + $buf = false;
  134 + break;
  135 + }
  136 + }
  137 + /**
  138 + * Decrease the number of bytes returned from remaining
  139 + */
  140 + $remaining -= RandomCompat_strlen($read);
  141 + /**
  142 + * @var string|bool
  143 + */
  144 + $buf = $buf . $read;
  145 + } while ($remaining > 0);
  146 +
  147 + /**
  148 + * Is our result valid?
  149 + */
  150 + if (is_string($buf)) {
  151 + if (RandomCompat_strlen($buf) === $bytes) {
  152 + /**
  153 + * Return our random entropy buffer here:
  154 + */
  155 + return $buf;
  156 + }
  157 + }
  158 + }
  159 +
  160 + /**
  161 + * If we reach here, PHP has failed us.
  162 + */
  163 + throw new Exception(
  164 + 'Error reading from source device'
  165 + );
  166 + }
  167 +}
... ...
pacotes/composer/vendor/paragonie/random_compat/lib/random_bytes_libsodium.php 0 → 100644
... ... @@ -0,0 +1,88 @@
  1 +<?php
  2 +/**
  3 + * Random_* Compatibility Library
  4 + * for using the new PHP 7 random_* API in PHP 5 projects
  5 + *
  6 + * The MIT License (MIT)
  7 + *
  8 + * Copyright (c) 2015 - 2017 Paragon Initiative Enterprises
  9 + *
  10 + * Permission is hereby granted, free of charge, to any person obtaining a copy
  11 + * of this software and associated documentation files (the "Software"), to deal
  12 + * in the Software without restriction, including without limitation the rights
  13 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14 + * copies of the Software, and to permit persons to whom the Software is
  15 + * furnished to do so, subject to the following conditions:
  16 + *
  17 + * The above copyright notice and this permission notice shall be included in
  18 + * all copies or substantial portions of the Software.
  19 + *
  20 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  26 + * SOFTWARE.
  27 + */
  28 +
  29 +if (!is_callable('random_bytes')) {
  30 + /**
  31 + * If the libsodium PHP extension is loaded, we'll use it above any other
  32 + * solution.
  33 + *
  34 + * libsodium-php project:
  35 + * @ref https://github.com/jedisct1/libsodium-php
  36 + *
  37 + * @param int $bytes
  38 + *
  39 + * @throws Exception
  40 + *
  41 + * @return string
  42 + */
  43 + function random_bytes($bytes)
  44 + {
  45 + try {
  46 + $bytes = RandomCompat_intval($bytes);
  47 + } catch (TypeError $ex) {
  48 + throw new TypeError(
  49 + 'random_bytes(): $bytes must be an integer'
  50 + );
  51 + }
  52 +
  53 + if ($bytes < 1) {
  54 + throw new Error(
  55 + 'Length must be greater than 0'
  56 + );
  57 + }
  58 +
  59 + /**
  60 + * \Sodium\randombytes_buf() doesn't allow more than 2147483647 bytes to be
  61 + * generated in one invocation.
  62 + */
  63 + if ($bytes > 2147483647) {
  64 + $buf = '';
  65 + for ($i = 0; $i < $bytes; $i += 1073741824) {
  66 + $n = ($bytes - $i) > 1073741824
  67 + ? 1073741824
  68 + : $bytes - $i;
  69 + $buf .= \Sodium\randombytes_buf($n);
  70 + }
  71 + } else {
  72 + $buf = \Sodium\randombytes_buf($bytes);
  73 + }
  74 +
  75 + if ($buf !== false) {
  76 + if (RandomCompat_strlen($buf) === $bytes) {
  77 + return $buf;
  78 + }
  79 + }
  80 +
  81 + /**
  82 + * If we reach here, PHP has failed us.
  83 + */
  84 + throw new Exception(
  85 + 'Could not gather sufficient random data'
  86 + );
  87 + }
  88 +}
... ...
pacotes/composer/vendor/paragonie/random_compat/lib/random_bytes_libsodium_legacy.php 0 → 100644
... ... @@ -0,0 +1,92 @@
  1 +<?php
  2 +/**
  3 + * Random_* Compatibility Library
  4 + * for using the new PHP 7 random_* API in PHP 5 projects
  5 + *
  6 + * The MIT License (MIT)
  7 + *
  8 + * Copyright (c) 2015 - 2017 Paragon Initiative Enterprises
  9 + *
  10 + * Permission is hereby granted, free of charge, to any person obtaining a copy
  11 + * of this software and associated documentation files (the "Software"), to deal
  12 + * in the Software without restriction, including without limitation the rights
  13 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14 + * copies of the Software, and to permit persons to whom the Software is
  15 + * furnished to do so, subject to the following conditions:
  16 + *
  17 + * The above copyright notice and this permission notice shall be included in
  18 + * all copies or substantial portions of the Software.
  19 + *
  20 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  26 + * SOFTWARE.
  27 + */
  28 +
  29 +if (!is_callable('random_bytes')) {
  30 + /**
  31 + * If the libsodium PHP extension is loaded, we'll use it above any other
  32 + * solution.
  33 + *
  34 + * libsodium-php project:
  35 + * @ref https://github.com/jedisct1/libsodium-php
  36 + *
  37 + * @param int $bytes
  38 + *
  39 + * @throws Exception
  40 + *
  41 + * @return string
  42 + */
  43 + function random_bytes($bytes)
  44 + {
  45 + try {
  46 + $bytes = RandomCompat_intval($bytes);
  47 + } catch (TypeError $ex) {
  48 + throw new TypeError(
  49 + 'random_bytes(): $bytes must be an integer'
  50 + );
  51 + }
  52 +
  53 + if ($bytes < 1) {
  54 + throw new Error(
  55 + 'Length must be greater than 0'
  56 + );
  57 + }
  58 +
  59 + /**
  60 + * @var string
  61 + */
  62 + $buf = '';
  63 +
  64 + /**
  65 + * \Sodium\randombytes_buf() doesn't allow more than 2147483647 bytes to be
  66 + * generated in one invocation.
  67 + */
  68 + if ($bytes > 2147483647) {
  69 + for ($i = 0; $i < $bytes; $i += 1073741824) {
  70 + $n = ($bytes - $i) > 1073741824
  71 + ? 1073741824
  72 + : $bytes - $i;
  73 + $buf .= Sodium::randombytes_buf($n);
  74 + }
  75 + } else {
  76 + $buf .= Sodium::randombytes_buf($bytes);
  77 + }
  78 +
  79 + if (is_string($buf)) {
  80 + if (RandomCompat_strlen($buf) === $bytes) {
  81 + return $buf;
  82 + }
  83 + }
  84 +
  85 + /**
  86 + * If we reach here, PHP has failed us.
  87 + */
  88 + throw new Exception(
  89 + 'Could not gather sufficient random data'
  90 + );
  91 + }
  92 +}
... ...
pacotes/composer/vendor/paragonie/random_compat/lib/random_bytes_mcrypt.php 0 → 100644
... ... @@ -0,0 +1,77 @@
  1 +<?php
  2 +/**
  3 + * Random_* Compatibility Library
  4 + * for using the new PHP 7 random_* API in PHP 5 projects
  5 + *
  6 + * The MIT License (MIT)
  7 + *
  8 + * Copyright (c) 2015 - 2017 Paragon Initiative Enterprises
  9 + *
  10 + * Permission is hereby granted, free of charge, to any person obtaining a copy
  11 + * of this software and associated documentation files (the "Software"), to deal
  12 + * in the Software without restriction, including without limitation the rights
  13 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14 + * copies of the Software, and to permit persons to whom the Software is
  15 + * furnished to do so, subject to the following conditions:
  16 + *
  17 + * The above copyright notice and this permission notice shall be included in
  18 + * all copies or substantial portions of the Software.
  19 + *
  20 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  26 + * SOFTWARE.
  27 + */
  28 +
  29 +if (!is_callable('random_bytes')) {
  30 + /**
  31 + * Powered by ext/mcrypt (and thankfully NOT libmcrypt)
  32 + *
  33 + * @ref https://bugs.php.net/bug.php?id=55169
  34 + * @ref https://github.com/php/php-src/blob/c568ffe5171d942161fc8dda066bce844bdef676/ext/mcrypt/mcrypt.c#L1321-L1386
  35 + *
  36 + * @param int $bytes
  37 + *
  38 + * @throws Exception
  39 + *
  40 + * @return string
  41 + */
  42 + function random_bytes($bytes)
  43 + {
  44 + try {
  45 + $bytes = RandomCompat_intval($bytes);
  46 + } catch (TypeError $ex) {
  47 + throw new TypeError(
  48 + 'random_bytes(): $bytes must be an integer'
  49 + );
  50 + }
  51 +
  52 + if ($bytes < 1) {
  53 + throw new Error(
  54 + 'Length must be greater than 0'
  55 + );
  56 + }
  57 +
  58 + $buf = @mcrypt_create_iv($bytes, MCRYPT_DEV_URANDOM);
  59 + if (
  60 + $buf !== false
  61 + &&
  62 + RandomCompat_strlen($buf) === $bytes
  63 + ) {
  64 + /**
  65 + * Return our random entropy buffer here:
  66 + */
  67 + return $buf;
  68 + }
  69 +
  70 + /**
  71 + * If we reach here, PHP has failed us.
  72 + */
  73 + throw new Exception(
  74 + 'Could not gather sufficient random data'
  75 + );
  76 + }
  77 +}
... ...
pacotes/composer/vendor/paragonie/random_compat/lib/random_int.php 0 → 100644
... ... @@ -0,0 +1,190 @@
  1 +<?php
  2 +
  3 +if (!is_callable('random_int')) {
  4 + /**
  5 + * Random_* Compatibility Library
  6 + * for using the new PHP 7 random_* API in PHP 5 projects
  7 + *
  8 + * The MIT License (MIT)
  9 + *
  10 + * Copyright (c) 2015 - 2017 Paragon Initiative Enterprises
  11 + *
  12 + * Permission is hereby granted, free of charge, to any person obtaining a copy
  13 + * of this software and associated documentation files (the "Software"), to deal
  14 + * in the Software without restriction, including without limitation the rights
  15 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  16 + * copies of the Software, and to permit persons to whom the Software is
  17 + * furnished to do so, subject to the following conditions:
  18 + *
  19 + * The above copyright notice and this permission notice shall be included in
  20 + * all copies or substantial portions of the Software.
  21 + *
  22 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  23 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  24 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  25 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  26 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  27 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  28 + * SOFTWARE.
  29 + */
  30 +
  31 + /**
  32 + * Fetch a random integer between $min and $max inclusive
  33 + *
  34 + * @param int $min
  35 + * @param int $max
  36 + *
  37 + * @throws Exception
  38 + *
  39 + * @return int
  40 + */
  41 + function random_int($min, $max)
  42 + {
  43 + /**
  44 + * Type and input logic checks
  45 + *
  46 + * If you pass it a float in the range (~PHP_INT_MAX, PHP_INT_MAX)
  47 + * (non-inclusive), it will sanely cast it to an int. If you it's equal to
  48 + * ~PHP_INT_MAX or PHP_INT_MAX, we let it fail as not an integer. Floats
  49 + * lose precision, so the <= and => operators might accidentally let a float
  50 + * through.
  51 + */
  52 +
  53 + try {
  54 + $min = RandomCompat_intval($min);
  55 + } catch (TypeError $ex) {
  56 + throw new TypeError(
  57 + 'random_int(): $min must be an integer'
  58 + );
  59 + }
  60 +
  61 + try {
  62 + $max = RandomCompat_intval($max);
  63 + } catch (TypeError $ex) {
  64 + throw new TypeError(
  65 + 'random_int(): $max must be an integer'
  66 + );
  67 + }
  68 +
  69 + /**
  70 + * Now that we've verified our weak typing system has given us an integer,
  71 + * let's validate the logic then we can move forward with generating random
  72 + * integers along a given range.
  73 + */
  74 + if ($min > $max) {
  75 + throw new Error(
  76 + 'Minimum value must be less than or equal to the maximum value'
  77 + );
  78 + }
  79 +
  80 + if ($max === $min) {
  81 + return $min;
  82 + }
  83 +
  84 + /**
  85 + * Initialize variables to 0
  86 + *
  87 + * We want to store:
  88 + * $bytes => the number of random bytes we need
  89 + * $mask => an integer bitmask (for use with the &) operator
  90 + * so we can minimize the number of discards
  91 + */
  92 + $attempts = $bits = $bytes = $mask = $valueShift = 0;
  93 +
  94 + /**
  95 + * At this point, $range is a positive number greater than 0. It might
  96 + * overflow, however, if $max - $min > PHP_INT_MAX. PHP will cast it to
  97 + * a float and we will lose some precision.
  98 + */
  99 + $range = $max - $min;
  100 +
  101 + /**
  102 + * Test for integer overflow:
  103 + */
  104 + if (!is_int($range)) {
  105 +
  106 + /**
  107 + * Still safely calculate wider ranges.
  108 + * Provided by @CodesInChaos, @oittaa
  109 + *
  110 + * @ref https://gist.github.com/CodesInChaos/03f9ea0b58e8b2b8d435
  111 + *
  112 + * We use ~0 as a mask in this case because it generates all 1s
  113 + *
  114 + * @ref https://eval.in/400356 (32-bit)
  115 + * @ref http://3v4l.org/XX9r5 (64-bit)
  116 + */
  117 + $bytes = PHP_INT_SIZE;
  118 + $mask = ~0;
  119 +
  120 + } else {
  121 +
  122 + /**
  123 + * $bits is effectively ceil(log($range, 2)) without dealing with
  124 + * type juggling
  125 + */
  126 + while ($range > 0) {
  127 + if ($bits % 8 === 0) {
  128 + ++$bytes;
  129 + }
  130 + ++$bits;
  131 + $range >>= 1;
  132 + $mask = $mask << 1 | 1;
  133 + }
  134 + $valueShift = $min;
  135 + }
  136 +
  137 + $val = 0;
  138 + /**
  139 + * Now that we have our parameters set up, let's begin generating
  140 + * random integers until one falls between $min and $max
  141 + */
  142 + do {
  143 + /**
  144 + * The rejection probability is at most 0.5, so this corresponds
  145 + * to a failure probability of 2^-128 for a working RNG
  146 + */
  147 + if ($attempts > 128) {
  148 + throw new Exception(
  149 + 'random_int: RNG is broken - too many rejections'
  150 + );
  151 + }
  152 +
  153 + /**
  154 + * Let's grab the necessary number of random bytes
  155 + */
  156 + $randomByteString = random_bytes($bytes);
  157 +
  158 + /**
  159 + * Let's turn $randomByteString into an integer
  160 + *
  161 + * This uses bitwise operators (<< and |) to build an integer
  162 + * out of the values extracted from ord()
  163 + *
  164 + * Example: [9F] | [6D] | [32] | [0C] =>
  165 + * 159 + 27904 + 3276800 + 201326592 =>
  166 + * 204631455
  167 + */
  168 + $val &= 0;
  169 + for ($i = 0; $i < $bytes; ++$i) {
  170 + $val |= ord($randomByteString[$i]) << ($i * 8);
  171 + }
  172 +
  173 + /**
  174 + * Apply mask
  175 + */
  176 + $val &= $mask;
  177 + $val += $valueShift;
  178 +
  179 + ++$attempts;
  180 + /**
  181 + * If $val overflows to a floating point number,
  182 + * ... or is larger than $max,
  183 + * ... or smaller than $min,
  184 + * then try again.
  185 + */
  186 + } while (!is_int($val) || $val > $max || $val < $min);
  187 +
  188 + return (int)$val;
  189 + }
  190 +}
... ...
pacotes/composer/vendor/paragonie/random_compat/other/build_phar.php 0 → 100644
... ... @@ -0,0 +1,57 @@
  1 +<?php
  2 +$dist = dirname(__DIR__).'/dist';
  3 +if (!is_dir($dist)) {
  4 + mkdir($dist, 0755);
  5 +}
  6 +if (file_exists($dist.'/random_compat.phar')) {
  7 + unlink($dist.'/random_compat.phar');
  8 +}
  9 +$phar = new Phar(
  10 + $dist.'/random_compat.phar',
  11 + FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::KEY_AS_FILENAME,
  12 + 'random_compat.phar'
  13 +);
  14 +rename(
  15 + dirname(__DIR__).'/lib/random.php',
  16 + dirname(__DIR__).'/lib/index.php'
  17 +);
  18 +$phar->buildFromDirectory(dirname(__DIR__).'/lib');
  19 +rename(
  20 + dirname(__DIR__).'/lib/index.php',
  21 + dirname(__DIR__).'/lib/random.php'
  22 +);
  23 +
  24 +/**
  25 + * If we pass an (optional) path to a private key as a second argument, we will
  26 + * sign the Phar with OpenSSL.
  27 + *
  28 + * If you leave this out, it will produce an unsigned .phar!
  29 + */
  30 +if ($argc > 1) {
  31 + if (!@is_readable($argv[1])) {
  32 + echo 'Could not read the private key file:', $argv[1], "\n";
  33 + exit(255);
  34 + }
  35 + $pkeyFile = file_get_contents($argv[1]);
  36 +
  37 + $private = openssl_get_privatekey($pkeyFile);
  38 + if ($private !== false) {
  39 + $pkey = '';
  40 + openssl_pkey_export($private, $pkey);
  41 + $phar->setSignatureAlgorithm(Phar::OPENSSL, $pkey);
  42 +
  43 + /**
  44 + * Save the corresponding public key to the file
  45 + */
  46 + if (!@is_readable($dist.'/random_compat.phar.pubkey')) {
  47 + $details = openssl_pkey_get_details($private);
  48 + file_put_contents(
  49 + $dist.'/random_compat.phar.pubkey',
  50 + $details['key']
  51 + );
  52 + }
  53 + } else {
  54 + echo 'An error occurred reading the private key from OpenSSL.', "\n";
  55 + exit(255);
  56 + }
  57 +}
... ...
pacotes/composer/vendor/paragonie/random_compat/psalm-autoload.php 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +<?php
  2 +
  3 +require_once 'lib/byte_safe_strings.php';
  4 +require_once 'lib/cast_to_int.php';
  5 +require_once 'lib/error_polyfill.php';
  6 +require_once 'other/ide_stubs/libsodium.php';
  7 +require_once 'lib/random.php';
  8 +
  9 +$int = random_int(0, 65536);
... ...
pacotes/composer/vendor/paragonie/random_compat/psalm.xml 0 → 100644
... ... @@ -0,0 +1,15 @@
  1 +<?xml version="1.0"?>
  2 +<psalm
  3 + autoloader="psalm-autoload.php"
  4 + stopOnFirstError="false"
  5 + useDocblockTypes="true"
  6 +>
  7 + <projectFiles>
  8 + <directory name="lib" />
  9 + </projectFiles>
  10 + <issueHandlers>
  11 + <InvalidOperand errorLevel="info" />
  12 + <UndefinedConstant errorLevel="info" />
  13 + <MissingReturnType errorLevel="info" />
  14 + </issueHandlers>
  15 +</psalm>
... ...