# keystore-go: Keystore integrity and password verification bypass via stripped trailing digest in Decode()

keystore-go Decode() ignores the error reading the trailing SHA-1 digest, so stripping the last 20 bytes of a JKS file bypasses integrity and password checks, letting attackers inject trusted CA certs.

- Payout: Research
- Severity: high
- Program: keystore-go
- Found by: KrisKennawayDD
- Disclosed: 2026-11-19
- CVE: CVE-2026-76101
- Write-up quality: 7/10
- Original: https://github.com/advisories/GHSA-j282-pjg5-j643
- Library page: https://bugbountylibrary.com/r/ghsa%3AGHSA-j282-pjg5-j643
- Tags: area:oss domain:oss impact:integrity kind:research platform:ghsa sev:high tech:go technique:source-review vuln:auth-bypass vuln:crypto vuln:misconfiguration

**Target:** JKS keystore/truststore decoder (Go library Decode())
**Root cause:** Decode() assigns but never checks the error from readBytes(20) for the trailing SHA-1 digest, and the comparison loop is bounded by len(actualDigest) instead of len(computedDigest). A short read yields a nil digest, so the loop never runs and Decode returns nil error.
**Steps:**
1. Encode a JKS truststore with a TrustedCertificateEntry using `keystore.Encode(&buf, ks, []byte("correct-password"))`.
2. Replace the original certificate bytes with an attacker CA cert of equal length via `bytes.Replace`.
3. Strip the trailing 20-byte digest: `tampered = tampered[:len(tampered)-20]`.
4. Call `keystore.Decode(bytes.NewReader(tampered), []byte("correct-password"))` — returns nil error with forged cert loaded.
5. Repeat with `[]byte("attacker-does-not-know")` — also returns nil error, password check bypassed.
**How found:** Code review of decoder.go Decode(): noticed the err from readBytes(20) is assigned but never inspected, and the comparison loop iterates over len(actualDigest) rather than len(computedDigest), so a nil digest skips verification entirely.
**Exploitation:** Attacker with write access to a .jks truststore file (local user, compromised deployment artefact, writable config volume) replaces trusted CA certificates, truncates the final 20-byte SHA-1 digest, and the consuming Go process loads the forged truststore as valid without knowing the password. Downstream enables MITM of TLS connections trusting the forged CA.
**Escalation:** Forged trusted CA enables man-in-the-middle interception of TLS connections, compromising confidentiality and integrity.
**Insight:** When auditing integrity-check code, check both that the read error is handled AND that the comparison loop is bounded by the expected digest length, not the received one — a truncated input makes a length-bounded loop a no-op. Also note JKS truststores verify the password only via this digest, so digest bypass equals password bypass.

## Proof of concept (copied exactly from the original report)

**Vulnerable Decode digest check code**

```
computedDigest := ksd.md.Sum(nil)
actualDigest, err := ksd.readBytes(uint32(ksd.md.Size()))
for i := 0; i < len(actualDigest); i++ {
    if actualDigest[i] != computedDigest[i] {
        return nil, ErrInvalidDigest
    }
}

return keyStore, nil
```

