Commit bcf118b
authored
core: reject a JWK entry missing x5c when loading a SPIFFE trust bundle (#12911)
`SpiffeUtil.extractCert` silently truncates a SPIFFE trust bundle when a
JWK `keys[]` entry is
missing `x5c`:
```java
for (Map<String, ?> keyNode : keysNode) {
checkJwkEntry(keyNode, trustDomainName);
List<String> rawCerts = JsonUtil.getListOfStrings(keyNode, "x5c");
if (rawCerts == null) {
break; // abandons the loop, dropping every remaining cert
}
if (rawCerts.size() != 1) {
throw new IllegalArgumentException(...); // sibling paths throw
}
...
}
```
`checkJwkEntry` has already guaranteed the entry is a declared
`x509-svid` key (`use == "x509-svid"`,
`kty` in `{RSA, EC}`), so an entry with no `x5c` is malformed. But
instead of failing, the `break`
abandons the loop and returns only the certificates collected **before**
the bad entry — so a
trust domain whose `keys` array has a missing-`x5c` entry ahead of valid
ones loads a **silently
truncated** trust store, and peers whose chain roots in a dropped CA
fail verification (or a
partially loaded store is accepted with no error).
This also contradicts the method's own contract
(`loadTrustBundleFromFile` javadoc: *"If any
element of the JSON content is invalid or unsupported, an
`IllegalArgumentException` is thrown and
the entire Bundle is considered invalid"*). Every other malformed
condition in `extractCert`
(`use`, `kty`, `kid`, `x5c.size() != 1`, unparseable cert) throws.
**Fix:** throw `IllegalArgumentException` for a missing `x5c`,
consistent with the sibling error
paths and the documented contract, instead of silently dropping
certificates.
**Tests:** added `spiffebundle_missing_x5c.json` and an assertion in
`SpiffeUtilTest.loadTrustBundleFromFileFailureTest`. It fails against
the current code (the old
`break` returns a truncated bundle without throwing) and passes with the
fix. `:grpc-core`
checkstyle/animalsniffer clean.1 parent 0585d48 commit bcf118b
3 files changed
Lines changed: 46 additions & 1 deletion
File tree
- core/src
- main/java/io/grpc/internal
- test
- java/io/grpc/internal
- resources/io/grpc/internal
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
232 | 232 | | |
233 | 233 | | |
234 | 234 | | |
235 | | - | |
| 235 | + | |
| 236 | + | |
236 | 237 | | |
237 | 238 | | |
238 | 239 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
| 233 | + | |
233 | 234 | | |
234 | 235 | | |
235 | 236 | | |
| |||
351 | 352 | | |
352 | 353 | | |
353 | 354 | | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
354 | 359 | | |
355 | 360 | | |
356 | 361 | | |
| |||
Lines changed: 39 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
0 commit comments