Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for HTTPS and reading from remote networks #165

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified KeePassHttp.plgx
Binary file not shown.
193 changes: 110 additions & 83 deletions KeePassHttp/ConfigOpt.cs
Original file line number Diff line number Diff line change
@@ -1,84 +1,111 @@
using KeePass.App.Configuration;

namespace KeePassHttp
{
public class ConfigOpt
{
readonly AceCustomConfig _config;
const string ReceiveCredentialNotificationKey = "KeePassHttp_ReceiveCredentialNotification";
const string SpecificMatchingOnlyKey = "KeePassHttp_SpecificMatchingOnly";
const string UnlockDatabaseRequestKey = "KeePassHttp_UnlockDatabaseRequest";
const string AlwaysAllowAccessKey = "KeePassHttp_AlwaysAllowAccess";
const string AlwaysAllowUpdatesKey = "KeePassHttp_AlwaysAllowUpdates";
const string SearchInAllOpenedDatabasesKey = "KeePassHttp_SearchInAllOpenedDatabases";
const string MatchSchemesKey = "KeePassHttp_MatchSchemes";
const string ReturnStringFieldsKey = "KeePassHttp_ReturnStringFields";
const string SortResultByUsernameKey = "KeePassHttp_SortResultByUsername";
const string ListenerPortKey = "KeePassHttp_ListenerPort";

public ConfigOpt(AceCustomConfig config)
{
_config = config;
}

public bool ReceiveCredentialNotification
{
get { return _config.GetBool(ReceiveCredentialNotificationKey, true); }
set { _config.SetBool(ReceiveCredentialNotificationKey, value); }
}

public bool UnlockDatabaseRequest
{
get { return _config.GetBool(UnlockDatabaseRequestKey, false); }
set { _config.SetBool(UnlockDatabaseRequestKey, value); }
}

public bool SpecificMatchingOnly
{
get { return _config.GetBool(SpecificMatchingOnlyKey, false); }
set { _config.SetBool(SpecificMatchingOnlyKey, value); }
}

public bool AlwaysAllowAccess
{
get { return _config.GetBool(AlwaysAllowAccessKey, false); }
set { _config.SetBool(AlwaysAllowAccessKey, value); }
}

public bool AlwaysAllowUpdates
{
get { return _config.GetBool(AlwaysAllowUpdatesKey, false); }
set { _config.SetBool(AlwaysAllowUpdatesKey, value); }
}

public bool SearchInAllOpenedDatabases
{
get { return _config.GetBool(SearchInAllOpenedDatabasesKey, false); }
set { _config.SetBool(SearchInAllOpenedDatabasesKey, value); }
}

public bool MatchSchemes
{
get { return _config.GetBool(MatchSchemesKey, false); }
set { _config.SetBool(MatchSchemesKey, value); }
}

public bool ReturnStringFields
{
get { return _config.GetBool(ReturnStringFieldsKey, false); }
set { _config.SetBool(ReturnStringFieldsKey, value); }
}

public bool SortResultByUsername
{
get { return _config.GetBool(SortResultByUsernameKey, true); }
set { _config.SetBool(SortResultByUsernameKey, value); }
}

public long ListenerPort
{
get { return _config.GetLong(ListenerPortKey, KeePassHttpExt.DEFAULT_PORT); }
set { _config.SetLong(ListenerPortKey, value); }
}
}
using KeePass.App.Configuration;

namespace KeePassHttp
{
public class ConfigOpt
{
readonly AceCustomConfig _config;
const string ReceiveCredentialNotificationKey = "KeePassHttp_ReceiveCredentialNotification";
const string SpecificMatchingOnlyKey = "KeePassHttp_SpecificMatchingOnly";
const string UnlockDatabaseRequestKey = "KeePassHttp_UnlockDatabaseRequest";
const string AlwaysAllowAccessKey = "KeePassHttp_AlwaysAllowAccess";
const string AlwaysAllowUpdatesKey = "KeePassHttp_AlwaysAllowUpdates";
const string SearchInAllOpenedDatabasesKey = "KeePassHttp_SearchInAllOpenedDatabases";
const string MatchSchemesKey = "KeePassHttp_MatchSchemes";
const string ReturnStringFieldsKey = "KeePassHttp_ReturnStringFields";
const string SortResultByUsernameKey = "KeePassHttp_SortResultByUsername";
const string ListenerHostHttpKey = "KeePassHttp_ListenerHostHttp";
const string ListenerPortHttpKey = "KeePassHttp_ListenerPortHttp";
const string ActivateHttpsListenerKey = "KeePassHttp_ActivateHttpsListener";
const string ListenerHostHttpsKey = "KeePassHttp_ListenerHostHttps";
const string ListenerPortHttpsKey = "KeePassHttp_ListenerPortHttps";

public ConfigOpt(AceCustomConfig config)
{
_config = config;
}

public bool ReceiveCredentialNotification
{
get { return _config.GetBool(ReceiveCredentialNotificationKey, true); }
set { _config.SetBool(ReceiveCredentialNotificationKey, value); }
}

public bool UnlockDatabaseRequest
{
get { return _config.GetBool(UnlockDatabaseRequestKey, false); }
set { _config.SetBool(UnlockDatabaseRequestKey, value); }
}

public bool SpecificMatchingOnly
{
get { return _config.GetBool(SpecificMatchingOnlyKey, false); }
set { _config.SetBool(SpecificMatchingOnlyKey, value); }
}

public bool AlwaysAllowAccess
{
get { return _config.GetBool(AlwaysAllowAccessKey, false); }
set { _config.SetBool(AlwaysAllowAccessKey, value); }
}

public bool AlwaysAllowUpdates
{
get { return _config.GetBool(AlwaysAllowUpdatesKey, false); }
set { _config.SetBool(AlwaysAllowUpdatesKey, value); }
}

public bool SearchInAllOpenedDatabases
{
get { return _config.GetBool(SearchInAllOpenedDatabasesKey, false); }
set { _config.SetBool(SearchInAllOpenedDatabasesKey, value); }
}

public bool MatchSchemes
{
get { return _config.GetBool(MatchSchemesKey, false); }
set { _config.SetBool(MatchSchemesKey, value); }
}

public bool ReturnStringFields
{
get { return _config.GetBool(ReturnStringFieldsKey, false); }
set { _config.SetBool(ReturnStringFieldsKey, value); }
}

public bool SortResultByUsername
{
get { return _config.GetBool(SortResultByUsernameKey, true); }
set { _config.SetBool(SortResultByUsernameKey, value); }
}

public string ListenerHostHttp {
get { return _config.GetString(ListenerHostHttpKey, KeePassHttpExt.DEFAULT_HOST); }
set { _config.SetString(ListenerHostHttpKey, value); }
}

public long ListenerPortHttp
{
get { return _config.GetLong(ListenerPortHttpKey, KeePassHttpExt.DEFAULT_PORT_HTTP); }
set { _config.SetLong(ListenerPortHttpKey, value); }
}

public bool ActivateHttpsListener
{
get { return _config.GetBool(ActivateHttpsListenerKey, false); }
set { _config.SetBool(ActivateHttpsListenerKey, value); }
}

public string ListenerHostHttps
{
get { return _config.GetString(ListenerHostHttpsKey, KeePassHttpExt.DEFAULT_HOST); }
set { _config.SetString(ListenerHostHttpsKey, value); }
}

public long ListenerPortHttps
{
get { return _config.GetLong(ListenerPortHttpsKey, KeePassHttpExt.DEFAULT_PORT_HTTPS); }
set { _config.SetLong(ListenerPortHttpsKey, value); }
}
}
}
31 changes: 19 additions & 12 deletions KeePassHttp/KeePassHttp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,17 @@ public sealed partial class KeePassHttpExt : Plugin
public const string ASSOCIATE_KEY_PREFIX = "AES Key: ";
private IPluginHost host;
private HttpListener listener;
public const int DEFAULT_PORT = 19455;
/// <summary>
/// TODO make configurable
/// </summary>
private int port = DEFAULT_PORT;
private const string HTTP_PREFIX = "http://localhost:";
//private const string HTTPS_PREFIX = "https://localhost:";
//private int HTTPS_PORT = DEFAULT_PORT + 1;
public const int DEFAULT_PORT_HTTP = 19455;
public const int DEFAULT_PORT_HTTPS = 19456;
public const string DEFAULT_HOST = "localhost";
private const string HTTP_PREFIX = "http://";
private const string HTTPS_PREFIX = "https://";
private Thread httpThread;
private volatile bool stopped = false;
Dictionary<string, RequestHandler> handlers = new Dictionary<string, RequestHandler>();

//public string UpdateUrl = "";
public override string UpdateUrl { get { return "https://passifox.appspot.com/kph/latest-version.txt"; } }
public override string UpdateUrl { get { return "https://raw.githubusercontent.com/mheese/keepasshttp/master/latest-version.txt"; } }

private SearchParameters MakeSearchParameters()
{
Expand Down Expand Up @@ -198,9 +195,19 @@ public override bool Initialize(IPluginHost host)
listener = new HttpListener();

var configOpt = new ConfigOpt(this.host.CustomConfig);

listener.Prefixes.Add(HTTP_PREFIX + configOpt.ListenerPort.ToString() + "/");
//listener.Prefixes.Add(HTTPS_PREFIX + HTTPS_PORT + "/");
listener.Prefixes.Add(HTTP_PREFIX + configOpt.ListenerHostHttp + ":" + configOpt.ListenerPortHttp.ToString() + "/");
if (configOpt.ListenerHostHttp != DEFAULT_HOST)
{
listener.Prefixes.Add(HTTP_PREFIX + DEFAULT_HOST + ":" + configOpt.ListenerPortHttp.ToString() + "/");
}
if (configOpt.ActivateHttpsListener)
{
listener.Prefixes.Add(HTTPS_PREFIX + configOpt.ListenerHostHttps + ":" + configOpt.ListenerPortHttps.ToString() + "/");
if (configOpt.ListenerHostHttps != DEFAULT_HOST)
{
listener.Prefixes.Add(HTTPS_PREFIX + DEFAULT_HOST + ":" + configOpt.ListenerPortHttps.ToString() + "/");
}
}
listener.Start();

httpThread = new Thread(new ThreadStart(Run));
Expand Down
Loading