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
|
/*
KeePass Password Safe - The Open-Source Password Manager
Copyright (C) 2003-2019 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.Text;
using System.Windows.Forms;
using System.Xml.Serialization;
using KeePassLib;
using KeePassLib.Interfaces;
using KeePassLib.Utility;
namespace KeePass.App.Configuration
{
public sealed class AceIntegration
{
private ulong m_hkAutoType = (ulong)(Keys.Control | Keys.Alt | Keys.A);
public ulong HotKeyGlobalAutoType
{
get { return m_hkAutoType; }
set { m_hkAutoType = value; }
}
private ulong m_hkAutoTypeSel = (ulong)Keys.None;
public ulong HotKeySelectedAutoType
{
get { return m_hkAutoTypeSel; }
set { m_hkAutoTypeSel = value; }
}
private ulong m_hkShowWindow = (ulong)(Keys.Control | Keys.Alt | Keys.K);
public ulong HotKeyShowWindow
{
get { return m_hkShowWindow; }
set { m_hkShowWindow = value; }
}
private ulong m_hkEntryMenu = (ulong)Keys.None;
public ulong HotKeyEntryMenu
{
get { return m_hkEntryMenu; }
set { m_hkEntryMenu = value; }
}
private bool m_bCheckHotKeys = true;
[DefaultValue(true)]
public bool CheckHotKeys
{
get { return m_bCheckHotKeys; }
set { m_bCheckHotKeys = value; }
}
private string m_strUrlOverride = string.Empty;
[DefaultValue("")]
public string UrlOverride
{
get { return m_strUrlOverride; }
set
{
if(value == null) throw new ArgumentNullException("value");
m_strUrlOverride = value;
}
}
private AceUrlSchemeOverrides m_vSchemeOverrides = new AceUrlSchemeOverrides();
public AceUrlSchemeOverrides UrlSchemeOverrides
{
get { return m_vSchemeOverrides; }
set
{
if(value == null) throw new ArgumentNullException("value");
m_vSchemeOverrides = value;
}
}
private bool m_bSearchKeyFiles = true;
[DefaultValue(true)]
public bool SearchKeyFiles
{
get { return m_bSearchKeyFiles; }
set { m_bSearchKeyFiles = value; }
}
private bool m_bSearchKeyFilesOnRemovable = false;
[DefaultValue(false)]
public bool SearchKeyFilesOnRemovableMedia
{
get { return m_bSearchKeyFilesOnRemovable; }
set { m_bSearchKeyFilesOnRemovable = value; }
}
private bool m_bSingleInstance = true;
[DefaultValue(true)]
public bool LimitToSingleInstance
{
get { return m_bSingleInstance; }
set { m_bSingleInstance = value; }
}
private bool m_bMatchByTitle = true;
[DefaultValue(true)]
public bool AutoTypeMatchByTitle
{
get { return m_bMatchByTitle; }
set { m_bMatchByTitle = value; }
}
private bool m_bMatchByUrlInTitle = false;
[DefaultValue(false)]
public bool AutoTypeMatchByUrlInTitle
{
get { return m_bMatchByUrlInTitle; }
set { m_bMatchByUrlInTitle = value; }
}
private bool m_bMatchByUrlHostInTitle = false;
[DefaultValue(false)]
public bool AutoTypeMatchByUrlHostInTitle
{
get { return m_bMatchByUrlHostInTitle; }
set { m_bMatchByUrlHostInTitle = value; }
}
private bool m_bMatchByTagInTitle = false;
[DefaultValue(false)]
public bool AutoTypeMatchByTagInTitle
{
get { return m_bMatchByTagInTitle; }
set { m_bMatchByTagInTitle = value; }
}
private bool m_bExpiredCanMatch = false;
[DefaultValue(false)]
public bool AutoTypeExpiredCanMatch
{
get { return m_bExpiredCanMatch; }
set { m_bExpiredCanMatch = value; }
}
private bool m_bAutoTypeAlwaysShowSelDlg = false;
[DefaultValue(false)]
public bool AutoTypeAlwaysShowSelDialog
{
get { return m_bAutoTypeAlwaysShowSelDlg; }
set { m_bAutoTypeAlwaysShowSelDlg = value; }
}
private bool m_bPrependInitSeqIE = true;
[DefaultValue(true)]
public bool AutoTypePrependInitSequenceForIE
{
get { return m_bPrependInitSeqIE; }
set { m_bPrependInitSeqIE = value; }
}
private bool m_bSpecialReleaseAlt = true;
[DefaultValue(true)]
public bool AutoTypeReleaseAltWithKeyPress
{
get { return m_bSpecialReleaseAlt; }
set { m_bSpecialReleaseAlt = value; }
}
private bool m_bAdjustKeybLayout = true;
[DefaultValue(true)]
public bool AutoTypeAdjustKeyboardLayout
{
get { return m_bAdjustKeybLayout; }
set { m_bAdjustKeybLayout = value; }
}
private bool m_bAllowInterleaved = false;
[DefaultValue(false)]
public bool AutoTypeAllowInterleaved
{
get { return m_bAllowInterleaved; }
set { m_bAllowInterleaved = value; }
}
private bool m_bCancelOnWindowChange = false;
[DefaultValue(false)]
public bool AutoTypeCancelOnWindowChange
{
get { return m_bCancelOnWindowChange; }
set { m_bCancelOnWindowChange = value; }
}
private bool m_bCancelOnTitleChange = false;
[DefaultValue(false)]
public bool AutoTypeCancelOnTitleChange
{
get { return m_bCancelOnTitleChange; }
set { m_bCancelOnTitleChange = value; }
}
private int m_iInterKeyDelay = -1;
[DefaultValue(-1)]
public int AutoTypeInterKeyDelay
{
get { return m_iInterKeyDelay; }
set { m_iInterKeyDelay = value; }
}
private List<string> m_lAbortWindows = new List<string>();
[XmlArrayItem("Window")]
public List<string> AutoTypeAbortOnWindows
{
get { return m_lAbortWindows; }
set
{
if(value == null) throw new ArgumentNullException("value");
m_lAbortWindows = value;
}
}
private ProxyServerType m_pstProxyType = ProxyServerType.System;
[DefaultValue(ProxyServerType.System)]
public ProxyServerType ProxyType
{
get { return m_pstProxyType; }
set { m_pstProxyType = value; }
}
private string m_strProxyAddr = string.Empty;
[DefaultValue("")]
public string ProxyAddress
{
get { return m_strProxyAddr; }
set
{
if(value == null) throw new ArgumentNullException("value");
m_strProxyAddr = value;
}
}
private string m_strProxyPort = string.Empty;
[DefaultValue("")]
public string ProxyPort
{
get { return m_strProxyPort; }
set
{
if(value == null) throw new ArgumentNullException("value");
m_strProxyPort = value;
}
}
private ProxyAuthType m_pstProxyAuthType = ProxyAuthType.Auto;
[DefaultValue(ProxyAuthType.Auto)]
public ProxyAuthType ProxyAuthType
{
get { return m_pstProxyAuthType; }
set { m_pstProxyAuthType = value; }
}
private string m_strProxyUser = string.Empty;
[DefaultValue("")]
public string ProxyUserName
{
get { return m_strProxyUser; }
set
{
if(value == null) throw new ArgumentNullException("value");
m_strProxyUser = value;
}
}
private string m_strProxyPassword = string.Empty;
[DefaultValue("")]
public string ProxyPassword
{
get { return m_strProxyPassword; }
set
{
if(value == null) throw new ArgumentNullException("value");
m_strProxyPassword = value;
}
}
public AceIntegration()
{
}
}
public sealed class AceUrlSchemeOverrides : IDeepCloneable<AceUrlSchemeOverrides>
{
private List<AceUrlSchemeOverride> m_lBuiltInOverrides =
new List<AceUrlSchemeOverride>();
[XmlIgnore]
public List<AceUrlSchemeOverride> BuiltInOverrides
{
get { return m_lBuiltInOverrides; }
set
{
if(value == null) throw new ArgumentNullException("value");
m_lBuiltInOverrides = value;
}
}
public ulong BuiltInOverridesEnabled
{
get { return GetEnabledBuiltInOverrides(); }
set { SetEnabledBuiltInOverrides(value); }
}
private List<AceUrlSchemeOverride> m_lCustomOverrides =
new List<AceUrlSchemeOverride>();
[XmlArrayItem("Override")]
public List<AceUrlSchemeOverride> CustomOverrides
{
get { return m_lCustomOverrides; }
set
{
if(value == null) throw new ArgumentNullException("value");
m_lCustomOverrides = value;
}
}
public AceUrlSchemeOverrides()
{
MakeBuiltInList();
}
private void MakeBuiltInList()
{
m_lBuiltInOverrides.Clear();
m_lBuiltInOverrides.Add(new AceUrlSchemeOverride(true, "ssh",
@"cmd://PuTTY.exe -ssh {USERNAME}@{BASE:RMVSCM}", 0x1));
m_lBuiltInOverrides.Add(new AceUrlSchemeOverride(false, "http",
"cmd://{INTERNETEXPLORER} \"{BASE}\"", 0x2));
m_lBuiltInOverrides.Add(new AceUrlSchemeOverride(false, "https",
"cmd://{INTERNETEXPLORER} \"{BASE}\"", 0x4));
m_lBuiltInOverrides.Add(new AceUrlSchemeOverride(false, "http",
"cmd://{INTERNETEXPLORER} -private \"{BASE}\"", 0x10000));
m_lBuiltInOverrides.Add(new AceUrlSchemeOverride(false, "https",
"cmd://{INTERNETEXPLORER} -private \"{BASE}\"", 0x20000));
m_lBuiltInOverrides.Add(new AceUrlSchemeOverride(false, "http",
"microsoft-edge:{BASE}", 0x4000));
m_lBuiltInOverrides.Add(new AceUrlSchemeOverride(false, "https",
"microsoft-edge:{BASE}", 0x8000));
m_lBuiltInOverrides.Add(new AceUrlSchemeOverride(false, "http",
"cmd://{FIREFOX} \"{BASE}\"", 0x8));
m_lBuiltInOverrides.Add(new AceUrlSchemeOverride(false, "https",
"cmd://{FIREFOX} \"{BASE}\"", 0x10));
m_lBuiltInOverrides.Add(new AceUrlSchemeOverride(false, "http",
"cmd://{FIREFOX} -private-window \"{BASE}\"", 0x100000));
m_lBuiltInOverrides.Add(new AceUrlSchemeOverride(false, "https",
"cmd://{FIREFOX} -private-window \"{BASE}\"", 0x200000));
m_lBuiltInOverrides.Add(new AceUrlSchemeOverride(false, "chrome",
"cmd://{FIREFOX} -chrome \"{BASE}\"", 0x20));
m_lBuiltInOverrides.Add(new AceUrlSchemeOverride(false, "http",
"cmd://{GOOGLECHROME} \"{BASE}\"", 0x100));
m_lBuiltInOverrides.Add(new AceUrlSchemeOverride(false, "https",
"cmd://{GOOGLECHROME} \"{BASE}\"", 0x200));
m_lBuiltInOverrides.Add(new AceUrlSchemeOverride(false, "http",
"cmd://{GOOGLECHROME} --incognito \"{BASE}\"", 0x40000));
m_lBuiltInOverrides.Add(new AceUrlSchemeOverride(false, "https",
"cmd://{GOOGLECHROME} --incognito \"{BASE}\"", 0x80000));
m_lBuiltInOverrides.Add(new AceUrlSchemeOverride(false, "http",
"cmd://{OPERA} \"{BASE}\"", 0x40));
m_lBuiltInOverrides.Add(new AceUrlSchemeOverride(false, "https",
"cmd://{OPERA} \"{BASE}\"", 0x80));
m_lBuiltInOverrides.Add(new AceUrlSchemeOverride(false, "http",
"cmd://{OPERA} --private \"{BASE}\"", 0x400000));
m_lBuiltInOverrides.Add(new AceUrlSchemeOverride(false, "https",
"cmd://{OPERA} --private \"{BASE}\"", 0x800000));
m_lBuiltInOverrides.Add(new AceUrlSchemeOverride(false, "http",
"cmd://{SAFARI} \"{BASE}\"", 0x400));
m_lBuiltInOverrides.Add(new AceUrlSchemeOverride(false, "https",
"cmd://{SAFARI} \"{BASE}\"", 0x800));
m_lBuiltInOverrides.Add(new AceUrlSchemeOverride(false, "kdbx",
"cmd://\"{APPDIR}\\KeePass.exe\" \"{BASE:RMVSCM}\" -pw-enc:\"{PASSWORD_ENC}\"", 0x1000));
m_lBuiltInOverrides.Add(new AceUrlSchemeOverride(false, "kdbx",
"cmd://mono \"{APPDIR}/KeePass.exe\" \"{BASE:RMVSCM}\" -pw-enc:\"{PASSWORD_ENC}\"", 0x2000));
// Free: 0x1000000
#if DEBUG
ulong u = 0;
foreach(AceUrlSchemeOverride o in m_lBuiltInOverrides)
{
Debug.Assert(o.IsBuiltIn);
ulong f = o.BuiltInFlagID;
Debug.Assert((f != 0) && ((f & (f - 1)) == 0)); // Check power of 2
u += f;
}
Debug.Assert(u == ((1UL << m_lBuiltInOverrides.Count) - 1UL));
#endif
}
public string GetOverrideForUrl(string strUrl)
{
if(string.IsNullOrEmpty(strUrl)) return null;
for(int i = 0; i < 2; ++i)
{
List<AceUrlSchemeOverride> l = ((i == 0) ? m_lBuiltInOverrides :
m_lCustomOverrides);
foreach(AceUrlSchemeOverride ovr in l)
{
if(!ovr.Enabled) continue;
if(strUrl.StartsWith(ovr.Scheme + ":", StrUtil.CaseIgnoreCmp))
return ovr.UrlOverride;
}
}
return null;
}
public AceUrlSchemeOverrides CloneDeep()
{
AceUrlSchemeOverrides ovr = new AceUrlSchemeOverrides();
CopyTo(ovr);
return ovr;
}
public void CopyTo(AceUrlSchemeOverrides ovrTarget)
{
ovrTarget.m_lBuiltInOverrides.Clear();
foreach(AceUrlSchemeOverride shB in m_lBuiltInOverrides)
{
ovrTarget.m_lBuiltInOverrides.Add(shB.CloneDeep());
}
ovrTarget.m_lCustomOverrides.Clear();
foreach(AceUrlSchemeOverride shC in m_lCustomOverrides)
{
ovrTarget.m_lCustomOverrides.Add(shC.CloneDeep());
}
}
public ulong GetEnabledBuiltInOverrides()
{
ulong u = 0;
for(int i = 0; i < m_lBuiltInOverrides.Count; ++i)
{
if(m_lBuiltInOverrides[i].Enabled)
u |= m_lBuiltInOverrides[i].BuiltInFlagID;
}
return u;
}
public void SetEnabledBuiltInOverrides(ulong uFlags)
{
for(int i = 0; i < m_lBuiltInOverrides.Count; ++i)
m_lBuiltInOverrides[i].Enabled = ((uFlags &
m_lBuiltInOverrides[i].BuiltInFlagID) != 0UL);
}
}
public sealed class AceUrlSchemeOverride : IDeepCloneable<AceUrlSchemeOverride>
{
private bool m_bEnabled = true;
public bool Enabled
{
get { return m_bEnabled; }
set { m_bEnabled = value; }
}
private string m_strScheme = string.Empty;
public string Scheme
{
get { return m_strScheme; }
set
{
if(value == null) throw new ArgumentNullException("value");
m_strScheme = value;
}
}
private string m_strOvr = string.Empty;
public string UrlOverride
{
get { return m_strOvr; }
set
{
if(value == null) throw new ArgumentNullException("value");
m_strOvr = value;
}
}
private ulong m_uBuiltInFlagID = 0;
[XmlIgnore]
internal ulong BuiltInFlagID
{
get { return m_uBuiltInFlagID; }
}
[XmlIgnore]
public bool IsBuiltIn
{
get { return (m_uBuiltInFlagID != 0UL); }
}
public AceUrlSchemeOverride()
{
}
public AceUrlSchemeOverride(bool bEnable, string strScheme,
string strUrlOverride)
{
Init(bEnable, strScheme, strUrlOverride, 0);
}
internal AceUrlSchemeOverride(bool bEnable, string strScheme,
string strUrlOverride, ulong uBuiltInFlagID)
{
Init(bEnable, strScheme, strUrlOverride, uBuiltInFlagID);
}
private void Init(bool bEnable, string strScheme, string strUrlOverride,
ulong uBuiltInFlagID)
{
if(strScheme == null) throw new ArgumentNullException("strScheme");
if(strUrlOverride == null) throw new ArgumentNullException("strUrlOverride");
m_bEnabled = bEnable;
m_strScheme = strScheme;
m_strOvr = strUrlOverride;
m_uBuiltInFlagID = uBuiltInFlagID;
}
public AceUrlSchemeOverride CloneDeep()
{
return new AceUrlSchemeOverride(m_bEnabled, m_strScheme,
m_strOvr, m_uBuiltInFlagID);
}
}
}
|