Merge lp:~mardy/signon-ui/export-cookies into lp:signon-ui

Proposed by Alberto Mardegan
Status: Merged
Approved by: Alberto Mardegan
Approved revision: 124
Merged at revision: 122
Proposed branch: lp:~mardy/signon-ui/export-cookies
Merge into: lp:signon-ui
Diff against target: 133 lines (+57/-0)
4 files modified
src/cookie-jar-manager.cpp (+1/-0)
src/service.cpp (+44/-0)
src/service.h (+11/-0)
src/signon-ui.pro (+1/-0)
To merge this branch: bzr merge lp:~mardy/signon-ui/export-cookies
Reviewer Review Type Date Requested Status
Ken VanDine Approve
Alexandre Abreu (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+198233@code.launchpad.net

Commit message

Add an experimental method to get the WebView cookies

This is intended to be used by the webapps container, in the attempt to reduce the number of web logins required to the user.

Description of the change

Add an experimental method to get the WebView cookies

This is intended to be used by the webapps container, in the attempt to reduce the number of web logins required to the user.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ken VanDine (ken-vandine) wrote :

Looks fine, my only concern is security. We need to make sure this can only be used by the webapps container. I guess we need an apparmor profile for that. Has that been discussed yet?

review: Needs Information
Revision history for this message
Alberto Mardegan (mardy) wrote :

> Looks fine, my only concern is security. We need to make sure this can only
> be used by the webapps container. I guess we need an apparmor profile for
> that. Has that been discussed yet?

Well, click packages cannot access this interface, and unconfined processes can directly read the cookies.db file anyway. :-)

Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

Random question:
L63: can't we have a more reliable information about the timestamp (than the last time the cookie file was touched which seems quite arbitrary)?

Revision history for this message
Alberto Mardegan (mardy) wrote :

On 12/11/2013 10:37 AM, Alexandre Abreu wrote:
> Random question:
> L63: can't we have a more reliable information about the timestamp (than the last time the cookie file was touched which seems quite arbitrary)?

I'm afraid not (or I don't have a better idea). We can try to find a
better way when Oxyde is taken into use, maybe.

Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

I am wondering, since the interface basically changed ... shouldn't there be (even a minor) bump in the dbus if or something?

review: Needs Information
Revision history for this message
Alberto Mardegan (mardy) wrote :

> I am wondering, since the interface basically changed ... shouldn't there be
> (even a minor) bump in the dbus if or something?

I wouldn't be so strict about this addition, it's not meant to be used by anyone other than the webapp container, and I'd like to be able to change/remove it as needed.
If you prefer, I could move it under a new interface ("com.ubuntu.SignonUi.experimental"?); I wouldn't do it if it were for me, but strictly speaking it would be the right thing to do.

