This repository was archived by the owner on Apr 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathinstaller.php
More file actions
executable file
·859 lines (752 loc) · 26.2 KB
/
Copy pathinstaller.php
File metadata and controls
executable file
·859 lines (752 loc) · 26.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
<?php
/*
* Substantial portions of this file are taken from Composer's installer script,
* which is MIT-licenced. At Feb 8, 2017, its licence read as follows:
*
* Copyright (c) Nils Adermann, Jordi Boggiano
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*/
if (!defined('TESTING_QA_TOOLS_INSTALLER')) {
installQaTools(is_array($argv) ? $argv : []);
}
/**
* processes the installer
*/
function installQaTools($argv)
{
// Determine ANSI output from --ansi and --no-ansi flags
setUseAnsi($argv);
if (in_array('--help', $argv)) {
displayHelp();
exit(0);
}
$check = in_array('--check', $argv);
$force = in_array('--force', $argv);
$quiet = in_array('--quiet', $argv);
$installDir = getOptValue('--install-dir', $argv, false);
$version = getOptValue('--version', $argv, false);
$filename = getOptValue('--filename', $argv, 'qa-tools');
if (!checkParams($installDir, $version)) {
exit(1);
}
$ok = checkPlatform($warnings, $quiet);
if ($check) {
// Only show warnings if we haven't output any errors
if ($ok) {
showWarnings($warnings);
}
exit($ok ? 0 : 1);
}
if ($ok || $force) {
$installer = new Installer($quiet, new HttpClient(), new PharValidator(), 'ibuildingsnl', 'qa-tools');
if ($installer->run($version, $installDir, $filename)) {
showWarnings($warnings);
exit(0);
}
}
exit(1);
}
/**
* displays the help
*/
function displayHelp()
{
echo <<<EOF
QA Tools Installer
------------------
Options
--help this help
--check for checking environment only
--force forces the installation
--ansi force ANSI color output
--no-ansi disable ANSI color output
--quiet do not output unimportant messages
--install-dir="..." accepts a target installation directory
--version="..." accepts a specific version to install instead of the latest
--filename="..." accepts a target filename (default: composer.phar)
EOF;
}
/**
* Sets the QA_TOOLS_INSTALLER_ANSI define for colorizing output
*
* @param array $argv Command-line arguments
*/
function setUseAnsi($argv)
{
if (defined('QA_TOOLS_INSTALLER_ANSI')) {
return;
}
if (in_array('--no-ansi', $argv)) {
define('QA_TOOLS_INSTALLER_ANSI', false);
return;
}
if (in_array('--ansi', $argv)) {
define('QA_TOOLS_INSTALLER_ANSI', true);
return;
}
define(
'QA_TOOLS_INSTALLER_ANSI',
(DIRECTORY_SEPARATOR === '\\')
? (false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI'))
: (function_exists('posix_isatty') && posix_isatty(1))
);
}
/**
* Returns the value of a command-line option
*
* @param string $opt The command-line option to check
* @param array $argv Command-line arguments
* @param mixed $default Default value to be returned
*
* @return mixed The command-line value or the default
*/
function getOptValue($opt, $argv, $default)
{
$optLength = strlen($opt);
foreach ($argv as $key => $value) {
$next = $key + 1;
if (0 === strpos($value, $opt)) {
if ($optLength === strlen($value) && isset($argv[$next])) {
return trim($argv[$next]);
} else {
return trim(substr($value, $optLength + 1));
}
}
}
return $default;
}
/**
* Checks that user-supplied params are valid
*
* @param mixed $installDir The required istallation directory
* @param mixed $version The required composer version to install
*
* @return bool True if the supplied params are okay
*/
function checkParams($installDir, $version)
{
$result = true;
if (false !== $installDir && !is_dir($installDir)) {
out("The defined install dir ({$installDir}) does not exist.", 'info');
$result = false;
}
if (false !== $version && 1 !== preg_match('/^\d+\.\d+\.\d+(\-(alpha|beta|RC)\d*)*$/', $version)) {
out("The defined install version ({$version}) does not match release pattern.", 'info');
$result = false;
}
return $result;
}
/**
* Checks the platform for possible issues running QA Tools
*
* Errors are written to the output, warnings are saved for later display.
*
* @param array $warnings Populated by method, to be shown later
* @param bool $quiet Quiet mode
*
* @return bool True if there are no errors
*/
function checkPlatform(&$warnings, $quiet)
{
getPlatformIssues($errors, $warnings);
if (!empty($errors)) {
out('Some settings on your machine make it impossible for QA Tools to work properly.', 'error');
out('Make sure that you fix the issues listed below and run this script again:', 'error');
outputIssues($errors);
return false;
}
if (empty($warnings) && !$quiet) {
out('All settings correct for using QA Tools', 'success');
}
return true;
}
/**
* Checks platform configuration for common incompatibility issues
*
* @param array $errors Populated by method
* @param array $warnings Populated by method
*
* @return bool If any errors or warnings have been found
*/
function getPlatformIssues(&$errors, &$warnings)
{
$errors = [];
$warnings = [];
if ($iniPath = php_ini_loaded_file()) {
$iniMessage = PHP_EOL . 'The php.ini used by your command-line PHP is: ' . $iniPath;
} else {
$iniMessage = PHP_EOL . 'A php.ini file does not exist. You will have to create one.';
}
$iniMessage .= PHP_EOL . 'If you can not modify the ini file, you can also run `php -d option=value` to modify ini values on the fly. You can use -d multiple times.';
if (extension_loaded('suhosin')) {
$suhosin = ini_get('suhosin.executor.include.whitelist');
$suhosinBlacklist = ini_get('suhosin.executor.include.blacklist');
if (false === stripos($suhosin, 'phar') && (!$suhosinBlacklist || false !== stripos($suhosinBlacklist,
'phar'))
) {
$errors['suhosin'] = [
'The suhosin.executor.include.whitelist setting is incorrect.',
'Add the following to the end of your `php.ini` or suhosin.ini (Example path [for Debian]: /etc/php5/cli/conf.d/suhosin.ini):',
' suhosin.executor.include.whitelist = phar ' . $suhosin,
$iniMessage,
];
}
}
if (!function_exists('json_decode')) {
$errors['json'] = [
'The json extension is missing.',
'Install it or recompile php without --disable-json',
];
}
if (!extension_loaded('Phar')) {
$errors['phar'] = [
'The phar extension is missing.',
'Install it or recompile php without --disable-phar',
];
}
if (!extension_loaded('pcntl')) {
$errors['pcntl'] = [
'The pcntl extension is missing.',
];
}
if (!ini_get('allow_url_fopen')) {
$errors['allow_url_fopen'] = [
'The allow_url_fopen setting is incorrect.',
'Add the following to the end of your `php.ini`:',
' allow_url_fopen = On',
$iniMessage,
];
}
if (extension_loaded('ionCube Loader') && ioncube_loader_iversion() < 40009) {
$ioncube = ioncube_loader_version();
$errors['ioncube'] = [
'Your ionCube Loader extension (' . $ioncube . ') is incompatible with Phar files.',
'Upgrade to ionCube 4.0.9 or higher or remove this line (path may be different) from your `php.ini` to disable it:',
' zend_extension = /usr/lib/php5/20090626+lfs/ioncube_loader_lin_5.3.so',
$iniMessage,
];
}
if (version_compare(PHP_VERSION, '5.6.0', '<')) {
$errors['php'] = [
'Your PHP (' . PHP_VERSION . ') is too old, you must upgrade to PHP 5.6.0 or higher.',
];
}
if (!extension_loaded('openssl')) {
$errors['openssl'] = [
'The openssl extension is missing, which means that secure HTTPS transfers are impossible.',
'If possible you should enable it or recompile php with --with-openssl',
];
}
if (extension_loaded('openssl') && OPENSSL_VERSION_NUMBER < 0x1000100f) {
// Attempt to parse version number out, fallback to whole string value.
$opensslVersion = trim(strstr(OPENSSL_VERSION_TEXT, ' '));
$opensslVersion = substr($opensslVersion, 0, strpos($opensslVersion, ' '));
$opensslVersion = $opensslVersion ?: OPENSSL_VERSION_TEXT;
$warnings['openssl_version'] = [
'The OpenSSL library (' . $opensslVersion . ') used by PHP does not support TLSv1.2 or TLSv1.1.',
'If possible you should upgrade OpenSSL to version 1.0.1 or above.',
];
}
if (!defined('HHVM_VERSION') && !extension_loaded('apcu') && ini_get('apc.enable_cli')) {
$warnings['apc_cli'] = [
'The apc.enable_cli setting is incorrect.',
'Add the following to the end of your `php.ini`:',
' apc.enable_cli = Off',
$iniMessage,
];
}
ob_start();
phpinfo(INFO_GENERAL);
$phpinfo = ob_get_clean();
if (preg_match('{Configure Command(?: *</td><td class="v">| *=> *)(.*?)(?:</td>|$)}m', $phpinfo, $match)) {
$configure = $match[1];
if (false !== strpos($configure, '--enable-sigchild')) {
$warnings['sigchild'] = [
'PHP was compiled with --enable-sigchild which can cause issues on some platforms.',
'Recompile it without this flag if possible, see also:',
' https://bugs.php.net/bug.php?id=22999',
];
}
if (false !== strpos($configure, '--with-curlwrappers')) {
$warnings['curlwrappers'] = [
'PHP was compiled with --with-curlwrappers which will cause issues with HTTP authentication and GitHub.',
'Recompile it without this flag if possible',
];
}
}
// Stringify the message arrays
foreach ($errors as $key => $value) {
$errors[$key] = PHP_EOL . implode(PHP_EOL, $value);
}
foreach ($warnings as $key => $value) {
$warnings[$key] = PHP_EOL . implode(PHP_EOL, $value);
}
return !empty($errors) || !empty($warnings);
}
/**
* Outputs an array of issues
*
* @param array $issues
*/
function outputIssues($issues)
{
foreach ($issues as $issue) {
out($issue, 'info');
}
out('');
}
/**
* Outputs any warnings found
*
* @param array $warnings
*/
function showWarnings($warnings)
{
if (!empty($warnings)) {
out('Some settings on your machine may cause stability issues with QA Tools.', 'error');
out('If you encounter issues, try to change the following:', 'error');
outputIssues($warnings);
}
}
/**
* colorize output
*/
function out($text, $color = null, $newLine = true)
{
$styles = [
'success' => "\033[0;32m%s\033[0m",
'error' => "\033[31;31m%s\033[0m",
'info' => "\033[33;33m%s\033[0m",
];
$format = '%s';
if (isset($styles[$color]) && QA_TOOLS_INSTALLER_ANSI) {
$format = $styles[$color];
}
if ($newLine) {
$format .= PHP_EOL;
}
printf($format, $text);
}
class Installer
{
/** @var bool $quiet */
private $quiet;
/** @var string $installPath */
private $installPath;
/** @var string $target */
private $target;
/** @var string $tmpPharPath */
private $tmpPharPath;
/** @var string $tmpPubkeyPath */
private $tmpPubkeyPath;
/** @var HttpClient $httpClient */
private $httpClient;
/** @var string $repositoryOwner */
private $repositoryOwner;
/** @var string $repositoryName */
private $repositoryName;
/**
* @var PharValidator
*/
private $pharValidator;
/**
* @param bool $quiet Quiet mode
* @param HttpClient $httpClient Http client to download release info and files
* @param PharValidator $pharValidator A class that can validate Phar files
* @param string $repositoryOwner Owner of repository to download from
* @param string $repositoryName Name of repository to download release from
*/
public function __construct($quiet, HttpClient $httpClient, PharValidator $pharValidator, $repositoryOwner, $repositoryName)
{
if (($this->quiet = $quiet)) {
ob_start();
}
$this->httpClient = $httpClient;
$this->repositoryOwner = $repositoryOwner;
$this->repositoryName = $repositoryName;
$this->pharValidator = $pharValidator;
}
/**
* Runs the installer
*
* @param mixed $version Specific version to install, or false
* @param mixed $installDir Specific installation directory, or false
* @param string $filename Specific filename to save to, or composer.phar
* @throws Exception If anything other than a RuntimeException is caught
*
* @return bool If the installation succeeded
*/
public function run($version, $installDir, $filename)
{
try {
$this->initTargets($installDir, $filename);
$result = $this->install($version);
} catch (Exception $e) {
$result = false;
if (!$e instanceof RuntimeException) {
throw $e;
}
out($e->getMessage(), 'error');
} finally {
if (!$result) {
$this->cleanUp();
}
}
return $result;
}
/**
* Initialization methods to set the required filenames and base url
*
* @param mixed $installDir Specific installation directory, or false
* @param string $filename Specific filename to save to
* @throws RuntimeException If the installation directory is not writable
*/
private function initTargets($installDir, $filename)
{
if ($installDir === false) {
$installDir = getcwd();
}
$this->installPath = rtrim($installDir, '/') . '/'. $filename;
if (!is_writable($installDir)) {
throw new RuntimeException('The installation directory "' . $installDir . '" is not writable');
}
$this->target = $installDir . DIRECTORY_SEPARATOR . $filename;
$this->tmpPharPath = $installDir . DIRECTORY_SEPARATOR . basename($this->target, '.phar') . '-temp.phar';
$this->tmpPubkeyPath = $this->tmpPharPath . '.pubkey';
}
/**
* The main install function
*
* @param mixed $version Specific version to install, or false
*
* @return bool If the installation succeeded
*/
private function install($version)
{
$retries = 3;
$infoMsg = 'Downloading...';
$infoType = 'info';
$success = false;
while ($retries--) {
try {
if (!$this->quiet) {
out($infoMsg, $infoType);
$infoMsg = 'Retrying...';
$infoType = 'error';
}
$releaseInfo = $this->getReleaseInfo($version);
$this->downloadTemporaryFile($releaseInfo['pharUrl'], $this->tmpPharPath);
$this->downloadTemporaryFile($releaseInfo['pubkeyUrl'], $this->tmpPubkeyPath);
$this->verifyAndSave();
$success = true;
break;
} catch (RuntimeException $e) {
out($e->getMessage(), 'error');
}
}
if (!$this->quiet) {
if ($success) {
out(PHP_EOL . "QA Tools (version {$releaseInfo['version']}) successfully installed to: {$this->target}", 'success');
out("Use it: php {$this->installPath}", 'info');
out('');
} else {
out('The download failed repeatedly, aborting.', 'error');
}
}
return $success;
}
/**
* @return string|false $version The release information of the specified version, if given, or the latest version.
* @throws \RuntimeException
*/
public function getReleaseInfo($version)
{
if ($version === false) {
$url = sprintf(
'https://api.github.com/repos/%s/%s/releases/latest',
urlencode($this->repositoryOwner),
urlencode($this->repositoryName)
);
} elseif (is_string($version) && $version !== '') {
$url = sprintf(
'https://api.github.com/repos/%s/%s/releases/tags/%s',
urlencode($this->repositoryOwner),
urlencode($this->repositoryName),
urlencode($version)
);
} else {
throw new InvalidArgumentException(
sprintf(
'Version must be either `false` or a non-empty string, got value of type "%s"',
gettype($version)
)
);
}
try {
$response = $this->httpClient->get($url, 'application/vnd.github.v3+json');
} catch (Exception $e) {
throw new RuntimeException('Unable to download version information from '.$url.': '.$e->getMessage());
}
$allReleaseInfo = json_decode($response, true);
if (json_last_error()) {
throw new RuntimeException(
'Invalid response from GitHub when requesting version information (' . json_last_error_msg() . ')'
);
}
if (!isset($allReleaseInfo['tag_name'])) {
throw new RuntimeException('Unable to determine version number from release');
}
$releaseInfo = ['version' => $allReleaseInfo['tag_name']];
foreach ($allReleaseInfo['assets'] as $asset) {
if ($asset['name'] === 'qa-tools.phar') {
$releaseInfo['pharUrl'] = $asset['url'];
}
if ($asset['name'] === 'qa-tools.phar.pubkey') {
$releaseInfo['pubkeyUrl'] = $asset['url'];
}
}
if (!isset($releaseInfo['pharUrl'])) {
throw new RuntimeException(
sprintf('Unable to find qa-tools.phar in release %s', $releaseInfo['version'])
);
}
if (!isset($releaseInfo['pubkeyUrl'])) {
throw new RuntimeException(
sprintf('Unable to find qa-tools.phar.pubkey in release %s', $releaseInfo['version'])
);
}
return $releaseInfo;
}
/**
* A wrapper around the methods needed to download and save the phar
*
* @param string $url The versioned download url
* @param string $target The target location to download to
*
* @throws \RuntimeException
*/
private function downloadTemporaryFile($url, $target)
{
try {
if (($fh = @fopen($target, 'w')) === false) {
throw new RuntimeException(
sprintf(
'Could not create file "%s": %s',
$target,
@error_get_last()['message']
)
);
}
if ((@fwrite($fh, $this->httpClient->get($url, 'application/octet-stream'))) === false) {
throw new RuntimeException(
sprintf(
'The "%s" file could not be downloaded: %s',
$url,
@error_get_last()['message']
)
);
}
} finally {
if (is_resource($fh)) {
fclose($fh);
}
}
}
/**
* Verifies the downloaded file and saves it to the target location
*
* @throws \RuntimeException
*/
private function verifyAndSave()
{
$this->pharValidator->assertPharValid($this->tmpPharPath);
if (!@rename($this->tmpPharPath, $this->target)) {
throw new RuntimeException(
sprintf(
'Could not write to file "%s": %s',
$this->target,
@error_get_last()['message']
)
);
}
if (!@rename($this->tmpPubkeyPath, $this->target . '.pubkey')) {
throw new RuntimeException(
sprintf(
'Could not write to file "%s": %s',
$this->target,
@error_get_last()['message']
)
);
}
chmod($this->target, 0755);
}
/**
* Cleans up resources at the end of a failed installation
*/
private function cleanUp()
{
if ($this->quiet) {
$errors = explode(PHP_EOL, ob_get_clean());
$shown = [];
foreach ($errors as $error) {
if ($error && !in_array($error, $shown)) {
out($error, 'error');
$shown[] = $error;
}
}
}
if (file_exists($this->tmpPharPath)) {
@unlink($this->tmpPharPath);
}
if (file_exists($this->tmpPubkeyPath)) {
@unlink($this->tmpPharPath);
}
}
}
class HttpClient
{
/** @var array $options */
private $options = ['http' => []];
public function __construct()
{
$this->options = array_replace_recursive(
$this->options,
$this->getTlsStreamContextDefaults()
);
}
public function get($url, $acceptMimeType = 'application/octet-stream')
{
$context = $this->getMergedStreamContext($url, $acceptMimeType);
$result = @file_get_contents($url, false, $context);
if ($result === false) {
throw new RuntimeException('Unable to read '.$url.': '.@error_get_last()['message']);
}
if ($result && extension_loaded('zlib')) {
$decode = false;
foreach ($http_response_header as $header) {
if (preg_match('{^content-encoding: *gzip *$}i', $header)) {
$decode = true;
continue;
} elseif (preg_match('{^HTTP/}i', $header)) {
$decode = false;
}
}
if ($decode) {
$result = zlib_decode($result);
if ($result === false) {
throw new RuntimeException('Failed to decode zlib stream');
}
}
}
return $result;
}
private function getTlsStreamContextDefaults()
{
$ciphers = implode(':', [
'ECDHE-RSA-AES128-GCM-SHA256',
'ECDHE-ECDSA-AES128-GCM-SHA256',
'ECDHE-RSA-AES256-GCM-SHA384',
'ECDHE-ECDSA-AES256-GCM-SHA384',
'DHE-RSA-AES128-GCM-SHA256',
'DHE-DSS-AES128-GCM-SHA256',
'kEDH+AESGCM',
'ECDHE-RSA-AES128-SHA256',
'ECDHE-ECDSA-AES128-SHA256',
'ECDHE-RSA-AES128-SHA',
'ECDHE-ECDSA-AES128-SHA',
'ECDHE-RSA-AES256-SHA384',
'ECDHE-ECDSA-AES256-SHA384',
'ECDHE-RSA-AES256-SHA',
'ECDHE-ECDSA-AES256-SHA',
'DHE-RSA-AES128-SHA256',
'DHE-RSA-AES128-SHA',
'DHE-DSS-AES128-SHA256',
'DHE-RSA-AES256-SHA256',
'DHE-DSS-AES256-SHA',
'DHE-RSA-AES256-SHA',
'AES128-GCM-SHA256',
'AES256-GCM-SHA384',
'ECDHE-RSA-RC4-SHA',
'ECDHE-ECDSA-RC4-SHA',
'AES128',
'AES256',
'RC4-SHA',
'HIGH',
'!aNULL',
'!eNULL',
'!EXPORT',
'!DES',
'!3DES',
'!MD5',
'!PSK',
]);
return [
'ssl' => [
'ciphers' => $ciphers,
'verify_peer' => true,
'verify_depth' => 7,
'SNI_enabled' => true,
],
];
}
/**
* function copied from Composer\Util\StreamContextFactory::getContext
*
* Any changes should be applied there as well, or backported here.
*
* @param string $url URL the context is to be used for
* @param string $acceptMimeType Mime type used in the Accept: header of the request
* @return resource Default context
*/
private function getMergedStreamContext($url, $acceptMimeType)
{
$options = $this->options;
if (isset($options['http']['header'])) {
$options['http']['header'] .= "Connection: close\r\n";
} else {
$options['http']['header'] = "Connection: close\r\n";
}
if (extension_loaded('zlib')) {
$options['http']['header'] .= "Accept-Encoding: gzip\r\n";
}
$options['http']['header'] .= "User-Agent: Ibuildingsnl QA Tools Installer\r\n";
$options['http']['header'] .= 'Accept: '.$acceptMimeType."\r\n";
$options['http']['protocol_version'] = 1.1;
return stream_context_create($options);
}
}
class PharValidator
{
public function assertPharValid($path)
{
try {
// Test the phar validity - simply opening the PHAR will actually
// check the against the <pharname>.pubkey file
$phar = new Phar($path);
$signature = $phar->getSignature();
if (strtolower($signature['hash_type']) !== 'openssl') {
throw new RuntimeException('Downloaded PHAR was not signed!');
}
// Free the variable to unlock the file
unset($phar);
} catch (Exception $e) {
throw new RuntimeException(
sprintf(
'Unable to open PHAR file: %s',
$e->getMessage()
),
0,
$e
);
}
}
}