Skip to content

Commit

Permalink
[lipstick] Allow control of VPN credential storage/retrieval. Contrib…
Browse files Browse the repository at this point in the history
…utes to JB#45178

When using the VPN the UI can request credentials from the user. These
can optionally be stored if the user selects the option to store them in
the dialogue.

There may be times when the VPN should prevent the user from choosing to
store credentials. This change allows connman to request for them not to
be stored.

The controlling input comes from connman. The resulting UI is handled by
lipstick-jolla-home.
  • Loading branch information
llewelld committed Jun 4, 2019
1 parent 8da2b42 commit af22e3e
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions src/vpnagent.cpp
Expand Up @@ -158,6 +158,32 @@ QVariant extract(const QDBusArgument &arg)
return QVariant::fromValue(rv);
}

// Extracts a boolean value and removes it from the map
bool ExtractRequestBool(QVariantMap &extracted, const QString key, bool defaultValue) {
bool result = defaultValue;
QVariantMap::iterator it = extracted.find(key);
while (it != extracted.end()) {
bool found = false;
if (it.key() == key) {
QVariantMap field(it.value().value<QVariantMap>());
QString type = field.value(QStringLiteral("Type")).toString();
QString requirement = field.value(QStringLiteral("Requirement")).toString();
QString value = field.value(QStringLiteral("Value")).toString();

if ((type == QStringLiteral("string")) && (requirement == QStringLiteral("mandatory"))) {
qDebug() << "VPNUI extracted " << it.key() << ": " << value;
result = (value == QStringLiteral("1"));
it = extracted.erase(it);
found = true;
}
}
if (!found) {
it++;
}
}
return result;
}

}

QVariantMap VpnAgent::RequestInput(const QDBusObjectPath &path, const QVariantMap &details)
Expand All @@ -168,10 +194,16 @@ QVariantMap VpnAgent::RequestInput(const QDBusObjectPath &path, const QVariantMa
*it = extract<QVariantMap>(it.value().value<QDBusArgument>());
}

const bool allowCredentialStorage(ExtractRequestBool(extracted, "AllowStoreCredentials", true));
const bool allowCredentialRetrieval(ExtractRequestBool(extracted, "AllowRetrieveCredentials", true));

qDebug() << "VPNUI final AllowStoreCredentials: " << allowCredentialStorage;
qDebug() << "VPNUI final AllowRetrieveCredentials: " << allowCredentialRetrieval;

// Can we supply the requested data from stored credentials?
const QString objectPath(path.path());
const bool storeCredentials(m_connections->connectionCredentialsEnabled(objectPath));
if (storeCredentials) {
if (storeCredentials && allowCredentialRetrieval) {
const QVariantMap credentials(m_connections->connectionCredentials(objectPath));

bool satisfied(true);
Expand Down Expand Up @@ -228,7 +260,9 @@ QVariantMap VpnAgent::RequestInput(const QDBusObjectPath &path, const QVariantMa
}
}

extracted.insert(QStringLiteral("storeCredentials"), QVariant::fromValue(storeCredentials));
if (allowCredentialStorage) {
extracted.insert(QStringLiteral("storeCredentials"), QVariant::fromValue(storeCredentials));
}

// Inform the caller that the reponse will be asynchronous
QDBusContext::setDelayedReply(true);
Expand Down

0 comments on commit af22e3e

Please sign in to comment.