Skip to content

Commit 29ff45c

Browse files
committed
New CLI
New CLI - add/remove/replace/info commands
1 parent 15e7560 commit 29ff45c

8 files changed

Lines changed: 552 additions & 138 deletions

File tree

js/sign/README.md

Lines changed: 42 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -124,80 +124,47 @@ const webBundleIdWithIWAOrigin = new wbnSign.WebBundleId(
124124

125125
## CLI
126126

127-
This package also includes 2 CLI tools
127+
This package includes 2 CLI tools:
128128

129-
- `wbn-sign` which lets you sign a web bundle easily without having to write any
130-
additional JavaScript.
131-
- `wbn-dump-id` which can be used to calculate the Web Bundle ID corresponding
132-
to your signing key.
129+
- `wbn-sign`: A comprehensive tool for signing bundles and managing signatures.
130+
- `wbn-dump-id`: A simple utility to calculate the Web Bundle ID for a given key.
133131

134-
### Running wbn-sign
135-
#### New usage form (>= 0.2.7)
132+
### Running wbn-sign
136133

137-
The base usage from is: `wbn-sign [command] [options] <arguments...>`
134+
The base usage is: `wbn-sign [command] [options] <arguments...>`
138135

139-
Currenly supported commands are:
140-
```
141-
Usage: wbn-sign sign [options] <web_bundle> <private_keys...>
142-
143-
Signs the given web bundle with private key(s). Produces signed web bundle output file.
144-
145-
Arguments:
146-
web_bundle a web bundle (file `*.wbn`) to sign
147-
private_keys private keys (files `*.pem`) with which the web bundle will be signed. EcdsaP256 and ed25519 keys (encrypted and not encrypted) are supported.
148-
149-
Options:
150-
-o, --output <file> signed web bundle output file (default: "signed.swbn")
151-
--web-bundle-id <web-bundle-id> web bundle ID. Derived from the first key if not specified.
152-
-h, --help display help for command
153-
```
136+
#### Commands:
154137

155-
For more details check `wbn-sign help [command]`.
138+
- `sign <web_bundle> <private_keys...>`: Signs a web bundle with one or more private keys.
139+
- `add-signature <signed_web_bundle> <private_keys...>`: Adds new signatures to an already signed bundle.
140+
- `remove-signature <signed_web_bundle> <keys...>`: Removes signatures from a bundle. Keys can be public (Base64/.pem) or private (.pem).
141+
- `replace-signature <signed_web_bundle> <old_key> <new_private_key>`: Replaces an existing signature.
142+
- `info <web_bundle>`: Displays information about the integrity block, including the Web Bundle ID and public keys of signers.
156143

157-
Example commands:
144+
#### Examples:
158145

159146
```bash
160-
wbn-sign sign ~/path/to/webbundle.wbn ~/path/to/ed25519key.pem -o ~/path/to/signed-webbundle.swbn
161-
```
147+
# Sign a web bundle with two keys.
148+
wbn-sign sign webbundle.wbn key1.pem key2.pem -o signed.swbn
162149

163-
```bash
164-
wbn-sign sign ~/path/to/webbundle.wbn ~/path/to/ed25519key.pem ~/path/to/ecdsa_p256key.pem \
165-
--web-bundle-id amfcf7c4bmpbjbmq4h4yptcobves56hfdyr7tm3doxqvfmsk5ss6maacai \
166-
-o ~/path/to/signed-webbundle.swbn
167-
```
150+
# Add a signature to an existing swbn.
151+
wbn-sign add-signature signed.swbn key3.pem --in-place
168152

153+
# View information about a signed bundle.
154+
wbn-sign info signed.swbn
155+
```
169156

170-
#### Legacy usage (<0.2.6)
171-
Previously the CLI tool used only options (no command). This usage form will be deprecated, but in the actual version is still supported.
172-
173-
In `wbn-sign [options]` form followling options are available:
174-
- (required) `--private-key <filePath>` (`-k <filePath>`)
175-
which takes the path to ed25519/ecdsaP256 private key. Can be specified multiple times.
176-
- (required) `--input <filePath>` (`-i <filePath>`)
177-
which takes the path to the web bundle to be signed.
178-
- (optional) `--output <filePath>` (`-o <filePath>`)
179-
which takes the path to the wanted signed web bundle output. Default:
180-
`signed.swbn`.
181-
- (required if more than one key is provided)
182-
`--web-bundle-id <web-bundle-id>`
183-
which takes the `web-bundle-id` to be associated with the web bundle.
157+
For more details, run `wbn-sign help [command]`.
184158

185159
### Running wbn-dump-id
186160

187-
There are the following command-line flags available:
188-
189-
- (required) `--key <filePath>` which takes the path to ed25519/ecdsaP256 public
190-
or private key.
191-
- (optional) `--with-iwa-scheme <boolean>` (`-s`) which dumps the Web Bundle ID
192-
with isolated-app:// scheme. By default it only dumps the ID. Default:
193-
`false`.
194-
- (optional) `--with-key-type <boolean>` (`-t`) which also outputs the type of
195-
the key used (ecdsa/ed25519). Default: `false`.
196-
197-
Example command:
161+
- `--key <filePath>` (required): Path to ed25519/ecdsaP256 public or private key.
162+
- `--with-iwa-scheme` (`-s`): Dumps the Web Bundle ID with `isolated-app://` scheme.
163+
- `--with-key-type` (`-t`): Outputs the type of the key used (ecdsa/ed25519).
198164

165+
Example:
199166
```bash
200-
wbn-dump-id -s -k ~/path/to/ed25519key.pem
167+
wbn-dump-id -s -k /ed25519key.pem
201168
```
202169

203170
This would print the Web Bundle ID calculated from `ed25519key.pem` into the
@@ -218,31 +185,41 @@ The environment variable set like this, can then be used in other scripts, for
218185
example in `--baseURL` when creating a web bundle with
219186
[wbn CLI tool](https://github.com/WICG/webpackage/tree/main/js/bundle#cli).
220187

221-
## Generating Ed25519 key
188+
## Generating Keys
189+
190+
### Ed25519
222191

223192
An unencrypted ed25519 private key can be generated with:
224193

225194
```
226195
openssl genpkey -algorithm Ed25519 -out ed25519key.pem
227196
```
228197

229-
For better security, one should prefer using passphrase-encrypted ed25519
198+
### ECDSA P-256
199+
```bash
200+
openssl ecparam -name prime256v1 -genkey -noout -out ecdsap256key.pem
201+
```
202+
203+
### Encrytpion
204+
For better security, one should prefer using passphrase-encrypted
230205
private keys. To encrypt an unencrypted private key, run:
231206

232-
```
207+
```bash
233208
# encrypt the key (will ask for a passphrase, make sure to use a strong one)
234-
openssl pkcs8 -in ed25519key.pem -topk8 -out encrypted_ed25519key.pem
209+
openssl pkcs8 -in private_key.pem -topk8 -out encrypted_key.pem
235210
# delete the unencrypted key
236-
rm ed25519key.pem
211+
rm private_key.pem
237212
```
238213

239-
If you use an encrypted private key, you will be prompted for its passphrase as
214+
If you use an encrypted private key to sign a bundle, you will be prompted for its passphrase as
240215
part of the signing process. If you want to use the CLI tool programmatically,
241216
then you can bypass the passphrase prompt by storing the passphrase in an
242217
environment variable named `WEB_BUNDLE_SIGNING_PASSPHRASE`.
243-
244218
## Release Notes
245219

220+
### v0.3.1
221+
- Enhanced **CLI**: New commands `add-signature`, `remove-signature`, `replace-signature`, and `info`.
222+
246223
### v0.3.0
247224
- **Major architectural update**: Introduced `SignedWebBundle` as the primary interface for managing signed bundles.
248225
- Support for **multi-signatures**: Add, remove, and replace signatures in already signed web bundles.

js/sign/package-lock.json

Lines changed: 12 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/sign/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wbn-sign",
3-
"version": "0.3.0",
3+
"version": "0.3.1",
44
"description": "Tool to sign web bundles and manage signatures of signed web bundles.",
55
"homepage": "https://github.com/WICG/webpackage/tree/main/js/sign",
66
"main": "./lib/wbn-sign.cjs",
@@ -44,6 +44,7 @@
4444
"dependencies": {
4545
"base32-encode": "^2.0.0",
4646
"cborg": "^4.2.14",
47+
"colors": "^1.4.0",
4748
"commander": "^14.0.0",
4849
"read": "^2.0.0"
4950
},

0 commit comments

Comments
 (0)