Introduction
A JKS file is a keystore for Java: a file holding private keys with their certificate chains, and trusted certificates, each under a name called an alias. Java servers such as Tomcat have long read their TLS keys from JKS files, and Android apps used to be signed with keys kept in one.
JKS was Java’s default keystore type until Java 9, when the default became
PKCS #12. The JDK’s keytool converts between
the two.
A file named .jks is not always a JKS keystore. The JDK’s JKS
keystore type loads any file that does not start with FE ED FE ED as
PKCS #12, so a .jks made by a current
keytool is usually PKCS #12 (a DER sequence, 30 82 …). The
explorer recognises three kinds under this extension: JKS, JCEKS
(CE CE CE CE) and PKCS #12; the
structure page says how Java decides.
Structure
All values are big-endian. The file starts with the magic number
FE ED FE ED, a version number and the number of entries. Each
entry starts
with a tag, 1 for a private key and 2 for a trusted certificate, then the alias and the
time the entry was made. A private key entry holds the key, encrypted with a password
using a weak Sun-specific scheme, and its certificate chain. A certificate entry holds
one certificate, with its type name, such as X.509, and its
DER bytes.
The file ends with a 20-byte SHA-1 hash computed from the keystore password and all
the bytes before it, which detects changes and wrong passwords. The related JCEKS format
starts with CE CE CE CE and uses stronger key encryption.
0Header magicFE ED FE ED, version, entry count12 bytes12Entries tag, alias, date, then a key and chain or a certificaterepeatedendIntegrity hash SHA-1 over the password and the file20 bytes
In the explorer
Drop a .jks file on this site. The structure tree shows the header (the magic, FE ED FE ED for
JKS or CE CE CE CE for JCEKS, the version and the entry count) and every entry: its tag, the alias (Java’s
modified UTF-8), the creation date, and for a private key entry the protected key with the Sun key protector laid out
(algorithm identifier, salt, encrypted key, check) and the certificate chain, for a trusted certificate entry its type and
certificate. Each X.509 certificate is walked as DER far enough to name the subject, issuer, serial number, validity and
signature algorithm. The Entries and Certificates tables list them, and the closing 20-byte integrity hash is shown.
The key protection and the hash need the keystore password, which is the user’s own data, so they are shown as stored and
not checked.
Not described
Written against the pages on this site (Entries and protection), tested with keystores built from them.
Known, not yet covered
- Viewer: the integrity hash and a private key’s check value are not verified, and the key is not decrypted: both need the
password. A JCEKS secret key entry (tag 3) holds a Java-serialised
SealedObject, which states no length, so it is shown as one block to the integrity hash and later entries are not separated. Certificate types other than X.509 are shown as bytes.
Also used for
- PKCS #12 key and certificate bundle – A PKCS #12 file saved with the .jks name: Java opens it as a keystore.
Links
Software
- keytool – the command-line key tool that comes with Java (Windows, macOS, Linux)
- KeyStore Explorer – free key and certificate manager that opens JKS files (Windows, macOS, Linux)
Developers
- java.security.KeyStore – the standard class that loads and saves keystores (Java)