Skip to content

Commit 3c81376

Browse files
authored
fix: audit and common fixes (#55)
* fix doctests * task: pin differential tests to specific commit (#58) * fix(F7): CBC encryption for ooba target (#56) * add cbc encryption for ooba target * use crate's inner trait method * add security warning * fix(F6): hint entropy leak (#57) * add hint to integrity checks * add integrity check for add hint * verify policy integrity before hint checks * fix(F3): derive internal key and external key for domain separation (#59) clippy fixes * fix(F4): add docs for integrity
1 parent 898bb26 commit 3c81376

25 files changed

Lines changed: 522 additions & 110 deletions

File tree

.github/workflows/bindings.yaml

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,25 +94,6 @@ jobs:
9494
name: mfkdf2-web-mochawesome-report
9595
path: mfkdf2-web/test-results/mochawesome/
9696

97-
98-
- name: Generate TypeScript bindings for differential tests
99-
working-directory: mfkdf2-web
100-
run: npm run ubrn:web:differential:release
101-
102-
- name: Copy index.web.ts implementation
103-
run: cp mfkdf2-web/src/index.ts mfkdf2-web/src/index.web.ts
104-
105-
- name: Run differential tests with reports
106-
working-directory: mfkdf2-web
107-
run: npm run test:differential:report
108-
109-
- name: Upload differential HTML test report
110-
if: always()
111-
uses: actions/upload-artifact@v4
112-
with:
113-
name: mfkdf2-web-differential-report
114-
path: mfkdf2-web/test-results/mochawesome-differential/
115-
11697
- name: Run TypeScript type checking
11798
working-directory: mfkdf2-web
11899
run: npm run typecheck
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Differential Tests
2+
concurrency:
3+
group: ${{ github.workflow }}-${{ github.ref }}
4+
cancel-in-progress: true
5+
6+
on:
7+
workflow_dispatch:
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
differential-tests:
14+
name: differential
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout pinned mfkdf2.rs commit
18+
uses: actions/checkout@v4
19+
with:
20+
ref: 7c33c7164d6e40a26c0899f19b8f9ad9b9f0c029
21+
22+
- name: Install Rust
23+
uses: dtolnay/rust-toolchain@master
24+
with:
25+
toolchain: stable
26+
targets: wasm32-unknown-unknown
27+
28+
- name: Rust Cache
29+
uses: Swatinem/rust-cache@v2
30+
with:
31+
key: typescript/differential
32+
33+
- name: Setup Node.js
34+
uses: actions/setup-node@v4
35+
with:
36+
node-version: "20"
37+
cache: "npm"
38+
cache-dependency-path: mfkdf2-web/package-lock.json
39+
40+
- name: Install wasm-bindgen-cli
41+
uses: taiki-e/install-action@v2
42+
with:
43+
tool: wasm-bindgen-cli
44+
45+
- name: Cache node_modules
46+
id: cache-node-modules
47+
uses: actions/cache@v4
48+
with:
49+
path: mfkdf2-web/node_modules
50+
key: ${{ runner.os }}-node-modules-${{ hashFiles('mfkdf2-web/package-lock.json') }}
51+
restore-keys: |
52+
${{ runner.os }}-node-modules-
53+
54+
- name: Install mfkdf2-web dependencies
55+
if: steps.cache-node-modules.outputs.cache-hit != 'true'
56+
working-directory: mfkdf2-web
57+
run: npm ci
58+
59+
- name: Generate TypeScript bindings for differential tests
60+
working-directory: mfkdf2-web
61+
run: npm run ubrn:web:differential:release
62+
63+
- name: Copy index.web.ts implementation
64+
run: cp mfkdf2-web/src/index.ts mfkdf2-web/src/index.web.ts
65+
66+
- name: Verify bindings were generated
67+
run: |
68+
if [ ! -d "mfkdf2-web/src/generated" ] || [ -z "$(ls -A mfkdf2-web/src/generated)" ]; then
69+
echo "Error: mfkdf2-web/src/generated does not exist or is empty"
70+
exit 1
71+
fi
72+
if [ ! -d "mfkdf2-web/rust_modules" ]; then
73+
echo "Error: mfkdf2-web/rust_modules does not exist"
74+
exit 1
75+
fi
76+
echo "✓ TypeScript bindings verified"
77+
78+
- name: Run differential tests
79+
working-directory: mfkdf2-web
80+
run: npm run test:differential
81+
82+

.github/workflows/rust.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ jobs:
119119

120120
- name: Run tests (JUnit)
121121
run: cargo nextest run --release --profile ci
122+
123+
- name: Run doctests
124+
run: cargo test --release --doc
122125

123126
- name: Publish JUnit test report
124127
if: always()
@@ -184,7 +187,7 @@ jobs:
184187
uses: taiki-e/install-action@cargo-llvm-cov
185188

186189
- name: Run cargo-llvm-cov
187-
run: cargo llvm-cov --all-features --workspace --html --output-dir target/coverage
190+
run: cargo llvm-cov --workspace --html --output-dir target/coverage
188191

189192
- name: Upload coverage to Artifacts
190193
uses: actions/upload-artifact@v4

Cargo.lock

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

SECURITY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Please check here before filing new reports.
1212
| Affected Version(s) | Description | Status | CVE / Advisory |
1313
| ------------------- | ---------------------------------------------------------------------- | ------------ | -------------- |
1414
| 0.0.1 | RSA Marvin Attack: potential key recovery through timing sidechannels. | 🔴 Unresolved | 2023-49092 |
15+
| 0.0.1 | Generic-Array: v0.14.9 is deprecated but used by aes-v0.8.4 | 🔴 Unresolved | - |
1516

1617
Legend:
1718
- 🟢 Fixed

docs/src/differential-tests.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,26 @@ See: [multifactor/MFKDF#27](https://github.com/multifactor/MFKDF/pull/27)
3131
See: [multifactor/MFKDF2.rs#43](https://github.com/multifactor/MFKDF2.rs/pull/43)
3232
- Add a `differential-test` feature flag providing a global deterministic RNG equivalent to the reference.
3333
- Provide utility methods in the TypeScript bindings facade for nested parameter parsing and stringification (read/write inner params) to match reference structures.
34+
- Pin the versions used for differential testing to:
35+
- `MFKDF2.rs` commit `7c33c7164d6e40a26c0899f19b8f9ad9b9f0c029`
36+
- `MFKDF` commit `3d5bf73b4ce42b23da113b4be6d35e7d941fadf8`
3437

3538
## How to reproduce
3639

37-
Run the differential tests using the bindings workflow. From the repository root:
40+
You can run the differential tests **locally** or via the **GitHub Actions workflow**.
41+
42+
### Locally
43+
44+
From the repository root:
3845

3946
```bash
4047
# Ensure the WASM target is present (one-time)
4148
rustup target add wasm32-unknown-unknown
4249

43-
# Generate differential-release bindings (optimized)
50+
# Generate differential-release bindings (includes the `differential-test` feature)
4451
just gen-ts-bindings-differential
4552

46-
# Run the TypeScript test suite (includes differential tests)
53+
# Run only the differential TypeScript test suite
4754
just test-bindings-differential
4855
```
4956

mfkdf2-web/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mfkdf2-web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@
6161
"tsconfig-paths": "^4.2.0",
6262
"tsx": "^4.19.0",
6363
"typescript": "^5.6.2",
64-
"mfkdf": "github:multifactor/MFKDF#test/differential-testing"
64+
"mfkdf": "github:multifactor/MFKDF#3d5bf7"
6565
}
6666
}

mfkdf2-web/test/factors/hmacsha1.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ suite('factors/hmacsha1', () => {
7373
derive.key
7474
.toString('hex')
7575
.should.equal(
76-
'2747ebf65219aee6630a758e40fd05ccbb39ab465745ea1c9a6c5adb6673d2d3'
76+
'e1e67a0a2118867d8baf660d87500e650211855d2eff4c557ef2c8ae26ab5b6f'
7777
);
7878
});
7979

mfkdf2/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ required-features = ["bindings"]
1414
[dependencies]
1515
# Cryptography
1616
aes = { version = "0.8", default-features = false }
17+
cbc = { version = "0.1.2", default-features = false }
1718
cipher = { version = "0.4", default-features = false, features = [
1819
"block-padding",
20+
"rand_core",
21+
"std",
1922
] }
2023
ecb = { version = "0.1", default-features = false }
2124
hkdf = { version = "0.12", default-features = false }
@@ -84,6 +87,7 @@ data-encoding = { version = "2.9.0", default-features = false, features = [
8487
] }
8588
regex = { version = "1.11.3", default-features = false }
8689

90+
8791
[target.'cfg(target_arch = "wasm32")'.dependencies]
8892
console_log = { version = "1.0", default-features = false }
8993
getrandom = { version = "0.2", default-features = false, features = ["js"] }

0 commit comments

Comments
 (0)