Esempio n. 1
0
            public static bool UpdateVersionWindows(string path, Version version)
            {
                var args = string.Format(
                    "- '{0}' {1} {2} {3} {4}",
                    path, version.major, version.minor, version.patch, version.build
                    );
                string output, error;
                var    exitcode = OptionHelper.RunScript("python", args, PythonUpdateWindows, out output, out error);

                if (exitcode != 0)
                {
                    Debug.LogError("OptionVersion: Failed to run python to update version: " + output);
                    return(false);
                }
                return(true);
            }
Esempio n. 2
0
            override public void SetPassword(string service, string name, string password)
            {
                // We use the interactive mode of security here that allows us to
                // pipe the command to stdin and thus avoid having the password
                // exposed in the process table.
                var command = string.Format(
                    "add-generic-password -U -a '{0}' -s '{1}' -w '{2}'\n",
                    name, service, password
                    );
                string output, error;
                var    code = OptionHelper.RunScript("security", "-i", command, out output, out error);

                if (code != 0)
                {
                    Debug.LogError("Failed to store password in Keychain: " + error);
                }
            }
Esempio n. 3
0
            override public string GetPassword(string service, string name)
            {
                var command = string.Format(
                    "find-generic-password -a '{0}' -s '{1}' -w",
                    name, service
                    );
                string output, error;
                var    code = OptionHelper.RunScript("security", command, out output, out error);

                if (code != 0)
                {
                    return(null);
                }
                else
                {
                    return(output.TrimEnd('\n'));
                }
            }
Esempio n. 4
0
        /// <summary>
        /// Get aliases defined in a keystore using `keytool`.
        /// </summary>
        Error GetKeyAliases(string path, string password, List <string> aliases)
        {
            var result = FindKeytool();

            if (result != Error.None)
            {
                return(result);
            }

            var arguments = string.Format(
                "-list -v -keystore '{0}'",
                path
                );
            string output, error;
            var    code = OptionHelper.RunScript(keytoolPath, arguments, password, out output, out error);

            if (code != 0)
            {
                if (output.Contains("password was incorrect"))
                {
                    return(Error.InvalidKeystorePassword);
                }
                else
                {
                    return(Error.KeytoolFailed);
                }
            }

            aliases.Clear();
            var lines = output.Split(Newlines, StringSplitOptions.None);

            foreach (var line in lines)
            {
                if (line.StartsWith("Alias name: "))
                {
                    aliases.Add(line.Substring(12));
                }
            }

            return(Error.None);
        }
Esempio n. 5
0
        /// <summary>
        /// Check the alias password.
        /// </summary>
        /// <remarks>
        /// There isn't really a nice way to check the key password from the command line,
        /// so we have to abuse `keytool` a bit.
        ///
        /// The main issue is that the tools will try the store password on the key and
        /// therefore if the two match, the key password will never be checked. Unity, on
        /// the other hand, will not try the store password on the key and requires the
        /// proper key password to be set.
        ///
        /// We use the `-keypaswd` command of keytool, which usually changes a key's password,
        /// but we don't supply it with a new password and only use it to check its error
        /// output. In case the store password is wrong 'password was incorrect' will be
        /// printed. In case the key password is wrong 'Cannot recover key' will be printed.
        /// In case both store and key passwords match, we check if the keytool prompted
        /// for the key password (if not, the passwords must match) and check if they match
        /// ourself.
        /// </remarks>
        Error CheckAliasPassword(string keystore, string alias, string keystorePass, string aliasPass)
        {
            var result = FindKeytool();

            if (result != Error.None)
            {
                return(result);
            }

            var arguments = string.Format(
                "-keypasswd -keystore '{0}' -alias '{1}'",
                keystore, alias
                );
            var    input = keystorePass + "\n" + aliasPass;
            string output, error;

            OptionHelper.RunScript(keytoolPath, arguments, input, out output, out error);

            if (output.Contains("password was incorrect"))
            {
                return(Error.InvalidKeystorePassword);
            }

            if (output.Contains("Cannot recover key"))
            {
                return(Error.InvalidAliasPassword);
            }

            // keytool first tries the store password on the key, so if they
            // match, the key password is never actually checked.
            // In this case we didn't get a key password prompt. Therefore
            // make sure keystore and alias passwords match.
            if (!error.Contains("Enter key password") && keystorePass != aliasPass)
            {
                return(Error.InvalidAliasPassword);
            }

            return(Error.None);
        }
