Commit 4f8864a
authored
jwe: parse and bound-check PBES2 p2c in int64 space; name the violated bound in the error (#2118)
decryptKeyPBES2 read p2c into float64, compared against the cap in
float64 space, then cast via int(countFlt) before passing to PBKDF2.
At the default MaxPBES2Count=1_000_000 every value is exact and the
arithmetic is sound. The risk lives at the cap-raising end: a caller
who sets WithMaxPBES2Count past 2^53 to support legitimately heavy
PBES2 traffic enables float-precision drift to influence which value
the cap accepts vs rejects, and the int() cast then converts the
rounded float, not the wire integer. int64 throughout removes the
precision class entirely.
The two error sites that reject p2c (NaN/Inf/non-integer; out-of-range)
both emitted the identical opaque "invalid 'p2c' value" string. The
caller couldn't tell which check rejected, the offending value, or
which option to call to widen/tighten. Reword each error site to
include the value, the bound that was violated, and the option name.
Bundled doc improvements:
- Decrypt godoc now mentions WithMaxPBES2Count / WithMinPBES2Count
alongside the existing WithMaxDecompressBufferSize paragraph; the
PBES2 amplification surface is now visible from go doc jwe.Decrypt.
- WithMinPBES2Count godoc adds the threat model (under-iteration
attack on the recipient by a careless or malicious issuer) and
notes the OWASP 2023 vs RFC 7518 §4.8.1.2 floor asymmetry.
Float-domain bounds use float64(1 << 63) instead of math.MaxInt64 to
keep the comparison platform-independent: 1<<63 is a 65-bit untyped
constant that converts cleanly to float64 (= 2^63, exact) without
going through the implementation's int width. The eventual int(count)
cast is safe because count is bound-checked against int64(maxCount)
where maxCount is platform-int-typed; on 32-bit, count is therefore
always within int range when the cast runs.1 parent 608daea commit 4f8864a
5 files changed
Lines changed: 126 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
87 | 94 | | |
88 | 95 | | |
89 | | - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
90 | 113 | | |
91 | | - | |
92 | | - | |
| 114 | + | |
93 | 115 | | |
94 | | - | |
| 116 | + | |
95 | 117 | | |
| 118 | + | |
96 | 119 | | |
97 | 120 | | |
98 | 121 | | |
99 | 122 | | |
100 | | - | |
101 | | - | |
| 123 | + | |
| 124 | + | |
102 | 125 | | |
103 | | - | |
104 | | - | |
105 | | - | |
| 126 | + | |
| 127 | + | |
106 | 128 | | |
107 | 129 | | |
108 | 130 | | |
| |||
113 | 135 | | |
114 | 136 | | |
115 | 137 | | |
116 | | - | |
| 138 | + | |
117 | 139 | | |
118 | 140 | | |
119 | 141 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1097 | 1097 | | |
1098 | 1098 | | |
1099 | 1099 | | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
1100 | 1111 | | |
1101 | 1112 | | |
1102 | 1113 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1306 | 1306 | | |
1307 | 1307 | | |
1308 | 1308 | | |
| 1309 | + | |
| 1310 | + | |
1309 | 1311 | | |
1310 | 1312 | | |
1311 | 1313 | | |
| |||
1315 | 1317 | | |
1316 | 1318 | | |
1317 | 1319 | | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
1318 | 1370 | | |
1319 | 1371 | | |
1320 | 1372 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
190 | 190 | | |
191 | 191 | | |
192 | 192 | | |
193 | | - | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
194 | 208 | | |
195 | 209 | | |
196 | 210 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments