コード例 #1
0
        private async Task PerformObfuscation()
        {
            await Task.Yield();

            //generate a fake username or password here
            List <string> _fakes = new List <string>();

            if (FakeUsernames)
            {
                _logger.Log(LoggerMessageType.VerboseHigh | LoggerMessageType.Information, "Generating fake username.");
                string user = SimpleRandomGenerator.QuickGetRandomString(
                    SimpleRandomGenerator.CharSelection.Lowercase | SimpleRandomGenerator.CharSelection.Uppercase | SimpleRandomGenerator.CharSelection.Digits,
                    SimpleRandomGenerator.QuickGetRandomInt(4, 12),
                    false);
                string userName = String.Empty;
                if (_domains == null)
                {
                    _logger.Log(LoggerMessageType.VerboseHigh | LoggerMessageType.Information, "Loading list of domains for first time.");
                    _domains = new List <string>();
                    using (StringReader stringReader = new StringReader(Properties.Resources.domains))
                    {
                        string curLine = stringReader.ReadLine();
                        while (!String.IsNullOrEmpty(curLine))
                        {
                            if (!_domains.Contains(curLine))
                            {
                                _domains.Add(curLine);
                            }
                            curLine = stringReader.ReadLine();
                        }
                    }
                }
                string domain = SimpleRandomGenerator.QuickGetRandomStringArrayEntry(_domains.ToArray());
                userName = String.Format("{0}@{1}", user, domain);
                _fakes.Add(userName);
            }

            if (FakePasswords)
            {
                _logger.Log(LoggerMessageType.VerboseHigh | LoggerMessageType.Information, "Generating fake password.");
                _fakes.Add(SimpleRandomGenerator.QuickGetRandomString(SimpleRandomGenerator.CharSelection.All, 16, false));
            }

            _logger.Log(LoggerMessageType.VerboseHigh | LoggerMessageType.Information, "Randomly picking fake data.");
            string fakeEntry = SimpleRandomGenerator.QuickGetRandomStringArrayEntry(_fakes.ToArray());

            _logger.Log(LoggerMessageType.VerboseHigh | LoggerMessageType.Information, "Fake data picked, invoking obfuscate action.");
            await _action.Invoke(new ClipboardObfuscatorGeneratedFakeEventArgs(fakeEntry));
        }
