예제 #1
0
        public override int Run(string[] remainingArguments)
        {
            try
            {
                if (_user.tbl_UserMount != null)
                {
                    Console.Out.WriteLine("  *** The user already has a mount ***");
                    Console.Out.WriteLine();
                    ConsoleHelper.StdOutUserMounts(new List <tbl_UserMount> {
                        _user.tbl_UserMount
                    });

                    return(StandardOutput.FondFarewell());
                }

                var credentials = _uow.Credentials.Get();

                ConsoleHelper.StdOutCredentials(credentials);

                Console.Out.WriteLine();
                Console.Out.Write("  *** Enter GUID of credential to use for mount *** : ");
                var input = StandardInput.GetInput();

                _user.tbl_UserMount.CredentialId = Guid.Parse(input);

                _uow.Users.Update(_user);
                _uow.Commit();

                return(StandardOutput.FondFarewell());
            }
            catch (Exception ex)
            {
                return(StandardOutput.AngryFarewell(ex));
            }
        }
예제 #2
0
    private static bool IsCertOnKeychain(string keychain, X509Certificate2 certificate)
    {
        TimeSpan     MaxRegexTimeout         = TimeSpan.FromMinutes(1);
        const string CertificateSubjectRegex = "CN=(.*[^,]+).*";

        var subjectMatch = Regex.Match(certificate.Subject, CertificateSubjectRegex, RegexOptions.Singleline, MaxRegexTimeout);

        if (!subjectMatch.Success)
        {
            throw new InvalidOperationException($"Can't determine the subject for the certificate with subject '{certificate.Subject}'.");
        }

        var subject = subjectMatch.Groups[1].Value;

        // Run the find-certificate command, and look for the cert's hash in the output
        using var findCertificateProcess = Process.Start(new ProcessStartInfo(
                                                             MacOSFindCertificateOnKeychainCommandLine,
                                                             string.Format(CultureInfo.InvariantCulture, MacOSFindCertificateOnKeychainCommandLineArgumentsFormat, subject, keychain))
        {
            RedirectStandardOutput = true
        });

        var output = findCertificateProcess !.StandardOutput.ReadToEnd();

        findCertificateProcess.WaitForExit();

        var matches = Regex.Matches(output, MacOSFindCertificateOutputRegex, RegexOptions.Multiline, MaxRegexTimeout);
        var hashes  = matches.OfType <Match>().Select(m => m.Groups[1].Value).ToList();

        return(hashes.Any(h => string.Equals(h, certificate.Thumbprint, StringComparison.Ordinal)));
    }
예제 #3
0
        public override int Run(string[] remainingArguments)
        {
            var license = _uow.Settings.Get(QueryExpressionFactory.GetQueryExpression <tbl_Setting>()
                                            .Where(x => x.ConfigKey == "RebexLicense").ToLambda()).OrderBy(x => x.Created)
                          .Last();

            Rebex.Licensing.Key = license.ConfigValue;

            AsymmetricKeyAlgorithm.Register(Curve25519.Create);
            AsymmetricKeyAlgorithm.Register(Ed25519.Create);
            AsymmetricKeyAlgorithm.Register(EllipticCurveAlgorithm.Create);

            try
            {
                if (string.IsNullOrEmpty(_privKeyPass))
                {
                    Console.Out.Write("  *** Enter password for the private key *** : ");
                    _privKeyPass = StandardInput.GetHiddenInput();
                }

                Console.Out.WriteLine();
                Console.Out.WriteLine("Opened " + _path.FullName);

                KeyHelper.ImportPrivKey(_conf, _uow, _privKeyPass, SignatureHashAlgorithm.SHA256, new FileInfo(_path.FullName));

                return(StandardOutput.FondFarewell());
            }
            catch (Exception ex)
            {
                return(StandardOutput.AngryFarewell(ex));
            }
        }
예제 #4
0
        public override int Run(string[] remainingArguments)
        {
            try
            {
                var license = _uow.Settings.Get(QueryExpressionFactory.GetQueryExpression <tbl_Setting>()
                                                .Where(x => x.ConfigKey == "RebexLicense").ToLambda()).OrderBy(x => x.Created)
                              .Last();

                Rebex.Licensing.Key = license.ConfigValue;

                AsymmetricKeyAlgorithm.Register(Curve25519.Create);
                AsymmetricKeyAlgorithm.Register(Ed25519.Create);
                AsymmetricKeyAlgorithm.Register(EllipticCurveAlgorithm.Create);

                if (string.IsNullOrEmpty(_secretCurrent))
                {
                    Console.Out.Write("  *** Enter current secret to encrypt passwords *** : ");
                    _secretCurrent = StandardInput.GetHiddenInput();
                }

                if (string.IsNullOrEmpty(_secretNew))
                {
                    Console.Out.Write("  *** Enter new secret to encrypt passwords *** : ");
                    _secretNew = StandardInput.GetHiddenInput();
                }
                else
                {
                    _secretNew = AlphaNumeric.CreateString(32);
                    Console.Out.WriteLine($"  *** The new secret to encrypt passwords is *** : {_secretNew}");
                }

                var keys  = _uow.PrivateKeys.Get().ToList();
                var creds = _uow.Credentials.Get().ToList();

                Console.Out.WriteLine();
                Console.Out.WriteLine("  *** Current private key pass ciphertexts *** ");
                ConsoleHelper.StdOutKeyPairSecrets(keys);

                Console.Out.WriteLine();
                Console.Out.WriteLine("  *** Current credential password ciphertexts *** ");
                ConsoleHelper.StdOutCredentialSecrets(creds);

                keys  = KeyHelper.EditPrivKeySecrets(_uow, keys, _secretCurrent, _secretNew).ToList();
                creds = UserHelper.EditCredentialSecrets(_uow, creds, _secretCurrent, _secretNew).ToList();

                Console.Out.WriteLine();
                Console.Out.WriteLine("  *** New private key pass ciphertexts *** ");
                ConsoleHelper.StdOutKeyPairSecrets(keys);

                Console.Out.WriteLine();
                Console.Out.WriteLine("  *** New credential password ciphertexts *** ");
                ConsoleHelper.StdOutCredentialSecrets(creds);

                return(StandardOutput.FondFarewell());
            }
            catch (Exception ex)
            {
                return(StandardOutput.AngryFarewell(ex));
            }
        }
예제 #5
0
        public override int Run(string[] remainingArguments)
        {
            try
            {
                var config = _uow.Settings.Get(QueryExpressionFactory.GetQueryExpression <tbl_Setting>()
                                               .Where(x => x.ConfigKey == _configType.ToString()).ToLambda())
                             .SingleOrDefault();

                if (config == null)
                {
                    throw new ConsoleHelpAsException($"  *** Invalid config type '{_configType.ToString()}' ***");
                }

                config.ConfigValue = _configValue;

                _uow.Settings.Update(config);
                _uow.Commit();

                return(StandardOutput.FondFarewell());
            }
            catch (Exception ex)
            {
                return(StandardOutput.AngryFarewell(ex));
            }
        }
예제 #6
0
 private RunResult CreateRunResult()
 {
     return(new RunResult {
         Output = StandardOutput.ReadToEnd(),
         Error = StandardError.ReadToEnd(),
         RunTime = (int)ExitTime.Subtract(StartTime).TotalMilliseconds
     });
 }