This is a simple set of scripts to generate a keybox file for android key attestation. Keyboxes generated using these scripts CANNOT PASS STRONG INTEGRITY (Unless you have the correct private key to sign the root certificate or any certificate down the chain).
- Python 3
- OpenSSL
- Generate the certificate chains
python generate_cert_chains.py- Generate the keybox
python generate_keybox.py -a -tThis will generate a keybox.xml file in the working directory.
For more options, run the scripts with the -h flag.
To verify the generated keybox, you can use this checker.
There is a wizard for a more user-friendly experience, run it with:
python wizard.pyThe scripts folder contains scripts used to develop the keybox generator.
This is all experimental.
generate_cert_chains.py Generates 2 certificate chains (one in RSA and one in ECDSA) made of 4 certificates starting from a RSA root certificate (either generated or given).
The variable SUBJECTS contains a list of either generated or user specified subjects for the certificates.
You can use this list with the option -s, if you leave the list empty, the script will generate random subjects. These will be coherent with the rest of the chain.
By default the script will generate subjects using the default openssl configuration and the same subject for all certificates.
You can edit this field too, by changing the DETAILS variable.
The certs folder contains the all generated certificates.
The certificate chains and the end-entity private keys are copied into the working directory for the next script.
Check this page for more information about certificate chains.
Root CA (self-signed) (By google hopefully) (RSA) (ECDSA optional)
|_ OEM CA (RSA and ECDSA, Signed by Root CA)
|_ Model CA (RSA and ECDSA, Signed by OEM CA)
|_ End-entity (Optional) (RSA and ECDSA, Signed by Model CA) (The certificate subject here can literally be anything)
If you want to generate the root certificate using a specific private key, you can put it into the certs folder and name it rootCA.key.
You can also put a corresponding root certificate named rootCA.pem in the same folder.
The same goes for the other certificates down the chain.
rootCA.keyandrootCA.pemfor the root certificaterootCA_ecdsa.keyandrootCA_ecdsa.pemfor the ECDSA root certificate (optional)
[type]_oem_CA.keyand[type]_oem_CA.pemfor the OEM certificate[type]_model_CA.keyand[type]_model_CA.pemfor the model certificate[type]_end.keyand[type]_end.pemfor the end-entity certificate
Where [type] is either RSA or ECDSA.
generate_keybox.py Generates a keybox file using the certificate chains generated by the previous script.
By default, this script will generate an empty keybox, if no files are specified.
There is an auto mode (-a) that automatically detects necessary files in the working directory.
You can generate a pretty printed keybox with the -t option.
Check TrickyStore for more information about keyboxes.
Check this page of the android documentation for more information about key attestation.