Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 82f0428

Browse files
authoredOct 30, 2023
doc: Various improvements (#1137)
1 parent 5163fbb commit 82f0428

11 files changed

+114
-92
lines changed
 

‎doc/code-isolation.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ conflicts.
1414
To illustrate that issue with an example: we are building a console application `myapp.phar` which relies on the library
1515
Symfony YAML 2.8.0 which execute a given PHP script.
1616

17-
```bash
17+
```shell
1818
# Usage of the application we are building
1919
myapp.phar myscript.php
2020
```

‎doc/configuration.md

+11-3
Original file line numberDiff line numberDiff line change
@@ -770,12 +770,17 @@ available:
770770
- `SHA1`
771771
- `SHA256`
772772
- `SHA512`
773-
- `OPENSSL`
773+
- `OPENSSL` (deprecated)
774774

775-
By default PHARs are `SHA1` signed.
775+
By default, PHARs are `SHA1` signed.
776776

777777
The `OPENSSL` algorithm will require to provide [a key][key].
778778

779+
!!! warning
780+
781+
The OpenSSL signature has been deprecated as of Box 4.4.0. If you are wondering why check out
782+
[the signing best practices].
783+
779784

780785
### The private key (`key`)
781786

@@ -825,7 +830,9 @@ With the configuration excerpt:
825830

826831
Then the `Phar::getMetadata()` will return `['application_version' => '1.0.0-dev']` array.
827832

828-
**CAUTION**: Your callable function must be readable by your autoloader.
833+
!!! warning
834+
835+
Your callable function must be readable by your autoloader.
829836

830837
That means, for Composer, in previous example, we require to have such kind of declaration in your `composer.json` file.
831838

@@ -1044,6 +1051,7 @@ The short commit hash will only be used if no tag is available.
10441051
[requirement-checker]: requirement-checker.md#requirements-checker
10451052
[security]: #security
10461053
[shebang]: #shebang-shebang
1054+
[the signing best practices]: ./phar-signing.md#phar-signing-best-practices
10471055
[stub-stub]: #stub-stub
10481056
[stub]: #stub
10491057
[symfony-finder]: https://symfony.com/doc/current//components/finder.html

‎doc/faq.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ if (false === in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
5858
The shebang `#!/usr/bin/env php` is required to the auto-detection of the type of the script. This allows to use it as
5959
follows:
6060

61-
```bash
62-
$ chmod +x bin/acme.php
63-
$ ./bin/acme.php
64-
$ php bin/acme.php # still works
61+
```shell
62+
chmod +x bin/acme.php
63+
./bin/acme.php
64+
php bin/acme.php # still works
6565
# Without the shebang line, you can only use the latter
6666
```
6767

‎doc/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ box help
5555
The project provides a `Makefile` in which the most common commands have been registered such as fixing the coding
5656
style or running the test.
5757

58-
```bash
58+
```shell
5959
make
6060
```
6161

‎doc/installation.md

+18-18
Original file line numberDiff line numberDiff line change
@@ -17,54 +17,54 @@ The preferred method of installation is to use the Box PHAR which can be downloa
1717

1818
You can install Box with [Phive][phive]
1919

20-
```bash
21-
$ phive install humbug/box
20+
```shell
21+
phive install humbug/box
2222
```
2323

2424
To upgrade `box` use the following command:
2525

26-
```bash
27-
$ phive update humbug/box
26+
```shell
27+
phive update humbug/box
2828
```
2929

3030

3131
## Composer
3232

3333
You can install Box with [Composer][composer]:
3434

35-
```bash
36-
$ composer global require humbug/box
35+
```shell
36+
composer global require humbug/box
3737
```
3838

3939
If you cannot install it because of a dependency conflict or you prefer to install it for your project, we recommend
4040
you to take a look at [bamarni/composer-bin-plugin][bamarni/composer-bin-plugin]. Example:
4141

42-
```bash
43-
$ composer require --dev bamarni/composer-bin-plugin
44-
$ composer bin box require --dev humbug/box
42+
```shell
43+
composer require --dev bamarni/composer-bin-plugin
44+
composer bin box require --dev humbug/box
4545

46-
$ vendor/bin/box
46+
vendor/bin/box
4747
```
4848

4949
## Homebrew
5050

5151
To install box using [Homebrew](https://brew.sh), you need to tap the box formula first
5252

53-
```bash
54-
$ brew tap box-project/box
55-
$ brew install box
53+
```shell
54+
brew tap box-project/box
55+
brew install box
5656
```
5757

5858
The `box` command is now available to run from anywhere in the system:
5959

60-
```bash
61-
$ box -v
60+
```shell
61+
box -v
6262
```
6363

6464
To upgrade `box` use the following command:
6565

66-
```bash
67-
$ brew upgrade box
66+
```shell
67+
brew upgrade box
6868
```
6969

7070
## GitHub
@@ -73,7 +73,7 @@ You may download the Box PHAR directly from the [GitHub release][releases] direc
7373
You should however beware that it is not as secure as downloading it from the other mediums.
7474
Hence, it is recommended to check the signature when doing so:
7575

76-
```
76+
```shell
7777
# Do adjust the URL based on the latest release
7878
wget -O box.phar "https://github.com/box-project/box/releases/download/4.4.0/box.phar"
7979
wget -O box.phar.asc "https://github.com/box-project/box/releases/download/4.4.0/box.phar.asc"

‎doc/phar-signing.md

+54-44
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# PHAR signing best practices
22

33
1. [Built-in PHAR API](#built-in-phar-api)
4-
1. [How to sign your PHAR](#how-to-sign-your-phar)
5-
1. [How it works](#how-it-works)
6-
1. [Why it is bad](#why-it-is-bad)
4+
1. [How to sign your PHAR](#how-to-sign-your-phar)
5+
1. [How it works](#how-it-works)
6+
1. [Why it is bad](#why-it-is-bad)
77
1. [How to (properly) sign your PHAR](#how-to-properly-sign-your-phar)
8-
1. [Create a new GPG-key](#create-a-new-gpg-key)
9-
1. [Manually signing](#manually-signing)
10-
1. [Generate the encryption key](#generate-the-encryption-key)
11-
1. [Secure your encryption key](#secure-your-encryption-key)
12-
1. [Sign your PHAR](#sign-your-phar)
13-
1. [Verifying the PHAR signature](#verifying-the-phar-signature)
8+
1. [Create a new GPG-key](#create-a-new-gpg-key)
9+
1. [Manually signing](#manually-signing)
10+
1. [Generate the encryption key](#generate-the-encryption-key)
11+
1. [Secure your encryption key](#secure-your-encryption-key)
12+
1. [Sign your PHAR](#sign-your-phar)
13+
1. [Verifying the PHAR signature](#verifying-the-phar-signature)
1414
1. [Automatically sign in GitHub Actions](#automatically-sign-in-github-actions)
1515

1616
There is two idiomatic ways to secure a PHAR:
@@ -35,8 +35,8 @@ $phar->setSignatureAlgorithm($algo, $privateKey);
3535
There is various algorithm available. The most "secure" one would be `Phar::OPENSSL` with an
3636
OpenSSL private key. For instance:
3737

38-
```
39-
$ openssl genrsa -des3 -out acme-phar-private.pem 4096
38+
```shell
39+
openssl genrsa -des3 -out acme-phar-private.pem 4096
4040
```
4141

4242
```php
@@ -94,7 +94,7 @@ there is ways to void the signature:
9494
file (the public key), but in the context the attacker could inject code to the PHAR this is unlikely to be a real
9595
prevention measure.
9696

97-
So to conclude, **this security mechanism CANNOT prevent modifications of the archive itself.** It is NOT a reliable
97+
So to conclude, **this security mechanism CANNOT prevent modifications of the archive itself.** It is **NOT** a reliable
9898
protection measure.
9999

100100
The good news, there is a solution.
@@ -106,14 +106,15 @@ The good news, there is a solution.
106106

107107
The first step is to create a new GPG-key. You can either do that via a GUI or via the CLI like this:
108108

109-
```
110-
$ gpg --gen-key
109+
```shell
110+
gpg --gen-key
111111
```
112112

113113
It will ask for some questions. It is recommended to use a passphrase (ideally generated and managed by a reputable
114114
password manager). In the end, you will end up with something like this:
115115

116116
```
117+
# $ gpg --gen-key output
117118
pub ed25519 2023-10-21 [SC] [expires: 2026-10-20]
118119
96C8013A3CC293C465EE3FBB03B2F4DF7A20DF08
119120
uid Théo Fidry <theo.fidry+phar-signing-example@example.com>
@@ -123,8 +124,8 @@ sub cv25519 2023-10-21 [E] [expires: 2026-10-20]
123124
In this case the interesting part is `96C8013A3CC293C465EE3FBB03B2F4DF7A20DF08` which is the key ID. You can also check
124125
the list of your GPG keys like so:
125126

126-
```
127-
$ gpg --list-secret-keys --keyid-format=long
127+
```shell
128+
gpg --list-secret-keys --keyid-format=long
128129

129130
#
130131
# Other keys displayed too
@@ -135,22 +136,24 @@ uid [ultimate] Théo Fidry <theo.fidry+phar-signing-example@exam
135136
ssb cv25519/765C0E3CCBC7D7D3 2023-10-21 [E] [expires: 2026-10-20]
136137
```
137138

138-
The interesting part is the `96C8013A3CC293C465EE3FBB03B2F4DF7A20DF08` which is the key-ID.
139+
Like above, you see the key ID `96C8013A3CC293C465EE3FBB03B2F4DF7A20DF08`.
139140

140-
To make the key accessible for others we should now send it to a keyserver.
141+
To make the key accessible for others we should now send it to a keyserver[^1].
141142

142-
```
143-
$ gpg --keyserver keys.openpgp.org --send-key 96C8013A3CC293C465EE3FBB03B2F4DF7A20DF08
143+
```shell
144+
gpg --keyserver keys.openpgp.org --send-key 96C8013A3CC293C465EE3FBB03B2F4DF7A20DF08
144145
```
145146

146-
†: There is several OpenPGP Keyservers. It is recommended to push your keys to [keys.openpgp.org] _at least_, but you
147-
can also push it to other servers if you wish to.
147+
[^1]:
148+
149+
There is several OpenPGP Keyservers. It is recommended to push your keys to [keys.openpgp.org] _at least_, but you
150+
can also push it to other servers if you wish to.
148151

149152
You can also already generate a revocation certificate for the key. Should the key be compromised you can then send the
150153
revocation certificate to the keyserver to invalidate the signing key.
151154

152-
```
153-
$ gpg --output revoke-96C8013A3CC293C465EE3FBB03B2F4DF7A20DF08.asc --gen-revoke 96C8013A3CC293C465EE3FBB03B2F4DF7A20DF08
155+
```shell
156+
gpg --output revoke-96C8013A3CC293C465EE3FBB03B2F4DF7A20DF08.asc --gen-revoke 96C8013A3CC293C465EE3FBB03B2F4DF7A20DF08
154157
```
155158

156159
This will leave you with a revocation certificate in the file `revoke-96C8013A3CC293C465EE3FBB03B2F4DF7A20DF08.asc`
@@ -167,13 +170,15 @@ private GPG key.
167170

168171
In order to use the key to encrypt files, you need to first export it:
169172

170-
```
171-
$ gpg --export --armor 96C8013A3CC293C465EE3FBB03B2F4DF7A20DF08 > keys.asc
172-
$ gpg --export-secret-key --armor 96C8013A3CC293C465EE3FBB03B2F4DF7A20DF08 >> keys.asc
173+
```shell
174+
gpg --export --armor 96C8013A3CC293C465EE3FBB03B2F4DF7A20DF08 > keys.asc
175+
gpg --export-secret-key --armor 96C8013A3CC293C465EE3FBB03B2F4DF7A20DF08 >> keys.asc
173176
```
174177

175-
That will leave the public and private key in a single file. Anyone that has that file can sign on your behalf! So keep
176-
that file secure at all times and make sure it never accidentally shows up in your git repository!
178+
!!! warning
179+
180+
That will leave the public and private key in a single file. Anyone that has that file can sign on your behalf! So keep
181+
that file secure at all times and make sure it never accidentally shows up in your git repository.
177182

178183

179184
### Secure your encryption key
@@ -196,9 +201,9 @@ it is better to not keep that decrypted key around.
196201

197202
You first need to encrypt `keys.asc.gpg` into `keys.asc`:
198203

199-
```
204+
```shell
200205
# If you are locally:
201-
$ gpg keys.asc.gpg
206+
gpg keys.asc.gpg
202207
# In another environment: CI or other. You should use an environment variable
203208
# or a temporary file to avoid printing the password in clear text.
204209
echo $DECRYPT_KEY_PASSPHRASE | gpg --passphrase-fd 0 keys.asc.gpg
@@ -208,14 +213,14 @@ cat $(.decrypt-key-passphrase) | gpg --passphrase-fd 0 keys.asc.gpg
208213

209214
Import the decrypted key if it is not already present on the machine:
210215

211-
```
212-
$ gpg --batch --yes --import keys.asc
216+
```shell
217+
gpg --batch --yes --import keys.asc
213218
```
214219

215220
Sign your file:
216221

217-
```
218-
$ gpg \
222+
```shell
223+
gpg \
219224
--batch \
220225
--passphrase="$GPG_KEY_96C8013A3CC293C465EE3FBB03B2F4DF7A20DF08_PASSPHRASE" \
221226
--local-user 96C8013A3CC293C465EE3FBB03B2F4DF7A20DF08 \
@@ -241,12 +246,12 @@ documentation:
241246
gpg --keyserver hkps://keys.openpgp.org --recv-keys 96C8013A3CC293C465EE3FBB03B2F4DF7A20DF08
242247
```
243248

244-
However not everyone expose what is their GPG key ID. So sometimes to avoid bad surprises, you
249+
However not everyone exposes what is their GPG key ID. So sometimes to avoid bad surprises, you
245250
can look up for similar issuers to the key ID given by the `.asc`:
246251

247-
```
252+
```shell
248253
# Verify the signature
249-
$ gpg --verify bin/command.phar.asc bin/command.phar
254+
gpg --verify bin/command.phar.asc bin/command.phar
250255

251256
# Example of output:
252257
gpg: Signature made Sat 21 Oct 16:58:05 2023 CEST
@@ -256,19 +261,21 @@ gpg: Good signature from "Théo Fidry <theo.fidry+phar-signing-example@example.c
256261

257262
If the key ID was not provided before, you can try to look it up to check it was properly registered to a keyserver:
258263

259-
```
260-
$ gpg --keyserver https://keys.openpgp.org --search-keys "theo.fidry+phar-signing-example@example.com"
264+
```shell
265+
gpg --keyserver https://keys.openpgp.org --search-keys "theo.fidry+phar-signing-example@example.com"
261266
```
262267

263-
Also note that when dealing with PHARs, the above steps are automatically done for you by [PHIVE][phive].
268+
!!! info
269+
270+
Also note that when dealing with PHARs, the above steps are automatically done for you by [PHIVE][phive].
264271

265272

266273
## Automatically sign in GitHub Actions
267274

268275
The first step is to add [environment secrets to your repository][github-environment-secrets]:
269276

270-
```
271-
$ gpg --export-secret-key --armor 96C8013A3CC293C465EE3FBB03B2F4DF7A20DF08
277+
```shell
278+
gpg --export-secret-key --armor 96C8013A3CC293C465EE3FBB03B2F4DF7A20DF08
272279
# Paste the content into a secret environment variable
273280
GPG_KEY_96C8013A3CC293C465EE3FBB03B2F4DF7A20DF08
274281

@@ -277,15 +284,17 @@ GPG_KEY_96C8013A3CC293C465EE3FBB03B2F4DF7A20DF08_PASSPHRASE
277284
```
278285

279286
Then you need to:
287+
280288
- Build your PHAR
281289
- Import the GPG key
282290
- Sign your PHAR
283291
- Publish your PHAR
284292

285293
I highly recommend to build your PHAR as part of your regular workflows. Then the other steps can be enable on release
286-
only. The following is an example of GitHub workflow:
294+
only. The following is an example of [GitHub workflow][github-workflow]:
287295

288296
```yaml
297+
# .github/workflows/release.yaml
289298
name: Release
290299

291300
on:
@@ -380,5 +389,6 @@ Credits:
380389
[box-release-workflow]: https://github.com/box-project/box/blob/main/.github/workflows/release.yaml
381390
[keys.openpgp.org]: https://keys.openpgp.org/about
382391
[github-environment-secrets]: https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions
392+
[github-workflow]: https://docs.github.com/en/actions/using-workflows
383393
[phive]: https://phar.io/
384394
[jar]: https://docs.oracle.com/javase/8/docs/technotes/guides/jar/jarGuide.html

‎doc/reproducible-builds.md

+14-14
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
1. [PHP-Scoper](#php-scoper)
44
1. [Composer](#composer)
5-
1. [Composer root version](#composer-root-version)
6-
1. [Composer autoload suffix](#composer-autoload-suffix)
5+
1. [Composer root version](#composer-root-version)
6+
1. [Composer autoload suffix](#composer-autoload-suffix)
77
1. [Box](#box)
8-
1. [PHAR alias](#phar-alias)
9-
1. [Requirement Checker](#requirement-checker)
10-
1. [Box banner](#box-banner)
8+
1. [PHAR alias](#phar-alias)
9+
1. [Requirement Checker](#requirement-checker)
10+
1. [Box banner](#box-banner)
1111
1. [PHAR](#phar)
1212

1313

@@ -40,8 +40,8 @@ This is not ideal as the content of the PHAR could be identical for two differen
4040
this problem, you can leverage the [`COMPOSER_ROOT_VERSION`][composer-root-version]. Either by exporting it or passing
4141
it to Box when compiling it:
4242

43-
```
44-
$ COMPOSER_ROOT_VERSION=1.0.0-dev box compile
43+
```shell
44+
COMPOSER_ROOT_VERSION=1.0.0-dev box compile
4545
```
4646

4747
### Composer autoload suffix
@@ -50,13 +50,13 @@ By default, Box will dump the Composer autoloader which usually results in a dif
5050
exceptions to this, for example Composer tend to try to keep the known suffix if one already exist, but it is an exotic
5151
case that is not recommended to rely on. For this reason you need to configure the [Composer autoload prefix][composer-autoload-prefix]:
5252

53-
```
54-
$ composer config autoloader-suffix AppChecksum
53+
```shell
54+
composer config autoloader-suffix AppChecksum
5555
```
5656

5757
Or configure it directly in your `composer.json`:
5858

59-
```
59+
```json
6060
{
6161
"config": {
6262
"autoloader-suffix": "AppChecksum"
@@ -105,7 +105,7 @@ you add a PHAR to a file, it is changed to the time at when you added it).
105105

106106
To fix this, you can leverage [Seldaek PHAR-Utils][phar-utils] with the following script:
107107

108-
```
108+
```php
109109
// resign.php
110110
<?php declare(strict_types=1);
111111

@@ -126,11 +126,11 @@ $util->save($file, Phar::SHA512);
126126

127127
Then once your PHAR is built:
128128

129-
```
130-
$ php resign.php app.phar
129+
```shell
130+
php resign.php app.phar
131131
```
132132

133-
This is obviously not ideal and should be fixed by Box at some point (see https://github.com/box-project/box/issues/1074).
133+
This is obviously not ideal and should be fixed by Box at some point (see [#1074](https://github.com/box-project/box/issues/1074)).
134134

135135

136136
<br />

‎doc/requirement-checker.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ When the requirement checker is shipped, you can always skip it by setting the e
130130
`BOX_REQUIREMENT_CHECKER` to `0`. For example if you are using the `box.phar` which ships a requirement checker and want
131131
to skip it, you can run:
132132

133-
```
134-
$ BOX_REQUIREMENT_CHECKER=0 php box.phar
133+
```shell
134+
BOX_REQUIREMENT_CHECKER=0 php box.phar
135135
```
136136

137137

@@ -140,8 +140,8 @@ $ BOX_REQUIREMENT_CHECKER=0 php box.phar
140140
Since version 3.17.0, box logs the requirements checker output to `stderr` per default (see: [#678](https://github.com/box-project/box/issues/678)).
141141
The requirements checker can be configured to output to `stdout` instead by setting `BOX_REQUIREMENTS_CHECKER_LOG_TO_STDOUT=1`:
142142

143-
```
144-
$ BOX_REQUIREMENTS_CHECKER_LOG_TO_STDOUT=1 php box.phar
143+
```shell
144+
BOX_REQUIREMENTS_CHECKER_LOG_TO_STDOUT=1 php box.phar
145145
```
146146

147147

‎doc/symfony.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ To achieve this with the least amount of changes is to:
5555

5656
- Create the `.env.local.php` file by running the following command:
5757

58-
```
59-
$ composer dump-env prod
58+
```shell
59+
composer dump-env prod
6060
```
6161

6262
This will ensure when loading the variables that your application is in production mode.

‎doc/usage.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ You can then find more advanced configuration settings in [the configuration doc
1313
For more information on which command or options is available, you can run:
1414

1515
```
16-
$ box help
16+
box help
1717
```
1818

1919
<br />

‎mkdocs.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ theme:
3333
primary: brown
3434
accent: amber
3535
features:
36+
- content.tabs.link
3637
- navigation.tabs
3738
- navigation.top
3839
custom_dir: doc/overrides
@@ -55,8 +56,11 @@ nav:
5556
markdown_extensions:
5657
- admonition
5758
- attr_list
59+
- footnotes
5860
- pymdownx.highlight
5961
- pymdownx.superfences
62+
- toc:
63+
permalink: true
6064

6165
extra_css:
6266
- assets/announce.css

0 commit comments

Comments
 (0)
Please sign in to comment.