|
| 1 | +#!/usr/bin/env python |
| 2 | +# |
| 3 | +# Copyright (C) 2017 The LineageOS Project |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +""" |
| 18 | +Signs the given zip with the given key producing a new zip. |
| 19 | +
|
| 20 | +Usage: sign_release_zip [flags] input_zip output_zip |
| 21 | +
|
| 22 | + -k (--package_key) <key> Key to use to sign the package (default is |
| 23 | + "build/target/product/security/testkey"). |
| 24 | +""" |
| 25 | +import sys |
| 26 | + |
| 27 | +import common |
| 28 | + |
| 29 | +OPTIONS = common.OPTIONS |
| 30 | + |
| 31 | +OPTIONS.package_key = "build/target/product/security/testkey" |
| 32 | + |
| 33 | +def SignOutput(input_zip_name, output_zip_name): |
| 34 | + key_passwords = common.GetKeyPasswords([OPTIONS.package_key]) |
| 35 | + pw = key_passwords[OPTIONS.package_key] |
| 36 | + |
| 37 | + common.SignFile(input_zip_name, output_zip_name, OPTIONS.package_key, pw, |
| 38 | + whole_file=True) |
| 39 | + |
| 40 | + |
| 41 | +def main(argv): |
| 42 | + |
| 43 | + def option_handler(o, a): |
| 44 | + if o in ("-k", "--package_key"): |
| 45 | + OPTIONS.package_key = a |
| 46 | + else: |
| 47 | + return False |
| 48 | + return True |
| 49 | + |
| 50 | + args = common.ParseOptions(argv, __doc__, |
| 51 | + extra_opts="k:", |
| 52 | + extra_long_opts=[ |
| 53 | + "package_key=", |
| 54 | + ], extra_option_handler=option_handler) |
| 55 | + if len(args) != 2: |
| 56 | + common.Usage(__doc__) |
| 57 | + sys.exit(1) |
| 58 | + |
| 59 | + SignOutput(args[0], args[1]) |
| 60 | + |
| 61 | + |
| 62 | +if __name__ == '__main__': |
| 63 | + try: |
| 64 | + main(sys.argv[1:]) |
| 65 | + except common.ExternalError as e: |
| 66 | + print() |
| 67 | + print(" ERROR: %s" % e) |
| 68 | + print() |
| 69 | + sys.exit(1) |
0 commit comments