зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1674498 - Remove references to `jarsigner` from `configure` and delete the `debug_sign_tool` r=geckoview-reviewers,nalexander,snorp
This is no longer used by Android devs. Differential Revision: https://phabricator.services.mozilla.com/D95417
This commit is contained in:
Родитель
d7a64d8211
Коммит
119ff36277
|
@ -10,7 +10,7 @@
|
|||
option(
|
||||
"--with-java-bin-path",
|
||||
nargs=1,
|
||||
help="Location of Java binaries (java, jarsigner, keytool)",
|
||||
help="Location of Java binaries",
|
||||
)
|
||||
|
||||
|
||||
|
@ -62,8 +62,6 @@ def check_java_tool(tool):
|
|||
|
||||
|
||||
check_java_tool("java")
|
||||
check_java_tool("jarsigner")
|
||||
check_java_tool("keytool")
|
||||
|
||||
|
||||
# Java Code Coverage
|
||||
|
|
|
@ -3,5 +3,4 @@
|
|||
|
||||
[include]
|
||||
path:gfx/wr/
|
||||
path:mobile/android/debug_sign_tool.py
|
||||
path:taskcluster/scripts/misc/
|
||||
|
|
|
@ -1,226 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
"""
|
||||
Sign Android packages using an Android debug keystore, creating the
|
||||
keystore if it does not exist.
|
||||
|
||||
This and |zip| can be combined to replace the Android |apkbuilder|
|
||||
tool, which was deprecated in SDK r22.
|
||||
|
||||
Exits with code 0 if creating the keystore and every signing succeeded,
|
||||
or with code 1 if any creation or signing failed.
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from argparse import ArgumentParser
|
||||
import errno
|
||||
import logging
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
log = logging.getLogger(os.path.basename(__file__))
|
||||
log.setLevel(logging.INFO)
|
||||
sh = logging.StreamHandler(stream=sys.stdout)
|
||||
sh.setFormatter(logging.Formatter("%(name)s: %(message)s"))
|
||||
log.addHandler(sh)
|
||||
|
||||
|
||||
class DebugKeystore:
|
||||
"""
|
||||
A thin abstraction on top of an Android debug key store.
|
||||
"""
|
||||
|
||||
def __init__(self, keystore):
|
||||
self._keystore = os.path.abspath(os.path.expanduser(keystore))
|
||||
self._alias = "androiddebugkey"
|
||||
self.verbose = False
|
||||
self.keytool = "keytool"
|
||||
self.jarsigner = "jarsigner"
|
||||
|
||||
@property
|
||||
def keystore(self):
|
||||
return self._keystore
|
||||
|
||||
@property
|
||||
def alias(self):
|
||||
return self._alias
|
||||
|
||||
def _check(self, args):
|
||||
try:
|
||||
if self.verbose:
|
||||
subprocess.check_call(args)
|
||||
else:
|
||||
subprocess.check_output(args)
|
||||
except OSError as ex:
|
||||
if ex.errno != errno.ENOENT:
|
||||
raise
|
||||
raise Exception("Could not find executable '%s'" % args[0])
|
||||
|
||||
def keystore_contains_alias(self):
|
||||
args = [
|
||||
self.keytool,
|
||||
"-list",
|
||||
"-keystore",
|
||||
self.keystore,
|
||||
"-storepass",
|
||||
"android",
|
||||
"-alias",
|
||||
self.alias,
|
||||
]
|
||||
if self.verbose:
|
||||
args.append("-v")
|
||||
contains = True
|
||||
try:
|
||||
self._check(args)
|
||||
except subprocess.CalledProcessError:
|
||||
contains = False
|
||||
if self.verbose:
|
||||
log.info(
|
||||
"Keystore %s %s alias %s"
|
||||
% (
|
||||
self.keystore,
|
||||
"contains" if contains else "does not contain",
|
||||
self.alias,
|
||||
)
|
||||
)
|
||||
return contains
|
||||
|
||||
def create_alias_in_keystore(self):
|
||||
try:
|
||||
path = os.path.dirname(self.keystore)
|
||||
os.makedirs(path)
|
||||
except OSError as exception:
|
||||
if exception.errno != errno.EEXIST:
|
||||
raise
|
||||
|
||||
args = [
|
||||
self.keytool,
|
||||
"-genkeypair",
|
||||
"-keystore",
|
||||
self.keystore,
|
||||
"-storepass",
|
||||
"android",
|
||||
"-alias",
|
||||
self.alias,
|
||||
"-keypass",
|
||||
"android",
|
||||
"-dname",
|
||||
"CN=Android Debug,O=Android,C=US",
|
||||
"-keyalg",
|
||||
"RSA",
|
||||
"-validity",
|
||||
"365",
|
||||
]
|
||||
if self.verbose:
|
||||
args.append("-v")
|
||||
self._check(args)
|
||||
if self.verbose:
|
||||
log.info("Created alias %s in keystore %s" % (self.alias, self.keystore))
|
||||
|
||||
def sign(self, apk):
|
||||
if not self.keystore_contains_alias():
|
||||
self.create_alias_in_keystore()
|
||||
|
||||
args = [
|
||||
self.jarsigner,
|
||||
"-digestalg",
|
||||
"SHA1",
|
||||
"-sigalg",
|
||||
"MD5withRSA",
|
||||
"-keystore",
|
||||
self.keystore,
|
||||
"-storepass",
|
||||
"android",
|
||||
apk,
|
||||
self.alias,
|
||||
]
|
||||
if self.verbose:
|
||||
args.append("-verbose")
|
||||
self._check(args)
|
||||
if self.verbose:
|
||||
log.info(
|
||||
"Signed %s with alias %s from keystore %s"
|
||||
% (apk, self.alias, self.keystore)
|
||||
)
|
||||
|
||||
|
||||
def parse_args(argv):
|
||||
parser = ArgumentParser(
|
||||
description="Sign Android packages using an Android debug keystore."
|
||||
)
|
||||
parser.add_argument(
|
||||
"apks", nargs="+", metavar="APK", help="Android packages to be signed"
|
||||
)
|
||||
parser.add_argument(
|
||||
"-v",
|
||||
"--verbose",
|
||||
dest="verbose",
|
||||
default=False,
|
||||
action="store_true",
|
||||
help="verbose output",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--keytool", metavar="PATH", default="keytool", help="path to Java keytool"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--jarsigner",
|
||||
metavar="PATH",
|
||||
default="jarsigner",
|
||||
help="path to Java jarsigner",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--keystore",
|
||||
metavar="PATH",
|
||||
default="~/.android/debug.keystore",
|
||||
help="path to keystore (default: ~/.android/debug.keystore)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-f",
|
||||
"--force-create-keystore",
|
||||
dest="force",
|
||||
default=False,
|
||||
action="store_true",
|
||||
help="force creating keystore",
|
||||
)
|
||||
return parser.parse_args(argv)
|
||||
|
||||
|
||||
def main():
|
||||
args = parse_args(sys.argv[1:])
|
||||
|
||||
keystore = DebugKeystore(args.keystore)
|
||||
keystore.verbose = args.verbose
|
||||
keystore.keytool = args.keytool
|
||||
keystore.jarsigner = args.jarsigner
|
||||
|
||||
if args.force:
|
||||
try:
|
||||
keystore.create_alias_in_keystore()
|
||||
except subprocess.CalledProcessError as e:
|
||||
log.error(
|
||||
"Failed to force-create alias %s in keystore %s"
|
||||
% (keystore.alias, keystore.keystore)
|
||||
)
|
||||
log.error(e)
|
||||
return 1
|
||||
|
||||
for apk in args.apks:
|
||||
try:
|
||||
keystore.sign(apk)
|
||||
except subprocess.CalledProcessError as e:
|
||||
log.error("Failed to sign %s", apk)
|
||||
log.error(e)
|
||||
return 1
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
|
@ -561,14 +561,8 @@ class TestChecksConfigure(unittest.TestCase):
|
|||
def test_java_tool_checks(self):
|
||||
# A valid set of tools in a standard location.
|
||||
java = mozpath.abspath("/usr/bin/java")
|
||||
jarsigner = mozpath.abspath("/usr/bin/jarsigner")
|
||||
keytool = mozpath.abspath("/usr/bin/keytool")
|
||||
|
||||
paths = {
|
||||
java: None,
|
||||
jarsigner: None,
|
||||
keytool: None,
|
||||
}
|
||||
paths = {java: None}
|
||||
|
||||
script = textwrap.dedent(
|
||||
"""\
|
||||
|
@ -586,8 +580,6 @@ class TestChecksConfigure(unittest.TestCase):
|
|||
config,
|
||||
{
|
||||
"JAVA": java,
|
||||
"JARSIGNER": jarsigner,
|
||||
"KEYTOOL": keytool,
|
||||
"MOZ_JAVA_CODE_COVERAGE": False,
|
||||
},
|
||||
)
|
||||
|
@ -596,26 +588,16 @@ class TestChecksConfigure(unittest.TestCase):
|
|||
textwrap.dedent(
|
||||
"""\
|
||||
checking for java... %s
|
||||
checking for jarsigner... %s
|
||||
checking for keytool... %s
|
||||
"""
|
||||
% (java, jarsigner, keytool)
|
||||
% java
|
||||
),
|
||||
)
|
||||
|
||||
# An alternative valid set of tools referred to by JAVA_HOME.
|
||||
alt_java = mozpath.abspath("/usr/local/bin/java")
|
||||
alt_jarsigner = mozpath.abspath("/usr/local/bin/jarsigner")
|
||||
alt_keytool = mozpath.abspath("/usr/local/bin/keytool")
|
||||
alt_java_home = mozpath.dirname(mozpath.dirname(alt_java))
|
||||
|
||||
paths.update(
|
||||
{
|
||||
alt_java: None,
|
||||
alt_jarsigner: None,
|
||||
alt_keytool: None,
|
||||
}
|
||||
)
|
||||
paths.update({alt_java: None})
|
||||
|
||||
config, out, status = self.get_result(
|
||||
command=script,
|
||||
|
@ -627,8 +609,6 @@ class TestChecksConfigure(unittest.TestCase):
|
|||
config,
|
||||
{
|
||||
"JAVA": alt_java,
|
||||
"JARSIGNER": alt_jarsigner,
|
||||
"KEYTOOL": alt_keytool,
|
||||
"MOZ_JAVA_CODE_COVERAGE": False,
|
||||
},
|
||||
)
|
||||
|
@ -637,10 +617,8 @@ class TestChecksConfigure(unittest.TestCase):
|
|||
textwrap.dedent(
|
||||
"""\
|
||||
checking for java... %s
|
||||
checking for jarsigner... %s
|
||||
checking for keytool... %s
|
||||
"""
|
||||
% (alt_java, alt_jarsigner, alt_keytool)
|
||||
% alt_java
|
||||
),
|
||||
)
|
||||
|
||||
|
@ -657,8 +635,6 @@ class TestChecksConfigure(unittest.TestCase):
|
|||
config,
|
||||
{
|
||||
"JAVA": alt_java,
|
||||
"JARSIGNER": alt_jarsigner,
|
||||
"KEYTOOL": alt_keytool,
|
||||
"MOZ_JAVA_CODE_COVERAGE": False,
|
||||
},
|
||||
)
|
||||
|
@ -667,10 +643,8 @@ class TestChecksConfigure(unittest.TestCase):
|
|||
textwrap.dedent(
|
||||
"""\
|
||||
checking for java... %s
|
||||
checking for jarsigner... %s
|
||||
checking for keytool... %s
|
||||
"""
|
||||
% (alt_java, alt_jarsigner, alt_keytool)
|
||||
% alt_java
|
||||
),
|
||||
)
|
||||
|
||||
|
@ -690,8 +664,6 @@ class TestChecksConfigure(unittest.TestCase):
|
|||
config,
|
||||
{
|
||||
"JAVA": alt_java,
|
||||
"JARSIGNER": alt_jarsigner,
|
||||
"KEYTOOL": alt_keytool,
|
||||
"MOZ_JAVA_CODE_COVERAGE": False,
|
||||
},
|
||||
)
|
||||
|
@ -700,10 +672,8 @@ class TestChecksConfigure(unittest.TestCase):
|
|||
textwrap.dedent(
|
||||
"""\
|
||||
checking for java... %s
|
||||
checking for jarsigner... %s
|
||||
checking for keytool... %s
|
||||
"""
|
||||
% (alt_java, alt_jarsigner, alt_keytool)
|
||||
% alt_java
|
||||
),
|
||||
)
|
||||
|
||||
|
@ -722,34 +692,25 @@ class TestChecksConfigure(unittest.TestCase):
|
|||
config,
|
||||
{
|
||||
"JAVA": java,
|
||||
"JARSIGNER": jarsigner,
|
||||
"KEYTOOL": keytool,
|
||||
"MOZ_JAVA_CODE_COVERAGE": True,
|
||||
},
|
||||
)
|
||||
|
||||
# Any missing tool is fatal when these checks run.
|
||||
del paths[jarsigner]
|
||||
del paths[java]
|
||||
config, out, status = self.get_result(
|
||||
command=script, extra_paths=paths, environ={"PATH": mozpath.dirname(java)}
|
||||
)
|
||||
self.assertEqual(status, 1)
|
||||
self.assertEqual(
|
||||
config,
|
||||
{
|
||||
"JAVA": java,
|
||||
},
|
||||
)
|
||||
self.assertEqual(config, {})
|
||||
self.assertEqual(
|
||||
out,
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
checking for java... %s
|
||||
checking for jarsigner... not found
|
||||
ERROR: The program jarsigner was not found. Set $JAVA_HOME to your \
|
||||
checking for java... not found
|
||||
ERROR: The program java was not found. Set $JAVA_HOME to your \
|
||||
Java SDK directory or use '--with-java-bin-path={java-bin-dir}'
|
||||
"""
|
||||
% (java)
|
||||
),
|
||||
)
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ warning; etc.) or platform or language or whatever.
|
|||
|
||||
import re
|
||||
|
||||
from mozharness.base.log import CRITICAL, DEBUG, ERROR, FATAL, WARNING
|
||||
from mozharness.base.log import CRITICAL, DEBUG, ERROR, WARNING
|
||||
|
||||
|
||||
# Exceptions
|
||||
|
@ -126,34 +126,6 @@ TarErrorList = BaseErrorList + [
|
|||
{"substr": r""": Error is not recoverable: exiting now""", "level": ERROR},
|
||||
]
|
||||
|
||||
JarsignerErrorList = [
|
||||
{"substr": r"""command not found""", "level": FATAL},
|
||||
{
|
||||
"substr": r"""jarsigner error: java.lang.RuntimeException: keystore load: """
|
||||
r"""Keystore was tampered with, or password was incorrect""",
|
||||
"level": FATAL,
|
||||
"explanation": r"""The store passphrase is probably incorrect!""",
|
||||
},
|
||||
{
|
||||
"regex": re.compile(r"""jarsigner: key associated with .* not a private key"""),
|
||||
"level": FATAL,
|
||||
"explanation": r"""The key passphrase is probably incorrect!""",
|
||||
},
|
||||
{
|
||||
"regex": re.compile(
|
||||
r"""jarsigner error: java.lang.RuntimeException: """
|
||||
r"""keystore load: .* .No such file or directory"""
|
||||
),
|
||||
"level": FATAL,
|
||||
"explanation": r"""The keystore doesn't exist!""",
|
||||
},
|
||||
{
|
||||
"substr": r"""jarsigner: unable to open jar file:""",
|
||||
"level": FATAL,
|
||||
"explanation": r"""The apk is missing!""",
|
||||
},
|
||||
]
|
||||
|
||||
ZipErrorList = BaseErrorList + [
|
||||
{
|
||||
"substr": r"""zip warning:""",
|
||||
|
|
Загрузка…
Ссылка в новой задаче