{"vuln_id":"GHSA-j282-pjg5-j643","aliases":["CVE-2026-76101"],"description":"keystore-go: Keystore integrity and password verification bypass via stripped trailing digest in Decode()","published_at":"2026-11-19T20:35:35Z","modified_at":"2026-11-19T20:45:04.178017Z","first_seen_at":"2026-11-21T19:15:19.494487Z","severity":"high","severity_source":"ghsa","cvss_score":7.1,"cvss_vector":"CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:N","cwe":["CWE-252","CWE-347","CWE-354"],"vendor":null,"product":null,"kev":{"is_kev":false,"date_added":null,"due_date":null,"ransomware":false},"epss":null,"epss_percentile":null,"nvd_status":null,"enriched_at":null,"links":{"nvd":"https://github.com/advisories/GHSA-j282-pjg5-j643"},"matched_alias":null,"items":[{"id":10977,"source":{"id":"osv","name":"OSV.dev"},"title":"GHSA-j282-pjg5-j643: keystore-go: Keystore integrity and password verification bypass via stripped trailing digest in Decode()","summary":"keystore-go: Keystore integrity and password verification bypass via stripped trailing digest in Decode()\n\n### 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\n\nAffected: Go:github.com/pavel-v-chernykh/keystore-go, Go:github.com/pavel-v-chernykh/keystore-go/v3\n\nFixed in: 3.0.0\n\nReferences:\nhttps://github.com/pavlo-v-chernykh/keystore-go/security/advisories/GHSA-j282-pjg5-j643\nhttps://nvd.nist.gov/vuln/detail/CVE-2026-76101\nhttps://github.com/pavlo-v-chernykh/keystore-go/commit/af93effd832cf1aef7794e69c31e1b668e17b851\nhttps://github.com/pavlo-v-chernykh/keystore-go\nhttps://github.com/pavlo-v-chernykh/keystore-go/releases/tag/v3.0.0","url":"https://osv.dev/vulnerability/GHSA-j282-pjg5-j643","published_at":"2026-11-19T20:35:35Z","updated_at":"2026-11-19T20:45:04.178017Z","fetched_at":"2026-11-21T19:15:55.946343Z","severity":"high","cvss_score":7.1,"epss":0.00087,"is_kev":false,"has_exploit":false,"kev_due_date":null,"vendor":null,"product":"github.com/pavel-v-chernykh/keystore-go","vuln_id":"CVE-2026-76101","vuln_ids":["CVE-2026-76101","GHSA-J282-PJG5-J643"],"tags":["osv","go","fix-available"],"cluster_id":2240,"links":{"self":"https://vulnwatch.ve1ve2.com/api/v1/items/10977","html":"https://vulnwatch.ve1ve2.com/item/10977"}},{"id":2404,"source":{"id":"ghsa","name":"GitHub Security Advisories"},"title":"GHSA-j282-pjg5-j643 / CVE-2026-76101: keystore-go: Keystore integrity and password verification bypass via stripped trailing digest in Decode()","summary":"keystore-go: Keystore integrity and password verification bypass via stripped trailing digest in Decode()\n\n### 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\n\nAffected packages: go:github.com/pavel-v-chernykh/keystore-go, go:github.com/pavel-v-chernykh/keystore-go/v3\nPatched: github.com/pavel-v-chernykh/keystore-go/v3 3.0.0","url":"https://github.com/advisories/GHSA-j282-pjg5-j643","published_at":"2026-11-19T20:35:35Z","updated_at":"2026-11-19T20:35:35Z","fetched_at":"2026-11-21T19:15:18.416810Z","severity":"high","cvss_score":7.1,"epss":0.00087,"is_kev":false,"has_exploit":false,"kev_due_date":null,"vendor":null,"product":"github.com/pavel-v-chernykh/keystore-go","vuln_id":"CVE-2026-76101","vuln_ids":["CVE-2026-76101","GHSA-J282-PJG5-J643"],"tags":["ghsa","go","CWE-252","CWE-347","CWE-354"],"cluster_id":2240,"links":{"self":"https://vulnwatch.ve1ve2.com/api/v1/items/2404","html":"https://vulnwatch.ve1ve2.com/item/2404"}},{"id":8254,"source":{"id":"nvd","name":"NVD CVE API 2.0"},"title":"CVE-2026-76101: 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 retur…","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.\n\nReferences:\nhttps://github.com/pavlo-v-chernykh/keystore-go/commit/af93effd832cf1aef7794e69c31e1b668e17b851\nhttps://github.com/pavlo-v-chernykh/keystore-go/releases/tag/v3.0.0\nhttps://github.com/pavlo-v-chernykh/keystore-go/security/advisories/GHSA-j282-pjg5-j643\nhttps://github.com/pavlo-v-chernykh/keystore-go/security/advisories/GHSA-j282-pjg5-j643","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-76101","published_at":"2026-11-18T22:17:24.567000Z","updated_at":"2026-11-19T20:17:52.247000Z","fetched_at":"2026-11-21T19:15:31.484038Z","severity":"high","cvss_score":7.1,"epss":0.00087,"is_kev":false,"has_exploit":false,"kev_due_date":null,"vendor":null,"product":null,"vuln_id":"CVE-2026-76101","vuln_ids":["CVE-2026-76101","GHSA-J282-PJG5-J643"],"tags":["CWE-252","CWE-347","CWE-354"],"cluster_id":2241,"links":{"self":"https://vulnwatch.ve1ve2.com/api/v1/items/8254","html":"https://vulnwatch.ve1ve2.com/item/8254"}}]}