Esempio n. 1
0
 public static EntryConfig GetKPRPCConfig(this PwEntry entry, ProtectedStringDictionary strings, ref List<string> configErrors)
 {
     if (strings == null)
         strings = entry.Strings;
     EntryConfig conf = null;
     string json = strings.ReadSafe("KPRPC JSON");
     if (string.IsNullOrEmpty(json))
         conf = new EntryConfig();
     else
     {
         try
         {
             conf = (EntryConfig)Jayrock.Json.Conversion.JsonConvert.Import(typeof(EntryConfig), json);
         }
         catch (Exception)
         {
             var url = strings.ReadSafe("URL");
             if (string.IsNullOrEmpty(url))
                 url = "<unknown>";
             if (configErrors != null)
             {
                 string entryUserName = strings.ReadSafe(PwDefs.UserNameField);
                 //entryUserName = KeePassRPCPlugin.GetPwEntryStringFromDereferencableValue(entry, entryUserName, db);
                 configErrors.Add("Username: "******". URL: " + url);
             }
             else
             {
                 MessageBox.Show("There are configuration errors in this entry. To fix the entry and prevent this warning message appearing, please edit the value of the 'KPRPC JSON' advanced string. Please ask for help on http://keefox.org/help/forum if you're not sure how to fix this. The URL of the entry is: " + url + " and the full configuration data is: " + json, "Warning: Configuration errors", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             }
             return null;
         }
     }
     return conf;
 }
Esempio n. 2
0
        internal static PEDCalcValue ReadPEDCString(this ProtectedStringDictionary psd)
        {
            string sPEDC = psd.ReadSafe(Configuration.DaysField);

            if (string.IsNullOrEmpty(sPEDC))
            {
                sPEDC = psd.ReadSafe(Configuration.Interval);
            }
            if (!string.IsNullOrEmpty(sPEDC))
            {
                return(PEDCalcValue.ConvertFromString(sPEDC));
            }
            return(null);
        }
Esempio n. 3
0
        public KeeFoxEntryUserControl(KeePassRPCExt keePassRPCPlugin, PwEntry entry,
                                      CustomListViewEx advancedListView, PwEntryForm pwEntryForm, ProtectedStringDictionary strings)
        {
            KeePassRPCPlugin = keePassRPCPlugin;
            _entry           = entry;
            InitializeComponent();
            _pwEntryForm = pwEntryForm;
            _strings     = strings;
            string json = strings.ReadSafe("KPRPC JSON");

            if (string.IsNullOrEmpty(json))
            {
                _conf = new EntryConfig();
            }
            else
            {
                try
                {
                    _conf = (EntryConfig)Jayrock.Json.Conversion.JsonConvert.Import(typeof(EntryConfig), json);
                }
                catch (Exception)
                {
                    MessageBox.Show("There are configuration errors in this entry. To fix the entry and prevent this warning message appearing, please edit the value of the 'KeePassRPC JSON config' advanced string. Please ask for help on http://keefox.org/help/forum if you're not sure how to fix this.", "Warning: Configuration errors", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }
Esempio n. 4
0
        public static ISshKey GetSshKey(this EntrySettings settings,
                                        ProtectedStringDictionary strings, ProtectedBinaryDictionary binaries,
                                        SprContext sprContext)
        {
            if (!settings.AllowUseOfSshKey)
            {
                return(null);
            }
            KeyFormatter.GetPassphraseCallback getPassphraseCallback =
                delegate(string comment)
            {
                var securePassphrase = new SecureString();
                var passphrase       = SprEngine.Compile(strings.ReadSafe(
                                                             PwDefs.PasswordField), sprContext);
                foreach (var c in passphrase)
                {
                    securePassphrase.AppendChar(c);
                }
                return(securePassphrase);
            };
            Func <Stream> getPrivateKeyStream;
            Func <Stream> getPublicKeyStream = null;

            switch (settings.Location.SelectedType)
            {
            case EntrySettings.LocationType.Attachment:
                if (string.IsNullOrWhiteSpace(settings.Location.AttachmentName))
                {
                    throw new NoAttachmentException();
                }
                var privateKeyData = binaries.Get(settings.Location.AttachmentName);
                var publicKeyData  = binaries.Get(settings.Location.AttachmentName + ".pub");
                getPrivateKeyStream = () => new MemoryStream(privateKeyData.ReadData());
                if (publicKeyData != null)
                {
                    getPublicKeyStream = () => new MemoryStream(publicKeyData.ReadData());
                }
                return(GetSshKey(getPrivateKeyStream, getPublicKeyStream,
                                 settings.Location.AttachmentName, getPassphraseCallback));

            case EntrySettings.LocationType.File:
                var filename = settings.Location.FileName.ExpandEnvironmentVariables();
                getPrivateKeyStream = () => File.OpenRead(filename);
                var publicKeyFile = filename + ".pub";
                if (File.Exists(publicKeyFile))
                {
                    getPublicKeyStream = () => File.OpenRead(publicKeyFile);
                }
                return(GetSshKey(getPrivateKeyStream, getPublicKeyStream,
                                 settings.Location.AttachmentName, getPassphraseCallback));

            default:
                return(null);
            }
        }
Esempio n. 5
0
        public static EntryConfig GetKPRPCConfig(this PwEntry entry, ProtectedStringDictionary strings, ref List <string> configErrors)
        {
            if (strings == null)
            {
                strings = entry.Strings;
            }
            EntryConfig conf = null;
            string      json = strings.ReadSafe("KPRPC JSON");

            if (string.IsNullOrEmpty(json))
            {
                conf = new EntryConfig();
            }
            else
            {
                try
                {
                    conf = (EntryConfig)Jayrock.Json.Conversion.JsonConvert.Import(typeof(EntryConfig), json);
                }
                catch (Exception)
                {
                    var url = strings.ReadSafe("URL");
                    if (string.IsNullOrEmpty(url))
                    {
                        url = "<unknown>";
                    }
                    if (configErrors != null)
                    {
                        string entryUserName = strings.ReadSafe(PwDefs.UserNameField);
                        //entryUserName = KeePassRPCPlugin.GetPwEntryStringFromDereferencableValue(entry, entryUserName, db);
                        configErrors.Add("Username: "******". URL: " + url);
                    }
                    else
                    {
                        MessageBox.Show("There are configuration errors in this entry. To fix the entry and prevent this warning message appearing, please edit the value of the 'KPRPC JSON' advanced string. Please ask for help on https://keefox.org/help/forum if you're not sure how to fix this. The URL of the entry is: " + url + " and the full configuration data is: " + json, "Warning: Configuration errors", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    return(null);
                }
            }
            return(conf);
        }
Esempio n. 6
0
        private void CalculateHashString()
        {
            ProtectedStringDictionary stringDict = Entry.Strings;

            byte[] pw     = StrUtil.Utf8.GetBytes(stringDict.ReadSafe(KeePassLib.PwDefs.PasswordField));
            byte[] hashed = null;
            using (SHA1 sha1 = new SHA1Managed())
            {
                hashed = sha1.ComputeHash(pw);
            }
            MemUtil.ZeroByteArray(pw);
            Hash = MemUtil.ByteArrayToHexString(hashed);
            MemUtil.ZeroByteArray(hashed);
        }
Esempio n. 7
0
        public override void AttachToEntryDialog(KeePassRPCExt plugin, PwEntry entry, TabControl mainTabControl, PwEntryForm form, CustomListViewEx advancedListView, ProtectedStringDictionary strings)
        {
            UserControl entryControl;

            try
            {
                string qualifiedName = typeof(KeePass.Util.AutoType).AssemblyQualifiedName
                                       .Replace("KeePass.Util.AutoType", "KeePass.Util.MultipleValues.MultipleValuesEx");
                System.Type  mvType   = System.Type.GetType(qualifiedName);
                PropertyInfo prop     = mvType.GetProperty("CueString", BindingFlags.Public | BindingFlags.Static);
                string       mvString = (string)prop.GetValue(null, null);
                string       json     = strings.ReadSafe("KPRPC JSON");
                if (!string.IsNullOrEmpty(json) && mvString == json)
                {
                    entryControl = new KeeMultiEntryUserControl();
                }
                else
                {
                    entryControl = new KeeEntryUserControl(plugin, entry, advancedListView, form, strings);
                }
            }
            catch
            {
                // Assume we're running in an older version of KeePass that can't edit multiple entries
                entryControl = new KeeEntryUserControl(plugin, entry, advancedListView, form, strings);
            }

            TabPage keeTabPage = new TabPage("Kee");

            entryControl.Dock = DockStyle.Fill;
            keeTabPage.Controls.Add(entryControl);
            if (mainTabControl.ImageList == null)
            {
                mainTabControl.ImageList = new ImageList();
            }
            int imageIndex = mainTabControl.ImageList.Images.Add(global::KeePassRPC.Properties.Resources.KPRPC64, Color.Transparent);

            keeTabPage.ImageIndex = imageIndex;
            mainTabControl.TabPages.Add(keeTabPage);
        }
Esempio n. 8
0
 public KeeFoxEntryUserControl(KeePassRPCExt keePassRPCPlugin, PwEntry entry,
     CustomListViewEx advancedListView, PwEntryForm pwEntryForm, ProtectedStringDictionary strings)
 {
     KeePassRPCPlugin = keePassRPCPlugin;
     _entry = entry;
     InitializeComponent();
     _pwEntryForm = pwEntryForm;
     _strings = strings;
     string json = strings.ReadSafe("KPRPC JSON");
     if (string.IsNullOrEmpty(json))
         _conf = new EntryConfig();
     else
     {
         try
         {
             _conf = (EntryConfig)Jayrock.Json.Conversion.JsonConvert.Import(typeof(EntryConfig), json);
         }
         catch (Exception)
         {
             MessageBox.Show("There are configuration errors in this entry. To fix the entry and prevent this warning message appearing, please edit the value of the 'KeePassRPC JSON config' advanced string. Please ask for help on http://keefox.org/help/forum if you're not sure how to fix this.", "Warning: Configuration errors", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
     }
 }
Esempio n. 9
0
 public static ISshKey GetSshKey(this EntrySettings settings,
     ProtectedStringDictionary strings, ProtectedBinaryDictionary binaries,
     SprContext sprContext)
 {
     if (!settings.AllowUseOfSshKey) {
     return null;
       }
       KeyFormatter.GetPassphraseCallback getPassphraseCallback =
     delegate(string comment)
     {
       var securePassphrase = new SecureString();
     var passphrase = SprEngine.Compile(strings.ReadSafe(
                   PwDefs.PasswordField), sprContext);
       foreach (var c in passphrase) {
     securePassphrase.AppendChar(c);
       }
       return securePassphrase;
     };
       Func<Stream> getPrivateKeyStream;
       Func<Stream> getPublicKeyStream = null;
       switch (settings.Location.SelectedType) {
     case EntrySettings.LocationType.Attachment:
       if (string.IsNullOrWhiteSpace(settings.Location.AttachmentName)) {
     throw new NoAttachmentException();
       }
       var privateKeyData = binaries.Get(settings.Location.AttachmentName);
       var publicKeyData = binaries.Get(settings.Location.AttachmentName + ".pub");
       getPrivateKeyStream = () => new MemoryStream(privateKeyData.ReadData());
       if (publicKeyData != null)
     getPublicKeyStream = () => new MemoryStream(publicKeyData.ReadData());
       return GetSshKey(getPrivateKeyStream, getPublicKeyStream,
                    settings.Location.AttachmentName, getPassphraseCallback);
     case EntrySettings.LocationType.File:
       getPrivateKeyStream = () => File.OpenRead(settings.Location.FileName);
       var publicKeyFile = settings.Location.FileName + ".pub";
       if (File.Exists(publicKeyFile))
     getPublicKeyStream = () => File.OpenRead(publicKeyFile);
       return GetSshKey(getPrivateKeyStream, getPublicKeyStream,
                    settings.Location.AttachmentName, getPassphraseCallback);
     default:
       return null;
       }
 }
Esempio n. 10
0
 // For display in debugger
 public override string ToString()
 {
     return(@"PwEntry '" + m_listStrings.ReadSafe(PwDefs.TitleField) + @"'");
 }