Example #1
0
        private static string GetKeystoreGenerationArguments(AndroidKeystoreData d)
        {
            string cert = GetKeystoreCertificateInputString(d);

            string days = (d.ValidityInYears * 365).ToString();

            if (string.IsNullOrEmpty(cert))
            {
                cert = "cn=" + d.KeyAlias;
            }

            var cmd = new ArgumentsBuilder(spacesBetweenFlagParam: true);

            cmd.AppendFlag("-genkeypair");
            cmd.AppendFlag("-noprompt");

            cmd.AppendFlagAndParameter("-keyalg", "RSA");
            cmd.AppendFlagAndParameter("-keysize", "4096");

            cmd.AppendFlagAndParameter("-dname", cert, quoteAlways: true);

            cmd.AppendFlagAndParameter("-alias", d.KeyAlias);
            cmd.AppendFlagAndParameter("-keypass", d.KeyPassword);
            cmd.AppendFlagAndParameter("-storepass", d.Password);
            cmd.AppendFlagAndParameter("-keystore", d.KeystorePath, quoteAlways: true);
            cmd.AppendFlagAndParameter("-validity", days);

            return(cmd.ToString());
        }
Example #2
0
        public static bool RunGenerateKeystore(AndroidKeystoreData d)
        {
            if (!IsKeytoolAvailable())
            {
                return(false);
            }
            string keytool = GetKeytoolPath();
            string args    = GetKeystoreGenerationArguments(d);
            string wdir    = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);

            return(RunCommand(command: keytool, args: args, working_dir: wdir, show_window: false));
        }
Example #3
0
        public static IEnumerable <string> GetKeystoreErrors(AndroidKeystoreData d)
        {
            List <string> errors = new List <string>();

            if (string.IsNullOrEmpty(d.KeystorePath))
            {
                errors.Add("Key store path can't be empty.");
            }
            if (!string.IsNullOrEmpty(d.KeystorePath) && Directory.GetParent(d.KeystorePath) == null)
            {
                errors.Add("Key store path directory doesn't exist!");
            }
            if (!string.IsNullOrEmpty(d.KeystorePath) && string.IsNullOrEmpty(Path.GetExtension(d.KeystorePath)))
            {
                errors.Add("Key store path must include desired filename with extension.");
            }
            if (!string.IsNullOrEmpty(d.KeystorePath) && !Path.IsPathRooted(d.KeystorePath))
            {
                errors.Add("Key store path must be absolute.");
            }
            if (!string.IsNullOrEmpty(d.KeystorePath) && File.Exists(d.KeystorePath))
            {
                errors.Add("Key store path must be a new file, it cannot overwrite an existing file.");
            }

            if (string.IsNullOrEmpty(d.Password))
            {
                errors.Add("Password can't be empty.");
            }
            if (string.IsNullOrEmpty(d.KeyPassword))
            {
                errors.Add("Key Password can't be empty.");
            }
            if (d.KeyPassword != d.Password)
            {
                errors.Add("Passwords don't match.");
            }
            if (string.IsNullOrEmpty(d.KeyAlias))
            {
                errors.Add("Key alias cannot be empty.");
            }

            if (d.ValidityInYears < 1)
            {
                errors.Add("Validity cannot be lower than 1 year.");
            }

            return(errors);
        }
Example #4
0
        public AndroidKeystoreData Copy()
        {
            AndroidKeystoreData ks = new AndroidKeystoreData
            {
                _keystorePath    = _keystorePath,
                _password        = _password,
                _keyAlias        = _keyAlias,
                _keyPassword     = _keyPassword,
                _validityInYears = _validityInYears,

                _firstAndLastName   = _firstAndLastName,
                _organizationalUnit = _organizationalUnit,
                _organizationName   = _organizationName,
                _cityOrLocality     = _cityOrLocality,
                _stateOrProvince    = _stateOrProvince,
                _countryCode        = _countryCode
            };

            return(ks);
        }