Commit graph

60 commits

Author SHA1 Message Date
Pranav Kant
b8ef017610 Move JWT auth to inside websocket to prevent CSRF
... instead of setting a httpOnly cookie for admin websocket
endpoint which can be CSRFed.

With this, we remove the httpOnly tag on jwt cookie so that
scripts in admin html pages can access the jwt cookie and
authenticates after opening websocket endpoint. Until
authenticated using 'auth authToken' command, admin will not
respond to any admin command.

Also, adapt admin test these changes
2016-07-29 12:03:14 +05:30
Pranav Kant
319dd56598 loolwsd: Don't send an empty result in frame
Change-Id: Ia4cf4c6d49be4b65d075c8380994dd7115ba2dc6
2016-07-19 23:28:36 +05:30
Pranav Kant
478879f181 loolwsd: Reorder header files alphabetically
Change-Id: Ic83155ddf596c7d5168ef37721417d211b85313d
2016-07-19 22:53:48 +05:30
Miklos Vajna
ec0c49447f Admin: avoid unsigned long -> unsigned int coversion 2016-07-12 15:56:19 +02:00
Miklos Vajna
afb6a7ebb0 Util: turn TerminationFlag into an std::atomic<bool>
Running unit-fonts under helgrind points out missing synchronization
there.
2016-06-15 15:31:41 +02:00
Ashod Nakashian
fae850189d loolwsd: include cleanup and organization
A source file (.cpp) must include its own header first.
This insures that the header is self-contained and
doesn't depend on arbitrary (and accidental) includes
before it to compile.

Furthermore, system headers should go next, followed by
C then C++ headers, then libraries (Poco, etc) and, finally,
project headers come last.

This makes sure that headers and included in the same dependency
order to avoid side-effects. For example, Poco should never rely on
anything from our project in the same way that a C header should
never rely on anything in C++, Poco, or project headers.

Also, includes ought to be sorted where possible, to improve
readability and avoid accidental duplicates (of which there
were a few).

Change-Id: I62cc1343e4a091d69195e37ed659dba20cfcb1ef
Reviewed-on: https://gerrit.libreoffice.org/25262
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-05-21 15:52:54 +00:00
Miklos Vajna
c2fc95ac23 Drop unused using declarations
Change-Id: Iee778833781c6f00c1fb0b8fc1975acfe4fb0cd9
2016-05-10 09:14:22 +02:00
Pranav Kant
0559b58144 loolwsd: Use SocketProcessor from IoUtil in Admin
Change-Id: Ic89f04ee61f58ae13da9205e84d36ec06ed1d7ee
2016-05-03 12:59:02 +05:30
Tor Lillqvist
bfcf9756f5 Don't assert on PING frames that we send
UnitPrefork got what I assume is one of those PING frames that
ChildProcess::isAlive() sends before the actual reply when it sent the
"unit-memdump" message, and did not like it. Uncommenting the line
that outputs the "memory stats" message it expects showed:

Got memory stats 'PING'

Followed by:

