nish 0.21.0 → 0.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/docs/AI.md +18 -0
- package/docs/INSTALL.md +30 -0
- package/package.json +8 -5
- package/runtime/browser.d.ts +1 -9
- package/runtime/browser.mjs +2 -13
- package/runtime/core/arrays.d.ts +26 -8
- package/runtime/core/arrays.mjs +31 -3
- package/runtime/core/host.d.ts +10 -0
- package/runtime/core/host.mjs +14 -0
- package/runtime/core/numbers.d.ts +14 -1
- package/runtime/core/numbers.mjs +30 -3
- package/runtime/core/result.d.ts +4 -0
- package/runtime/core/result.mjs +13 -0
- package/runtime/core/strings.d.ts +2 -2
- package/runtime/nish.d.ts +2 -2
- package/runtime/node.mjs +3 -0
- package/runtime/runtime-net.c +12 -1
- package/scripts/build.sh +58 -14
- package/scripts/check-hardening.mjs +202 -0
- package/std/README.md +2 -2
- package/std/cli.ts +17 -1
- package/std/crypto/bcrypt.ts +869 -72
- package/std/json.ts +4 -7
- package/std/net/http1-server.ts +199 -34
- package/std/net/http1.ts +40 -21
- package/std/net/postgres.ts +471 -52
- package/std/net/prefork.ts +23 -3
- package/std/random.ts +66 -4
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Reads the hardening a native binary carries, from its headers rather than
|
|
3
|
+
// from the flags that should have put it there.
|
|
4
|
+
//
|
|
5
|
+
// node scripts/check-hardening.mjs <binary> [--imports name,name,...]
|
|
6
|
+
//
|
|
7
|
+
// An ELF binary must be position independent (DYN), carry GNU_RELRO, bind now
|
|
8
|
+
// (DF_BIND_NOW or DF_1_NOW), have a GNU_STACK header without E, and carry
|
|
9
|
+
// control-flow protection: the x86 feature note naming IBT and SHSTK, or on
|
|
10
|
+
// AArch64 the feature note naming BTI and PAC, or failing that `bti` and
|
|
11
|
+
// `paciasp` in its code. The note is the linker's AND over every object, the C
|
|
12
|
+
// library's start files included, so the instructions are what show that the
|
|
13
|
+
// objects scripts/build.sh compiled carry the protection when a start file
|
|
14
|
+
// does not. A Mach-O binary must be MH_PIE and must not be
|
|
15
|
+
// MH_ALLOW_STACK_EXECUTION.
|
|
16
|
+
//
|
|
17
|
+
// `--imports` names undefined symbols the binary must import, without
|
|
18
|
+
// Mach-O's leading underscore: `__stack_chk_fail` shows the stack protector
|
|
19
|
+
// reached it, and a `__*_chk` function shows _FORTIFY_SOURCE did. Whether one
|
|
20
|
+
// appears depends on the code linked, so the caller names them. Exits 0 when
|
|
21
|
+
// every property holds, 1 naming the ones that do not, and 2 when no tool to
|
|
22
|
+
// read the binary is installed. tests/run.js ("hardening") and CI's
|
|
23
|
+
// `bootstrap` job call it (docs/security/runtime.md, RT-HARDEN).
|
|
24
|
+
|
|
25
|
+
import { spawnSync } from "node:child_process"
|
|
26
|
+
import fs from "node:fs"
|
|
27
|
+
import path from "node:path"
|
|
28
|
+
|
|
29
|
+
/** The first of `names` that runs, or null. */
|
|
30
|
+
const firstTool = (names) =>
|
|
31
|
+
names.find((name) => spawnSync(name, ["--version"], { encoding: "utf8" }).status === 0) ?? null
|
|
32
|
+
|
|
33
|
+
const run = (tool, args) => {
|
|
34
|
+
const r = spawnSync(tool, args, { encoding: "utf8", maxBuffer: 256 * 1024 * 1024 })
|
|
35
|
+
return r.status === 0 ? r.stdout : null
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const ELF_MAGIC = "7f454c46"
|
|
39
|
+
const MACHO_MAGICS = ["cffaedfe", "cefaedfe", "feedfacf", "feedface"]
|
|
40
|
+
|
|
41
|
+
const magicOf = (file) => {
|
|
42
|
+
const fd = fs.openSync(file, "r")
|
|
43
|
+
const buf = Buffer.alloc(4)
|
|
44
|
+
fs.readSync(fd, buf, 0, 4, 0)
|
|
45
|
+
fs.closeSync(fd)
|
|
46
|
+
return buf.toString("hex")
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const elfProblems = (file, imports) => {
|
|
50
|
+
const readelf = firstTool(["llvm-readelf", "llvm-readelf-18", "readelf"])
|
|
51
|
+
if (readelf === null) {
|
|
52
|
+
return { skip: "no llvm-readelf or readelf on PATH", problems: [] }
|
|
53
|
+
}
|
|
54
|
+
const out = run(readelf, ["-W", "-h", "-l", "-d", "-n", "--dyn-syms", file])
|
|
55
|
+
if (out === null) {
|
|
56
|
+
return { skip: null, problems: [`${readelf} could not read ${file}`] }
|
|
57
|
+
}
|
|
58
|
+
const problems = []
|
|
59
|
+
const type = /^\s*Type:\s+(\S+)/m.exec(out)
|
|
60
|
+
if (type === null || type[1] !== "DYN") {
|
|
61
|
+
problems.push(`not position independent: Type is ${type === null ? "missing" : type[1]}, not DYN`)
|
|
62
|
+
}
|
|
63
|
+
if (!/^\s*GNU_RELRO\s/m.test(out)) {
|
|
64
|
+
problems.push("no GNU_RELRO program header (-z relro)")
|
|
65
|
+
}
|
|
66
|
+
const flags = /\(FLAGS\)\s+(.*)$/m.exec(out)
|
|
67
|
+
const flags1 = /\(FLAGS_1\)\s+(.*)$/m.exec(out)
|
|
68
|
+
const bindNow =
|
|
69
|
+
(flags !== null && /\bBIND_NOW\b/.test(flags[1])) || (flags1 !== null && /\bNOW\b/.test(flags1[1]))
|
|
70
|
+
if (!bindNow) {
|
|
71
|
+
problems.push("does not bind now: no BIND_NOW in FLAGS or NOW in FLAGS_1 (-z now), so RELRO is partial")
|
|
72
|
+
}
|
|
73
|
+
const stack = /^\s*GNU_STACK\s+(?:0x[0-9a-f]+\s+){5}([RWE ]{3})/m.exec(out)
|
|
74
|
+
if (stack === null) {
|
|
75
|
+
problems.push("no GNU_STACK program header, so the stack may be executable (-z noexecstack)")
|
|
76
|
+
} else if (stack[1].includes("E")) {
|
|
77
|
+
problems.push(`the stack is executable: GNU_STACK flags are "${stack[1].trim()}"`)
|
|
78
|
+
}
|
|
79
|
+
const machine = /^\s*Machine:\s+(.*)$/m.exec(out)
|
|
80
|
+
const machineName = machine === null ? "" : machine[1]
|
|
81
|
+
if (/X86-64/.test(machineName)) {
|
|
82
|
+
const note = /x86 feature:\s*(.*)$/m.exec(out)
|
|
83
|
+
if (note === null || !/\bIBT\b/.test(note[1]) || !/\bSHSTK\b/.test(note[1])) {
|
|
84
|
+
problems.push(
|
|
85
|
+
`no control-flow protection: the x86 feature note is ${note === null ? "missing" : `"${note[1].trim()}"`}, not IBT, SHSTK (-fcf-protection=full)`
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
} else if (/AArch64/.test(machineName)) {
|
|
89
|
+
const note = /AArch64 feature:\s*(.*)$/m.exec(out)
|
|
90
|
+
if (note === null || !/\bBTI\b/.test(note[1]) || !/\bPAC\b/.test(note[1])) {
|
|
91
|
+
problems.push(...aarch64CodeProblems(file))
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const undefinedNames = new Set(
|
|
95
|
+
out
|
|
96
|
+
.split("\n")
|
|
97
|
+
.filter((line) => /\sUND\s/.test(line))
|
|
98
|
+
.map((line) => line.trim().split(/\s+/).at(-1).replace(/@.*$/, ""))
|
|
99
|
+
)
|
|
100
|
+
for (const name of imports) {
|
|
101
|
+
if (!undefinedNames.has(name)) {
|
|
102
|
+
problems.push(`does not import ${name}`)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return { skip: null, problems }
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Without the feature note, the protection shown in the instructions themselves. */
|
|
109
|
+
const aarch64CodeProblems = (file) => {
|
|
110
|
+
const objdump = firstTool(["llvm-objdump", "llvm-objdump-18", "objdump"])
|
|
111
|
+
if (objdump === null) {
|
|
112
|
+
return ["no AArch64 feature note naming BTI and PAC, and no llvm-objdump to look for the instructions"]
|
|
113
|
+
}
|
|
114
|
+
const code = run(objdump, ["-d", "--no-show-raw-insn", file]) ?? ""
|
|
115
|
+
const problems = []
|
|
116
|
+
if (!/\sbti\b/.test(code)) {
|
|
117
|
+
problems.push(
|
|
118
|
+
"no BTI: neither the AArch64 feature note nor a `bti` instruction (-mbranch-protection=standard)"
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
if (!/\spaciasp\b/.test(code)) {
|
|
122
|
+
problems.push(
|
|
123
|
+
"no return-address signing: neither the AArch64 feature note nor a `paciasp` instruction (-mbranch-protection=standard)"
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
return problems
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const machoProblems = (file, imports) => {
|
|
130
|
+
const readobj = firstTool(["llvm-readobj", "llvm-readobj-18"])
|
|
131
|
+
if (readobj === null) {
|
|
132
|
+
return { skip: "no llvm-readobj on PATH", problems: [] }
|
|
133
|
+
}
|
|
134
|
+
const header = run(readobj, ["--file-headers", file])
|
|
135
|
+
if (header === null) {
|
|
136
|
+
return { skip: null, problems: [`${readobj} could not read ${file}`] }
|
|
137
|
+
}
|
|
138
|
+
const problems = []
|
|
139
|
+
if (!/\bMH_PIE\b/.test(header)) {
|
|
140
|
+
problems.push("not position independent: no MH_PIE flag")
|
|
141
|
+
}
|
|
142
|
+
if (/\bMH_ALLOW_STACK_EXECUTION\b/.test(header)) {
|
|
143
|
+
problems.push("the stack is executable: MH_ALLOW_STACK_EXECUTION is set")
|
|
144
|
+
}
|
|
145
|
+
if (imports.length > 0) {
|
|
146
|
+
const nm = firstTool(["llvm-nm", "llvm-nm-18", "nm"])
|
|
147
|
+
const names = new Set(
|
|
148
|
+
(nm === null ? "" : (run(nm, ["-u", file]) ?? ""))
|
|
149
|
+
.split("\n")
|
|
150
|
+
.map((line) => line.trim().split(/\s+/).at(-1) ?? "")
|
|
151
|
+
.map((name) => (name.startsWith("_") ? name.slice(1) : name))
|
|
152
|
+
)
|
|
153
|
+
for (const name of imports) {
|
|
154
|
+
if (!names.has(name)) {
|
|
155
|
+
problems.push(`does not import ${name}`)
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return { skip: null, problems }
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* What `file` lacks of the hardening, or why it could not be read: `skip` is
|
|
164
|
+
* the missing tool, and `problems` is empty when every property holds.
|
|
165
|
+
*/
|
|
166
|
+
export const hardeningProblems = (file, imports = []) => {
|
|
167
|
+
const magic = magicOf(file)
|
|
168
|
+
if (magic === ELF_MAGIC) {
|
|
169
|
+
return elfProblems(file, imports)
|
|
170
|
+
}
|
|
171
|
+
if (MACHO_MAGICS.includes(magic)) {
|
|
172
|
+
return machoProblems(file, imports)
|
|
173
|
+
}
|
|
174
|
+
return { skip: null, problems: [`${file} is neither ELF nor Mach-O (magic ${magic})`] }
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const main = () => {
|
|
178
|
+
const args = process.argv.slice(2)
|
|
179
|
+
const at = args.indexOf("--imports")
|
|
180
|
+
const imports = at < 0 ? [] : (args[at + 1] ?? "").split(",").filter((name) => name !== "")
|
|
181
|
+
const files = at < 0 ? args : args.filter((_, i) => i !== at && i !== at + 1)
|
|
182
|
+
if (files.length !== 1 || (at >= 0 && imports.length === 0)) {
|
|
183
|
+
process.stderr.write("usage: node scripts/check-hardening.mjs <binary> [--imports name,name,...]\n")
|
|
184
|
+
process.exit(2)
|
|
185
|
+
}
|
|
186
|
+
const result = hardeningProblems(files[0], imports)
|
|
187
|
+
if (result.skip !== null) {
|
|
188
|
+
process.stderr.write(`check-hardening: ${result.skip}\n`)
|
|
189
|
+
process.exit(2)
|
|
190
|
+
}
|
|
191
|
+
if (result.problems.length > 0) {
|
|
192
|
+
for (const problem of result.problems) {
|
|
193
|
+
process.stderr.write(`check-hardening: ${files[0]}: ${problem}\n`)
|
|
194
|
+
}
|
|
195
|
+
process.exit(1)
|
|
196
|
+
}
|
|
197
|
+
process.stdout.write(`check-hardening: ${files[0]}: hardened\n`)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (path.resolve(process.argv[1] ?? "") === import.meta.filename) {
|
|
201
|
+
main()
|
|
202
|
+
}
|
package/std/README.md
CHANGED
|
@@ -24,7 +24,7 @@ whatever program imports it, and subject to the same rules as `examples/` or
|
|
|
24
24
|
| [`map.ts`](./map.ts) | `reserve(m, n)` and `getOrInsert(m, k, v)` for the global `Map`. Their bodies are the meaning, and what runs under Node: `reserve` does nothing, and `getOrInsert` is a `get`, and a `set` of `v` when the key was missing. Natively the compiler lowers every call in place — `reserve` to the table's `reserveSlots`, which grows the buckets once so that `n` entries fit without a rebuild, and `getOrInsert` to one `probe` and a `valueAt` or an `insertAt` through its answer — so, like `collections.ts`, it writes no `.ll` of its own ([`docs/wp32-map.md`](../docs/wp32-map.md) §9.2, [`docs/LANGUAGE.md`](../docs/LANGUAGE.md#map-and-set)) |
|
|
25
25
|
| [`bytes.ts`](./bytes.ts) | `getU16LE` / `getU16BE` to `getF64LE` / `getF64BE` and the `set` twins: `u16`, `u32`, `u64`, `i32`, `i64` and `f64` read from and written into a `u8[]` at an offset, little- or big-endian. Each access is an ordinary index, so out of range is an `index` panic naming the first missing byte. In range the answers are those of the private copies `std/` keeps (`sha256LoadWord`, `chacha20Word`, `poly1305Le64`, sha512's `loadWord` / `storeWord`, `http2FramePut32`, `tlsPutU16`), none of which it replaces. A guard in the caller does not yet remove the checks after inlining. Under Node only the `u16` and `u32` functions answer as natively. Beside them are the runs a parser walks — `skipBlank`, `skipDigits`, `skipJsonText` and `skipJsonPlain`, the first index in a clamped range whose byte is not a JSON blank, a digit, a byte a JSON string holds as itself or a byte a JSON writer copies without an escape — and `copyBytes`, a window copied as one move that panics on a range outside its array. Their bodies call private walkers, which are what runs under Node; natively the compiler replaces each walker's call with a kernel of `runtime/runtime-bytes.c`, or `llvm.memmove` for the copy ([`docs/LANGUAGE.md`](../docs/LANGUAGE.md#byte-runs-skipblank-skipdigits-skipjsontext-skipjsonplain-and-copybytes-in-nishbytes)). The runs are variable-time. `tests/link/std_bytes*` are its programs |
|
|
26
26
|
| [`base64.ts`](./base64.ts) | `nish/base64`: `base64Encode(bytes)`, `base64EncodeInto(src, off, len, dst, at)` and `base64EncodedLength(n)`, padded standard base64 (RFC 4648 §4) for kitty graphics frames. It only encodes, and it indexes its alphabet by the sextet, so it is not constant-time: it is for pixels, not secrets. A strict decoder, and an encoder for key material, are `crypto/base64url.ts`'s `base64StdPadDecode` and `base64StdPadEncode` (`tests/link/std_base64`; the two modules in one program: `tests/link/std_base64_two_modules`) |
|
|
27
|
-
| [`random.ts`](./random.ts) | `Rng`, a seeded generator of pseudo-random numbers: `new Rng(seed)`, `nextI32()` and `
|
|
27
|
+
| [`random.ts`](./random.ts) | `Rng`, a seeded generator of pseudo-random numbers: `new Rng(seed)`, `nextI32()`, `nextF64()` and `nextInt(lo, hi)`, an unbiased integer in [lo, hi] by rejection sampling. A Weyl sequence through all 2^32 states with MurmurHash3's finaliser on each, written with `nish:unsafe`'s `wrappingAdd`, `wrappingSub` and `wrappingMul` so that every answer is the same bits natively and under Node (`tests/link/std_random`; [`docs/LANGUAGE.md`](../docs/LANGUAGE.md#random-numbers-rng-in-nishrandom)). A parallel body or a task that makes its own steps it without a shared write. Not for cryptography |
|
|
28
28
|
| [`cli.ts`](./cli.ts) | a command-line tool's `--help`. `HelpMenu` builds it a line at a time — `header`, `usage`, `section`, `row(flag, placeholder, description)`, `note`, `value` — with descriptions lined up at the caller's columns, counted on the plain text, and answers it with `text()`. `Style` paints it in the eight basic ANSI colours, bold and faint, which the terminal's theme defines, or in bold and underline alone when `TERM` declares no colours. `styleFor(fd, agent)` is the policy `nish --help` follows: plain unless the descriptor is a terminal, `NO_COLOR`, `FORCE_COLOR`, `CLICOLOR_FORCE`, `CLICOLOR` and `TERM=dumb` honoured, plain for an agent (`agentDriven`), forced colour always the theme's; it reads the environment and, for the terminal check, forks `/bin/sh` once, which runs `tput` by absolute path. `HelpMenu` and `Style` reach no capability. The compiler's own help is built with it through a relative import, so the module may use only what the last release compiles (`tests/link/std_cli`; [guide](../docs/guide/using-nish/standard-library.md#nishcli)) |
|
|
29
29
|
| [`sqlite.ts`](./sqlite.ts) | SQLite, vendored in `runtime/sqlite/` and linked into a program that imports the module, through the C adapter `runtime/sqlite/nish-sqlite.c`. `openDatabase(path, flags)` answers a `Database`: `exec`, `begin` / `commit` / `rollback`, `prepare` into a `Statement`, `lastInsertRowid`, `changes` and `close`, which finalizes the connection's statements. A `Statement` binds (`bindI64`, `bindF64`, `bindNull`, `bindText`, `bindTextBytes`, `bindBlob`), steps, resets and reads columns (`columnType`, `columnI64`, `columnF64`, `columnBytes`, `columnText`, and `columnInto`, a copy into the caller's `u8[]`), so a row allocates nothing. Every failure is a `Result` of SQLite's extended code, and `error(code)` builds the `SqliteError` with its message. A handle is an `i32` into the adapter's thread-local tables, and one used after `close` or `finalize` answers `SQLITE_MISUSE`. Reaches `ffi`; links natively and under `--profile wasi` (`tests/link/std_sqlite*`; [`docs/LANGUAGE.md`](../docs/LANGUAGE.md#sqlite-nishsqlite)) |
|
|
30
30
|
| [`base64.ts`](./base64.ts) | standard base64 (RFC 4648 §4) with `=` padding, encode only: `base64Encode(bytes)` answers a string, `base64EncodeInto(src, off, len, dst, at)` writes into a byte buffer allocating nothing, `base64EncodedLength(n)` sizes it; a range outside its array panics before a byte is written. What kitty graphics frames are sent in; not the constant-time `crypto/base64url` (`tests/link/std_base64`, `std_base64_f64`, `std_base64_negative_*`; [guide](../docs/guide/using-nish/standard-library.md#nishbase64)) |
|
|
@@ -81,7 +81,7 @@ is listed in [`SECURITY.md`](../SECURITY.md#threat-model).
|
|
|
81
81
|
| [`crypto/hmac.ts`](./crypto/hmac.ts) | `hmacSha256` and `hmacSha384`, the streaming `HmacSha256` and `HmacSha384` (keyed in the constructor, then `update` and `digest`), and `hmacSha256Verify` / `hmacSha384Verify`, which compare a received tag with `timingSafeEqual`. The one-shot functions panic on a message longer than 2^31 − 1 bytes. `HmacSha256Scratch` / `HmacSha384Scratch` are the same tag over hashers the caller allocates once — `begin(key, off, len)`, `update`, `finishInto(out, at)`, `wipe` — so a loop of them inside `using a = arena()` leaves the arena where it was; `hmacCopySha256` / `hmacCopySha384` copy a hasher's state into one the caller holds. `pbkdf2HmacSha256(password, salt, iterations, dkLen)` is PBKDF2 with HMAC-SHA-256, for SCRAM-SHA-256: the password goes in and the key comes out as a `Secret<u8[]>`, every intermediate is wiped, and fewer than one iteration or a `dkLen` below one answers `null` | RFC 2104, RFC 4231 §4, RFC 8018 §5.2 |
|
|
82
82
|
| [`crypto/hkdf.ts`](./crypto/hkdf.ts) | `hkdfExtractSha256` / `hkdfExtractSha384` (an empty salt is HashLen zeros) and `hkdfExpandSha256` / `hkdfExpandSha384`, which answer `null` for a length below zero or above 255 × HashLen, for an `info` longer than 2^31 − 1 bytes, and for a PRK shorter than HashLen. `hkdfExpandLabelSha256` / `hkdfExpandLabelSha384` are TLS 1.3's HKDF-Expand-Label, which QUIC uses too; the label is given without its `"tls13 "` prefix, and a length outside 0 to 255, a label outside 1 to 249 bytes, a context past 255 bytes or a secret shorter than HashLen panics, since each is the program's choice rather than the peer's. `hkdfExtractInto`, `hkdfExpandInto` (`false` where the others answer `null`) and `hkdfExpandLabelInto` compute the same bytes in an `HkdfScratch` the caller owns, over the hash a length of 32 or 48 names, into the caller's array, and wipe the scratch before they return. A key held as a `Secret<u8[]>` (`nish:secret`) goes through the `*Secret` twins, which read it only inside `exposeWith` and answer a `Secret`: `hkdfSha256Secret` / `hkdfSha384Secret`, each step's, and `hkdfExpandLabelSha256Secret(prk, label, context, length)` / `hkdfExpandLabelSha384Secret`, which panic where HKDF-Expand-Label does. A destination already held as a `Secret` is derived into in place by `hkdfExpandLabelSha256Held(dst, prk, label, context)` / `hkdfExpandLabelSha384Held`, as many bytes as `dst` holds, the plain output copied in inside `exposeWith` and wiped; `dst` may be `prk`. `hkdfExpandLabelHeldInto(hashLength, prk, label, context, out, at, length)` writes a plain window from a held PRK, for output that is plain by design, a record key or IV | RFC 5869 §2, Appendix A; RFC 8448 §3 and RFC 9001 A.1 for the label |
|
|
83
83
|
| [`crypto/ct.ts`](./crypto/ct.ts) | `timingSafeEqual(a, b)`, which reads every byte whatever it holds, and `timingSafeEqualAt(a, aOff, b, bOff, len)` over two windows, which answers `false` for a window outside its array. Two lengths that differ answer `false` at once, because a length is public, and so does an array longer than 2^31 − 1 bytes | — |
|
|
84
|
-
| [`crypto/bcrypt.ts`](./crypto/bcrypt.ts) | `bcryptHash(password, salt, cost)`, the 60-character `$2b$` hash of a `Secret<u8[]>` password under a 16-byte salt and a cost of 4 to 31, and `bcryptVerify(password, hash)`, which reads `$2a$`, `$2b$` and `$2y$` hashes, refuses `$2x$`, and compares in constant time. The first 72 bytes of a password count, up to its first NUL, as under libxcrypt's `crypt_r` (where other implementations differ: [the interoperability table](../docs/security/crypto-bcrypt.md#interoperability)); the Blowfish state is wiped before either returns. `BCRYPT_MAX_PASSWORD`, `BCRYPT_HASH_LENGTH`, `BCRYPT_SALT_SIZE`, `BCRYPT_MIN_COST`, `BCRYPT_MAX_COST`. A `std/threads` task
|
|
84
|
+
| [`crypto/bcrypt.ts`](./crypto/bcrypt.ts) | `bcryptHash(password, salt, cost)`, the 60-character `$2b$` hash of a `Secret<u8[]>` password under a 16-byte salt and a cost of 4 to 31, and `bcryptVerify(password, hash)`, which reads `$2a$`, `$2b$` and `$2y$` hashes, refuses `$2x$`, and compares in constant time. The first 72 bytes of a password count, up to its first NUL, as under libxcrypt's `crypt_r` (where other implementations differ: [the interoperability table](../docs/security/crypto-bcrypt.md#interoperability)); the Blowfish state is wiped before either returns. `bcryptHash4(p0, p1, p2, p3, salts, cost)` and `bcryptVerify4(p0, p1, p2, p3, hashes)` do up to four at once, interleaved (four in the time of about 1.2 single hashes on one core), each lane the single path's answer; verify groups lanes by cost, and a malformed lane makes the whole call an `Err` naming it. `BCRYPT_MAX_PASSWORD`, `BCRYPT_HASH_LENGTH`, `BCRYPT_SALT_SIZE`, `BCRYPT_MIN_COST`, `BCRYPT_MAX_COST`. A `std/threads` task may call all four ([BCRYPT-9](../docs/security/crypto-bcrypt.md#findings)) | OpenBSD `bcrypt(3)`; crypt_blowfish 1.3 for `$2a$` and `$2y$` |
|
|
85
85
|
| [`crypto/base64url.ts`](./crypto/base64url.ts) | `base64urlEncode(data)` and `base64urlDecode(text)`, unpadded; `base64StdPadEncode(data)` and `base64StdPadDecode(text)`, the padded standard alphabet that SCRAM and PEM use, constant-time in both directions. These are not `nish/base64`, which encodes only, is not constant-time and is for pixels; the names differ because std modules share the program's one namespace. Decoding is strict, so every byte string has one spelling. `base64urlDecode` answers `null` for any `=`, a character outside the alphabet, a length of 1 mod 4 or nonzero unused low bits; `base64StdPadDecode` requires the padding, answering `null` unless the text is whole four-character groups with `=` only as the last one or two characters, every other character in the alphabet and the unused bits zero. Both refuse a text longer than 2^31 − 1 bytes, and `base64urlEncode` panics on such an array | RFC 4648 §4, §5, §10 (`tests/link/std_base64_padded`) |
|
|
86
86
|
| [`crypto/sha1.ts`](./crypto/sha1.ts) | `sha1(data)`, a fresh 20-byte digest, and `SHA1_SIZE` and `SHA1_BLOCK`. **Not for security**: SHA-1 is broken for collisions, and it is here only because RFC 6455 §4.2.2's `Sec-WebSocket-Accept` is defined on it (`nish/net/websocket` is its importer). One-shot only; it panics on an array longer than 2^31 − 1 bytes. It came after the #363 audit and has no record in `docs/security/` | FIPS 180-4 §6.1 |
|
|
87
87
|
| [`crypto/x25519.ts`](./crypto/x25519.ts) | `x25519(scalar, u)`, the shared secret as a `Secret<u8[]>`, and `x25519Base(scalar)`, the public key, each from a `Secret<u8[]>` scalar, on ten 25.5-bit limbs in `i64`. Either answers `null` unless its arguments are `X25519_SIZE` (32) bytes; the scalar is clamped on a copy, which is wiped | RFC 7748 §5.2, §6.1, Wycheproof `x25519_test` |
|
package/std/cli.ts
CHANGED
|
@@ -273,9 +273,25 @@ export class HelpMenu {
|
|
|
273
273
|
|
|
274
274
|
/** The opening line, the program's name, `version` and a one-line `summary`, and a blank after it. */
|
|
275
275
|
header(version: string, summary: string): void {
|
|
276
|
+
this.title(version, summary)
|
|
277
|
+
this.lines.push("")
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* The opening line alone, without `header`'s blank after it, for a menu that
|
|
282
|
+
* puts something under its title (`line`) before the blank.
|
|
283
|
+
*/
|
|
284
|
+
title(version: string, summary: string): void {
|
|
276
285
|
const style = this.style
|
|
277
286
|
this.lines.push(`${style.name(this.program)} ${style.dim(version)} ${style.dim(summary)}`)
|
|
278
|
-
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* A line exactly as given, painted (or not) by the caller with the menu's
|
|
291
|
+
* `style`: a rule, a banner, a blank. Its width is the caller's to keep.
|
|
292
|
+
*/
|
|
293
|
+
line(text: string): void {
|
|
294
|
+
this.lines.push(text)
|
|
279
295
|
}
|
|
280
296
|
|
|
281
297
|
/**
|