Esempio n. 6
0
        Version DetermineProjectVersion(BuildTarget target)
        {
            // Get version string from either the override or PlayerSettings.bundleVersion
            string versionString;

            var overrideVersion = GetChild <OptionOverrideVersion>().Value;

            if (!string.IsNullOrEmpty(overrideVersion))
            {
                versionString = overrideVersion;
            }
            else
            {
                versionString = PlayerSettings.bundleVersion;
                if (string.IsNullOrEmpty(versionString))
                {
                    Debug.LogError("OptionVersion: Please configure the version in the player settings.");
                    return(default(Version));
                }
            }

            // -- Parse version
            string error;
            var    version = Version.Parse(versionString, out error);

            if (error != null)
            {
                Debug.LogError(error);
                return(default(Version));
            }

            if (!version.IsDefined)
            {
                Debug.LogWarning("OptionVersion: No valid version defined (" + version.MajorMinorPatch + ")");
            }

            // -- Parse build
            var sharing       = GetChild <OptionShareBuildNumber>().Value;
            var overrideBuild = GetChild <OptionOverrideBuild>().Value;

            if (overrideBuild >= 0)
            {
                // Build number has been overridden
                version.build = overrideBuild;
            }
            else if (sharing != BuildNumberSharing.None)
            {
                // Look for highest build number across build target groups, increment it
                // and then apply it back to all groups
                if (!LoadBuildNumberMethods())
                {
                    Debug.LogError("OptionVersion: Could not find internal GetBuildNumber method on PlayerSettings.");
                    return(default(Version));
                }

                var buildNumbers = new List <int>();
                foreach (var targetGroup in GetSharedTargets(sharing))
                {
                    var numberString = GetBuildNumber(targetGroup);
                    int number;
                    if (!int.TryParse(numberString, out number) || number < 0)
                    {
                        Debug.LogError("OptionVersion: " + targetGroup + " build number should be a positive integer (" + numberString + ")");
                    }
                    else
                    {
                        buildNumbers.Add(number);
                    }
                }

                var android = PlayerSettings.Android.bundleVersionCode;
                if (android < 0)
                {
                    Debug.LogError("OptionVersion: Android bundle version code should be a positive integer.");
                }
                else
                {
                    buildNumbers.Add(android);
                }

                // Use the highest defined build number
                version.build = buildNumbers.Max();
            }
            else
            {
                // Only increment the number for the current build target group
                var targetGroup = BuildPipeline.GetBuildTargetGroup(target);
                if (targetGroup == BuildTargetGroup.Android)
                {
                    version.build = PlayerSettings.Android.bundleVersionCode;
                }
                else
                {
                    if (!LoadBuildNumberMethods())
                    {
                        Debug.LogError("OptionVersion: Could not find internal GetBuildNumber method on PlayerSettings.");
                        return(default(Version));
                    }

                    var numberString = GetBuildNumber(targetGroup);
                    var number       = 0;
                    if (!int.TryParse(numberString, out number) || number < 0)
                    {
                        Debug.LogError("OptionVersion: " + targetGroup + " build number should be a positive integer (" + numberString + ")");
                    }

                    version.build = number;
                }
            }

            // -- Version Control
            if (GetChild <OptionVersionControl>().Value)
            {
                // -- Git
                if (System.IO.Directory.Exists(".git"))
                {
                    OptionHelper.RunScript("git", "rev-parse --verify HEAD", out version.commit);
                    if (version.commit != null)
                    {
                        version.commit = version.commit.Trim();
                        if (version.commit.Length == 0)
                        {
                            version.commit = null;
                        }
                    }

                    OptionHelper.RunScript("git", "rev-parse --abbrev-ref --verify HEAD", out version.branch);
                    if (version.branch != null)
                    {
                        version.branch = version.branch.Trim();
                        if (version.branch.Length == 0)
                        {
                            version.branch = null;
                        }
                    }
                }
            }

            return(version);
        }