1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
|
/*
KeePass Password Safe - The Open-Source Password Manager
Copyright (C) 2003-2024 Dominik Reichl <dominik.reichl@t-online.de>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using KeePass.Resources;
using KeePass.UI;
using KeePassLib;
using KeePassLib.Utility;
namespace KeePass.App
{
public static class AppDefs
{
public static readonly Color ColorControlNormal = SystemColors.Window;
public static readonly Color ColorControlDisabled = SystemColors.Control;
public static readonly Color ColorEditError = (UIUtil.IsDarkTheme ?
Color.FromArgb(128, 0, 0) : Color.FromArgb(255, 192, 192));
public const string DebianDataDir = "/usr/share/keepass2/";
public static readonly Color ColorQualityLow = Color.FromArgb(255, 128, 0);
public static readonly Color ColorQualityHigh = Color.FromArgb(0, 255, 0);
public static readonly Color ColorQualityMid = Color.FromArgb(255, 255, 0);
public static readonly string LanguagesDir = "Languages";
public static readonly string PluginsDir = "Plugins";
public static readonly string PluginProductName = "KeePass Plugin";
public static readonly string XslFilesDir = "XSL";
public static readonly string XslFileHtmlFull = "KDBX_DetailsFull_HTML.xsl";
public static readonly string XslFileHtmlLight = "KDBX_DetailsLight_HTML.xsl";
public static readonly string XslFileHtmlTabular = "KDBX_Tabular_HTML.xsl";
public static class FileNames
{
public static readonly string Program = "KeePass.exe";
public static readonly string XmlSerializers = "KeePass.XmlSerializers.dll";
public static readonly string NativeLib32 = "KeePassLibC32.dll";
public static readonly string NativeLib64 = "KeePassLibC64.dll";
public static readonly string ShInstUtil = "ShInstUtil.exe";
}
// internal const string MruNameValueSplitter = @"/::/";
/// <summary>
/// Hot key IDs (used in <c>WM_HOTKEY</c> window messages).
/// </summary>
public static class GlobalHotKeyId
{
public static readonly int AutoType = 195;
public static readonly int AutoTypePassword = 197;
public static readonly int AutoTypeSelected = 196;
public static readonly int ShowWindow = 226;
public static readonly int EntryMenu = 227;
internal const int TempRegTest = 225;
}
public static class HelpTopics
{
internal const string Default = "index";
public static readonly string Acknowledgements = "base/credits";
public static readonly string License = "v2/license";
public static readonly string DatabaseSettings = "v2/dbsettings";
public static readonly string DbSettingsGeneral = "general";
public static readonly string DbSettingsSecurity = "security";
// public static readonly string DbSettingsProtection = "protection";
public static readonly string DbSettingsCompression = "compression";
public static readonly string AutoType = "base/autotype";
public static readonly string AutoTypeObfuscation = "v2/autotype_obfuscation";
public static readonly string AutoTypeWindowFilters = "autowindows";
public static readonly string Entry = "v2/entry";
public static readonly string EntryGeneral = "gen";
public static readonly string EntryStrings = "str";
public static readonly string EntryAutoType = "at";
public static readonly string EntryHistory = "hst";
internal const string EntryAdvanced = "adv";
internal const string EntryProperties = "prp";
public static readonly string KeySources = "base/keys";
public static readonly string KeySourcesKeyFile = "keyfiles";
public static readonly string KeySourcesUserAccount = "winuser";
public static readonly string PwGenerator = "base/pwgenerator";
public static readonly string Search = "base/search";
public static readonly string IOConnections = "v2/ioconnect";
public static readonly string UrlField = "base/autourl";
public static readonly string CommandLine = "base/cmdline";
public static readonly string FieldRefs = "base/fieldrefs";
public static readonly string Configuration = "base/configuration";
internal const string ConfigurationEnableEnf = "enableenf";
internal const string Placeholders = "base/placeholders";
internal const string PlaceholdersOtp = "otp";
public static readonly string ImportExport = "base/importexport";
public static readonly string ImportExportGenericCsv = "genericcsv";
public static readonly string ImportExportSteganos = "imp_steganos";
public static readonly string ImportExportPassKeeper = "imp_passkeeper";
internal const string ImportExportParents = "exp_parents";
public static readonly string Security = "base/security";
internal const string SecurityDictProt = "secdictprotect";
internal const string SecurityOptEx = "secoptex";
internal const string SecurityOptAdm = "secoptadm";
public static readonly string AppPolicy = "v2/policy";
public static readonly string Triggers = "v2/triggers";
public static readonly string TriggersEvents = "events";
public static readonly string TriggersConditions = "conditions";
public static readonly string TriggersActions = "actions";
public static readonly string TriggerUIStateUpd = "kb/trigger_uistateupd";
public static readonly string Setup = "v2/setup";
public static readonly string SetupMono = "mono";
internal const string FaqTech = "base/faq_tech";
internal const string FaqTechGuiDark = "guidark";
internal const string FaqTechGuiFont = "guifont";
public static readonly string XmlReplace = "v2/xml_replace";
public static readonly string KbFaq = "kb/faq";
public static readonly string KbFaqURtf = "urtf";
internal const string KbConfigEnf = "kb/config_enf";
}
public static class CommandLineOptions
{
public static readonly string Password = "pw";
public static readonly string KeyFile = "keyfile";
public static readonly string UserAccount = "useraccount";
public static readonly string PasswordEncrypted = "pw-enc";
public static readonly string PasswordStdIn = "pw-stdin";
public static readonly string PreSelect = "preselect";
public static readonly string IoCredUserName = "iousername";
public static readonly string IoCredPassword = "iopassword";
public static readonly string IoCredFromRecent = "iocredfromrecent";
public static readonly string IoCredIsComplete = "ioiscomplete";
// User-friendly Pascal-case (shown in UAC dialog)
public static readonly string FileExtRegister = "RegisterFileExt";
public static readonly string FileExtUnregister = "UnregisterFileExt";
public static readonly string PreLoad = "preload";
// public static readonly string PreLoadRegister = "registerpreload";
// public static readonly string PreLoadUnregister = "unregisterpreload";
public static readonly string ExitAll = "exit-all";
public static readonly string Minimize = "minimize";
public static readonly string AutoType = "auto-type";
public static readonly string AutoTypePassword = "auto-type-password";
public static readonly string AutoTypeSelected = "auto-type-selected";
public static readonly string OpenEntryUrl = "entry-url-open";
public static readonly string LockAll = "lock-all";
public static readonly string UnlockAll = "unlock-all";
public static readonly string Cancel = "cancel";
public static readonly string IpcEvent = "e";
public static readonly string IpcEvent1 = "e1";
public static readonly string Uuid = "uuid";
public static readonly string Scheme = "scheme";
public static readonly string Value = "value";
public static readonly string Activate = "activate";
public static readonly string Help = "?";
public static readonly string HelpLong = "help";
public static readonly string WorkaroundDisable = "wa-disable";
public static readonly string WorkaroundEnable = "wa-enable";
public static readonly string ConfigPathLocal = "cfg-local";
public static readonly string ConfigSetUrlOverride = "set-urloverride";
public static readonly string ConfigClearUrlOverride = "clear-urloverride";
public static readonly string ConfigGetUrlOverride = "get-urloverride";
public static readonly string ConfigAddUrlOverride = "add-urloverride";
public static readonly string ConfigRemoveUrlOverride = "remove-urloverride";
public static readonly string ConfigSetLanguageFile = "set-languagefile";
internal const string ConfigEnfSetupFile = "cfg-enf-setup-f";
internal const string ConfigEnfSetupHash = "cfg-enf-setup-h";
internal const string KdfTest = "kdf-test";
public static readonly string PlgxCreate = "plgx-create";
public static readonly string PlgxCreateInfo = "plgx-create-info";
public static readonly string PlgxPrereqKP = "plgx-prereq-kp";
public static readonly string PlgxPrereqNet = "plgx-prereq-net";
public static readonly string PlgxPrereqOS = "plgx-prereq-os";
public static readonly string PlgxPrereqPtr = "plgx-prereq-ptr";
public static readonly string PlgxBuildPre = "plgx-build-pre";
public static readonly string PlgxBuildPost = "plgx-build-post";
public static readonly string Debug = "debug";
public static readonly string DebugThrowException = "debug-throwexcp";
// public static readonly string SavePluginCompileRes = "saveplgxcr"; // Now: Debug
public static readonly string ShowAssemblyInfo = "showasminfo";
public static readonly string MakeXmlSerializerEx = "makexmlserializerex";
public static readonly string MakeXspFile = "makexspfile";
#if DEBUG
public static readonly string TestGfx = "testgfx";
#endif
public static readonly string Version = "version"; // For Unix
// #if (DEBUG && !KeePassLibSD)
// public static readonly string MakePopularPasswordTable = "makepopularpasswordtable";
// #endif
}
public static class FileExtension
{
public static readonly string FileExt = "kdbx";
public static readonly string FileExtId = "kdbxfile";
public static readonly string KeyFile = "keyx";
internal const string KeyFileAlt = "key";
}
public static readonly string AutoRunName = "KeePass Password Safe 2";
public static readonly string PreLoadName = "KeePass 2 PreLoad";
public static readonly string MutexName = "KeePassAppMutex";
public static readonly string MutexNameGlobal = "KeePassAppMutexEx";
// public static readonly string ScriptExtension = "kps";
public static readonly int InvalidWindowValue = -16381;
public static class NamedEntryColor
{
public static readonly Color LightRed = Color.FromArgb(255, 204, 204);
public static readonly Color LightGreen = Color.FromArgb(204, 255, 204);
public static readonly Color LightBlue = Color.FromArgb(153, 204, 255);
public static readonly Color LightYellow = Color.FromArgb(255, 255, 153);
}
public static class FileDialogContext
{
// Values must not contain '@'
public static readonly string Database = "Database";
public static readonly string Sync = "Sync";
public static readonly string KeyFile = "KeyFile";
public static readonly string Import = "Import";
public static readonly string Export = "Export";
public static readonly string Attachments = "Attachments";
public static readonly string Xsl = "Xsl";
}
public static readonly string DefaultTrlAuthor = "Dominik Reichl";
public static readonly string DefaultTrlContact = "https://www.dominik-reichl.de/";
// public static readonly string LanguageInfoFileName = "LanguageInfo.xml";
internal const string Rsa4096PublicKeyXml =
@"<RSAKeyValue><Modulus>9Oa8Bb9if4rSYBxczLVQ3Yyae95dWQrNJ1FlqS7DoF" +
@"RF80tD2hq84vxDE8slVeSHs68KMFnJhPsXFD6nM9oTRBaUlU/alnRTUU+X/cUXbr" +
@"mhYN9DkJhM0OcWk5Vsl9Qxl613sA+hqIwmPc+el/fCM/1vP6JkHo/JTJ2OxQvDKN" +
@"4cC55pHYMZt+HX6AhemsPe7ejTG7l9nN5tHGmD+GrlwuxBTddzFBARmoknFzDPWd" +
@"QHddjuK1mXDs6lWeu73ODlSLSHMc5n0R2xMwGHN4eaiIMGzEbt0lv1aMWz+Iy1H3" +
@"XgFgWGDHX9kx8yefmfcgFIK4Y/xHU5EyGAV68ZHPatv6i4pT4ZuecIb5GSoFzVXq" +
@"8BZjbe+zDI+Wr1u8jLcBH0mySTWkF2gooQLvE1vgZXP1blsA7UFZSVFzYjBt36HQ" +
@"SJLpQ9AjjB5MKpMSlvdb5SnvjzREiFVLoBsY7KH2TMz+IG1Rh3OZTGwjQKXkgRVj" +
@"5XrEMTFRmT1zo2BHWhx8vrY6agVzqsCVqxYRbjeAhgOi6hLDMHSNAVuNg6ZHOKS8" +
@"6x6kmBcBhGJriwY017H3Oxuhfz33ehRFX/C05egCvmR2TAXbqm+CUgrq1bZ96T/y" +
@"s+O5uvKpe7H+EZuWb655Y9WuQSby+q0Vqqny7T6Z2NbEnI8nYHg5ZZP+TijSxeH0" +
@"8=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";
public static readonly string ColumnIdnGroup = "Group";
public static readonly string ColumnIdnCreationTime = "CreationTime";
public static readonly string ColumnIdnLastModificationTime = "LastModificationTime";
public static readonly string ColumnIdnLastAccessTime = "LastAccessTime";
public static readonly string ColumnIdnExpiryTime = "ExpiryTime";
public static readonly string ColumnIdnUuid = "UUID";
public static readonly string ColumnIdnAttachment = "Attachment";
public static string GetEntryField(PwEntry pe, string strFieldId)
{
if(pe == null) throw new ArgumentNullException("pe");
if(strFieldId == null) throw new ArgumentNullException("strFieldId");
if(strFieldId == AppDefs.ColumnIdnGroup)
return ((pe.ParentGroup != null) ? pe.ParentGroup.Name : string.Empty);
else if(strFieldId == AppDefs.ColumnIdnCreationTime)
return TimeUtil.ToDisplayString(pe.CreationTime);
else if(strFieldId == AppDefs.ColumnIdnLastModificationTime)
return TimeUtil.ToDisplayString(pe.LastModificationTime);
else if(strFieldId == AppDefs.ColumnIdnLastAccessTime)
return TimeUtil.ToDisplayString(pe.LastAccessTime);
else if(strFieldId == AppDefs.ColumnIdnExpiryTime)
{
if(!pe.Expires) return KPRes.NeverExpires;
return TimeUtil.ToDisplayString(pe.ExpiryTime);
}
else if(strFieldId == AppDefs.ColumnIdnUuid)
return pe.Uuid.ToHexString();
else if(strFieldId == AppDefs.ColumnIdnAttachment)
return pe.Binaries.UCount.ToString();
return pe.Strings.ReadSafe(strFieldId);
}
internal static Color GetQualityColor(float fQ, bool bToControlBack)
{
if(fQ < 0.0f) { Debug.Assert(false); fQ = 0.0f; }
if(fQ > 1.0f) { Debug.Assert(false); fQ = 1.0f; }
Color clrL = AppDefs.ColorQualityLow;
Color clrH = AppDefs.ColorQualityHigh;
Color clrM = AppDefs.ColorQualityMid;
int iR, iG, iB;
if(fQ <= 0.5f)
{
fQ *= 2.0f;
iR = clrL.R + (int)(fQ * ((int)clrM.R - (int)clrL.R));
iG = clrL.G + (int)(fQ * ((int)clrM.G - (int)clrL.G));
iB = clrL.B + (int)(fQ * ((int)clrM.B - (int)clrL.B));
}
else
{
fQ = (fQ - 0.5f) * 2.0f;
iR = clrM.R + (int)(fQ * ((int)clrH.R - (int)clrM.R));
iG = clrM.G + (int)(fQ * ((int)clrH.G - (int)clrM.G));
iB = clrM.B + (int)(fQ * ((int)clrH.B - (int)clrM.B));
}
if(iR < 0) { Debug.Assert(false); iR = 0; }
if(iR > 255) { Debug.Assert(false); iR = 255; }
if(iG < 0) { Debug.Assert(false); iG = 0; }
if(iG > 255) { Debug.Assert(false); iG = 255; }
if(iB < 0) { Debug.Assert(false); iB = 0; }
if(iB > 255) { Debug.Assert(false); iB = 255; }
Color clrQ = Color.FromArgb(iR, iG, iB);
if(bToControlBack)
return UIUtil.ColorTowards(clrQ, AppDefs.ColorControlNormal, 0.5);
return clrQ;
}
internal static string GetKeyFileFilter()
{
return UIUtil.CreateFileTypeFilter(AppDefs.FileExtension.KeyFile +
"|" + AppDefs.FileExtension.KeyFileAlt, KPRes.KeyFiles, true);
}
}
}
|