Revision history for this message
Alexandre Abreu (abreu-alexandre) :
review: Approve
Revision history for this message
Ken VanDine (ken-vandine) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/cookie-jar-manager.cpp'
2--- src/cookie-jar-manager.cpp 2013-04-24 08:36:41 +0000
3+++ src/cookie-jar-manager.cpp 2013-12-09 11:50:35 +0000
4@@ -151,6 +151,7 @@
5 {
6 Q_D(CookieJarManager);
7
8+ qRegisterMetaType<RawCookies>("RawCookies");
9 qDBusRegisterMetaType<RawCookies>();
10 qRegisterMetaTypeStreamOperators<QList<QNetworkCookie> >("QList<QNetworkCookie>");
11
12
13=== modified file 'src/service.cpp'
14--- src/service.cpp 2013-05-01 22:53:03 +0000
15+++ src/service.cpp 2013-12-09 11:50:35 +0000
16@@ -25,6 +25,11 @@
17 #include "request.h"
18
19 #include <QDBusArgument>
20+#include <QDateTime>
21+#include <QFileInfo>
22+#include <QSqlDatabase>
23+#include <QSqlQuery>
24+#include <QStandardPaths>
25 #include <QQueue>
26
27 using namespace SignOnUi;
28@@ -78,6 +83,7 @@
29 void runQueue(RequestQueue &queue);
30 void cancelUiRequest(const QString &requestId);
31 void removeIdentityData(quint32 id);
32+ RawCookies cookiesForIdentity(quint32 id, qint64 &timestamp) const;
33
34 private Q_SLOTS:
35 void onRequestCompleted();
36@@ -94,6 +100,8 @@
37 QObject(service),
38 q_ptr(service)
39 {
40+ // This registers the RawCookies metatype with DBus
41+ CookieJarManager::instance();
42 }
43
44 ServicePrivate::~ServicePrivate()
45@@ -198,6 +206,35 @@
46 CookieJarManager::instance()->removeForIdentity(id);
47 }
48
49+RawCookies ServicePrivate::cookiesForIdentity(quint32 id,
50+ qint64 &timestamp) const
51+{
52+ RawCookies cookies;
53+ timestamp = 0;
54+
55+ QString cachePath =
56+ QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
57+ QString cookiesDBFile =
58+ QString("%1/id-%2/.local/share/browser-process/.QtWebKit/cookies.db")
59+ .arg(cachePath).arg(id);
60+
61+ QFileInfo fileInfo(cookiesDBFile);
62+ if (!fileInfo.exists()) return cookies;
63+ timestamp = fileInfo.lastModified().toMSecsSinceEpoch() / 1000;
64+
65+ QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
66+ db.setDatabaseName(cookiesDBFile);
67+ if (!db.open()) return cookies;
68+
69+ QSqlQuery q(db);
70+ q.exec("SELECT cookieId, cookie FROM cookies;");
71+ while (q.next()) {
72+ cookies.insert(q.value(0).toString(), q.value(1).toString());
73+ }
74+
75+ return cookies;
76+}
77+
78 Service::Service(QObject *parent):
79 QObject(parent),
80 d_ptr(new ServicePrivate(this))
81@@ -254,4 +291,11 @@
82 d->removeIdentityData(id);
83 }
84
85+void Service::cookiesForIdentity(quint32 id,
86+ RawCookies &cookies, qint64 &timestamp)
87+{
88+ Q_D(const Service);
89+ cookies = d->cookiesForIdentity(id, timestamp);
90+}
91+
92 #include "service.moc"
93
94=== modified file 'src/service.h'
95--- src/service.h 2013-04-24 08:36:41 +0000
96+++ src/service.h 2013-12-09 11:50:35 +0000
97@@ -21,6 +21,8 @@
98 #ifndef SIGNON_UI_SERVICE_H
99 #define SIGNON_UI_SERVICE_H
100
101+#include "cookie-jar-manager.h"
102+
103 #include <QDBusContext>
104 #include <QObject>
105 #include <QVariantMap>
106@@ -47,6 +49,15 @@
107 Q_NOREPLY void cancelUiRequest(const QString &requestId);
108 void removeIdentityData(quint32 id);
109
110+ /*
111+ * This is not officially part of the interface; it's an Ubuntu-specific
112+ * experimental method, and we reserve the right to remove or change it in
113+ * future releases.
114+ */
115+ void cookiesForIdentity(quint32 id,
116+ // Output parameters
117+ RawCookies &cookies, qint64 &timestamp);
118+
119 Q_SIGNALS:
120 void isIdleChanged();
121
122
123=== modified file 'src/signon-ui.pro'
124--- src/signon-ui.pro 2013-10-04 17:15:49 +0000
125+++ src/signon-ui.pro 2013-12-09 11:50:35 +0000
126@@ -16,6 +16,7 @@
127 dbus \
128 gui \
129 network \
130+ sql \
131 webkit
132
133 PKGCONFIG += \

Subscribers

People subscribed via source and target branches

to all changes: