Beispiel #1
0
        /// <summary>
        /// Synchronously calls the jarsigner tool to sign the specified ZIP file using a custom keystore.
        /// This can be used to sign Android App Bundles.
        /// </summary>
        /// <returns>An error message if there was a problem running jarsigner, or null if successful.</returns>
        public string Sign(string zipFilePath)
        {
            if (!_useCustomKeystore)
            {
                throw new InvalidOperationException("Unexpected request to sign without a custom keystore");
            }

            if (string.IsNullOrEmpty(_keystoreName))
            {
                return("Unable to sign since the keystore file path is unspecified");
            }

            if (!File.Exists(_keystoreName))
            {
                return(string.Format("Failed to locate keystore file: {0}", _keystoreName));
            }

            var arguments = string.Format(
                "-keystore {0} {1} {2}",
                CommandLine.QuotePath(_keystoreName),
                CommandLine.QuotePath(zipFilePath),
                CommandLine.QuotePath(_keyaliasName));

            var promptToPasswordDictionary = new Dictionary <string, string>
            {
                { "Enter Passphrase for keystore:", _keystorePass },
                // Example keyalias password prompt: "Enter key password for myalias:"
                { "Enter key password for .+:", _keyaliasPass }
            };
            var responder = new JarSignerResponder(promptToPasswordDictionary);
            var result    = CommandLine.Run(_javaUtils.JarSignerBinaryPath, arguments, ioHandler: responder.AggregateLine);

            return(result.exitCode == 0 ? null : result.message);
        }
        /// <summary>
        /// Synchronously calls the jarsigner tool to sign the specified ZIP file.
        /// This can be used to sign Android App Bundles.
        /// </summary>
        /// <returns>An error message if there was a problem running jarsigner, or null if successful.</returns>
        public virtual string SignZip(string zipFilePath)
        {
            string keystoreName;
            string keystorePass;
            string keyaliasName;
            string keyaliasPass;

            if (UseDebugKeystore())
            {
                Debug.Log("No keystore and/or no keyalias specified. Signing using Android debug keystore.");
                var homePath =
                    Application.platform == RuntimePlatform.WindowsEditor
                        ? Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%")
                        : Environment.GetEnvironmentVariable("HOME");
                if (string.IsNullOrEmpty(homePath))
                {
                    return("Failed to locate directory that contains Android debug keystore.");
                }

                keystoreName = Path.Combine(homePath, AndroidDebugKeystore);
                keystorePass = "******";
                keyaliasName = "androiddebugkey";
                keyaliasPass = "******";
            }
            else
            {
                keystoreName = _keystoreName;
                keystorePass = _keystorePass;
                keyaliasName = _keyaliasName;
                keyaliasPass = _keyaliasPass;
            }

            if (!File.Exists(keystoreName))
            {
                return(string.Format("Failed to locate keystore file: {0}", keystoreName));
            }

            var arguments = string.Format(
                "-keystore {0} {1} {2}",
                CommandLine.QuotePath(keystoreName),
                CommandLine.QuotePath(zipFilePath),
                CommandLine.QuotePath(keyaliasName));

            var promptToPasswordDictionary = new Dictionary <string, string>
            {
                { "Enter Passphrase for keystore:", keystorePass },
                // Example keyalias password prompt: "Enter key password for myalias:"
                { "Enter key password for .+:", keyaliasPass }
            };
            var responder = new JarSignerResponder(promptToPasswordDictionary);
            var result    = CommandLine.Run(_javaUtils.JarSignerBinaryPath, arguments, ioHandler: responder.AggregateLine);

            return(result.exitCode == 0 ? null : result.message);
        }