Commit 3582237e authored by Ilia Kats's avatar Ilia Kats
Browse files

Port all VPN-Plugins which support this to the new secrets flags system.

Add auth-dialogs for OpenVPN and PTTP.
Fix some minor bugs

BUG: 269951
BUG: 277354
CCBUG: 274930
parent 34e6d2a5
......@@ -20,7 +20,6 @@ void VpnPersistence::load()
VpnSetting * setting = static_cast<VpnSetting *>(m_setting);
setting->setServiceType(m_config->readEntry("ServiceType", ""));
setting->setData(stringMapFromStringList(m_config->readEntry("Data", QStringList())));
setting->setSecretsStorageType(stringMapFromStringList(m_config->readEntry("SecretsStorageType", QStringList())));
setting->setUserName(m_config->readEntry("UserName", ""));
// SECRET
if (m_storageMode == SettingPersistence::PlainText) {
......
......@@ -44,7 +44,6 @@ VpnSetting::VpnSetting() : Setting(Setting::Vpn)
qDBusRegisterMetaType<QStringMap>();
m_secretsObject = new VpnSecrets(this);
mSecretsStorageType = QStringMap();
}
VpnSetting::VpnSetting(VpnSetting *setting) : Setting(setting)
......@@ -57,7 +56,6 @@ VpnSetting::VpnSetting(VpnSetting *setting) : Setting(setting)
setUserName(setting->userName());
setVpnSecrets(setting->vpnSecrets());
setPluginName(setting->pluginName());
setSecretsStorageType(setting->secretsStorageType());
}
VpnSetting::~VpnSetting()
......@@ -72,12 +70,3 @@ bool VpnSetting::hasSecrets() const
{
return true;
}
bool VpnSetting::hasVolatileSecrets() const
{
foreach(const QString & s, mSecretsStorageType.keys())
if (mSecretsStorageType.value(s) == QLatin1String(NM_VPN_PW_TYPE_ASK))
return true;
return false;
}
......@@ -10,10 +10,6 @@
#include "knminternals_export.h"
#include "../types.h"
#define NM_VPN_PW_TYPE_SAVE "save"
#define NM_VPN_PW_TYPE_ASK "ask"
#define NM_VPN_PW_TYPE_UNUSED "unused"
namespace Knm {
class KNMINTERNALS_EXPORT VpnSetting : public Setting
......@@ -57,32 +53,7 @@ class KNMINTERNALS_EXPORT VpnSetting : public Setting
*/
QStringMap data() const
{
QStringMap r = mData;
// Add secrets flags.
foreach (QString key, mSecretsStorageType.keys()) {
r.insert(key + "-flags", QString::number(storageTypeToSecretsType(mSecretsStorageType.value(key))));
// TODO: remove this when all vpnplugins/*/*widget.* are converted to use Settings::secretsTypes.
r.insert(key.replace(' ', "-").toLower() + "-type", mSecretsStorageType.value(key));
}
return r;
}
static secretsTypes storageTypeToSecretsType(const QString & storageType)
{
// Assuming VPN secrets are always AgentOwned.
secretsTypes s = AgentOwned;
if (storageType == NM_VPN_PW_TYPE_SAVE) {
s |= None;
}
if (storageType == NM_VPN_PW_TYPE_ASK) {
s |= NotSaved;
}
if (storageType == NM_VPN_PW_TYPE_UNUSED) {
s |= NotRequired;
}
return s;
return mData;
}
/**
......@@ -133,24 +104,6 @@ class KNMINTERNALS_EXPORT VpnSetting : public Setting
return mPluginName;
}
/**
Set secret storage type
*/
void setSecretsStorageType( const QStringMap & v )
{
mSecretsStorageType = v;
}
/**
Get secret storage type
*/
QStringMap secretsStorageType() const
{
return mSecretsStorageType;
}
bool hasVolatileSecrets() const;
protected:
// vpn
......@@ -159,7 +112,6 @@ class KNMINTERNALS_EXPORT VpnSetting : public Setting
QString mUserName;
QStringMap mVpnSecrets;
QString mPluginName;
QStringMap mSecretsStorageType;
private:
};
......
......@@ -82,8 +82,7 @@ QStringList VpnSecrets::stringMapToStringList(const QStringMap & map)
QMap<QString,QString> VpnSecrets::secretsToMap() const
{
QMap<QString,QString> map;
// Assuming VPN secrets are always AgentOwned.
map.insert(QLatin1String("VpnSecrets"), variantMapToStringList(secretsToSave(m_setting->secretsStorageType(), m_setting->vpnSecrets())).join(QLatin1String("%SEP%")));
map.insert(QLatin1String("VpnSecrets"), variantMapToStringList(secretsToSave(m_setting->data(), m_setting->vpnSecrets())).join(QLatin1String("%SEP%")));
return map;
}
......@@ -121,13 +120,13 @@ QStringList VpnSecrets::needSecrets()
return QStringList() << "VpnSecrets";
}
QVariantMap VpnSecrets::secretsToSave(const QStringMap & type, const QStringMap & secrets)
QVariantMap VpnSecrets::secretsToSave(const QStringMap & data, const QStringMap & secrets)
{
QVariantMap toSave;
QMapIterator<QString,QString> i(secrets);
while (i.hasNext()) {
i.next();
if (type[i.key()].isNull() || type[i.key()] == QLatin1String(NM_VPN_PW_TYPE_SAVE))
if ((Knm::Setting::secretsTypes)data[i.key() + "-flags"].toInt() & Knm::Setting::AgentOwned)
toSave.insert( i.key(), i.value() );
}
return toSave;
......
......@@ -62,16 +62,12 @@ VpnPreferences::VpnPreferences(const QVariantList &args, QWidget *parent)
kDebug() << error;
}
}
// If additional settings are passed, populate them : data, secretsData and secretsType, connection name
// If additional settings are passed, populate them : data, secretsData, connection name
// Connection Name
if (args.count() > 5) {
m_contents->setDefaultName(args[5].toString());
}
Knm::VpnSetting * conSetting = static_cast<Knm::VpnSetting*>(m_connection->setting(Knm::Setting::Vpn));
if (args.count() > 4) {
// Secret Storage Type
conSetting->setSecretsStorageType(Knm::VpnSecrets::stringMapFromStringList(Knm::VpnSecrets::variantMapToStringList(args[4].toMap())));
m_contents->setDefaultName(args[4].toString());
}
Knm::VpnSetting * conSetting = static_cast<Knm::VpnSetting*>(m_connection->setting(Knm::Setting::Vpn));
if (args.count() > 3) {
// VPN Secrets
conSetting->setVpnSecrets(Knm::VpnSecrets::stringMapFromStringList(Knm::VpnSecrets::variantMapToStringList(args[3].toMap())));
......
......@@ -5,6 +5,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../libs/internals)
set(openvpn_SRCS
openvpn.cpp
openvpnwidget.cpp
openvpnauth.cpp
)
kde4_add_ui_files(openvpn_SRCS openvpnprop.ui)
......
......@@ -23,6 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <KPluginFactory>
#include "openvpnwidget.h"
#include "openvpnauth.h"
#include "connection.h"
......@@ -45,6 +46,11 @@ SettingWidget * OpenVpnUiPlugin::widget(Knm::Connection * connection, QWidget *
return wid;
}
SettingWidget * OpenVpnUiPlugin::askUser(Knm::Connection * connection, QWidget * parent)
{
return new OpenVpnAuthWidget(connection, parent);
}
QString OpenVpnUiPlugin::suggestedFileName(Knm::Connection *connection) const
{
// TODO : implement suggested file name
......
......@@ -37,6 +37,7 @@ public:
OpenVpnUiPlugin(QObject * parent = 0, const QVariantList& = QVariantList());
virtual ~OpenVpnUiPlugin();
SettingWidget * widget(Knm::Connection *, QWidget * parent = 0);
SettingWidget * askUser(Knm::Connection *, QWidget * parent = 0);
QString suggestedFileName(Knm::Connection *connection) const;
QVariantList importConnectionSettings(const QString &fileName);
void exportConnectionSettings(Knm::Connection * connection, const QString &fileName);
......
/*
Copyright 2011 Ilia Kats <ilia-kats@gmx.net>
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) version 3 or any later version
accepted by the membership of KDE e.V. (or its successor approved
by the membership of KDE e.V.), which shall act as a proxy
defined in Section 14 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#include "openvpnauth.h"
#include <QString>
#include <QFormLayout>
#include <QLabel>
#include <QCheckBox>
#include <KLineEdit>
#include <KLocale>
#include "nm-openvpn-service.h"
#include "connection.h"
class OpenVpnAuthWidgetPrivate
{
public:
Knm::VpnSetting * setting;
QFormLayout *layout;
};
OpenVpnAuthWidget::OpenVpnAuthWidget(Knm::Connection * connection, QWidget * parent)
: SettingWidget(connection, parent), d_ptr(new OpenVpnAuthWidgetPrivate)
{
Q_D(OpenVpnAuthWidget);
d->setting = static_cast<Knm::VpnSetting *>(connection->setting(Knm::Setting::Vpn));
d->layout = new QFormLayout(this);
this->setLayout(d->layout);
}
OpenVpnAuthWidget::~OpenVpnAuthWidget()
{
delete d_ptr;
}
void OpenVpnAuthWidget::readSecrets()
{
Q_D(OpenVpnAuthWidget);
QStringMap secrets = d->setting->vpnSecrets();
QStringMap dataMap = d->setting->data();
QString cType = dataMap[NM_OPENVPN_KEY_CONNECTION_TYPE];
QLabel *label;
KLineEdit *lineEdit;
Knm::Setting::secretsTypes certType;
Knm::Setting::secretsTypes passType;
Knm::Setting::secretsTypes proxyType;
if (!dataMap[NM_OPENVPN_KEY_CERTPASS"-flags"].isEmpty()) {
certType = (Knm::Setting::secretsTypes)dataMap[NM_OPENVPN_KEY_CERTPASS"-flags"].toInt();
} else {
certType = (Knm::Setting::secretsTypes)Knm::Setting::NotRequired;
}
if (!dataMap[NM_OPENVPN_KEY_PASSWORD"-flags"].isEmpty()) {
passType = (Knm::Setting::secretsTypes)dataMap[NM_OPENVPN_KEY_PASSWORD"-flags"].toInt();
} else {
passType = (Knm::Setting::secretsTypes)Knm::Setting::NotRequired;
}
if (!dataMap[NM_OPENVPN_KEY_HTTP_PROXY_PASSWORD"-flags"].isEmpty()) {
proxyType = (Knm::Setting::secretsTypes)dataMap[NM_OPENVPN_KEY_HTTP_PROXY_PASSWORD"-flags"].toInt();
} else {
proxyType = (Knm::Setting::secretsTypes)Knm::Setting::NotRequired;
}
if (cType == QLatin1String(NM_OPENVPN_CONTYPE_TLS) && !(certType & Knm::Setting::NotRequired)) {
label = new QLabel(this);
label->setText(i18n("Key Password:"));
lineEdit = new KLineEdit(this);
lineEdit->setPasswordMode(true);
lineEdit->setProperty("nm_secrets_key", QLatin1String(NM_OPENVPN_KEY_CERTPASS));
lineEdit->setText(secrets.value(QLatin1String(NM_OPENVPN_KEY_CERTPASS)));
d->layout->addRow(label, lineEdit);
} else if (cType == QLatin1String(NM_OPENVPN_CONTYPE_PASSWORD) && !(passType & Knm::Setting::NotRequired)) {
label = new QLabel(this);
label->setText(i18n("Password:"));
lineEdit = new KLineEdit(this);
lineEdit->setPasswordMode(true);
lineEdit->setProperty("nm_secrets_key", QLatin1String(NM_OPENVPN_KEY_PASSWORD));
lineEdit->setText(secrets.value(QLatin1String(NM_OPENVPN_KEY_PASSWORD)));
d->layout->addRow(label, lineEdit);
} else if (cType == QLatin1String(NM_OPENVPN_CONTYPE_PASSWORD_TLS)) {
if (!(passType & Knm::Setting::NotRequired)) {
label = new QLabel(this);
label->setText(i18n("Password:"));
lineEdit = new KLineEdit(this);
lineEdit->setPasswordMode(true);
lineEdit->setProperty("nm_secrets_key", QLatin1String(NM_OPENVPN_KEY_PASSWORD));
lineEdit->setText(secrets.value(QLatin1String(NM_OPENVPN_KEY_PASSWORD)));
d->layout->addRow(label, lineEdit);
}
if (!(certType & Knm::Setting::NotRequired)) {
label = new QLabel(this);
label->setText(i18n("Key Password:"));
lineEdit = new KLineEdit(this);
lineEdit->setPasswordMode(true);
lineEdit->setProperty("nm_secrets_key", QLatin1String(NM_OPENVPN_KEY_CERTPASS));
lineEdit->setText(secrets.value(QLatin1String(NM_OPENVPN_KEY_CERTPASS)));
d->layout->addRow(label, lineEdit);
}
}
if (!(proxyType & Knm::Setting::NotRequired)) {
label = new QLabel(this);
label->setText(i18n("Proxy Password:"));
lineEdit = new KLineEdit(this);
lineEdit->setPasswordMode(true);
lineEdit->setProperty("nm_secrets_key", QLatin1String(NM_OPENVPN_KEY_HTTP_PROXY_PASSWORD));
lineEdit->setText(secrets.value(QLatin1String(NM_OPENVPN_KEY_HTTP_PROXY_PASSWORD)));
d->layout->addRow(label, lineEdit);
}
for (int i = 0; i < d->layout->rowCount(); i++)
{
KLineEdit *le = qobject_cast<KLineEdit*>(d->layout->itemAt(i, QFormLayout::FieldRole)->widget());
if (le && le->text().isEmpty()) {
le->setFocus(Qt::OtherFocusReason);
break;
}
}
QCheckBox *showPasswords = new QCheckBox(this);
showPasswords->setText(i18n("&Show password"));
d->layout->addRow(showPasswords);
connect(showPasswords, SIGNAL(toggled(bool)), this, SLOT(showPasswordsToggled(bool)));
}
void OpenVpnAuthWidget::writeConfig()
{
Q_D(OpenVpnAuthWidget);
QStringMap secretData;
for (int i = 0; i < d->layout->rowCount() - 1; i++)
{
KLineEdit *le = qobject_cast<KLineEdit*>(d->layout->itemAt(i, QFormLayout::FieldRole)->widget());
if (le && !le->text().isEmpty()) {
QString key = le->property("nm_secrets_key").toString();
secretData.insert(key, le->text());
}
}
d->setting->setVpnSecrets(secretData);
}
void OpenVpnAuthWidget::showPasswordsToggled(bool toggled)
{
Q_D(OpenVpnAuthWidget);
for (int i = 0; i < d->layout->rowCount() - 1; i++)
{
KLineEdit *le = qobject_cast<KLineEdit*>(d->layout->itemAt(i, QFormLayout::FieldRole)->widget());
if (le) {
le->setPasswordMode(!toggled);
}
}
}
/*
Copyright 2011 Ilia Kats <ilia-kats@gmx.net>
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) version 3 or any later version
accepted by the membership of KDE e.V. (or its successor approved
by the membership of KDE e.V.), which shall act as a proxy
defined in Section 14 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPENVPNAUTH_H
#define OPENVPNAUTH_H
#include "settingwidget.h"
#include "settings/vpn.h"
namespace Knm
{
class Connection;
} // namespace Knm
class OpenVpnAuthWidgetPrivate;
class OpenVpnAuthWidget : public SettingWidget
{
Q_OBJECT
Q_DECLARE_PRIVATE(OpenVpnAuthWidget)
public:
OpenVpnAuthWidget(Knm::Connection *, QWidget * parent = 0);
~OpenVpnAuthWidget();
void readConfig() {}
void readSecrets();
void writeConfig();
protected Q_SLOTS:
void validate() {}
void showPasswordsToggled(bool);
private:
OpenVpnAuthWidgetPrivate * d_ptr;
};
#endif // OPENVPNAUTH_H
......@@ -155,17 +155,40 @@
<property name="text">
<string>Key password:</string>
</property>
<property name="buddy">
<cstring>x509KeyPassword</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="KLineEdit" name="x509KeyPassword">
<property name="passwordMode">
<bool>true</bool>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="KLineEdit" name="x509KeyPassword">
<property name="enabled">
<bool>false</bool>
</property>
<property name="passwordMode">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="KComboBox" name="x509KeyPasswordStorage">
<item>
<property name="text">
<string>Always Ask</string>
</property>
</item>
<item>
<property name="text">
<string>Store</string>
</property>
</item>
<item>
<property name="text">
<string>Not Required</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
</layout>
</item>
......@@ -342,17 +365,40 @@
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>passPassword</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="KLineEdit" name="passPassword">
<property name="passwordMode">
<bool>true</bool>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
<widget class="KLineEdit" name="passPassword">
<property name="enabled">
<bool>false</bool>
</property>
<property name="passwordMode">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="KComboBox" name="passPasswordStorage">
<item>
<property name="text">
<string>Always Ask</string>
</property>
</item>
<item>
<property name="text">
<string>Store</string>
</property>
</item>
<item>
<property name="text">
<string>Not Required</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
</layout>
</item>
......@@ -428,16 +474,6 @@
<property name="text">
<string>Key password</string>
</property>
<property name="buddy">
<cstring>x509PassKeyPassword</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="KLineEdit" name="x509PassKeyPassword">
<property name="passwordMode">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="0">
......@@ -461,17 +497,73 @@
<property name="text">
<string>Password</string>
</property>
<property name="buddy">
<cstring>x509PassPassword</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_12">
<item>
<widget class="KLineEdit" name="x509PassKeyPassword">
<property name="enabled">
<bool>false</bool>
</property>
<property name="passwordMode">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="KComboBox" name="x509PassKeyPasswordStorage">
<item>
<property name="text">
<string>Always Ask</string>
</property>
</item>
<item>
<property name="text">
<string>Store</string>
</property>
</item>
<item>
<property name="text">
<string>Not Required</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item row="5" column="1">
<widget class="KLineEdit" name="x509PassPassword">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_13">
<item>
<widget class="KLineEdit" name="x509PassPassword">
<property name="enabled">
<bool>false</bool>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item>
<widget class="KComboBox" name="x509PassPasswordStorage">
<item>
<property name="text">
<string>Always Ask</string>
</property>
</item>