summaryrefslogtreecommitdiff
path: root/apexer/apexer.py
diff options
context:
space:
mode:
authorJiyong Park <jiyong@google.com>2018-12-17 11:19:58 +0900
committerJiyong Park <jiyong@google.com>2018-12-17 11:22:55 +0900
commit0a7e57c0e9c6122ac582e94dd465571c632add3b (patch)
tree0f4da3a4a52892c80b8f072b2684eed75e84c15d /apexer/apexer.py
parentb3883720fb9ccb002b5ad65b98179aba0c89b62f (diff)
Output of apexer is deterministic
Output of apexer is now deterministic. Unless the input files are changed, the output is not changed across different runs. Bug: 120811390 Test: Build two com.android.tzdata APEXes without changing the source The two APEXes are identical. Change-Id: I56657493bb54a859f18deb276edb68d6c9ee8f9e
Diffstat (limited to 'apexer/apexer.py')
-rw-r--r--apexer/apexer.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/apexer/apexer.py b/apexer/apexer.py
index ac33b2d..0926638 100644
--- a/apexer/apexer.py
+++ b/apexer/apexer.py
@@ -23,6 +23,7 @@ Typical usage: apexer input_dir output.apex
"""
import argparse
+import hashlib
import json
import os
import re
@@ -30,6 +31,7 @@ import shutil
import subprocess
import sys
import tempfile
+import uuid
if 'APEXER_TOOL_PATH' not in os.environ:
sys.stderr.write("""
@@ -216,8 +218,11 @@ def CreateApex(args, work_dir):
cmd.extend(['-m', '0']) # reserved block percentage
cmd.extend(['-t', 'ext4'])
cmd.append(img_file)
+ uu = str(uuid.uuid5(uuid.NAMESPACE_URL, "www.android.com"))
+ cmd.extend(['-U', uu])
+ cmd.extend(['-E', 'hash_seed=' + uu])
cmd.append(str(size_in_mb) + 'M')
- RunCommand(cmd, args.verbose)
+ RunCommand(cmd, args.verbose, {"E2FSPROGS_FAKE_TIME": "1"})
# Compile the file context into the binary form
compiled_file_contexts = os.path.join(work_dir, 'file_contexts.bin')
@@ -243,13 +248,14 @@ def CreateApex(args, work_dir):
cmd.extend(['-S', compiled_file_contexts])
cmd.extend(['-C', args.canned_fs_config])
cmd.append(img_file)
- RunCommand(cmd, args.verbose)
+ RunCommand(cmd, args.verbose, {"E2FSPROGS_FAKE_TIME": "1"})
# Resize the image file to save space
cmd = ['resize2fs']
cmd.append('-M') # shrink as small as possible
cmd.append(img_file)
- RunCommand(cmd, args.verbose)
+ RunCommand(cmd, args.verbose, {"E2FSPROGS_FAKE_TIME": "1"})
+
cmd = ['avbtool']
cmd.append('add_hashtree_footer')
@@ -257,6 +263,10 @@ def CreateApex(args, work_dir):
cmd.extend(['--algorithm', 'SHA256_RSA4096'])
cmd.extend(['--key', args.key])
cmd.extend(['--prop', "apex.key:" + key_name])
+ # Set up the salt based on manifest content which includes name
+ # and version
+ salt = hashlib.sha256(json.dumps(manifest)).hexdigest()
+ cmd.extend(['--salt', salt])
cmd.extend(['--image', img_file])
RunCommand(cmd, args.verbose)