コード例 #2
0
ファイル: AuditLogEntryTests.cs プロジェクト: devoctomy/cachy
        public static AuditLogEntry CreateRandomAuditLogEntry(Random rng,
                                                              out String name,
                                                              out String type,
                                                              out AuditLogEntry.EntryType entryType)
        {
            name      = SimpleRandomGenerator.QuickGetRandomString("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 6);
            type      = rng.Next(0, 100) >= 50 ? "vault" : "credential";
            entryType = SimpleRandomGenerator.QuickGetRandomEnum <AuditLogEntry.EntryType>(1, AuditLogEntry.EntryType.None);
            Dictionary <String, String> parameters = new Dictionary <String, String>();

            parameters.Add("Name", name);
            parameters.Add("Type", type);

            AuditLogEntry entry = new AuditLogEntry(entryType,
                                                    parameters.ToArray());

            return(entry);
        }
コード例 #3
0
ファイル: VaultViewModel.cs プロジェクト: devoctomy/cachy
        public async Task ExportCSV(object parameter)
        {
            App.AppLogger.Logger.Log(devoctomy.DFramework.Logging.Interfaces.LoggerMessageType.VerboseHigh | devoctomy.DFramework.Logging.Interfaces.LoggerMessageType.Information, "Export CSV.");

            VaultExporter exporter = new VaultExporter(
                Common.ExportFormat.cachyCSV1_0,
                Common.ExportWrapping.PasswordProtectedZip);

            string extension = exporter.ExportWrapping == Common.ExportWrapping.PasswordProtectedZip ? "zip" : "csv";
            string name      = String.Format("{0}_{1}", Vault.Name, DateTime.Now.ToString("ddMMyyyy"));
            string fileName  = String.Format("{0}.{1}", name, extension);

            string passsword = SimpleRandomGenerator.QuickGetRandomString(
                SimpleRandomGenerator.CharSelection.All,
                16,
                true);

            byte[] exportData = exporter.Export(
                Vault,
                new KeyValuePair <string, string>("password", passsword));   //auto generate the password and display it in a popup after

            String fullExportPath = String.Empty;
            bool   success        = false;

            try
            {
                switch (Device.RuntimePlatform)
                {
                case Device.UWP:
                {
                    KeyValuePair <string, string[]> extensions = new KeyValuePair <string, string[]>(extension.ToUpper(), new string[] { String.Format(".{0}", extension) });
                    KeyValuePair <string, Stream>?  output     = await devoctomy.cachy.Framework.Native.Native.FileHandler.PickFileForSave(
                        fileName,
                        extensions);

                    if (output.HasValue)
                    {
                        fullExportPath = output.Value.Key;
                        await output.Value.Value.WriteAsync(exportData, 0, exportData.Length);

                        await output.Value.Value.FlushAsync();

                        output.Value.Value.Close();
                        success = true;
                    }

                    break;
                }

                default:
                {
                    String appDataPath = String.Empty;
                    devoctomy.DFramework.Core.IO.Directory.ResolvePath("{AppData}", out appDataPath);
                    if (!appDataPath.EndsWith(DLoggerManager.PathDelimiter))
                    {
                        appDataPath += DLoggerManager.PathDelimiter;
                    }
                    String vaultExportsPath = String.Format("{0}{1}", appDataPath, "Exports");
                    fullExportPath = String.Format("{0}\\{1}", vaultExportsPath, fileName);
                    try
                    {
                        await devoctomy.cachy.Framework.Native.Native.FileHandler.WriteAsync(fullExportPath, exportData);

                        success = true;
                    }
                    catch (Exception)
                    { }
                    break;
                }
                }
            }
            catch (Exception ex)
            {
                App.AppLogger.Logger.Log(devoctomy.DFramework.Logging.Interfaces.LoggerMessageType.Exception, "Failed to export credentials. {0}", ex.ToString());
            }

            if (success)
            {
                Credential credential = Vault.CreateCredential();
                credential.GlyphKey    = Fonts.CachyFont.Glyph.Export.ToString();
                credential.GlyphColour = "Red";
                credential.Name        = name;
                credential.Description = "Password protected ZIP export.";
                credential.Notes       = fullExportPath;
                credential.Password    = passsword;
                credential.AddToVault(true);

                if (AppConfig.Instance.AutoSave && AppConfig.Instance.AutoSaveOnDuplicatingCred)
                {
                    Common.SaveResult saveResult = await Save();

                    if (saveResult == Common.SaveResult.Success)
                    {
                        VaultIndexFile.Invalidate();
                    }
                }

                NotifyPropertyChanged("FilteredCredentials");

                await App.Controller.MainPageInstance.DisplayAlert("Export Credentials",
                                                                   String.Format("Export was successful, the password for the export ZIP file has been placed in your vault, under the name '{0}'. Please remember to lock your vault to save the credential if you do not have aut-save enabled.", name),
                                                                   "OK");
            }
        }
コード例 #4
0
        private void Generate()
        {
            if (Memorable)
            {
                try
                {
                    string format = String.Empty;
                    if (RandomFormat)
                    {
                        List <string> formatParts = new List <string>();
                        formatParts.Add("{adjective:rc}");
                        formatParts.Add("{noun:rc}");
                        formatParts.Add("{verb:rc}");
                        formatParts.Add("{special1:1}");
                        formatParts.Add("{int:1-100}");
                        while (formatParts.Count > 0)
                        {
                            if (formatParts.Count > 0)
                            {
                                int randomIndex = SimpleRandomGenerator.QuickGetRandomInt(0, formatParts.Count);
                                format += formatParts[randomIndex];
                                formatParts.RemoveAt(randomIndex);
                            }
                            else
                            {
                                format += formatParts[0];
                                formatParts.RemoveAt(0);
                            }
                        }
                    }
                    else
                    {
                        format = MemorableFormat;
                    }
                    Password = Dictionaries.Instance.GeneratePhrase(format);
                }
                catch (Exception)
                {
                    Password = "******";
                }
            }
            else
            {
                SimpleRandomGenerator.CharSelection charSelection = SimpleRandomGenerator.CharSelection.None;
                if (UseDigits)
                {
                    charSelection |= SimpleRandomGenerator.CharSelection.Digits;
                }
                if (UseLowercase)
                {
                    charSelection |= SimpleRandomGenerator.CharSelection.Lowercase;
                }
                if (UseUppercase)
                {
                    charSelection |= SimpleRandomGenerator.CharSelection.Uppercase;
                }
                if (UseSpecial && UseBrackets)
                {
                    charSelection |= SimpleRandomGenerator.CharSelection.Brackets;
                }
                if (UseSpecial && UseMinus)
                {
                    charSelection |= SimpleRandomGenerator.CharSelection.Minus;
                }
                if (UseSpecial && UseOther)
                {
                    charSelection |= SimpleRandomGenerator.CharSelection.Other;
                }
                if (UseSpecial && UseSpace)
                {
                    charSelection |= SimpleRandomGenerator.CharSelection.Space;
                }
                if (UseSpecial && UseUnderline)
                {
                    charSelection |= SimpleRandomGenerator.CharSelection.Underline;
                }

                Password = SimpleRandomGenerator.QuickGetRandomString(charSelection, Length, AtLeastOneOfEach);
            }
        }
コード例 #5
0
        public static Credential CreateRandomCredential(
            Random rng,
            out string id,
            out string glyphKey,
            out string glyphColour,
            out string name,
            out string description,
            out string website,
            out DateTime createdAt,
            out DateTime lastModifiedAt,
            out DateTime passwordLastModifiedAt,
            out string username,
            out string password,
            out string[] tags,
            out string notes,
            out AuditLogEntry[] auditLogEntries)
        {
            id                     = Guid.NewGuid().ToString();
            glyphKey               = "None";
            glyphColour            = "Black";
            name                   = Guid.NewGuid().ToString();
            description            = Guid.NewGuid().ToString();
            website                = Guid.NewGuid().ToString();
            createdAt              = new DateTime(1982, 4, 3, rng.Next(0, 24), rng.Next(0, 60), rng.Next(0, 60));
            lastModifiedAt         = createdAt.Add(new TimeSpan(rng.Next(0, 101), rng.Next(0, 24), rng.Next(0, 60), rng.Next(0, 60)));
            passwordLastModifiedAt = createdAt.Add(new TimeSpan(rng.Next(0, 101), rng.Next(0, 24), rng.Next(0, 60), rng.Next(0, 60)));
            username               = SimpleRandomGenerator.QuickGetRandomString("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", 12) + "@" + SimpleRandomGenerator.QuickGetRandomString("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", 6) + ".com";
            password               = SimpleRandomGenerator.QuickGetRandomString(SimpleRandomGenerator.CharSelection.All, 16, true);
            List <String> tagsList = new List <String>();

            while (tagsList.Count < 10)
            {
                tagsList.Add(Guid.NewGuid().ToString());
            }
            tags  = tagsList.ToArray();
            notes = SimpleRandomGenerator.QuickGetRandomString("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", 256);
            List <AuditLogEntry> auditLogEntriesList = new List <AuditLogEntry>();

            while (auditLogEntriesList.Count < 100)
            {
                auditLogEntriesList.Add(AuditLogEntryTests.CreateRandomAuditLogEntry(rng));
            }
            auditLogEntries = auditLogEntriesList.ToArray();

            Credential credential = new Credential(id,
                                                   glyphKey,
                                                   glyphColour,
                                                   name,
                                                   description,
                                                   website,
                                                   createdAt,
                                                   lastModifiedAt,
                                                   passwordLastModifiedAt,
                                                   username,
                                                   password,
                                                   tags,
                                                   notes,
                                                   auditLogEntries);

            return(credential);
        }
コード例 #6
0
ファイル: Dictionaries.cs プロジェクト: devoctomy/cachy
        public string GeneratePhrase(string format)
        {
            string phrase = format;

            //we do this in a loop so we can replace individual tokens as we go
            Regex tokenRegex = new Regex("\\{(.*?)\\}");
            Dictionary <string, string> invalidTokens = new Dictionary <string, string>();
            MatchCollection             tokens        = tokenRegex.Matches(phrase);

            while (tokens.Count > 0)
            {
                Match firstMatch = tokens[0];

                string   token      = firstMatch.Value.Trim(new char[] { '{', '}' });
                string[] tokenParts = token.Split(':');
                if (tokenParts.Length == 2)
                {
                    string randomWord = String.Empty;
                    switch (tokenParts[0])
                    {
                    case "verb":
                    {
                        randomWord = SimpleRandomGenerator.QuickGetRandomStringArrayEntry(Verbs.ToArray());
                        break;
                    }

                    case "adjective":
                    {
                        randomWord = SimpleRandomGenerator.QuickGetRandomStringArrayEntry(Adjectives.ToArray());
                        break;
                    }

                    case "noun":
                    {
                        randomWord = SimpleRandomGenerator.QuickGetRandomStringArrayEntry(Nouns.ToArray());
                        break;
                    }

                    case "int":
                    {
                        randomWord = "{int}";
                        break;
                    }

                    case "special1":
                    {
                        randomWord = "{special1}";
                        break;
                    }

                    default:
                    {
                        randomWord = "{invalid}";
                        break;
                    }
                    }
                    bool replace = true;
                    switch (randomWord)
                    {
                    case "{int}":
                    {
                        string   range      = tokenParts[1];
                        string[] rangeParts = range.Split('-');
                        int      min        = int.Parse(rangeParts[0]);
                        int      max        = int.Parse(rangeParts[1]);
                        if (max > min)
                        {
                            int randomInt = SimpleRandomGenerator.QuickGetRandomInt(min, max);
                            randomWord = randomInt.ToString();
                        }
                        else
                        {
                            randomWord = String.Empty;
                        }
                        break;
                    }

                    case "{special1}":
                    {
                        int count = int.Parse(tokenParts[1]);
                        randomWord = SimpleRandomGenerator.QuickGetRandomString(
                            SimpleRandomGenerator.CharSelection.Minus |
                            SimpleRandomGenerator.CharSelection.Underline,
                            count,
                            false);
                        break;
                    }

                    case "{invalid}":
                    {
                        string tempReplacement = String.Format("[invalidtoken:{0}]", invalidTokens.Count);
                        invalidTokens.Add(tempReplacement, firstMatch.Value);
                        phrase  = phrase.Remove(firstMatch.Index, firstMatch.Length);
                        phrase  = phrase.Insert(firstMatch.Index, tempReplacement);
                        replace = false;
                        break;
                    }

                    default:
                    {
                        string casing = tokenParts[1];
                        if (casing == "rc")
                        {
                            casing = SimpleRandomGenerator.QuickGetRandomStringArrayEntry(new string[] { "lc", "uc", "ic" });
                        }
                        switch (casing)
                        {
                        case "lc":
                        {
                            randomWord = randomWord.ToLower();
                            break;
                        }

                        case "uc":
                        {
                            randomWord = randomWord.ToUpper();
                            break;
                        }

                        case "ic":
                        {
                            randomWord = randomWord[0].ToString().ToUpper() + randomWord.Substring(1);
                            break;
                        }
                        }
                        break;
                    }
                    }
                    if (replace)
                    {
                        phrase = phrase.Remove(firstMatch.Index, firstMatch.Length);
                        phrase = phrase.Insert(firstMatch.Index, randomWord);
                    }
                }
                else
                {
                    //invalid token, remove it so that we don't get stuck in the loop
                    string tempReplacement = String.Format("[invalidtoken:{0}]", invalidTokens.Count);
                    invalidTokens.Add(tempReplacement, firstMatch.Value);
                    phrase = phrase.Remove(firstMatch.Index, firstMatch.Length);
                    phrase = phrase.Insert(firstMatch.Index, tempReplacement);
                }

                tokens = tokenRegex.Matches(phrase);
            }

            foreach (string token in invalidTokens.Keys)
            {
                if (phrase.Contains(token))
                {
                    phrase = phrase.Replace(token, invalidTokens[token]);
                }
            }

            return(phrase);
        }