Assertion `tokens.count() == 2' failed.

Fix by factoring out the handling of PING frames, PONG frames, and the
pseudo-PONG frames that we send ourselves in reply to PING frames into
a new function IoUtil::receiveFrame(). Use that in a couple of
places. (Probably should use in many more places.)

Getting past this then leads to later cppunit tests again being run,
and their failures then again showing up...
2016-05-03 09:50:38 +03:00
Ashod Nakashian
fc9df5db91 loolwsd: don't log memory usage if not changed
Change-Id: I98c43abb87e2291a304e77d6eb09ea1800545b72
Reviewed-on: https://gerrit.libreoffice.org/24524
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-04-30 14:36:02 +00:00
Pranav Kant
3e93a212f0 loolwsd: Admin console unit tests
Change-Id: Id0baa51c2adb14b77080b5acd2abf0658ee54b2b
2016-04-19 14:40:03 +05:30
Pranav Kant
3111c5c6d1 loolwsd: Use common method to send websocket messages
Will help in placing unit test hooks to better test the admin
console

Change-Id: Ic4daae685a8fe493a0395d94e40112bf119c93e3
2016-04-19 14:39:50 +05:30
Pranav Kant
56d18909d5 loolwsd: Remove unused code
Change-Id: I7edf6b8d4f83f2cf9f85a2075d1dca216cda3d34
2016-04-19 14:39:50 +05:30
Ashod Nakashian
892358e5cb loolwsd: new Admin API to remove documents
Normally, when each client view closes, the
session count is decremented until the last
view is closed. However this doesn't work
when the kit child process terminates.

Due to a race condition between the last
client disconnecting, and the internal
structure destructing, and the next
client connecting (on the same doc),
the Admin loses track of the doc and pid.

This is an issue of assuming a document
and its pid are unique and will always
remain unchanged.

This patch adds a new API to remove a
doc and all its views unconditionally
to try to avoid the above issues.

Change-Id: I0c181260679875b0464dd9b6548b29b8d6a361f7
Reviewed-on: https://gerrit.libreoffice.org/24183
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-04-18 03:35:29 +00:00
Ashod Nakashian
52959b7289 loolwsd: admin cleanups
Change-Id: Ib8a488ef08d345f768323e1303f7a053e54464d5
Reviewed-on: https://gerrit.libreoffice.org/24182
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-04-18 03:34:54 +00:00
Ashod Nakashian
4254ddad77 loolwsd: consistently set HTTP status and reason everywhere
Change-Id: Ie538e4907e3a3a514918000bb585d2aaf182e468
Reviewed-on: https://gerrit.libreoffice.org/24132
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-04-16 17:29:35 +00:00
Ashod Nakashian
93d3f806e1 loolwsd: logging and cosmetics
Change-Id: I413a2e40f480ba41e37c7442724c3f037528f89b
Reviewed-on: https://gerrit.libreoffice.org/24130
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-04-16 17:28:45 +00:00
Pranav Kant
cca858732a loolwsd: Allow admin console to kill documents (again)
Change-Id: I30405854e9ebdc56ab3477758e9008963d4b8efa
2016-04-15 15:25:01 +05:30
Pranav Kant
91c6154fc0 loolwsd: Use docKey as key for Admin instead of PID
Also change some variable names to be consistent with rest of the
coding style.

Change-Id: Icca9a9aec9bfb34c1edd5b6533d7646b05fe814f
2016-04-15 14:42:14 +05:30
Pranav Kant
7bf5e84a90 loolwsd: Make admin console work (again)
Change-Id: Ib51f33c60b5e42e154795357a7a787cb8691ad51
2016-04-15 13:28:42 +05:30
Pranav Kant
4f9eef9324 loolwsd: Be consistent, and use unique_lock
Change-Id: Idfc14bb7dd82827493865241f6d04cf9ae4a88fc
2016-04-15 13:28:42 +05:30
Pranav Kant
9669470d09 loolwsd: Admin doesn't need its own thread now
The timers are cancelled upon destruction of the static Admin
instance.

Change-Id: Ie43dc9d3ec96b002e12685ec997ad83c29b684d0
2016-04-15 13:28:42 +05:30
Tor Lillqvist
c9796255ae Don't check for undocumented "eof" frames read from a websocket either
Now with "disconnect" frames gone, surely checks for "eof" ones can go
away too, whatever they were.
2016-04-13 15:50:09 +03:00
Tor Lillqvist
3b5f126b89 Typo 2016-04-08 14:30:48 +03:00
Tor Lillqvist
d36c8bbbba Avoid some use-once variables
Also, use different names for the HTTPRequestHandler threads in
ClientRequestHandlerFactory and PrisonerRequestHandlerFactory.
2016-04-07 19:31:56 +03:00
Tor Lillqvist
711674f7ce Use Log::debug() here, too, for consistency 2016-04-07 15:56:23 +03:00
Tor Lillqvist
4fdd6d684f Reduce redundant information in logging
The logging functions already display the thread name on all output
lines. No need to mention it another time in the thread start and
finish logging messages.
2016-04-07 15:53:53 +03:00
Tor Lillqvist
84cd6bbceb Try to be more consistent in terminology
The "Broker" process is called "ForKit" now. The only things called
"broker" now are the DocumentBroker objects in the WSD process.
2016-04-07 11:53:44 +03:00
Tor Lillqvist
5637064e9a Factor out the prctl() calls
Silly to keep copy-pasting the same couple of lines over and over
again.
2016-04-07 11:53:33 +03:00
Tor Lillqvist
ec604599f1 Introduce separate Log::syserror() function for logging actual syscall errors
Much better than assuming that errno would be relevant at all
Log::error() calls (or alternatively, having to remember to append a
false parameter to the Log::error() call, which had not been done a
single time anyway.)

Call log::syserror() right after a system call has returned an
error. Don't call it otherwise.
2016-04-07 10:36:38 +03:00
Jan Holesovsky
204a9c742f loolwsd: Allow asking for credentials even during websocket setup.
It may happen that admin.html is cached, which leads to the cookie not being
set up, which then leads to endless amount of attempts to log in.
2016-04-06 20:17:24 +02:00
Ashod Nakashian
6e5e9033f2 loolwsd: removed Admin pipe
Admin no longer needs a pipe as it's notified
from WSD. It is now a singleton with improved
locking.

The tracking of documents and views still needs
improvement and corrections.

Change-Id: If614331de6dd595c6dd4443f480d4ab588ca4551
Reviewed-on: https://gerrit.libreoffice.org/23860
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-04-06 13:52:57 +00:00
Ashod Nakashian
ae8ce06162 loolwsd: removed unnecessary from pipe messages
Change-Id: I5fc310f98764b31fc50f877c28d6076bbb14866f
Reviewed-on: https://gerrit.libreoffice.org/23784
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-04-04 04:05:46 +00:00
Ashod Nakashian
aacd162673 loolwsd: FIFO_NOTIFY -> FIFO_ADMIN_NOTIFY
Change-Id: Ia42983010b3962ca9228032817c6f9024a74c59f
Reviewed-on: https://gerrit.libreoffice.org/23783
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-04-04 04:05:31 +00:00
Ashod Nakashian
ceaefabc91 Revert "loolwsd: replace fifo for socket WSD -> Broker"
This reverts commit 97c8f35ddf.

Since the Broker design has been extremely simplified,
all communication between Broker <-> Kit are gone.
Only a pipe between WSD and Broker remain.

Temporarily reverting this to apply the Broker redesign,
after which this patch can be reviewed and merged.
This will be easier than trying to merge the redesigned
Broker on top of this.

Change-Id: Ia901fad604008654c01841df62e88918adad45e1
Reviewed-on: https://gerrit.libreoffice.org/23769
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-04-04 04:00:45 +00:00
Henry Castro
97c8f35ddf loolwsd: replace fifo for socket WSD -> Broker 2016-04-03 08:12:10 -04:00
Pranav Kant
d26246dab0 loolwsd: Temporarily use hard-coded path to key file
We will switch to reading all these values as soon as wip
configuration file object is accessible globally.

Change-Id: I16eff339349683050be1985eefabc34854cccba3
2016-03-31 00:56:57 +05:30
Ashod Nakashian
ecce874315 loolwsd: new PipeReader class to poll and tokenize pipe messages
Change-Id: I5676b313ca4c7e711ead04c1491fe36591a00531
Reviewed-on: https://gerrit.libreoffice.org/23644
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-03-30 01:59:31 +00:00
Ashod Nakashian
ce2fabb733 loolwsd: moved IO utilities into IoUtil file
Change-Id: I1e8d5562787134cbb490c38b19d83b7514ec9baa
Reviewed-on: https://gerrit.libreoffice.org/23586
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-03-29 14:09:04 +00:00
Ashod Nakashian
48dfce13de loolwsd: moved TileCache into DocumentBroker
Change-Id: If44a2d3158801e0910cf0f991c75b5ef845a5a30
Reviewed-on: https://gerrit.libreoffice.org/23532
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-03-26 16:58:55 +00:00
Pranav Kant
2f60313971 loolwsd: Cancel admin stats timer when thread finishes
Change-Id: I19d6a5368e650f0de93ee15b82c3549344a1d4b4
2016-03-23 22:16:35 +05:30
Ashod Nakashian
ece4538a90 loolwsd: break admin stat gathering if terminating
Change-Id: I3bd7dd9de829d2658d723da031b533504900054b
Reviewed-on: https://gerrit.libreoffice.org/23455
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-03-23 00:07:14 +00:00
Pranav Kant
7f371958ae SSL everywhere
Use same port (9989) for all client connections. This includes
admin panel, static file serving and normal client websocket
connections.

Change-Id: Idcfd7dd8925523c36e884717c41a3b6a827f6ff3
2016-03-22 00:05:29 +05:30
Pranav Kant
06f1c874d6 loolwsd: Use JWT authentication to access admin console
File server serves the admin html file after successfull
authentication, and sets the cookie in client which would be sent
for all subsequent connections by client to connect to admin websocket.

Change-Id: I0ee3bbfca7eefc428020d29612374410556b1e27
2016-03-22 00:05:29 +05:30
Tor Lillqvist
3ccce7d4ca Revert "loolwsd: Use JWT authentication to access admin console"
This reverts commit a0d3c5f3e4.
2016-03-21 16:52:53 +02:00
Pranav Kant
a0d3c5f3e4 loolwsd: Use JWT authentication to access admin console
File server serves the admin html file after successfull
authentication, and sets the cookie in client which would be sent
for all subsequent connections by client to connect to admin websocket.

Change-Id: I0ee3bbfca7eefc428020d29612374410556b1e27
2016-03-21 16:32:41 +02:00
Miklos Vajna
2563b3c848 loolwsd: add missing prefix in Admin 2016-03-21 08:59:15 +01:00
Andras Timar
345f136145 loolwsd: fix -Werror,-Wshadow 2016-03-14 10:33:11 +01:00
Pranav Kant
ea29196fed loolwsd: Periodic memory usage subscription
By default, queries and stores the total memory usage in
AdminModel every 5 seconds, and caches the last 100 such values.
Both cache size and interval can be changed by simple commands
from the clients.

Change-Id: I86cf8228d0129dc8aab0a03856c12dfeb240b169
2016-03-13 19:40:13 +05:30
Pranav Kant
d0006ae5d8 loolwsd: Wait for client threads to finish
Well, it was already there.
e7f75a3e56 was though correct
introduced it again. Remove duplicate such call.

Change-Id: Iddacbee53aaec58340db489e7830af75354aee34
2016-03-13 19:37:08 +05:30