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 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591
|
/*
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.ComponentModel;
using System.Diagnostics;
using System.Net;
using System.Xml.Serialization;
using KeePassLib.Delegates;
using KeePassLib.Interfaces;
using KeePassLib.Serialization;
namespace KeePassLib
{
/// <summary>
/// Contains KeePassLib-global definitions and enums.
/// </summary>
public static class PwDefs
{
/// <summary>
/// The product name.
/// </summary>
public static readonly string ProductName = "KeePass Password Safe";
/// <summary>
/// A short, simple string representing the product name. The string
/// should contain no spaces, directory separator characters, etc.
/// </summary>
public static readonly string ShortProductName = "KeePass";
internal const string UnixName = "keepass2";
internal const string ResClass = "KeePass2"; // With initial capital
/// <summary>
/// Version, encoded as 32-bit unsigned integer.
/// 2.00 = 0x02000000, 2.01 = 0x02000100, ..., 2.18 = 0x02010800.
/// As of 2.19, the version is encoded component-wise per byte,
/// e.g. 2.19 = 0x02130000.
/// It is highly recommended to use <c>FileVersion64</c> instead.
/// </summary>
public static readonly uint Version32 = 0x02390000;
/// <summary>
/// Version, encoded as 64-bit unsigned integer
/// (component-wise, 16 bits per component).
/// </summary>
public static readonly ulong FileVersion64 = 0x0002003900000000UL;
/// <summary>
/// Version, encoded as string.
/// </summary>
public static readonly string VersionString = "2.57";
public static readonly string Copyright = @"Copyright © 2003-2024 Dominik Reichl";
/// <summary>
/// Product website URL. Terminated by a forward slash.
/// </summary>
public static readonly string HomepageUrl = "https://keepass.info/";
/// <summary>
/// URL to the online translations page.
/// </summary>
public static readonly string TranslationsUrl = "https://keepass.info/translations.html";
/// <summary>
/// URL to the online plugins page.
/// </summary>
public static readonly string PluginsUrl = "https://keepass.info/plugins.html";
/// <summary>
/// Product donations URL.
/// </summary>
public static readonly string DonationsUrl = "https://keepass.info/donate.html";
/// <summary>
/// URL to the root path of the online KeePass help. Terminated by
/// a forward slash.
/// </summary>
public static readonly string HelpUrl = "https://keepass.info/help/";
/// <summary>
/// URL to a TXT file (eventually compressed) that contains information
/// about the latest KeePass version available on the website.
/// </summary>
public static readonly string VersionUrl = "https://www.dominik-reichl.de/update/version2x.txt.gz";
/// <summary>
/// A <c>DateTime</c> object that represents the time when the assembly
/// was loaded.
/// </summary>
public static readonly DateTime DtDefaultNow = DateTime.UtcNow;
/// <summary>
/// Default number of master key encryption/transformation rounds
/// (making dictionary attacks harder).
/// </summary>
public static readonly ulong DefaultKeyEncryptionRounds = 600000;
/// <summary>
/// Default identifier string for the title field.
/// Should not contain spaces, tabs or other whitespace.
/// </summary>
public const string TitleField = "Title";
// Const instead of static readonly for backward compatibility with plugins
/// <summary>
/// Default identifier string for the user name field.
/// Should not contain spaces, tabs or other whitespace.
/// </summary>
public const string UserNameField = "UserName";
// Const instead of static readonly for backward compatibility with plugins
/// <summary>
/// Default identifier string for the password field.
/// Should not contain spaces, tabs or other whitespace.
/// </summary>
public const string PasswordField = "Password";
// Const instead of static readonly for backward compatibility with plugins
/// <summary>
/// Default identifier string for the URL field.
/// Should not contain spaces, tabs or other whitespace.
/// </summary>
public const string UrlField = "URL";
// Const instead of static readonly for backward compatibility with plugins
/// <summary>
/// Default identifier string for the notes field.
/// Should not contain spaces, tabs or other whitespace.
/// </summary>
public const string NotesField = "Notes";
// Const instead of static readonly for backward compatibility with plugins
/// <summary>
/// Default identifier string for the field which will contain TAN indices.
/// </summary>
public static readonly string TanIndexField = UserNameField;
/// <summary>
/// Default title of an entry that is really a TAN entry.
/// </summary>
public static readonly string TanTitle = @"<TAN>";
/// <summary>
/// Prefix of a custom auto-type string field.
/// </summary>
public static readonly string AutoTypeStringPrefix = "S:";
/// <summary>
/// Default string representing a hidden password.
/// </summary>
public static readonly string HiddenPassword = "********";
/// <summary>
/// Default auto-type keystroke sequence. If no custom sequence is
/// specified, this sequence is used.
/// </summary>
public static readonly string DefaultAutoTypeSequence = @"{USERNAME}{TAB}{PASSWORD}{ENTER}";
/// <summary>
/// Default auto-type keystroke sequence for TAN entries. If no custom
/// sequence is specified, this sequence is used.
/// </summary>
public static readonly string DefaultAutoTypeSequenceTan = @"{PASSWORD}";
/// <summary>
/// Maximum time (in milliseconds) after which the user interface
/// should be updated.
/// </summary>
internal const int UIUpdateDelay = 50;
internal const uint QualityBitsWeak = 79;
internal const string FavoriteTag = "Favorite";
internal static bool DebugMode { get; set; } // Command line option '-debug'
/// <summary>
/// Check whether a name is a standard field name.
/// </summary>
public static bool IsStandardField(string strFieldName)
{
if(strFieldName == null) { Debug.Assert(false); return false; }
return ((strFieldName == TitleField) ||
(strFieldName == UserNameField) ||
(strFieldName == PasswordField) ||
(strFieldName == UrlField) ||
(strFieldName == NotesField));
}
public static List<string> GetStandardFields()
{
return new List<string>
{
TitleField, UserNameField, PasswordField, UrlField, NotesField
};
}
/// <summary>
/// Check whether an entry is a TAN entry.
/// </summary>
public static bool IsTanEntry(PwEntry pe)
{
if(pe == null) { Debug.Assert(false); return false; }
return (pe.Strings.ReadSafe(PwDefs.TitleField) == TanTitle);
}
internal static string GetTranslationDisplayVersion(string strFileVersion)
{
if(strFileVersion == null) { Debug.Assert(false); return string.Empty; }
if(strFileVersion == "2.39") return "2.39.1 / 2.39";
if(strFileVersion == "2.42") return "2.42.1 / 2.42";
if(strFileVersion == "2.48") return "2.48.1 / 2.48";
if(strFileVersion == "2.51") return "2.51.1 / 2.51";
return strFileVersion;
}
internal static PwIcon GroupIconToEntryIcon(PwIcon i)
{
PwIcon r = i; // Inherit by default
switch(i)
{
case PwIcon.Folder:
case PwIcon.FolderOpen:
case PwIcon.FolderPackage:
Debug.Assert((new PwEntry(false, false)).IconId == PwIcon.Key);
r = PwIcon.Key;
break;
case PwIcon.EMailBox:
r = PwIcon.EMail;
break;
default: break;
}
return r;
}
}
// #pragma warning disable 1591 // Missing XML comments warning
/// <summary>
/// Search parameters for group and entry searches.
/// </summary>
public sealed class SearchParameters
{
private string m_strName = string.Empty;
[DefaultValue("")]
public string Name
{
get { return m_strName; }
set
{
if(value == null) throw new ArgumentNullException("value");
m_strName = value;
}
}
private string m_strText = string.Empty;
[DefaultValue("")]
public string SearchString
{
get { return m_strText; }
set
{
if(value == null) throw new ArgumentNullException("value");
m_strText = value;
}
}
private PwSearchMode m_sm = PwSearchMode.Simple;
public PwSearchMode SearchMode
{
get { return m_sm; }
set { m_sm = value; }
}
[DefaultValue(false)]
[Obsolete]
[XmlIgnore]
public bool RegularExpression
{
get { return (m_sm == PwSearchMode.Regular); }
set { m_sm = (value ? PwSearchMode.Regular : PwSearchMode.Simple); }
}
private bool m_bSearchInTitles = true;
[DefaultValue(true)]
public bool SearchInTitles
{
get { return m_bSearchInTitles; }
set { m_bSearchInTitles = value; }
}
private bool m_bSearchInUserNames = true;
[DefaultValue(true)]
public bool SearchInUserNames
{
get { return m_bSearchInUserNames; }
set { m_bSearchInUserNames = value; }
}
private bool m_bSearchInPasswords = false;
[DefaultValue(false)]
public bool SearchInPasswords
{
get { return m_bSearchInPasswords; }
set { m_bSearchInPasswords = value; }
}
private bool m_bSearchInUrls = true;
[DefaultValue(true)]
public bool SearchInUrls
{
get { return m_bSearchInUrls; }
set { m_bSearchInUrls = value; }
}
private bool m_bSearchInNotes = true;
[DefaultValue(true)]
public bool SearchInNotes
{
get { return m_bSearchInNotes; }
set { m_bSearchInNotes = value; }
}
private bool m_bSearchInOther = true;
[DefaultValue(true)]
public bool SearchInOther
{
get { return m_bSearchInOther; }
set { m_bSearchInOther = value; }
}
private bool m_bSearchInStringNames = false;
[DefaultValue(false)]
public bool SearchInStringNames
{
get { return m_bSearchInStringNames; }
set { m_bSearchInStringNames = value; }
}
private bool m_bSearchInTags = true;
[DefaultValue(true)]
public bool SearchInTags
{
get { return m_bSearchInTags; }
set { m_bSearchInTags = value; }
}
private bool m_bSearchInUuids = false;
[DefaultValue(false)]
public bool SearchInUuids
{
get { return m_bSearchInUuids; }
set { m_bSearchInUuids = value; }
}
private bool m_bSearchInGroupPaths = false;
[DefaultValue(false)]
public bool SearchInGroupPaths
{
get { return m_bSearchInGroupPaths; }
set { m_bSearchInGroupPaths = value; }
}
private bool m_bSearchInGroupNames = false;
[DefaultValue(false)]
public bool SearchInGroupNames
{
get { return m_bSearchInGroupNames; }
set { m_bSearchInGroupNames = value; }
}
private bool m_bSearchInHistory = false;
[DefaultValue(false)]
public bool SearchInHistory
{
get { return m_bSearchInHistory; }
set { m_bSearchInHistory = value; }
}
#if KeePassUAP
private StringComparison m_scType = StringComparison.OrdinalIgnoreCase;
#else
private StringComparison m_scType = StringComparison.InvariantCultureIgnoreCase;
#endif
/// <summary>
/// String comparison type. Specifies the condition when the specified
/// text matches a group/entry string.
/// </summary>
public StringComparison ComparisonMode
{
get { return m_scType; }
set { m_scType = value; }
}
private bool m_bExcludeExpired = false;
[DefaultValue(false)]
public bool ExcludeExpired
{
get { return m_bExcludeExpired; }
set { m_bExcludeExpired = value; }
}
private bool m_bRespectEntrySearchingDisabled = true;
[DefaultValue(true)]
public bool RespectEntrySearchingDisabled
{
get { return m_bRespectEntrySearchingDisabled; }
set { m_bRespectEntrySearchingDisabled = value; }
}
private StrPwEntryDelegate m_fnDataTrf = null;
[XmlIgnore]
public StrPwEntryDelegate DataTransformationFn
{
get { return m_fnDataTrf; }
set { m_fnDataTrf = value; }
}
private string m_strDataTrf = string.Empty;
/// <summary>
/// Only for serialization.
/// </summary>
[DefaultValue("")]
public string DataTransformation
{
get { return m_strDataTrf; }
set
{
if(value == null) throw new ArgumentNullException("value");
m_strDataTrf = value;
}
}
[XmlIgnore]
public static SearchParameters None
{
get
{
SearchParameters sp = new SearchParameters();
Debug.Assert(sp.m_strName.Length == 0);
Debug.Assert(sp.m_strText.Length == 0);
Debug.Assert(sp.m_sm == PwSearchMode.Simple);
sp.m_bSearchInTitles = false;
sp.m_bSearchInUserNames = false;
Debug.Assert(!sp.m_bSearchInPasswords);
sp.m_bSearchInUrls = false;
sp.m_bSearchInNotes = false;
sp.m_bSearchInOther = false;
Debug.Assert(!sp.m_bSearchInStringNames);
sp.m_bSearchInTags = false;
Debug.Assert(!sp.m_bSearchInUuids);
Debug.Assert(!sp.m_bSearchInGroupPaths);
Debug.Assert(!sp.m_bSearchInGroupNames);
Debug.Assert(!sp.m_bSearchInHistory);
// Debug.Assert(sp.m_scType == StringComparison.InvariantCultureIgnoreCase);
Debug.Assert(!sp.m_bExcludeExpired);
Debug.Assert(sp.m_bRespectEntrySearchingDisabled);
return sp;
}
}
/// <summary>
/// Construct a new search parameters object.
/// </summary>
public SearchParameters()
{
}
public SearchParameters Clone()
{
return (SearchParameters)this.MemberwiseClone();
}
}
// #pragma warning restore 1591 // Missing XML comments warning
// #pragma warning disable 1591 // Missing XML comments warning
/// <summary>
/// Memory protection configuration structure (for default fields).
/// </summary>
public sealed class MemoryProtectionConfig : IDeepCloneable<MemoryProtectionConfig>
{
public bool ProtectTitle = false;
public bool ProtectUserName = false;
public bool ProtectPassword = true;
public bool ProtectUrl = false;
public bool ProtectNotes = false;
// public bool AutoEnableVisualHiding = false;
public MemoryProtectionConfig CloneDeep()
{
return (MemoryProtectionConfig)this.MemberwiseClone();
}
public bool GetProtection(string strField)
{
if(strField == PwDefs.TitleField) return this.ProtectTitle;
if(strField == PwDefs.UserNameField) return this.ProtectUserName;
if(strField == PwDefs.PasswordField) return this.ProtectPassword;
if(strField == PwDefs.UrlField) return this.ProtectUrl;
if(strField == PwDefs.NotesField) return this.ProtectNotes;
return false;
}
}
// #pragma warning restore 1591 // Missing XML comments warning
public sealed class ObjectTouchedEventArgs : EventArgs
{
private readonly object m_o;
public object Object { get { return m_o; } }
private readonly bool m_bModified;
public bool Modified { get { return m_bModified; } }
private readonly bool m_bParentsTouched;
public bool ParentsTouched { get { return m_bParentsTouched; } }
public ObjectTouchedEventArgs(object o, bool bModified,
bool bParentsTouched)
{
m_o = o;
m_bModified = bModified;
m_bParentsTouched = bParentsTouched;
}
}
public sealed class IOAccessEventArgs : EventArgs
{
private readonly IOConnectionInfo m_ioc;
public IOConnectionInfo IOConnectionInfo { get { return m_ioc; } }
private readonly IOConnectionInfo m_ioc2;
public IOConnectionInfo IOConnectionInfo2 { get { return m_ioc2; } }
private readonly IOAccessType m_t;
public IOAccessType Type { get { return m_t; } }
public IOAccessEventArgs(IOConnectionInfo ioc, IOConnectionInfo ioc2,
IOAccessType t)
{
m_ioc = ioc;
m_ioc2 = ioc2;
m_t = t;
}
}
public sealed class IOWebRequestEventArgs : EventArgs
{
private readonly WebRequest m_wr;
public WebRequest Request { get { return m_wr; } }
private readonly IOConnectionInfo m_ioc;
public IOConnectionInfo IOConnectionInfo { get { return m_ioc; } }
public IOWebRequestEventArgs(WebRequest r, IOConnectionInfo ioc)
{
m_wr = r;
m_ioc = ioc;
}
}
}
|