From f01bf10dc511268ead551a191a6a3211c006ba44 Mon Sep 17 00:00:00 2001 From: Orochimarufan Date: Sun, 24 Feb 2013 18:22:35 +0100 Subject: Implement Keyring system base --- libsettings/src/keyring.cpp | 63 +++++++++++++++++++++++++++ libsettings/src/stubkeyring.cpp | 96 +++++++++++++++++++++++++++++++++++++++++ libsettings/src/stubkeyring.h | 42 ++++++++++++++++++ 3 files changed, 201 insertions(+) create mode 100644 libsettings/src/keyring.cpp create mode 100644 libsettings/src/stubkeyring.cpp create mode 100644 libsettings/src/stubkeyring.h (limited to 'libsettings/src') diff --git a/libsettings/src/keyring.cpp b/libsettings/src/keyring.cpp new file mode 100644 index 00000000..1b13e35c --- /dev/null +++ b/libsettings/src/keyring.cpp @@ -0,0 +1,63 @@ +/* Copyright 2013 MultiMC Contributors + * + * Authors: Orochimarufan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "include/keyring.h" + +#include "osutils.h" + +#include "stubkeyring.h" + +// system specific keyrings +/*#if defined(OSX) +class OSXKeychain; +#define KEYRING OSXKeychain +#elif defined(LINUX) +class XDGKeyring; +#define KEYRING XDGKeyring +#elif defined(WINDOWS) +class Win32Keystore; +#define KEYRING Win32Keystore +#else +#pragma message Keyrings are not supported on your os. Falling back to the insecure StubKeyring +#endif*/ + +Keyring *Keyring::instance() +{ + if (m_instance == nullptr) + { +#ifdef KEYRING + m_instance = new KEYRING(); + if (!m_instance->isValid()) + { + qWarning("Could not create SystemKeyring! falling back to StubKeyring."); + m_instance = new StubKeyring(); + } +#else + qWarning("Keyrings are not supported on your OS. Fallback StubKeyring is insecure!"); + m_instance = new StubKeyring(); +#endif + atexit(Keyring::destroy); + } + return m_instance; +} + +void Keyring::destroy() +{ + delete m_instance; +} + +Keyring *Keyring::m_instance; diff --git a/libsettings/src/stubkeyring.cpp b/libsettings/src/stubkeyring.cpp new file mode 100644 index 00000000..0e29d2f2 --- /dev/null +++ b/libsettings/src/stubkeyring.cpp @@ -0,0 +1,96 @@ +/* Copyright 2013 MultiMC Contributors + * + * Authors: Orochimarufan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stubkeyring.h" + +#include + +// Scrambling +// this is NOT SAFE, but it's not plain either. +int scrambler = 0x9586309; + +QString scramble(QString in_) +{ + QByteArray in = in_.toUtf8(); + QByteArray out; + for (int i = 0; i + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef STUBKEYRING_H +#define STUBKEYRING_H + +#include "include/keyring.h" + +#include + +class StubKeyring : public Keyring +{ + Q_OBJECT +public: + virtual bool storePassword(QString service, QString username, QString password); + virtual QString getPassword(QString service, QString username); + virtual bool hasPassword(QString service, QString username); + virtual QStringList getStoredAccounts(QString service); + +private: + friend class Keyring; + explicit StubKeyring(); + virtual bool isValid() { return true; } + + QSettings m_settings; +}; + +#endif // STUBKEYRING_H -- cgit v1.2.3 From f4c9cb8c1d395422b7e4f1c27ac92b6df08a39bb Mon Sep 17 00:00:00 2001 From: Orochimarufan Date: Mon, 25 Feb 2013 22:47:03 +0100 Subject: refactor indendation, fix a bug in MinecraftProcess & fix a bug in InstanceLauncher --- libsettings/src/keyring.cpp | 30 ++++++++++---------- libsettings/src/stubkeyring.cpp | 62 ++++++++++++++++++++--------------------- libsettings/src/stubkeyring.h | 20 ++++++------- 3 files changed, 56 insertions(+), 56 deletions(-) (limited to 'libsettings/src') diff --git a/libsettings/src/keyring.cpp b/libsettings/src/keyring.cpp index 1b13e35c..9eaba684 100644 --- a/libsettings/src/keyring.cpp +++ b/libsettings/src/keyring.cpp @@ -6,7 +6,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -37,27 +37,27 @@ class Win32Keystore; Keyring *Keyring::instance() { - if (m_instance == nullptr) - { + if (m_instance == nullptr) + { #ifdef KEYRING - m_instance = new KEYRING(); - if (!m_instance->isValid()) - { - qWarning("Could not create SystemKeyring! falling back to StubKeyring."); - m_instance = new StubKeyring(); - } + m_instance = new KEYRING(); + if (!m_instance->isValid()) + { + qWarning("Could not create SystemKeyring! falling back to StubKeyring."); + m_instance = new StubKeyring(); + } #else - qWarning("Keyrings are not supported on your OS. Fallback StubKeyring is insecure!"); - m_instance = new StubKeyring(); + qWarning("Keyrings are not supported on your OS. Fallback StubKeyring is insecure!"); + m_instance = new StubKeyring(); #endif - atexit(Keyring::destroy); - } - return m_instance; + atexit(Keyring::destroy); + } + return m_instance; } void Keyring::destroy() { - delete m_instance; + delete m_instance; } Keyring *Keyring::m_instance; diff --git a/libsettings/src/stubkeyring.cpp b/libsettings/src/stubkeyring.cpp index 0e29d2f2..963f3dd9 100644 --- a/libsettings/src/stubkeyring.cpp +++ b/libsettings/src/stubkeyring.cpp @@ -6,7 +6,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -25,72 +25,72 @@ int scrambler = 0x9586309; QString scramble(QString in_) { - QByteArray in = in_.toUtf8(); - QByteArray out; - for (int i = 0; i Date: Fri, 22 Mar 2013 14:40:55 +0100 Subject: fix merge issues, make console window work again --- libsettings/src/stubkeyring.h | 1 - 1 file changed, 1 deletion(-) (limited to 'libsettings/src') diff --git a/libsettings/src/stubkeyring.h b/libsettings/src/stubkeyring.h index 0566d5ab..b5f04e4c 100644 --- a/libsettings/src/stubkeyring.h +++ b/libsettings/src/stubkeyring.h @@ -24,7 +24,6 @@ class StubKeyring : public Keyring { - Q_OBJECT public: virtual bool storePassword(QString service, QString username, QString password); virtual QString getPassword(QString service, QString username); -- cgit v1.2.3 From 40570c321069b832722b807227fd8ff9bbd7c10d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 24 Mar 2013 15:36:00 +0100 Subject: Fix settings objects, instances can be started from the GUI now --- libsettings/src/basicsettingsobject.cpp | 5 ++++- libsettings/src/inisettingsobject.cpp | 5 ++++- libsettings/src/setting.cpp | 9 ++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) (limited to 'libsettings/src') diff --git a/libsettings/src/basicsettingsobject.cpp b/libsettings/src/basicsettingsobject.cpp index 66a2c2c8..484928c8 100644 --- a/libsettings/src/basicsettingsobject.cpp +++ b/libsettings/src/basicsettingsobject.cpp @@ -26,7 +26,10 @@ void BasicSettingsObject::changeSetting(const Setting &setting, QVariant value) { if (contains(setting.id())) { - config.setValue(setting.configKey(), value); + if(value.isValid()) + config.setValue(setting.configKey(), value); + else + config.remove(setting.configKey()); } } diff --git a/libsettings/src/inisettingsobject.cpp b/libsettings/src/inisettingsobject.cpp index 75228865..8c4cc89d 100644 --- a/libsettings/src/inisettingsobject.cpp +++ b/libsettings/src/inisettingsobject.cpp @@ -32,7 +32,10 @@ void INISettingsObject::changeSetting(const Setting &setting, QVariant value) { if (contains(setting.id())) { - m_ini.set(setting.configKey(), value); + if(value.isValid()) + m_ini.set(setting.configKey(), value); + else + m_ini.remove(setting.configKey()); } } diff --git a/libsettings/src/setting.cpp b/libsettings/src/setting.cpp index a224ad39..1a4f9e13 100644 --- a/libsettings/src/setting.cpp +++ b/libsettings/src/setting.cpp @@ -26,9 +26,16 @@ QVariant Setting::get() const { SettingsObject *sbase = qobject_cast(parent()); if (!sbase) + { return defValue(); + } else - return sbase->retrieveValue(*this); + { + QVariant test = sbase->retrieveValue(*this); + if(!test.isValid()) + return defValue(); + return test; + } } QVariant Setting::defValue() const -- cgit v1.2.3 From 737273348faa598af906bef2d96e6520a85cbc88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 26 Mar 2013 17:43:49 +0100 Subject: Use Keyring in the login dialog --- libsettings/src/stubkeyring.cpp | 6 ++++++ libsettings/src/stubkeyring.h | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'libsettings/src') diff --git a/libsettings/src/stubkeyring.cpp b/libsettings/src/stubkeyring.cpp index 963f3dd9..cb03bf79 100644 --- a/libsettings/src/stubkeyring.cpp +++ b/libsettings/src/stubkeyring.cpp @@ -90,6 +90,12 @@ QStringList StubKeyring::getStoredAccounts(QString service) return out; } +void StubKeyring::removeStoredAccount ( QString service, QString username ) +{ + QString key = generateKey(service, username); + m_settings.remove(key); +} + StubKeyring::StubKeyring() : m_settings(QSettings::UserScope, "Orochimarufan", "Keyring") { diff --git a/libsettings/src/stubkeyring.h b/libsettings/src/stubkeyring.h index b5f04e4c..45791c85 100644 --- a/libsettings/src/stubkeyring.h +++ b/libsettings/src/stubkeyring.h @@ -29,7 +29,7 @@ public: virtual QString getPassword(QString service, QString username); virtual bool hasPassword(QString service, QString username); virtual QStringList getStoredAccounts(QString service); - + virtual void removeStoredAccount(QString service, QString username); private: friend class Keyring; explicit StubKeyring(); -- cgit v1.2.3 From 1f13f0c665001a1a79f00cdad1e63e6c9802e55f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 26 Mar 2013 19:26:10 +0100 Subject: Store stub keyring data in the same folder as the binary --- libsettings/src/stubkeyring.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'libsettings/src') diff --git a/libsettings/src/stubkeyring.cpp b/libsettings/src/stubkeyring.cpp index cb03bf79..cf814d2f 100644 --- a/libsettings/src/stubkeyring.cpp +++ b/libsettings/src/stubkeyring.cpp @@ -96,7 +96,9 @@ void StubKeyring::removeStoredAccount ( QString service, QString username ) m_settings.remove(key); } +//FIXME: this needs tweaking/changes for user account level storage StubKeyring::StubKeyring() : - m_settings(QSettings::UserScope, "Orochimarufan", "Keyring") +// m_settings(QSettings::UserScope, "Orochimarufan", "Keyring") + m_settings("keyring.cfg", QSettings::IniFormat) { } -- cgit v1.2.3